Skip to content

Syntax: use child name instead of type name for gyb-generated functions. NFC #24176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/swift/Parse/ParsedSyntaxBuilders.h.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Parsed${node.name}Builder {
% if child_node and child_node.is_syntax_collection():
% child_elt = child_node.collection_element_name
% child_elt_type = child_node.collection_element_type
SmallVector<ParsedRawSyntaxNode, 8> ${child_elt}Nodes;
% child_elt_name = child.name + 'Member'
SmallVector<ParsedRawSyntaxNode, 8> ${child_elt_name}s;
% end
% end

Expand All @@ -55,7 +56,8 @@ public:
% if child_node and child_node.is_syntax_collection():
% child_elt = child_node.collection_element_name
% child_elt_type = child_node.collection_element_type
Parsed${node.name}Builder &add${child_elt}(Parsed${child_elt_type} ${child_elt});
% child_elt_name = child.name + 'Member'
Parsed${node.name}Builder &add${child_elt_name}(Parsed${child_elt_type} ${child_elt});
% end
% end

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Syntax/SyntaxNodes.h.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public:
/// `${child.name}` collection.
/// - returns: A copy of the receiver with the provided `${child_elt}`
/// appended to its `${child.name}` collection.
${node.name} add${child_elt}(${child_elt_type} ${child_elt});
${node.name} add${child.name}Member(${child_elt_type} ${child_elt});
% end

/// Returns a copy of the receiver with its `${child.name}` replaced.
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
.useArguments(Arguments)
.useRightParen(RightParen);
} else {
Builder.addTupleTypeElement(ParsedSyntaxRecorder::makeTupleTypeElement(
Builder.addArgumentsMember(ParsedSyntaxRecorder::makeTupleTypeElement(
InputNode, /*TrailingComma=*/None, *SyntaxContext));
}
SyntaxContext->addSyntax(Builder.build());
Expand Down
13 changes: 7 additions & 6 deletions lib/Parse/ParsedSyntaxBuilders.cpp.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ using namespace swift::syntax;
% if child_node and child_node.is_syntax_collection():
% child_elt = child_node.collection_element_name
% child_elt_type = child_node.collection_element_type
% child_elt_name = child.name + 'Member'
% end
Parsed${node.name}Builder &
Parsed${node.name}Builder::use${child.name}(Parsed${child.type_name} ${child.name}) {
% if child_elt:
assert(${child_elt}Nodes.empty() && "use either 'use' function or 'add', not both");
assert(${child_elt_name}s.empty() && "use either 'use' function or 'add', not both");
% end
Layout[cursorIndex(${node.name}::Cursor::${child.name})] =
${child.name}.getRaw();
return *this;
}
% if child_elt:
Parsed${node.name}Builder &
Parsed${node.name}Builder::add${child_elt}(Parsed${child_elt_type} ${child_elt}) {
Parsed${node.name}Builder::add${child_elt_name}(Parsed${child_elt_type} ${child_elt}) {
assert(Layout[cursorIndex(${node.name}::Cursor::${child.name})].isNull() && "use either 'use' function or 'add', not both");
${child_elt}Nodes.push_back(std::move(${child_elt}.getRaw()));
${child_elt_name}s.push_back(std::move(${child_elt}.getRaw()));
return *this;
}
% end
Expand Down Expand Up @@ -88,12 +89,12 @@ void Parsed${node.name}Builder::finishLayout(bool deferred) {
% if child_node and child_node.is_syntax_collection():
% child_elt = child_node.collection_element_name
% if child_elt:
if (!${child_elt}Nodes.empty()) {
if (!${child_elt_name}s.empty()) {
if (deferred) {
Layout[${idx}] = ParsedRawSyntaxNode::makeDeferred(SyntaxKind::${child_node.syntax_kind},
${child_elt}Nodes, SPCtx);
${child_elt_name}s, SPCtx);
} else {
Layout[${idx}] = Rec.recordRawSyntax(SyntaxKind::${child_node.syntax_kind}, ${child_elt}Nodes);
Layout[${idx}] = Rec.recordRawSyntax(SyntaxKind::${child_node.syntax_kind}, ${child_elt_name}s);
}
}
% end
Expand Down
3 changes: 2 additions & 1 deletion lib/Syntax/SyntaxNodes.cpp.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ ${child.type_name} ${node.name}::get${child.name}() {
% if child_node and child_node.is_syntax_collection():
% child_elt = child_node.collection_element_name
% child_elt_type = child_node.collection_element_type
${node.name} ${node.name}::add${child_elt}(${child_elt_type} ${child_elt}) {
% child_elt_name = child.name + 'Member'
${node.name} ${node.name}::add${child_elt_name}(${child_elt_type} ${child_elt}) {
RC<RawSyntax> raw = getRaw()->getChild(Cursor::${child.name});
if (raw)
raw = raw->append(${child_elt}.getRaw());
Expand Down
8 changes: 4 additions & 4 deletions unittests/Syntax/TypeSyntaxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ TEST(TypeSyntaxTests, FunctionTypeWithAPIs) {

SyntaxFactory::makeBlankFunctionType()
.withLeftParen(LeftParen)
.addTupleTypeElement(xArg)
.addTupleTypeElement(yArg)
.addArgumentsMember(xArg)
.addArgumentsMember(yArg)
.withRightParen(RightParen)
.withThrowsOrRethrowsKeyword(Throws)
.withArrow(Arrow)
Expand All @@ -580,8 +580,8 @@ TEST(TypeSyntaxTests, FunctionTypeWithAPIs) {
SyntaxFactory::makeBlankFunctionType()
.withLeftParen(LeftParen)
.withRightParen(RightParen)
.addTupleTypeElement(IntArg.withTrailingComma(Comma))
.addTupleTypeElement(IntArg)
.addArgumentsMember(IntArg.withTrailingComma(Comma))
.addArgumentsMember(IntArg)
.withThrowsOrRethrowsKeyword(Rethrows)
.withArrow(Arrow)
.withReturnType(Int)
Expand Down