Skip to content

Commit ca187d7

Browse files
committed
Invent nodetag_only attribute for Nodes.
This allows explaining gen_node_support.pl's handling of execnodes.h and some other input files as being a shortcut for explicit marking of all their node declarations as pg_node_attr(nodetag_only). I foresee that someday we might need to be more fine-grained about that, and this change provides the infrastructure needed to do so. For now, it just allows removal of the script's klugy special case for CallContext and InlineCodeBlock. Discussion: https://postgr.es/m/75063.1657410615@sss.pgh.pa.us
1 parent 09c5ace commit ca187d7

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/backend/nodes/gen_node_support.pl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ sub elem
5050
my @no_read;
5151
# node types we don't want read/write support for
5252
my @no_read_write;
53+
# node types we don't want any support functions for, just node tags
54+
my @nodetag_only;
5355

5456
# types that are copied by straight assignment
5557
my @scalar_types = qw(
@@ -95,7 +97,10 @@ sub elem
9597
# currently not required.
9698
push @scalar_types, qw(QualCost);
9799

98-
# Nodes from these input files don't need support functions, just node tags.
100+
# Nodes from these input files are automatically treated as nodetag_only.
101+
# In the future we might add explicit pg_node_attr labeling to some of these
102+
# files and remove them from this list, but for now this is the path of least
103+
# resistance.
99104
my @nodetag_only_files = qw(
100105
nodes/execnodes.h
101106
access/amapi.h
@@ -113,10 +118,8 @@ sub elem
113118

114119
# XXX various things we are not publishing right now to stay level
115120
# with the manual system
116-
push @no_copy, qw(CallContext InlineCodeBlock);
117-
push @no_equal, qw(CallContext InlineCodeBlock);
118121
push @no_read_write,
119-
qw(AccessPriv AlterTableCmd CallContext CreateOpClassItem FunctionParameter InferClause InlineCodeBlock ObjectWithArgs OnConflictClause PartitionCmd RoleSpec VacuumRelation);
122+
qw(AccessPriv AlterTableCmd CreateOpClassItem FunctionParameter InferClause ObjectWithArgs OnConflictClause PartitionCmd RoleSpec VacuumRelation);
120123
push @no_read, qw(A_ArrayExpr A_Indices A_Indirection AlterStatsStmt
121124
CollateClause ColumnDef ColumnRef CreateForeignTableStmt CreateStatsStmt
122125
CreateStmt FuncCall ImportForeignSchemaStmt IndexElem IndexStmt
@@ -254,6 +257,10 @@ sub elem
254257
{
255258
push @no_read, $in_struct;
256259
}
260+
elsif ($attr eq 'nodetag_only')
261+
{
262+
push @nodetag_only, $in_struct;
263+
}
257264
elsif ($attr eq 'special_read_write')
258265
{
259266
# This attribute is called
@@ -314,13 +321,9 @@ sub elem
314321
$node_type_info{$in_struct}->{field_types} = \%ft;
315322
$node_type_info{$in_struct}->{field_attrs} = \%fa;
316323

317-
# Exclude nodes in nodetag_only_files from support.
318-
if (elem $infile, @nodetag_only_files)
319-
{
320-
push @no_copy, $in_struct;
321-
push @no_equal, $in_struct;
322-
push @no_read_write, $in_struct;
323-
}
324+
# Propagate nodetag_only marking from files to nodes
325+
push @nodetag_only, $in_struct
326+
if (elem $infile, @nodetag_only_files);
324327

325328
# Propagate some node attributes from supertypes
326329
if ($supertype)
@@ -515,6 +518,7 @@ sub elem
515518
foreach my $n (@node_types)
516519
{
517520
next if elem $n, @abstract_types;
521+
next if elem $n, @nodetag_only;
518522
my $struct_no_copy = (elem $n, @no_copy);
519523
my $struct_no_equal = (elem $n, @no_equal);
520524
next if $struct_no_copy && $struct_no_equal;
@@ -706,6 +710,7 @@ sub elem
706710
foreach my $n (@node_types)
707711
{
708712
next if elem $n, @abstract_types;
713+
next if elem $n, @nodetag_only;
709714
next if elem $n, @no_read_write;
710715

711716
# XXX For now, skip all "Stmt"s except that ones that were there before.

src/include/nodes/nodes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ typedef enum NodeTag
6161
*
6262
* - no_read: Does not support nodeRead() at all.
6363
*
64+
* - nodetag_only: Does not support copyObject(), equal(), outNode(),
65+
* or nodeRead().
66+
*
6467
* - special_read_write: Has special treatment in outNode() and nodeRead().
6568
*
6669
* Node types can be supertypes of other types whether or not they are marked
6770
* abstract: if a node struct appears as the first field of another struct
6871
* type, then it is the supertype of that type. The no_copy, no_equal, and
6972
* no_read node attributes are automatically inherited from the supertype.
73+
* (Notice that nodetag_only does not inherit, so it's not quite equivalent
74+
* to a combination of other attributes.)
7075
*
7176
* Valid node field attributes:
7277
*

src/include/nodes/parsenodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,6 +3382,8 @@ typedef struct DoStmt
33823382

33833383
typedef struct InlineCodeBlock
33843384
{
3385+
pg_node_attr(nodetag_only) /* this is not a member of parse trees */
3386+
33853387
NodeTag type;
33863388
char *source_text; /* source text of anonymous code block */
33873389
Oid langOid; /* OID of selected language */
@@ -3408,6 +3410,8 @@ typedef struct CallStmt
34083410

34093411
typedef struct CallContext
34103412
{
3413+
pg_node_attr(nodetag_only) /* this is not a member of parse trees */
3414+
34113415
NodeTag type;
34123416
bool atomic;
34133417
} CallContext;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy