|
@@ -245,7 +245,7 @@ ASTUnit::~ASTUnit() {
|
|
// perform this operation here because we explicitly request that the
|
|
// perform this operation here because we explicitly request that the
|
|
// compiler instance *not* free these buffers for each invocation of the
|
|
// compiler instance *not* free these buffers for each invocation of the
|
|
// parser.
|
|
// parser.
|
|
- if (Invocation.get() && OwnsRemappedFileBuffers) {
|
|
|
|
|
|
+ if (Invocation && OwnsRemappedFileBuffers) {
|
|
PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
|
|
PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
|
|
for (const auto &RB : PPOpts.RemappedFileBuffers)
|
|
for (const auto &RB : PPOpts.RemappedFileBuffers)
|
|
delete RB.second;
|
|
delete RB.second;
|
|
@@ -348,7 +348,7 @@ void ASTUnit::CacheCodeCompletionResults() {
|
|
// Gather the set of global code completions.
|
|
// Gather the set of global code completions.
|
|
typedef CodeCompletionResult Result;
|
|
typedef CodeCompletionResult Result;
|
|
SmallVector<Result, 8> Results;
|
|
SmallVector<Result, 8> Results;
|
|
- CachedCompletionAllocator = new GlobalCodeCompletionAllocator;
|
|
|
|
|
|
+ CachedCompletionAllocator = std::make_shared<GlobalCodeCompletionAllocator>();
|
|
CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator);
|
|
CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator);
|
|
TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
|
|
TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
|
|
CCTUInfo, Results);
|
|
CCTUInfo, Results);
|
|
@@ -1048,10 +1048,7 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
CICleanup(Clang.get());
|
|
CICleanup(Clang.get());
|
|
|
|
|
|
- IntrusiveRefCntPtr<CompilerInvocation>
|
|
|
|
- CCInvocation(new CompilerInvocation(*Invocation));
|
|
|
|
-
|
|
|
|
- Clang->setInvocation(CCInvocation.get());
|
|
|
|
|
|
+ Clang->setInvocation(std::make_shared<CompilerInvocation>(*Invocation));
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
|
|
|
|
// Set up diagnostics, capturing any diagnostics that would
|
|
// Set up diagnostics, capturing any diagnostics that would
|
|
@@ -1344,8 +1341,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|
const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild,
|
|
const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild,
|
|
unsigned MaxLines) {
|
|
unsigned MaxLines) {
|
|
|
|
|
|
- IntrusiveRefCntPtr<CompilerInvocation>
|
|
|
|
- PreambleInvocation(new CompilerInvocation(PreambleInvocationIn));
|
|
|
|
|
|
+ auto PreambleInvocation =
|
|
|
|
+ std::make_shared<CompilerInvocation>(PreambleInvocationIn);
|
|
FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
|
|
FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
|
|
PreprocessorOptions &PreprocessorOpts
|
|
PreprocessorOptions &PreprocessorOpts
|
|
= PreambleInvocation->getPreprocessorOpts();
|
|
= PreambleInvocation->getPreprocessorOpts();
|
|
@@ -1523,7 +1520,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
CICleanup(Clang.get());
|
|
CICleanup(Clang.get());
|
|
|
|
|
|
- Clang->setInvocation(&*PreambleInvocation);
|
|
|
|
|
|
+ Clang->setInvocation(std::move(PreambleInvocation));
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
|
|
|
|
// Set up diagnostics, capturing all of the diagnostics produced.
|
|
// Set up diagnostics, capturing all of the diagnostics produced.
|
|
@@ -1709,30 +1706,29 @@ StringRef ASTUnit::getASTFileName() const {
|
|
return Mod.FileName;
|
|
return Mod.FileName;
|
|
}
|
|
}
|
|
|
|
|
|
-ASTUnit *ASTUnit::create(CompilerInvocation *CI,
|
|
|
|
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
|
|
|
- bool CaptureDiagnostics,
|
|
|
|
- bool UserFilesAreVolatile) {
|
|
|
|
- std::unique_ptr<ASTUnit> AST;
|
|
|
|
- AST.reset(new ASTUnit(false));
|
|
|
|
|
|
+std::unique_ptr<ASTUnit>
|
|
|
|
+ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
|
|
|
|
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
|
|
|
+ bool CaptureDiagnostics, bool UserFilesAreVolatile) {
|
|
|
|
+ std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
|
|
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
|
|
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
|
|
- AST->Diagnostics = Diags;
|
|
|
|
- AST->Invocation = CI;
|
|
|
|
- AST->FileSystemOpts = CI->getFileSystemOpts();
|
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> VFS =
|
|
IntrusiveRefCntPtr<vfs::FileSystem> VFS =
|
|
createVFSFromCompilerInvocation(*CI, *Diags);
|
|
createVFSFromCompilerInvocation(*CI, *Diags);
|
|
if (!VFS)
|
|
if (!VFS)
|
|
return nullptr;
|
|
return nullptr;
|
|
|
|
+ AST->Diagnostics = Diags;
|
|
|
|
+ AST->FileSystemOpts = CI->getFileSystemOpts();
|
|
|
|
+ AST->Invocation = std::move(CI);
|
|
AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
|
|
AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
|
|
AST->UserFilesAreVolatile = UserFilesAreVolatile;
|
|
AST->UserFilesAreVolatile = UserFilesAreVolatile;
|
|
AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
|
|
AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
|
|
UserFilesAreVolatile);
|
|
UserFilesAreVolatile);
|
|
|
|
|
|
- return AST.release();
|
|
|
|
|
|
+ return AST;
|
|
}
|
|
}
|
|
|
|
|
|
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
|
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
|
- CompilerInvocation *CI,
|
|
|
|
|
|
+ std::shared_ptr<CompilerInvocation> CI,
|
|
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
|
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FrontendAction *Action,
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FrontendAction *Action,
|
|
ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
|
|
ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
|
|
@@ -1746,7 +1742,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
|
ASTUnit *AST = Unit;
|
|
ASTUnit *AST = Unit;
|
|
if (!AST) {
|
|
if (!AST) {
|
|
// Create the AST unit.
|
|
// Create the AST unit.
|
|
- OwnAST.reset(create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile));
|
|
|
|
|
|
+ OwnAST = create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile);
|
|
AST = OwnAST.get();
|
|
AST = OwnAST.get();
|
|
if (!AST)
|
|
if (!AST)
|
|
return nullptr;
|
|
return nullptr;
|
|
@@ -1785,7 +1781,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
CICleanup(Clang.get());
|
|
CICleanup(Clang.get());
|
|
|
|
|
|
- Clang->setInvocation(CI);
|
|
|
|
|
|
+ Clang->setInvocation(std::move(CI));
|
|
AST->OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
AST->OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
|
|
|
|
// Set up diagnostics, capturing any diagnostics that would
|
|
// Set up diagnostics, capturing any diagnostics that would
|
|
@@ -1903,7 +1899,7 @@ bool ASTUnit::LoadFromCompilerInvocation(
|
|
}
|
|
}
|
|
|
|
|
|
std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
|
std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
|
- CompilerInvocation *CI,
|
|
|
|
|
|
+ std::shared_ptr<CompilerInvocation> CI,
|
|
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
|
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
|
|
bool OnlyLocalDecls, bool CaptureDiagnostics,
|
|
bool OnlyLocalDecls, bool CaptureDiagnostics,
|
|
@@ -1920,7 +1916,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
|
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
|
|
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
|
|
AST->IncludeBriefCommentsInCodeCompletion
|
|
AST->IncludeBriefCommentsInCodeCompletion
|
|
= IncludeBriefCommentsInCodeCompletion;
|
|
= IncludeBriefCommentsInCodeCompletion;
|
|
- AST->Invocation = CI;
|
|
|
|
|
|
+ AST->Invocation = std::move(CI);
|
|
AST->FileSystemOpts = FileMgr->getFileSystemOpts();
|
|
AST->FileSystemOpts = FileMgr->getFileSystemOpts();
|
|
AST->FileMgr = FileMgr;
|
|
AST->FileMgr = FileMgr;
|
|
AST->UserFilesAreVolatile = UserFilesAreVolatile;
|
|
AST->UserFilesAreVolatile = UserFilesAreVolatile;
|
|
@@ -1952,8 +1948,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
|
|
assert(Diags.get() && "no DiagnosticsEngine was provided");
|
|
assert(Diags.get() && "no DiagnosticsEngine was provided");
|
|
|
|
|
|
SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
|
|
SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
|
|
-
|
|
|
|
- IntrusiveRefCntPtr<CompilerInvocation> CI;
|
|
|
|
|
|
+
|
|
|
|
+ std::shared_ptr<CompilerInvocation> CI;
|
|
|
|
|
|
{
|
|
{
|
|
|
|
|
|
@@ -1961,8 +1957,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
|
|
StoredDiagnostics);
|
|
StoredDiagnostics);
|
|
|
|
|
|
CI = clang::createInvocationFromCommandLine(
|
|
CI = clang::createInvocationFromCommandLine(
|
|
- llvm::makeArrayRef(ArgBegin, ArgEnd),
|
|
|
|
- Diags);
|
|
|
|
|
|
+ llvm::makeArrayRef(ArgBegin, ArgEnd), Diags);
|
|
if (!CI)
|
|
if (!CI)
|
|
return nullptr;
|
|
return nullptr;
|
|
}
|
|
}
|
|
@@ -2333,8 +2328,7 @@ void ASTUnit::CodeComplete(
|
|
CompletionTimer.setOutput("Code completion @ " + File + ":" +
|
|
CompletionTimer.setOutput("Code completion @ " + File + ":" +
|
|
Twine(Line) + ":" + Twine(Column));
|
|
Twine(Line) + ":" + Twine(Column));
|
|
|
|
|
|
- IntrusiveRefCntPtr<CompilerInvocation>
|
|
|
|
- CCInvocation(new CompilerInvocation(*Invocation));
|
|
|
|
|
|
+ auto CCInvocation = std::make_shared<CompilerInvocation>(*Invocation);
|
|
|
|
|
|
FrontendOptions &FrontendOpts = CCInvocation->getFrontendOpts();
|
|
FrontendOptions &FrontendOpts = CCInvocation->getFrontendOpts();
|
|
CodeCompleteOptions &CodeCompleteOpts = FrontendOpts.CodeCompleteOpts;
|
|
CodeCompleteOptions &CodeCompleteOpts = FrontendOpts.CodeCompleteOpts;
|
|
@@ -2366,7 +2360,8 @@ void ASTUnit::CodeComplete(
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
|
|
CICleanup(Clang.get());
|
|
CICleanup(Clang.get());
|
|
|
|
|
|
- Clang->setInvocation(&*CCInvocation);
|
|
|
|
|
|
+ auto &Inv = *CCInvocation;
|
|
|
|
+ Clang->setInvocation(std::move(CCInvocation));
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
|
|
|
|
|
|
// Set up diagnostics, capturing any diagnostics produced.
|
|
// Set up diagnostics, capturing any diagnostics produced.
|
|
@@ -2374,8 +2369,8 @@ void ASTUnit::CodeComplete(
|
|
CaptureDroppedDiagnostics Capture(true,
|
|
CaptureDroppedDiagnostics Capture(true,
|
|
Clang->getDiagnostics(),
|
|
Clang->getDiagnostics(),
|
|
StoredDiagnostics);
|
|
StoredDiagnostics);
|
|
- ProcessWarningOptions(Diag, CCInvocation->getDiagnosticOpts());
|
|
|
|
-
|
|
|
|
|
|
+ ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
|
|
|
|
+
|
|
// Create the target instance.
|
|
// Create the target instance.
|
|
Clang->setTarget(TargetInfo::CreateTargetInfo(
|
|
Clang->setTarget(TargetInfo::CreateTargetInfo(
|
|
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
|
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
|
@@ -2431,7 +2426,7 @@ void ASTUnit::CodeComplete(
|
|
if (!llvm::sys::fs::getUniqueID(MainPath, MainID)) {
|
|
if (!llvm::sys::fs::getUniqueID(MainPath, MainID)) {
|
|
if (CompleteFileID == MainID && Line > 1)
|
|
if (CompleteFileID == MainID && Line > 1)
|
|
OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
|
|
OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
|
|
- PCHContainerOps, *CCInvocation, false, Line - 1);
|
|
|
|
|
|
+ PCHContainerOps, Inv, false, Line - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|