1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

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

@@ -131,7 +131,8 @@ NULL { yylval->kw = "NULL"; return XNULL; }
void
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);
}
@@ -159,6 +160,6 @@ yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
void
yyfree(void *ptr, yyscan_t yyscanner)
{
if (ptr)
pfree(ptr);
if (ptr)
pfree(ptr);
}

View File

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

View File

@@ -1468,9 +1468,9 @@ check_escape_warning(core_yyscan_t yyscanner)
ereport(WARNING,
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
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()));
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
yyfree(void *ptr, yyscan_t yyscanner)
{
if (ptr)
pfree(ptr);
if (ptr)
pfree(ptr);
}

View File

@@ -140,7 +140,8 @@ xdinside [^"]+
void
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 */
if (syncrep_parse_error_msg)

View File

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

View File

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

View File

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