[clang-tools-extra] 142c6f8 - [clang] Simplify buildSyntaxTree API

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 13:55:30 PST 2020


Author: Kirill Bobyrev
Date: 2020-11-09T22:49:54+01:00
New Revision: 142c6f82fda8d406ed26f1205d22dc1782653b32

URL: https://github.com/llvm/llvm-project/commit/142c6f82fda8d406ed26f1205d22dc1782653b32
DIFF: https://github.com/llvm/llvm-project/commit/142c6f82fda8d406ed26f1205d22dc1782653b32.diff

LOG: [clang] Simplify buildSyntaxTree API

Follow-up on https://reviews.llvm.org/D88553#inline-837013

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90672

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/SemanticSelection.cpp b/clang-tools-extra/clangd/SemanticSelection.cpp
index b855d7b63435..0cb66814f31b 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -160,8 +160,7 @@ llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
 // 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());
 }
 

diff  --git a/clang/include/clang/Tooling/Syntax/BuildTree.h b/clang/include/clang/Tooling/Syntax/BuildTree.h
index 537ade4b7151..3c8dd8ceed09 100644
--- a/clang/include/clang/Tooling/Syntax/BuildTree.h
+++ b/clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -19,8 +19,9 @@ namespace clang {
 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.
 

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 6777782e070d..7654e3dfaa01 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1711,9 +1711,9 @@ const syntax::Token *syntax::TreeBuilder::findToken(SourceLocation L) const {
   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();
 }

diff  --git a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
index 2305b78006b1..92d0c07ce235 100644
--- a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
@@ -81,7 +81,7 @@ SyntaxTreeTest::buildTree(StringRef Code, const TestClangConfig &ClangConfig) {
       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:


        


More information about the cfe-commits mailing list