This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG142c6f82fda8: [clang] Simplify buildSyntaxTree API (authored by kbobyrev).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D90672/new/ https://reviews.llvm.org/D90672 Files: clang-tools-extra/clangd/SemanticSelection.cpp clang/include/clang/Tooling/Syntax/BuildTree.h clang/lib/Tooling/Syntax/BuildTree.cpp clang/unittests/Tooling/Syntax/TreeTestBase.cpp Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp =================================================================== --- clang/unittests/Tooling/Syntax/TreeTestBase.cpp +++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp @@ -81,7 +81,7 @@ Tokens = nullptr; // make sure we fail if this gets called twice. Arena = std::make_unique<syntax::Arena>(Ctx.getSourceManager(), Ctx.getLangOpts(), *TB); - Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl()); + Root = syntax::buildSyntaxTree(*Arena, Ctx); } private: Index: clang/lib/Tooling/Syntax/BuildTree.cpp =================================================================== --- clang/lib/Tooling/Syntax/BuildTree.cpp +++ clang/lib/Tooling/Syntax/BuildTree.cpp @@ -1711,9 +1711,9 @@ return It->second; } -syntax::TranslationUnit * -syntax::buildSyntaxTree(Arena &A, const TranslationUnitDecl &TU) { +syntax::TranslationUnit *syntax::buildSyntaxTree(Arena &A, + ASTContext &Context) { TreeBuilder Builder(A); - BuildTreeVisitor(TU.getASTContext(), Builder).TraverseAST(TU.getASTContext()); + BuildTreeVisitor(Context, Builder).TraverseAST(Context); return std::move(Builder).finalize(); } Index: clang/include/clang/Tooling/Syntax/BuildTree.h =================================================================== --- clang/include/clang/Tooling/Syntax/BuildTree.h +++ clang/include/clang/Tooling/Syntax/BuildTree.h @@ -19,8 +19,9 @@ namespace syntax { /// Build a syntax tree for the main file. -syntax::TranslationUnit *buildSyntaxTree(Arena &A, - const clang::TranslationUnitDecl &TU); +/// This usually covers the whole TranslationUnitDecl, but can be restricted by +/// the ASTContext's traversal scope. +syntax::TranslationUnit *buildSyntaxTree(Arena &A, ASTContext &Context); // Create syntax trees from subtrees not backed by the source code. Index: clang-tools-extra/clangd/SemanticSelection.cpp =================================================================== --- clang-tools-extra/clangd/SemanticSelection.cpp +++ clang-tools-extra/clangd/SemanticSelection.cpp @@ -160,8 +160,7 @@ // Related issue: https://github.com/clangd/clangd/issues/310 llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) { syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), AST.getTokens()); - const auto *SyntaxTree = - syntax::buildSyntaxTree(A, *AST.getASTContext().getTranslationUnitDecl()); + const auto *SyntaxTree = syntax::buildSyntaxTree(A, AST.getASTContext()); return collectFoldingRanges(SyntaxTree, AST.getSourceManager()); }
Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp =================================================================== --- clang/unittests/Tooling/Syntax/TreeTestBase.cpp +++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp @@ -81,7 +81,7 @@ Tokens = nullptr; // make sure we fail if this gets called twice. Arena = std::make_unique<syntax::Arena>(Ctx.getSourceManager(), Ctx.getLangOpts(), *TB); - Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl()); + Root = syntax::buildSyntaxTree(*Arena, Ctx); } private: Index: clang/lib/Tooling/Syntax/BuildTree.cpp =================================================================== --- clang/lib/Tooling/Syntax/BuildTree.cpp +++ clang/lib/Tooling/Syntax/BuildTree.cpp @@ -1711,9 +1711,9 @@ return It->second; } -syntax::TranslationUnit * -syntax::buildSyntaxTree(Arena &A, const TranslationUnitDecl &TU) { +syntax::TranslationUnit *syntax::buildSyntaxTree(Arena &A, + ASTContext &Context) { TreeBuilder Builder(A); - BuildTreeVisitor(TU.getASTContext(), Builder).TraverseAST(TU.getASTContext()); + BuildTreeVisitor(Context, Builder).TraverseAST(Context); return std::move(Builder).finalize(); } Index: clang/include/clang/Tooling/Syntax/BuildTree.h =================================================================== --- clang/include/clang/Tooling/Syntax/BuildTree.h +++ clang/include/clang/Tooling/Syntax/BuildTree.h @@ -19,8 +19,9 @@ namespace syntax { /// Build a syntax tree for the main file. -syntax::TranslationUnit *buildSyntaxTree(Arena &A, - const clang::TranslationUnitDecl &TU); +/// This usually covers the whole TranslationUnitDecl, but can be restricted by +/// the ASTContext's traversal scope. +syntax::TranslationUnit *buildSyntaxTree(Arena &A, ASTContext &Context); // Create syntax trees from subtrees not backed by the source code. Index: clang-tools-extra/clangd/SemanticSelection.cpp =================================================================== --- clang-tools-extra/clangd/SemanticSelection.cpp +++ clang-tools-extra/clangd/SemanticSelection.cpp @@ -160,8 +160,7 @@ // Related issue: https://github.com/clangd/clangd/issues/310 llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) { syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), AST.getTokens()); - const auto *SyntaxTree = - syntax::buildSyntaxTree(A, *AST.getASTContext().getTranslationUnitDecl()); + const auto *SyntaxTree = syntax::buildSyntaxTree(A, AST.getASTContext()); return collectFoldingRanges(SyntaxTree, AST.getSourceManager()); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits