PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
preproc_extern.h File Reference
#include "common/keywords.h"
#include "type.h"
#include <limits.h>
Include dependency graph for preproc_extern.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STRUCT_DEPTH   128
 
#define YYLTYPE_IS_DECLARED   1
 
#define ILLEGAL_OPTION   1
 
#define NO_INCLUDE_FILE   2
 
#define PARSE_ERROR   3
 
#define INDICATOR_NOT_ARRAY   4
 
#define OUT_OF_MEMORY   5
 
#define INDICATOR_NOT_STRUCT   6
 
#define INDICATOR_NOT_SIMPLE   7
 
#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)
 
#define ORACLE_MODE   (compat == ECPG_COMPAT_ORACLE)
 

Typedefs

typedef const char * YYLTYPE
 

Enumerations

enum  COMPAT_MODE {
  ECPG_COMPAT_PGSQL = 0 , ECPG_COMPAT_INFORMIX , ECPG_COMPAT_INFORMIX_SE , ECPG_COMPAT_ORACLE ,
  ECPG_COMPAT_PGSQL = 0 , ECPG_COMPAT_INFORMIX , ECPG_COMPAT_INFORMIX_SE , ECPG_COMPAT_ORACLE
}
 

Functions

const char * get_dtype (enum ECPGdtype)
 
void lex_init (void)
 
void output_line_number (void)
 
void output_statement (const char *stmt, int whenever_mode, enum ECPG_statement_type st)
 
void output_prepare_statement (const char *name, const char *stmt)
 
void output_deallocate_prepare_statement (const char *name)
 
void output_simple_statement (const char *stmt, int whenever_mode)
 
char * hashline_number (void)
 
int base_yyparse (void)
 
int base_yylex (void)
 
void base_yyerror (const char *error)
 
void * mm_alloc (size_t size)
 
char * mm_strdup (const char *string)
 
void * loc_alloc (size_t size)
 
char * loc_strdup (const char *string)
 
void reclaim_local_storage (void)
 
char * cat2_str (const char *str1, const char *str2)
 
char * cat_str (int count,...)
 
char * make2_str (const char *str1, const char *str2)
 
char * make3_str (const char *str1, const char *str2, const char *str3)
 
void mmerror (int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
 
void void mmfatal (int error_code, const char *error,...) pg_attribute_printf(2
 
void void pg_attribute_noreturn ()
 
void output_get_descr_header (const char *desc_name)
 
void output_get_descr (const char *desc_name, const char *index)
 
void output_set_descr_header (const char *desc_name)
 
void output_set_descr (const char *desc_name, const char *index)
 
void push_assignment (const char *var, enum ECPGdtype value)
 
struct variablefind_variable (const char *name)
 
void whenever_action (int mode)
 
void add_descriptor (const char *name, const char *connection)
 
void drop_descriptor (const char *name, const char *connection)
 
struct descriptorlookup_descriptor (const char *name, const char *connection)
 
struct variabledescriptor_variable (const char *name, int input)
 
struct variablesqlda_variable (const char *name)
 
void add_variable_to_head (struct arguments **list, struct variable *var, struct variable *ind)
 
void add_variable_to_tail (struct arguments **list, struct variable *var, struct variable *ind)
 
void remove_variable_from_list (struct arguments **list, struct variable *var)
 
void dump_variables (struct arguments *list, int mode)
 
struct typedefsget_typedef (const char *name, bool noerror)
 
void adjust_array (enum ECPGttype type_enum, const char **dimension, const char **length, const char *type_dimension, const char *type_index, int pointer_len, bool type_definition)
 
void reset_variables (void)
 
void check_indicator (struct ECPGtype *var)
 
void remove_typedefs (int brace_level)
 
void remove_variables (int brace_level)
 
struct variablenew_variable (const char *name, struct ECPGtype *type, int brace_level)
 
int ScanCKeywordLookup (const char *text)
 
int ScanECPGKeywordLookup (const char *text)
 
void parser_init (void)
 
int filtered_base_yylex (void)
 

Variables

bool autocommit
 
bool auto_create_c
 
bool system_includes
 
bool force_indicator
 
bool questionmarks
 
bool regression_mode
 
bool auto_prepare
 
int braces_open
 
int ret_value
 
int struct_level
 
int ecpg_internal_var
 
char * current_function
 
char * descriptor_name
 
char * connection
 
char * input_filename
 
char * base_yytext
 
char * token_start
 
int base_yylineno
 
FILE * base_yyin
 
FILE * base_yyout
 
char * output_filename
 
struct _include_pathinclude_paths
 
struct cursorcur
 
struct typedefstypes
 
struct _definesdefines
 
struct declared_listg_declared_list
 
struct ECPGtype ecpg_no_indicator
 
struct variable no_indicator
 
struct argumentsargsinsert
 
struct argumentsargsresult
 
struct when when_error when_nf when_warn
 
struct ECPGstruct_memberstruct_member_list [STRUCT_DEPTH]
 
const uint16 SQLScanKeywordTokens []
 
enum COMPAT_MODE compat
 

Macro Definition Documentation

◆ ILLEGAL_OPTION

#define ILLEGAL_OPTION   1

Definition at line 132 of file preproc_extern.h.

◆ INDICATOR_NOT_ARRAY

#define INDICATOR_NOT_ARRAY   4

Definition at line 135 of file preproc_extern.h.

◆ INDICATOR_NOT_SIMPLE

#define INDICATOR_NOT_SIMPLE   7

Definition at line 138 of file preproc_extern.h.

◆ INDICATOR_NOT_STRUCT

#define INDICATOR_NOT_STRUCT   6

Definition at line 137 of file preproc_extern.h.

◆ INFORMIX_MODE

#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)

Definition at line 146 of file preproc_extern.h.

◆ NO_INCLUDE_FILE

#define NO_INCLUDE_FILE   2

Definition at line 133 of file preproc_extern.h.

◆ ORACLE_MODE

#define ORACLE_MODE   (compat == ECPG_COMPAT_ORACLE)

Definition at line 147 of file preproc_extern.h.

◆ OUT_OF_MEMORY

#define OUT_OF_MEMORY   5

Definition at line 136 of file preproc_extern.h.

◆ PARSE_ERROR

#define PARSE_ERROR   3

Definition at line 134 of file preproc_extern.h.

◆ STRUCT_DEPTH

#define STRUCT_DEPTH   128

Definition at line 15 of file preproc_extern.h.

◆ YYLTYPE_IS_DECLARED

#define YYLTYPE_IS_DECLARED   1

Definition at line 22 of file preproc_extern.h.

Typedef Documentation

◆ YYLTYPE

typedef const char* YYLTYPE

Definition at line 20 of file preproc_extern.h.

Enumeration Type Documentation

◆ COMPAT_MODE

Enumerator
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 

Definition at line 140 of file preproc_extern.h.

141 {
143 };
@ ECPG_COMPAT_PGSQL
@ ECPG_COMPAT_ORACLE
@ ECPG_COMPAT_INFORMIX
@ ECPG_COMPAT_INFORMIX_SE

Function Documentation

◆ add_descriptor()

void add_descriptor ( const char *  name,
const char *  connection 
)

Definition at line 75 of file descriptor.c.

76 {
77  struct descriptor *new;
78 
79  if (name[0] != '"')
80  return;
81 
82  new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
83 
84  new->next = descriptors;
85  new->name = mm_strdup(name);
86  if (connection)
87  new->connection = mm_strdup(connection);
88  else
89  new->connection = NULL;
90  descriptors = new;
91 }
static struct descriptor * descriptors
Definition: descriptor.c:72
char * mm_strdup(const char *string)
Definition: util.c:97
void * mm_alloc(size_t size)
Definition: util.c:85
const char * name

References descriptors, mm_alloc(), mm_strdup(), name, and descriptor::name.

◆ add_variable_to_head()

void add_variable_to_head ( struct arguments **  list,
struct variable var,
struct variable ind 
)

Definition at line 382 of file variable.c.

383 {
384  struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
385 
386  p->variable = var;
387  p->indicator = ind;
388  p->next = *list;
389  *list = p;
390 }
struct variable * indicator
Definition: type.h:199
struct arguments * next
Definition: type.h:200
struct variable * variable
Definition: type.h:198

References arguments::indicator, sort-test::list, mm_alloc(), arguments::next, and arguments::variable.

◆ add_variable_to_tail()

void add_variable_to_tail ( struct arguments **  list,
struct variable var,
struct variable ind 
)

Definition at line 394 of file variable.c.

395 {
396  struct arguments *p,
397  *new = (struct arguments *) mm_alloc(sizeof(struct arguments));
398 
399  for (p = *list; p && p->next; p = p->next);
400 
401  new->variable = var;
402  new->indicator = ind;
403  new->next = NULL;
404 
405  if (p)
406  p->next = new;
407  else
408  *list = new;
409 }

References sort-test::list, mm_alloc(), and arguments::next.

◆ adjust_array()

void adjust_array ( enum ECPGttype  type_enum,
const char **  dimension,
const char **  length,
const char *  type_dimension,
const char *  type_index,
int  pointer_len,
bool  type_definition 
)

Definition at line 520 of file variable.c.

524 {
525  if (atoi(type_index) >= 0)
526  {
527  if (atoi(*length) >= 0)
528  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
529 
530  *length = type_index;
531  }
532 
533  if (atoi(type_dimension) >= 0)
534  {
535  if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
536  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
537 
538  if (atoi(*dimension) >= 0)
539  *length = *dimension;
540 
541  *dimension = type_dimension;
542  }
543 
544  if (pointer_len > 2)
545  mmfatal(PARSE_ERROR, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
546  "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
547  pointer_len);
548 
549  if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
550  mmfatal(PARSE_ERROR, "pointer to pointer is not supported for this data type");
551 
552  if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
553  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
554 
555  if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
556  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
557 
558  switch (type_enum)
559  {
560  case ECPGt_struct:
561  case ECPGt_union:
562  /* pointer has to get dimension 0 */
563  if (pointer_len)
564  {
565  *length = *dimension;
566  *dimension = "0";
567  }
568 
569  if (atoi(*length) >= 0)
570  mmfatal(PARSE_ERROR, "multidimensional arrays for structures are not supported");
571 
572  break;
573  case ECPGt_varchar:
574  case ECPGt_bytea:
575  /* pointer has to get dimension 0 */
576  if (pointer_len)
577  *dimension = "0";
578 
579  /* one index is the string length */
580  if (atoi(*length) < 0)
581  {
582  *length = *dimension;
583  *dimension = "-1";
584  }
585 
586  break;
587  case ECPGt_char:
588  case ECPGt_unsigned_char:
589  case ECPGt_string:
590  /* char ** */
591  if (pointer_len == 2)
592  {
593  *length = *dimension = "0";
594  break;
595  }
596 
597  /* pointer has to get length 0 */
598  if (pointer_len == 1)
599  *length = "0";
600 
601  /* one index is the string length */
602  if (atoi(*length) < 0)
603  {
604  /*
605  * make sure we return length = -1 for arrays without given
606  * bounds
607  */
608  if (atoi(*dimension) < 0 && !type_definition)
609 
610  /*
611  * do not change this for typedefs since it will be
612  * changed later on when the variable is defined
613  */
614  *length = "1";
615  else if (strcmp(*dimension, "0") == 0)
616  *length = "-1";
617  else
618  *length = *dimension;
619 
620  *dimension = "-1";
621  }
622  break;
623  default:
624  /* a pointer has dimension = 0 */
625  if (pointer_len)
626  {
627  *length = *dimension;
628  *dimension = "0";
629  }
630 
631  if (atoi(*length) >= 0)
632  mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
633 
634  break;
635  }
636 }
#define ngettext(s, p, n)
Definition: c.h:1186
@ ECPGt_bytea
Definition: ecpgtype.h:67
@ ECPGt_union
Definition: ecpgtype.h:58
@ ECPGt_varchar
Definition: ecpgtype.h:48
@ ECPGt_struct
Definition: ecpgtype.h:57
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGt_string
Definition: ecpgtype.h:65
void void mmfatal(int error_code, const char *error,...) pg_attribute_printf(2
#define PARSE_ERROR

References ECPGt_bytea, ECPGt_char, ECPGt_string, ECPGt_struct, ECPGt_union, ECPGt_unsigned_char, ECPGt_varchar, mmfatal(), ngettext, and PARSE_ERROR.

◆ base_yyerror()

void base_yyerror ( const char *  error)

Referenced by ECPGdump_a_type(), and ECPGfree_type().

◆ base_yylex()

int base_yylex ( void  )

◆ base_yyparse()

int base_yyparse ( void  )

◆ cat2_str()

char* cat2_str ( const char *  str1,
const char *  str2 
)

Definition at line 205 of file util.c.

206 {
207  char *res_str = (char *) loc_alloc(strlen(str1) + strlen(str2) + 2);
208 
209  strcpy(res_str, str1);
210  if (strlen(str1) != 0 && strlen(str2) != 0)
211  strcat(res_str, " ");
212  strcat(res_str, str2);
213  return res_str;
214 }
void * loc_alloc(size_t size)
Definition: util.c:138

References loc_alloc().

Referenced by cat_str().

◆ cat_str()

char* cat_str ( int  count,
  ... 
)

Definition at line 220 of file util.c.

221 {
222  va_list args;
223  int i;
224  char *res_str;
225 
226  va_start(args, count);
227 
228  res_str = va_arg(args, char *);
229 
230  /* now add all other strings */
231  for (i = 1; i < count; i++)
232  res_str = cat2_str(res_str, va_arg(args, char *));
233 
234  va_end(args);
235 
236  return res_str;
237 }
char * cat2_str(const char *str1, const char *str2)
Definition: util.c:205
int i
Definition: isn.c:72
va_end(args)
va_start(args, fmt)

References generate_unaccent_rules::args, cat2_str(), i, va_end(), and va_start().

◆ check_indicator()

void check_indicator ( struct ECPGtype var)

Definition at line 470 of file variable.c.

471 {
472  /* make sure this is a valid indicator variable */
473  switch (var->type)
474  {
475  struct ECPGstruct_member *p;
476 
477  case ECPGt_short:
478  case ECPGt_int:
479  case ECPGt_long:
480  case ECPGt_long_long:
482  case ECPGt_unsigned_int:
483  case ECPGt_unsigned_long:
485  break;
486 
487  case ECPGt_struct:
488  case ECPGt_union:
489  for (p = var->u.members; p; p = p->next)
490  check_indicator(p->type);
491  break;
492 
493  case ECPGt_array:
494  check_indicator(var->u.element);
495  break;
496  default:
497  mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type");
498  break;
499  }
500 }
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_unsigned_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_array
Definition: ecpgtype.h:56
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
void check_indicator(struct ECPGtype *var)
Definition: variable.c:470
void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
struct ECPGtype * type
Definition: type.h:13
struct ECPGstruct_member * next
Definition: type.h:14
union ECPGtype::@164 u
enum ECPGttype type
Definition: type.h:19
struct ECPGstruct_member * members
Definition: type.h:30
struct ECPGtype * element
Definition: type.h:28
@ ET_ERROR
Definition: type.h:219

References check_indicator(), ECPGt_array, ECPGt_int, ECPGt_long, ECPGt_long_long, ECPGt_short, ECPGt_struct, ECPGt_union, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGtype::element, ET_ERROR, ECPGtype::members, mmerror(), ECPGstruct_member::next, PARSE_ERROR, ECPGstruct_member::type, ECPGtype::type, and ECPGtype::u.

Referenced by check_indicator().

◆ descriptor_variable()

struct variable* descriptor_variable ( const char *  name,
int  input 
)

Definition at line 331 of file descriptor.c.

332 {
333  static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
334  static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
335  static struct variable varspace[2] = {
336  {descriptor_names[0], &descriptor_type, 0, NULL},
337  {descriptor_names[1], &descriptor_type, 0, NULL}
338  };
339 
340  strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
341  return &varspace[input];
342 }
@ ECPGt_descriptor
Definition: ecpgtype.h:59
FILE * input
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define MAX_DESCRIPTOR_NAMELEN
Definition: descriptor.c:329
Definition: type.h:18

References ECPGt_descriptor, input, MAX_DESCRIPTOR_NAMELEN, name, and strlcpy().

◆ drop_descriptor()

void drop_descriptor ( const char *  name,
const char *  connection 
)

Definition at line 94 of file descriptor.c.

95 {
96  struct descriptor *i;
97  struct descriptor **lastptr = &descriptors;
98 
99  if (name[0] != '"')
100  return;
101 
102  for (i = descriptors; i; lastptr = &i->next, i = i->next)
103  {
104  if (strcmp(name, i->name) == 0)
105  {
106  if ((!connection && !i->connection)
107  || (connection && i->connection
108  && strcmp(connection, i->connection) == 0))
109  {
110  *lastptr = i->next;
111  free(i->connection);
112  free(i->name);
113  free(i);
114  return;
115  }
116  }
117  }
118  if (connection)
119  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
120  else
121  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
122 }
#define free(a)
Definition: header.h:65
@ ET_WARNING
Definition: type.h:219

References descriptors, ET_WARNING, free, i, mmerror(), name, and PARSE_ERROR.

◆ dump_variables()

void dump_variables ( struct arguments list,
int  mode 
)

Definition at line 441 of file variable.c.

442 {
443  char *str_zero;
444 
445  if (list == NULL)
446  return;
447 
448  str_zero = mm_strdup("0");
449 
450  /*
451  * The list is build up from the beginning so lets first dump the end of
452  * the list:
453  */
454 
455  dump_variables(list->next, mode);
456 
457  /* Then the current element and its indicator */
458  ECPGdump_a_type(base_yyout, list->variable->name, list->variable->type, list->variable->brace_level,
459  list->indicator->name, list->indicator->type, list->indicator->brace_level,
460  NULL, NULL, str_zero, NULL, NULL);
461 
462  /* Then release the list element. */
463  if (mode != 0)
464  free(list);
465 
466  free(str_zero);
467 }
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:441
static PgChecksumMode mode
Definition: pg_checksums.c:55
FILE * base_yyout
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:217

References base_yyout, dump_variables(), ECPGdump_a_type(), free, sort-test::list, mm_strdup(), and mode.

Referenced by dump_variables(), and output_statement().

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 57 of file parser.c.

58 {
59  int cur_token;
60  int next_token;
61  YYSTYPE cur_yylval;
62  YYLTYPE cur_yylloc;
63  char *cur_yytext;
64 
65  /* Get next token --- we might already have it */
66  if (have_lookahead)
67  {
68  cur_token = lookahead_token;
69  base_yylval = lookahead_yylval;
70  base_yylloc = lookahead_yylloc;
72  have_lookahead = false;
73  }
74  else
75  cur_token = base_yylex_location();
76 
77  /*
78  * If this token isn't one that requires lookahead, just return it.
79  */
80  switch (cur_token)
81  {
82  case FORMAT:
83  case NOT:
84  case NULLS_P:
85  case WITH:
86  case WITHOUT:
87  case UIDENT:
88  case USCONST:
89  break;
90  default:
91  return cur_token;
92  }
93 
94  /* Save and restore lexer output variables around the call */
95  cur_yylval = base_yylval;
96  cur_yylloc = base_yylloc;
97  cur_yytext = base_yytext;
98 
99  /* Get next token, saving outputs into lookahead variables */
101 
103  lookahead_yylval = base_yylval;
104  lookahead_yylloc = base_yylloc;
106 
107  base_yylval = cur_yylval;
108  base_yylloc = cur_yylloc;
109  base_yytext = cur_yytext;
110 
111  have_lookahead = true;
112 
113  /* Replace cur_token if needed, based on lookahead */
114  switch (cur_token)
115  {
116  case FORMAT:
117  /* Replace FORMAT by FORMAT_LA if it's followed by JSON */
118  switch (next_token)
119  {
120  case JSON:
121  cur_token = FORMAT_LA;
122  break;
123  }
124  break;
125 
126  case NOT:
127  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
128  switch (next_token)
129  {
130  case BETWEEN:
131  case IN_P:
132  case LIKE:
133  case ILIKE:
134  case SIMILAR:
135  cur_token = NOT_LA;
136  break;
137  }
138  break;
139 
140  case NULLS_P:
141  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
142  switch (next_token)
143  {
144  case FIRST_P:
145  case LAST_P:
146  cur_token = NULLS_LA;
147  break;
148  }
149  break;
150 
151  case WITH:
152  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
153  switch (next_token)
154  {
155  case TIME:
156  case ORDINALITY:
157  cur_token = WITH_LA;
158  break;
159  }
160  break;
161 
162  case WITHOUT:
163  /* Replace WITHOUT by WITHOUT_LA if it's followed by TIME */
164  switch (next_token)
165  {
166  case TIME:
167  cur_token = WITHOUT_LA;
168  break;
169  }
170  break;
171  case UIDENT:
172  case USCONST:
173  /* Look ahead for UESCAPE */
174  if (next_token == UESCAPE)
175  {
176  /* Yup, so get third token, which had better be SCONST */
177  const char *escstr;
178 
179  /*
180  * Again save and restore lexer output variables around the
181  * call
182  */
183  cur_yylval = base_yylval;
184  cur_yylloc = base_yylloc;
185  cur_yytext = base_yytext;
186 
187  /* Get third token */
189 
190  if (next_token != SCONST)
191  mmerror(PARSE_ERROR, ET_ERROR, "UESCAPE must be followed by a simple string literal");
192 
193  /*
194  * Save and check escape string, which the scanner returns
195  * with quotes
196  */
197  escstr = base_yylval.str;
198  if (strlen(escstr) != 3 || !check_uescapechar(escstr[1]))
199  mmerror(PARSE_ERROR, ET_ERROR, "invalid Unicode escape character");
200 
201  base_yylval = cur_yylval;
202  base_yylloc = cur_yylloc;
203  base_yytext = cur_yytext;
204 
205  /* Combine 3 tokens into 1 */
206  base_yylval.str = psprintf("%s UESCAPE %s", base_yylval.str, escstr);
207  base_yylloc = loc_strdup(base_yylval.str);
208 
209  /* Clear have_lookahead, thereby consuming all three tokens */
210  have_lookahead = false;
211  }
212 
213  if (cur_token == UIDENT)
214  cur_token = IDENT;
215  else if (cur_token == USCONST)
216  cur_token = SCONST;
217  break;
218  }
219 
220  return cur_token;
221 }
static bool next_token(char **lineptr, StringInfo buf, bool *initial_quote, bool *terminating_comma)
Definition: hba.c:185
static YYLTYPE lookahead_yylloc
Definition: parser.c:31
static int base_yylex_location(void)
Definition: parser.c:237
static bool have_lookahead
Definition: parser.c:28
static int lookahead_token
Definition: parser.c:29
static YYSTYPE lookahead_yylval
Definition: parser.c:30
static char * lookahead_yytext
Definition: parser.c:32
static bool check_uescapechar(unsigned char escape)
Definition: parser.c:280
const char * YYLTYPE
char * loc_strdup(const char *string)
Definition: util.c:170
char * base_yytext
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43

References base_yylex_location(), base_yytext, check_uescapechar(), ET_ERROR, have_lookahead, loc_strdup(), lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, mmerror(), next_token(), PARSE_ERROR, and psprintf().

◆ find_variable()

struct variable* find_variable ( const char *  name)

Definition at line 193 of file variable.c.

194 {
195  char *next,
196  *end;
197  struct variable *p;
198  int count;
199 
200  next = strpbrk(name, ".[-");
201  if (next)
202  {
203  if (*next == '[')
204  {
205  /*
206  * We don't care about what's inside the array braces so just eat
207  * up the characters
208  */
209  for (count = 1, end = next + 1; count; end++)
210  {
211  switch (*end)
212  {
213  case '[':
214  count++;
215  break;
216  case ']':
217  count--;
218  break;
219  case '\0':
220  mmfatal(PARSE_ERROR, "unmatched brace in variable \"%s\"", name);
221  break;
222  default:
223  break;
224  }
225  }
226  if (*end == '.')
227  p = find_struct(name, next, end);
228  else
229  {
230  char c = *next;
231 
232  *next = '\0';
233  p = find_simple(name);
234  if (p == NULL)
235  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
236  if (p->type->type != ECPGt_array)
237  mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
238  *next = c;
239  switch (p->type->u.element->type)
240  {
241  case ECPGt_array:
242  return new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size, p->type->u.element->u.element->counter), p->type->u.element->size), p->brace_level);
243  case ECPGt_struct:
244  case ECPGt_union:
245  return new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->type_name, p->type->u.element->struct_sizeof), p->brace_level);
246  default:
247  return new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->counter), p->brace_level);
248  }
249  }
250  }
251  else
252  p = find_struct(name, next, next);
253  }
254  else
255  p = find_simple(name);
256 
257  if (p == NULL)
258  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
259 
260  return p;
261 }
static int32 next
Definition: blutils.c:219
static struct variable * find_simple(const char *name)
Definition: variable.c:177
static struct variable * find_struct(const char *name, char *next, char *end)
Definition: variable.c:126
struct variable * new_variable(const char *name, struct ECPGtype *type, int brace_level)
Definition: variable.c:10
char * c
enum ECPGttype type
int brace_level
Definition: type.h:192
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:97
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, const char *size)
Definition: type.c:87
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, const char *size, int counter)
Definition: type.c:72

References variable::brace_level, ECPGmake_array_type(), ECPGmake_simple_type(), ECPGmake_struct_type(), ECPGt_array, ECPGt_struct, ECPGt_union, find_simple(), find_struct(), mmfatal(), name, new_variable(), next, PARSE_ERROR, and variable::type.

Referenced by ECPGdump_a_type(), ECPGnumeric_lvalue(), find_struct(), output_get_descr(), and output_set_descr().

◆ get_dtype()

const char* get_dtype ( enum  ECPGdtype)

Definition at line 669 of file type.c.

670 {
671  switch (type)
672  {
673  case ECPGd_count:
674  return "ECPGd_count";
675  break;
676  case ECPGd_data:
677  return "ECPGd_data";
678  break;
679  case ECPGd_di_code:
680  return "ECPGd_di_code";
681  break;
682  case ECPGd_di_precision:
683  return "ECPGd_di_precision";
684  break;
685  case ECPGd_indicator:
686  return "ECPGd_indicator";
687  break;
688  case ECPGd_key_member:
689  return "ECPGd_key_member";
690  break;
691  case ECPGd_length:
692  return "ECPGd_length";
693  break;
694  case ECPGd_name:
695  return "ECPGd_name";
696  break;
697  case ECPGd_nullable:
698  return "ECPGd_nullable";
699  break;
700  case ECPGd_octet:
701  return "ECPGd_octet";
702  break;
703  case ECPGd_precision:
704  return "ECPGd_precision";
705  break;
706  case ECPGd_ret_length:
707  return "ECPGd_ret_length";
708  case ECPGd_ret_octet:
709  return "ECPGd_ret_octet";
710  break;
711  case ECPGd_scale:
712  return "ECPGd_scale";
713  break;
714  case ECPGd_type:
715  return "ECPGd_type";
716  break;
717  case ECPGd_cardinality:
718  return "ECPGd_cardinality";
719  default:
720  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
721  }
722 
723  return NULL;
724 }
@ ECPGd_scale
Definition: ecpgtype.h:86
@ ECPGd_precision
Definition: ecpgtype.h:83
@ ECPGd_length
Definition: ecpgtype.h:79
@ ECPGd_nullable
Definition: ecpgtype.h:81
@ ECPGd_di_precision
Definition: ecpgtype.h:76
@ ECPGd_type
Definition: ecpgtype.h:87
@ ECPGd_cardinality
Definition: ecpgtype.h:89
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_ret_length
Definition: ecpgtype.h:84
@ ECPGd_di_code
Definition: ecpgtype.h:75
@ ECPGd_count
Definition: ecpgtype.h:73
@ ECPGd_name
Definition: ecpgtype.h:80
@ ECPGd_key_member
Definition: ecpgtype.h:78
@ ECPGd_octet
Definition: ecpgtype.h:82
@ ECPGd_ret_octet
Definition: ecpgtype.h:85
@ ECPGd_data
Definition: ecpgtype.h:74
const char * type

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ET_ERROR, mmerror(), PARSE_ERROR, and type.

Referenced by output_get_descr(), and output_set_descr().

◆ get_typedef()

struct typedefs* get_typedef ( const char *  name,
bool  noerror 
)

Definition at line 503 of file variable.c.

504 {
505  struct typedefs *this;
506 
507  for (this = types; this != NULL; this = this->next)
508  {
509  if (strcmp(this->name, name) == 0)
510  return this;
511  }
512 
513  if (!noerror)
514  mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
515 
516  return NULL;
517 }
struct typedefs * types
Definition: ecpg.c:29
Definition: type.h:158

References mmfatal(), name, next, PARSE_ERROR, and types.

◆ hashline_number()

char* hashline_number ( void  )

Definition at line 92 of file output.c.

93 {
94  /* do not print line numbers if we are in debug mode */
95  if (input_filename
96 #ifdef YYDEBUG
97  && !base_yydebug
98 #endif
99  )
100  {
101  /* "* 2" here is for escaping '\' and '"' below */
102  char *line = loc_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2);
103  char *src,
104  *dest;
105 
106  sprintf(line, "\n#line %d \"", base_yylineno);
107  src = input_filename;
108  dest = line + strlen(line);
109  while (*src)
110  {
111  if (*src == '\\' || *src == '"')
112  *dest++ = '\\';
113  *dest++ = *src++;
114  }
115  *dest = '\0';
116  strcat(dest, "\"\n");
117 
118  return line;
119  }
120 
121  return "";
122 }
#define sprintf
Definition: port.h:240
int base_yylineno
char * input_filename
void * loc_alloc(size_t size)
Definition: util.c:138

References base_yylineno, generate_unaccent_rules::dest, input_filename, loc_alloc(), and sprintf.

Referenced by output_line_number().

◆ lex_init()

void lex_init ( void  )

Referenced by main().

◆ loc_alloc()

void* loc_alloc ( size_t  size)

Definition at line 138 of file util.c.

139 {
140  void *result;
141  loc_chunk *cur_chunk = loc_chunks;
142 
143  /* Ensure all allocations are adequately aligned */
144  size = MAXALIGN(size);
145 
146  /* Need a new chunk? */
147  if (cur_chunk == NULL || size > cur_chunk->chunk_avail)
148  {
149  size_t chunk_size = Max(size, LOC_CHUNK_MIN_SIZE);
150 
151  cur_chunk = mm_alloc(chunk_size + LOC_CHUNK_OVERHEAD);
152  /* Depending on alignment rules, we could waste a bit here */
153  cur_chunk->chunk_used = LOC_CHUNK_OVERHEAD - offsetof(loc_chunk, data);
154  cur_chunk->chunk_avail = chunk_size;
155  /* New chunk becomes the head of the list */
156  cur_chunk->next = loc_chunks;
157  loc_chunks = cur_chunk;
158  }
159 
160  result = cur_chunk->data + cur_chunk->chunk_used;
161  cur_chunk->chunk_used += size;
162  cur_chunk->chunk_avail -= size;
163  return result;
164 }
#define MAXALIGN(LEN)
Definition: c.h:816
#define Max(x, y)
Definition: c.h:1003
#define LOC_CHUNK_OVERHEAD
Definition: util.c:126
static loc_chunk * loc_chunks
Definition: util.c:130
#define LOC_CHUNK_MIN_SIZE
Definition: util.c:127
void * mm_alloc(size_t size)
Definition: util.c:85
const void * data
static pg_noinline void Size size
Definition: slab.c:607
struct loc_chunk * next
Definition: util.c:120
char data[FLEXIBLE_ARRAY_MEMBER]
Definition: util.c:123
unsigned int chunk_used
Definition: util.c:121
unsigned int chunk_avail
Definition: util.c:122

References loc_chunk::chunk_avail, loc_chunk::chunk_used, loc_chunk::data, data, LOC_CHUNK_MIN_SIZE, LOC_CHUNK_OVERHEAD, loc_chunks, Max, MAXALIGN, mm_alloc(), loc_chunk::next, and size.

Referenced by cat2_str(), hashline_number(), loc_strdup(), make2_str(), and make3_str().

◆ loc_strdup()

char* loc_strdup ( const char *  string)

Definition at line 170 of file util.c.

171 {
172  char *result = loc_alloc(strlen(string) + 1);
173 
174  strcpy(result, string);
175  return result;
176 }

References loc_alloc().

Referenced by base_yylex_location(), and filtered_base_yylex().

◆ lookup_descriptor()

struct descriptor* lookup_descriptor ( const char *  name,
const char *  connection 
)

Definition at line 125 of file descriptor.c.

126 {
127  struct descriptor *i;
128 
129  if (name[0] != '"')
130  return NULL;
131 
132  for (i = descriptors; i; i = i->next)
133  {
134  if (strcmp(name, i->name) == 0)
135  {
136  if ((!connection && !i->connection)
137  || (connection && i->connection
138  && strcmp(connection, i->connection) == 0))
139  return i;
140  if (connection && !i->connection)
141  {
142  /* overwrite descriptor's connection */
143  i->connection = mm_strdup(connection);
144  return i;
145  }
146  }
147  }
148  if (connection)
149  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
150  else
151  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
152  return NULL;
153 }

References descriptors, ET_WARNING, i, mm_strdup(), mmerror(), name, and PARSE_ERROR.

◆ make2_str()

char* make2_str ( const char *  str1,
const char *  str2 
)

Definition at line 243 of file util.c.

244 {
245  char *res_str = (char *) loc_alloc(strlen(str1) + strlen(str2) + 1);
246 
247  strcpy(res_str, str1);
248  strcat(res_str, str2);
249  return res_str;
250 }

References loc_alloc().

◆ make3_str()

char* make3_str ( const char *  str1,
const char *  str2,
const char *  str3 
)

Definition at line 256 of file util.c.

257 {
258  char *res_str = (char *) loc_alloc(strlen(str1) + strlen(str2) + strlen(str3) + 1);
259 
260  strcpy(res_str, str1);
261  strcat(res_str, str2);
262  strcat(res_str, str3);
263  return res_str;
264 }

References loc_alloc().

◆ mm_alloc()

void* mm_alloc ( size_t  size)

Definition at line 85 of file util.c.

86 {
87  void *ptr = malloc(size);
88 
89  if (ptr == NULL)
90  mmfatal(OUT_OF_MEMORY, "out of memory");
91 
92  return ptr;
93 }
#define malloc(a)
Definition: header.h:50
void mmfatal(int error_code, const char *error,...)
Definition: util.c:61
#define OUT_OF_MEMORY

References malloc, mmfatal(), OUT_OF_MEMORY, and size.

Referenced by add_descriptor(), add_include_path(), add_preprocessor_define(), add_variable_to_head(), add_variable_to_tail(), ECPGdump_a_simple(), ECPGdump_a_struct(), ECPGmake_simple_type(), ECPGmake_struct_member(), loc_alloc(), main(), new_variable(), push_assignment(), and sqlda_variable().

◆ mm_strdup()

char* mm_strdup ( const char *  string)

Definition at line 97 of file util.c.

98 {
99  char *new = strdup(string);
100 
101  if (new == NULL)
102  mmfatal(OUT_OF_MEMORY, "out of memory");
103 
104  return new;
105 }

References mmfatal(), and OUT_OF_MEMORY.

Referenced by add_descriptor(), add_preprocessor_define(), dump_variables(), ECPGdump_a_type(), ECPGmake_simple_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), lookup_descriptor(), main(), new_variable(), output_get_descr(), output_set_descr(), push_assignment(), and sqlda_variable().

◆ mmerror()

◆ mmfatal()

void void mmfatal ( int  error_code,
const char *  error,
  ... 
)

◆ new_variable()

struct variable* new_variable ( const char *  name,
struct ECPGtype type,
int  brace_level 
)

Definition at line 10 of file variable.c.

11 {
12  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
13 
14  p->name = mm_strdup(name);
15  p->type = type;
17 
18  p->next = allvariables;
19  allvariables = p;
20 
21  return p;
22 }
static struct variable * allvariables
Definition: variable.c:7
char * name
Definition: type.h:190
struct variable * next

References allvariables, variable::brace_level, mm_alloc(), mm_strdup(), name, variable::name, variable::next, type, and variable::type.

Referenced by find_struct_member(), and find_variable().

◆ output_deallocate_prepare_statement()

void output_deallocate_prepare_statement ( const char *  name)

Definition at line 178 of file output.c.

179 {
180  const char *con = connection ? connection : "NULL";
181 
182  if (strcmp(name, "all") != 0)
183  {
184  fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
185  output_escaped_str(name, true);
186  fputs(");", base_yyout);
187  }
188  else
189  fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
190 
191  whenever_action(2);
192 }
enum COMPAT_MODE compat
Definition: ecpg.c:25
void whenever_action(int mode)
Definition: output.c:64
static void output_escaped_str(const char *str, bool quoted)
Definition: output.c:195
#define fprintf
Definition: port.h:242
char * connection

References base_yyout, compat, connection, fprintf, name, output_escaped_str(), and whenever_action().

◆ output_get_descr()

void output_get_descr ( const char *  desc_name,
const char *  index 
)

Definition at line 175 of file descriptor.c.

176 {
177  struct assignment *results;
178 
179  fprintf(base_yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
180  for (results = assignments; results != NULL; results = results->next)
181  {
182  const struct variable *v = find_variable(results->variable);
183  char *str_zero = mm_strdup("0");
184 
185  switch (results->value)
186  {
187  case ECPGd_nullable:
188  mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
189  break;
190  case ECPGd_key_member:
191  mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
192  break;
193  default:
194  break;
195  }
196  fprintf(base_yyout, "%s,", get_dtype(results->value));
198  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
199  free(str_zero);
200  }
202  fputs("ECPGd_EODT);\n", base_yyout);
203 
204  whenever_action(2 | 1);
205 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:32
const char * get_dtype(enum ECPGdtype)
Definition: type.c:669
struct variable * find_variable(const char *name)
Definition: variable.c:193
char * variable
Definition: type.h:212
enum ECPGdtype value
Definition: type.h:213
struct assignment * next
Definition: type.h:214
Definition: type.h:95

References assignments, base_yyout, variable::brace_level, drop_assignments(), ECPGd_key_member, ECPGd_nullable, ECPGdump_a_type(), ET_WARNING, find_variable(), fprintf, free, get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

◆ output_get_descr_header()

void output_get_descr_header ( const char *  desc_name)

Definition at line 156 of file descriptor.c.

157 {
158  struct assignment *results;
159 
160  fprintf(base_yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
161  for (results = assignments; results != NULL; results = results->next)
162  {
163  if (results->value == ECPGd_count)
164  ECPGnumeric_lvalue(results->variable);
165  else
166  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
167  }
168 
170  fprintf(base_yyout, "));\n");
171  whenever_action(3);
172 }
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:45

References assignments, base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, fprintf, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

◆ output_line_number()

void output_line_number ( void  )

Definition at line 10 of file output.c.

11 {
12  char *line = hashline_number();
13 
14  fprintf(base_yyout, "%s", line);
15 }
char * hashline_number(void)
Definition: output.c:92

References base_yyout, fprintf, and hashline_number().

Referenced by main(), output_simple_statement(), and whenever_action().

◆ output_prepare_statement()

void output_prepare_statement ( const char *  name,
const char *  stmt 
)

Definition at line 167 of file output.c.

168 {
169  fprintf(base_yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
170  output_escaped_str(name, true);
171  fputs(", ", base_yyout);
172  output_escaped_str(stmt, true);
173  fputs(");", base_yyout);
174  whenever_action(2);
175 }
bool questionmarks
Definition: ecpg.c:19
#define stmt
Definition: indent_codes.h:59

References base_yyout, fprintf, name, output_escaped_str(), questionmarks, stmt, and whenever_action().

◆ output_set_descr()

void output_set_descr ( const char *  desc_name,
const char *  index 
)

Definition at line 269 of file descriptor.c.

270 {
271  struct assignment *results;
272 
273  fprintf(base_yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
274  for (results = assignments; results != NULL; results = results->next)
275  {
276  const struct variable *v = find_variable(results->variable);
277 
278  switch (results->value)
279  {
280  case ECPGd_cardinality:
281  case ECPGd_di_code:
282  case ECPGd_di_precision:
283  case ECPGd_precision:
284  case ECPGd_scale:
285  mmfatal(PARSE_ERROR, "descriptor item \"%s\" is not implemented",
286  descriptor_item_name(results->value));
287  break;
288 
289  case ECPGd_key_member:
290  case ECPGd_name:
291  case ECPGd_nullable:
292  case ECPGd_octet:
293  case ECPGd_ret_length:
294  case ECPGd_ret_octet:
295  mmfatal(PARSE_ERROR, "descriptor item \"%s\" cannot be set",
296  descriptor_item_name(results->value));
297  break;
298 
299  case ECPGd_data:
300  case ECPGd_indicator:
301  case ECPGd_length:
302  case ECPGd_type:
303  {
304  char *str_zero = mm_strdup("0");
305 
306  fprintf(base_yyout, "%s,", get_dtype(results->value));
308  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
309  free(str_zero);
310  }
311  break;
312 
313  default:
314  ;
315  }
316  }
318  fputs("ECPGd_EODT);\n", base_yyout);
319 
320  whenever_action(2 | 1);
321 }
static const char * descriptor_item_name(enum ECPGdtype itemcode)
Definition: descriptor.c:227

References assignments, base_yyout, variable::brace_level, descriptor_item_name(), drop_assignments(), ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdump_a_type(), find_variable(), fprintf, free, get_dtype(), mm_strdup(), mmfatal(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

◆ output_set_descr_header()

void output_set_descr_header ( const char *  desc_name)

Definition at line 208 of file descriptor.c.

209 {
210  struct assignment *results;
211 
212  fprintf(base_yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
213  for (results = assignments; results != NULL; results = results->next)
214  {
215  if (results->value == ECPGd_count)
216  ECPGnumeric_lvalue(results->variable);
217  else
218  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
219  }
220 
222  fprintf(base_yyout, "));\n");
223  whenever_action(3);
224 }

References assignments, base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, fprintf, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

◆ output_simple_statement()

void output_simple_statement ( const char *  stmt,
int  whenever_mode 
)

Definition at line 18 of file output.c.

19 {
20  output_escaped_str(stmt, false);
21  if (whenever_mode)
22  whenever_action(whenever_mode);
24 }
void output_line_number(void)
Definition: output.c:10

References output_escaped_str(), output_line_number(), stmt, and whenever_action().

◆ output_statement()

void output_statement ( const char *  stmt,
int  whenever_mode,
enum ECPG_statement_type  st 
)

Definition at line 134 of file output.c.

135 {
136  fprintf(base_yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
137 
138  if (st == ECPGst_prepnormal && !auto_prepare)
139  st = ECPGst_normal;
140 
141  /*
142  * In following cases, stmt is CSTRING or char_variable. They must be
143  * output directly. - prepared_name of EXECUTE without exprlist -
144  * execstring of EXECUTE IMMEDIATE
145  */
147  if (st == ECPGst_execute || st == ECPGst_exec_immediate)
148  fprintf(base_yyout, "%s, ", stmt);
149  else
150  {
151  fputs("\"", base_yyout);
152  output_escaped_str(stmt, false);
153  fputs("\", ", base_yyout);
154  }
155 
156  /* dump variables to C file */
158  fputs("ECPGt_EOIT, ", base_yyout);
160  fputs("ECPGt_EORT);", base_yyout);
161  reset_variables();
162 
163  whenever_action(whenever_mode | 2);
164 }
bool auto_prepare
Definition: ecpg.c:21
bool force_indicator
Definition: ecpg.c:18
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGst_exec_immediate
Definition: ecpgtype.h:99
@ ECPGst_prepnormal
Definition: ecpgtype.h:100
static char * ecpg_statement_type_name[]
Definition: output.c:124
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:441
void reset_variables(void)
Definition: variable.c:372
struct arguments * argsresult
Definition: variable.c:369
struct arguments * argsinsert
Definition: variable.c:368

References argsinsert, argsresult, auto_prepare, base_yyout, compat, dump_variables(), ecpg_statement_type_name, ECPGst_exec_immediate, ECPGst_execute, ECPGst_normal, ECPGst_prepnormal, force_indicator, fprintf, output_escaped_str(), questionmarks, reset_variables(), stmt, and whenever_action().

◆ parser_init()

void parser_init ( void  )

◆ pg_attribute_noreturn()

void void pg_attribute_noreturn ( )

◆ push_assignment()

void push_assignment ( const char *  var,
enum ECPGdtype  value 
)

Definition at line 21 of file descriptor.c.

22 {
23  struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
24 
25  new->next = assignments;
26  new->variable = mm_strdup(var);
27  new->value = value;
28  assignments = new;
29 }
static struct @160 value

References assignments, mm_alloc(), mm_strdup(), value, and assignment::variable.

◆ reclaim_local_storage()

void reclaim_local_storage ( void  )

Definition at line 182 of file util.c.

183 {
184  loc_chunk *cur_chunk,
185  *next_chunk;
186 
187  for (cur_chunk = loc_chunks; cur_chunk; cur_chunk = next_chunk)
188  {
189  next_chunk = cur_chunk->next;
190  free(cur_chunk);
191  }
192  loc_chunks = NULL;
193 }

References free, loc_chunks, and loc_chunk::next.

◆ remove_typedefs()

void remove_typedefs ( int  brace_level)

Definition at line 264 of file variable.c.

265 {
266  struct typedefs *p,
267  *prev;
268 
269  for (p = prev = types; p;)
270  {
271  if (p->brace_level >= brace_level)
272  {
273  /* remove it */
274  if (p == types)
275  prev = types = p->next;
276  else
277  prev->next = p->next;
278 
279  if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union)
281  free(p->type);
282  free(p->name);
283  free(p);
284  if (prev == types)
285  p = types;
286  else
287  p = prev ? prev->next : NULL;
288  }
289  else
290  {
291  prev = p;
292  p = prev->next;
293  }
294  }
295 }
enum ECPGttype type_enum
Definition: type.h:123
int brace_level
Definition: type.h:162
char * name
Definition: type.h:159
struct ECPGstruct_member * struct_member_list
Definition: type.h:161
struct typedefs * next
Definition: type.h:163
struct this_type * type
Definition: type.h:160

References typedefs::brace_level, ECPGt_struct, ECPGt_union, free, typedefs::name, typedefs::next, typedefs::struct_member_list, typedefs::type, this_type::type_enum, and types.

◆ remove_variable_from_list()

void remove_variable_from_list ( struct arguments **  list,
struct variable var 
)

Definition at line 412 of file variable.c.

413 {
414  struct arguments *p,
415  *prev = NULL;
416  bool found = false;
417 
418  for (p = *list; p; p = p->next)
419  {
420  if (p->variable == var)
421  {
422  found = true;
423  break;
424  }
425  prev = p;
426  }
427  if (found)
428  {
429  if (prev)
430  prev->next = p->next;
431  else
432  *list = p->next;
433  }
434 }

References sort-test::list, arguments::next, and arguments::variable.

◆ remove_variables()

void remove_variables ( int  brace_level)

Definition at line 298 of file variable.c.

299 {
300  struct variable *p,
301  *prev;
302 
303  for (p = prev = allvariables; p;)
304  {
305  if (p->brace_level >= brace_level)
306  {
307  /* is it still referenced by a cursor? */
308  struct cursor *ptr;
309 
310  for (ptr = cur; ptr != NULL; ptr = ptr->next)
311  {
312  struct arguments *varptr,
313  *prevvar;
314 
315  for (varptr = prevvar = ptr->argsinsert; varptr != NULL; varptr = varptr->next)
316  {
317  if (p == varptr->variable)
318  {
319  /* remove from list */
320  if (varptr == ptr->argsinsert)
321  ptr->argsinsert = varptr->next;
322  else
323  prevvar->next = varptr->next;
324  }
325  }
326  for (varptr = prevvar = ptr->argsresult; varptr != NULL; varptr = varptr->next)
327  {
328  if (p == varptr->variable)
329  {
330  /* remove from list */
331  if (varptr == ptr->argsresult)
332  ptr->argsresult = varptr->next;
333  else
334  prevvar->next = varptr->next;
335  }
336  }
337  }
338 
339  /* remove it */
340  if (p == allvariables)
341  prev = allvariables = p->next;
342  else
343  prev->next = p->next;
344 
345  ECPGfree_type(p->type);
346  free(p->name);
347  free(p);
348  if (prev == allvariables)
349  p = allvariables;
350  else
351  p = prev ? prev->next : NULL;
352  }
353  else
354  {
355  prev = p;
356  p = prev->next;
357  }
358  }
359 }
struct cursor * cur
Definition: ecpg.c:28
Definition: type.h:137
struct arguments * argsinsert
Definition: type.h:143
struct cursor * next
Definition: type.h:147
struct arguments * argsresult
Definition: type.h:145
void ECPGfree_type(struct ECPGtype *type)
Definition: type.c:631

References allvariables, cursor::argsinsert, cursor::argsresult, variable::brace_level, cur, ECPGfree_type(), free, variable::name, variable::next, cursor::next, arguments::next, variable::type, and arguments::variable.

◆ reset_variables()

void reset_variables ( void  )

Definition at line 372 of file variable.c.

373 {
374  argsinsert = NULL;
375  argsresult = NULL;
376 }
struct arguments * argsresult
Definition: variable.c:369
struct arguments * argsinsert
Definition: variable.c:368

References argsinsert, and argsresult.

Referenced by output_statement().

◆ ScanCKeywordLookup()

int ScanCKeywordLookup ( const char *  text)

Definition at line 36 of file c_keywords.c.

37 {
38  size_t len;
39  int h;
40  const char *kw;
41 
42  /*
43  * Reject immediately if too long to be any keyword. This saves useless
44  * hashing work on long strings.
45  */
46  len = strlen(text);
47  if (len > ScanCKeywords.max_kw_len)
48  return -1;
49 
50  /*
51  * Compute the hash function. Since it's a perfect hash, we need only
52  * match to the specific keyword it identifies.
53  */
54  h = ScanCKeywords_hash_func(text, len);
55 
56  /* An out-of-range result implies no match */
57  if (h < 0 || h >= ScanCKeywords.num_keywords)
58  return -1;
59 
60  kw = GetScanKeyword(h, &ScanCKeywords);
61 
62  if (strcmp(kw, text) == 0)
63  return ScanCKeywordTokens[h];
64 
65  return -1;
66 }
static const uint16 ScanCKeywordTokens[]
Definition: c_keywords.c:20
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)
Definition: kwlookup.h:39
const void size_t len
Definition: c.h:692

References GetScanKeyword(), len, and ScanCKeywordTokens.

◆ ScanECPGKeywordLookup()

int ScanECPGKeywordLookup ( const char *  text)

Definition at line 39 of file ecpg_keywords.c.

40 {
41  int kwnum;
42 
43  /* First check SQL symbols defined by the backend. */
45  if (kwnum >= 0)
46  return SQLScanKeywordTokens[kwnum];
47 
48  /* Try ECPG-specific keywords. */
49  kwnum = ScanKeywordLookup(text, &ScanECPGKeywords);
50  if (kwnum >= 0)
51  return ECPGScanKeywordTokens[kwnum];
52 
53  return -1;
54 }
static const uint16 ECPGScanKeywordTokens[]
Definition: ecpg_keywords.c:24
const uint16 SQLScanKeywordTokens[]
Definition: keywords.c:34
PGDLLIMPORT const ScanKeywordList ScanKeywords
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
Definition: kwlookup.c:38

References ECPGScanKeywordTokens, ScanKeywordLookup(), ScanKeywords, and SQLScanKeywordTokens.

◆ sqlda_variable()

struct variable* sqlda_variable ( const char *  name)

Definition at line 345 of file descriptor.c.

346 {
347  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
348 
349  p->name = mm_strdup(name);
350  p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
351  p->type->type = ECPGt_sqlda;
352  p->type->size = NULL;
353  p->type->struct_sizeof = NULL;
354  p->type->u.element = NULL;
355  p->type->counter = 0;
356  p->brace_level = 0;
357  p->next = NULL;
358 
359  return p;
360 }
@ ECPGt_sqlda
Definition: ecpgtype.h:66

References variable::brace_level, ECPGt_sqlda, mm_alloc(), mm_strdup(), name, variable::name, variable::next, and variable::type.

◆ whenever_action()

void whenever_action ( int  mode)

Definition at line 64 of file output.c.

65 {
66  if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
67  {
69  fprintf(base_yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
70  print_action(&when_nf);
71  }
72  if (when_warn.code != W_NOTHING)
73  {
75  fprintf(base_yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
77  }
78  if (when_error.code != W_NOTHING)
79  {
81  fprintf(base_yyout, "\nif (sqlca.sqlcode < 0) ");
82  print_action(&when_error);
83  }
84 
85  if ((mode & 2) == 2)
86  fputc('}', base_yyout);
87 
89 }
struct when when_error when_nf when_warn
Definition: output.c:30
static void print_action(struct when *w)
Definition: output.c:35
enum WHEN_TYPE code
Definition: type.h:89
@ W_NOTHING
Definition: type.h:78

References base_yyout, when::code, fprintf, mode, output_line_number(), print_action(), W_NOTHING, and when_warn.

Referenced by output_deallocate_prepare_statement(), output_get_descr(), output_get_descr_header(), output_prepare_statement(), output_set_descr(), output_set_descr_header(), output_simple_statement(), and output_statement().

Variable Documentation

◆ argsinsert

struct arguments* argsinsert
extern

Definition at line 368 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ argsresult

struct arguments* argsresult
extern

Definition at line 369 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ auto_create_c

bool auto_create_c

Definition at line 27 of file preproc_extern.h.

◆ auto_prepare

bool auto_prepare

Definition at line 32 of file preproc_extern.h.

◆ autocommit

bool autocommit
extern

Definition at line 15 of file ecpg.c.

Referenced by ECPGconnect(), and main().

◆ base_yyin

FILE* base_yyin
extern

Referenced by main(), and mmfatal().

◆ base_yylineno

int base_yylineno
extern

Referenced by hashline_number(), and vmmerror().

◆ base_yyout

◆ base_yytext

char* base_yytext
extern

◆ braces_open

int braces_open
extern

◆ compat

◆ connection

◆ cur

◆ current_function

char* current_function
extern

◆ defines

struct _defines* defines
extern

Definition at line 30 of file ecpg.c.

Referenced by add_preprocessor_define(), and main().

◆ descriptor_name

char* descriptor_name
extern

◆ ecpg_internal_var

int ecpg_internal_var

Definition at line 36 of file preproc_extern.h.

Referenced by main().

◆ ecpg_no_indicator

struct ECPGtype ecpg_no_indicator
extern

Referenced by ECPGdump_a_struct().

◆ force_indicator

bool force_indicator

Definition at line 29 of file preproc_extern.h.

◆ g_declared_list

struct declared_list* g_declared_list
extern

Definition at line 31 of file ecpg.c.

Referenced by main().

◆ include_paths

struct _include_path* include_paths
extern

Definition at line 27 of file ecpg.c.

Referenced by add_include_path(), and main().

◆ input_filename

◆ no_indicator

struct variable no_indicator
extern

◆ output_filename

char* output_filename
extern

◆ questionmarks

bool questionmarks

Definition at line 30 of file preproc_extern.h.

◆ regression_mode

bool regression_mode

Definition at line 31 of file preproc_extern.h.

◆ ret_value

int ret_value

Definition at line 34 of file preproc_extern.h.

◆ SQLScanKeywordTokens

const uint16 SQLScanKeywordTokens[]
extern

Definition at line 34 of file keywords.c.

Referenced by ScanECPGKeywordLookup().

◆ struct_level

int struct_level

Definition at line 35 of file preproc_extern.h.

◆ struct_member_list

struct ECPGstruct_member* struct_member_list[STRUCT_DEPTH]
extern

Referenced by main().

◆ system_includes

bool system_includes

Definition at line 28 of file preproc_extern.h.

◆ token_start

char * token_start

Definition at line 42 of file preproc_extern.h.

◆ types

◆ when_warn

struct when when_error when_nf when_warn
extern

Definition at line 18 of file output.c.

Referenced by main(), and whenever_action().