| 1 |
/* src/interfaces/ecpg/preproc/ecpg.trailer */ |
| 2 |
|
| 3 |
statements: /* EMPTY */ |
| 4 |
| statements statement |
| 5 |
{ |
| 6 |
/* Reclaim local storage used while processing statement */ |
| 7 |
reclaim_local_storage(); |
| 8 |
/* Clean up now-dangling location pointer */ |
| 9 |
@$ = ""; |
| 10 |
} |
| 11 |
; |
| 12 |
|
| 13 |
statement: ecpgstart at toplevel_stmt ';' |
| 14 |
{ |
| 15 |
if (connection) |
| 16 |
free(connection); |
| 17 |
connection = NULL; |
| 18 |
} |
| 19 |
| ecpgstart toplevel_stmt ';' |
| 20 |
{ |
| 21 |
if (connection) |
| 22 |
free(connection); |
| 23 |
connection = NULL; |
| 24 |
} |
| 25 |
| ecpgstart ECPGVarDeclaration |
| 26 |
{ |
| 27 |
fprintf(base_yyout, "%s", @$); |
| 28 |
output_line_number(); |
| 29 |
} |
| 30 |
| ECPGDeclaration |
| 31 |
| c_thing |
| 32 |
{ |
| 33 |
fprintf(base_yyout, "%s", @$); |
| 34 |
} |
| 35 |
| CPP_LINE |
| 36 |
{ |
| 37 |
fprintf(base_yyout, "%s", @$); |
| 38 |
} |
| 39 |
| '{' |
| 40 |
{ |
| 41 |
braces_open++; |
| 42 |
fputs("{", base_yyout); |
| 43 |
} |
| 44 |
| '}' |
| 45 |
{ |
| 46 |
if (braces_open > 0) |
| 47 |
{ |
| 48 |
remove_typedefs(braces_open); |
| 49 |
remove_variables(braces_open); |
| 50 |
if (--braces_open == 0) |
| 51 |
{ |
| 52 |
free(current_function); |
| 53 |
current_function = NULL; |
| 54 |
} |
| 55 |
} |
| 56 |
fputs("}", base_yyout); |
| 57 |
} |
| 58 |
; |
| 59 |
|
| 60 |
CreateAsStmt: CREATE OptTemp TABLE create_as_target AS |
| 61 |
{ |
| 62 |
FoundInto = 0; |
| 63 |
} SelectStmt opt_with_data |
| 64 |
{ |
| 65 |
if (FoundInto == 1) |
| 66 |
mmerror(PARSE_ERROR, ET_ERROR, "CREATE TABLE AS cannot specify INTO"); |
| 67 |
} |
| 68 |
| CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS |
| 69 |
{ |
| 70 |
FoundInto = 0; |
| 71 |
} SelectStmt opt_with_data |
| 72 |
{ |
| 73 |
if (FoundInto == 1) |
| 74 |
mmerror(PARSE_ERROR, ET_ERROR, "CREATE TABLE AS cannot specify INTO"); |
| 75 |
} |
| 76 |
; |
| 77 |
|
| 78 |
at: AT connection_object |
| 79 |
{ |
| 80 |
if (connection) |
| 81 |
free(connection); |
| 82 |
connection = mm_strdup(@2); |
| 83 |
|
| 84 |
/* |
| 85 |
* Do we have a variable as connection target? Remove the variable |
| 86 |
* from the variable list or else it will be used twice. |
| 87 |
*/ |
| 88 |
if (argsinsert != NULL) |
| 89 |
argsinsert = NULL; |
| 90 |
} |
| 91 |
; |
| 92 |
|
| 93 |
/* |
| 94 |
* the exec sql connect statement: connect to the given database |
| 95 |
*/ |
| 96 |
ECPGConnect: SQL_CONNECT TO connection_target opt_connection_name opt_user |
| 97 |
{ |
| 98 |
@$ = cat_str(5, @3, ",", @5, ",", @4); |
| 99 |
} |
| 100 |
| SQL_CONNECT TO DEFAULT |
| 101 |
{ |
| 102 |
@$ = "NULL, NULL, NULL, \"DEFAULT\""; |
| 103 |
} |
| 104 |
/* also allow ORACLE syntax */ |
| 105 |
| SQL_CONNECT ora_user |
| 106 |
{ |
| 107 |
@$ = cat_str(3, "NULL,", @2, ", NULL"); |
| 108 |
} |
| 109 |
| DATABASE connection_target |
| 110 |
{ |
| 111 |
@$ = cat2_str(@2, ", NULL, NULL, NULL"); |
| 112 |
} |
| 113 |
; |
| 114 |
|
| 115 |
connection_target: opt_database_name opt_server opt_port |
| 116 |
{ |
| 117 |
/* old style: dbname[@server][:port] */ |
| 118 |
if (strlen(@2) > 0 && *(@2) != '@') |
| 119 |
mmerror(PARSE_ERROR, ET_ERROR, "expected \"@\", found \"%s\"", @2); |
| 120 |
|
| 121 |
/* C strings need to be handled differently */ |
| 122 |
if (@1[0] == '\"') |
| 123 |
@$ = @1; |
| 124 |
else |
| 125 |
@$ = make3_str("\"", make3_str(@1, @2, @3), "\""); |
| 126 |
} |
| 127 |
| db_prefix ':' server opt_port '/' opt_database_name opt_options |
| 128 |
{ |
| 129 |
/* new style: <tcp|unix>:postgresql://server[:port][/dbname] */ |
| 130 |
if (strncmp(@1, "unix:postgresql", strlen("unix:postgresql")) != 0 && strncmp(@1, "tcp:postgresql", strlen("tcp:postgresql")) != 0) |
| 131 |
mmerror(PARSE_ERROR, ET_ERROR, "only protocols \"tcp\" and \"unix\" and database type \"postgresql\" are supported"); |
| 132 |
|
| 133 |
if (strncmp(@3, "//", strlen("//")) != 0) |
| 134 |
mmerror(PARSE_ERROR, ET_ERROR, "expected \"://\", found \"%s\"", @3); |
| 135 |
|
| 136 |
if (strncmp(@1, "unix", strlen("unix")) == 0 && |
| 137 |
strncmp(@3 + strlen("//"), "localhost", strlen("localhost")) != 0 && |
| 138 |
strncmp(@3 + strlen("//"), "127.0.0.1", strlen("127.0.0.1")) != 0) |
| 139 |
mmerror(PARSE_ERROR, ET_ERROR, "Unix-domain sockets only work on \"localhost\" but not on \"%s\"", @3 + strlen("//")); |
| 140 |
|
| 141 |
@$ = make3_str(make3_str("\"", @1, ":"), @3, make3_str(make3_str(@4, "/", @6), @7, "\"")); |
| 142 |
} |
| 143 |
| char_variable |
| 144 |
| ecpg_sconst |
| 145 |
{ |
| 146 |
/* |
| 147 |
* We can only process double quoted strings not single quoted ones, |
| 148 |
* so we change the quotes. Note that the rule for ecpg_sconst adds |
| 149 |
* these single quotes. |
| 150 |
*/ |
| 151 |
char *str = loc_strdup(@1); |
| 152 |
|
| 153 |
str[0] = '\"'; |
| 154 |
str[strlen(str) - 1] = '\"'; |
| 155 |
@$ = str; |
| 156 |
} |
| 157 |
; |
| 158 |
|
| 159 |
opt_database_name: name |
| 160 |
| /* EMPTY */ |
| 161 |
; |
| 162 |
|
| 163 |
db_prefix: ecpg_ident cvariable |
| 164 |
{ |
| 165 |
if (strcmp(@2, "postgresql") != 0 && strcmp(@2, "postgres") != 0) |
| 166 |
mmerror(PARSE_ERROR, ET_ERROR, "expected \"postgresql\", found \"%s\"", @2); |
| 167 |
|
| 168 |
if (strcmp(@1, "tcp") != 0 && strcmp(@1, "unix") != 0) |
| 169 |
mmerror(PARSE_ERROR, ET_ERROR, "invalid connection type: %s", @1); |
| 170 |
|
| 171 |
@$ = make3_str(@1, ":", @2); |
| 172 |
} |
| 173 |
; |
| 174 |
|
| 175 |
server: Op server_name |
| 176 |
{ |
| 177 |
if (strcmp(@1, "@") != 0 && strcmp(@1, "//") != 0) |
| 178 |
mmerror(PARSE_ERROR, ET_ERROR, "expected \"@\" or \"://\", found \"%s\"", @1); |
| 179 |
|
| 180 |
@$ = make2_str(@1, @2); |
| 181 |
} |
| 182 |
; |
| 183 |
|
| 184 |
opt_server: server |
| 185 |
| /* EMPTY */ |
| 186 |
; |
| 187 |
|
| 188 |
server_name: ColId |
| 189 |
| ColId '.' server_name |
| 190 |
| IP |
| 191 |
; |
| 192 |
|
| 193 |
opt_port: ':' Iconst |
| 194 |
{ |
| 195 |
@$ = make2_str(":", @2); |
| 196 |
} |
| 197 |
| /* EMPTY */ |
| 198 |
; |
| 199 |
|
| 200 |
opt_connection_name: AS connection_object |
| 201 |
{ |
| 202 |
@$ = @2; |
| 203 |
} |
| 204 |
| /* EMPTY */ |
| 205 |
{ |
| 206 |
@$ = "NULL"; |
| 207 |
} |
| 208 |
; |
| 209 |
|
| 210 |
opt_user: USER ora_user |
| 211 |
{ |
| 212 |
@$ = @2; |
| 213 |
} |
| 214 |
| /* EMPTY */ |
| 215 |
{ |
| 216 |
@$ = "NULL, NULL"; |
| 217 |
} |
| 218 |
; |
| 219 |
|
| 220 |
ora_user: user_name |
| 221 |
{ |
| 222 |
@$ = cat2_str(@1, ", NULL"); |
| 223 |
} |
| 224 |
| user_name '/' user_name |
| 225 |
{ |
| 226 |
@$ = cat_str(3, @1, ",", @3); |
| 227 |
} |
| 228 |
| user_name SQL_IDENTIFIED BY user_name |
| 229 |
{ |
| 230 |
@$ = cat_str(3, @1, ",", @4); |
| 231 |
} |
| 232 |
| user_name USING user_name |
| 233 |
{ |
| 234 |
@$ = cat_str(3, @1, ",", @3); |
| 235 |
} |
| 236 |
; |
| 237 |
|
| 238 |
user_name: RoleId |
| 239 |
{ |
| 240 |
if (@1[0] == '\"') |
| 241 |
@$ = @1; |
| 242 |
else |
| 243 |
@$ = make3_str("\"", @1, "\""); |
| 244 |
} |
| 245 |
| ecpg_sconst |
| 246 |
{ |
| 247 |
if (@1[0] == '\"') |
| 248 |
@$ = @1; |
| 249 |
else |
| 250 |
@$ = make3_str("\"", @1, "\""); |
| 251 |
} |
| 252 |
| civar |
| 253 |
{ |
| 254 |
enum ECPGttype type = argsinsert->variable->type->type; |
| 255 |
|
| 256 |
/* if array see what's inside */ |
| 257 |
if (type == ECPGt_array) |
| 258 |
type = argsinsert->variable->type->u.element->type; |
| 259 |
|
| 260 |
/* handle varchars */ |
| 261 |
if (type == ECPGt_varchar) |
| 262 |
@$ = make2_str(argsinsert->variable->name, ".arr"); |
| 263 |
else |
| 264 |
@$ = argsinsert->variable->name; |
| 265 |
} |
| 266 |
; |
| 267 |
|
| 268 |
char_variable: cvariable |
| 269 |
{ |
| 270 |
/* check if we have a string variable */ |
| 271 |
struct variable *p = find_variable(@1); |
| 272 |
enum ECPGttype type = p->type->type; |
| 273 |
|
| 274 |
/* If we have just one character this is not a string */ |
| 275 |
if (atol(p->type->size) == 1) |
| 276 |
mmerror(PARSE_ERROR, ET_ERROR, "invalid data type"); |
| 277 |
else |
| 278 |
{ |
| 279 |
/* if array see what's inside */ |
| 280 |
if (type == ECPGt_array) |
| 281 |
type = p->type->u.element->type; |
| 282 |
|
| 283 |
switch (type) |
| 284 |
{ |
| 285 |
case ECPGt_char: |
| 286 |
case ECPGt_unsigned_char: |
| 287 |
case ECPGt_string: |
| 288 |
@$ = @1; |
| 289 |
break; |
| 290 |
case ECPGt_varchar: |
| 291 |
@$ = make2_str(@1, ".arr"); |
| 292 |
break; |
| 293 |
default: |
| 294 |
mmerror(PARSE_ERROR, ET_ERROR, "invalid data type"); |
| 295 |
@$ = @1; |
| 296 |
break; |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
; |
| 301 |
|
| 302 |
opt_options: Op connect_options |
| 303 |
{ |
| 304 |
if (strlen(@1) == 0) |
| 305 |
mmerror(PARSE_ERROR, ET_ERROR, "incomplete statement"); |
| 306 |
|
| 307 |
if (strcmp(@1, "?") != 0) |
| 308 |
mmerror(PARSE_ERROR, ET_ERROR, "unrecognized token \"%s\"", @1); |
| 309 |
|
| 310 |
@$ = make2_str("?", @2); |
| 311 |
} |
| 312 |
| /* EMPTY */ |
| 313 |
; |
| 314 |
|
| 315 |
connect_options: ColId opt_opt_value |
| 316 |
{ |
| 317 |
@$ = make2_str(@1, @2); |
| 318 |
} |
| 319 |
| ColId opt_opt_value Op connect_options |
| 320 |
{ |
| 321 |
if (strlen(@3) == 0) |
| 322 |
mmerror(PARSE_ERROR, ET_ERROR, "incomplete statement"); |
| 323 |
|
| 324 |
if (strcmp(@3, "&") != 0) |
| 325 |
mmerror(PARSE_ERROR, ET_ERROR, "unrecognized token \"%s\"", @3); |
| 326 |
|
| 327 |
@$ = make3_str(make2_str(@1, @2), @3, @4); |
| 328 |
} |
| 329 |
; |
| 330 |
|
| 331 |
opt_opt_value: /* EMPTY */ |
| 332 |
| '=' Iconst |
| 333 |
{ |
| 334 |
@$ = make2_str("=", @2); |
| 335 |
} |
| 336 |
| '=' ecpg_ident |
| 337 |
{ |
| 338 |
@$ = make2_str("=", @2); |
| 339 |
} |
| 340 |
| '=' civar |
| 341 |
{ |
| 342 |
@$ = make2_str("=", @2); |
| 343 |
} |
| 344 |
; |
| 345 |
|
| 346 |
prepared_name: name |
| 347 |
{ |
| 348 |
size_t slen = strlen(@1); |
| 349 |
|
| 350 |
if (@1[0] == '\"' && @1[slen - 1] == '\"') /* already quoted? */ |
| 351 |
@$ = @1; |
| 352 |
else /* not quoted => convert to lowercase */ |
| 353 |
{ |
| 354 |
char *str = loc_alloc(slen + 3); |
| 355 |
|
| 356 |
str[0] = '\"'; |
| 357 |
for (size_t i = 0; i < slen; i++) |
| 358 |
str[i + 1] = tolower((unsigned char) @1[i]); |
| 359 |
str[slen + 1] = '\"'; |
| 360 |
str[slen + 2] = '\0'; |
| 361 |
@$ = str; |
| 362 |
} |
| 363 |
} |
| 364 |
| char_variable |
| 365 |
; |
| 366 |
|
| 367 |
/* |
| 368 |
* Declare Statement |
| 369 |
*/ |
| 370 |
ECPGDeclareStmt: DECLARE prepared_name STATEMENT |
| 371 |
{ |
| 372 |
struct declared_list *ptr; |
| 373 |
|
| 374 |
/* Check whether the declared name has been defined or not */ |
| 375 |
for (ptr = g_declared_list; ptr != NULL; ptr = ptr->next) |
| 376 |
{ |
| 377 |
if (strcmp(@2, ptr->name) == 0) |
| 378 |
{ |
| 379 |
/* re-definition is not allowed */ |
| 380 |
mmerror(PARSE_ERROR, ET_ERROR, "name \"%s\" is already declared", ptr->name); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/* Add a new declared name into the g_declared_list */ |
| 385 |
ptr = (struct declared_list *) mm_alloc(sizeof(struct declared_list)); |
| 386 |
if (ptr) |
| 387 |
{ |
| 388 |
/* initial definition */ |
| 389 |
ptr->name = mm_strdup(@2); |
| 390 |
if (connection) |
| 391 |
ptr->connection = mm_strdup(connection); |
| 392 |
else |
| 393 |
ptr->connection = NULL; |
| 394 |
|
| 395 |
ptr->next = g_declared_list; |
| 396 |
g_declared_list = ptr; |
| 397 |
} |
| 398 |
|
| 399 |
@$ = cat_str(3, "/* declare ", @2, " as an SQL identifier */"); |
| 400 |
} |
| 401 |
; |
| 402 |
|
| 403 |
/* |
| 404 |
* Declare a prepared cursor. The syntax is different from the standard |
| 405 |
* declare statement, so we create a new rule. |
| 406 |
*/ |
| 407 |
ECPGCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared_name |
| 408 |
{ |
| 409 |
struct cursor *ptr, |
| 410 |
*this; |
| 411 |
const char *cursor_marker = @2[0] == ':' ? "$0" : @2; |
| 412 |
int (*strcmp_fn) (const char *, const char *) = ((@2[0] == ':' || @2[0] == '"') ? strcmp : pg_strcasecmp); |
| 413 |
struct variable *thisquery = (struct variable *) mm_alloc(sizeof(struct variable)); |
| 414 |
char *comment; |
| 415 |
char *con; |
| 416 |
|
| 417 |
if (INFORMIX_MODE && pg_strcasecmp(@2, "database") == 0) |
| 418 |
mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode"); |
| 419 |
|
| 420 |
check_declared_list(@7); |
| 421 |
con = connection ? connection : "NULL"; |
| 422 |
for (ptr = cur; ptr != NULL; ptr = ptr->next) |
| 423 |
{ |
| 424 |
if (strcmp_fn(@2, ptr->name) == 0) |
| 425 |
{ |
| 426 |
/* re-definition is a bug */ |
| 427 |
if (@2[0] == ':') |
| 428 |
mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", @2 + 1); |
| 429 |
else |
| 430 |
mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", @2); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
this = (struct cursor *) mm_alloc(sizeof(struct cursor)); |
| 435 |
|
| 436 |
/* initial definition */ |
| 437 |
this->next = cur; |
| 438 |
this->name = mm_strdup(@2); |
| 439 |
this->function = (current_function ? mm_strdup(current_function) : NULL); |
| 440 |
this->connection = connection ? mm_strdup(connection) : NULL; |
| 441 |
this->opened = false; |
| 442 |
this->command = mm_strdup(cat_str(6, "declare", cursor_marker, @3, "cursor", @5, "for $1")); |
| 443 |
this->argsresult = NULL; |
| 444 |
this->argsresult_oos = NULL; |
| 445 |
|
| 446 |
thisquery->type = &ecpg_query; |
| 447 |
thisquery->brace_level = 0; |
| 448 |
thisquery->next = NULL; |
| 449 |
thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(, , __LINE__)") + strlen(con) + strlen(@7)); |
| 450 |
sprintf(thisquery->name, "ECPGprepared_statement(%s, %s, __LINE__)", con, @7); |
| 451 |
|
| 452 |
this->argsinsert = NULL; |
| 453 |
this->argsinsert_oos = NULL; |
| 454 |
if (@2[0] == ':') |
| 455 |
{ |
| 456 |
struct variable *var = find_variable(@2 + 1); |
| 457 |
|
| 458 |
remove_variable_from_list(&argsinsert, var); |
| 459 |
add_variable_to_head(&(this->argsinsert), var, &no_indicator); |
| 460 |
} |
| 461 |
add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator); |
| 462 |
|
| 463 |
cur = this; |
| 464 |
|
| 465 |
comment = cat_str(3, "/*", this->command, "*/"); |
| 466 |
|
| 467 |
@$ = cat_str(2, adjust_outofscope_cursor_vars(this), |
| 468 |
comment); |
| 469 |
} |
| 470 |
; |
| 471 |
|
| 472 |
ECPGExecuteImmediateStmt: EXECUTE IMMEDIATE execstring |
| 473 |
{ |
| 474 |
/* |
| 475 |
* execute immediate means prepare the statement and immediately |
| 476 |
* execute it |
| 477 |
*/ |
| 478 |
@$ = @3; |
| 479 |
} |
| 480 |
; |
| 481 |
|
| 482 |
/* |
| 483 |
* variable declaration outside exec sql declare block |
| 484 |
*/ |
| 485 |
ECPGVarDeclaration: single_vt_declaration; |
| 486 |
|
| 487 |
single_vt_declaration: type_declaration |
| 488 |
| var_declaration |
| 489 |
; |
| 490 |
|
| 491 |
precision: NumericOnly |
| 492 |
; |
| 493 |
|
| 494 |
opt_scale: ',' NumericOnly |
| 495 |
{ |
| 496 |
@$ = @2; |
| 497 |
} |
| 498 |
| /* EMPTY */ |
| 499 |
; |
| 500 |
|
| 501 |
ecpg_interval: opt_interval |
| 502 |
| YEAR_P TO MINUTE_P |
| 503 |
| YEAR_P TO SECOND_P |
| 504 |
| DAY_P TO DAY_P |
| 505 |
| MONTH_P TO MONTH_P |
| 506 |
; |
| 507 |
|
| 508 |
/* |
| 509 |
* variable declaration inside exec sql declare block |
| 510 |
*/ |
| 511 |
ECPGDeclaration: sql_startdeclare |
| 512 |
{ |
| 513 |
fputs("/* exec sql begin declare section */", base_yyout); |
| 514 |
} |
| 515 |
var_type_declarations sql_enddeclare |
| 516 |
{ |
| 517 |
fprintf(base_yyout, "%s/* exec sql end declare section */", @3); |
| 518 |
output_line_number(); |
| 519 |
} |
| 520 |
; |
| 521 |
|
| 522 |
sql_startdeclare: ecpgstart BEGIN_P DECLARE SQL_SECTION ';' |
| 523 |
{ |
| 524 |
} |
| 525 |
; |
| 526 |
|
| 527 |
sql_enddeclare: ecpgstart END_P DECLARE SQL_SECTION ';' |
| 528 |
{ |
| 529 |
} |
| 530 |
; |
| 531 |
|
| 532 |
var_type_declarations: /* EMPTY */ |
| 533 |
| vt_declarations |
| 534 |
; |
| 535 |
|
| 536 |
vt_declarations: single_vt_declaration |
| 537 |
| CPP_LINE |
| 538 |
| vt_declarations single_vt_declaration |
| 539 |
| vt_declarations CPP_LINE |
| 540 |
; |
| 541 |
|
| 542 |
variable_declarations: var_declaration |
| 543 |
| variable_declarations var_declaration |
| 544 |
; |
| 545 |
|
| 546 |
type_declaration: S_TYPEDEF |
| 547 |
{ |
| 548 |
/* reset this variable so we see if there was */ |
| 549 |
/* an initializer specified */ |
| 550 |
initializer = 0; |
| 551 |
} |
| 552 |
var_type opt_pointer ECPGColLabel opt_array_bounds ';' |
| 553 |
{ |
| 554 |
add_typedef(@5, $6.index1, $6.index2, $3.type_enum, $3.type_dimension, $3.type_index, initializer, *@4 ? 1 : 0); |
| 555 |
|
| 556 |
fprintf(base_yyout, "typedef %s %s %s %s;\n", $3.type_str, *@4 ? "*" : "", @5, $6.str); |
| 557 |
output_line_number(); |
| 558 |
@$ = ""; |
| 559 |
} |
| 560 |
; |
| 561 |
|
| 562 |
var_declaration: |
| 563 |
storage_declaration var_type |
| 564 |
{ |
| 565 |
actual_type[struct_level].type_storage = loc_strdup(@1); |
| 566 |
actual_type[struct_level].type_enum = $2.type_enum; |
| 567 |
actual_type[struct_level].type_str = $2.type_str; |
| 568 |
actual_type[struct_level].type_dimension = $2.type_dimension; |
| 569 |
actual_type[struct_level].type_index = $2.type_index; |
| 570 |
actual_type[struct_level].type_sizeof = $2.type_sizeof; |
| 571 |
|
| 572 |
actual_startline[struct_level] = hashline_number(); |
| 573 |
} |
| 574 |
variable_list ';' |
| 575 |
{ |
| 576 |
@$ = cat_str(5, actual_startline[struct_level], @1, $2.type_str, @4, ";\n"); |
| 577 |
} |
| 578 |
| var_type |
| 579 |
{ |
| 580 |
actual_type[struct_level].type_storage = loc_strdup(""); |
| 581 |
actual_type[struct_level].type_enum = $1.type_enum; |
| 582 |
actual_type[struct_level].type_str = $1.type_str; |
| 583 |
actual_type[struct_level].type_dimension = $1.type_dimension; |
| 584 |
actual_type[struct_level].type_index = $1.type_index; |
| 585 |
actual_type[struct_level].type_sizeof = $1.type_sizeof; |
| 586 |
|
| 587 |
actual_startline[struct_level] = hashline_number(); |
| 588 |
} |
| 589 |
variable_list ';' |
| 590 |
{ |
| 591 |
@$ = cat_str(4, actual_startline[struct_level], $1.type_str, @3, ";\n"); |
| 592 |
} |
| 593 |
| struct_union_type_with_symbol ';' |
| 594 |
; |
| 595 |
|
| 596 |
opt_bit_field: ':' Iconst |
| 597 |
| /* EMPTY */ |
| 598 |
; |
| 599 |
|
| 600 |
storage_declaration: storage_clause storage_modifier |
| 601 |
| storage_clause |
| 602 |
| storage_modifier |
| 603 |
; |
| 604 |
|
| 605 |
storage_clause: S_EXTERN |
| 606 |
| S_STATIC |
| 607 |
| S_REGISTER |
| 608 |
| S_AUTO |
| 609 |
; |
| 610 |
|
| 611 |
storage_modifier: S_CONST |
| 612 |
| S_VOLATILE |
| 613 |
; |
| 614 |
|
| 615 |
var_type: simple_type |
| 616 |
{ |
| 617 |
$$.type_enum = $1; |
| 618 |
$$.type_str = loc_strdup(ecpg_type_name($1)); |
| 619 |
$$.type_dimension = "-1"; |
| 620 |
$$.type_index = "-1"; |
| 621 |
$$.type_sizeof = NULL; |
| 622 |
} |
| 623 |
| struct_union_type |
| 624 |
{ |
| 625 |
$$.type_str = loc_strdup(@1); |
| 626 |
$$.type_dimension = "-1"; |
| 627 |
$$.type_index = "-1"; |
| 628 |
|
| 629 |
if (strncmp(@1, "struct", sizeof("struct") - 1) == 0) |
| 630 |
{ |
| 631 |
$$.type_enum = ECPGt_struct; |
| 632 |
$$.type_sizeof = ECPGstruct_sizeof; |
| 633 |
} |
| 634 |
else |
| 635 |
{ |
| 636 |
$$.type_enum = ECPGt_union; |
| 637 |
$$.type_sizeof = NULL; |
| 638 |
} |
| 639 |
} |
| 640 |
| enum_type |
| 641 |
{ |
| 642 |
$$.type_str = loc_strdup(@1); |
| 643 |
$$.type_enum = ECPGt_int; |
| 644 |
$$.type_dimension = "-1"; |
| 645 |
$$.type_index = "-1"; |
| 646 |
$$.type_sizeof = NULL; |
| 647 |
} |
| 648 |
| NUMERIC '(' precision opt_scale ')' |
| 649 |
{ |
| 650 |
$$.type_enum = ECPGt_numeric; |
| 651 |
$$.type_str = "numeric"; |
| 652 |
$$.type_dimension = "-1"; |
| 653 |
$$.type_index = "-1"; |
| 654 |
$$.type_sizeof = NULL; |
| 655 |
} |
| 656 |
| DECIMAL_P '(' precision opt_scale ')' |
| 657 |
{ |
| 658 |
$$.type_enum = ECPGt_decimal; |
| 659 |
$$.type_str = "decimal"; |
| 660 |
$$.type_dimension = "-1"; |
| 661 |
$$.type_index = "-1"; |
| 662 |
$$.type_sizeof = NULL; |
| 663 |
} |
| 664 |
| IDENT '(' precision opt_scale ')' |
| 665 |
{ |
| 666 |
/* |
| 667 |
* In C parsing mode, NUMERIC and DECIMAL are not keywords, so they |
| 668 |
* will show up here as a plain identifier, and we need this duplicate |
| 669 |
* code to recognize them. |
| 670 |
*/ |
| 671 |
if (strcmp(@1, "numeric") == 0) |
| 672 |
{ |
| 673 |
$$.type_enum = ECPGt_numeric; |
| 674 |
$$.type_str = "numeric"; |
| 675 |
} |
| 676 |
else if (strcmp(@1, "decimal") == 0) |
| 677 |
{ |
| 678 |
$$.type_enum = ECPGt_decimal; |
| 679 |
$$.type_str = "decimal"; |
| 680 |
} |
| 681 |
else |
| 682 |
{ |
| 683 |
mmerror(PARSE_ERROR, ET_ERROR, "only data types numeric and decimal have precision/scale argument"); |
| 684 |
$$.type_enum = ECPGt_numeric; |
| 685 |
$$.type_str = "numeric"; |
| 686 |
} |
| 687 |
|
| 688 |
$$.type_dimension = "-1"; |
| 689 |
$$.type_index = "-1"; |
| 690 |
$$.type_sizeof = NULL; |
| 691 |
} |
| 692 |
| VARCHAR |
| 693 |
{ |
| 694 |
$$.type_enum = ECPGt_varchar; |
| 695 |
$$.type_str = ""; /* "varchar"; */ |
| 696 |
$$.type_dimension = "-1"; |
| 697 |
$$.type_index = "-1"; |
| 698 |
$$.type_sizeof = NULL; |
| 699 |
} |
| 700 |
| FLOAT_P |
| 701 |
{ |
| 702 |
/* Note: DOUBLE is handled in simple_type */ |
| 703 |
$$.type_enum = ECPGt_float; |
| 704 |
$$.type_str = "float"; |
| 705 |
$$.type_dimension = "-1"; |
| 706 |
$$.type_index = "-1"; |
| 707 |
$$.type_sizeof = NULL; |
| 708 |
} |
| 709 |
| NUMERIC |
| 710 |
{ |
| 711 |
$$.type_enum = ECPGt_numeric; |
| 712 |
$$.type_str = "numeric"; |
| 713 |
$$.type_dimension = "-1"; |
| 714 |
$$.type_index = "-1"; |
| 715 |
$$.type_sizeof = NULL; |
| 716 |
} |
| 717 |
| DECIMAL_P |
| 718 |
{ |
| 719 |
$$.type_enum = ECPGt_decimal; |
| 720 |
$$.type_str = "decimal"; |
| 721 |
$$.type_dimension = "-1"; |
| 722 |
$$.type_index = "-1"; |
| 723 |
$$.type_sizeof = NULL; |
| 724 |
} |
| 725 |
| TIMESTAMP |
| 726 |
{ |
| 727 |
$$.type_enum = ECPGt_timestamp; |
| 728 |
$$.type_str = "timestamp"; |
| 729 |
$$.type_dimension = "-1"; |
| 730 |
$$.type_index = "-1"; |
| 731 |
$$.type_sizeof = NULL; |
| 732 |
} |
| 733 |
| STRING_P |
| 734 |
{ |
| 735 |
if (INFORMIX_MODE) |
| 736 |
{ |
| 737 |
/* In Informix mode, "string" is automatically a typedef */ |
| 738 |
$$.type_enum = ECPGt_string; |
| 739 |
$$.type_str = "char"; |
| 740 |
$$.type_dimension = "-1"; |
| 741 |
$$.type_index = "-1"; |
| 742 |
$$.type_sizeof = NULL; |
| 743 |
} |
| 744 |
else |
| 745 |
{ |
| 746 |
/* Otherwise, legal only if user typedef'ed it */ |
| 747 |
struct typedefs *this = get_typedef("string", false); |
| 748 |
|
| 749 |
$$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? mm_strdup("") : mm_strdup(this->name); |
| 750 |
$$.type_enum = this->type->type_enum; |
| 751 |
$$.type_dimension = this->type->type_dimension; |
| 752 |
$$.type_index = this->type->type_index; |
| 753 |
if (this->type->type_sizeof && strlen(this->type->type_sizeof) != 0) |
| 754 |
$$.type_sizeof = this->type->type_sizeof; |
| 755 |
else |
| 756 |
$$.type_sizeof = cat_str(3, "sizeof(", this->name, ")"); |
| 757 |
|
| 758 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 759 |
struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list); |
| 760 |
} |
| 761 |
} |
| 762 |
| INTERVAL ecpg_interval |
| 763 |
{ |
| 764 |
$$.type_enum = ECPGt_interval; |
| 765 |
$$.type_str = "interval"; |
| 766 |
$$.type_dimension = "-1"; |
| 767 |
$$.type_index = "-1"; |
| 768 |
$$.type_sizeof = NULL; |
| 769 |
} |
| 770 |
| IDENT ecpg_interval |
| 771 |
{ |
| 772 |
/* |
| 773 |
* In C parsing mode, the above SQL type names are not keywords, so |
| 774 |
* they will show up here as a plain identifier, and we need this |
| 775 |
* duplicate code to recognize them. |
| 776 |
* |
| 777 |
* Note that we also handle the type names bytea, date, and datetime |
| 778 |
* here, but not above because those are not currently SQL keywords. |
| 779 |
* If they ever become so, they must gain duplicate productions above. |
| 780 |
*/ |
| 781 |
if (strlen(@2) != 0 && strcmp(@1, "datetime") != 0 && strcmp(@1, "interval") != 0) |
| 782 |
mmerror(PARSE_ERROR, ET_ERROR, "interval specification not allowed here"); |
| 783 |
|
| 784 |
if (strcmp(@1, "varchar") == 0) |
| 785 |
{ |
| 786 |
$$.type_enum = ECPGt_varchar; |
| 787 |
$$.type_str = ""; /* "varchar"; */ |
| 788 |
$$.type_dimension = "-1"; |
| 789 |
$$.type_index = "-1"; |
| 790 |
$$.type_sizeof = NULL; |
| 791 |
} |
| 792 |
else if (strcmp(@1, "bytea") == 0) |
| 793 |
{ |
| 794 |
$$.type_enum = ECPGt_bytea; |
| 795 |
$$.type_str = ""; |
| 796 |
$$.type_dimension = "-1"; |
| 797 |
$$.type_index = "-1"; |
| 798 |
$$.type_sizeof = NULL; |
| 799 |
} |
| 800 |
else if (strcmp(@1, "float") == 0) |
| 801 |
{ |
| 802 |
$$.type_enum = ECPGt_float; |
| 803 |
$$.type_str = "float"; |
| 804 |
$$.type_dimension = "-1"; |
| 805 |
$$.type_index = "-1"; |
| 806 |
$$.type_sizeof = NULL; |
| 807 |
} |
| 808 |
else if (strcmp(@1, "double") == 0) |
| 809 |
{ |
| 810 |
$$.type_enum = ECPGt_double; |
| 811 |
$$.type_str = "double"; |
| 812 |
$$.type_dimension = "-1"; |
| 813 |
$$.type_index = "-1"; |
| 814 |
$$.type_sizeof = NULL; |
| 815 |
} |
| 816 |
else if (strcmp(@1, "numeric") == 0) |
| 817 |
{ |
| 818 |
$$.type_enum = ECPGt_numeric; |
| 819 |
$$.type_str = "numeric"; |
| 820 |
$$.type_dimension = "-1"; |
| 821 |
$$.type_index = "-1"; |
| 822 |
$$.type_sizeof = NULL; |
| 823 |
} |
| 824 |
else if (strcmp(@1, "decimal") == 0) |
| 825 |
{ |
| 826 |
$$.type_enum = ECPGt_decimal; |
| 827 |
$$.type_str = "decimal"; |
| 828 |
$$.type_dimension = "-1"; |
| 829 |
$$.type_index = "-1"; |
| 830 |
$$.type_sizeof = NULL; |
| 831 |
} |
| 832 |
else if (strcmp(@1, "date") == 0) |
| 833 |
{ |
| 834 |
$$.type_enum = ECPGt_date; |
| 835 |
$$.type_str = "date"; |
| 836 |
$$.type_dimension = "-1"; |
| 837 |
$$.type_index = "-1"; |
| 838 |
$$.type_sizeof = NULL; |
| 839 |
} |
| 840 |
else if (strcmp(@1, "timestamp") == 0) |
| 841 |
{ |
| 842 |
$$.type_enum = ECPGt_timestamp; |
| 843 |
$$.type_str = "timestamp"; |
| 844 |
$$.type_dimension = "-1"; |
| 845 |
$$.type_index = "-1"; |
| 846 |
$$.type_sizeof = NULL; |
| 847 |
} |
| 848 |
else if (strcmp(@1, "interval") == 0) |
| 849 |
{ |
| 850 |
$$.type_enum = ECPGt_interval; |
| 851 |
$$.type_str = "interval"; |
| 852 |
$$.type_dimension = "-1"; |
| 853 |
$$.type_index = "-1"; |
| 854 |
$$.type_sizeof = NULL; |
| 855 |
} |
| 856 |
else if (strcmp(@1, "datetime") == 0) |
| 857 |
{ |
| 858 |
$$.type_enum = ECPGt_timestamp; |
| 859 |
$$.type_str = "timestamp"; |
| 860 |
$$.type_dimension = "-1"; |
| 861 |
$$.type_index = "-1"; |
| 862 |
$$.type_sizeof = NULL; |
| 863 |
} |
| 864 |
else if ((strcmp(@1, "string") == 0) && INFORMIX_MODE) |
| 865 |
{ |
| 866 |
$$.type_enum = ECPGt_string; |
| 867 |
$$.type_str = "char"; |
| 868 |
$$.type_dimension = "-1"; |
| 869 |
$$.type_index = "-1"; |
| 870 |
$$.type_sizeof = NULL; |
| 871 |
} |
| 872 |
else |
| 873 |
{ |
| 874 |
/* Otherwise, it must be a user-defined typedef name */ |
| 875 |
struct typedefs *this = get_typedef(@1, false); |
| 876 |
|
| 877 |
$$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? "" : this->name; |
| 878 |
$$.type_enum = this->type->type_enum; |
| 879 |
$$.type_dimension = this->type->type_dimension; |
| 880 |
$$.type_index = this->type->type_index; |
| 881 |
if (this->type->type_sizeof && strlen(this->type->type_sizeof) != 0) |
| 882 |
$$.type_sizeof = this->type->type_sizeof; |
| 883 |
else |
| 884 |
$$.type_sizeof = cat_str(3, "sizeof(", this->name, ")"); |
| 885 |
|
| 886 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 887 |
struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list); |
| 888 |
} |
| 889 |
} |
| 890 |
| s_struct_union_symbol |
| 891 |
{ |
| 892 |
/* this is for named structs/unions */ |
| 893 |
char *name; |
| 894 |
struct typedefs *this; |
| 895 |
bool forward = (forward_name != NULL && strcmp($1.symbol, forward_name) == 0 && strcmp($1.su, "struct") == 0); |
| 896 |
|
| 897 |
name = cat2_str($1.su, $1.symbol); |
| 898 |
/* Do we have a forward definition? */ |
| 899 |
if (!forward) |
| 900 |
{ |
| 901 |
/* No */ |
| 902 |
|
| 903 |
this = get_typedef(name, false); |
| 904 |
$$.type_str = this->name; |
| 905 |
$$.type_enum = this->type->type_enum; |
| 906 |
$$.type_dimension = this->type->type_dimension; |
| 907 |
$$.type_index = this->type->type_index; |
| 908 |
$$.type_sizeof = this->type->type_sizeof; |
| 909 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 910 |
struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list); |
| 911 |
} |
| 912 |
else |
| 913 |
{ |
| 914 |
$$.type_str = name; |
| 915 |
$$.type_enum = ECPGt_long; |
| 916 |
$$.type_dimension = "-1"; |
| 917 |
$$.type_index = "-1"; |
| 918 |
$$.type_sizeof = ""; |
| 919 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 920 |
struct_member_list[struct_level] = NULL; |
| 921 |
} |
| 922 |
} |
| 923 |
; |
| 924 |
|
| 925 |
enum_type: ENUM_P symbol enum_definition |
| 926 |
| ENUM_P enum_definition |
| 927 |
| ENUM_P symbol |
| 928 |
; |
| 929 |
|
| 930 |
enum_definition: '{' c_list '}' |
| 931 |
; |
| 932 |
|
| 933 |
struct_union_type_with_symbol: s_struct_union_symbol |
| 934 |
{ |
| 935 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 936 |
struct_member_list[struct_level++] = NULL; |
| 937 |
if (struct_level >= STRUCT_DEPTH) |
| 938 |
mmerror(PARSE_ERROR, ET_ERROR, "too many levels in nested structure/union definition"); |
| 939 |
forward_name = mm_strdup($1.symbol); |
| 940 |
} |
| 941 |
'{' variable_declarations '}' |
| 942 |
{ |
| 943 |
struct typedefs *ptr, |
| 944 |
*this; |
| 945 |
struct this_type su_type; |
| 946 |
|
| 947 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 948 |
struct_member_list[struct_level] = NULL; |
| 949 |
struct_level--; |
| 950 |
if (strcmp($1.su, "struct") == 0) |
| 951 |
su_type.type_enum = ECPGt_struct; |
| 952 |
else |
| 953 |
su_type.type_enum = ECPGt_union; |
| 954 |
su_type.type_str = cat2_str($1.su, $1.symbol); |
| 955 |
free(forward_name); |
| 956 |
forward_name = NULL; |
| 957 |
|
| 958 |
/* |
| 959 |
* This is essentially a typedef but needs the keyword struct/union as |
| 960 |
* well. So we create the typedef for each struct definition with |
| 961 |
* symbol |
| 962 |
*/ |
| 963 |
for (ptr = types; ptr != NULL; ptr = ptr->next) |
| 964 |
{ |
| 965 |
if (strcmp(su_type.type_str, ptr->name) == 0) |
| 966 |
/* re-definition is a bug */ |
| 967 |
mmerror(PARSE_ERROR, ET_ERROR, "type \"%s\" is already defined", su_type.type_str); |
| 968 |
} |
| 969 |
|
| 970 |
this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); |
| 971 |
|
| 972 |
/* initial definition */ |
| 973 |
this->next = types; |
| 974 |
this->name = mm_strdup(su_type.type_str); |
| 975 |
this->brace_level = braces_open; |
| 976 |
this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); |
| 977 |
this->type->type_storage = NULL; |
| 978 |
this->type->type_enum = su_type.type_enum; |
| 979 |
this->type->type_str = mm_strdup(su_type.type_str); |
| 980 |
this->type->type_dimension = mm_strdup("-1"); /* dimension of array */ |
| 981 |
this->type->type_index = mm_strdup("-1"); /* length of string */ |
| 982 |
this->type->type_sizeof = ECPGstruct_sizeof ? mm_strdup(ECPGstruct_sizeof) : NULL; |
| 983 |
this->struct_member_list = ECPGstruct_member_dup(struct_member_list[struct_level]); |
| 984 |
|
| 985 |
types = this; |
| 986 |
@$ = cat_str(4, su_type.type_str, "{", @4, "}"); |
| 987 |
} |
| 988 |
; |
| 989 |
|
| 990 |
struct_union_type: struct_union_type_with_symbol |
| 991 |
| s_struct_union |
| 992 |
{ |
| 993 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 994 |
struct_member_list[struct_level++] = NULL; |
| 995 |
if (struct_level >= STRUCT_DEPTH) |
| 996 |
mmerror(PARSE_ERROR, ET_ERROR, "too many levels in nested structure/union definition"); |
| 997 |
} |
| 998 |
'{' variable_declarations '}' |
| 999 |
{ |
| 1000 |
ECPGfree_struct_member(struct_member_list[struct_level]); |
| 1001 |
struct_member_list[struct_level] = NULL; |
| 1002 |
struct_level--; |
| 1003 |
@$ = cat_str(4, @1, "{", @4, "}"); |
| 1004 |
} |
| 1005 |
; |
| 1006 |
|
| 1007 |
s_struct_union_symbol: SQL_STRUCT symbol |
| 1008 |
{ |
| 1009 |
$$.su = "struct"; |
| 1010 |
$$.symbol = @2; |
| 1011 |
free(ECPGstruct_sizeof); |
| 1012 |
ECPGstruct_sizeof = mm_strdup(cat_str(3, "sizeof(", |
| 1013 |
cat2_str($$.su, $$.symbol), |
| 1014 |
")")); |
| 1015 |
} |
| 1016 |
| UNION symbol |
| 1017 |
{ |
| 1018 |
$$.su = "union"; |
| 1019 |
$$.symbol = @2; |
| 1020 |
} |
| 1021 |
; |
| 1022 |
|
| 1023 |
s_struct_union: SQL_STRUCT |
| 1024 |
{ |
| 1025 |
free(ECPGstruct_sizeof); |
| 1026 |
ECPGstruct_sizeof = mm_strdup(""); /* This must not be NULL to |
| 1027 |
* distinguish from simple types. */ |
| 1028 |
@$ = "struct"; |
| 1029 |
} |
| 1030 |
| UNION |
| 1031 |
{ |
| 1032 |
@$ = "union"; |
| 1033 |
} |
| 1034 |
; |
| 1035 |
|
| 1036 |
simple_type: unsigned_type |
| 1037 |
| opt_signed signed_type { $$ = $2; } |
| 1038 |
; |
| 1039 |
|
| 1040 |
unsigned_type: SQL_UNSIGNED SQL_SHORT { $$ = ECPGt_unsigned_short; } |
| 1041 |
| SQL_UNSIGNED SQL_SHORT INT_P { $$ = ECPGt_unsigned_short; } |
| 1042 |
| SQL_UNSIGNED { $$ = ECPGt_unsigned_int; } |
| 1043 |
| SQL_UNSIGNED INT_P { $$ = ECPGt_unsigned_int; } |
| 1044 |
| SQL_UNSIGNED SQL_LONG { $$ = ECPGt_unsigned_long; } |
| 1045 |
| SQL_UNSIGNED SQL_LONG INT_P { $$ = ECPGt_unsigned_long; } |
| 1046 |
| SQL_UNSIGNED SQL_LONG SQL_LONG { $$ = ECPGt_unsigned_long_long; } |
| 1047 |
| SQL_UNSIGNED SQL_LONG SQL_LONG INT_P { $$ = ECPGt_unsigned_long_long; } |
| 1048 |
| SQL_UNSIGNED CHAR_P { $$ = ECPGt_unsigned_char; } |
| 1049 |
; |
| 1050 |
|
| 1051 |
signed_type: SQL_SHORT { $$ = ECPGt_short; } |
| 1052 |
| SQL_SHORT INT_P { $$ = ECPGt_short; } |
| 1053 |
| INT_P { $$ = ECPGt_int; } |
| 1054 |
| SQL_LONG { $$ = ECPGt_long; } |
| 1055 |
| SQL_LONG INT_P { $$ = ECPGt_long; } |
| 1056 |
| SQL_LONG SQL_LONG { $$ = ECPGt_long_long; } |
| 1057 |
| SQL_LONG SQL_LONG INT_P { $$ = ECPGt_long_long; } |
| 1058 |
| SQL_BOOL { $$ = ECPGt_bool; } |
| 1059 |
| CHAR_P { $$ = ECPGt_char; } |
| 1060 |
| DOUBLE_P { $$ = ECPGt_double; } |
| 1061 |
; |
| 1062 |
|
| 1063 |
opt_signed: SQL_SIGNED |
| 1064 |
| /* EMPTY */ |
| 1065 |
; |
| 1066 |
|
| 1067 |
variable_list: variable |
| 1068 |
| variable_list ',' variable |
| 1069 |
{ |
| 1070 |
if (actual_type[struct_level].type_enum == ECPGt_varchar || actual_type[struct_level].type_enum == ECPGt_bytea) |
| 1071 |
@$ = cat_str(4, @1, ";", actual_type[struct_level].type_storage, @3); |
| 1072 |
else |
| 1073 |
@$ = cat_str(3, @1, ",", @3); |
| 1074 |
} |
| 1075 |
; |
| 1076 |
|
| 1077 |
variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initializer |
| 1078 |
{ |
| 1079 |
struct ECPGtype *type; |
| 1080 |
const char *dimension = $3.index1; /* dimension of array */ |
| 1081 |
const char *length = $3.index2; /* length of string */ |
| 1082 |
char *dim_str; |
| 1083 |
char vcn[32]; |
| 1084 |
int *varlen_type_counter; |
| 1085 |
char *struct_name; |
| 1086 |
|
| 1087 |
adjust_array(actual_type[struct_level].type_enum, |
| 1088 |
&dimension, &length, |
| 1089 |
actual_type[struct_level].type_dimension, |
| 1090 |
actual_type[struct_level].type_index, |
| 1091 |
strlen(@1), false); |
| 1092 |
switch (actual_type[struct_level].type_enum) |
| 1093 |
{ |
| 1094 |
case ECPGt_struct: |
| 1095 |
case ECPGt_union: |
| 1096 |
if (atoi(dimension) < 0) |
| 1097 |
type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_str, actual_type[struct_level].type_sizeof); |
| 1098 |
else |
| 1099 |
type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_str, actual_type[struct_level].type_sizeof), dimension); |
| 1100 |
|
| 1101 |
@$ = cat_str(5, @1, @2, $3.str, @4, @5); |
| 1102 |
break; |
| 1103 |
|
| 1104 |
case ECPGt_varchar: |
| 1105 |
case ECPGt_bytea: |
| 1106 |
if (actual_type[struct_level].type_enum == ECPGt_varchar) |
| 1107 |
{ |
| 1108 |
varlen_type_counter = &varchar_counter; |
| 1109 |
struct_name = " struct varchar_"; |
| 1110 |
} |
| 1111 |
else |
| 1112 |
{ |
| 1113 |
varlen_type_counter = &bytea_counter; |
| 1114 |
struct_name = " struct bytea_"; |
| 1115 |
} |
| 1116 |
if (atoi(dimension) < 0) |
| 1117 |
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, *varlen_type_counter); |
| 1118 |
else |
| 1119 |
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, *varlen_type_counter), dimension); |
| 1120 |
|
| 1121 |
if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1) |
| 1122 |
dim_str = ""; |
| 1123 |
else |
| 1124 |
dim_str = cat_str(3, "[", dimension, "]"); |
| 1125 |
|
| 1126 |
/* |
| 1127 |
* cannot check for atoi <= 0 because a defined constant will |
| 1128 |
* yield 0 here as well |
| 1129 |
*/ |
| 1130 |
if (atoi(length) < 0 || strcmp(length, "0") == 0) |
| 1131 |
mmerror(PARSE_ERROR, ET_ERROR, "pointers to varchar are not implemented"); |
| 1132 |
|
| 1133 |
/* |
| 1134 |
* make sure varchar struct name is unique by adding a unique |
| 1135 |
* counter to its definition |
| 1136 |
*/ |
| 1137 |
snprintf(vcn, sizeof(vcn), "%d", *varlen_type_counter); |
| 1138 |
if (strcmp(dimension, "0") == 0) |
| 1139 |
@$ = cat_str(7, make2_str(struct_name, vcn), " { int len; char arr[", length, "]; } *", @2, @4, @5); |
| 1140 |
else |
| 1141 |
@$ = cat_str(8, make2_str(struct_name, vcn), " { int len; char arr[", length, "]; } ", @2, dim_str, @4, @5); |
| 1142 |
(*varlen_type_counter)++; |
| 1143 |
break; |
| 1144 |
|
| 1145 |
case ECPGt_char: |
| 1146 |
case ECPGt_unsigned_char: |
| 1147 |
case ECPGt_string: |
| 1148 |
if (atoi(dimension) == -1) |
| 1149 |
{ |
| 1150 |
int i = strlen(@5); |
| 1151 |
|
| 1152 |
if (atoi(length) == -1 && i > 0) /* char <var>[] = |
| 1153 |
* "string" */ |
| 1154 |
{ |
| 1155 |
/* |
| 1156 |
* if we have an initializer but no string size set, |
| 1157 |
* let's use the initializer's length |
| 1158 |
*/ |
| 1159 |
char *buf = loc_alloc(32); |
| 1160 |
|
| 1161 |
snprintf(buf, 32, "sizeof(%s)", @5 + 2); |
| 1162 |
length = buf; |
| 1163 |
} |
| 1164 |
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, 0); |
| 1165 |
} |
| 1166 |
else |
| 1167 |
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, 0), dimension); |
| 1168 |
|
| 1169 |
@$ = cat_str(5, @1, @2, $3.str, @4, @5); |
| 1170 |
break; |
| 1171 |
|
| 1172 |
default: |
| 1173 |
if (atoi(dimension) < 0) |
| 1174 |
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, "1", 0); |
| 1175 |
else |
| 1176 |
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, "1", 0), dimension); |
| 1177 |
|
| 1178 |
@$ = cat_str(5, @1, @2, $3.str, @4, @5); |
| 1179 |
break; |
| 1180 |
} |
| 1181 |
|
| 1182 |
if (struct_level == 0) |
| 1183 |
new_variable(@2, type, braces_open); |
| 1184 |
else |
| 1185 |
ECPGmake_struct_member(@2, type, &(struct_member_list[struct_level - 1])); |
| 1186 |
} |
| 1187 |
; |
| 1188 |
|
| 1189 |
opt_initializer: /* EMPTY */ |
| 1190 |
| '=' c_term |
| 1191 |
{ |
| 1192 |
initializer = 1; |
| 1193 |
} |
| 1194 |
; |
| 1195 |
|
| 1196 |
opt_pointer: /* EMPTY */ |
| 1197 |
| '*' |
| 1198 |
| '*' '*' |
| 1199 |
{ |
| 1200 |
@$ = "**"; |
| 1201 |
} |
| 1202 |
; |
| 1203 |
|
| 1204 |
/* |
| 1205 |
* We try to simulate the correct DECLARE syntax here so we get dynamic SQL |
| 1206 |
*/ |
| 1207 |
ECPGDeclare: DECLARE STATEMENT ecpg_ident |
| 1208 |
{ |
| 1209 |
/* this is only supported for compatibility */ |
| 1210 |
@$ = cat_str(3, "/* declare statement", @3, "*/"); |
| 1211 |
} |
| 1212 |
; |
| 1213 |
/* |
| 1214 |
* the exec sql disconnect statement: disconnect from the given database |
| 1215 |
*/ |
| 1216 |
ECPGDisconnect: SQL_DISCONNECT dis_name |
| 1217 |
{ |
| 1218 |
@$ = @2; |
| 1219 |
} |
| 1220 |
; |
| 1221 |
|
| 1222 |
dis_name: connection_object |
| 1223 |
| CURRENT_P |
| 1224 |
{ |
| 1225 |
@$ = "\"CURRENT\""; |
| 1226 |
} |
| 1227 |
| ALL |
| 1228 |
{ |
| 1229 |
@$ = "\"ALL\""; |
| 1230 |
} |
| 1231 |
| /* EMPTY */ |
| 1232 |
{ |
| 1233 |
@$ = "\"CURRENT\""; |
| 1234 |
} |
| 1235 |
; |
| 1236 |
|
| 1237 |
connection_object: name |
| 1238 |
{ |
| 1239 |
@$ = make3_str("\"", @1, "\""); |
| 1240 |
} |
| 1241 |
| DEFAULT |
| 1242 |
{ |
| 1243 |
@$ = "\"DEFAULT\""; |
| 1244 |
} |
| 1245 |
| char_variable |
| 1246 |
; |
| 1247 |
|
| 1248 |
execstring: char_variable |
| 1249 |
| CSTRING |
| 1250 |
{ |
| 1251 |
@$ = make3_str("\"", @1, "\""); |
| 1252 |
} |
| 1253 |
; |
| 1254 |
|
| 1255 |
/* |
| 1256 |
* the exec sql free command to deallocate a previously |
| 1257 |
* prepared statement |
| 1258 |
*/ |
| 1259 |
ECPGFree: SQL_FREE cursor_name |
| 1260 |
{ |
| 1261 |
@$ = @2; |
| 1262 |
} |
| 1263 |
| SQL_FREE ALL |
| 1264 |
{ |
| 1265 |
@$ = "all"; |
| 1266 |
} |
| 1267 |
; |
| 1268 |
|
| 1269 |
/* |
| 1270 |
* open is an open cursor, at the moment this has to be removed |
| 1271 |
*/ |
| 1272 |
ECPGOpen: SQL_OPEN cursor_name opt_ecpg_using |
| 1273 |
{ |
| 1274 |
if (@2[0] == ':') |
| 1275 |
remove_variable_from_list(&argsinsert, find_variable(@2 + 1)); |
| 1276 |
@$ = @2; |
| 1277 |
} |
| 1278 |
; |
| 1279 |
|
| 1280 |
opt_ecpg_using: /* EMPTY */ |
| 1281 |
| ecpg_using |
| 1282 |
; |
| 1283 |
|
| 1284 |
ecpg_using: USING using_list |
| 1285 |
{ |
| 1286 |
@$ = ""; |
| 1287 |
} |
| 1288 |
| using_descriptor |
| 1289 |
; |
| 1290 |
|
| 1291 |
using_descriptor: USING SQL_P SQL_DESCRIPTOR quoted_ident_stringvar |
| 1292 |
{ |
| 1293 |
add_variable_to_head(&argsinsert, descriptor_variable(@4, 0), &no_indicator); |
| 1294 |
@$ = ""; |
| 1295 |
} |
| 1296 |
| USING SQL_DESCRIPTOR name |
| 1297 |
{ |
| 1298 |
add_variable_to_head(&argsinsert, sqlda_variable(@3), &no_indicator); |
| 1299 |
@$ = ""; |
| 1300 |
} |
| 1301 |
; |
| 1302 |
|
| 1303 |
into_descriptor: INTO SQL_P SQL_DESCRIPTOR quoted_ident_stringvar |
| 1304 |
{ |
| 1305 |
add_variable_to_head(&argsresult, descriptor_variable(@4, 1), &no_indicator); |
| 1306 |
@$ = ""; |
| 1307 |
} |
| 1308 |
| INTO SQL_DESCRIPTOR name |
| 1309 |
{ |
| 1310 |
add_variable_to_head(&argsresult, sqlda_variable(@3), &no_indicator); |
| 1311 |
@$ = ""; |
| 1312 |
} |
| 1313 |
; |
| 1314 |
|
| 1315 |
into_sqlda: INTO name |
| 1316 |
{ |
| 1317 |
add_variable_to_head(&argsresult, sqlda_variable(@2), &no_indicator); |
| 1318 |
@$ = ""; |
| 1319 |
} |
| 1320 |
; |
| 1321 |
|
| 1322 |
using_list: UsingValue | UsingValue ',' using_list |
| 1323 |
; |
| 1324 |
|
| 1325 |
UsingValue: UsingConst |
| 1326 |
{ |
| 1327 |
char length[32]; |
| 1328 |
|
| 1329 |
snprintf(length, sizeof(length), "%zu", strlen(@1)); |
| 1330 |
add_variable_to_head(&argsinsert, new_variable(@1, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator); |
| 1331 |
} |
| 1332 |
| civar |
| 1333 |
{ |
| 1334 |
@$ = ""; |
| 1335 |
} |
| 1336 |
| civarind |
| 1337 |
{ |
| 1338 |
@$ = ""; |
| 1339 |
} |
| 1340 |
; |
| 1341 |
|
| 1342 |
UsingConst: Iconst |
| 1343 |
| '+' Iconst |
| 1344 |
| '-' Iconst |
| 1345 |
| ecpg_fconst |
| 1346 |
| '+' ecpg_fconst |
| 1347 |
| '-' ecpg_fconst |
| 1348 |
| ecpg_sconst |
| 1349 |
| ecpg_bconst |
| 1350 |
| ecpg_xconst |
| 1351 |
; |
| 1352 |
|
| 1353 |
/* |
| 1354 |
* We accept DESCRIBE [OUTPUT] but do nothing with DESCRIBE INPUT so far. |
| 1355 |
*/ |
| 1356 |
ECPGDescribe: SQL_DESCRIBE INPUT_P prepared_name using_descriptor |
| 1357 |
{ |
| 1358 |
$$.input = 1; |
| 1359 |
$$.stmt_name = @3; |
| 1360 |
} |
| 1361 |
| SQL_DESCRIBE opt_output prepared_name using_descriptor |
| 1362 |
{ |
| 1363 |
struct variable *var; |
| 1364 |
|
| 1365 |
var = argsinsert->variable; |
| 1366 |
remove_variable_from_list(&argsinsert, var); |
| 1367 |
add_variable_to_head(&argsresult, var, &no_indicator); |
| 1368 |
|
| 1369 |
$$.input = 0; |
| 1370 |
$$.stmt_name = @3; |
| 1371 |
} |
| 1372 |
| SQL_DESCRIBE opt_output prepared_name into_descriptor |
| 1373 |
{ |
| 1374 |
$$.input = 0; |
| 1375 |
$$.stmt_name = @3; |
| 1376 |
} |
| 1377 |
| SQL_DESCRIBE INPUT_P prepared_name into_sqlda |
| 1378 |
{ |
| 1379 |
$$.input = 1; |
| 1380 |
$$.stmt_name = @3; |
| 1381 |
} |
| 1382 |
| SQL_DESCRIBE opt_output prepared_name into_sqlda |
| 1383 |
{ |
| 1384 |
$$.input = 0; |
| 1385 |
$$.stmt_name = @3; |
| 1386 |
} |
| 1387 |
; |
| 1388 |
|
| 1389 |
opt_output: SQL_OUTPUT |
| 1390 |
| /* EMPTY */ |
| 1391 |
; |
| 1392 |
|
| 1393 |
/* |
| 1394 |
* dynamic SQL: descriptor based access |
| 1395 |
* originally written by Christof Petig <[email protected]> |
| 1396 |
* and Peter Eisentraut <[email protected]> |
| 1397 |
*/ |
| 1398 |
|
| 1399 |
/* |
| 1400 |
* allocate a descriptor |
| 1401 |
*/ |
| 1402 |
ECPGAllocateDescr: SQL_ALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar |
| 1403 |
{ |
| 1404 |
add_descriptor(@3, connection); |
| 1405 |
@$ = @3; |
| 1406 |
} |
| 1407 |
; |
| 1408 |
|
| 1409 |
|
| 1410 |
/* |
| 1411 |
* deallocate a descriptor |
| 1412 |
*/ |
| 1413 |
ECPGDeallocateDescr: DEALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar |
| 1414 |
{ |
| 1415 |
drop_descriptor(@3, connection); |
| 1416 |
@$ = @3; |
| 1417 |
} |
| 1418 |
; |
| 1419 |
|
| 1420 |
/* |
| 1421 |
* manipulate a descriptor header |
| 1422 |
*/ |
| 1423 |
|
| 1424 |
ECPGGetDescriptorHeader: SQL_GET SQL_DESCRIPTOR quoted_ident_stringvar ECPGGetDescHeaderItem |
| 1425 |
{ |
| 1426 |
@$ = @3; |
| 1427 |
} |
| 1428 |
; |
| 1429 |
|
| 1430 |
ECPGGetDescHeaderItem: cvariable '=' desc_header_item |
| 1431 |
{ |
| 1432 |
push_assignment(@1, $3); |
| 1433 |
} |
| 1434 |
; |
| 1435 |
|
| 1436 |
ECPGSetDescriptorHeader: SET SQL_DESCRIPTOR quoted_ident_stringvar ECPGSetDescHeaderItem |
| 1437 |
{ |
| 1438 |
@$ = @3; |
| 1439 |
} |
| 1440 |
; |
| 1441 |
|
| 1442 |
ECPGSetDescHeaderItem: desc_header_item '=' IntConstVar |
| 1443 |
{ |
| 1444 |
push_assignment(@3, $1); |
| 1445 |
} |
| 1446 |
; |
| 1447 |
|
| 1448 |
IntConstVar: Iconst |
| 1449 |
{ |
| 1450 |
char length[32]; |
| 1451 |
|
| 1452 |
snprintf(length, sizeof(length), "%zu", strlen(@1)); |
| 1453 |
new_variable(@1, ECPGmake_simple_type(ECPGt_const, length, 0), 0); |
| 1454 |
} |
| 1455 |
| cvariable |
| 1456 |
; |
| 1457 |
|
| 1458 |
desc_header_item: SQL_COUNT |
| 1459 |
{ |
| 1460 |
$$ = ECPGd_count; |
| 1461 |
} |
| 1462 |
; |
| 1463 |
|
| 1464 |
/* |
| 1465 |
* manipulate a descriptor |
| 1466 |
*/ |
| 1467 |
|
| 1468 |
ECPGGetDescriptor: SQL_GET SQL_DESCRIPTOR quoted_ident_stringvar VALUE_P IntConstVar ECPGGetDescItems |
| 1469 |
{ |
| 1470 |
$$.str = @5; |
| 1471 |
$$.name = @3; |
| 1472 |
} |
| 1473 |
; |
| 1474 |
|
| 1475 |
ECPGGetDescItems: ECPGGetDescItem |
| 1476 |
| ECPGGetDescItems ',' ECPGGetDescItem |
| 1477 |
; |
| 1478 |
|
| 1479 |
ECPGGetDescItem: cvariable '=' descriptor_item |
| 1480 |
{ |
| 1481 |
push_assignment(@1, $3); |
| 1482 |
} |
| 1483 |
; |
| 1484 |
|
| 1485 |
ECPGSetDescriptor: SET SQL_DESCRIPTOR quoted_ident_stringvar VALUE_P IntConstVar ECPGSetDescItems |
| 1486 |
{ |
| 1487 |
$$.str = @5; |
| 1488 |
$$.name = @3; |
| 1489 |
} |
| 1490 |
; |
| 1491 |
|
| 1492 |
ECPGSetDescItems: ECPGSetDescItem |
| 1493 |
| ECPGSetDescItems ',' ECPGSetDescItem |
| 1494 |
; |
| 1495 |
|
| 1496 |
ECPGSetDescItem: descriptor_item '=' AllConstVar |
| 1497 |
{ |
| 1498 |
push_assignment(@3, $1); |
| 1499 |
} |
| 1500 |
; |
| 1501 |
|
| 1502 |
AllConstVar: ecpg_fconst |
| 1503 |
{ |
| 1504 |
char length[32]; |
| 1505 |
|
| 1506 |
snprintf(length, sizeof(length), "%zu", strlen(@1)); |
| 1507 |
new_variable(@1, ECPGmake_simple_type(ECPGt_const, length, 0), 0); |
| 1508 |
} |
| 1509 |
| IntConstVar |
| 1510 |
| '-' ecpg_fconst |
| 1511 |
{ |
| 1512 |
char length[32]; |
| 1513 |
char *var = cat2_str("-", @2); |
| 1514 |
|
| 1515 |
snprintf(length, sizeof(length), "%zu", strlen(var)); |
| 1516 |
new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0); |
| 1517 |
@$ = var; |
| 1518 |
} |
| 1519 |
| '-' Iconst |
| 1520 |
{ |
| 1521 |
char length[32]; |
| 1522 |
char *var = cat2_str("-", @2); |
| 1523 |
|
| 1524 |
snprintf(length, sizeof(length), "%zu", strlen(var)); |
| 1525 |
new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0); |
| 1526 |
@$ = var; |
| 1527 |
} |
| 1528 |
| ecpg_sconst |
| 1529 |
{ |
| 1530 |
char length[32]; |
| 1531 |
char *var; |
| 1532 |
|
| 1533 |
/* Strip single quotes from ecpg_sconst */ |
| 1534 |
var = loc_strdup(@1 + 1); |
| 1535 |
var[strlen(var) - 1] = '\0'; |
| 1536 |
snprintf(length, sizeof(length), "%zu", strlen(var)); |
| 1537 |
new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0); |
| 1538 |
@$ = var; |
| 1539 |
} |
| 1540 |
; |
| 1541 |
|
| 1542 |
descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; } |
| 1543 |
| DATA_P { $$ = ECPGd_data; } |
| 1544 |
| SQL_DATETIME_INTERVAL_CODE { $$ = ECPGd_di_code; } |
| 1545 |
| SQL_DATETIME_INTERVAL_PRECISION { $$ = ECPGd_di_precision; } |
| 1546 |
| SQL_INDICATOR { $$ = ECPGd_indicator; } |
| 1547 |
| SQL_KEY_MEMBER { $$ = ECPGd_key_member; } |
| 1548 |
| SQL_LENGTH { $$ = ECPGd_length; } |
| 1549 |
| NAME_P { $$ = ECPGd_name; } |
| 1550 |
| SQL_NULLABLE { $$ = ECPGd_nullable; } |
| 1551 |
| SQL_OCTET_LENGTH { $$ = ECPGd_octet; } |
| 1552 |
| PRECISION { $$ = ECPGd_precision; } |
| 1553 |
| SQL_RETURNED_LENGTH { $$ = ECPGd_length; } |
| 1554 |
| SQL_RETURNED_OCTET_LENGTH { $$ = ECPGd_ret_octet; } |
| 1555 |
| SQL_SCALE { $$ = ECPGd_scale; } |
| 1556 |
| TYPE_P { $$ = ECPGd_type; } |
| 1557 |
; |
| 1558 |
|
| 1559 |
/* |
| 1560 |
* set/reset the automatic transaction mode, this needs a different handling |
| 1561 |
* as the other set commands |
| 1562 |
*/ |
| 1563 |
ECPGSetAutocommit: SET SQL_AUTOCOMMIT '=' on_off |
| 1564 |
{ |
| 1565 |
@$ = @4; |
| 1566 |
} |
| 1567 |
| SET SQL_AUTOCOMMIT TO on_off |
| 1568 |
{ |
| 1569 |
@$ = @4; |
| 1570 |
} |
| 1571 |
; |
| 1572 |
|
| 1573 |
on_off: ON |
| 1574 |
| OFF |
| 1575 |
; |
| 1576 |
|
| 1577 |
/* |
| 1578 |
* set the actual connection, this needs a different handling as the other |
| 1579 |
* set commands |
| 1580 |
*/ |
| 1581 |
ECPGSetConnection: SET CONNECTION TO connection_object |
| 1582 |
{ |
| 1583 |
@$ = @4; |
| 1584 |
} |
| 1585 |
| SET CONNECTION '=' connection_object |
| 1586 |
{ |
| 1587 |
@$ = @4; |
| 1588 |
} |
| 1589 |
| SET CONNECTION connection_object |
| 1590 |
{ |
| 1591 |
@$ = @3; |
| 1592 |
} |
| 1593 |
; |
| 1594 |
|
| 1595 |
/* |
| 1596 |
* define a new type for embedded SQL |
| 1597 |
*/ |
| 1598 |
ECPGTypedef: TYPE_P |
| 1599 |
{ |
| 1600 |
/* reset this variable so we see if there was */ |
| 1601 |
/* an initializer specified */ |
| 1602 |
initializer = 0; |
| 1603 |
} |
| 1604 |
ECPGColLabel IS var_type opt_array_bounds opt_reference |
| 1605 |
{ |
| 1606 |
add_typedef(@3, $6.index1, $6.index2, $5.type_enum, $5.type_dimension, $5.type_index, initializer, *@7 ? 1 : 0); |
| 1607 |
|
| 1608 |
if (auto_create_c == false) |
| 1609 |
@$ = cat_str(7, "/* exec sql type", @3, "is", $5.type_str, $6.str, @7, "*/"); |
| 1610 |
else |
| 1611 |
@$ = cat_str(6, "typedef ", $5.type_str, *@7 ? "*" : "", @3, $6.str, ";"); |
| 1612 |
} |
| 1613 |
; |
| 1614 |
|
| 1615 |
opt_reference: SQL_REFERENCE |
| 1616 |
| /* EMPTY */ |
| 1617 |
; |
| 1618 |
|
| 1619 |
/* |
| 1620 |
* define the type of one variable for embedded SQL |
| 1621 |
*/ |
| 1622 |
ECPGVar: SQL_VAR |
| 1623 |
{ |
| 1624 |
/* reset this variable so we see if there was */ |
| 1625 |
/* an initializer specified */ |
| 1626 |
initializer = 0; |
| 1627 |
} |
| 1628 |
ColLabel IS var_type opt_array_bounds opt_reference |
| 1629 |
{ |
| 1630 |
struct variable *p = find_variable(@3); |
| 1631 |
const char *dimension = $6.index1; |
| 1632 |
const char *length = $6.index2; |
| 1633 |
struct ECPGtype *type; |
| 1634 |
|
| 1635 |
if (($5.type_enum == ECPGt_struct || |
| 1636 |
$5.type_enum == ECPGt_union) && |
| 1637 |
initializer == 1) |
| 1638 |
mmerror(PARSE_ERROR, ET_ERROR, "initializer not allowed in EXEC SQL VAR command"); |
| 1639 |
else |
| 1640 |
{ |
| 1641 |
adjust_array($5.type_enum, &dimension, &length, |
| 1642 |
$5.type_dimension, $5.type_index, *@7 ? 1 : 0, false); |
| 1643 |
|
| 1644 |
switch ($5.type_enum) |
| 1645 |
{ |
| 1646 |
case ECPGt_struct: |
| 1647 |
case ECPGt_union: |
| 1648 |
if (atoi(dimension) < 0) |
| 1649 |
type = ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_str, $5.type_sizeof); |
| 1650 |
else |
| 1651 |
type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_str, $5.type_sizeof), dimension); |
| 1652 |
break; |
| 1653 |
|
| 1654 |
case ECPGt_varchar: |
| 1655 |
case ECPGt_bytea: |
| 1656 |
if (atoi(dimension) == -1) |
| 1657 |
type = ECPGmake_simple_type($5.type_enum, length, 0); |
| 1658 |
else |
| 1659 |
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length, 0), dimension); |
| 1660 |
break; |
| 1661 |
|
| 1662 |
case ECPGt_char: |
| 1663 |
case ECPGt_unsigned_char: |
| 1664 |
case ECPGt_string: |
| 1665 |
if (atoi(dimension) == -1) |
| 1666 |
type = ECPGmake_simple_type($5.type_enum, length, 0); |
| 1667 |
else |
| 1668 |
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length, 0), dimension); |
| 1669 |
break; |
| 1670 |
|
| 1671 |
default: |
| 1672 |
if (atoi(length) >= 0) |
| 1673 |
mmerror(PARSE_ERROR, ET_ERROR, "multidimensional arrays for simple data types are not supported"); |
| 1674 |
|
| 1675 |
if (atoi(dimension) < 0) |
| 1676 |
type = ECPGmake_simple_type($5.type_enum, "1", 0); |
| 1677 |
else |
| 1678 |
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, "1", 0), dimension); |
| 1679 |
break; |
| 1680 |
} |
| 1681 |
|
| 1682 |
ECPGfree_type(p->type); |
| 1683 |
p->type = type; |
| 1684 |
} |
| 1685 |
|
| 1686 |
@$ = cat_str(7, "/* exec sql var", @3, "is", $5.type_str, $6.str, @7, "*/"); |
| 1687 |
} |
| 1688 |
; |
| 1689 |
|
| 1690 |
/* |
| 1691 |
* whenever statement: decide what to do in case of error/no data found |
| 1692 |
* according to SQL standards we lack: SQLSTATE, CONSTRAINT and SQLEXCEPTION |
| 1693 |
*/ |
| 1694 |
ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action |
| 1695 |
{ |
| 1696 |
when_error.code = $3.code; |
| 1697 |
free(when_error.command); |
| 1698 |
when_error.command = $3.command ? mm_strdup($3.command) : NULL; |
| 1699 |
@$ = cat_str(3, "/* exec sql whenever sqlerror ", $3.str, "; */"); |
| 1700 |
} |
| 1701 |
| SQL_WHENEVER NOT SQL_FOUND action |
| 1702 |
{ |
| 1703 |
when_nf.code = $4.code; |
| 1704 |
free(when_nf.command); |
| 1705 |
when_nf.command = $4.command ? mm_strdup($4.command) : NULL; |
| 1706 |
@$ = cat_str(3, "/* exec sql whenever not found ", $4.str, "; */"); |
| 1707 |
} |
| 1708 |
| SQL_WHENEVER SQL_SQLWARNING action |
| 1709 |
{ |
| 1710 |
when_warn.code = $3.code; |
| 1711 |
free(when_warn.command); |
| 1712 |
when_warn.command = $3.command ? mm_strdup($3.command) : NULL; |
| 1713 |
@$ = cat_str(3, "/* exec sql whenever sql_warning ", $3.str, "; */"); |
| 1714 |
} |
| 1715 |
; |
| 1716 |
|
| 1717 |
action: CONTINUE_P |
| 1718 |
{ |
| 1719 |
$$.code = W_NOTHING; |
| 1720 |
$$.command = NULL; |
| 1721 |
$$.str = "continue"; |
| 1722 |
} |
| 1723 |
| SQL_SQLPRINT |
| 1724 |
{ |
| 1725 |
$$.code = W_SQLPRINT; |
| 1726 |
$$.command = NULL; |
| 1727 |
$$.str = "sqlprint"; |
| 1728 |
} |
| 1729 |
| SQL_STOP |
| 1730 |
{ |
| 1731 |
$$.code = W_STOP; |
| 1732 |
$$.command = NULL; |
| 1733 |
$$.str = "stop"; |
| 1734 |
} |
| 1735 |
| SQL_GOTO name |
| 1736 |
{ |
| 1737 |
$$.code = W_GOTO; |
| 1738 |
$$.command = loc_strdup(@2); |
| 1739 |
$$.str = cat2_str("goto ", @2); |
| 1740 |
} |
| 1741 |
| SQL_GO TO name |
| 1742 |
{ |
| 1743 |
$$.code = W_GOTO; |
| 1744 |
$$.command = loc_strdup(@3); |
| 1745 |
$$.str = cat2_str("goto ", @3); |
| 1746 |
} |
| 1747 |
| DO name '(' c_args ')' |
| 1748 |
{ |
| 1749 |
$$.code = W_DO; |
| 1750 |
$$.command = cat_str(4, @2, "(", @4, ")"); |
| 1751 |
$$.str = cat2_str("do", $$.command); |
| 1752 |
} |
| 1753 |
| DO SQL_BREAK |
| 1754 |
{ |
| 1755 |
$$.code = W_BREAK; |
| 1756 |
$$.command = NULL; |
| 1757 |
$$.str = "break"; |
| 1758 |
} |
| 1759 |
| DO CONTINUE_P |
| 1760 |
{ |
| 1761 |
$$.code = W_CONTINUE; |
| 1762 |
$$.command = NULL; |
| 1763 |
$$.str = "continue"; |
| 1764 |
} |
| 1765 |
| CALL name '(' c_args ')' |
| 1766 |
{ |
| 1767 |
$$.code = W_DO; |
| 1768 |
$$.command = cat_str(4, @2, "(", @4, ")"); |
| 1769 |
$$.str = cat2_str("call", $$.command); |
| 1770 |
} |
| 1771 |
| CALL name |
| 1772 |
{ |
| 1773 |
$$.code = W_DO; |
| 1774 |
$$.command = cat2_str(@2, "()"); |
| 1775 |
$$.str = cat2_str("call", $$.command); |
| 1776 |
} |
| 1777 |
; |
| 1778 |
|
| 1779 |
/* some other stuff for ecpg */ |
| 1780 |
|
| 1781 |
/* additional unreserved keywords */ |
| 1782 |
ECPGKeywords: ECPGKeywords_vanames |
| 1783 |
| ECPGKeywords_rest |
| 1784 |
; |
| 1785 |
|
| 1786 |
ECPGKeywords_vanames: SQL_BREAK |
| 1787 |
| SQL_CARDINALITY |
| 1788 |
| SQL_COUNT |
| 1789 |
| SQL_DATETIME_INTERVAL_CODE |
| 1790 |
| SQL_DATETIME_INTERVAL_PRECISION |
| 1791 |
| SQL_FOUND |
| 1792 |
| SQL_GO |
| 1793 |
| SQL_GOTO |
| 1794 |
| SQL_IDENTIFIED |
| 1795 |
| SQL_INDICATOR |
| 1796 |
| SQL_KEY_MEMBER |
| 1797 |
| SQL_LENGTH |
| 1798 |
| SQL_NULLABLE |
| 1799 |
| SQL_OCTET_LENGTH |
| 1800 |
| SQL_RETURNED_LENGTH |
| 1801 |
| SQL_RETURNED_OCTET_LENGTH |
| 1802 |
| SQL_SCALE |
| 1803 |
| SQL_SECTION |
| 1804 |
| SQL_SQLERROR |
| 1805 |
| SQL_SQLPRINT |
| 1806 |
| SQL_SQLWARNING |
| 1807 |
| SQL_STOP |
| 1808 |
; |
| 1809 |
|
| 1810 |
ECPGKeywords_rest: SQL_CONNECT |
| 1811 |
| SQL_DESCRIBE |
| 1812 |
| SQL_DISCONNECT |
| 1813 |
| SQL_OPEN |
| 1814 |
| SQL_VAR |
| 1815 |
| SQL_WHENEVER |
| 1816 |
; |
| 1817 |
|
| 1818 |
/* additional keywords that can be SQL type names (but not ECPGColLabels) */ |
| 1819 |
ECPGTypeName: SQL_BOOL |
| 1820 |
| SQL_LONG |
| 1821 |
| SQL_OUTPUT |
| 1822 |
| SQL_SHORT |
| 1823 |
| SQL_STRUCT |
| 1824 |
| SQL_SIGNED |
| 1825 |
| SQL_UNSIGNED |
| 1826 |
; |
| 1827 |
|
| 1828 |
symbol: ColLabel |
| 1829 |
; |
| 1830 |
|
| 1831 |
ECPGColId: ecpg_ident |
| 1832 |
| unreserved_keyword |
| 1833 |
| col_name_keyword |
| 1834 |
| ECPGunreserved_interval |
| 1835 |
| ECPGKeywords |
| 1836 |
| ECPGCKeywords |
| 1837 |
| CHAR_P |
| 1838 |
| VALUES |
| 1839 |
; |
| 1840 |
|
| 1841 |
/* |
| 1842 |
* Name classification hierarchy. |
| 1843 |
* |
| 1844 |
* These productions should match those in the core grammar, except that |
| 1845 |
* we use all_unreserved_keyword instead of unreserved_keyword, and |
| 1846 |
* where possible include ECPG keywords as well as core keywords. |
| 1847 |
*/ |
| 1848 |
|
| 1849 |
/* Column identifier --- names that can be column, table, etc names. |
| 1850 |
*/ |
| 1851 |
ColId: ecpg_ident |
| 1852 |
| all_unreserved_keyword |
| 1853 |
| col_name_keyword |
| 1854 |
| ECPGKeywords |
| 1855 |
| ECPGCKeywords |
| 1856 |
| CHAR_P |
| 1857 |
| VALUES |
| 1858 |
; |
| 1859 |
|
| 1860 |
/* Type/function identifier --- names that can be type or function names. |
| 1861 |
*/ |
| 1862 |
type_function_name: ecpg_ident |
| 1863 |
| all_unreserved_keyword |
| 1864 |
| type_func_name_keyword |
| 1865 |
| ECPGKeywords |
| 1866 |
| ECPGCKeywords |
| 1867 |
| ECPGTypeName |
| 1868 |
; |
| 1869 |
|
| 1870 |
/* Column label --- allowed labels in "AS" clauses. |
| 1871 |
* This presently includes *all* Postgres keywords. |
| 1872 |
*/ |
| 1873 |
ColLabel: ECPGColLabel |
| 1874 |
| ECPGTypeName |
| 1875 |
| CHAR_P |
| 1876 |
| CURRENT_P |
| 1877 |
| INPUT_P |
| 1878 |
| INT_P |
| 1879 |
| TO |
| 1880 |
| UNION |
| 1881 |
| VALUES |
| 1882 |
| ECPGCKeywords |
| 1883 |
| ECPGunreserved_interval |
| 1884 |
; |
| 1885 |
|
| 1886 |
ECPGColLabel: ecpg_ident |
| 1887 |
| unreserved_keyword |
| 1888 |
| col_name_keyword |
| 1889 |
| type_func_name_keyword |
| 1890 |
| reserved_keyword |
| 1891 |
| ECPGKeywords_vanames |
| 1892 |
| ECPGKeywords_rest |
| 1893 |
| CONNECTION |
| 1894 |
; |
| 1895 |
|
| 1896 |
ECPGCKeywords: S_AUTO |
| 1897 |
| S_CONST |
| 1898 |
| S_EXTERN |
| 1899 |
| S_REGISTER |
| 1900 |
| S_STATIC |
| 1901 |
| S_TYPEDEF |
| 1902 |
| S_VOLATILE |
| 1903 |
; |
| 1904 |
|
| 1905 |
/* "Unreserved" keywords --- available for use as any kind of name. |
| 1906 |
*/ |
| 1907 |
|
| 1908 |
/* |
| 1909 |
* The following symbols must be excluded from ECPGColLabel and directly |
| 1910 |
* included into ColLabel to enable C variables to get names from ECPGColLabel: |
| 1911 |
* DAY_P, HOUR_P, MINUTE_P, MONTH_P, SECOND_P, YEAR_P. |
| 1912 |
* |
| 1913 |
* We also have to exclude CONNECTION, CURRENT, and INPUT for various reasons. |
| 1914 |
* CONNECTION can be added back in all_unreserved_keyword, but CURRENT and |
| 1915 |
* INPUT are reserved for ecpg purposes. |
| 1916 |
* |
| 1917 |
* The mentioned exclusions are done by $replace_line settings in parse.pl. |
| 1918 |
*/ |
| 1919 |
all_unreserved_keyword: unreserved_keyword |
| 1920 |
| ECPGunreserved_interval |
| 1921 |
| CONNECTION |
| 1922 |
; |
| 1923 |
|
| 1924 |
ECPGunreserved_interval: DAY_P |
| 1925 |
| HOUR_P |
| 1926 |
| MINUTE_P |
| 1927 |
| MONTH_P |
| 1928 |
| SECOND_P |
| 1929 |
| YEAR_P |
| 1930 |
; |
| 1931 |
|
| 1932 |
into_list: coutputvariable | into_list ',' coutputvariable |
| 1933 |
; |
| 1934 |
|
| 1935 |
ecpgstart: SQL_START |
| 1936 |
{ |
| 1937 |
reset_variables(); |
| 1938 |
pacounter = 1; |
| 1939 |
@$ = ""; |
| 1940 |
} |
| 1941 |
; |
| 1942 |
|
| 1943 |
c_args: /* EMPTY */ |
| 1944 |
| c_list |
| 1945 |
; |
| 1946 |
|
| 1947 |
coutputvariable: cvariable indicator |
| 1948 |
{ |
| 1949 |
add_variable_to_head(&argsresult, find_variable(@1), find_variable(@2)); |
| 1950 |
} |
| 1951 |
| cvariable |
| 1952 |
{ |
| 1953 |
add_variable_to_head(&argsresult, find_variable(@1), &no_indicator); |
| 1954 |
} |
| 1955 |
; |
| 1956 |
|
| 1957 |
|
| 1958 |
civarind: cvariable indicator |
| 1959 |
{ |
| 1960 |
if (find_variable(@2)->type->type == ECPGt_array) |
| 1961 |
mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input"); |
| 1962 |
|
| 1963 |
add_variable_to_head(&argsinsert, find_variable(@1), find_variable(@2)); |
| 1964 |
@$ = create_questionmarks(@1, false); |
| 1965 |
} |
| 1966 |
; |
| 1967 |
|
| 1968 |
char_civar: char_variable |
| 1969 |
{ |
| 1970 |
char *ptr = (char *) strstr(@1, ".arr"); |
| 1971 |
|
| 1972 |
if (ptr) /* varchar, we need the struct name here, not |
| 1973 |
* the struct element */ |
| 1974 |
*ptr = '\0'; |
| 1975 |
add_variable_to_head(&argsinsert, find_variable(@1), &no_indicator); |
| 1976 |
} |
| 1977 |
; |
| 1978 |
|
| 1979 |
civar: cvariable |
| 1980 |
{ |
| 1981 |
add_variable_to_head(&argsinsert, find_variable(@1), &no_indicator); |
| 1982 |
@$ = create_questionmarks(@1, false); |
| 1983 |
} |
| 1984 |
; |
| 1985 |
|
| 1986 |
indicator: cvariable |
| 1987 |
{ |
| 1988 |
check_indicator((find_variable(@1))->type); |
| 1989 |
} |
| 1990 |
| SQL_INDICATOR cvariable |
| 1991 |
{ |
| 1992 |
check_indicator((find_variable(@2))->type); |
| 1993 |
@$ = @2; |
| 1994 |
} |
| 1995 |
| SQL_INDICATOR name |
| 1996 |
{ |
| 1997 |
check_indicator((find_variable(@2))->type); |
| 1998 |
@$ = @2; |
| 1999 |
} |
| 2000 |
; |
| 2001 |
|
| 2002 |
cvariable: CVARIABLE |
| 2003 |
{ |
| 2004 |
/* |
| 2005 |
* As long as multidimensional arrays are not implemented we have to |
| 2006 |
* check for those here |
| 2007 |
*/ |
| 2008 |
const char *ptr = @1; |
| 2009 |
int brace_open = 0, |
| 2010 |
brace = false; |
| 2011 |
|
| 2012 |
for (; *ptr; ptr++) |
| 2013 |
{ |
| 2014 |
switch (*ptr) |
| 2015 |
{ |
| 2016 |
case '[': |
| 2017 |
if (brace) |
| 2018 |
mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported"); |
| 2019 |
brace_open++; |
| 2020 |
break; |
| 2021 |
case ']': |
| 2022 |
brace_open--; |
| 2023 |
if (brace_open == 0) |
| 2024 |
brace = true; |
| 2025 |
break; |
| 2026 |
case '\t': |
| 2027 |
case ' ': |
| 2028 |
break; |
| 2029 |
default: |
| 2030 |
if (brace_open == 0) |
| 2031 |
brace = false; |
| 2032 |
break; |
| 2033 |
} |
| 2034 |
} |
| 2035 |
} |
| 2036 |
; |
| 2037 |
|
| 2038 |
ecpg_param: PARAM |
| 2039 |
; |
| 2040 |
|
| 2041 |
ecpg_bconst: BCONST |
| 2042 |
; |
| 2043 |
|
| 2044 |
ecpg_fconst: FCONST |
| 2045 |
; |
| 2046 |
|
| 2047 |
ecpg_sconst: SCONST |
| 2048 |
; |
| 2049 |
|
| 2050 |
ecpg_xconst: XCONST |
| 2051 |
; |
| 2052 |
|
| 2053 |
ecpg_ident: IDENT |
| 2054 |
| CSTRING |
| 2055 |
{ |
| 2056 |
@$ = make3_str("\"", @1, "\""); |
| 2057 |
} |
| 2058 |
; |
| 2059 |
|
| 2060 |
quoted_ident_stringvar: name |
| 2061 |
{ |
| 2062 |
@$ = make3_str("\"", @1, "\""); |
| 2063 |
} |
| 2064 |
| char_variable |
| 2065 |
{ |
| 2066 |
@$ = make3_str("(", @1, ")"); |
| 2067 |
} |
| 2068 |
; |
| 2069 |
|
| 2070 |
/* |
| 2071 |
* C stuff |
| 2072 |
*/ |
| 2073 |
|
| 2074 |
c_stuff_item: c_anything |
| 2075 |
| '(' ')' |
| 2076 |
{ |
| 2077 |
@$ = "()"; |
| 2078 |
} |
| 2079 |
| '(' c_stuff ')' |
| 2080 |
; |
| 2081 |
|
| 2082 |
c_stuff: c_stuff_item |
| 2083 |
| c_stuff c_stuff_item |
| 2084 |
; |
| 2085 |
|
| 2086 |
c_list: c_term |
| 2087 |
| c_list ',' c_term |
| 2088 |
; |
| 2089 |
|
| 2090 |
c_term: c_stuff |
| 2091 |
| '{' c_list '}' |
| 2092 |
; |
| 2093 |
|
| 2094 |
c_thing: c_anything |
| 2095 |
| '(' |
| 2096 |
| ')' |
| 2097 |
| ',' |
| 2098 |
| ';' |
| 2099 |
; |
| 2100 |
|
| 2101 |
/* |
| 2102 |
* Note: NULL_P is treated specially to force it to be output in upper case, |
| 2103 |
* since it's likely meant as a reference to the standard C macro NULL. |
| 2104 |
*/ |
| 2105 |
c_anything: ecpg_ident |
| 2106 |
| Iconst |
| 2107 |
| ecpg_fconst |
| 2108 |
| ecpg_sconst |
| 2109 |
| '*' |
| 2110 |
| '+' |
| 2111 |
| '-' |
| 2112 |
| '/' |
| 2113 |
| '%' |
| 2114 |
| NULL_P { @$ = "NULL"; } |
| 2115 |
| S_ADD |
| 2116 |
| S_AND |
| 2117 |
| S_ANYTHING |
| 2118 |
| S_AUTO |
| 2119 |
| S_CONST |
| 2120 |
| S_DEC |
| 2121 |
| S_DIV |
| 2122 |
| S_DOTPOINT |
| 2123 |
| S_EQUAL |
| 2124 |
| S_EXTERN |
| 2125 |
| S_INC |
| 2126 |
| S_LSHIFT |
| 2127 |
| S_MEMBER |
| 2128 |
| S_MEMPOINT |
| 2129 |
| S_MOD |
| 2130 |
| S_MUL |
| 2131 |
| S_NEQUAL |
| 2132 |
| S_OR |
| 2133 |
| S_REGISTER |
| 2134 |
| S_RSHIFT |
| 2135 |
| S_STATIC |
| 2136 |
| S_SUB |
| 2137 |
| S_TYPEDEF |
| 2138 |
| S_VOLATILE |
| 2139 |
| SQL_BOOL |
| 2140 |
| ENUM_P |
| 2141 |
| HOUR_P |
| 2142 |
| INT_P |
| 2143 |
| SQL_LONG |
| 2144 |
| MINUTE_P |
| 2145 |
| MONTH_P |
| 2146 |
| SECOND_P |
| 2147 |
| SQL_SHORT |
| 2148 |
| SQL_SIGNED |
| 2149 |
| SQL_STRUCT |
| 2150 |
| SQL_UNSIGNED |
| 2151 |
| YEAR_P |
| 2152 |
| CHAR_P |
| 2153 |
| FLOAT_P |
| 2154 |
| TO |
| 2155 |
| UNION |
| 2156 |
| VARCHAR |
| 2157 |
| '[' |
| 2158 |
| ']' |
| 2159 |
| '=' |
| 2160 |
| ':' |
| 2161 |
; |
| 2162 |
|
| 2163 |
DeallocateStmt: DEALLOCATE prepared_name |
| 2164 |
{ |
| 2165 |
check_declared_list(@2); |
| 2166 |
@$ = @2; |
| 2167 |
} |
| 2168 |
| DEALLOCATE PREPARE prepared_name |
| 2169 |
{ |
| 2170 |
check_declared_list(@3); |
| 2171 |
@$ = @3; |
| 2172 |
} |
| 2173 |
| DEALLOCATE ALL |
| 2174 |
{ |
| 2175 |
@$ = "all"; |
| 2176 |
} |
| 2177 |
| DEALLOCATE PREPARE ALL |
| 2178 |
{ |
| 2179 |
@$ = "all"; |
| 2180 |
} |
| 2181 |
; |
| 2182 |
|
| 2183 |
Iresult: Iconst |
| 2184 |
| '(' Iresult ')' |
| 2185 |
| Iresult '+' Iresult |
| 2186 |
| Iresult '-' Iresult |
| 2187 |
| Iresult '*' Iresult |
| 2188 |
| Iresult '/' Iresult |
| 2189 |
| Iresult '%' Iresult |
| 2190 |
| ecpg_sconst |
| 2191 |
| ColId |
| 2192 |
| ColId '(' var_type ')' |
| 2193 |
{ |
| 2194 |
if (pg_strcasecmp(@1, "sizeof") != 0) |
| 2195 |
mmerror(PARSE_ERROR, ET_ERROR, "operator not allowed in variable definition"); |
| 2196 |
else |
| 2197 |
@$ = cat_str(4, @1, "(", $3.type_str, ")"); |
| 2198 |
} |
| 2199 |
; |
| 2200 |
|
| 2201 |
execute_rest: /* EMPTY */ |
| 2202 |
| ecpg_using opt_ecpg_into |
| 2203 |
| ecpg_into ecpg_using |
| 2204 |
| ecpg_into |
| 2205 |
; |
| 2206 |
|
| 2207 |
ecpg_into: INTO into_list |
| 2208 |
{ |
| 2209 |
/* always suppress this from the constructed string */ |
| 2210 |
@$ = ""; |
| 2211 |
} |
| 2212 |
| into_descriptor |
| 2213 |
; |
| 2214 |
|
| 2215 |
opt_ecpg_into: /* EMPTY */ |
| 2216 |
| ecpg_into |
| 2217 |
; |
| 2218 |
|
| 2219 |
ecpg_fetch_into: ecpg_into |
| 2220 |
| using_descriptor |
| 2221 |
{ |
| 2222 |
struct variable *var; |
| 2223 |
|
| 2224 |
var = argsinsert->variable; |
| 2225 |
remove_variable_from_list(&argsinsert, var); |
| 2226 |
add_variable_to_head(&argsresult, var, &no_indicator); |
| 2227 |
} |
| 2228 |
; |
| 2229 |
|
| 2230 |
opt_ecpg_fetch_into: /* EMPTY */ |
| 2231 |
| ecpg_fetch_into |
| 2232 |
; |
| 2233 |
|
| 2234 |
%% |
| 2235 |
|
| 2236 |
void |
| 2237 |
base_yyerror(const char *error) |
| 2238 |
{ |
| 2239 |
/* translator: %s is typically the translation of "syntax error" */ |
| 2240 |
mmerror(PARSE_ERROR, ET_ERROR, "%s at or near \"%s\"", |
| 2241 |
_(error), token_start ? token_start : base_yytext); |
| 2242 |
} |
| 2243 |
|
| 2244 |
void |
| 2245 |
parser_init(void) |
| 2246 |
{ |
| 2247 |
/* |
| 2248 |
* This function is empty. It only exists for compatibility with the |
| 2249 |
* backend parser right now. |
| 2250 |
*/ |
| 2251 |
} |