diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-25 17:01:33 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-25 17:01:33 +0000 |
commit | 266c0c986eb43ba113b3653e2c996af3ca257713 (patch) | |
tree | 6184504aba659da490bf596c12c4c4e13621a0f2 | |
parent | 8a6fa5cade1b3e402e3e161936045361eeaa426f (diff) | |
download | clang_35a-266c0c986eb43ba113b3653e2c996af3ca257713.tar.gz |
Push unique_ptr ownership of ASTUnits further back into their factories.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207237 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 16 | ||||
-rw-r--r-- | include/clang/Tooling/Tooling.h | 11 | ||||
-rw-r--r-- | lib/Frontend/ASTUnit.cpp | 23 | ||||
-rw-r--r-- | lib/Tooling/Tooling.cpp | 16 | ||||
-rw-r--r-- | unittests/Tooling/ToolingTest.cpp | 4 |
5 files changed, 34 insertions, 36 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index b730cb9da7..17675c3037 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -775,15 +775,13 @@ public: // // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we // shouldn't need to specify them at construction time. - static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI, - IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - bool OnlyLocalDecls = false, - bool CaptureDiagnostics = false, - bool PrecompilePreamble = false, - TranslationUnitKind TUKind = TU_Complete, - bool CacheCodeCompletionResults = false, - bool IncludeBriefCommentsInCodeCompletion = false, - bool UserFilesAreVolatile = false); + static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation( + CompilerInvocation *CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, + bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete, + bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false, + bool UserFilesAreVolatile = false); /// LoadFromCommandLine - Create an ASTUnit from a vector of command line /// arguments, which must specify exactly one source file. diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index 46c988b7e7..ece38fc7e7 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -161,8 +161,8 @@ bool runToolOnCodeWithArgs(clang::FrontendAction *ToolAction, const Twine &Code, /// \param FileName The file name which 'Code' will be mapped as. /// /// \return The resulting AST or null if an error occurred. -ASTUnit *buildASTFromCode(const Twine &Code, - const Twine &FileName = "input.cc"); +std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code, + const Twine &FileName = "input.cc"); /// \brief Builds an AST for 'Code' with additional flags. /// @@ -171,9 +171,10 @@ ASTUnit *buildASTFromCode(const Twine &Code, /// \param FileName The file name which 'Code' will be mapped as. /// /// \return The resulting AST or null if an error occurred. -ASTUnit *buildASTFromCodeWithArgs(const Twine &Code, - const std::vector<std::string> &Args, - const Twine &FileName = "input.cc"); +std::unique_ptr<ASTUnit> +buildASTFromCodeWithArgs(const Twine &Code, + const std::vector<std::string> &Args, + const Twine &FileName = "input.cc"); /// \brief Utility to run a FrontendAction in a single clang invocation. class ToolInvocation { diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index b35fcf196d..7416987086 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -51,6 +51,7 @@ using namespace clang; using llvm::TimeRecord; +using llvm::make_unique; namespace { class SimpleTimer { @@ -1945,18 +1946,13 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) { return Parse(OverrideMainBuffer); } -ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, - IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - bool OnlyLocalDecls, - bool CaptureDiagnostics, - bool PrecompilePreamble, - TranslationUnitKind TUKind, - bool CacheCodeCompletionResults, - bool IncludeBriefCommentsInCodeCompletion, - bool UserFilesAreVolatile) { +std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation( + CompilerInvocation *CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, + TranslationUnitKind TUKind, bool CacheCodeCompletionResults, + bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile) { // Create the AST unit. - std::unique_ptr<ASTUnit> AST; - AST.reset(new ASTUnit(false)); + std::unique_ptr<ASTUnit> AST(new ASTUnit(false)); ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics); AST->Diagnostics = Diags; AST->OnlyLocalDecls = OnlyLocalDecls; @@ -1981,8 +1977,9 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> > DiagCleanup(Diags.getPtr()); - return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0 - : AST.release(); + if (AST->LoadFromCompilerInvocation(PrecompilePreamble)) + return nullptr; + return AST; } ASTUnit *ASTUnit::LoadFromCommandLine( diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 9bd85ee357..5f4c46d6ef 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -379,10 +379,10 @@ public: bool runInvocation(CompilerInvocation *Invocation, FileManager *Files, DiagnosticConsumer *DiagConsumer) override { // FIXME: This should use the provided FileManager. - std::unique_ptr<ASTUnit> AST(ASTUnit::LoadFromCompilerInvocation( + std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation( Invocation, CompilerInstance::createDiagnostics( &Invocation->getDiagnosticOpts(), DiagConsumer, - /*ShouldOwnClient=*/false))); + /*ShouldOwnClient=*/false)); if (!AST) return false; @@ -398,13 +398,15 @@ int ClangTool::buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs) { return run(&Action); } -ASTUnit *buildASTFromCode(const Twine &Code, const Twine &FileName) { +std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code, + const Twine &FileName) { return buildASTFromCodeWithArgs(Code, std::vector<std::string>(), FileName); } -ASTUnit *buildASTFromCodeWithArgs(const Twine &Code, - const std::vector<std::string> &Args, - const Twine &FileName) { +std::unique_ptr<ASTUnit> +buildASTFromCodeWithArgs(const Twine &Code, + const std::vector<std::string> &Args, + const Twine &FileName) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); @@ -419,7 +421,7 @@ ASTUnit *buildASTFromCodeWithArgs(const Twine &Code, return 0; assert(ASTs.size() == 1); - return ASTs[0].release(); + return std::move(ASTs[0]); } } // end namespace tooling diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index 606eda15df..2d055e7085 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/unittests/Tooling/ToolingTest.cpp @@ -108,11 +108,11 @@ TEST(runToolOnCode, FindsClassDecl) { } TEST(buildASTFromCode, FindsClassDecl) { - std::unique_ptr<ASTUnit> AST(buildASTFromCode("class X;")); + std::unique_ptr<ASTUnit> AST = buildASTFromCode("class X;"); ASSERT_TRUE(AST.get()); EXPECT_TRUE(FindClassDeclX(AST.get())); - AST.reset(buildASTFromCode("class Y;")); + AST = buildASTFromCode("class Y;"); ASSERT_TRUE(AST.get()); EXPECT_FALSE(FindClassDeclX(AST.get())); } |