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

402{
403 struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
404
405 p->variable = var;
406 p->indicator = ind;
407 p->next = *list;
408 *list = p;
409}
struct variable * indicator
Definition: type.h:200
struct arguments * next
Definition: type.h:201
struct variable * variable
Definition: type.h:199

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

414{
415 struct arguments *p,
416 *new = (struct arguments *) mm_alloc(sizeof(struct arguments));
417
418 for (p = *list; p && p->next; p = p->next);
419
420 new->variable = var;
421 new->indicator = ind;
422 new->next = NULL;
423
424 if (p)
425 p->next = new;
426 else
427 *list = new;
428}

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

544{
545 if (atoi(type_index) >= 0)
546 {
547 if (atoi(*length) >= 0)
548 mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
549
550 *length = type_index;
551 }
552
553 if (atoi(type_dimension) >= 0)
554 {
555 if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
556 mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
557
558 if (atoi(*dimension) >= 0)
559 *length = *dimension;
560
561 *dimension = type_dimension;
562 }
563
564 if (pointer_len > 2)
565 mmfatal(PARSE_ERROR, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
566 "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
567 pointer_len);
568
569 if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
570 mmfatal(PARSE_ERROR, "pointer to pointer is not supported for this data type");
571
572 if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
573 mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
574
575 if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
576 mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
577
578 switch (type_enum)
579 {
580 case ECPGt_struct:
581 case ECPGt_union:
582 /* pointer has to get dimension 0 */
583 if (pointer_len)
584 {
585 *length = *dimension;
586 *dimension = "0";
587 }
588
589 if (atoi(*length) >= 0)
590 mmfatal(PARSE_ERROR, "multidimensional arrays for structures are not supported");
591
592 break;
593 case ECPGt_varchar:
594 case ECPGt_bytea:
595 /* pointer has to get dimension 0 */
596 if (pointer_len)
597 *dimension = "0";
598
599 /* one index is the string length */
600 if (atoi(*length) < 0)
601 {
602 *length = *dimension;
603 *dimension = "-1";
604 }
605
606 break;
607 case ECPGt_char:
609 case ECPGt_string:
610 /* char ** */
611 if (pointer_len == 2)
612 {
613 *length = *dimension = "0";
614 break;
615 }
616
617 /* pointer has to get length 0 */
618 if (pointer_len == 1)
619 *length = "0";
620
621 /* one index is the string length */
622 if (atoi(*length) < 0)
623 {
624 /*
625 * make sure we return length = -1 for arrays without given
626 * bounds
627 */
628 if (atoi(*dimension) < 0 && !type_definition)
629
630 /*
631 * do not change this for typedefs since it will be
632 * changed later on when the variable is defined
633 */
634 *length = "1";
635 else if (strcmp(*dimension, "0") == 0)
636 *length = "-1";
637 else
638 *length = *dimension;
639
640 *dimension = "-1";
641 }
642 break;
643 default:
644 /* a pointer has dimension = 0 */
645 if (pointer_len)
646 {
647 *length = *dimension;
648 *dimension = "0";
649 }
650
651 if (atoi(*length) >= 0)
652 mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
653
654 break;
655 }
656}
#define ngettext(s, p, n)
Definition: c.h:1138
@ 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 490 of file variable.c.

491{
492 /* make sure this is a valid indicator variable */
493 switch (var->type)
494 {
495 struct ECPGstruct_member *p;
496
497 case ECPGt_short:
498 case ECPGt_int:
499 case ECPGt_long:
500 case ECPGt_long_long:
505 break;
506
507 case ECPGt_struct:
508 case ECPGt_union:
509 for (p = var->u.members; p; p = p->next)
511 break;
512
513 case ECPGt_array:
515 break;
516 default:
517 mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type");
518 break;
519 }
520}
@ 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:490
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::@166 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:220

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

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

◆ dump_variables()

void dump_variables ( struct arguments list,
int  mode 
)

Definition at line 461 of file variable.c.

462{
463 char *str_zero;
464
465 if (list == NULL)
466 return;
467
468 str_zero = mm_strdup("0");
469
470 /*
471 * The list is build up from the beginning so lets first dump the end of
472 * the list:
473 */
474
475 dump_variables(list->next, mode);
476
477 /* Then the current element and its indicator */
478 ECPGdump_a_type(base_yyout, list->variable->name, list->variable->type, list->variable->brace_level,
479 list->indicator->name, list->indicator->type, list->indicator->brace_level,
480 NULL, NULL, str_zero, NULL, NULL);
481
482 /* Then release the list element. */
483 if (mode != 0)
484 free(list);
485
486 free(str_zero);
487}
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:461
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:218

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 */
67 {
68 cur_token = lookahead_token;
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
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 */
207 " UESCAPE ",
208 escstr);
209 base_yylloc = loc_strdup(base_yylval.str);
210
211 /* Clear have_lookahead, thereby consuming all three tokens */
212 have_lookahead = false;
213 }
214
215 if (cur_token == UIDENT)
216 cur_token = IDENT;
217 else if (cur_token == USCONST)
218 cur_token = SCONST;
219 break;
220 }
221
222 return cur_token;
223}
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:239
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:282
YYSTYPE base_yylval
const char * YYLTYPE
char * make3_str(const char *str1, const char *str2, const char *str3)
Definition: util.c:256
char * base_yytext
char * loc_strdup(const char *string)
Definition: util.c:170
int YYSTYPE
Definition: psqlscanslash.l:39

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

◆ 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
struct variable * new_variable(const char *name, struct ECPGtype *type, int brace_level)
Definition: variable.c:10
static struct variable * find_struct(const char *name, char *next, char *end)
Definition: variable.c:126
static struct variable * find_simple(const char *name)
Definition: variable.c:177
char * c
enum ECPGttype type
int brace_level
Definition: type.h:193
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, const char *size, int counter)
Definition: type.c:72
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, const char *size)
Definition: type.c:87
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, const char *type_name, const char *struct_sizeof)
Definition: type.c:97

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

673{
674 switch (type)
675 {
676 case ECPGd_count:
677 return "ECPGd_count";
678 break;
679 case ECPGd_data:
680 return "ECPGd_data";
681 break;
682 case ECPGd_di_code:
683 return "ECPGd_di_code";
684 break;
686 return "ECPGd_di_precision";
687 break;
688 case ECPGd_indicator:
689 return "ECPGd_indicator";
690 break;
691 case ECPGd_key_member:
692 return "ECPGd_key_member";
693 break;
694 case ECPGd_length:
695 return "ECPGd_length";
696 break;
697 case ECPGd_name:
698 return "ECPGd_name";
699 break;
700 case ECPGd_nullable:
701 return "ECPGd_nullable";
702 break;
703 case ECPGd_octet:
704 return "ECPGd_octet";
705 break;
706 case ECPGd_precision:
707 return "ECPGd_precision";
708 break;
709 case ECPGd_ret_length:
710 return "ECPGd_ret_length";
711 case ECPGd_ret_octet:
712 return "ECPGd_ret_octet";
713 break;
714 case ECPGd_scale:
715 return "ECPGd_scale";
716 break;
717 case ECPGd_type:
718 return "ECPGd_type";
719 break;
721 return "ECPGd_cardinality";
722 default:
723 mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
724 }
725
726 return NULL;
727}
@ 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 523 of file variable.c.

524{
525 struct typedefs *this;
526
527 for (this = types; this != NULL; this = this->next)
528 {
529 if (strcmp(this->name, name) == 0)
530 return this;
531 }
532
533 if (!noerror)
534 mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
535
536 return NULL;
537}
struct typedefs * types
Definition: ecpg.c:30
Definition: type.h:159

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 */
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
void * loc_alloc(size_t size)
Definition: util.c:138
int base_yylineno
char * input_filename

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

Referenced by output_line_number().

◆ lex_init()

void lex_init ( void  )

Definition at line 1616 of file pgc.l.

1617{
1618 braces_open = 0;
1619 parenths_open = 0;
1620 current_function = NULL;
1621
1622 yylineno = 1;
1623
1624 /* initialize state for if/else/endif */
1625 preproc_tos = 0;
1629
1630 /* initialize literal buffer to a reasonable but expansible size */
1631 if (literalbuf == NULL)
1632 {
1633 literalalloc = 1024;
1634 literalbuf = (char *) mm_alloc(literalalloc);
1635 }
1636 startlit();
1637
1638 BEGIN(C);
1639}
static int parenths_open
Definition: pgc.l:52
static short preproc_tos
Definition: pgc.l:103
static struct _if_value stacked_if_value[MAX_NESTED_IF]
#define startlit()
Definition: pgc.l:57
static char * literalbuf
Definition: pgc.l:47
static int literalalloc
Definition: pgc.l:49
int braces_open
char * current_function
bool active
Definition: pgc.l:107
bool else_branch
Definition: pgc.l:109
bool saw_active
Definition: pgc.l:108

References _if_value::active, braces_open, current_function, _if_value::else_branch, literalalloc, literalbuf, mm_alloc(), parenths_open, preproc_tos, _if_value::saw_active, stacked_if_value, and startlit.

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:768
#define Max(x, y)
Definition: c.h:955
#define LOC_CHUNK_OVERHEAD
Definition: util.c:126
static loc_chunk * loc_chunks
Definition: util.c:130
void * mm_alloc(size_t size)
Definition: util.c:85
#define LOC_CHUNK_MIN_SIZE
Definition: util.c:127
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(), make3_str(), and sqlda_variable().

◆ 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(), filtered_base_yylex(), process_integer_literal(), and sqlda_variable().

◆ 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().

Referenced by filtered_base_yylex().

◆ 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(), isdefine(), isinformixdefine(), lex_init(), loc_alloc(), main(), new_variable(), parse_include(), and push_assignment().

◆ mm_strdup()

char * mm_strdup ( const char *  string)

◆ 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:191
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 179 of file output.c.

180{
181 const char *con = connection ? connection : "NULL";
182
183 if (strcmp(name, "all") != 0)
184 {
185 fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
187 fputs(");", base_yyout);
188 }
189 else
190 fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
191
193}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
enum COMPAT_MODE compat
Definition: ecpg.c:26
void whenever_action(int mode)
Definition: output.c:64
static void output_escaped_str(const char *str, bool quoted)
Definition: output.c:196
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:672
struct variable * find_variable(const char *name)
Definition: variable.c:193
char * variable
Definition: type.h:213
enum ECPGdtype value
Definition: type.h:214
struct assignment * next
Definition: type.h:215
Definition: type.h:96

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)
165 else
166 mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
167 }
168
170 fprintf(base_yyout, "));\n");
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(), parse_include(), and whenever_action().

◆ output_prepare_statement()

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

Definition at line 168 of file output.c.

169{
170 fprintf(base_yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
172 fputs(", ", base_yyout);
174 fputs(");", base_yyout);
176}
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 {
281 case ECPGd_di_code:
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)
217 else
218 mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
219 }
220
222 fprintf(base_yyout, "));\n");
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{
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 argsinsert = NULL;
159 fputs("ECPGt_EOIT, ", base_yyout);
161 argsresult = NULL;
162 fputs("ECPGt_EORT);", base_yyout);
163
164 whenever_action(whenever_mode | 2);
165}
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:461
struct arguments * argsresult
Definition: variable.c:375
struct arguments * argsinsert
Definition: variable.c:374

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, 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 @162 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 *next;
269
270 for (p = types, prev = NULL; p; p = next)
271 {
272 next = p->next;
273 if (p->brace_level >= brace_level)
274 {
275 /* remove it */
276 if (prev)
277 prev->next = next;
278 else
279 types = next;
280
284 free(p->type->type_str);
286 free(p->type->type_index);
287 free(p->type->type_sizeof);
288 free(p->type);
289 free(p->name);
290 free(p);
291 }
292 else
293 prev = p;
294 }
295}
char * type_index
Definition: type.h:127
char * type_dimension
Definition: type.h:126
char * type_sizeof
Definition: type.h:128
char * type_str
Definition: type.h:125
char * type_storage
Definition: type.h:123
enum ECPGttype type_enum
Definition: type.h:124
int brace_level
Definition: type.h:163
char * name
Definition: type.h:160
struct ECPGstruct_member * struct_member_list
Definition: type.h:162
struct typedefs * next
Definition: type.h:164
struct this_type * type
Definition: type.h:161
void ECPGfree_struct_member(struct ECPGstruct_member *rm)
Definition: type.c:618

References typedefs::brace_level, ECPGfree_struct_member(), ECPGt_struct, ECPGt_union, free, typedefs::name, next, typedefs::next, typedefs::struct_member_list, typedefs::type, this_type::type_dimension, this_type::type_enum, this_type::type_index, this_type::type_sizeof, this_type::type_storage, this_type::type_str, and types.

◆ remove_variable_from_list()

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

Definition at line 431 of file variable.c.

432{
433 struct arguments *p,
434 *prev = NULL;
435 bool found = false;
436
437 for (p = *list; p; p = p->next)
438 {
439 if (p->variable == var)
440 {
441 found = true;
442 break;
443 }
444 prev = p;
445 }
446 if (found)
447 {
448 if (prev)
449 prev->next = p->next;
450 else
451 *list = p->next;
452 free(p);
453 }
454}

References free, 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 *next;
303
304 for (p = allvariables, prev = NULL; p; p = next)
305 {
306 next = p->next;
307 if (p->brace_level >= brace_level)
308 {
309 /* remove it, but first remove any references from cursors */
310 struct cursor *ptr;
311
312 for (ptr = cur; ptr != NULL; ptr = ptr->next)
313 {
314 struct arguments *varptr,
315 *prevvar,
316 *nextvar;
317
318 for (varptr = ptr->argsinsert, prevvar = NULL;
319 varptr != NULL; varptr = nextvar)
320 {
321 nextvar = varptr->next;
322 if (p == varptr->variable)
323 {
324 /* remove from list */
325 if (prevvar)
326 prevvar->next = nextvar;
327 else
328 ptr->argsinsert = nextvar;
329 free(varptr);
330 }
331 else
332 prevvar = varptr;
333 }
334 for (varptr = ptr->argsresult, prevvar = NULL;
335 varptr != NULL; varptr = nextvar)
336 {
337 nextvar = varptr->next;
338 if (p == varptr->variable)
339 {
340 /* remove from list */
341 if (prevvar)
342 prevvar->next = nextvar;
343 else
344 ptr->argsresult = nextvar;
345 free(varptr);
346 }
347 else
348 prevvar = varptr;
349 }
350 }
351
352 /* remove it */
353 if (prev)
354 prev->next = next;
355 else
357
359 free(p->name);
360 free(p);
361 }
362 else
363 prev = p;
364 }
365}
struct cursor * cur
Definition: ecpg.c:29
Definition: type.h:138
struct arguments * argsinsert
Definition: type.h:144
struct cursor * next
Definition: type.h:148
struct arguments * argsresult
Definition: type.h:146
void ECPGfree_type(struct ECPGtype *type)
Definition: type.c:632

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

◆ reset_variables()

void reset_variables ( void  )

Definition at line 378 of file variable.c.

379{
380 struct arguments *p,
381 *next;
382
383 for (p = argsinsert; p; p = next)
384 {
385 next = p->next;
386 free(p);
387 }
388 argsinsert = NULL;
389 for (p = argsresult; p; p = next)
390 {
391 next = p->next;
392 free(p);
393 }
394 argsresult = NULL;
395}
struct arguments * argsresult
Definition: variable.c:375
struct arguments * argsinsert
Definition: variable.c:374

References argsinsert, argsresult, free, next, and arguments::next.

◆ 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:644

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 /*
348 * Presently, sqlda variables are only needed for the duration of the
349 * current statement. Rather than add infrastructure to manage them,
350 * let's just loc_alloc them.
351 */
352 struct variable *p = (struct variable *) loc_alloc(sizeof(struct variable));
353
354 p->name = loc_strdup(name);
355 p->type = (struct ECPGtype *) loc_alloc(sizeof(struct ECPGtype));
356 p->type->type = ECPGt_sqlda;
357 p->type->type_name = NULL;
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, loc_alloc(), loc_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 }
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:90
@ W_NOTHING
Definition: type.h:79

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

Referenced by output_statement(), and reset_variables().

◆ argsresult

struct arguments* argsresult
extern

Definition at line 375 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

Referenced by lex_init().

◆ compat

◆ connection

◆ cur

◆ current_function

char* current_function
extern

Referenced by lex_init().

◆ defines

struct _defines* defines
extern

Definition at line 31 of file ecpg.c.

Referenced by add_preprocessor_define(), isdefine(), 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 32 of file ecpg.c.

Referenced by main().

◆ include_paths

struct _include_path* include_paths
extern

Definition at line 28 of file ecpg.c.

Referenced by add_include_path(), main(), and parse_include().

◆ 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 32 of file output.c.

Referenced by main(), and whenever_action().