forked from OSchip/llvm-project
Push unique_ptr ownership of ASTUnits further back into their factories.
llvm-svn: 207237
This commit is contained in:
parent
0840a22452
commit
103a2de0b4
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue