Automatically generate node support functions
authorPeter Eisentraut <peter@eisentraut.org>
Sat, 9 Jul 2022 06:52:19 +0000 (08:52 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sat, 9 Jul 2022 06:53:59 +0000 (08:53 +0200)
commit964d01ae90c314eb31132c2e7712d5d9fc237331
tree244be052514e9c37bfa31f2799038964d12a2c88
parent2373fe78dfc9d4aa2348a86fffdf8eb9d757e9d5
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
23 files changed:
src/backend/Makefile
src/backend/nodes/.gitignore [new file with mode: 0644]
src/backend/nodes/Makefile
src/backend/nodes/README
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/gen_node_support.pl [new file with mode: 0644]
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/include/Makefile
src/include/catalog/catversion.h
src/include/executor/tuptable.h
src/include/nodes/.gitignore [new file with mode: 0644]
src/include/nodes/extensible.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/pathnodes.h
src/include/nodes/plannodes.h
src/include/nodes/primnodes.h
src/include/nodes/value.h
src/include/utils/rel.h
src/tools/msvc/Solution.pm
src/tools/pgindent/exclude_file_patterns