Skip to content

Commit 21fc2fb

Browse files
committed
libSyntax: use node choices for closure parameters.
This is to incorporate two styles of closure parameters: "a, b, c" or "(a: T1, b: T2, c: T3)".
1 parent 6c1f682 commit 21fc2fb

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

Diff for: include/swift/Syntax/RawSyntax.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ using llvm::StringRef;
101101
#endif
102102

103103
#ifndef NDEBUG
104-
#define syntax_assert_node_choice(Raw, CursorName) \
104+
#define syntax_assert_node_choice(Raw, CursorName, NodeName) \
105105
({ \
106106
auto Child = Raw->getChild(Cursor::CursorName); \
107107
auto Node = make<Syntax>(Child); \
108-
assert(check##CursorName(Node)); \
108+
assert(check##CursorName##In##NodeName(Node)); \
109109
})
110110
#else
111-
#define syntax_assert_node_choice(Raw, CursorName) ({});
111+
#define syntax_assert_node_choice(Raw, CursorName, NodeName) ({});
112112
#endif
113113

114114
namespace swift {

Diff for: include/swift/Syntax/SyntaxNodes.h.gyb

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public:
100100
% end
101101
% end
102102

103-
bool checkAccessorListOrStmtList(const Syntax &S);
103+
bool checkAccessorListOrStmtListInAccessorBlock(const Syntax &S);
104+
bool checkInputInClosureSignature(const Syntax &S);
104105
}
105106
}
106107

Diff for: lib/Syntax/SyntaxFactory.cpp.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ SyntaxFactory::createSyntax(SyntaxKind Kind, llvm::ArrayRef<Syntax> Elements) {
149149
% elif child.node_choices:
150150
{ ${option},
151151
[] (const Syntax &S) {
152-
return check${child.name}(S);
152+
return check${child.name}In${node.syntax_kind}(S);
153153
}
154154
},
155155
% else:

Diff for: lib/Syntax/SyntaxNodes.cpp.gyb

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ using namespace swift;
2525
using namespace swift::syntax;
2626

2727

28-
bool swift::syntax::checkAccessorListOrStmtList(const Syntax &S) {
28+
bool swift::syntax::
29+
checkAccessorListOrStmtListInAccessorBlock(const Syntax &S) {
2930
return S.getKind() == SyntaxKind::AccessorList ||
3031
S.getKind() == SyntaxKind::StmtList;
3132
}
3233

34+
bool swift::syntax::checkInputInClosureSignature(const Syntax &S) {
35+
return S.getKind() == SyntaxKind::ClosureParamList ||
36+
S.getKind() == SyntaxKind::ParameterClause;
37+
}
38+
3339
% for node in SYNTAX_NODES:
3440
% if node.requires_validation():
3541
void ${node.name}::validate() const {
@@ -51,7 +57,7 @@ void ${node.name}::validate() const {
5157
tok::${token_kind}, ${choices});
5258
% end
5359
% if child.node_choices:
54-
syntax_assert_node_choice(raw, ${child.name});
60+
syntax_assert_node_choice(raw, ${child.name}, ${node.syntax_kind});
5561
% end
5662
% end
5763
}

Diff for: utils/gyb_syntax_support/ExprNodes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@
300300
children=[
301301
Child('Capture', kind='ClosureCaptureSignature',
302302
is_optional=True),
303-
# FIXME: one and only one of these two children is required
304-
Child('SimpleInput', kind='ClosureParamList', is_optional=True),
305-
Child('Input', kind='ParameterClause', is_optional=True),
303+
Child('Input', kind='Syntax', is_optional=True,
304+
node_choices=[
305+
Child('SimpleInput', kind='ClosureParamList'),
306+
Child('Input', kind='ParameterClause'),
307+
]),
306308
Child('ThrowsTok', kind='ThrowsToken', is_optional=True),
307309
Child('Output', kind='ReturnClause', is_optional=True),
308310
Child('InTok', kind='InToken'),

Diff for: utils/gyb_syntax_support/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def make_missing_child(child):
2828
else:
2929
missing_kind = "Unknown" if child.syntax_kind == "Syntax" \
3030
else child.syntax_kind
31+
if child.node_choices:
32+
return make_missing_child(child.node_choices[0])
3133
return 'RawSyntax::missing(SyntaxKind::%s)' % missing_kind
3234

3335

0 commit comments

Comments
 (0)