Skip to content

Commit 57807fb

Browse files
authored
Merge pull request #60334 from ahoppen/pr/missing-base-nodes
Introduce a new syntax kind to represent missing base nodes
2 parents 227f0de + e643fb1 commit 57807fb

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

utils/gyb_syntax_support/CommonNodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
Node('UnknownStmt', kind='Stmt'),
1313
Node('UnknownType', kind='Type'),
1414
Node('UnknownPattern', kind='Pattern'),
15+
Node('Missing', kind='Syntax'),
16+
Node('MissingDecl', kind='Decl'),
17+
Node('MissingExpr', kind='Expr'),
18+
Node('MissingStmt', kind='Stmt'),
19+
Node('MissingType', kind='Type'),
20+
Node('MissingPattern', kind='Pattern'),
1521

1622
# code-block-item = (decl | stmt | expr) ';'?
1723
Node('CodeBlockItem', kind='Syntax', omit_when_empty=True,

utils/gyb_syntax_support/Node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,19 @@ def is_unknown(self):
6969
"""
7070
return "Unknown" in self.syntax_kind
7171

72+
def is_missing(self):
73+
"""
74+
Returns `True` if this node is a `Missing` syntax subclass.
75+
"""
76+
return "Missing" in self.syntax_kind
77+
7278
def is_buildable(self):
7379
"""
7480
Returns `True` if this node should have a builder associated.
7581
"""
7682
return not self.is_base() and \
7783
not self.is_unknown() and \
84+
not self.is_missing() and \
7885
not self.is_syntax_collection()
7986

8087
def shall_be_omitted_when_empty(self):

utils/gyb_syntax_support/NodeSerializationCodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@
261261
'BackDeployAttributeSpecList' : 257,
262262
'BackDeployVersionList' : 258,
263263
'BackDeployVersionArgument' : 259,
264+
'Missing': 260,
265+
'MissingDecl': 261,
266+
'MissingExpr': 262,
267+
'MissingStmt': 263,
268+
'MissingType': 264,
269+
'MissingPattern': 265,
264270
}
265271

266272

utils/gyb_syntax_support/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
from .StmtNodes import STMT_NODES # noqa: I201
1616
from .Trivia import TRIVIAS # noqa: I201
1717
from .TypeNodes import TYPE_NODES # noqa: I201
18+
from .kinds import SYNTAX_BASE_KINDS # noqa: I201
1819

1920

2021
# Re-export global constants
2122
SYNTAX_NODES = COMMON_NODES + EXPR_NODES + DECL_NODES + ATTRIBUTE_NODES + \
2223
STMT_NODES + GENERIC_NODES + TYPE_NODES + PATTERN_NODES + \
2324
AVAILABILITY_NODES
25+
NON_BASE_SYNTAX_NODES = [node for node in SYNTAX_NODES if not node.is_base()]
2426
SYNTAX_TOKENS = Token.SYNTAX_TOKENS
2527
SYNTAX_TOKEN_MAP = Token.SYNTAX_TOKEN_MAP
2628
SYNTAX_CLASSIFICATIONS = Classification.SYNTAX_CLASSIFICATIONS
@@ -121,8 +123,12 @@ def make_missing_swift_child(child):
121123
tok_kind += '("")'
122124
return 'RawSyntax.missingToken(TokenKind.%s)' % tok_kind
123125
else:
124-
missing_kind = "unknown" if child.syntax_kind == "Syntax" \
125-
else child.swift_syntax_kind
126+
if child.syntax_kind == "Syntax":
127+
missing_kind = "unknown"
128+
elif child.syntax_kind in SYNTAX_BASE_KINDS:
129+
missing_kind = f"missing{child.syntax_kind}"
130+
else:
131+
missing_kind = child.swift_syntax_kind
126132
return 'RawSyntax.missing(SyntaxKind.%s)' % missing_kind
127133

128134

0 commit comments

Comments
 (0)