eduucaldas updated this revision to Diff 283638. eduucaldas added a comment.
Clean List specific code Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85440/new/ https://reviews.llvm.org/D85440 Files: clang/include/clang/Tooling/Syntax/Nodes.h clang/lib/Tooling/Syntax/BuildTree.cpp clang/lib/Tooling/Syntax/Nodes.cpp
Index: clang/lib/Tooling/Syntax/Nodes.cpp =================================================================== --- clang/lib/Tooling/Syntax/Nodes.cpp +++ clang/lib/Tooling/Syntax/Nodes.cpp @@ -200,10 +200,6 @@ return OS << "IdExpression_id"; case syntax::NodeRole::IdExpression_qualifier: return OS << "IdExpression_qualifier"; - case syntax::NodeRole::NestedNameSpecifier_specifier: - return OS << "NestedNameSpecifier_specifier"; - case syntax::NodeRole::NestedNameSpecifier_delimiter: - return OS << "NestedNameSpecifier_delimiter"; case syntax::NodeRole::ParenExpression_subExpression: return OS << "ParenExpression_subExpression"; } @@ -219,23 +215,29 @@ syntax::SimpleTemplateSpecifier *>::getFromOpaqueValue(firstChild()); } -std::vector<syntax::Leaf *> syntax::NestedNameSpecifier::delimiters() { - std::vector<syntax::Leaf *> Children; - for (auto *C = firstChild(); C; C = C->nextSibling()) { - assert(C->role() == syntax::NodeRole::NestedNameSpecifier_delimiter); - Children.push_back(llvm::cast<syntax::Leaf>(C)); +// We could have an interator in list to not pay memory costs of temporary +// vector +std::vector<syntax::NameSpecifier *> syntax::NestedNameSpecifier::specifiers() { + auto specifiersAsNodes = getElementsAsNodes(); + std::vector<syntax::NameSpecifier *> Children; + for (const auto &element : specifiersAsNodes) { + Children.push_back(llvm::cast<syntax::NameSpecifier>(element)); } return Children; } -std::vector<syntax::NameSpecifier *> syntax::NestedNameSpecifier::specifiers() { - std::vector<syntax::NameSpecifier *> Children; - for (auto *C = firstChild(); C; C = C->nextSibling()) { - assert(C->role() == syntax::NodeRole::NestedNameSpecifier_specifier); - Children.push_back(llvm::cast<syntax::NameSpecifier>(C)); +std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>> +syntax::NestedNameSpecifier::specifiersAndDoubleColons() { + auto specifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters(); + std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>> + Children; + for (const auto &specifierAndDoubleColon : specifiersAsNodesAndDoubleColons) { + Children.push_back( + {llvm::cast<syntax::NameSpecifier>(specifierAndDoubleColon.element), + specifierAndDoubleColon.delimiter}); } return Children; -} +}; syntax::NestedNameSpecifier *syntax::IdExpression::qualifier() { return llvm::cast_or_null<syntax::NestedNameSpecifier>( Index: clang/lib/Tooling/Syntax/BuildTree.cpp =================================================================== --- clang/lib/Tooling/Syntax/BuildTree.cpp +++ clang/lib/Tooling/Syntax/BuildTree.cpp @@ -895,9 +895,8 @@ for (auto it = QualifierLoc; it; it = it.getPrefix()) { auto *NS = BuildNameSpecifier(it); assert(NS); - Builder.markChild(NS, syntax::NodeRole::NestedNameSpecifier_specifier); - Builder.markChildToken(it.getEndLoc(), - syntax::NodeRole::NestedNameSpecifier_delimiter); + Builder.markChild(NS, syntax::NodeRole::List_element); + Builder.markChildToken(it.getEndLoc(), syntax::NodeRole::List_delimiter); } Builder.foldNode(Builder.getRange(QualifierLoc.getSourceRange()), new (allocator()) syntax::NestedNameSpecifier, Index: clang/include/clang/Tooling/Syntax/Nodes.h =================================================================== --- clang/include/clang/Tooling/Syntax/Nodes.h +++ clang/include/clang/Tooling/Syntax/Nodes.h @@ -174,8 +174,6 @@ ParametersAndQualifiers_trailingReturn, IdExpression_id, IdExpression_qualifier, - NestedNameSpecifier_specifier, - NestedNameSpecifier_delimiter, ParenExpression_subExpression }; /// For debugging purposes. @@ -235,14 +233,15 @@ /// Models a `nested-name-specifier`. C++ [expr.prim.id.qual] /// e.g. the `std::vector<int>::` in `std::vector<int>::size`. -class NestedNameSpecifier final : public Tree { +class NestedNameSpecifier final : public List { public: - NestedNameSpecifier() : Tree(NodeKind::NestedNameSpecifier) {} + NestedNameSpecifier() : List(NodeKind::NestedNameSpecifier) {} static bool classof(const Node *N) { return N->kind() <= NodeKind::NestedNameSpecifier; } std::vector<syntax::NameSpecifier *> specifiers(); - std::vector<syntax::Leaf *> delimiters(); + std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>> + specifiersAndDoubleColons(); }; /// Models an `unqualified-id`. C++ [expr.prim.id.unqual]
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits