mirror of
https://github.com/postgres/postgres.git
synced 2025-10-29 22:49:41 +03:00
Make more use of castNode()
This commit is contained in:
@@ -824,8 +824,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
|
||||
AttrNumber attr_num;
|
||||
TargetEntry *tle;
|
||||
|
||||
col = (ResTarget *) lfirst(icols);
|
||||
Assert(IsA(col, ResTarget));
|
||||
col = castNode(ResTarget, lfirst(icols));
|
||||
attr_num = (AttrNumber) lfirst_int(attnos);
|
||||
|
||||
tle = makeTargetEntry(expr,
|
||||
@@ -950,8 +949,7 @@ transformInsertRow(ParseState *pstate, List *exprlist,
|
||||
Expr *expr = (Expr *) lfirst(lc);
|
||||
ResTarget *col;
|
||||
|
||||
col = (ResTarget *) lfirst(icols);
|
||||
Assert(IsA(col, ResTarget));
|
||||
col = castNode(ResTarget, lfirst(icols));
|
||||
|
||||
expr = transformAssignedExpr(pstate, expr,
|
||||
EXPR_KIND_INSERT_TARGET,
|
||||
@@ -1633,10 +1631,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
/*
|
||||
* Recursively transform the components of the tree.
|
||||
*/
|
||||
sostmt = (SetOperationStmt *) transformSetOperationTree(pstate, stmt,
|
||||
true,
|
||||
NULL);
|
||||
Assert(sostmt && IsA(sostmt, SetOperationStmt));
|
||||
sostmt = castNode(SetOperationStmt,
|
||||
transformSetOperationTree(pstate, stmt, true, NULL));
|
||||
Assert(sostmt);
|
||||
qry->setOperations = (Node *) sostmt;
|
||||
|
||||
/*
|
||||
@@ -2298,8 +2295,7 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
|
||||
}
|
||||
if (orig_tl == NULL)
|
||||
elog(ERROR, "UPDATE target count mismatch --- internal error");
|
||||
origTarget = (ResTarget *) lfirst(orig_tl);
|
||||
Assert(IsA(origTarget, ResTarget));
|
||||
origTarget = castNode(ResTarget, lfirst(orig_tl));
|
||||
|
||||
attrno = attnameAttNum(pstate->p_target_relation,
|
||||
origTarget->name, true);
|
||||
|
||||
@@ -3249,8 +3249,7 @@ ColQualList:
|
||||
ColConstraint:
|
||||
CONSTRAINT name ColConstraintElem
|
||||
{
|
||||
Constraint *n = (Constraint *) $3;
|
||||
Assert(IsA(n, Constraint));
|
||||
Constraint *n = castNode(Constraint, $3);
|
||||
n->conname = $2;
|
||||
n->location = @1;
|
||||
$$ = (Node *) n;
|
||||
@@ -3442,8 +3441,7 @@ TableLikeOption:
|
||||
TableConstraint:
|
||||
CONSTRAINT name ConstraintElem
|
||||
{
|
||||
Constraint *n = (Constraint *) $3;
|
||||
Assert(IsA(n, Constraint));
|
||||
Constraint *n = castNode(Constraint, $3);
|
||||
n->conname = $2;
|
||||
n->location = @1;
|
||||
$$ = (Node *) n;
|
||||
@@ -12845,8 +12843,7 @@ c_expr: columnref { $$ = $1; }
|
||||
}
|
||||
| ARRAY array_expr
|
||||
{
|
||||
A_ArrayExpr *n = (A_ArrayExpr *) $2;
|
||||
Assert(IsA(n, A_ArrayExpr));
|
||||
A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
|
||||
/* point outermost A_ArrayExpr to the ARRAY keyword */
|
||||
n->location = @1;
|
||||
$$ = (Node *)n;
|
||||
|
||||
@@ -903,8 +903,7 @@ transformFromClauseItem(ParseState *pstate, Node *n,
|
||||
rel = transformFromClauseItem(pstate, rts->relation,
|
||||
top_rte, top_rti, namespace);
|
||||
/* Currently, grammar could only return a RangeVar as contained rel */
|
||||
Assert(IsA(rel, RangeTblRef));
|
||||
rtr = (RangeTblRef *) rel;
|
||||
rtr = castNode(RangeTblRef, rel);
|
||||
rte = rt_fetch(rtr->rtindex, pstate->p_rtable);
|
||||
/* We only support this on plain relations and matviews */
|
||||
if (rte->relkind != RELKIND_RELATION &&
|
||||
|
||||
@@ -514,8 +514,7 @@ assign_collations_walker(Node *node, assign_collations_context *context)
|
||||
|
||||
if (qtree->targetList == NIL)
|
||||
return false;
|
||||
tent = (TargetEntry *) linitial(qtree->targetList);
|
||||
Assert(IsA(tent, TargetEntry));
|
||||
tent = castNode(TargetEntry, linitial(qtree->targetList));
|
||||
if (tent->resjunk)
|
||||
return false;
|
||||
|
||||
@@ -650,9 +649,7 @@ assign_collations_walker(Node *node, assign_collations_context *context)
|
||||
|
||||
foreach(lc, expr->args)
|
||||
{
|
||||
CaseWhen *when = (CaseWhen *) lfirst(lc);
|
||||
|
||||
Assert(IsA(when, CaseWhen));
|
||||
CaseWhen *when = castNode(CaseWhen, lfirst(lc));
|
||||
|
||||
/*
|
||||
* The condition expressions mustn't affect
|
||||
@@ -868,9 +865,8 @@ assign_aggregate_collations(Aggref *aggref,
|
||||
/* Process aggregated args, holding resjunk ones at arm's length */
|
||||
foreach(lc, aggref->args)
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(lc);
|
||||
TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
|
||||
|
||||
Assert(IsA(tle, TargetEntry));
|
||||
if (tle->resjunk)
|
||||
assign_expr_collations(loccontext->pstate, (Node *) tle);
|
||||
else
|
||||
@@ -913,9 +909,8 @@ assign_ordered_set_collations(Aggref *aggref,
|
||||
/* Process aggregated args appropriately */
|
||||
foreach(lc, aggref->args)
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(lc);
|
||||
TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
|
||||
|
||||
Assert(IsA(tle, TargetEntry));
|
||||
if (merge_sort_collations)
|
||||
(void) assign_collations_walker((Node *) tle, loccontext);
|
||||
else
|
||||
|
||||
@@ -917,13 +917,11 @@ transformAExprOp(ParseState *pstate, A_Expr *a)
|
||||
/* ROW() op ROW() is handled specially */
|
||||
lexpr = transformExprRecurse(pstate, lexpr);
|
||||
rexpr = transformExprRecurse(pstate, rexpr);
|
||||
Assert(IsA(lexpr, RowExpr));
|
||||
Assert(IsA(rexpr, RowExpr));
|
||||
|
||||
result = make_row_comparison_op(pstate,
|
||||
a->name,
|
||||
((RowExpr *) lexpr)->args,
|
||||
((RowExpr *) rexpr)->args,
|
||||
castNode(RowExpr, lexpr)->args,
|
||||
castNode(RowExpr, rexpr)->args,
|
||||
a->location);
|
||||
}
|
||||
else
|
||||
@@ -1296,8 +1294,7 @@ transformAExprBetween(ParseState *pstate, A_Expr *a)
|
||||
|
||||
/* Deconstruct A_Expr into three subexprs */
|
||||
aexpr = a->lexpr;
|
||||
Assert(IsA(a->rexpr, List));
|
||||
args = (List *) a->rexpr;
|
||||
args = castNode(List, a->rexpr);
|
||||
Assert(list_length(args) == 2);
|
||||
bexpr = (Node *) linitial(args);
|
||||
cexpr = (Node *) lsecond(args);
|
||||
@@ -1672,12 +1669,10 @@ transformCaseExpr(ParseState *pstate, CaseExpr *c)
|
||||
resultexprs = NIL;
|
||||
foreach(l, c->args)
|
||||
{
|
||||
CaseWhen *w = (CaseWhen *) lfirst(l);
|
||||
CaseWhen *w = castNode(CaseWhen, lfirst(l));
|
||||
CaseWhen *neww = makeNode(CaseWhen);
|
||||
Node *warg;
|
||||
|
||||
Assert(IsA(w, CaseWhen));
|
||||
|
||||
warg = (Node *) w->expr;
|
||||
if (placeholder)
|
||||
{
|
||||
@@ -2339,12 +2334,10 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
|
||||
|
||||
foreach(lc, x->named_args)
|
||||
{
|
||||
ResTarget *r = (ResTarget *) lfirst(lc);
|
||||
ResTarget *r = castNode(ResTarget, lfirst(lc));
|
||||
Node *expr;
|
||||
char *argname;
|
||||
|
||||
Assert(IsA(r, ResTarget));
|
||||
|
||||
expr = transformExprRecurse(pstate, r->val);
|
||||
|
||||
if (r->name)
|
||||
@@ -2800,8 +2793,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
|
||||
Node *rarg = (Node *) lfirst(r);
|
||||
OpExpr *cmp;
|
||||
|
||||
cmp = (OpExpr *) make_op(pstate, opname, larg, rarg, location);
|
||||
Assert(IsA(cmp, OpExpr));
|
||||
cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg, location));
|
||||
|
||||
/*
|
||||
* We don't use coerce_to_boolean here because we insist on the
|
||||
|
||||
@@ -1515,8 +1515,7 @@ func_get_detail(List *funcname,
|
||||
&isnull);
|
||||
Assert(!isnull);
|
||||
str = TextDatumGetCString(proargdefaults);
|
||||
defaults = (List *) stringToNode(str);
|
||||
Assert(IsA(defaults, List));
|
||||
defaults = castNode(List, stringToNode(str));
|
||||
pfree(str);
|
||||
|
||||
/* Delete any unused defaults from the returned list */
|
||||
|
||||
@@ -335,10 +335,9 @@ transformArraySubscripts(ParseState *pstate,
|
||||
*/
|
||||
foreach(idx, indirection)
|
||||
{
|
||||
A_Indices *ai = (A_Indices *) lfirst(idx);
|
||||
A_Indices *ai = castNode(A_Indices, lfirst(idx));
|
||||
Node *subexpr;
|
||||
|
||||
Assert(IsA(ai, A_Indices));
|
||||
if (isSlice)
|
||||
{
|
||||
if (ai->lidx)
|
||||
|
||||
@@ -910,12 +910,11 @@ markRTEForSelectPriv(ParseState *pstate, RangeTblEntry *rte,
|
||||
JoinExpr *j;
|
||||
|
||||
if (rtindex > 0 && rtindex <= list_length(pstate->p_joinexprs))
|
||||
j = (JoinExpr *) list_nth(pstate->p_joinexprs, rtindex - 1);
|
||||
j = castNode(JoinExpr, list_nth(pstate->p_joinexprs, rtindex - 1));
|
||||
else
|
||||
j = NULL;
|
||||
if (j == NULL)
|
||||
elog(ERROR, "could not find JoinExpr for whole-row reference");
|
||||
Assert(IsA(j, JoinExpr));
|
||||
|
||||
/* Note: we can't see FromExpr here */
|
||||
if (IsA(j->larg, RangeTblRef))
|
||||
|
||||
@@ -478,9 +478,8 @@ TypeNameListToString(List *typenames)
|
||||
initStringInfo(&string);
|
||||
foreach(l, typenames)
|
||||
{
|
||||
TypeName *typeName = (TypeName *) lfirst(l);
|
||||
TypeName *typeName = castNode(TypeName, lfirst(l));
|
||||
|
||||
Assert(IsA(typeName, TypeName));
|
||||
if (l != list_head(typenames))
|
||||
appendStringInfoChar(&string, ',');
|
||||
appendTypeNameToBuffer(typeName, &string);
|
||||
|
||||
@@ -543,8 +543,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
|
||||
foreach(clist, column->constraints)
|
||||
{
|
||||
constraint = lfirst(clist);
|
||||
Assert(IsA(constraint, Constraint));
|
||||
constraint = castNode(Constraint, lfirst(clist));
|
||||
|
||||
switch (constraint->contype)
|
||||
{
|
||||
@@ -1520,9 +1519,8 @@ transformIndexConstraints(CreateStmtContext *cxt)
|
||||
*/
|
||||
foreach(lc, cxt->ixconstraints)
|
||||
{
|
||||
Constraint *constraint = (Constraint *) lfirst(lc);
|
||||
Constraint *constraint = castNode(Constraint, lfirst(lc));
|
||||
|
||||
Assert(IsA(constraint, Constraint));
|
||||
Assert(constraint->contype == CONSTR_PRIMARY ||
|
||||
constraint->contype == CONSTR_UNIQUE ||
|
||||
constraint->contype == CONSTR_EXCLUSION);
|
||||
@@ -1842,10 +1840,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
List *opname;
|
||||
|
||||
Assert(list_length(pair) == 2);
|
||||
elem = (IndexElem *) linitial(pair);
|
||||
Assert(IsA(elem, IndexElem));
|
||||
opname = (List *) lsecond(pair);
|
||||
Assert(IsA(opname, List));
|
||||
elem = castNode(IndexElem, linitial(pair));
|
||||
opname = castNode(List, lsecond(pair));
|
||||
|
||||
index->indexParams = lappend(index->indexParams, elem);
|
||||
index->excludeOpNames = lappend(index->excludeOpNames, opname);
|
||||
@@ -1872,8 +1868,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
|
||||
foreach(columns, cxt->columns)
|
||||
{
|
||||
column = (ColumnDef *) lfirst(columns);
|
||||
Assert(IsA(column, ColumnDef));
|
||||
column = castNode(ColumnDef, lfirst(columns));
|
||||
if (strcmp(column->colname, key) == 0)
|
||||
{
|
||||
found = true;
|
||||
@@ -1902,11 +1897,10 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
|
||||
foreach(inher, cxt->inhRelations)
|
||||
{
|
||||
RangeVar *inh = (RangeVar *) lfirst(inher);
|
||||
RangeVar *inh = castNode(RangeVar, lfirst(inher));
|
||||
Relation rel;
|
||||
int count;
|
||||
|
||||
Assert(IsA(inh, RangeVar));
|
||||
rel = heap_openrv(inh, AccessShareLock);
|
||||
/* check user requested inheritance from valid relkind */
|
||||
if (rel->rd_rel->relkind != RELKIND_RELATION &&
|
||||
@@ -2586,9 +2580,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
|
||||
case AT_AddColumn:
|
||||
case AT_AddColumnToView:
|
||||
{
|
||||
ColumnDef *def = (ColumnDef *) cmd->def;
|
||||
ColumnDef *def = castNode(ColumnDef, cmd->def);
|
||||
|
||||
Assert(IsA(def, ColumnDef));
|
||||
transformColumnDefinition(&cxt, def);
|
||||
|
||||
/*
|
||||
@@ -2693,9 +2686,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
|
||||
*/
|
||||
foreach(l, cxt.alist)
|
||||
{
|
||||
IndexStmt *idxstmt = (IndexStmt *) lfirst(l);
|
||||
IndexStmt *idxstmt = castNode(IndexStmt, lfirst(l));
|
||||
|
||||
Assert(IsA(idxstmt, IndexStmt));
|
||||
idxstmt = transformIndexStmt(relid, idxstmt, queryString);
|
||||
newcmd = makeNode(AlterTableCmd);
|
||||
newcmd->subtype = OidIsValid(idxstmt->indexOid) ? AT_AddIndexConstraint : AT_AddIndex;
|
||||
|
||||
Reference in New Issue
Block a user