mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[clang] Simplify buildSyntaxTree API
Follow-up on https://reviews.llvm.org/D88553#inline-837013 Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D90672
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user