1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +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:
Peter Eisentraut
2022-07-09 08:52:19 +02:00
parent 2373fe78df
commit 964d01ae90
23 changed files with 1613 additions and 222 deletions

View File

@ -33,9 +33,7 @@
#include <math.h>
#include "miscadmin.h"
#include "nodes/extensible.h"
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
#include "nodes/bitmapset.h"
#include "nodes/readfuncs.h"
@ -238,6 +236,8 @@ readBitmapset(void)
return _readBitmapset();
}
#include "readfuncs.funcs.c"
/*
* _readQuery
*/
@ -291,6 +291,7 @@ _readQuery(void)
READ_DONE();
}
#ifdef OBSOLETE
/*
* _readNotifyStmt
*/
@ -629,6 +630,7 @@ _readVar(void)
READ_DONE();
}
#endif /* OBSOLETE */
/*
* _readConst
@ -655,6 +657,7 @@ _readConst(void)
READ_DONE();
}
#ifdef OBSOLETE
/*
* _readParam
*/
@ -880,6 +883,7 @@ _readScalarArrayOpExpr(void)
READ_DONE();
}
#endif /* OBSOLETE */
/*
* _readBoolExpr
@ -907,6 +911,7 @@ _readBoolExpr(void)
READ_DONE();
}
#ifdef OBSOLETE
/*
* _readSubLink
*/
@ -1649,6 +1654,7 @@ _readAppendRelInfo(void)
/*
* Stuff from parsenodes.h.
*/
#endif /* OBSOLETE */
/*
* _readRangeTblEntry
@ -1744,6 +1750,7 @@ _readRangeTblEntry(void)
READ_DONE();
}
#ifdef OBSOLETE
/*
* _readRangeTblFunction
*/
@ -2846,6 +2853,7 @@ _readAlternativeSubPlan(void)
READ_DONE();
}
#endif /* OBSOLETE */
/*
* _readExtensibleNode
@ -2877,6 +2885,7 @@ _readExtensibleNode(void)
READ_DONE();
}
#ifdef OBSOLETE
/*
* _readPartitionBoundSpec
*/
@ -2911,6 +2920,7 @@ _readPartitionRangeDatum(void)
READ_DONE();
}
#endif /* OBSOLETE */
/*
* parseNodeString
@ -2935,7 +2945,11 @@ parseNodeString(void)
#define MATCH(tokname, namelen) \
(length == namelen && memcmp(token, tokname, namelen) == 0)
if (MATCH("QUERY", 5))
if (false)
;
#include "readfuncs.switch.c"
#ifdef OBSOLETE
else if (MATCH("QUERY", 5))
return_value = _readQuery();
else if (MATCH("WITHCHECKOPTION", 15))
return_value = _readWithCheckOption();
@ -3205,6 +3219,7 @@ parseNodeString(void)
return_value = _readJsonTableParent();
else if (MATCH("JSONTABLESIBLING", 16))
return_value = _readJsonTableSibling();
#endif /* OBSOLETE */
else
{
elog(ERROR, "badly formatted node string \"%.32s\"...", token);