[PATCH] D90672: [clang] Simplify buildSyntaxTree API
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 13:55:37 PST 2020
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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90672.303985.patch
Type: text/x-patch
Size: 2735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201109/9acda800/attachment-0001.bin>
More information about the cfe-commits
mailing list