Partial pgindent of .l and .y files

Trying to clean up the code a bit while we're working on these files
for the reentrant scanner/pure parser patches.  This cleanup only
touches the code sections after the second '%%' in each file, via a
manually-supervised and locally hacked up pgindent.
This commit is contained in:
Peter Eisentraut 2024-12-25 17:52:42 +01:00
parent 2571c1d5cc
commit 301de6a6f6
16 changed files with 207 additions and 188 deletions

View File

@ -244,8 +244,8 @@ write_box(int dim, char *str1, char *str2,
* The value turned out to be a point, ie. all the upper-right * The value turned out to be a point, ie. all the upper-right
* coordinates were equal to the lower-left coordinates. Resize the * coordinates were equal to the lower-left coordinates. Resize the
* cube we constructed. Note: we don't bother to repalloc() it * cube we constructed. Note: we don't bother to repalloc() it
* smaller, as it's unlikely that the tiny amount of memory freed * smaller, as it's unlikely that the tiny amount of memory freed that
* that way would be useful, and the output is always short-lived. * way would be useful, and the output is always short-lived.
*/ */
size = POINT_SIZE(dim); size = POINT_SIZE(dim);
SET_VARSIZE(bp, size); SET_VARSIZE(bp, size);
@ -260,7 +260,7 @@ static bool
write_point_as_box(int dim, char *str, write_point_as_box(int dim, char *str,
NDBOX **result, struct Node *escontext) NDBOX **result, struct Node *escontext)
{ {
NDBOX *bp; NDBOX *bp;
int i, int i,
size; size;
char *s; char *s;

View File

@ -73,14 +73,15 @@ cube_yyerror(NDBOX **result, Size scanbuflen,
yyscan_t yyscanner, yyscan_t yyscanner,
const char *message) const char *message)
{ {
struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yytext macro */ struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
* macro */
if (*yytext == YY_END_OF_BUFFER_CHAR) if (*yytext == YY_END_OF_BUFFER_CHAR)
{ {
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for cube"), errmsg("invalid input syntax for cube"),
/* translator: %s is typically "syntax error" */ /* translator: %s is typically "syntax error" */
errdetail("%s at end of input", message))); errdetail("%s at end of input", message)));
} }
else else
@ -88,7 +89,7 @@ cube_yyerror(NDBOX **result, Size scanbuflen,
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for cube"), errmsg("invalid input syntax for cube"),
/* translator: first %s is typically "syntax error" */ /* translator: first %s is typically "syntax error" */
errdetail("%s at or near \"%s\"", message, yytext))); errdetail("%s at or near \"%s\"", message, yytext)));
} }
} }

View File

@ -66,7 +66,8 @@ float ({integer}|{real})([eE]{integer})?
void void
seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char *message) seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char *message)
{ {
struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yytext macro */ struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
* macro */
/* if we already reported an error, don't overwrite it */ /* if we already reported an error, don't overwrite it */
if (SOFT_ERROR_OCCURRED(escontext)) if (SOFT_ERROR_OCCURRED(escontext))
@ -77,7 +78,7 @@ seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad seg representation"), errmsg("bad seg representation"),
/* translator: %s is typically "syntax error" */ /* translator: %s is typically "syntax error" */
errdetail("%s at end of input", message))); errdetail("%s at end of input", message)));
} }
else else
@ -85,7 +86,7 @@ seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad seg representation"), errmsg("bad seg representation"),
/* translator: first %s is typically "syntax error" */ /* translator: first %s is typically "syntax error" */
errdetail("%s at or near \"%s\"", message, yytext))); errdetail("%s at or near \"%s\"", message, yytext)));
} }
} }
@ -97,7 +98,7 @@ seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char
void void
seg_scanner_init(const char *str, yyscan_t *yyscannerp) seg_scanner_init(const char *str, yyscan_t *yyscannerp)
{ {
yyscan_t yyscanner; yyscan_t yyscanner;
if (yylex_init(yyscannerp) != 0) if (yylex_init(yyscannerp) != 0)
elog(ERROR, "yylex_init() failed: %m"); elog(ERROR, "yylex_init() failed: %m");

View File

@ -131,7 +131,8 @@ NULL { yylval->kw = "NULL"; return XNULL; }
void void
boot_yyerror(yyscan_t yyscanner, const char *message) boot_yyerror(yyscan_t yyscanner, const char *message)
{ {
struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yylineno macro */ struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yylineno
* macro */
elog(ERROR, "%s at line %d", message, yylineno); elog(ERROR, "%s at line %d", message, yylineno);
} }
@ -159,6 +160,6 @@ yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
void void
yyfree(void *ptr, yyscan_t yyscanner) yyfree(void *ptr, yyscan_t yyscanner)
{ {
if (ptr) if (ptr)
pfree(ptr); pfree(ptr);
} }

View File

@ -18646,31 +18646,31 @@ updatePreparableStmtEnd(Node *n, int end_location)
{ {
if (IsA(n, SelectStmt)) if (IsA(n, SelectStmt))
{ {
SelectStmt *stmt = (SelectStmt *)n; SelectStmt *stmt = (SelectStmt *) n;
stmt->stmt_len = end_location - stmt->stmt_location; stmt->stmt_len = end_location - stmt->stmt_location;
} }
else if (IsA(n, InsertStmt)) else if (IsA(n, InsertStmt))
{ {
InsertStmt *stmt = (InsertStmt *)n; InsertStmt *stmt = (InsertStmt *) n;
stmt->stmt_len = end_location - stmt->stmt_location; stmt->stmt_len = end_location - stmt->stmt_location;
} }
else if (IsA(n, UpdateStmt)) else if (IsA(n, UpdateStmt))
{ {
UpdateStmt *stmt = (UpdateStmt *)n; UpdateStmt *stmt = (UpdateStmt *) n;
stmt->stmt_len = end_location - stmt->stmt_location; stmt->stmt_len = end_location - stmt->stmt_location;
} }
else if (IsA(n, DeleteStmt)) else if (IsA(n, DeleteStmt))
{ {
DeleteStmt *stmt = (DeleteStmt *)n; DeleteStmt *stmt = (DeleteStmt *) n;
stmt->stmt_len = end_location - stmt->stmt_location; stmt->stmt_len = end_location - stmt->stmt_location;
} }
else if (IsA(n, MergeStmt)) else if (IsA(n, MergeStmt))
{ {
MergeStmt *stmt = (MergeStmt *)n; MergeStmt *stmt = (MergeStmt *) n;
stmt->stmt_len = end_location - stmt->stmt_location; stmt->stmt_len = end_location - stmt->stmt_location;
} }
@ -18683,10 +18683,10 @@ makeColumnRef(char *colname, List *indirection,
int location, core_yyscan_t yyscanner) int location, core_yyscan_t yyscanner)
{ {
/* /*
* Generate a ColumnRef node, with an A_Indirection node added if there * Generate a ColumnRef node, with an A_Indirection node added if there is
* is any subscripting in the specified indirection list. However, * any subscripting in the specified indirection list. However, any field
* any field selection at the start of the indirection list must be * selection at the start of the indirection list must be transposed into
* transposed into the "fields" part of the ColumnRef node. * the "fields" part of the ColumnRef node.
*/ */
ColumnRef *c = makeNode(ColumnRef); ColumnRef *c = makeNode(ColumnRef);
int nfields = 0; int nfields = 0;
@ -18752,55 +18752,55 @@ makeStringConstCast(char *str, int location, TypeName *typename)
static Node * static Node *
makeIntConst(int val, int location) makeIntConst(int val, int location)
{ {
A_Const *n = makeNode(A_Const); A_Const *n = makeNode(A_Const);
n->val.ival.type = T_Integer; n->val.ival.type = T_Integer;
n->val.ival.ival = val; n->val.ival.ival = val;
n->location = location; n->location = location;
return (Node *) n; return (Node *) n;
} }
static Node * static Node *
makeFloatConst(char *str, int location) makeFloatConst(char *str, int location)
{ {
A_Const *n = makeNode(A_Const); A_Const *n = makeNode(A_Const);
n->val.fval.type = T_Float; n->val.fval.type = T_Float;
n->val.fval.fval = str; n->val.fval.fval = str;
n->location = location; n->location = location;
return (Node *) n; return (Node *) n;
} }
static Node * static Node *
makeBoolAConst(bool state, int location) makeBoolAConst(bool state, int location)
{ {
A_Const *n = makeNode(A_Const); A_Const *n = makeNode(A_Const);
n->val.boolval.type = T_Boolean; n->val.boolval.type = T_Boolean;
n->val.boolval.boolval = state; n->val.boolval.boolval = state;
n->location = location; n->location = location;
return (Node *) n; return (Node *) n;
} }
static Node * static Node *
makeBitStringConst(char *str, int location) makeBitStringConst(char *str, int location)
{ {
A_Const *n = makeNode(A_Const); A_Const *n = makeNode(A_Const);
n->val.bsval.type = T_BitString; n->val.bsval.type = T_BitString;
n->val.bsval.bsval = str; n->val.bsval.bsval = str;
n->location = location; n->location = location;
return (Node *) n; return (Node *) n;
} }
static Node * static Node *
makeNullAConst(int location) makeNullAConst(int location)
{ {
A_Const *n = makeNode(A_Const); A_Const *n = makeNode(A_Const);
n->isnull = true; n->isnull = true;
n->location = location; n->location = location;
@ -18889,7 +18889,7 @@ check_func_name(List *names, core_yyscan_t yyscanner)
static List * static List *
check_indirection(List *indirection, core_yyscan_t yyscanner) check_indirection(List *indirection, core_yyscan_t yyscanner)
{ {
ListCell *l; ListCell *l;
foreach(l, indirection) foreach(l, indirection)
{ {
@ -18944,7 +18944,7 @@ makeOrderedSetArgs(List *directargs, List *orderedargs,
core_yyscan_t yyscanner) core_yyscan_t yyscanner)
{ {
FunctionParameter *lastd = (FunctionParameter *) llast(directargs); FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
Integer *ndirectargs; Integer *ndirectargs;
/* No restriction unless last direct arg is VARIADIC */ /* No restriction unless last direct arg is VARIADIC */
if (lastd->mode == FUNC_PARAM_VARIADIC) if (lastd->mode == FUNC_PARAM_VARIADIC)
@ -18952,8 +18952,8 @@ makeOrderedSetArgs(List *directargs, List *orderedargs,
FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs); FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
/* /*
* We ignore the names, though the aggr_arg production allows them; * We ignore the names, though the aggr_arg production allows them; it
* it doesn't allow default values, so those need not be checked. * doesn't allow default values, so those need not be checked.
*/ */
if (list_length(orderedargs) != 1 || if (list_length(orderedargs) != 1 ||
firsto->mode != FUNC_PARAM_VARIADIC || firsto->mode != FUNC_PARAM_VARIADIC ||
@ -19115,7 +19115,7 @@ doNegate(Node *n, int location)
{ {
if (IsA(n, A_Const)) if (IsA(n, A_Const))
{ {
A_Const *con = (A_Const *) n; A_Const *con = (A_Const *) n;
/* report the constant's location as that of the '-' sign */ /* report the constant's location as that of the '-' sign */
con->location = location; con->location = location;
@ -19143,7 +19143,7 @@ doNegateFloat(Float *v)
if (*oldval == '+') if (*oldval == '+')
oldval++; oldval++;
if (*oldval == '-') if (*oldval == '-')
v->fval = oldval+1; /* just strip the '-' */ v->fval = oldval + 1; /* just strip the '-' */
else else
v->fval = psprintf("-%s", oldval); v->fval = psprintf("-%s", oldval);
} }
@ -19214,10 +19214,11 @@ static Node *
makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args, makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
int location) int location)
{ {
XmlExpr *x = makeNode(XmlExpr); XmlExpr *x = makeNode(XmlExpr);
x->op = op; x->op = op;
x->name = name; x->name = name;
/* /*
* named_args is a list of ResTarget; it'll be split apart into separate * named_args is a list of ResTarget; it'll be split apart into separate
* expression and name lists in transformXmlExpr(). * expression and name lists in transformXmlExpr().
@ -19227,7 +19228,7 @@ makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
x->args = args; x->args = args;
/* xmloption, if relevant, must be filled in by caller */ /* xmloption, if relevant, must be filled in by caller */
/* type and typmod will be filled in during parse analysis */ /* type and typmod will be filled in during parse analysis */
x->type = InvalidOid; /* marks the node as not analyzed */ x->type = InvalidOid; /* marks the node as not analyzed */
x->location = location; x->location = location;
return (Node *) x; return (Node *) x;
} }
@ -19352,7 +19353,7 @@ makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
errcode(ERRCODE_SYNTAX_ERROR), errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper qualified name (too many dotted names): %s", errmsg("improper qualified name (too many dotted names): %s",
NameListToString(lcons(makeString(name), namelist))), NameListToString(lcons(makeString(name), namelist))),
parser_errposition(location)); parser_errposition(location));
break; break;
} }
@ -19421,7 +19422,7 @@ processCASbits(int cas_bits, int location, const char *constrType,
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */ /* translator: %s is CHECK, UNIQUE, or similar */
errmsg("%s constraints cannot be marked DEFERRABLE", errmsg("%s constraints cannot be marked DEFERRABLE",
constrType), constrType),
parser_errposition(location))); parser_errposition(location)));
@ -19434,7 +19435,7 @@ processCASbits(int cas_bits, int location, const char *constrType,
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */ /* translator: %s is CHECK, UNIQUE, or similar */
errmsg("%s constraints cannot be marked DEFERRABLE", errmsg("%s constraints cannot be marked DEFERRABLE",
constrType), constrType),
parser_errposition(location))); parser_errposition(location)));
@ -19447,7 +19448,7 @@ processCASbits(int cas_bits, int location, const char *constrType,
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */ /* translator: %s is CHECK, UNIQUE, or similar */
errmsg("%s constraints cannot be marked NOT VALID", errmsg("%s constraints cannot be marked NOT VALID",
constrType), constrType),
parser_errposition(location))); parser_errposition(location)));
@ -19460,7 +19461,7 @@ processCASbits(int cas_bits, int location, const char *constrType,
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */ /* translator: %s is CHECK, UNIQUE, or similar */
errmsg("%s constraints cannot be marked NO INHERIT", errmsg("%s constraints cannot be marked NO INHERIT",
constrType), constrType),
parser_errposition(location))); parser_errposition(location)));
@ -19485,7 +19486,7 @@ parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized partitioning strategy \"%s\"", strategy), errmsg("unrecognized partitioning strategy \"%s\"", strategy),
parser_errposition(location))); parser_errposition(location)));
return PARTITION_STRATEGY_LIST; /* keep compiler quiet */ return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
} }
@ -19556,8 +19557,8 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
parser_errposition(pubobj->location)); parser_errposition(pubobj->location));
/* /*
* We can distinguish between the different type of schema * We can distinguish between the different type of schema objects
* objects based on whether name and pubtable is set. * based on whether name and pubtable is set.
*/ */
if (pubobj->name) if (pubobj->name)
pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA; pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
@ -19612,11 +19613,13 @@ makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
w->ctes = list_make1(cte); w->ctes = list_make1(cte);
w->location = -1; w->location = -1;
/* create target list for the new SELECT from the alias list of the /*
* recursive view specification */ * create target list for the new SELECT from the alias list of the
foreach (lc, aliases) * recursive view specification
*/
foreach(lc, aliases)
{ {
ResTarget *rt = makeNode(ResTarget); ResTarget *rt = makeNode(ResTarget);
rt->name = NULL; rt->name = NULL;
rt->indirection = NIL; rt->indirection = NIL;
@ -19626,8 +19629,10 @@ makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
tl = lappend(tl, rt); tl = lappend(tl, rt);
} }
/* create new SELECT combining WITH clause, target list, and fake FROM /*
* clause */ * create new SELECT combining WITH clause, target list, and fake FROM
* clause
*/
s->withClause = w; s->withClause = w;
s->targetList = tl; s->targetList = tl;
s->fromClause = list_make1(makeRangeVar(NULL, relname, -1)); s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));

View File

@ -1468,9 +1468,9 @@ check_escape_warning(core_yyscan_t yyscanner)
ereport(WARNING, ereport(WARNING,
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER), (errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
errmsg("nonstandard use of escape in a string literal"), errmsg("nonstandard use of escape in a string literal"),
errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."), errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
lexer_errposition())); lexer_errposition()));
yyextra->warn_on_first_escape = false; /* warn only once per string */ yyextra->warn_on_first_escape = false; /* warn only once per string */
} }
/* /*

View File

@ -341,6 +341,6 @@ yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
void void
yyfree(void *ptr, yyscan_t yyscanner) yyfree(void *ptr, yyscan_t yyscanner)
{ {
if (ptr) if (ptr)
pfree(ptr); pfree(ptr);
} }

View File

@ -140,7 +140,8 @@ xdinside [^"]+
void void
syncrep_yyerror(yyscan_t yyscanner, const char *message) syncrep_yyerror(yyscan_t yyscanner, const char *message)
{ {
struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yytext macro */ struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
* macro */
/* report only the first error in a parse operation */ /* report only the first error in a parse operation */
if (syncrep_parse_error_msg) if (syncrep_parse_error_msg)

View File

@ -562,7 +562,7 @@ makeAny(int first, int last)
static bool static bool
makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern, makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
JsonPathString *flags, JsonPathParseItem ** result, JsonPathString *flags, JsonPathParseItem **result,
struct Node *escontext) struct Node *escontext)
{ {
JsonPathParseItem *v = makeItemType(jpiLikeRegex); JsonPathParseItem *v = makeItemType(jpiLikeRegex);
@ -605,15 +605,15 @@ makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
} }
/* Convert flags to what pg_regcomp needs */ /* Convert flags to what pg_regcomp needs */
if ( !jspConvertRegexFlags(v->value.like_regex.flags, &cflags, escontext)) if (!jspConvertRegexFlags(v->value.like_regex.flags, &cflags, escontext))
return false; return false;
/* check regex validity */ /* check regex validity */
{ {
regex_t re_tmp; regex_t re_tmp;
pg_wchar *wpattern; pg_wchar *wpattern;
int wpattern_len; int wpattern_len;
int re_result; int re_result;
wpattern = (pg_wchar *) palloc((pattern->len + 1) * sizeof(pg_wchar)); wpattern = (pg_wchar *) palloc((pattern->len + 1) * sizeof(pg_wchar));
wpattern_len = pg_mb2wchar_with_len(pattern->val, wpattern_len = pg_mb2wchar_with_len(pattern->val,
@ -623,7 +623,7 @@ makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
if ((re_result = pg_regcomp(&re_tmp, wpattern, wpattern_len, cflags, if ((re_result = pg_regcomp(&re_tmp, wpattern, wpattern_len, cflags,
DEFAULT_COLLATION_OID)) != REG_OKAY) DEFAULT_COLLATION_OID)) != REG_OKAY)
{ {
char errMsg[100]; char errMsg[100];
pg_regerror(re_result, &re_tmp, errMsg, sizeof(errMsg)); pg_regerror(re_result, &re_tmp, errMsg, sizeof(errMsg));
ereturn(escontext, false, ereturn(escontext, false,

View File

@ -363,7 +363,8 @@ jsonpath_yyerror(JsonPathParseResult **result, struct Node *escontext,
yyscan_t yyscanner, yyscan_t yyscanner,
const char *message) const char *message)
{ {
struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yytext macro */ struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
* macro */
/* don't overwrite escontext if it's already been set */ /* don't overwrite escontext if it's already been set */
if (SOFT_ERROR_OCCURRED(escontext)) if (SOFT_ERROR_OCCURRED(escontext))
@ -373,14 +374,14 @@ jsonpath_yyerror(JsonPathParseResult **result, struct Node *escontext,
{ {
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
/* translator: %s is typically "syntax error" */ /* translator: %s is typically "syntax error" */
errmsg("%s at end of jsonpath input", _(message)))); errmsg("%s at end of jsonpath input", _(message))));
} }
else else
{ {
errsave(escontext, errsave(escontext,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
/* translator: first %s is typically "syntax error" */ /* translator: first %s is typically "syntax error" */
errmsg("%s at or near \"%s\" of jsonpath input", errmsg("%s at or near \"%s\" of jsonpath input",
_(message), yytext))); _(message), yytext)));
} }
@ -399,39 +400,39 @@ typedef struct JsonPathKeyword
* alphabetical order * alphabetical order
*/ */
static const JsonPathKeyword keywords[] = { static const JsonPathKeyword keywords[] = {
{ 2, false, IS_P, "is"}, {2, false, IS_P, "is"},
{ 2, false, TO_P, "to"}, {2, false, TO_P, "to"},
{ 3, false, ABS_P, "abs"}, {3, false, ABS_P, "abs"},
{ 3, false, LAX_P, "lax"}, {3, false, LAX_P, "lax"},
{ 4, false, DATE_P, "date"}, {4, false, DATE_P, "date"},
{ 4, false, FLAG_P, "flag"}, {4, false, FLAG_P, "flag"},
{ 4, false, LAST_P, "last"}, {4, false, LAST_P, "last"},
{ 4, true, NULL_P, "null"}, {4, true, NULL_P, "null"},
{ 4, false, SIZE_P, "size"}, {4, false, SIZE_P, "size"},
{ 4, false, TIME_P, "time"}, {4, false, TIME_P, "time"},
{ 4, true, TRUE_P, "true"}, {4, true, TRUE_P, "true"},
{ 4, false, TYPE_P, "type"}, {4, false, TYPE_P, "type"},
{ 4, false, WITH_P, "with"}, {4, false, WITH_P, "with"},
{ 5, true, FALSE_P, "false"}, {5, true, FALSE_P, "false"},
{ 5, false, FLOOR_P, "floor"}, {5, false, FLOOR_P, "floor"},
{ 6, false, BIGINT_P, "bigint"}, {6, false, BIGINT_P, "bigint"},
{ 6, false, DOUBLE_P, "double"}, {6, false, DOUBLE_P, "double"},
{ 6, false, EXISTS_P, "exists"}, {6, false, EXISTS_P, "exists"},
{ 6, false, NUMBER_P, "number"}, {6, false, NUMBER_P, "number"},
{ 6, false, STARTS_P, "starts"}, {6, false, STARTS_P, "starts"},
{ 6, false, STRICT_P, "strict"}, {6, false, STRICT_P, "strict"},
{ 6, false, STRINGFUNC_P, "string"}, {6, false, STRINGFUNC_P, "string"},
{ 7, false, BOOLEAN_P, "boolean"}, {7, false, BOOLEAN_P, "boolean"},
{ 7, false, CEILING_P, "ceiling"}, {7, false, CEILING_P, "ceiling"},
{ 7, false, DECIMAL_P, "decimal"}, {7, false, DECIMAL_P, "decimal"},
{ 7, false, INTEGER_P, "integer"}, {7, false, INTEGER_P, "integer"},
{ 7, false, TIME_TZ_P, "time_tz"}, {7, false, TIME_TZ_P, "time_tz"},
{ 7, false, UNKNOWN_P, "unknown"}, {7, false, UNKNOWN_P, "unknown"},
{ 8, false, DATETIME_P, "datetime"}, {8, false, DATETIME_P, "datetime"},
{ 8, false, KEYVALUE_P, "keyvalue"}, {8, false, KEYVALUE_P, "keyvalue"},
{ 9, false, TIMESTAMP_P, "timestamp"}, {9, false, TIMESTAMP_P, "timestamp"},
{ 10,false, LIKE_REGEX_P, "like_regex"}, {10, false, LIKE_REGEX_P, "like_regex"},
{ 12,false, TIMESTAMP_TZ_P, "timestamp_tz"}, {12, false, TIMESTAMP_TZ_P, "timestamp_tz"},
}; };
/* /*
@ -442,9 +443,9 @@ checkKeyword(yyscan_t yyscanner)
{ {
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;
if (yyextra->scanstring.len > keywords[lengthof(keywords) - 1].len) if (yyextra->scanstring.len > keywords[lengthof(keywords) - 1].len)
return res; return res;
@ -526,7 +527,7 @@ addchar(bool init, char c, yyscan_t yyscanner)
JsonPathParseResult * JsonPathParseResult *
parsejsonpath(const char *str, int len, struct Node *escontext) parsejsonpath(const char *str, int len, struct Node *escontext)
{ {
JsonPathParseResult *parseresult; JsonPathParseResult *parseresult;
yyscan_t scanner; yyscan_t scanner;
struct jsonpath_yy_extra_type yyext; struct jsonpath_yy_extra_type yyext;
@ -541,7 +542,7 @@ parsejsonpath(const char *str, int len, struct Node *escontext)
jsonpath_yy_scan_bytes(str, len, scanner); jsonpath_yy_scan_bytes(str, len, scanner);
if (jsonpath_yyparse(&parseresult, escontext, scanner) != 0) if (jsonpath_yyparse(&parseresult, escontext, scanner) != 0)
jsonpath_yyerror(NULL, escontext, scanner, "invalid input"); /* shouldn't happen */ jsonpath_yyerror(NULL, escontext, scanner, "invalid input"); /* shouldn't happen */
jsonpath_yylex_destroy(scanner); jsonpath_yylex_destroy(scanner);
@ -581,7 +582,7 @@ addUnicodeChar(int ch, struct Node *escontext, yyscan_t yyscanner)
ereturn(escontext, false, ereturn(escontext, false,
(errcode(ERRCODE_UNTRANSLATABLE_CHARACTER), (errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
errmsg("unsupported Unicode escape sequence"), errmsg("unsupported Unicode escape sequence"),
errdetail("\\u0000 cannot be converted to text."))); errdetail("\\u0000 cannot be converted to text.")));
} }
else else
{ {
@ -593,7 +594,7 @@ addUnicodeChar(int ch, struct Node *escontext, yyscan_t yyscanner)
* more detailed errors. * more detailed errors.
*/ */
if (! escontext || ! IsA(escontext, ErrorSaveContext)) if (!escontext || !IsA(escontext, ErrorSaveContext))
pg_unicode_to_server(ch, (unsigned char *) cbuf); pg_unicode_to_server(ch, (unsigned char *) cbuf);
else if (!pg_unicode_to_server_noerror(ch, (unsigned char *) cbuf)) else if (!pg_unicode_to_server_noerror(ch, (unsigned char *) cbuf))
ereturn(escontext, false, ereturn(escontext, false,
@ -655,9 +656,10 @@ parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)
for (i = 2; i < l; i += 2) /* skip '\u' */ for (i = 2; i < l; i += 2) /* skip '\u' */
{ {
int ch = 0; int ch = 0;
int j, si; int j,
si;
if (s[i] == '{') /* parse '\u{XX...}' */ if (s[i] == '{') /* parse '\u{XX...}' */
{ {
while (s[++i] != '}' && i < l) while (s[++i] != '}' && i < l)
{ {
@ -665,9 +667,9 @@ parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)
return false; return false;
ch = (ch << 4) | si; ch = (ch << 4) | si;
} }
i++; /* skip '}' */ i++; /* skip '}' */
} }
else /* parse '\uXXXX' */ else /* parse '\uXXXX' */
{ {
for (j = 0; j < 4 && i < l; j++) for (j = 0; j < 4 && i < l; j++)
{ {
@ -677,7 +679,7 @@ parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)
} }
} }
if (! addUnicode(ch, &hi_surrogate, escontext, yyscanner)) if (!addUnicode(ch, &hi_surrogate, escontext, yyscanner))
return false; return false;
} }
@ -697,7 +699,10 @@ parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)
static bool static bool
parseHexChar(char *s, struct Node *escontext, yyscan_t yyscanner) parseHexChar(char *s, struct Node *escontext, yyscan_t yyscanner)
{ {
int s2, s3, ch; int s2,
s3,
ch;
if (!hexval(s[2], &s2, escontext, yyscanner)) if (!hexval(s[2], &s2, escontext, yyscanner))
return false; return false;
if (!hexval(s[3], &s3, escontext, yyscanner)) if (!hexval(s[3], &s3, escontext, yyscanner))

View File

@ -515,8 +515,8 @@ parse_error:
{ {
ereport(elevel, ereport(elevel,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error in file \"%s\" line %u, near end of line", errmsg("syntax error in file \"%s\" line %u, near end of line",
config_file, ConfigFileLineno - 1))); config_file, ConfigFileLineno - 1)));
record_config_file_error("syntax error", record_config_file_error("syntax error",
config_file, ConfigFileLineno - 1, config_file, ConfigFileLineno - 1,
head_p, tail_p); head_p, tail_p);
@ -525,8 +525,8 @@ parse_error:
{ {
ereport(elevel, ereport(elevel,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error in file \"%s\" line %u, near token \"%s\"", errmsg("syntax error in file \"%s\" line %u, near token \"%s\"",
config_file, ConfigFileLineno, yytext))); config_file, ConfigFileLineno, yytext)));
record_config_file_error("syntax error", record_config_file_error("syntax error",
config_file, ConfigFileLineno, config_file, ConfigFileLineno,
head_p, tail_p); head_p, tail_p);
@ -545,8 +545,8 @@ parse_error:
{ {
ereport(elevel, ereport(elevel,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("too many syntax errors found, abandoning file \"%s\"", errmsg("too many syntax errors found, abandoning file \"%s\"",
config_file))); config_file)));
break; break;
} }
@ -589,7 +589,7 @@ ParseConfigDirectory(const char *includedir,
int num_filenames; int num_filenames;
filenames = GetConfFilesInDir(includedir, calling_file, elevel, filenames = GetConfFilesInDir(includedir, calling_file, elevel,
&num_filenames, &err_msg); &num_filenames, &err_msg);
if (!filenames) if (!filenames)
{ {

View File

@ -252,7 +252,8 @@ static const struct
const char *fname; const char *fname;
int nargs; int nargs;
PgBenchFunction tag; PgBenchFunction tag;
} PGBENCH_FUNCTIONS[] = } PGBENCH_FUNCTIONS[] =
{ {
/* parsed as operators, executed as functions */ /* parsed as operators, executed as functions */
{ {
@ -451,7 +452,7 @@ elist_length(PgBenchExprList *list)
static PgBenchExpr * static PgBenchExpr *
make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args) make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
{ {
int len = elist_length(args); int len = elist_length(args);
PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr)); PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
@ -460,14 +461,14 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
/* validate arguments number including few special cases */ /* validate arguments number including few special cases */
switch (PGBENCH_FUNCTIONS[fnumber].nargs) switch (PGBENCH_FUNCTIONS[fnumber].nargs)
{ {
/* check at least one arg for least & greatest */ /* check at least one arg for least & greatest */
case PGBENCH_NARGS_VARIABLE: case PGBENCH_NARGS_VARIABLE:
if (len == 0) if (len == 0)
expr_yyerror_more(yyscanner, "at least one argument expected", expr_yyerror_more(yyscanner, "at least one argument expected",
PGBENCH_FUNCTIONS[fnumber].fname); PGBENCH_FUNCTIONS[fnumber].fname);
break; break;
/* case (when ... then ...)+ (else ...)? end */ /* case (when ... then ...)+ (else ...)? end */
case PGBENCH_NARGS_CASE: case PGBENCH_NARGS_CASE:
/* 'else' branch is always present, but could be a NULL-constant */ /* 'else' branch is always present, but could be a NULL-constant */
if (len < 3 || len % 2 != 1) if (len < 3 || len % 2 != 1)
@ -476,7 +477,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
"case control structure"); "case control structure");
break; break;
/* hash functions with optional seed argument */ /* hash functions with optional seed argument */
case PGBENCH_NARGS_HASH: case PGBENCH_NARGS_HASH:
if (len < 1 || len > 2) if (len < 1 || len > 2)
expr_yyerror_more(yyscanner, "unexpected number of arguments", expr_yyerror_more(yyscanner, "unexpected number of arguments",
@ -485,11 +486,12 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
if (len == 1) if (len == 1)
{ {
PgBenchExpr *var = make_variable("default_seed"); PgBenchExpr *var = make_variable("default_seed");
args = make_elist(var, args); args = make_elist(var, args);
} }
break; break;
/* pseudorandom permutation function with optional seed argument */ /* pseudorandom permutation function with optional seed argument */
case PGBENCH_NARGS_PERMUTE: case PGBENCH_NARGS_PERMUTE:
if (len < 2 || len > 3) if (len < 2 || len > 3)
expr_yyerror_more(yyscanner, "unexpected number of arguments", expr_yyerror_more(yyscanner, "unexpected number of arguments",
@ -498,11 +500,12 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
if (len == 2) if (len == 2)
{ {
PgBenchExpr *var = make_variable("default_seed"); PgBenchExpr *var = make_variable("default_seed");
args = make_elist(var, args); args = make_elist(var, args);
} }
break; break;
/* common case: positive arguments number */ /* common case: positive arguments number */
default: default:
Assert(PGBENCH_FUNCTIONS[fnumber].nargs >= 0); Assert(PGBENCH_FUNCTIONS[fnumber].nargs >= 0);

View File

@ -598,9 +598,9 @@ psql_scan_slash_option(PsqlScanState state,
psql_scan_reselect_sql_lexer(state); psql_scan_reselect_sql_lexer(state);
/* /*
* Check the lex result: we should have gotten back either LEXRES_OK * Check the lex result: we should have gotten back either LEXRES_OK or
* or LEXRES_EOL (the latter indicating end of string). If we were inside * LEXRES_EOL (the latter indicating end of string). If we were inside a
* a quoted string, as indicated by final_state, EOL is an error. * quoted string, as indicated by final_state, EOL is an error.
*/ */
Assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK); Assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
@ -642,6 +642,7 @@ psql_scan_slash_option(PsqlScanState state,
termPQExpBuffer(&mybuf); termPQExpBuffer(&mybuf);
return NULL; return NULL;
case xslashwholeline: case xslashwholeline:
/* /*
* In whole-line mode, we interpret semicolon = true as stripping * In whole-line mode, we interpret semicolon = true as stripping
* trailing whitespace as well as semicolons; this gives the * trailing whitespace as well as semicolons; this gives the

View File

@ -1317,7 +1317,7 @@ bool
psql_scan_in_quote(PsqlScanState state) psql_scan_in_quote(PsqlScanState state)
{ {
return state->start_state != INITIAL && return state->start_state != INITIAL &&
state->start_state != xqs; state->start_state != xqs;
} }
/* /*
@ -1568,8 +1568,8 @@ psqlscan_escape_variable(PsqlScanState state, const char *txt, int len,
void void
psqlscan_test_variable(PsqlScanState state, const char *txt, int len) psqlscan_test_variable(PsqlScanState state, const char *txt, int len)
{ {
char *varname; char *varname;
char *value; char *value;
varname = psqlscan_extract_substring(state, txt + 3, len - 4); varname = psqlscan_extract_substring(state, txt + 3, len - 4);
if (state->callbacks->get_variable) if (state->callbacks->get_variable)

View File

@ -1847,9 +1847,9 @@ isdefine(void)
ptr->used = yb; ptr->used = yb;
/* /*
* We use yy_scan_string which will copy the value, so there's * We use yy_scan_string which will copy the value, so there's no
* no need to worry about a possible undef happening while we * need to worry about a possible undef happening while we are
* are still scanning it. * still scanning it.
*/ */
yy_scan_string(ptr->value); yy_scan_string(ptr->value);
return true; return true;

View File

@ -2707,7 +2707,7 @@ read_sql_construct(int until,
for (;;) for (;;)
{ {
tok = yylex(); tok = yylex();
if (startlocation < 0) /* remember loc of first token */ if (startlocation < 0) /* remember loc of first token */
startlocation = yylloc; startlocation = yylloc;
if (tok == until && parenlevel == 0) if (tok == until && parenlevel == 0)
break; break;
@ -2723,10 +2723,11 @@ read_sql_construct(int until,
if (parenlevel < 0) if (parenlevel < 0)
yyerror("mismatched parentheses"); yyerror("mismatched parentheses");
} }
/* /*
* End of function definition is an error, and we don't expect to * End of function definition is an error, and we don't expect to hit
* hit a semicolon either (unless it's the until symbol, in which * a semicolon either (unless it's the until symbol, in which case we
* case we should have fallen out above). * should have fallen out above).
*/ */
if (tok == 0 || tok == ';') if (tok == 0 || tok == ';')
{ {
@ -2983,8 +2984,8 @@ make_execsql_stmt(int firsttoken, int location, PLword *word)
plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR; plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
/* /*
* Scan to the end of the SQL command. Identify any INTO-variables * Scan to the end of the SQL command. Identify any INTO-variables clause
* clause lurking within it, and parse that via read_into_target(). * lurking within it, and parse that via read_into_target().
* *
* The end of the statement is defined by a semicolon ... except that * The end of the statement is defined by a semicolon ... except that
* semicolons within parentheses or BEGIN/END blocks don't terminate a * semicolons within parentheses or BEGIN/END blocks don't terminate a
@ -3006,12 +3007,12 @@ make_execsql_stmt(int firsttoken, int location, PLword *word)
* but it's not very likely. * but it's not very likely.
* *
* 3. IMPORT FOREIGN SCHEMA ... INTO. This is not allowed in CREATE RULE * 3. IMPORT FOREIGN SCHEMA ... INTO. This is not allowed in CREATE RULE
* or WITH, so we just check for IMPORT as the command's first token. * or WITH, so we just check for IMPORT as the command's first token. (If
* (If IMPORT FOREIGN SCHEMA returned data someone might wish to capture * IMPORT FOREIGN SCHEMA returned data someone might wish to capture with
* with an INTO-variables clause, we'd have to work much harder here.) * an INTO-variables clause, we'd have to work much harder here.)
* *
* Fortunately, INTO is a fully reserved word in the main grammar, so * Fortunately, INTO is a fully reserved word in the main grammar, so at
* at least we need not worry about it appearing as an identifier. * least we need not worry about it appearing as an identifier.
* *
* Any future additional uses of INTO in the main grammar will doubtless * Any future additional uses of INTO in the main grammar will doubtless
* break this logic again ... beware! * break this logic again ... beware!
@ -3026,7 +3027,7 @@ make_execsql_stmt(int firsttoken, int location, PLword *word)
prev_tok = tok; prev_tok = tok;
tok = yylex(); tok = yylex();
if (have_into && into_end_loc < 0) if (have_into && into_end_loc < 0)
into_end_loc = yylloc; /* token after the INTO part */ into_end_loc = yylloc; /* token after the INTO part */
/* Detect CREATE [OR REPLACE] {FUNCTION|PROCEDURE} */ /* Detect CREATE [OR REPLACE] {FUNCTION|PROCEDURE} */
if (tokens[0] == 'c' && token_count < sizeof(tokens)) if (tokens[0] == 'c' && token_count < sizeof(tokens))
{ {
@ -3087,9 +3088,9 @@ make_execsql_stmt(int firsttoken, int location, PLword *word)
if (have_into) if (have_into)
{ {
/* /*
* Insert an appropriate number of spaces corresponding to the * Insert an appropriate number of spaces corresponding to the INTO
* INTO text, so that locations within the redacted SQL statement * text, so that locations within the redacted SQL statement still
* still line up with those in the original source text. * line up with those in the original source text.
*/ */
plpgsql_append_source_text(&ds, location, into_start_loc); plpgsql_append_source_text(&ds, location, into_start_loc);
appendStringInfoSpaces(&ds, into_end_loc - into_start_loc); appendStringInfoSpaces(&ds, into_end_loc - into_start_loc);
@ -3137,8 +3138,8 @@ read_fetch_direction(void)
bool check_FROM = true; bool check_FROM = true;
/* /*
* We create the PLpgSQL_stmt_fetch struct here, but only fill in * We create the PLpgSQL_stmt_fetch struct here, but only fill in the
* the fields arising from the optional direction clause * fields arising from the optional direction clause
*/ */
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;
@ -3172,7 +3173,7 @@ read_fetch_direction(void)
K_LAST, "last")) K_LAST, "last"))
{ {
fetch->direction = FETCH_ABSOLUTE; fetch->direction = FETCH_ABSOLUTE;
fetch->how_many = -1; fetch->how_many = -1;
} }
else if (tok_is_keyword(tok, &yylval, else if (tok_is_keyword(tok, &yylval,
K_ABSOLUTE, "absolute")) K_ABSOLUTE, "absolute"))
@ -3223,12 +3224,12 @@ read_fetch_direction(void)
else else
{ {
/* /*
* Assume it's a count expression with no preceding keyword. * Assume it's a count expression with no preceding keyword. Note: we
* Note: we allow this syntax because core SQL does, but it's * allow this syntax because core SQL does, but it's ambiguous with
* ambiguous with the case of an omitted direction clause; for * the case of an omitted direction clause; for instance, "MOVE n IN
* instance, "MOVE n IN c" will fail if n is a variable, because the * c" will fail if n is a variable, because the preceding else-arm
* preceding else-arm will trigger. Perhaps this can be improved * will trigger. Perhaps this can be improved someday, but it hardly
* someday, but it hardly seems worth a lot of work. * seems worth a lot of work.
*/ */
plpgsql_push_back_token(tok); plpgsql_push_back_token(tok);
fetch->expr = read_sql_expression2(K_FROM, K_IN, fetch->expr = read_sql_expression2(K_FROM, K_IN,
@ -3256,7 +3257,7 @@ read_fetch_direction(void)
* BACKWARD expr, BACKWARD ALL, BACKWARD * BACKWARD expr, BACKWARD ALL, BACKWARD
*/ */
static void static void
complete_direction(PLpgSQL_stmt_fetch *fetch, bool *check_FROM) complete_direction(PLpgSQL_stmt_fetch *fetch, bool *check_FROM)
{ {
int tok; int tok;
@ -3295,7 +3296,7 @@ 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;
@ -3357,8 +3358,8 @@ make_return_stmt(int location)
/* /*
* Not (just) a variable name, so treat as expression. * Not (just) a variable name, so treat as expression.
* *
* Note that a well-formed expression is _required_ here; * Note that a well-formed expression is _required_ here; anything
* anything else is a compile-time error. * else is a compile-time error.
*/ */
plpgsql_push_back_token(tok); plpgsql_push_back_token(tok);
new->expr = read_sql_expression(';', ";"); new->expr = read_sql_expression(';', ";");
@ -3420,8 +3421,8 @@ make_return_next_stmt(int location)
/* /*
* Not (just) a variable name, so treat as expression. * Not (just) a variable name, so treat as expression.
* *
* Note that a well-formed expression is _required_ here; * Note that a well-formed expression is _required_ here; anything
* anything else is a compile-time error. * else is a compile-time error.
*/ */
plpgsql_push_back_token(tok); plpgsql_push_back_token(tok);
new->expr = read_sql_expression(';', ";"); new->expr = read_sql_expression(';', ";");
@ -3540,11 +3541,11 @@ read_into_target(PLpgSQL_variable **target, bool *strict)
} }
/* /*
* Currently, a row or record variable can be the single INTO target, * Currently, a row or record variable can be the single INTO target, but
* but not a member of a multi-target list. So we throw error if there * not a member of a multi-target list. So we throw error if there is a
* is a comma after it, because that probably means the user tried to * comma after it, because that probably means the user tried to write a
* write a multi-target list. If this ever gets generalized, we should * multi-target list. If this ever gets generalized, we should probably
* probably refactor read_into_scalar_list so it handles all cases. * refactor read_into_scalar_list so it handles all cases.
*/ */
switch (tok) switch (tok)
{ {
@ -3590,7 +3591,7 @@ read_into_scalar_list(char *initial_name,
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);
@ -3620,7 +3621,7 @@ read_into_scalar_list(char *initial_name,
NameOfDatum(&(yylval.wdatum))), NameOfDatum(&(yylval.wdatum))),
parser_errposition(yylloc))); parser_errposition(yylloc)));
fieldnames[nfields] = NameOfDatum(&(yylval.wdatum)); fieldnames[nfields] = NameOfDatum(&(yylval.wdatum));
varnos[nfields++] = yylval.wdatum.datum->dno; varnos[nfields++] = yylval.wdatum.datum->dno;
break; break;
default: default:
@ -3630,8 +3631,8 @@ read_into_scalar_list(char *initial_name,
} }
/* /*
* We read an extra, non-comma token from yylex(), so push it * We read an extra, non-comma token from yylex(), so push it back onto
* back onto the input stream * the input stream
*/ */
plpgsql_push_back_token(tok); plpgsql_push_back_token(tok);
@ -3712,7 +3713,7 @@ static void
check_sql_expr(const char *stmt, RawParseMode parseMode, int location) check_sql_expr(const char *stmt, RawParseMode parseMode, int location)
{ {
sql_error_callback_arg cbarg; sql_error_callback_arg cbarg;
ErrorContextCallback syntax_errcontext; ErrorContextCallback syntax_errcontext;
MemoryContext oldCxt; MemoryContext oldCxt;
if (!plpgsql_check_syntax) if (!plpgsql_check_syntax)
@ -3741,14 +3742,14 @@ plpgsql_sql_error_callback(void *arg)
/* /*
* First, set up internalerrposition to point to the start of the * First, set up internalerrposition to point to the start of the
* statement text within the function text. Note this converts * statement text within the function text. Note this converts location
* location (a byte offset) to a character number. * (a byte offset) to a character number.
*/ */
parser_errposition(cbarg->location); parser_errposition(cbarg->location);
/* /*
* If the core parser provided an error position, transpose it. * If the core parser provided an error position, transpose it. Note we
* Note we are dealing with 1-based character numbers at this point. * are dealing with 1-based character numbers at this point.
*/ */
errpos = geterrposition(); errpos = geterrposition();
if (errpos > 0) if (errpos > 0)
@ -3779,7 +3780,7 @@ parse_datatype(const char *string, int location)
Oid type_id; Oid type_id;
int32 typmod; int32 typmod;
sql_error_callback_arg cbarg; sql_error_callback_arg cbarg;
ErrorContextCallback syntax_errcontext; ErrorContextCallback syntax_errcontext;
cbarg.location = location; cbarg.location = location;
@ -3890,7 +3891,7 @@ read_cursor_args(PLpgSQL_var *cursor, int until)
plpgsql_peek2(&tok1, &tok2, &arglocation, NULL); plpgsql_peek2(&tok1, &tok2, &arglocation, NULL);
if (tok1 == IDENT && tok2 == COLON_EQUALS) if (tok1 == IDENT && tok2 == COLON_EQUALS)
{ {
char *argname; char *argname;
IdentifierLookup save_IdentifierLookup; IdentifierLookup save_IdentifierLookup;
/* Read the argument name, ignoring any matching variable */ /* Read the argument name, ignoring any matching variable */
@ -4088,11 +4089,11 @@ check_raise_parameters(PLpgSQL_stmt_raise *stmt)
if (expected_nparams < list_length(stmt->params)) if (expected_nparams < list_length(stmt->params))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("too many parameters specified for RAISE"))); errmsg("too many parameters specified for RAISE")));
if (expected_nparams > list_length(stmt->params)) if (expected_nparams > list_length(stmt->params))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("too few parameters specified for RAISE"))); errmsg("too few parameters specified for RAISE")));
} }
/* /*
@ -4121,9 +4122,9 @@ make_case(int location, PLpgSQL_expr *t_expr,
/* /*
* When test expression is present, we create a var for it and then * When test expression is present, we create a var for it and then
* convert all the WHEN expressions to "VAR IN (original_expression)". * convert all the WHEN expressions to "VAR IN (original_expression)".
* This is a bit klugy, but okay since we haven't yet done more than * This is a bit klugy, but okay since we haven't yet done more than read
* read the expressions as text. (Note that previous parsing won't * the expressions as text. (Note that previous parsing won't have
* have complained if the WHEN ... THEN expression contained multiple * complained if the WHEN ... THEN expression contained multiple
* comma-separated values.) * comma-separated values.)
*/ */
if (t_expr) if (t_expr)