Skip to content

Commit a9ba1ce

Browse files
authored
Merge pull request #24176 from nkcsgexi/syntax-disambiguity
Syntax: use child name instead of type name for gyb-generated functions. NFC
2 parents 5c941e0 + 1015a60 commit a9ba1ce

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

include/swift/Parse/ParsedSyntaxBuilders.h.gyb

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class Parsed${node.name}Builder {
4141
% if child_node and child_node.is_syntax_collection():
4242
% child_elt = child_node.collection_element_name
4343
% child_elt_type = child_node.collection_element_type
44-
SmallVector<ParsedRawSyntaxNode, 8> ${child_elt}Nodes;
44+
% child_elt_name = child.name + 'Member'
45+
SmallVector<ParsedRawSyntaxNode, 8> ${child_elt_name}s;
4546
% end
4647
% end
4748

@@ -55,7 +56,8 @@ public:
5556
% if child_node and child_node.is_syntax_collection():
5657
% child_elt = child_node.collection_element_name
5758
% child_elt_type = child_node.collection_element_type
58-
Parsed${node.name}Builder &add${child_elt}(Parsed${child_elt_type} ${child_elt});
59+
% child_elt_name = child.name + 'Member'
60+
Parsed${node.name}Builder &add${child_elt_name}(Parsed${child_elt_type} ${child_elt});
5961
% end
6062
% end
6163

include/swift/Syntax/SyntaxNodes.h.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public:
9696
/// `${child.name}` collection.
9797
/// - returns: A copy of the receiver with the provided `${child_elt}`
9898
/// appended to its `${child.name}` collection.
99-
${node.name} add${child_elt}(${child_elt_type} ${child_elt});
99+
${node.name} add${child.name}Member(${child_elt_type} ${child_elt});
100100
% end
101101

102102
/// Returns a copy of the receiver with its `${child.name}` replaced.

lib/Parse/ParseType.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
442442
.useArguments(Arguments)
443443
.useRightParen(RightParen);
444444
} else {
445-
Builder.addTupleTypeElement(ParsedSyntaxRecorder::makeTupleTypeElement(
445+
Builder.addArgumentsMember(ParsedSyntaxRecorder::makeTupleTypeElement(
446446
InputNode, /*TrailingComma=*/None, *SyntaxContext));
447447
}
448448
SyntaxContext->addSyntax(Builder.build());

lib/Parse/ParsedSyntaxBuilders.cpp.gyb

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ using namespace swift::syntax;
3535
% if child_node and child_node.is_syntax_collection():
3636
% child_elt = child_node.collection_element_name
3737
% child_elt_type = child_node.collection_element_type
38+
% child_elt_name = child.name + 'Member'
3839
% end
3940
Parsed${node.name}Builder &
4041
Parsed${node.name}Builder::use${child.name}(Parsed${child.type_name} ${child.name}) {
4142
% if child_elt:
42-
assert(${child_elt}Nodes.empty() && "use either 'use' function or 'add', not both");
43+
assert(${child_elt_name}s.empty() && "use either 'use' function or 'add', not both");
4344
% end
4445
Layout[cursorIndex(${node.name}::Cursor::${child.name})] =
4546
${child.name}.getRaw();
4647
return *this;
4748
}
4849
% if child_elt:
4950
Parsed${node.name}Builder &
50-
Parsed${node.name}Builder::add${child_elt}(Parsed${child_elt_type} ${child_elt}) {
51+
Parsed${node.name}Builder::add${child_elt_name}(Parsed${child_elt_type} ${child_elt}) {
5152
assert(Layout[cursorIndex(${node.name}::Cursor::${child.name})].isNull() && "use either 'use' function or 'add', not both");
52-
${child_elt}Nodes.push_back(std::move(${child_elt}.getRaw()));
53+
${child_elt_name}s.push_back(std::move(${child_elt}.getRaw()));
5354
return *this;
5455
}
5556
% end
@@ -88,12 +89,12 @@ void Parsed${node.name}Builder::finishLayout(bool deferred) {
8889
% if child_node and child_node.is_syntax_collection():
8990
% child_elt = child_node.collection_element_name
9091
% if child_elt:
91-
if (!${child_elt}Nodes.empty()) {
92+
if (!${child_elt_name}s.empty()) {
9293
if (deferred) {
9394
Layout[${idx}] = ParsedRawSyntaxNode::makeDeferred(SyntaxKind::${child_node.syntax_kind},
94-
${child_elt}Nodes, SPCtx);
95+
${child_elt_name}s, SPCtx);
9596
} else {
96-
Layout[${idx}] = Rec.recordRawSyntax(SyntaxKind::${child_node.syntax_kind}, ${child_elt}Nodes);
97+
Layout[${idx}] = Rec.recordRawSyntax(SyntaxKind::${child_node.syntax_kind}, ${child_elt_name}s);
9798
}
9899
}
99100
% end

lib/Syntax/SyntaxNodes.cpp.gyb

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ ${child.type_name} ${node.name}::get${child.name}() {
7171
% if child_node and child_node.is_syntax_collection():
7272
% child_elt = child_node.collection_element_name
7373
% child_elt_type = child_node.collection_element_type
74-
${node.name} ${node.name}::add${child_elt}(${child_elt_type} ${child_elt}) {
74+
% child_elt_name = child.name + 'Member'
75+
${node.name} ${node.name}::add${child_elt_name}(${child_elt_type} ${child_elt}) {
7576
RC<RawSyntax> raw = getRaw()->getChild(Cursor::${child.name});
7677
if (raw)
7778
raw = raw->append(${child_elt}.getRaw());

unittests/Syntax/TypeSyntaxTests.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ TEST(TypeSyntaxTests, FunctionTypeWithAPIs) {
562562

563563
SyntaxFactory::makeBlankFunctionType()
564564
.withLeftParen(LeftParen)
565-
.addTupleTypeElement(xArg)
566-
.addTupleTypeElement(yArg)
565+
.addArgumentsMember(xArg)
566+
.addArgumentsMember(yArg)
567567
.withRightParen(RightParen)
568568
.withThrowsOrRethrowsKeyword(Throws)
569569
.withArrow(Arrow)
@@ -580,8 +580,8 @@ TEST(TypeSyntaxTests, FunctionTypeWithAPIs) {
580580
SyntaxFactory::makeBlankFunctionType()
581581
.withLeftParen(LeftParen)
582582
.withRightParen(RightParen)
583-
.addTupleTypeElement(IntArg.withTrailingComma(Comma))
584-
.addTupleTypeElement(IntArg)
583+
.addArgumentsMember(IntArg.withTrailingComma(Comma))
584+
.addArgumentsMember(IntArg)
585585
.withThrowsOrRethrowsKeyword(Rethrows)
586586
.withArrow(Arrow)
587587
.withReturnType(Int)

0 commit comments

Comments
 (0)