in ext/pg_query/src_backend_nodes_nodeFuncs.c [38:555]
static bool planstate_walk_subplans(List *plans, bool (*walker) (),
void *context);
static bool planstate_walk_members(PlanState **planstates, int nplans,
bool (*walker) (), void *context);
/*
* exprType -
* returns the Oid of the type of the expression's result.
*/
/*
* exprTypmod -
* returns the type-specific modifier of the expression's result type,
* if it can be determined. In many cases, it can't and we return -1.
*/
/*
* exprIsLengthCoercion
* Detect whether an expression tree is an application of a datatype's
* typmod-coercion function. Optionally extract the result's typmod.
*
* If coercedTypmod is not NULL, the typmod is stored there if the expression
* is a length-coercion function, else -1 is stored there.
*
* Note that a combined type-and-length coercion will be treated as a
* length coercion by this routine.
*/
/*
* applyRelabelType
* Add a RelabelType node if needed to make the expression expose
* the specified type, typmod, and collation.
*
* This is primarily intended to be used during planning. Therefore, it must
* maintain the post-eval_const_expressions invariants that there are not
* adjacent RelabelTypes, and that the tree is fully const-folded (hence,
* we mustn't return a RelabelType atop a Const). If we do find a Const,
* we'll modify it in-place if "overwrite_ok" is true; that should only be
* passed as true if caller knows the Const is newly generated.
*/
/*
* relabel_to_typmod
* Add a RelabelType node that changes just the typmod of the expression.
*
* Convenience function for a common usage of applyRelabelType.
*/
/*
* strip_implicit_coercions: remove implicit coercions at top level of tree
*
* This doesn't modify or copy the input expression tree, just return a
* pointer to a suitable place within it.
*
* Note: there isn't any useful thing we can do with a RowExpr here, so
* just return it unchanged, even if it's marked as an implicit coercion.
*/
/*
* expression_returns_set
* Test whether an expression returns a set result.
*
* Because we use expression_tree_walker(), this can also be applied to
* whole targetlists; it'll produce true if any one of the tlist items
* returns a set.
*/
/*
* exprCollation -
* returns the Oid of the collation of the expression's result.
*
* Note: expression nodes that can invoke functions generally have an
* "inputcollid" field, which is what the function should use as collation.
* That is the resolved common collation of the node's inputs. It is often
* but not always the same as the result collation; in particular, if the
* function produces a non-collatable result type from collatable inputs
* or vice versa, the two are different.
*/
/*
* exprInputCollation -
* returns the Oid of the collation a function should use, if available.
*
* Result is InvalidOid if the node type doesn't store this information.
*/
/*
* exprSetCollation -
* Assign collation information to an expression tree node.
*
* Note: since this is only used during parse analysis, we don't need to
* worry about subplans or PlaceHolderVars.
*/
#ifdef USE_ASSERT_CHECKING
#endif /* USE_ASSERT_CHECKING */
/*
* exprSetInputCollation -
* Assign input-collation information to an expression tree node.
*
* This is a no-op for node types that don't store their input collation.
* Note we omit RowCompareExpr, which needs special treatment since it
* contains multiple input collation OIDs.
*/
/*
* exprLocation -
* returns the parse location of an expression tree, for error reports
*
* -1 is returned if the location can't be determined.
*
* For expressions larger than a single token, the intent here is to
* return the location of the expression's leftmost token, not necessarily
* the topmost Node's location field. For example, an OpExpr's location
* field will point at the operator name, but if it is not a prefix operator
* then we should return the location of the left-hand operand instead.
* The reason is that we want to reference the entire expression not just
* that operator, and pointing to its start seems to be the most natural way.
*
* The location is not perfect --- for example, since the grammar doesn't
* explicitly represent parentheses in the parsetree, given something that
* had been written "(a + b) * c" we are going to point at "a" not "(".
* But it should be plenty good enough for error reporting purposes.
*
* You might think that this code is overly general, for instance why check
* the operands of a FuncExpr node, when the function name can be expected
* to be to the left of them? There are a couple of reasons. The grammar
* sometimes builds expressions that aren't quite what the user wrote;
* for instance x IS NOT BETWEEN ... becomes a NOT-expression whose keyword
* pointer is to the right of its leftmost argument. Also, nodes that were
* inserted implicitly by parse analysis (such as FuncExprs for implicit
* coercions) will have location -1, and so we can have odd combinations of
* known and unknown locations in a tree.
*/
int
exprLocation(const Node *expr)
{
int loc;
if (expr == NULL)
return -1;
switch (nodeTag(expr))
{
case T_RangeVar:
loc = ((const RangeVar *) expr)->location;
break;
case T_TableFunc:
loc = ((const TableFunc *) expr)->location;
break;
case T_Var:
loc = ((const Var *) expr)->location;
break;
case T_Const:
loc = ((const Const *) expr)->location;
break;
case T_Param:
loc = ((const Param *) expr)->location;
break;
case T_Aggref:
/* function name should always be the first thing */
loc = ((const Aggref *) expr)->location;
break;
case T_GroupingFunc:
loc = ((const GroupingFunc *) expr)->location;
break;
case T_WindowFunc:
/* function name should always be the first thing */
loc = ((const WindowFunc *) expr)->location;
break;
case T_SubscriptingRef:
/* just use container argument's location */
loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
break;
case T_FuncExpr:
{
const FuncExpr *fexpr = (const FuncExpr *) expr;
/* consider both function name and leftmost arg */
loc = leftmostLoc(fexpr->location,
exprLocation((Node *) fexpr->args));
}
break;
case T_NamedArgExpr:
{
const NamedArgExpr *na = (const NamedArgExpr *) expr;
/* consider both argument name and value */
loc = leftmostLoc(na->location,
exprLocation((Node *) na->arg));
}
break;
case T_OpExpr:
case T_DistinctExpr: /* struct-equivalent to OpExpr */
case T_NullIfExpr: /* struct-equivalent to OpExpr */
{
const OpExpr *opexpr = (const OpExpr *) expr;
/* consider both operator name and leftmost arg */
loc = leftmostLoc(opexpr->location,
exprLocation((Node *) opexpr->args));
}
break;
case T_ScalarArrayOpExpr:
{
const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
/* consider both operator name and leftmost arg */
loc = leftmostLoc(saopexpr->location,
exprLocation((Node *) saopexpr->args));
}
break;
case T_BoolExpr:
{
const BoolExpr *bexpr = (const BoolExpr *) expr;
/*
* Same as above, to handle either NOT or AND/OR. We can't
* special-case NOT because of the way that it's used for
* things like IS NOT BETWEEN.
*/
loc = leftmostLoc(bexpr->location,
exprLocation((Node *) bexpr->args));
}
break;
case T_SubLink:
{
const SubLink *sublink = (const SubLink *) expr;
/* check the testexpr, if any, and the operator/keyword */
loc = leftmostLoc(exprLocation(sublink->testexpr),
sublink->location);
}
break;
case T_FieldSelect:
/* just use argument's location */
loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
break;
case T_FieldStore:
/* just use argument's location */
loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
break;
case T_RelabelType:
{
const RelabelType *rexpr = (const RelabelType *) expr;
/* Much as above */
loc = leftmostLoc(rexpr->location,
exprLocation((Node *) rexpr->arg));
}
break;
case T_CoerceViaIO:
{
const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
/* Much as above */
loc = leftmostLoc(cexpr->location,
exprLocation((Node *) cexpr->arg));
}
break;
case T_ArrayCoerceExpr:
{
const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
/* Much as above */
loc = leftmostLoc(cexpr->location,
exprLocation((Node *) cexpr->arg));
}
break;
case T_ConvertRowtypeExpr:
{
const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
/* Much as above */
loc = leftmostLoc(cexpr->location,
exprLocation((Node *) cexpr->arg));
}
break;
case T_CollateExpr:
/* just use argument's location */
loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
break;
case T_CaseExpr:
/* CASE keyword should always be the first thing */
loc = ((const CaseExpr *) expr)->location;
break;
case T_CaseWhen:
/* WHEN keyword should always be the first thing */
loc = ((const CaseWhen *) expr)->location;
break;
case T_ArrayExpr:
/* the location points at ARRAY or [, which must be leftmost */
loc = ((const ArrayExpr *) expr)->location;
break;
case T_RowExpr:
/* the location points at ROW or (, which must be leftmost */
loc = ((const RowExpr *) expr)->location;
break;
case T_RowCompareExpr:
/* just use leftmost argument's location */
loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
break;
case T_CoalesceExpr:
/* COALESCE keyword should always be the first thing */
loc = ((const CoalesceExpr *) expr)->location;
break;
case T_MinMaxExpr:
/* GREATEST/LEAST keyword should always be the first thing */
loc = ((const MinMaxExpr *) expr)->location;
break;
case T_SQLValueFunction:
/* function keyword should always be the first thing */
loc = ((const SQLValueFunction *) expr)->location;
break;
case T_XmlExpr:
{
const XmlExpr *xexpr = (const XmlExpr *) expr;
/* consider both function name and leftmost arg */
loc = leftmostLoc(xexpr->location,
exprLocation((Node *) xexpr->args));
}
break;
case T_NullTest:
{
const NullTest *nexpr = (const NullTest *) expr;
/* Much as above */
loc = leftmostLoc(nexpr->location,
exprLocation((Node *) nexpr->arg));
}
break;
case T_BooleanTest:
{
const BooleanTest *bexpr = (const BooleanTest *) expr;
/* Much as above */
loc = leftmostLoc(bexpr->location,
exprLocation((Node *) bexpr->arg));
}
break;
case T_CoerceToDomain:
{
const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
/* Much as above */
loc = leftmostLoc(cexpr->location,
exprLocation((Node *) cexpr->arg));
}
break;
case T_CoerceToDomainValue:
loc = ((const CoerceToDomainValue *) expr)->location;
break;
case T_SetToDefault:
loc = ((const SetToDefault *) expr)->location;
break;
case T_TargetEntry:
/* just use argument's location */
loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
break;
case T_IntoClause:
/* use the contained RangeVar's location --- close enough */
loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
break;
case T_List:
{
/* report location of first list member that has a location */
ListCell *lc;
loc = -1; /* just to suppress compiler warning */
foreach(lc, (const List *) expr)
{
loc = exprLocation((Node *) lfirst(lc));
if (loc >= 0)
break;
}
}
break;
case T_A_Expr:
{
const A_Expr *aexpr = (const A_Expr *) expr;
/* use leftmost of operator or left operand (if any) */
/* we assume right operand can't be to left of operator */
loc = leftmostLoc(aexpr->location,
exprLocation(aexpr->lexpr));
}
break;
case T_ColumnRef:
loc = ((const ColumnRef *) expr)->location;
break;
case T_ParamRef:
loc = ((const ParamRef *) expr)->location;
break;
case T_A_Const:
loc = ((const A_Const *) expr)->location;
break;
case T_FuncCall:
{
const FuncCall *fc = (const FuncCall *) expr;
/* consider both function name and leftmost arg */
/* (we assume any ORDER BY nodes must be to right of name) */
loc = leftmostLoc(fc->location,
exprLocation((Node *) fc->args));
}
break;
case T_A_ArrayExpr:
/* the location points at ARRAY or [, which must be leftmost */
loc = ((const A_ArrayExpr *) expr)->location;
break;
case T_ResTarget:
/* we need not examine the contained expression (if any) */
loc = ((const ResTarget *) expr)->location;
break;
case T_MultiAssignRef:
loc = exprLocation(((const MultiAssignRef *) expr)->source);
break;
case T_TypeCast:
{
const TypeCast *tc = (const TypeCast *) expr;
/*
* This could represent CAST(), ::, or TypeName 'literal', so
* any of the components might be leftmost.
*/
loc = exprLocation(tc->arg);
loc = leftmostLoc(loc, tc->typeName->location);
loc = leftmostLoc(loc, tc->location);
}
break;
case T_CollateClause:
/* just use argument's location */
loc = exprLocation(((const CollateClause *) expr)->arg);
break;
case T_SortBy:
/* just use argument's location (ignore operator, if any) */
loc = exprLocation(((const SortBy *) expr)->node);
break;
case T_WindowDef:
loc = ((const WindowDef *) expr)->location;
break;
case T_RangeTableSample:
loc = ((const RangeTableSample *) expr)->location;
break;
case T_TypeName:
loc = ((const TypeName *) expr)->location;
break;
case T_ColumnDef:
loc = ((const ColumnDef *) expr)->location;
break;
case T_Constraint:
loc = ((const Constraint *) expr)->location;
break;
case T_FunctionParameter:
/* just use typename's location */
loc = exprLocation((Node *) ((const FunctionParameter *) expr)->argType);
break;
case T_XmlSerialize:
/* XMLSERIALIZE keyword should always be the first thing */
loc = ((const XmlSerialize *) expr)->location;
break;
case T_GroupingSet:
loc = ((const GroupingSet *) expr)->location;
break;
case T_WithClause:
loc = ((const WithClause *) expr)->location;
break;
case T_InferClause:
loc = ((const InferClause *) expr)->location;
break;
case T_OnConflictClause:
loc = ((const OnConflictClause *) expr)->location;
break;
case T_CommonTableExpr:
loc = ((const CommonTableExpr *) expr)->location;
break;
case T_PlaceHolderVar:
/* just use argument's location */
loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
break;
case T_InferenceElem:
/* just use nested expr's location */
loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
break;
case T_PartitionElem:
loc = ((const PartitionElem *) expr)->location;
break;
case T_PartitionSpec:
loc = ((const PartitionSpec *) expr)->location;
break;
case T_PartitionBoundSpec:
loc = ((const PartitionBoundSpec *) expr)->location;
break;
case T_PartitionRangeDatum:
loc = ((const PartitionRangeDatum *) expr)->location;
break;
default:
/* for any other node type it's just unknown... */
loc = -1;
break;
}
return loc;
}