summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp23
-rw-r--r--clang/lib/Tooling/Tooling.cpp16
2 files changed, 19 insertions, 20 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index b35fcf196d7..74169870868 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/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/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 9bd85ee357a..5f4c46d6ef3 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud