mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Automatically generate node support functions
Add a script to automatically generate the node support functions (copy, equal, out, and read, as well as the node tags enum) from the struct definitions. For each of the four node support files, it creates two include files, e.g., copyfuncs.funcs.c and copyfuncs.switch.c, to include in the main file. All the scaffolding of the main file stays in place. I have tried to mostly make the coverage of the output match what is currently there. For example, one could now do out/read coverage of utility statement nodes, but I have manually excluded those for now. The reason is mainly that it's easier to diff the before and after, and adding a bunch of stuff like this might require a separate analysis and review. Subtyping (TidScan -> Scan) is supported. For the hard cases, you can just write a manual function and exclude generating one. For the not so hard cases, there is a way of annotating struct fields to get special behaviors. For example, pg_node_attr(equal_ignore) has the field ignored in equal functions. (In this patch, I have only ifdef'ed out the code to could be removed, mainly so that it won't constantly have merge conflicts. It will be deleted in a separate patch. All the code comments that are worth keeping from those sections have already been moved to the header files where the structs are defined.) Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/c1097590-a6a4-486a-64b1-e1f9cc0533ce%40enterprisedb.com
This commit is contained in:
@@ -31,11 +31,10 @@
|
||||
|
||||
#include "lib/stringinfo.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/extensible.h"
|
||||
#include "nodes/pathnodes.h"
|
||||
#include "nodes/plannodes.h"
|
||||
#include "nodes/bitmapset.h"
|
||||
#include "nodes/nodes.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
static void outChar(StringInfo str, char c);
|
||||
|
||||
@@ -306,6 +305,9 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
||||
}
|
||||
|
||||
|
||||
#include "outfuncs.funcs.c"
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/*
|
||||
* Stuff from plannodes.h
|
||||
*/
|
||||
@@ -1138,6 +1140,7 @@ _outVar(StringInfo str, const Var *node)
|
||||
WRITE_INT_FIELD(varattnosyn);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outConst(StringInfo str, const Const *node)
|
||||
@@ -1159,6 +1162,7 @@ _outConst(StringInfo str, const Const *node)
|
||||
outDatum(str, node->constvalue, node->constlen, node->constbyval);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outParam(StringInfo str, const Param *node)
|
||||
{
|
||||
@@ -1329,6 +1333,7 @@ _outScalarArrayOpExpr(StringInfo str, const ScalarArrayOpExpr *node)
|
||||
WRITE_NODE_FIELD(args);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outBoolExpr(StringInfo str, const BoolExpr *node)
|
||||
@@ -1357,6 +1362,7 @@ _outBoolExpr(StringInfo str, const BoolExpr *node)
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outSubLink(StringInfo str, const SubLink *node)
|
||||
{
|
||||
@@ -2569,6 +2575,7 @@ _outIndexOptInfo(StringInfo str, const IndexOptInfo *node)
|
||||
WRITE_BOOL_FIELD(hypothetical);
|
||||
/* we don't bother with fields copied from the index AM's API struct */
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
||||
@@ -2596,6 +2603,7 @@ _outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
||||
appendStringInfo(str, " %d", list_length(node->rinfos[i]));
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outStatisticExtInfo(StringInfo str, const StatisticExtInfo *node)
|
||||
{
|
||||
@@ -2607,6 +2615,7 @@ _outStatisticExtInfo(StringInfo str, const StatisticExtInfo *node)
|
||||
WRITE_CHAR_FIELD(kind);
|
||||
WRITE_BITMAPSET_FIELD(keys);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
|
||||
@@ -2635,6 +2644,7 @@ _outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
|
||||
WRITE_UINT_FIELD(ec_max_security);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outEquivalenceMember(StringInfo str, const EquivalenceMember *node)
|
||||
{
|
||||
@@ -2819,6 +2829,7 @@ _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
|
||||
WRITE_NODE_FIELD(item);
|
||||
WRITE_INT_FIELD(paramId);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
@@ -2841,6 +2852,7 @@ _outExtensibleNode(StringInfo str, const ExtensibleNode *node)
|
||||
methods->nodeOut(str, node);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Stuff from parsenodes.h.
|
||||
@@ -3174,6 +3186,7 @@ _outStatsElem(StringInfo str, const StatsElem *node)
|
||||
WRITE_STRING_FIELD(name);
|
||||
WRITE_NODE_FIELD(expr);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outQuery(StringInfo str, const Query *node)
|
||||
@@ -3248,6 +3261,7 @@ _outQuery(StringInfo str, const Query *node)
|
||||
WRITE_INT_FIELD(stmt_len);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outWithCheckOption(StringInfo str, const WithCheckOption *node)
|
||||
{
|
||||
@@ -3413,6 +3427,7 @@ _outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
|
||||
WRITE_NODE_FIELD(colCollations);
|
||||
WRITE_NODE_FIELD(groupClauses);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
||||
@@ -3493,6 +3508,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
||||
WRITE_NODE_FIELD(securityQuals);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outRangeTblFunction(StringInfo str, const RangeTblFunction *node)
|
||||
{
|
||||
@@ -3516,6 +3532,7 @@ _outTableSampleClause(StringInfo str, const TableSampleClause *node)
|
||||
WRITE_NODE_FIELD(args);
|
||||
WRITE_NODE_FIELD(repeatable);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outA_Expr(StringInfo str, const A_Expr *node)
|
||||
@@ -3634,6 +3651,7 @@ _outBitString(StringInfo str, const BitString *node)
|
||||
appendStringInfoString(str, node->bsval);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outColumnRef(StringInfo str, const ColumnRef *node)
|
||||
{
|
||||
@@ -3665,6 +3683,7 @@ _outRawStmt(StringInfo str, const RawStmt *node)
|
||||
WRITE_LOCATION_FIELD(stmt_location);
|
||||
WRITE_INT_FIELD(stmt_len);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outA_Const(StringInfo str, const A_Const *node)
|
||||
@@ -3681,6 +3700,7 @@ _outA_Const(StringInfo str, const A_Const *node)
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outA_Star(StringInfo str, const A_Star *node)
|
||||
{
|
||||
@@ -3825,6 +3845,7 @@ _outRangeTableFuncCol(StringInfo str, const RangeTableFuncCol *node)
|
||||
WRITE_NODE_FIELD(coldefexpr);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
static void
|
||||
_outConstraint(StringInfo str, const Constraint *node)
|
||||
@@ -3947,6 +3968,7 @@ _outConstraint(StringInfo str, const Constraint *node)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void
|
||||
_outForeignKeyCacheInfo(StringInfo str, const ForeignKeyCacheInfo *node)
|
||||
{
|
||||
@@ -4007,6 +4029,7 @@ _outPartitionRangeDatum(StringInfo str, const PartitionRangeDatum *node)
|
||||
WRITE_NODE_FIELD(value);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
/*
|
||||
* outNode -
|
||||
@@ -4038,6 +4061,8 @@ outNode(StringInfo str, const void *obj)
|
||||
appendStringInfoChar(str, '{');
|
||||
switch (nodeTag(obj))
|
||||
{
|
||||
#include "outfuncs.switch.c"
|
||||
#ifdef OBSOLETE
|
||||
case T_PlannedStmt:
|
||||
_outPlannedStmt(str, obj);
|
||||
break;
|
||||
@@ -4743,6 +4768,7 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_JsonTableSibling:
|
||||
_outJsonTableSibling(str, obj);
|
||||
break;
|
||||
#endif /* OBSOLETE */
|
||||
|
||||
default:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user