diff options
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/analyze.c | 2 | ||||
-rw-r--r-- | src/backend/parser/gram.y | 13 | ||||
-rw-r--r-- | src/backend/parser/parse_agg.c | 4 | ||||
-rw-r--r-- | src/backend/parser/parse_coerce.c | 8 | ||||
-rw-r--r-- | src/backend/parser/parse_collate.c | 6 | ||||
-rw-r--r-- | src/backend/parser/parse_cte.c | 8 | ||||
-rw-r--r-- | src/backend/parser/parse_expr.c | 6 | ||||
-rw-r--r-- | src/backend/parser/parse_func.c | 16 | ||||
-rw-r--r-- | src/backend/parser/parse_relation.c | 31 | ||||
-rw-r--r-- | src/backend/parser/parse_target.c | 24 | ||||
-rw-r--r-- | src/backend/parser/parse_utilcmd.c | 2 |
11 files changed, 57 insertions, 63 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 345a8e61977..85d7a96406e 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -2341,7 +2341,7 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist) target_rte->updatedCols = bms_add_member(target_rte->updatedCols, attrno - FirstLowInvalidHeapAttributeNumber); - orig_tl = lnext(orig_tl); + orig_tl = lnext(origTlist, orig_tl); } if (orig_tl != NULL) elog(ERROR, "UPDATE target count mismatch --- internal error"); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 208b4a1f28a..c97bb367f8e 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -15579,7 +15579,7 @@ makeColumnRef(char *colname, List *indirection, else if (IsA(lfirst(l), A_Star)) { /* We only allow '*' at the end of a ColumnRef */ - if (lnext(l) != NULL) + if (lnext(indirection, l) != NULL) parser_yyerror("improper use of \"*\""); } nfields++; @@ -15768,7 +15768,7 @@ check_indirection(List *indirection, core_yyscan_t yyscanner) { if (IsA(lfirst(l), A_Star)) { - if (lnext(l) != NULL) + if (lnext(indirection, l) != NULL) parser_yyerror("improper use of \"*\""); } } @@ -16181,20 +16181,15 @@ SplitColQualList(List *qualList, core_yyscan_t yyscanner) { ListCell *cell; - ListCell *prev; - ListCell *next; *collClause = NULL; - prev = NULL; - for (cell = list_head(qualList); cell; cell = next) + foreach(cell, qualList) { Node *n = (Node *) lfirst(cell); - next = lnext(cell); if (IsA(n, Constraint)) { /* keep it in list */ - prev = cell; continue; } if (IsA(n, CollateClause)) @@ -16211,7 +16206,7 @@ SplitColQualList(List *qualList, else elog(ERROR, "unexpected node type %d", (int) n->type); /* remove non-Constraint nodes from qualList */ - qualList = list_delete_cell(qualList, cell, prev); + qualList = foreach_delete_current(qualList, cell); } *constraintList = qualList; } diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c index d50410d23a6..8dc3793b5fc 100644 --- a/src/backend/parser/parse_agg.c +++ b/src/backend/parser/parse_agg.c @@ -1083,7 +1083,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry) if (gset_common) { - for_each_cell(l, lnext(list_head(gsets))) + for_each_cell(l, gsets, list_second_cell(gsets)) { gset_common = list_intersection_int(gset_common, lfirst(l)); if (!gset_common) @@ -1777,7 +1777,7 @@ expand_grouping_sets(List *groupingSets, int limit) result = lappend(result, list_union_int(NIL, (List *) lfirst(lc))); } - for_each_cell(lc, lnext(list_head(expanded_groups))) + for_each_cell(lc, expanded_groups, list_second_cell(expanded_groups)) { List *p = lfirst(lc); List *new_result = NIL; diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 903478d8ca7..a6c51a95dae 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -1085,7 +1085,7 @@ coerce_record_to_complex(ParseState *pstate, Node *node, parser_coercion_errposition(pstate, location, expr))); newargs = lappend(newargs, cexpr); ucolno++; - arg = lnext(arg); + arg = lnext(args, arg); } if (arg != NULL) ereport(ERROR, @@ -1283,7 +1283,7 @@ select_common_type(ParseState *pstate, List *exprs, const char *context, Assert(exprs != NIL); pexpr = (Node *) linitial(exprs); - lc = lnext(list_head(exprs)); + lc = list_second_cell(exprs); ptype = exprType(pexpr); /* @@ -1293,7 +1293,7 @@ select_common_type(ParseState *pstate, List *exprs, const char *context, */ if (ptype != UNKNOWNOID) { - for_each_cell(lc, lc) + for_each_cell(lc, exprs, lc) { Node *nexpr = (Node *) lfirst(lc); Oid ntype = exprType(nexpr); @@ -1317,7 +1317,7 @@ select_common_type(ParseState *pstate, List *exprs, const char *context, ptype = getBaseType(ptype); get_type_category_preferred(ptype, &pcategory, &pispreferred); - for_each_cell(lc, lc) + for_each_cell(lc, exprs, lc) { Node *nexpr = (Node *) lfirst(lc); Oid ntype = getBaseType(exprType(nexpr)); diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 4d2e586bd64..31a5f702a9a 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -946,7 +946,7 @@ assign_hypothetical_collations(Aggref *aggref, while (extra_args-- > 0) { (void) assign_collations_walker((Node *) lfirst(h_cell), loccontext); - h_cell = lnext(h_cell); + h_cell = lnext(aggref->aggdirectargs, h_cell); } /* Scan hypothetical args and aggregated args in parallel */ @@ -1027,8 +1027,8 @@ assign_hypothetical_collations(Aggref *aggref, paircontext.location2, loccontext); - h_cell = lnext(h_cell); - s_cell = lnext(s_cell); + h_cell = lnext(aggref->aggdirectargs, h_cell); + s_cell = lnext(aggref->args, s_cell); } Assert(h_cell == NULL && s_cell == NULL); } diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c index 84af95ed866..63eea2a431c 100644 --- a/src/backend/parser/parse_cte.c +++ b/src/backend/parser/parse_cte.c @@ -122,7 +122,7 @@ transformWithClause(ParseState *pstate, WithClause *withClause) CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); ListCell *rest; - for_each_cell(rest, lnext(lc)) + for_each_cell(rest, withClause->ctes, lnext(withClause->ctes, lc)) { CommonTableExpr *cte2 = (CommonTableExpr *) lfirst(rest); @@ -327,9 +327,9 @@ analyzeCTE(ParseState *pstate, CommonTableExpr *cte) get_collation_name(exprCollation(texpr))), errhint("Use the COLLATE clause to set the collation of the non-recursive term."), parser_errposition(pstate, exprLocation(texpr)))); - lctyp = lnext(lctyp); - lctypmod = lnext(lctypmod); - lccoll = lnext(lccoll); + lctyp = lnext(cte->ctecoltypes, lctyp); + lctypmod = lnext(cte->ctecoltypmods, lctypmod); + lccoll = lnext(cte->ctecolcollations, lccoll); } if (lctyp != NULL || lctypmod != NULL || lccoll != NULL) /* shouldn't happen */ elog(ERROR, "wrong number of output columns in WITH"); diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 97f535a2f00..76f3dd7076f 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -2259,7 +2259,6 @@ transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault) RowExpr *newr; char fname[16]; int fnum; - ListCell *lc; newr = makeNode(RowExpr); @@ -2273,10 +2272,9 @@ transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault) /* ROW() has anonymous columns, so invent some field names */ newr->colnames = NIL; - fnum = 1; - foreach(lc, newr->args) + for (fnum = 1; fnum <= list_length(newr->args); fnum++) { - snprintf(fname, sizeof(fname), "f%d", fnum++); + snprintf(fname, sizeof(fname), "f%d", fnum); newr->colnames = lappend(newr->colnames, makeString(pstrdup(fname))); } diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 2a44b434a59..0102c220a4b 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -100,7 +100,6 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Oid rettype; Oid funcid; ListCell *l; - ListCell *nextl; Node *first_arg = NULL; int nargs; int nargsplusdefs; @@ -147,21 +146,18 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, * to distinguish "input" and "output" parameter symbols while parsing * function-call constructs. Don't do this if dealing with column syntax, * nor if we had WITHIN GROUP (because in that case it's critical to keep - * the argument count unchanged). We can't use foreach() because we may - * modify the list ... + * the argument count unchanged). */ nargs = 0; - for (l = list_head(fargs); l != NULL; l = nextl) + foreach(l, fargs) { Node *arg = lfirst(l); Oid argtype = exprType(arg); - nextl = lnext(l); - if (argtype == VOIDOID && IsA(arg, Param) && !is_column && !agg_within_group) { - fargs = list_delete_ptr(fargs, arg); + fargs = foreach_delete_current(fargs, l); continue; } @@ -1683,8 +1679,8 @@ func_get_detail(List *funcname, int ndelete; ndelete = list_length(defaults) - best_candidate->ndargs; - while (ndelete-- > 0) - defaults = list_delete_first(defaults); + if (ndelete > 0) + defaults = list_copy_tail(defaults, ndelete); *argdefaults = defaults; } } @@ -2009,7 +2005,7 @@ funcname_signature_string(const char *funcname, int nargs, if (i >= numposargs) { appendStringInfo(&argbuf, "%s => ", (char *) lfirst(lc)); - lc = lnext(lc); + lc = lnext(argnames, lc); } appendStringInfoString(&argbuf, format_type_be(argtypes[i])); } diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 77a48b039d9..4dd81507a78 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1044,6 +1044,7 @@ static void buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) { int maxattrs = tupdesc->natts; + List *aliaslist; ListCell *aliaslc; int numaliases; int varattno; @@ -1053,13 +1054,15 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) if (alias) { - aliaslc = list_head(alias->colnames); - numaliases = list_length(alias->colnames); + aliaslist = alias->colnames; + aliaslc = list_head(aliaslist); + numaliases = list_length(aliaslist); /* We'll rebuild the alias colname list */ alias->colnames = NIL; } else { + aliaslist = NIL; aliaslc = NULL; numaliases = 0; } @@ -1081,7 +1084,7 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) { /* Use the next user-supplied alias */ attrname = (Value *) lfirst(aliaslc); - aliaslc = lnext(aliaslc); + aliaslc = lnext(aliaslist, aliaslc); alias->colnames = lappend(alias->colnames, attrname); } else @@ -2287,7 +2290,7 @@ expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, *colvars = lappend(*colvars, varnode); } - aliasp_item = lnext(aliasp_item); + aliasp_item = lnext(rte->eref->colnames, aliasp_item); } } break; @@ -2514,7 +2517,7 @@ expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, *colnames = lappend(*colnames, makeString(pstrdup(""))); - aliasp_item = lnext(aliasp_item); + aliasp_item = lnext(rte->eref->colnames, aliasp_item); } if (colvars) @@ -2586,19 +2589,11 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, int location, bool include_dropped, List **colnames, List **colvars) { - ListCell *aliascell = list_head(eref->colnames); + ListCell *aliascell; int varattno; - if (colnames) - { - int i; - - for (i = 0; i < offset; i++) - { - if (aliascell) - aliascell = lnext(aliascell); - } - } + aliascell = (offset < list_length(eref->colnames)) ? + list_nth_cell(eref->colnames, offset) : NULL; Assert(count <= tupdesc->natts); for (varattno = 0; varattno < count; varattno++) @@ -2622,7 +2617,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, } } if (aliascell) - aliascell = lnext(aliascell); + aliascell = lnext(eref->colnames, aliascell); continue; } @@ -2633,7 +2628,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, if (aliascell) { label = strVal(lfirst(aliascell)); - aliascell = lnext(aliascell); + aliascell = lnext(eref->colnames, aliascell); } else { diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index b70d92b9550..29010250151 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -42,7 +42,8 @@ static Node *transformAssignmentIndirection(ParseState *pstate, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, - ListCell *indirection, + List *indirection, + ListCell *indirection_cell, Node *rhs, int location); static Node *transformAssignmentSubscripts(ParseState *pstate, @@ -53,6 +54,7 @@ static Node *transformAssignmentSubscripts(ParseState *pstate, Oid targetCollation, List *subscripts, bool isSlice, + List *indirection, ListCell *next_indirection, Node *rhs, int location); @@ -561,6 +563,7 @@ transformAssignedExpr(ParseState *pstate, attrtype, attrtypmod, attrcollation, + indirection, list_head(indirection), (Node *) expr, location); @@ -662,8 +665,9 @@ updateTargetListEntry(ParseState *pstate, * collation of the object to be assigned to (initially the target column, * later some subobject). * - * indirection is the sublist remaining to process. When it's NULL, we're - * done recursing and can just coerce and return the RHS. + * indirection is the list of indirection nodes, and indirection_cell is the + * start of the sublist remaining to process. When it's NULL, we're done + * recursing and can just coerce and return the RHS. * * rhs is the already-transformed value to be assigned; note it has not been * coerced to any particular type. @@ -681,7 +685,8 @@ transformAssignmentIndirection(ParseState *pstate, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, - ListCell *indirection, + List *indirection, + ListCell *indirection_cell, Node *rhs, int location) { @@ -690,7 +695,7 @@ transformAssignmentIndirection(ParseState *pstate, bool isSlice = false; ListCell *i; - if (indirection && !basenode) + if (indirection_cell && !basenode) { /* * Set up a substitution. We abuse CaseTestExpr for this. It's safe @@ -712,7 +717,7 @@ transformAssignmentIndirection(ParseState *pstate, * subscripting. Adjacent A_Indices nodes have to be treated as a single * multidimensional subscript operation. */ - for_each_cell(i, indirection) + for_each_cell(i, indirection, indirection_cell) { Node *n = lfirst(i); @@ -754,6 +759,7 @@ transformAssignmentIndirection(ParseState *pstate, targetCollation, subscripts, isSlice, + indirection, i, rhs, location); @@ -803,7 +809,8 @@ transformAssignmentIndirection(ParseState *pstate, fieldTypeId, fieldTypMod, fieldCollation, - lnext(i), + indirection, + lnext(indirection, i), rhs, location); @@ -840,6 +847,7 @@ transformAssignmentIndirection(ParseState *pstate, targetCollation, subscripts, isSlice, + indirection, NULL, rhs, location); @@ -892,6 +900,7 @@ transformAssignmentSubscripts(ParseState *pstate, Oid targetCollation, List *subscripts, bool isSlice, + List *indirection, ListCell *next_indirection, Node *rhs, int location) @@ -931,6 +940,7 @@ transformAssignmentSubscripts(ParseState *pstate, typeNeeded, containerTypMod, collationNeeded, + indirection, next_indirection, rhs, location); diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 7450d74b7ac..f0f6ee7db6b 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -1547,7 +1547,7 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, if (indexpr_item == NULL) elog(ERROR, "too few entries in indexprs list"); indexkey = (Node *) lfirst(indexpr_item); - indexpr_item = lnext(indexpr_item); + indexpr_item = lnext(indexprs, indexpr_item); /* Adjust Vars to match new table's column numbering */ indexkey = map_variable_attnos(indexkey, |