Skip to content

Commit 142c6f8

Browse files
committed
[clang] Simplify buildSyntaxTree API
Follow-up on https://reviews.llvm.org/D88553#inline-837013 Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D90672
1 parent 4d81c8a commit 142c6f8

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

clang-tools-extra/clangd/SemanticSelection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
160160
// Related issue: https://github.com/clangd/clangd/issues/310
161161
llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
162162
syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), AST.getTokens());
163-
const auto *SyntaxTree =
164-
syntax::buildSyntaxTree(A, *AST.getASTContext().getTranslationUnitDecl());
163+
const auto *SyntaxTree = syntax::buildSyntaxTree(A, AST.getASTContext());
165164
return collectFoldingRanges(SyntaxTree, AST.getSourceManager());
166165
}
167166

clang/include/clang/Tooling/Syntax/BuildTree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace clang {
1919
namespace syntax {
2020

2121
/// Build a syntax tree for the main file.
22-
syntax::TranslationUnit *buildSyntaxTree(Arena &A,
23-
const clang::TranslationUnitDecl &TU);
22+
/// This usually covers the whole TranslationUnitDecl, but can be restricted by
23+
/// the ASTContext's traversal scope.
24+
syntax::TranslationUnit *buildSyntaxTree(Arena &A, ASTContext &Context);
2425

2526
// Create syntax trees from subtrees not backed by the source code.
2627

clang/lib/Tooling/Syntax/BuildTree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,9 @@ const syntax::Token *syntax::TreeBuilder::findToken(SourceLocation L) const {
17111711
return It->second;
17121712
}
17131713

1714-
syntax::TranslationUnit *
1715-
syntax::buildSyntaxTree(Arena &A, const TranslationUnitDecl &TU) {
1714+
syntax::TranslationUnit *syntax::buildSyntaxTree(Arena &A,
1715+
ASTContext &Context) {
17161716
TreeBuilder Builder(A);
1717-
BuildTreeVisitor(TU.getASTContext(), Builder).TraverseAST(TU.getASTContext());
1717+
BuildTreeVisitor(Context, Builder).TraverseAST(Context);
17181718
return std::move(Builder).finalize();
17191719
}

clang/unittests/Tooling/Syntax/TreeTestBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SyntaxTreeTest::buildTree(StringRef Code, const TestClangConfig &ClangConfig) {
8181
Tokens = nullptr; // make sure we fail if this gets called twice.
8282
Arena = std::make_unique<syntax::Arena>(Ctx.getSourceManager(),
8383
Ctx.getLangOpts(), *TB);
84-
Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
84+
Root = syntax::buildSyntaxTree(*Arena, Ctx);
8585
}
8686

8787
private:

0 commit comments

Comments
 (0)