mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
libSyntax: specialize struct declaration syntax node. (#13307)
To construct struct syntax, this patch first specialized type inheritance clause. For protocol's class requirement, we currently treat it as an unknown type. This patch also teaches SyntaxParsingContext to collect syntax nodes from back in place. This is useful to squash multiple decl modifiers for declarations like function. This is not used for struct declaration because only accessibility modifier is allowed.
This commit is contained in:
@@ -126,6 +126,21 @@ void SyntaxParsingContext::createNodeInPlace(SyntaxKind Kind) {
|
||||
}
|
||||
}
|
||||
|
||||
void SyntaxParsingContext::collectNodesInPlace(SyntaxKind ColletionKind) {
|
||||
assert(isCollectionKind(ColletionKind));
|
||||
assert(isTopOfContextStack());
|
||||
if (!Enabled)
|
||||
return;
|
||||
auto Count = std::count_if(Parts.rbegin(), Parts.rend(),
|
||||
[&](const RC<RawSyntax> &Raw) {
|
||||
return SyntaxFactory::canServeAsCollectionMember(ColletionKind,
|
||||
make<Syntax>(Raw));
|
||||
});
|
||||
if (Count) {
|
||||
createNodeInPlace(ColletionKind, Count);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
RC<RawSyntax> bridgeAs(SyntaxContextKind Kind, ArrayRef<RC<RawSyntax>> Parts) {
|
||||
if (Parts.size() == 1) {
|
||||
|
||||
Reference in New Issue
Block a user