PostgreSQL Source Code  git master
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 EMPTY   mm_strdup("")
 
#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)
 

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 (char *stmt, int whenever_mode, enum ECPG_statement_type st)
 
void output_prepare_statement (char *name, char *stmt)
 
void output_deallocate_prepare_statement (char *name)
 
void output_simple_statement (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 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 (char *desc_name)
 
void output_get_descr (char *desc_name, char *index)
 
void output_set_descr_header (char *desc_name)
 
void output_set_descr (char *desc_name, char *index)
 
void push_assignment (char *var, enum ECPGdtype value)
 
struct variablefind_variable (char *name)
 
void whenever_action (int mode)
 
void add_descriptor (char *name, char *connection)
 
void drop_descriptor (char *name, char *connection)
 
struct descriptorlookup_descriptor (char *name, 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, char **dimension, char **length, char *type_dimension, 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

◆ EMPTY

#define EMPTY   mm_strdup("")

Definition at line 16 of file preproc_extern.h.

◆ ILLEGAL_OPTION

#define ILLEGAL_OPTION   1

Definition at line 119 of file preproc_extern.h.

◆ INDICATOR_NOT_ARRAY

#define INDICATOR_NOT_ARRAY   4

Definition at line 122 of file preproc_extern.h.

◆ INDICATOR_NOT_SIMPLE

#define INDICATOR_NOT_SIMPLE   7

Definition at line 125 of file preproc_extern.h.

◆ INDICATOR_NOT_STRUCT

#define INDICATOR_NOT_STRUCT   6

Definition at line 124 of file preproc_extern.h.

◆ INFORMIX_MODE

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

Definition at line 133 of file preproc_extern.h.

◆ NO_INCLUDE_FILE

#define NO_INCLUDE_FILE   2

Definition at line 120 of file preproc_extern.h.

◆ ORACLE_MODE

#define ORACLE_MODE   (compat == ECPG_COMPAT_ORACLE)

Definition at line 134 of file preproc_extern.h.

◆ OUT_OF_MEMORY

#define OUT_OF_MEMORY   5

Definition at line 123 of file preproc_extern.h.

◆ PARSE_ERROR

#define PARSE_ERROR   3

Definition at line 121 of file preproc_extern.h.

◆ STRUCT_DEPTH

#define STRUCT_DEPTH   128

Definition at line 15 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 127 of file preproc_extern.h.

128 {
130 };
@ ECPG_COMPAT_PGSQL
@ ECPG_COMPAT_ORACLE
@ ECPG_COMPAT_INFORMIX
@ ECPG_COMPAT_INFORMIX_SE

Function Documentation

◆ add_descriptor()

void add_descriptor ( char *  name,
char *  connection 
)

Definition at line 76 of file descriptor.c.

77 {
78  struct descriptor *new;
79 
80  if (name[0] != '"')
81  return;
82 
83  new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
84 
85  new->next = descriptors;
86  new->name = mm_alloc(strlen(name) + 1);
87  strcpy(new->name, name);
88  if (connection)
89  {
90  new->connection = mm_alloc(strlen(connection) + 1);
91  strcpy(new->connection, connection);
92  }
93  else
94  new->connection = connection;
95  descriptors = new;
96 }
static struct descriptor * descriptors
Definition: descriptor.c:73
char * connection
void * mm_alloc(size_t size)
Definition: type.c:13
const char * name

References connection, descriptors, mm_alloc(), 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 378 of file variable.c.

379 {
380  struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
381 
382  p->variable = var;
383  p->indicator = ind;
384  p->next = *list;
385  *list = p;
386 }
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 390 of file variable.c.

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

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

◆ adjust_array()

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

Definition at line 516 of file variable.c.

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

◆ check_indicator()

void check_indicator ( struct ECPGtype var)

Definition at line 466 of file variable.c.

467 {
468  /* make sure this is a valid indicator variable */
469  switch (var->type)
470  {
471  struct ECPGstruct_member *p;
472 
473  case ECPGt_short:
474  case ECPGt_int:
475  case ECPGt_long:
476  case ECPGt_long_long:
478  case ECPGt_unsigned_int:
479  case ECPGt_unsigned_long:
481  break;
482 
483  case ECPGt_struct:
484  case ECPGt_union:
485  for (p = var->u.members; p; p = p->next)
486  check_indicator(p->type);
487  break;
488 
489  case ECPGt_array:
490  check_indicator(var->u.element);
491  break;
492  default:
493  mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type");
494  break;
495  }
496 }
@ 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:466
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
enum ECPGttype type
Definition: type.h:19
struct ECPGstruct_member * members
Definition: type.h:30
struct ECPGtype * element
Definition: type.h:28
union ECPGtype::@159 u
@ 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 337 of file descriptor.c.

338 {
339  static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
340  static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
341  static struct variable varspace[2] = {
342  {descriptor_names[0], &descriptor_type, 0, NULL},
343  {descriptor_names[1], &descriptor_type, 0, NULL}
344  };
345 
346  strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
347  return &varspace[input];
348 }
@ 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:335
Definition: type.h:18

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

◆ drop_descriptor()

void drop_descriptor ( char *  name,
char *  connection 
)

Definition at line 99 of file descriptor.c.

100 {
101  struct descriptor *i;
102  struct descriptor **lastptr = &descriptors;
103 
104  if (name[0] != '"')
105  return;
106 
107  for (i = descriptors; i; lastptr = &i->next, i = i->next)
108  {
109  if (strcmp(name, i->name) == 0)
110  {
111  if ((!connection && !i->connection)
112  || (connection && i->connection
113  && strcmp(connection, i->connection) == 0))
114  {
115  *lastptr = i->next;
116  free(i->connection);
117  free(i->name);
118  free(i);
119  return;
120  }
121  }
122  }
123  if (connection)
124  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
125  else
126  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
127 }
#define free(a)
Definition: header.h:65
int i
Definition: isn.c:73
@ 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 437 of file variable.c.

438 {
439  char *str_zero;
440 
441  if (list == NULL)
442  return;
443 
444  str_zero = mm_strdup("0");
445 
446  /*
447  * The list is build up from the beginning so lets first dump the end of
448  * the list:
449  */
450 
451  dump_variables(list->next, mode);
452 
453  /* Then the current element and its indicator */
454  ECPGdump_a_type(base_yyout, list->variable->name, list->variable->type, list->variable->brace_level,
455  list->indicator->name, list->indicator->type, list->indicator->brace_level,
456  NULL, NULL, str_zero, NULL, NULL);
457 
458  /* Then release the list element. */
459  if (mode != 0)
460  free(list);
461 
462  free(str_zero);
463 }
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:437
static PgChecksumMode mode
Definition: pg_checksums.c:56
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:241

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 56 of file parser.c.

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

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

◆ find_variable()

struct variable* find_variable ( 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  default:
220  break;
221  }
222  }
223  if (*end == '.')
224  p = find_struct(name, next, end);
225  else
226  {
227  char c = *next;
228 
229  *next = '\0';
230  p = find_simple(name);
231  if (p == NULL)
232  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
233 
234  *next = c;
235  switch (p->type->u.element->type)
236  {
237  case ECPGt_array:
238  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);
239  case ECPGt_struct:
240  case ECPGt_union:
241  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);
242  default:
243  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);
244  }
245  }
246  }
247  else
248  p = find_struct(name, next, next);
249  }
250  else
251  p = find_simple(name);
252 
253  if (p == NULL)
254  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
255 
256  return p;
257 }
static int32 next
Definition: blutils.c:221
static struct variable * find_struct(char *name, char *next, char *end)
Definition: variable.c:126
static struct variable * find_simple(char *name)
Definition: variable.c:177
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_array_type(struct ECPGtype *type, char *size)
Definition: type.c:111
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:121

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 693 of file type.c.

694 {
695  switch (type)
696  {
697  case ECPGd_count:
698  return "ECPGd_count";
699  break;
700  case ECPGd_data:
701  return "ECPGd_data";
702  break;
703  case ECPGd_di_code:
704  return "ECPGd_di_code";
705  break;
706  case ECPGd_di_precision:
707  return "ECPGd_di_precision";
708  break;
709  case ECPGd_indicator:
710  return "ECPGd_indicator";
711  break;
712  case ECPGd_key_member:
713  return "ECPGd_key_member";
714  break;
715  case ECPGd_length:
716  return "ECPGd_length";
717  break;
718  case ECPGd_name:
719  return "ECPGd_name";
720  break;
721  case ECPGd_nullable:
722  return "ECPGd_nullable";
723  break;
724  case ECPGd_octet:
725  return "ECPGd_octet";
726  break;
727  case ECPGd_precision:
728  return "ECPGd_precision";
729  break;
730  case ECPGd_ret_length:
731  return "ECPGd_ret_length";
732  case ECPGd_ret_octet:
733  return "ECPGd_ret_octet";
734  break;
735  case ECPGd_scale:
736  return "ECPGd_scale";
737  break;
738  case ECPGd_type:
739  return "ECPGd_type";
740  break;
741  case ECPGd_cardinality:
742  return "ECPGd_cardinality";
743  default:
744  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
745  }
746 
747  return NULL;
748 }
@ 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 499 of file variable.c.

500 {
501  struct typedefs *this;
502 
503  for (this = types; this != NULL; this = this->next)
504  {
505  if (strcmp(this->name, name) == 0)
506  return this;
507  }
508 
509  if (!noerror)
510  mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
511 
512  return NULL;
513 }
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 94 of file output.c.

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

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

Referenced by output_line_number().

◆ lex_init()

void lex_init ( void  )

Referenced by main().

◆ lookup_descriptor()

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

Definition at line 131 of file descriptor.c.

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

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

◆ mm_alloc()

void* mm_alloc ( size_t  size)

Definition at line 13 of file type.c.

14 {
15  void *ptr = malloc(size);
16 
17  if (ptr == NULL)
18  mmfatal(OUT_OF_MEMORY, "out of memory");
19 
20  return ptr;
21 }
#define malloc(a)
Definition: header.h:50
#define OUT_OF_MEMORY
static pg_noinline void Size size
Definition: slab.c:607

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(), hashline_number(), main(), new_variable(), push_assignment(), and sqlda_variable().

◆ mm_strdup()

char* mm_strdup ( const char *  string)

Definition at line 25 of file type.c.

26 {
27  char *new = strdup(string);
28 
29  if (new == NULL)
30  mmfatal(OUT_OF_MEMORY, "out of memory");
31 
32  return new;
33 }

References mmfatal(), and OUT_OF_MEMORY.

Referenced by add_preprocessor_define(), adjust_array(), dump_variables(), ECPGdump_a_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), lookup_descriptor(), main(), new_variable(), output_get_descr(), output_set_descr(), 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 ( char *  name)

Definition at line 182 of file output.c.

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

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

◆ output_get_descr()

void output_get_descr ( char *  desc_name,
char *  index 
)

Definition at line 181 of file descriptor.c.

182 {
183  struct assignment *results;
184 
185  fprintf(base_yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
186  for (results = assignments; results != NULL; results = results->next)
187  {
188  const struct variable *v = find_variable(results->variable);
189  char *str_zero = mm_strdup("0");
190 
191  switch (results->value)
192  {
193  case ECPGd_nullable:
194  mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
195  break;
196  case ECPGd_key_member:
197  mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
198  break;
199  default:
200  break;
201  }
202  fprintf(base_yyout, "%s,", get_dtype(results->value));
204  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
205  free(str_zero);
206  }
208  fputs("ECPGd_EODT);\n", base_yyout);
209 
210  whenever_action(2 | 1);
211 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
struct variable * find_variable(char *name)
Definition: variable.c:193
const char * get_dtype(enum ECPGdtype)
Definition: type.c:693
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 ( char *  desc_name)

Definition at line 162 of file descriptor.c.

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

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  free(line);
16 }
char * hashline_number(void)
Definition: output.c:94

References base_yyout, fprintf, free, and hashline_number().

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

◆ output_prepare_statement()

void output_prepare_statement ( char *  name,
char *  stmt 
)

Definition at line 170 of file output.c.

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

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

◆ output_set_descr()

void output_set_descr ( char *  desc_name,
char *  index 
)

Definition at line 275 of file descriptor.c.

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

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 ( char *  desc_name)

Definition at line 214 of file descriptor.c.

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

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 ( char *  stmt,
int  whenever_mode 
)

Definition at line 19 of file output.c.

20 {
21  output_escaped_str(stmt, false);
22  if (whenever_mode)
23  whenever_action(whenever_mode);
25  free(stmt);
26 }
void output_line_number(void)
Definition: output.c:10

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

◆ output_statement()

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

Definition at line 136 of file output.c.

137 {
138  fprintf(base_yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
139 
140  if (st == ECPGst_prepnormal && !auto_prepare)
141  st = ECPGst_normal;
142 
143  /*
144  * In following cases, stmt is CSTRING or char_variable. They must be
145  * output directly. - prepared_name of EXECUTE without exprlist -
146  * execstring of EXECUTE IMMEDIATE
147  */
149  if (st == ECPGst_execute || st == ECPGst_exec_immediate)
150  fprintf(base_yyout, "%s, ", stmt);
151  else
152  {
153  fputs("\"", base_yyout);
154  output_escaped_str(stmt, false);
155  fputs("\", ", base_yyout);
156  }
157 
158  /* dump variables to C file */
160  fputs("ECPGt_EOIT, ", base_yyout);
162  fputs("ECPGt_EORT);", base_yyout);
163  reset_variables();
164 
165  whenever_action(whenever_mode | 2);
166  free(stmt);
167 }
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:126
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:437
void reset_variables(void)
Definition: variable.c:368
struct arguments * argsresult
Definition: variable.c:365
struct arguments * argsinsert
Definition: variable.c:364

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, free, 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 ( 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_alloc(strlen(var) + 1);
27  strcpy(new->variable, var);
28  new->value = value;
29  assignments = new;
30 }
static struct @155 value

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

◆ remove_typedefs()

void remove_typedefs ( int  brace_level)

Definition at line 260 of file variable.c.

261 {
262  struct typedefs *p,
263  *prev;
264 
265  for (p = prev = types; p;)
266  {
267  if (p->brace_level >= brace_level)
268  {
269  /* remove it */
270  if (p == types)
271  prev = types = p->next;
272  else
273  prev->next = p->next;
274 
275  if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union)
277  free(p->type);
278  free(p->name);
279  free(p);
280  if (prev == types)
281  p = types;
282  else
283  p = prev ? prev->next : NULL;
284  }
285  else
286  {
287  prev = p;
288  p = prev->next;
289  }
290  }
291 }
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 408 of file variable.c.

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

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

◆ remove_variables()

void remove_variables ( int  brace_level)

Definition at line 294 of file variable.c.

295 {
296  struct variable *p,
297  *prev;
298 
299  for (p = prev = allvariables; p;)
300  {
301  if (p->brace_level >= brace_level)
302  {
303  /* is it still referenced by a cursor? */
304  struct cursor *ptr;
305 
306  for (ptr = cur; ptr != NULL; ptr = ptr->next)
307  {
308  struct arguments *varptr,
309  *prevvar;
310 
311  for (varptr = prevvar = ptr->argsinsert; varptr != NULL; varptr = varptr->next)
312  {
313  if (p == varptr->variable)
314  {
315  /* remove from list */
316  if (varptr == ptr->argsinsert)
317  ptr->argsinsert = varptr->next;
318  else
319  prevvar->next = varptr->next;
320  }
321  }
322  for (varptr = prevvar = ptr->argsresult; varptr != NULL; varptr = varptr->next)
323  {
324  if (p == varptr->variable)
325  {
326  /* remove from list */
327  if (varptr == ptr->argsresult)
328  ptr->argsresult = varptr->next;
329  else
330  prevvar->next = varptr->next;
331  }
332  }
333  }
334 
335  /* remove it */
336  if (p == allvariables)
337  prev = allvariables = p->next;
338  else
339  prev->next = p->next;
340 
341  ECPGfree_type(p->type);
342  free(p->name);
343  free(p);
344  if (prev == allvariables)
345  p = allvariables;
346  else
347  p = prev ? prev->next : NULL;
348  }
349  else
350  {
351  prev = p;
352  p = prev->next;
353  }
354  }
355 }
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:655

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 368 of file variable.c.

369 {
370  argsinsert = NULL;
371  argsresult = NULL;
372 }
struct arguments * argsresult
Definition: variable.c:365
struct arguments * argsinsert
Definition: variable.c:364

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:687

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 351 of file descriptor.c.

352 {
353  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
354 
355  p->name = mm_strdup(name);
356  p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
357  p->type->type = ECPGt_sqlda;
358  p->type->size = NULL;
359  p->type->struct_sizeof = NULL;
360  p->type->u.element = NULL;
361  p->type->counter = 0;
362  p->brace_level = 0;
363  p->next = NULL;
364 
365  return p;
366 }
@ 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 66 of file output.c.

67 {
68  if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
69  {
71  fprintf(base_yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
72  print_action(&when_nf);
73  }
74  if (when_warn.code != W_NOTHING)
75  {
77  fprintf(base_yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
79  }
80  if (when_error.code != W_NOTHING)
81  {
83  fprintf(base_yyout, "\nif (sqlca.sqlcode < 0) ");
84  print_action(&when_error);
85  }
86 
87  if ((mode & 2) == 2)
88  fputc('}', base_yyout);
89 
91 }
struct when when_error when_nf when_warn
Definition: output.c:32
static void print_action(struct when *w)
Definition: output.c:37
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 364 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ argsresult

struct arguments* argsresult
extern

Definition at line 365 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ auto_create_c

bool auto_create_c

Definition at line 21 of file preproc_extern.h.

◆ auto_prepare

bool auto_prepare

Definition at line 26 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().

◆ base_yylineno

int base_yylineno
extern

Referenced by hashline_number().

◆ base_yyout

◆ base_yytext

char* base_yytext
extern

Referenced by filtered_base_yylex().

◆ 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 30 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 23 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 24 of file preproc_extern.h.

◆ regression_mode

bool regression_mode

Definition at line 25 of file preproc_extern.h.

◆ ret_value

int ret_value

Definition at line 28 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 29 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 22 of file preproc_extern.h.

◆ token_start

char * token_start

Definition at line 36 of file preproc_extern.h.

◆ types

◆ when_warn

struct when when_error when_nf when_warn
extern

Definition at line 19 of file output.c.

Referenced by main(), and whenever_action().