Indent C code in flex and bison files

In the style of pgindent, done semi-manually.

Discussion: https://www.postgresql.org/message-id/flat/7d062ecc-7444-23ec-a159-acd8adf9b586%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-05-13 07:17:29 +02:00
parent 0cf16cb8ca
commit 30ed71e423
12 changed files with 1955 additions and 1167 deletions

View File

@ -45,7 +45,7 @@ static NDBOX *write_point_as_box(int dim, char *str);
box: O_BRACKET paren_list COMMA paren_list C_BRACKET box: O_BRACKET paren_list COMMA paren_list C_BRACKET
{ {
int dim; int dim;
dim = item_count($2, ','); dim = item_count($2, ',');
if (item_count($4, ',') != dim) if (item_count($4, ',') != dim)
@ -72,7 +72,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
| paren_list COMMA paren_list | paren_list COMMA paren_list
{ {
int dim; int dim;
dim = item_count($1, ','); dim = item_count($1, ',');
if (item_count($3, ',') != dim) if (item_count($3, ',') != dim)
@ -99,7 +99,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
| paren_list | paren_list
{ {
int dim; int dim;
dim = item_count($1, ','); dim = item_count($1, ',');
if (dim > CUBE_MAX_DIM) if (dim > CUBE_MAX_DIM)
@ -117,7 +117,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
| list | list
{ {
int dim; int dim;
dim = item_count($1, ','); dim = item_count($1, ',');
if (dim > CUBE_MAX_DIM) if (dim > CUBE_MAX_DIM)

View File

@ -38,13 +38,15 @@ static char strbuf[25] = {
%expect 0 %expect 0
%name-prefix="seg_yy" %name-prefix="seg_yy"
%union { %union
struct BND { {
float val; struct BND
char ext; {
char sigd; float val;
char ext;
char sigd;
} bnd; } bnd;
char * text; char *text;
} }
%token <text> SEGFLOAT %token <text> SEGFLOAT
%token <text> RANGE %token <text> RANGE
@ -119,7 +121,7 @@ range: boundary PLUMIN deviation
boundary: SEGFLOAT boundary: SEGFLOAT
{ {
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */ /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
float val = seg_atof($1); float val = seg_atof($1);
$$.ext = '\0'; $$.ext = '\0';
$$.sigd = significant_digits($1); $$.sigd = significant_digits($1);
@ -128,7 +130,7 @@ boundary: SEGFLOAT
| EXTENSION SEGFLOAT | EXTENSION SEGFLOAT
{ {
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */ /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
float val = seg_atof($2); float val = seg_atof($2);
$$.ext = $1[0]; $$.ext = $1[0];
$$.sigd = significant_digits($2); $$.sigd = significant_digits($2);
@ -139,7 +141,7 @@ boundary: SEGFLOAT
deviation: SEGFLOAT deviation: SEGFLOAT
{ {
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */ /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
float val = seg_atof($1); float val = seg_atof($1);
$$.ext = '\0'; $$.ext = '\0';
$$.sigd = significant_digits($1); $$.sigd = significant_digits($1);
@ -153,7 +155,7 @@ deviation: SEGFLOAT
static float static float
seg_atof(const char *value) seg_atof(const char *value)
{ {
Datum datum; Datum datum;
datum = DirectFunctionCall1(float4in, CStringGetDatum(value)); datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
return DatumGetFloat4(datum); return DatumGetFloat4(datum);

View File

@ -167,9 +167,9 @@ Boot_CreateStmt:
} }
RPAREN RPAREN
{ {
TupleDesc tupdesc; TupleDesc tupdesc;
bool shared_relation; bool shared_relation;
bool mapped_relation; bool mapped_relation;
do_start(); do_start();
@ -218,7 +218,7 @@ Boot_CreateStmt:
} }
else else
{ {
Oid id; Oid id;
id = heap_create_with_catalog($2, id = heap_create_with_catalog($2,
PG_CATALOG_NAMESPACE, PG_CATALOG_NAMESPACE,
@ -269,8 +269,8 @@ Boot_InsertStmt:
Boot_DeclareIndexStmt: Boot_DeclareIndexStmt:
XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{ {
IndexStmt *stmt = makeNode(IndexStmt); IndexStmt *stmt = makeNode(IndexStmt);
Oid relationId; Oid relationId;
elog(DEBUG4, "creating index \"%s\"", $3); elog(DEBUG4, "creating index \"%s\"", $3);
@ -321,8 +321,8 @@ Boot_DeclareIndexStmt:
Boot_DeclareUniqueIndexStmt: Boot_DeclareUniqueIndexStmt:
XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{ {
IndexStmt *stmt = makeNode(IndexStmt); IndexStmt *stmt = makeNode(IndexStmt);
Oid relationId; Oid relationId;
elog(DEBUG4, "creating unique index \"%s\"", $4); elog(DEBUG4, "creating unique index \"%s\"", $4);
@ -400,7 +400,8 @@ boot_index_params:
boot_index_param: boot_index_param:
boot_ident boot_ident boot_ident boot_ident
{ {
IndexElem *n = makeNode(IndexElem); IndexElem *n = makeNode(IndexElem);
n->name = $1; n->name = $1;
n->expr = NULL; n->expr = NULL;
n->indexcolname = NULL; n->indexcolname = NULL;

File diff suppressed because it is too large Load Diff

View File

@ -42,15 +42,15 @@ Node *replication_parse_result;
%expect 0 %expect 0
%name-prefix="replication_yy" %name-prefix="replication_yy"
%union { %union
char *str; {
bool boolval; char *str;
uint32 uintval; bool boolval;
uint32 uintval;
XLogRecPtr recptr; XLogRecPtr recptr;
Node *node; Node *node;
List *list; List *list;
DefElem *defelt; DefElem *defelt;
} }
/* Non-keyword tokens */ /* Non-keyword tokens */
@ -215,27 +215,27 @@ create_slot_legacy_opt:
K_EXPORT_SNAPSHOT K_EXPORT_SNAPSHOT
{ {
$$ = makeDefElem("snapshot", $$ = makeDefElem("snapshot",
(Node *)makeString("export"), -1); (Node *) makeString("export"), -1);
} }
| K_NOEXPORT_SNAPSHOT | K_NOEXPORT_SNAPSHOT
{ {
$$ = makeDefElem("snapshot", $$ = makeDefElem("snapshot",
(Node *)makeString("nothing"), -1); (Node *) makeString("nothing"), -1);
} }
| K_USE_SNAPSHOT | K_USE_SNAPSHOT
{ {
$$ = makeDefElem("snapshot", $$ = makeDefElem("snapshot",
(Node *)makeString("use"), -1); (Node *) makeString("use"), -1);
} }
| K_RESERVE_WAL | K_RESERVE_WAL
{ {
$$ = makeDefElem("reserve_wal", $$ = makeDefElem("reserve_wal",
(Node *)makeBoolean(true), -1); (Node *) makeBoolean(true), -1);
} }
| K_TWO_PHASE | K_TWO_PHASE
{ {
$$ = makeDefElem("two_phase", $$ = makeDefElem("two_phase",
(Node *)makeBoolean(true), -1); (Node *) makeBoolean(true), -1);
} }
; ;

View File

@ -169,7 +169,8 @@ WAIT { return K_WAIT; }
} }
<xd>{xdstop} { <xd>{xdstop} {
int len; int len;
yyless(1); yyless(1);
BEGIN(INITIAL); BEGIN(INITIAL);
yylval.str = litbufdup(); yylval.str = litbufdup();
@ -183,7 +184,7 @@ WAIT { return K_WAIT; }
} }
{identifier} { {identifier} {
int len = strlen(yytext); int len = strlen(yytext);
yylval.str = downcase_truncate_identifier(yytext, len, true); yylval.str = downcase_truncate_identifier(yytext, len, true);
return IDENT; return IDENT;

View File

@ -77,7 +77,8 @@ static JsonPathParseItem *makeItemLikeRegex(JsonPathParseItem *expr,
%error-verbose %error-verbose
%parse-param {JsonPathParseResult **result} %parse-param {JsonPathParseResult **result}
%union { %union
{
JsonPathString str; JsonPathString str;
List *elems; /* list of JsonPathParseItem */ List *elems; /* list of JsonPathParseItem */
List *indexs; /* list of integers */ List *indexs; /* list of integers */
@ -313,7 +314,7 @@ method:
static JsonPathParseItem * static JsonPathParseItem *
makeItemType(JsonPathItemType type) makeItemType(JsonPathItemType type)
{ {
JsonPathParseItem *v = palloc(sizeof(*v)); JsonPathParseItem *v = palloc(sizeof(*v));
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
@ -326,7 +327,7 @@ makeItemType(JsonPathItemType type)
static JsonPathParseItem * static JsonPathParseItem *
makeItemString(JsonPathString *s) makeItemString(JsonPathString *s)
{ {
JsonPathParseItem *v; JsonPathParseItem *v;
if (s == NULL) if (s == NULL)
{ {
@ -345,7 +346,7 @@ makeItemString(JsonPathString *s)
static JsonPathParseItem * static JsonPathParseItem *
makeItemVariable(JsonPathString *s) makeItemVariable(JsonPathString *s)
{ {
JsonPathParseItem *v; JsonPathParseItem *v;
v = makeItemType(jpiVariable); v = makeItemType(jpiVariable);
v->value.string.val = s->val; v->value.string.val = s->val;
@ -357,7 +358,7 @@ makeItemVariable(JsonPathString *s)
static JsonPathParseItem * static JsonPathParseItem *
makeItemKey(JsonPathString *s) makeItemKey(JsonPathString *s)
{ {
JsonPathParseItem *v; JsonPathParseItem *v;
v = makeItemString(s); v = makeItemString(s);
v->type = jpiKey; v->type = jpiKey;
@ -368,7 +369,7 @@ makeItemKey(JsonPathString *s)
static JsonPathParseItem * static JsonPathParseItem *
makeItemNumeric(JsonPathString *s) makeItemNumeric(JsonPathString *s)
{ {
JsonPathParseItem *v; JsonPathParseItem *v;
v = makeItemType(jpiNumeric); v = makeItemType(jpiNumeric);
v->value.numeric = v->value.numeric =
@ -383,7 +384,7 @@ makeItemNumeric(JsonPathString *s)
static JsonPathParseItem * static JsonPathParseItem *
makeItemBool(bool val) makeItemBool(bool val)
{ {
JsonPathParseItem *v = makeItemType(jpiBool); JsonPathParseItem *v = makeItemType(jpiBool);
v->value.boolean = val; v->value.boolean = val;
@ -393,7 +394,7 @@ makeItemBool(bool val)
static JsonPathParseItem * static JsonPathParseItem *
makeItemBinary(JsonPathItemType type, JsonPathParseItem *la, JsonPathParseItem *ra) makeItemBinary(JsonPathItemType type, JsonPathParseItem *la, JsonPathParseItem *ra)
{ {
JsonPathParseItem *v = makeItemType(type); JsonPathParseItem *v = makeItemType(type);
v->value.args.left = la; v->value.args.left = la;
v->value.args.right = ra; v->value.args.right = ra;
@ -404,7 +405,7 @@ makeItemBinary(JsonPathItemType type, JsonPathParseItem *la, JsonPathParseItem *
static JsonPathParseItem * static JsonPathParseItem *
makeItemUnary(JsonPathItemType type, JsonPathParseItem *a) makeItemUnary(JsonPathItemType type, JsonPathParseItem *a)
{ {
JsonPathParseItem *v; JsonPathParseItem *v;
if (type == jpiPlus && a->type == jpiNumeric && !a->next) if (type == jpiPlus && a->type == jpiNumeric && !a->next)
return a; return a;
@ -428,9 +429,9 @@ makeItemUnary(JsonPathItemType type, JsonPathParseItem *a)
static JsonPathParseItem * static JsonPathParseItem *
makeItemList(List *list) makeItemList(List *list)
{ {
JsonPathParseItem *head, JsonPathParseItem *head,
*end; *end;
ListCell *cell; ListCell *cell;
head = end = (JsonPathParseItem *) linitial(list); head = end = (JsonPathParseItem *) linitial(list);
@ -455,9 +456,9 @@ makeItemList(List *list)
static JsonPathParseItem * static JsonPathParseItem *
makeIndexArray(List *list) makeIndexArray(List *list)
{ {
JsonPathParseItem *v = makeItemType(jpiIndexArray); JsonPathParseItem *v = makeItemType(jpiIndexArray);
ListCell *cell; ListCell *cell;
int i = 0; int i = 0;
Assert(list_length(list) > 0); Assert(list_length(list) > 0);
v->value.array.nelems = list_length(list); v->value.array.nelems = list_length(list);
@ -467,7 +468,7 @@ makeIndexArray(List *list)
foreach(cell, list) foreach(cell, list)
{ {
JsonPathParseItem *jpi = lfirst(cell); JsonPathParseItem *jpi = lfirst(cell);
Assert(jpi->type == jpiSubscript); Assert(jpi->type == jpiSubscript);
@ -481,7 +482,7 @@ makeIndexArray(List *list)
static JsonPathParseItem * static JsonPathParseItem *
makeAny(int first, int last) makeAny(int first, int last)
{ {
JsonPathParseItem *v = makeItemType(jpiAny); JsonPathParseItem *v = makeItemType(jpiAny);
v->value.anybounds.first = (first >= 0) ? first : PG_UINT32_MAX; v->value.anybounds.first = (first >= 0) ? first : PG_UINT32_MAX;
v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX; v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX;
@ -493,9 +494,9 @@ static JsonPathParseItem *
makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern, makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
JsonPathString *flags) JsonPathString *flags)
{ {
JsonPathParseItem *v = makeItemType(jpiLikeRegex); JsonPathParseItem *v = makeItemType(jpiLikeRegex);
int i; int i;
int cflags; int cflags;
v->value.like_regex.expr = expr; v->value.like_regex.expr = expr;
v->value.like_regex.pattern = pattern->val; v->value.like_regex.pattern = pattern->val;

View File

@ -332,8 +332,8 @@ static const JsonPathKeyword keywords[] = {
static enum yytokentype static enum yytokentype
checkKeyword() checkKeyword()
{ {
int res = IDENT_P; int res = IDENT_P;
int diff; int diff;
const JsonPathKeyword *StopLow = keywords, const JsonPathKeyword *StopLow = keywords,
*StopHigh = keywords + lengthof(keywords), *StopHigh = keywords + lengthof(keywords),
*StopMiddle; *StopMiddle;

View File

@ -49,10 +49,10 @@ static sigjmp_buf *GUC_flex_fatal_jmp;
static void FreeConfigVariable(ConfigVariable *item); static void FreeConfigVariable(ConfigVariable *item);
static void record_config_file_error(const char *errmsg, static void record_config_file_error(const char *errmsg,
const char *config_file, const char *config_file,
int lineno, int lineno,
ConfigVariable **head_p, ConfigVariable **head_p,
ConfigVariable **tail_p); ConfigVariable **tail_p);
static int GUC_flex_fatal(const char *msg); static int GUC_flex_fatal(const char *msg);

View File

@ -30,7 +30,7 @@ static PgBenchExpr *make_integer_constant(int64 ival);
static PgBenchExpr *make_double_constant(double dval); static PgBenchExpr *make_double_constant(double dval);
static PgBenchExpr *make_variable(char *varname); static PgBenchExpr *make_variable(char *varname);
static PgBenchExpr *make_op(yyscan_t yyscanner, const char *operator, static PgBenchExpr *make_op(yyscan_t yyscanner, const char *operator,
PgBenchExpr *lexpr, PgBenchExpr *rexpr); PgBenchExpr *lexpr, PgBenchExpr *rexpr);
static PgBenchExpr *make_uop(yyscan_t yyscanner, const char *operator, PgBenchExpr *expr); static PgBenchExpr *make_uop(yyscan_t yyscanner, const char *operator, PgBenchExpr *expr);
static int find_func(yyscan_t yyscanner, const char *fname); static int find_func(yyscan_t yyscanner, const char *fname);
static PgBenchExpr *make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args); static PgBenchExpr *make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args);
@ -240,7 +240,7 @@ make_uop(yyscan_t yyscanner, const char *operator, PgBenchExpr *expr)
* meaning #args >= 1; * meaning #args >= 1;
* - PGBENCH_NARGS_CASE is for the "CASE WHEN ..." function, which * - PGBENCH_NARGS_CASE is for the "CASE WHEN ..." function, which
* has #args >= 3 and odd; * has #args >= 3 and odd;
* - PGBENCH_NARGS_HASH is for hash functions, which have one required * - PGBENCH_NARGS_HASH is for hash functions, which have one required
* and one optional argument; * and one optional argument;
* - tag: function identifier from PgBenchFunction enum * - tag: function identifier from PgBenchFunction enum
*/ */

View File

@ -99,9 +99,9 @@ static short preproc_tos;
static bool ifcond; static bool ifcond;
static struct _if_value static struct _if_value
{ {
bool active; bool active;
bool saw_active; bool saw_active;
bool else_branch; bool else_branch;
} stacked_if_value[MAX_NESTED_IF]; } stacked_if_value[MAX_NESTED_IF];
%} %}
@ -1031,7 +1031,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
char* endptr; char* endptr;
errno = 0; errno = 0;
base_yylval.ival = strtoul((char *)yytext,&endptr,16); base_yylval.ival = strtoul((char *) yytext, &endptr, 16);
if (*endptr != '\0' || errno == ERANGE) if (*endptr != '\0' || errno == ERANGE)
{ {
errno = 0; errno = 0;
@ -1166,7 +1166,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
*/ */
for (i = strlen(yytext)-2; for (i = strlen(yytext)-2;
i > 0 && ecpg_isspace(yytext[i]); i > 0 && ecpg_isspace(yytext[i]);
i-- ) i--)
; ;
yytext[i+1] = '\0'; yytext[i+1] = '\0';
@ -1290,7 +1290,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
} }
<C,xskip>{exec_sql}{else}{space}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */ <C,xskip>{exec_sql}{else}{space}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */
if ( preproc_tos == 0 ) if (preproc_tos == 0)
mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\""); mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
else if (stacked_if_value[preproc_tos].else_branch) else if (stacked_if_value[preproc_tos].else_branch)
mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE"); mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE");
@ -1312,7 +1312,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
/* are we simulating Informix? */ /* are we simulating Informix? */
if (INFORMIX_MODE) if (INFORMIX_MODE)
{ {
if ( preproc_tos == 0 ) if (preproc_tos == 0)
mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\""); mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
else if (stacked_if_value[preproc_tos].else_branch) else if (stacked_if_value[preproc_tos].else_branch)
mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE"); mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE");
@ -1382,7 +1382,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
*/ */
for (i = strlen(yytext)-2; for (i = strlen(yytext)-2;
i > 0 && ecpg_isspace(yytext[i]); i > 0 && ecpg_isspace(yytext[i]);
i-- ) i--)
; ;
yytext[i+1] = '\0'; yytext[i+1] = '\0';
@ -1456,7 +1456,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<<EOF>> { <<EOF>> {
if (yy_buffer == NULL) if (yy_buffer == NULL)
{ {
if ( preproc_tos > 0 ) if (preproc_tos > 0)
{ {
preproc_tos = 0; preproc_tos = 0;
mmfatal(PARSE_ERROR, "missing \"EXEC SQL ENDIF;\""); mmfatal(PARSE_ERROR, "missing \"EXEC SQL ENDIF;\"");
@ -1479,7 +1479,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
if (yyin != NULL) if (yyin != NULL)
fclose(yyin); fclose(yyin);
yy_delete_buffer( YY_CURRENT_BUFFER ); yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(yy_buffer->buffer); yy_switch_to_buffer(yy_buffer->buffer);
yylineno = yy_buffer->lineno; yylineno = yy_buffer->lineno;
@ -1661,7 +1661,7 @@ parse_include(void)
if (strcmp(inc_file + strlen(inc_file) - 2, ".h") != 0) if (strcmp(inc_file + strlen(inc_file) - 2, ".h") != 0)
{ {
strcat(inc_file, ".h"); strcat(inc_file, ".h");
yyin = fopen( inc_file, "r" ); yyin = fopen(inc_file, "r");
} }
} }
/* if the command was "include_next" we have to disregard the first hit */ /* if the command was "include_next" we have to disregard the first hit */
@ -1677,7 +1677,7 @@ parse_include(void)
mmfatal(NO_INCLUDE_FILE, "could not open include file \"%s\" on line %d", yytext, yylineno); mmfatal(NO_INCLUDE_FILE, "could not open include file \"%s\" on line %d", yytext, yylineno);
input_filename = mm_strdup(inc_file); input_filename = mm_strdup(inc_file);
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE )); yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
yylineno = 1; yylineno = 1;
output_line_number(); output_line_number();

View File

@ -116,55 +116,56 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
%name-prefix="plpgsql_yy" %name-prefix="plpgsql_yy"
%locations %locations
%union { %union
core_YYSTYPE core_yystype; {
/* these fields must match core_YYSTYPE: */ core_YYSTYPE core_yystype;
int ival; /* these fields must match core_YYSTYPE: */
char *str; int ival;
const char *keyword; char *str;
const char *keyword;
PLword word; PLword word;
PLcword cword; PLcword cword;
PLwdatum wdatum; PLwdatum wdatum;
bool boolean; bool boolean;
Oid oid; Oid oid;
struct struct
{ {
char *name; char *name;
int lineno; int lineno;
} varname; } varname;
struct struct
{ {
char *name; char *name;
int lineno; int lineno;
PLpgSQL_datum *scalar; PLpgSQL_datum *scalar;
PLpgSQL_datum *row; PLpgSQL_datum *row;
} forvariable; } forvariable;
struct struct
{ {
char *label; char *label;
int n_initvars; int n_initvars;
int *initvarnos; int *initvarnos;
} declhdr; } declhdr;
struct struct
{ {
List *stmts; List *stmts;
char *end_label; char *end_label;
int end_label_location; int end_label_location;
} loop_body; } loop_body;
List *list; List *list;
PLpgSQL_type *dtype; PLpgSQL_type *dtype;
PLpgSQL_datum *datum; PLpgSQL_datum *datum;
PLpgSQL_var *var; PLpgSQL_var *var;
PLpgSQL_expr *expr; PLpgSQL_expr *expr;
PLpgSQL_stmt *stmt; PLpgSQL_stmt *stmt;
PLpgSQL_condition *condition; PLpgSQL_condition *condition;
PLpgSQL_exception *exception; PLpgSQL_exception *exception;
PLpgSQL_exception_block *exception_block; PLpgSQL_exception_block *exception_block;
PLpgSQL_nsitem *nsitem; PLpgSQL_nsitem *nsitem;
PLpgSQL_diag_item *diagitem; PLpgSQL_diag_item *diagitem;
PLpgSQL_stmt_fetch *fetch; PLpgSQL_stmt_fetch *fetch;
PLpgSQL_case_when *casewhen; PLpgSQL_case_when *casewhen;
} }
%type <declhdr> decl_sect %type <declhdr> decl_sect
@ -425,7 +426,7 @@ pl_block : decl_sect K_BEGIN proc_sect exception_sect K_END opt_label
check_labels($1.label, $6, @6); check_labels($1.label, $6, @6);
plpgsql_ns_pop(); plpgsql_ns_pop();
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -538,8 +539,8 @@ decl_statement : decl_varname decl_const decl_datatype decl_collate decl_notnull
PLpgSQL_var *new; PLpgSQL_var *new;
PLpgSQL_expr *curname_def; PLpgSQL_expr *curname_def;
char buf[NAMEDATALEN * 2 + 64]; char buf[NAMEDATALEN * 2 + 64];
char *cp1; char *cp1;
char *cp2; char *cp2;
/* pop local namespace for cursor args */ /* pop local namespace for cursor args */
plpgsql_ns_pop(); plpgsql_ns_pop();
@ -611,8 +612,8 @@ decl_cursor_args :
| '(' decl_cursor_arglist ')' | '(' decl_cursor_arglist ')'
{ {
PLpgSQL_row *new; PLpgSQL_row *new;
int i; int i;
ListCell *l; ListCell *l;
new = palloc0(sizeof(PLpgSQL_row)); new = palloc0(sizeof(PLpgSQL_row));
new->dtype = PLPGSQL_DTYPE_ROW; new->dtype = PLPGSQL_DTYPE_ROW;
@ -903,7 +904,7 @@ proc_stmt : pl_block ';'
stmt_perform : K_PERFORM stmt_perform : K_PERFORM
{ {
PLpgSQL_stmt_perform *new; PLpgSQL_stmt_perform *new;
int startloc; int startloc;
new = palloc0(sizeof(PLpgSQL_stmt_perform)); new = palloc0(sizeof(PLpgSQL_stmt_perform));
new->cmd_type = PLPGSQL_STMT_PERFORM; new->cmd_type = PLPGSQL_STMT_PERFORM;
@ -932,7 +933,7 @@ stmt_perform : K_PERFORM
check_sql_expr(new->expr->query, new->expr->parseMode, check_sql_expr(new->expr->query, new->expr->parseMode,
startloc + 1); startloc + 1);
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -951,7 +952,7 @@ stmt_call : K_CALL
/* Remember we may need a procedure resource owner */ /* Remember we may need a procedure resource owner */
plpgsql_curr_compile->requires_procedure_resowner = true; plpgsql_curr_compile->requires_procedure_resowner = true;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
| K_DO | K_DO
@ -970,7 +971,7 @@ stmt_call : K_CALL
/* Remember we may need a procedure resource owner */ /* Remember we may need a procedure resource owner */
plpgsql_curr_compile->requires_procedure_resowner = true; plpgsql_curr_compile->requires_procedure_resowner = true;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1000,7 +1001,7 @@ stmt_assign : T_DATUM
check_assignable($1.datum, @1); check_assignable($1.datum, @1);
new = palloc0(sizeof(PLpgSQL_stmt_assign)); new = palloc0(sizeof(PLpgSQL_stmt_assign));
new->cmd_type = PLPGSQL_STMT_ASSIGN; new->cmd_type = PLPGSQL_STMT_ASSIGN;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->varno = $1.datum->dno; new->varno = $1.datum->dno;
/* Push back the head name to include it in the stmt */ /* Push back the head name to include it in the stmt */
@ -1010,19 +1011,19 @@ stmt_assign : T_DATUM
false, true, true, false, true, true,
NULL, NULL); NULL, NULL);
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';' stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';'
{ {
PLpgSQL_stmt_getdiag *new; PLpgSQL_stmt_getdiag *new;
ListCell *lc; ListCell *lc;
new = palloc0(sizeof(PLpgSQL_stmt_getdiag)); new = palloc0(sizeof(PLpgSQL_stmt_getdiag));
new->cmd_type = PLPGSQL_STMT_GETDIAG; new->cmd_type = PLPGSQL_STMT_GETDIAG;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->is_stacked = $2; new->is_stacked = $2;
new->diag_items = $4; new->diag_items = $4;
@ -1072,7 +1073,7 @@ stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';'
} }
} }
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1114,7 +1115,7 @@ getdiag_list_item : getdiag_target assign_operator getdiag_item
getdiag_item : getdiag_item :
{ {
int tok = yylex(); int tok = yylex();
if (tok_is_keyword(tok, &yylval, if (tok_is_keyword(tok, &yylval,
K_ROW_COUNT, "row_count")) K_ROW_COUNT, "row_count"))
@ -1192,15 +1193,15 @@ stmt_if : K_IF expr_until_then proc_sect stmt_elsifs stmt_else K_END K_IF ';'
PLpgSQL_stmt_if *new; PLpgSQL_stmt_if *new;
new = palloc0(sizeof(PLpgSQL_stmt_if)); new = palloc0(sizeof(PLpgSQL_stmt_if));
new->cmd_type = PLPGSQL_STMT_IF; new->cmd_type = PLPGSQL_STMT_IF;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->cond = $2; new->cond = $2;
new->then_body = $3; new->then_body = $3;
new->elsif_list = $4; new->elsif_list = $4;
new->else_body = $5; new->else_body = $5;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1214,8 +1215,8 @@ stmt_elsifs :
new = palloc0(sizeof(PLpgSQL_if_elsif)); new = palloc0(sizeof(PLpgSQL_if_elsif));
new->lineno = plpgsql_location_to_lineno(@2); new->lineno = plpgsql_location_to_lineno(@2);
new->cond = $3; new->cond = $3;
new->stmts = $4; new->stmts = $4;
$$ = lappend($1, new); $$ = lappend($1, new);
} }
@ -1240,7 +1241,7 @@ stmt_case : K_CASE opt_expr_until_when case_when_list opt_case_else K_END K_CAS
opt_expr_until_when : opt_expr_until_when :
{ {
PLpgSQL_expr *expr = NULL; PLpgSQL_expr *expr = NULL;
int tok = yylex(); int tok = yylex();
if (tok != K_WHEN) if (tok != K_WHEN)
{ {
@ -1267,8 +1268,8 @@ case_when : K_WHEN expr_until_then proc_sect
PLpgSQL_case_when *new = palloc(sizeof(PLpgSQL_case_when)); PLpgSQL_case_when *new = palloc(sizeof(PLpgSQL_case_when));
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->expr = $2; new->expr = $2;
new->stmts = $3; new->stmts = $3;
$$ = new; $$ = new;
} }
; ;
@ -1298,15 +1299,15 @@ stmt_loop : opt_loop_label K_LOOP loop_body
new = palloc0(sizeof(PLpgSQL_stmt_loop)); new = palloc0(sizeof(PLpgSQL_stmt_loop));
new->cmd_type = PLPGSQL_STMT_LOOP; new->cmd_type = PLPGSQL_STMT_LOOP;
new->lineno = plpgsql_location_to_lineno(@2); new->lineno = plpgsql_location_to_lineno(@2);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->label = $1; new->label = $1;
new->body = $3.stmts; new->body = $3.stmts;
check_labels($1, $3.end_label, $3.end_label_location); check_labels($1, $3.end_label, $3.end_label_location);
plpgsql_ns_pop(); plpgsql_ns_pop();
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1316,16 +1317,16 @@ stmt_while : opt_loop_label K_WHILE expr_until_loop loop_body
new = palloc0(sizeof(PLpgSQL_stmt_while)); new = palloc0(sizeof(PLpgSQL_stmt_while));
new->cmd_type = PLPGSQL_STMT_WHILE; new->cmd_type = PLPGSQL_STMT_WHILE;
new->lineno = plpgsql_location_to_lineno(@2); new->lineno = plpgsql_location_to_lineno(@2);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->label = $1; new->label = $1;
new->cond = $3; new->cond = $3;
new->body = $4.stmts; new->body = $4.stmts;
check_labels($1, $4.end_label, $4.end_label_location); check_labels($1, $4.end_label, $4.end_label_location);
plpgsql_ns_pop(); plpgsql_ns_pop();
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1334,26 +1335,26 @@ stmt_for : opt_loop_label K_FOR for_control loop_body
/* This runs after we've scanned the loop body */ /* This runs after we've scanned the loop body */
if ($3->cmd_type == PLPGSQL_STMT_FORI) if ($3->cmd_type == PLPGSQL_STMT_FORI)
{ {
PLpgSQL_stmt_fori *new; PLpgSQL_stmt_fori *new;
new = (PLpgSQL_stmt_fori *) $3; new = (PLpgSQL_stmt_fori *) $3;
new->lineno = plpgsql_location_to_lineno(@2); new->lineno = plpgsql_location_to_lineno(@2);
new->label = $1; new->label = $1;
new->body = $4.stmts; new->body = $4.stmts;
$$ = (PLpgSQL_stmt *) new; $$ = (PLpgSQL_stmt *) new;
} }
else else
{ {
PLpgSQL_stmt_forq *new; PLpgSQL_stmt_forq *new;
Assert($3->cmd_type == PLPGSQL_STMT_FORS || Assert($3->cmd_type == PLPGSQL_STMT_FORS ||
$3->cmd_type == PLPGSQL_STMT_FORC || $3->cmd_type == PLPGSQL_STMT_FORC ||
$3->cmd_type == PLPGSQL_STMT_DYNFORS); $3->cmd_type == PLPGSQL_STMT_DYNFORS);
/* forq is the common supertype of all three */ /* forq is the common supertype of all three */
new = (PLpgSQL_stmt_forq *) $3; new = (PLpgSQL_stmt_forq *) $3;
new->lineno = plpgsql_location_to_lineno(@2); new->lineno = plpgsql_location_to_lineno(@2);
new->label = $1; new->label = $1;
new->body = $4.stmts; new->body = $4.stmts;
$$ = (PLpgSQL_stmt *) new; $$ = (PLpgSQL_stmt *) new;
} }
@ -1371,9 +1372,9 @@ for_control : for_variable K_IN
if (tok == K_EXECUTE) if (tok == K_EXECUTE)
{ {
/* EXECUTE means it's a dynamic FOR loop */ /* EXECUTE means it's a dynamic FOR loop */
PLpgSQL_stmt_dynfors *new; PLpgSQL_stmt_dynfors *new;
PLpgSQL_expr *expr; PLpgSQL_expr *expr;
int term; int term;
expr = read_sql_expression2(K_LOOP, K_USING, expr = read_sql_expression2(K_LOOP, K_USING,
"LOOP or USING", "LOOP or USING",
@ -1381,7 +1382,7 @@ for_control : for_variable K_IN
new = palloc0(sizeof(PLpgSQL_stmt_dynfors)); new = palloc0(sizeof(PLpgSQL_stmt_dynfors));
new->cmd_type = PLPGSQL_STMT_DYNFORS; new->cmd_type = PLPGSQL_STMT_DYNFORS;
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
if ($1.row) if ($1.row)
{ {
new->var = (PLpgSQL_variable *) $1.row; new->var = (PLpgSQL_variable *) $1.row;
@ -1422,8 +1423,8 @@ for_control : for_variable K_IN
((PLpgSQL_var *) yylval.wdatum.datum)->datatype->typoid == REFCURSOROID) ((PLpgSQL_var *) yylval.wdatum.datum)->datatype->typoid == REFCURSOROID)
{ {
/* It's FOR var IN cursor */ /* It's FOR var IN cursor */
PLpgSQL_stmt_forc *new; PLpgSQL_stmt_forc *new;
PLpgSQL_var *cursor = (PLpgSQL_var *) yylval.wdatum.datum; PLpgSQL_var *cursor = (PLpgSQL_var *) yylval.wdatum.datum;
new = (PLpgSQL_stmt_forc *) palloc0(sizeof(PLpgSQL_stmt_forc)); new = (PLpgSQL_stmt_forc *) palloc0(sizeof(PLpgSQL_stmt_forc));
new->cmd_type = PLPGSQL_STMT_FORC; new->cmd_type = PLPGSQL_STMT_FORC;
@ -1460,9 +1461,9 @@ for_control : for_variable K_IN
} }
else else
{ {
PLpgSQL_expr *expr1; PLpgSQL_expr *expr1;
int expr1loc; int expr1loc;
bool reverse = false; bool reverse = false;
/* /*
* We have to distinguish between two * We have to distinguish between two
@ -1503,10 +1504,10 @@ for_control : for_variable K_IN
if (tok == DOT_DOT) if (tok == DOT_DOT)
{ {
/* Saw "..", so it must be an integer loop */ /* Saw "..", so it must be an integer loop */
PLpgSQL_expr *expr2; PLpgSQL_expr *expr2;
PLpgSQL_expr *expr_by; PLpgSQL_expr *expr_by;
PLpgSQL_var *fvar; PLpgSQL_var *fvar;
PLpgSQL_stmt_fori *new; PLpgSQL_stmt_fori *new;
/* /*
* Relabel first expression as an expression; * Relabel first expression as an expression;
@ -1547,12 +1548,12 @@ for_control : for_variable K_IN
new = palloc0(sizeof(PLpgSQL_stmt_fori)); new = palloc0(sizeof(PLpgSQL_stmt_fori));
new->cmd_type = PLPGSQL_STMT_FORI; new->cmd_type = PLPGSQL_STMT_FORI;
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->var = fvar; new->var = fvar;
new->reverse = reverse; new->reverse = reverse;
new->lower = expr1; new->lower = expr1;
new->upper = expr2; new->upper = expr2;
new->step = expr_by; new->step = expr_by;
$$ = (PLpgSQL_stmt *) new; $$ = (PLpgSQL_stmt *) new;
} }
@ -1561,7 +1562,7 @@ for_control : for_variable K_IN
/* /*
* No "..", so it must be a query loop. * No "..", so it must be a query loop.
*/ */
PLpgSQL_stmt_fors *new; PLpgSQL_stmt_fors *new;
if (reverse) if (reverse)
ereport(ERROR, ereport(ERROR,
@ -1723,11 +1724,11 @@ stmt_exit : exit_type opt_label opt_exitcond
new = palloc0(sizeof(PLpgSQL_stmt_exit)); new = palloc0(sizeof(PLpgSQL_stmt_exit));
new->cmd_type = PLPGSQL_STMT_EXIT; new->cmd_type = PLPGSQL_STMT_EXIT;
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->is_exit = $1; new->is_exit = $1;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->label = $2; new->label = $2;
new->cond = $3; new->cond = $3;
if ($2) if ($2)
{ {
@ -1766,7 +1767,7 @@ stmt_exit : exit_type opt_label opt_exitcond
parser_errposition(@1))); parser_errposition(@1)));
} }
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -1782,7 +1783,7 @@ exit_type : K_EXIT
stmt_return : K_RETURN stmt_return : K_RETURN
{ {
int tok; int tok;
tok = yylex(); tok = yylex();
if (tok == 0) if (tok == 0)
@ -1808,19 +1809,19 @@ stmt_return : K_RETURN
stmt_raise : K_RAISE stmt_raise : K_RAISE
{ {
PLpgSQL_stmt_raise *new; PLpgSQL_stmt_raise *new;
int tok; int tok;
new = palloc(sizeof(PLpgSQL_stmt_raise)); new = palloc(sizeof(PLpgSQL_stmt_raise));
new->cmd_type = PLPGSQL_STMT_RAISE; new->cmd_type = PLPGSQL_STMT_RAISE;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->elog_level = ERROR; /* default */ new->elog_level = ERROR; /* default */
new->condname = NULL; new->condname = NULL;
new->message = NULL; new->message = NULL;
new->params = NIL; new->params = NIL;
new->options = NIL; new->options = NIL;
tok = yylex(); tok = yylex();
if (tok == 0) if (tok == 0)
@ -1913,7 +1914,7 @@ stmt_raise : K_RAISE
K_SQLSTATE, "sqlstate")) K_SQLSTATE, "sqlstate"))
{ {
/* next token should be a string literal */ /* next token should be a string literal */
char *sqlstatestr; char *sqlstatestr;
if (yylex() != SCONST) if (yylex() != SCONST)
yyerror("syntax error"); yyerror("syntax error");
@ -1947,20 +1948,20 @@ stmt_raise : K_RAISE
check_raise_parameters(new); check_raise_parameters(new);
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
stmt_assert : K_ASSERT stmt_assert : K_ASSERT
{ {
PLpgSQL_stmt_assert *new; PLpgSQL_stmt_assert *new;
int tok; int tok;
new = palloc(sizeof(PLpgSQL_stmt_assert)); new = palloc(sizeof(PLpgSQL_stmt_assert));
new->cmd_type = PLPGSQL_STMT_ASSERT; new->cmd_type = PLPGSQL_STMT_ASSERT;
new->lineno = plpgsql_location_to_lineno(@1); new->lineno = plpgsql_location_to_lineno(@1);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->cond = read_sql_expression2(',', ';', new->cond = read_sql_expression2(',', ';',
", or ;", ", or ;",
@ -2033,7 +2034,7 @@ stmt_dynexecute : K_EXECUTE
{ {
PLpgSQL_stmt_dynexecute *new; PLpgSQL_stmt_dynexecute *new;
PLpgSQL_expr *expr; PLpgSQL_expr *expr;
int endtoken; int endtoken;
expr = read_sql_construct(K_INTO, K_USING, ';', expr = read_sql_construct(K_INTO, K_USING, ';',
"INTO or USING or ;", "INTO or USING or ;",
@ -2088,7 +2089,7 @@ stmt_dynexecute : K_EXECUTE
yyerror("syntax error"); yyerror("syntax error");
} }
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -2096,7 +2097,7 @@ stmt_dynexecute : K_EXECUTE
stmt_open : K_OPEN cursor_variable stmt_open : K_OPEN cursor_variable
{ {
PLpgSQL_stmt_open *new; PLpgSQL_stmt_open *new;
int tok; int tok;
new = palloc0(sizeof(PLpgSQL_stmt_open)); new = palloc0(sizeof(PLpgSQL_stmt_open));
new->cmd_type = PLPGSQL_STMT_OPEN; new->cmd_type = PLPGSQL_STMT_OPEN;
@ -2133,7 +2134,7 @@ stmt_open : K_OPEN cursor_variable
tok = yylex(); tok = yylex();
if (tok == K_EXECUTE) if (tok == K_EXECUTE)
{ {
int endtoken; int endtoken;
new->dynquery = new->dynquery =
read_sql_expression2(K_USING, ';', read_sql_expression2(K_USING, ';',
@ -2167,7 +2168,7 @@ stmt_open : K_OPEN cursor_variable
new->argquery = read_cursor_args($2, ';'); new->argquery = read_cursor_args($2, ';');
} }
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -2197,7 +2198,7 @@ stmt_fetch : K_FETCH opt_fetch_direction cursor_variable K_INTO
fetch->curvar = $3->dno; fetch->curvar = $3->dno;
fetch->is_move = false; fetch->is_move = false;
$$ = (PLpgSQL_stmt *)fetch; $$ = (PLpgSQL_stmt *) fetch;
} }
; ;
@ -2206,10 +2207,10 @@ stmt_move : K_MOVE opt_fetch_direction cursor_variable ';'
PLpgSQL_stmt_fetch *fetch = $2; PLpgSQL_stmt_fetch *fetch = $2;
fetch->lineno = plpgsql_location_to_lineno(@1); fetch->lineno = plpgsql_location_to_lineno(@1);
fetch->curvar = $3->dno; fetch->curvar = $3->dno;
fetch->is_move = true; fetch->is_move = true;
$$ = (PLpgSQL_stmt *)fetch; $$ = (PLpgSQL_stmt *) fetch;
} }
; ;
@ -2229,7 +2230,7 @@ stmt_close : K_CLOSE cursor_variable ';'
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->curvar = $2->dno; new->curvar = $2->dno;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -2250,7 +2251,7 @@ stmt_commit : K_COMMIT opt_transaction_chain ';'
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->chain = $2; new->chain = $2;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -2264,7 +2265,7 @@ stmt_rollback : K_ROLLBACK opt_transaction_chain ';'
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->chain = $2; new->chain = $2;
$$ = (PLpgSQL_stmt *)new; $$ = (PLpgSQL_stmt *) new;
} }
; ;
@ -2710,12 +2711,12 @@ read_sql_construct(int until,
int *startloc, int *startloc,
int *endtoken) int *endtoken)
{ {
int tok; int tok;
StringInfoData ds; StringInfoData ds;
IdentifierLookup save_IdentifierLookup; IdentifierLookup save_IdentifierLookup;
int startlocation = -1; int startlocation = -1;
int parenlevel = 0; int parenlevel = 0;
PLpgSQL_expr *expr; PLpgSQL_expr *expr;
initStringInfo(&ds); initStringInfo(&ds);
@ -2792,12 +2793,12 @@ read_sql_construct(int until,
} }
expr = palloc0(sizeof(PLpgSQL_expr)); expr = palloc0(sizeof(PLpgSQL_expr));
expr->query = pstrdup(ds.data); expr->query = pstrdup(ds.data);
expr->parseMode = parsemode; expr->parseMode = parsemode;
expr->plan = NULL; expr->plan = NULL;
expr->paramnos = NULL; expr->paramnos = NULL;
expr->target_param = -1; expr->target_param = -1;
expr->ns = plpgsql_ns_top(); expr->ns = plpgsql_ns_top();
pfree(ds.data); pfree(ds.data);
if (valid_sql) if (valid_sql)
@ -2809,11 +2810,11 @@ read_sql_construct(int until,
static PLpgSQL_type * static PLpgSQL_type *
read_datatype(int tok) read_datatype(int tok)
{ {
StringInfoData ds; StringInfoData ds;
char *type_name; char *type_name;
int startlocation; int startlocation;
PLpgSQL_type *result; PLpgSQL_type *result;
int parenlevel = 0; int parenlevel = 0;
/* Should only be called while parsing DECLARE sections */ /* Should only be called while parsing DECLARE sections */
Assert(plpgsql_IdentifierLookup == IDENTIFIER_LOOKUP_DECLARE); Assert(plpgsql_IdentifierLookup == IDENTIFIER_LOOKUP_DECLARE);
@ -2830,7 +2831,7 @@ read_datatype(int tok)
*/ */
if (tok == T_WORD) if (tok == T_WORD)
{ {
char *dtname = yylval.word.ident; char *dtname = yylval.word.ident;
tok = yylex(); tok = yylex();
if (tok == '%') if (tok == '%')
@ -2854,7 +2855,7 @@ read_datatype(int tok)
} }
else if (plpgsql_token_is_unreserved_keyword(tok)) else if (plpgsql_token_is_unreserved_keyword(tok))
{ {
char *dtname = pstrdup(yylval.keyword); char *dtname = pstrdup(yylval.keyword);
tok = yylex(); tok = yylex();
if (tok == '%') if (tok == '%')
@ -2878,7 +2879,7 @@ read_datatype(int tok)
} }
else if (tok == T_CWORD) else if (tok == T_CWORD)
{ {
List *dtnames = yylval.cword.idents; List *dtnames = yylval.cword.idents;
tok = yylex(); tok = yylex();
if (tok == '%') if (tok == '%')
@ -2945,17 +2946,17 @@ read_datatype(int tok)
static PLpgSQL_stmt * static PLpgSQL_stmt *
make_execsql_stmt(int firsttoken, int location) make_execsql_stmt(int firsttoken, int location)
{ {
StringInfoData ds; StringInfoData ds;
IdentifierLookup save_IdentifierLookup; IdentifierLookup save_IdentifierLookup;
PLpgSQL_stmt_execsql *execsql; PLpgSQL_stmt_execsql *execsql;
PLpgSQL_expr *expr; PLpgSQL_expr *expr;
PLpgSQL_variable *target = NULL; PLpgSQL_variable *target = NULL;
int tok; int tok;
int prev_tok; int prev_tok;
bool have_into = false; bool have_into = false;
bool have_strict = false; bool have_strict = false;
int into_start_loc = -1; int into_start_loc = -1;
int into_end_loc = -1; int into_end_loc = -1;
initStringInfo(&ds); initStringInfo(&ds);
@ -3041,24 +3042,24 @@ make_execsql_stmt(int firsttoken, int location)
ds.data[--ds.len] = '\0'; ds.data[--ds.len] = '\0';
expr = palloc0(sizeof(PLpgSQL_expr)); expr = palloc0(sizeof(PLpgSQL_expr));
expr->query = pstrdup(ds.data); expr->query = pstrdup(ds.data);
expr->parseMode = RAW_PARSE_DEFAULT; expr->parseMode = RAW_PARSE_DEFAULT;
expr->plan = NULL; expr->plan = NULL;
expr->paramnos = NULL; expr->paramnos = NULL;
expr->target_param = -1; expr->target_param = -1;
expr->ns = plpgsql_ns_top(); expr->ns = plpgsql_ns_top();
pfree(ds.data); pfree(ds.data);
check_sql_expr(expr->query, expr->parseMode, location); check_sql_expr(expr->query, expr->parseMode, location);
execsql = palloc0(sizeof(PLpgSQL_stmt_execsql)); execsql = palloc0(sizeof(PLpgSQL_stmt_execsql));
execsql->cmd_type = PLPGSQL_STMT_EXECSQL; execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
execsql->lineno = plpgsql_location_to_lineno(location); execsql->lineno = plpgsql_location_to_lineno(location);
execsql->stmtid = ++plpgsql_curr_compile->nstatements; execsql->stmtid = ++plpgsql_curr_compile->nstatements;
execsql->sqlstmt = expr; execsql->sqlstmt = expr;
execsql->into = have_into; execsql->into = have_into;
execsql->strict = have_strict; execsql->strict = have_strict;
execsql->target = target; execsql->target = target;
return (PLpgSQL_stmt *) execsql; return (PLpgSQL_stmt *) execsql;
} }
@ -3080,11 +3081,11 @@ read_fetch_direction(void)
*/ */
fetch = (PLpgSQL_stmt_fetch *) palloc0(sizeof(PLpgSQL_stmt_fetch)); fetch = (PLpgSQL_stmt_fetch *) palloc0(sizeof(PLpgSQL_stmt_fetch));
fetch->cmd_type = PLPGSQL_STMT_FETCH; fetch->cmd_type = PLPGSQL_STMT_FETCH;
fetch->stmtid = ++plpgsql_curr_compile->nstatements; fetch->stmtid = ++plpgsql_curr_compile->nstatements;
/* set direction defaults: */ /* set direction defaults: */
fetch->direction = FETCH_FORWARD; fetch->direction = FETCH_FORWARD;
fetch->how_many = 1; fetch->how_many = 1;
fetch->expr = NULL; fetch->expr = NULL;
fetch->returns_multiple_rows = false; fetch->returns_multiple_rows = false;
tok = yylex(); tok = yylex();
@ -3232,9 +3233,9 @@ make_return_stmt(int location)
new = palloc0(sizeof(PLpgSQL_stmt_return)); new = palloc0(sizeof(PLpgSQL_stmt_return));
new->cmd_type = PLPGSQL_STMT_RETURN; new->cmd_type = PLPGSQL_STMT_RETURN;
new->lineno = plpgsql_location_to_lineno(location); new->lineno = plpgsql_location_to_lineno(location);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->expr = NULL; new->expr = NULL;
new->retvarno = -1; new->retvarno = -1;
if (plpgsql_curr_compile->fn_retset) if (plpgsql_curr_compile->fn_retset)
@ -3277,7 +3278,7 @@ make_return_stmt(int location)
* We want to special-case simple variable references for efficiency. * We want to special-case simple variable references for efficiency.
* So peek ahead to see if that's what we have. * So peek ahead to see if that's what we have.
*/ */
int tok = yylex(); int tok = yylex();
if (tok == T_DATUM && plpgsql_peek() == ';' && if (tok == T_DATUM && plpgsql_peek() == ';' &&
(yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR || (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
@ -3319,11 +3320,11 @@ make_return_next_stmt(int location)
parser_errposition(location))); parser_errposition(location)));
new = palloc0(sizeof(PLpgSQL_stmt_return_next)); new = palloc0(sizeof(PLpgSQL_stmt_return_next));
new->cmd_type = PLPGSQL_STMT_RETURN_NEXT; new->cmd_type = PLPGSQL_STMT_RETURN_NEXT;
new->lineno = plpgsql_location_to_lineno(location); new->lineno = plpgsql_location_to_lineno(location);
new->stmtid = ++plpgsql_curr_compile->nstatements; new->stmtid = ++plpgsql_curr_compile->nstatements;
new->expr = NULL; new->expr = NULL;
new->retvarno = -1; new->retvarno = -1;
if (plpgsql_curr_compile->out_param_varno >= 0) if (plpgsql_curr_compile->out_param_varno >= 0)
{ {
@ -3340,7 +3341,7 @@ make_return_next_stmt(int location)
* We want to special-case simple variable references for efficiency. * We want to special-case simple variable references for efficiency.
* So peek ahead to see if that's what we have. * So peek ahead to see if that's what we have.
*/ */
int tok = yylex(); int tok = yylex();
if (tok == T_DATUM && plpgsql_peek() == ';' && if (tok == T_DATUM && plpgsql_peek() == ';' &&
(yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR || (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
@ -3397,7 +3398,7 @@ make_return_query_stmt(int location)
else else
{ {
/* dynamic SQL */ /* dynamic SQL */
int term; int term;
new->dynquery = read_sql_expression2(';', K_USING, "; or USING", new->dynquery = read_sql_expression2(';', K_USING, "; or USING",
&term); &term);
@ -3525,16 +3526,16 @@ read_into_scalar_list(char *initial_name,
PLpgSQL_datum *initial_datum, PLpgSQL_datum *initial_datum,
int initial_location) int initial_location)
{ {
int nfields; int nfields;
char *fieldnames[1024]; char *fieldnames[1024];
int varnos[1024]; int varnos[1024];
PLpgSQL_row *row; PLpgSQL_row *row;
int tok; int tok;
check_assignable(initial_datum, initial_location); check_assignable(initial_datum, initial_location);
fieldnames[0] = initial_name; fieldnames[0] = initial_name;
varnos[0] = initial_datum->dno; varnos[0] = initial_datum->dno;
nfields = 1; nfields = 1;
while ((tok = yylex()) == ',') while ((tok = yylex()) == ',')
{ {
@ -3587,7 +3588,7 @@ read_into_scalar_list(char *initial_name,
row->varnos[nfields] = varnos[nfields]; row->varnos[nfields] = varnos[nfields];
} }
plpgsql_adddatum((PLpgSQL_datum *)row); plpgsql_adddatum((PLpgSQL_datum *) row);
return row; return row;
} }
@ -3604,7 +3605,7 @@ make_scalar_list1(char *initial_name,
PLpgSQL_datum *initial_datum, PLpgSQL_datum *initial_datum,
int lineno, int location) int lineno, int location)
{ {
PLpgSQL_row *row; PLpgSQL_row *row;
check_assignable(initial_datum, location); check_assignable(initial_datum, location);
@ -3619,7 +3620,7 @@ make_scalar_list1(char *initial_name,
row->fieldnames[0] = initial_name; row->fieldnames[0] = initial_name;
row->varnos[0] = initial_datum->dno; row->varnos[0] = initial_datum->dno;
plpgsql_adddatum((PLpgSQL_datum *)row); plpgsql_adddatum((PLpgSQL_datum *) row);
return row; return row;
} }
@ -3691,7 +3692,7 @@ plpgsql_sql_error_callback(void *arg)
errpos = geterrposition(); errpos = geterrposition();
if (errpos > 0) if (errpos > 0)
{ {
int myerrpos = getinternalerrposition(); int myerrpos = getinternalerrposition();
if (myerrpos > 0) /* safety check */ if (myerrpos > 0) /* safety check */
internalerrposition(myerrpos + errpos - 1); internalerrposition(myerrpos + errpos - 1);
@ -3818,11 +3819,11 @@ read_cursor_args(PLpgSQL_var *cursor, int until)
for (argc = 0; argc < row->nfields; argc++) for (argc = 0; argc < row->nfields; argc++)
{ {
PLpgSQL_expr *item; PLpgSQL_expr *item;
int endtoken; int endtoken;
int argpos; int argpos;
int tok1, int tok1,
tok2; tok2;
int arglocation; int arglocation;
/* Check if it's a named parameter: "param := value" */ /* Check if it's a named parameter: "param := value" */
plpgsql_peek2(&tok1, &tok2, &arglocation, NULL); plpgsql_peek2(&tok1, &tok2, &arglocation, NULL);
@ -3923,12 +3924,12 @@ read_cursor_args(PLpgSQL_var *cursor, int until)
} }
expr = palloc0(sizeof(PLpgSQL_expr)); expr = palloc0(sizeof(PLpgSQL_expr));
expr->query = pstrdup(ds.data); expr->query = pstrdup(ds.data);
expr->parseMode = RAW_PARSE_PLPGSQL_EXPR; expr->parseMode = RAW_PARSE_PLPGSQL_EXPR;
expr->plan = NULL; expr->plan = NULL;
expr->paramnos = NULL; expr->paramnos = NULL;
expr->target_param = -1; expr->target_param = -1;
expr->ns = plpgsql_ns_top(); expr->ns = plpgsql_ns_top();
pfree(ds.data); pfree(ds.data);
/* Next we'd better find the until token */ /* Next we'd better find the until token */
@ -3950,7 +3951,7 @@ read_raise_options(void)
for (;;) for (;;)
{ {
PLpgSQL_raise_option *opt; PLpgSQL_raise_option *opt;
int tok; int tok;
if ((tok = yylex()) == 0) if ((tok = yylex()) == 0)
yyerror("unexpected end of function definition"); yyerror("unexpected end of function definition");
@ -4044,7 +4045,7 @@ static PLpgSQL_stmt *
make_case(int location, PLpgSQL_expr *t_expr, make_case(int location, PLpgSQL_expr *t_expr,
List *case_when_list, List *else_stmts) List *case_when_list, List *else_stmts)
{ {
PLpgSQL_stmt_case *new; PLpgSQL_stmt_case *new;
new = palloc(sizeof(PLpgSQL_stmt_case)); new = palloc(sizeof(PLpgSQL_stmt_case));
new->cmd_type = PLPGSQL_STMT_CASE; new->cmd_type = PLPGSQL_STMT_CASE;
@ -4070,9 +4071,9 @@ make_case(int location, PLpgSQL_expr *t_expr,
*/ */
if (t_expr) if (t_expr)
{ {
char varname[32]; char varname[32];
PLpgSQL_var *t_var; PLpgSQL_var *t_var;
ListCell *l; ListCell *l;
/* use a name unlikely to collide with any user names */ /* use a name unlikely to collide with any user names */
snprintf(varname, sizeof(varname), "__Case__Variable_%d__", snprintf(varname, sizeof(varname), "__Case__Variable_%d__",
@ -4095,7 +4096,7 @@ make_case(int location, PLpgSQL_expr *t_expr,
{ {
PLpgSQL_case_when *cwt = (PLpgSQL_case_when *) lfirst(l); PLpgSQL_case_when *cwt = (PLpgSQL_case_when *) lfirst(l);
PLpgSQL_expr *expr = cwt->expr; PLpgSQL_expr *expr = cwt->expr;
StringInfoData ds; StringInfoData ds;
/* We expect to have expressions not statements */ /* We expect to have expressions not statements */
Assert(expr->parseMode == RAW_PARSE_PLPGSQL_EXPR); Assert(expr->parseMode == RAW_PARSE_PLPGSQL_EXPR);