Change OwningPtr::take() to OwningPtr::release().

This is a precursor to moving to std::unique_ptr.

llvm-svn: 203275
This commit is contained in:
Ahmed Charles 2014-03-07 19:33:25 +00:00
parent 9cbd3c628c
commit 9a16beb8bc
41 changed files with 100 additions and 112 deletions

View File

@ -82,8 +82,8 @@ public:
/// \brief Retrieve the next stat call cache in the chain, transferring /// \brief Retrieve the next stat call cache in the chain, transferring
/// ownership of this cache (and, transitively, all of the remaining caches) /// ownership of this cache (and, transitively, all of the remaining caches)
/// to the caller. /// to the caller.
FileSystemStatCache *takeNextStatCache() { return NextStatCache.take(); } FileSystemStatCache *takeNextStatCache() { return NextStatCache.release(); }
protected: protected:
virtual LookupResult getStat(const char *Path, FileData &Data, bool isFile, virtual LookupResult getStat(const char *Path, FileData &Data, bool isFile,
vfs::File **F, vfs::FileSystem &FS) = 0; vfs::File **F, vfs::FileSystem &FS) = 0;

View File

@ -435,7 +435,7 @@ public:
/// takeASTConsumer - Remove the current AST consumer and give ownership to /// takeASTConsumer - Remove the current AST consumer and give ownership to
/// the caller. /// the caller.
ASTConsumer *takeASTConsumer() { return Consumer.take(); } ASTConsumer *takeASTConsumer() { return Consumer.release(); }
/// setASTConsumer - Replace the current AST consumer; the compiler instance /// setASTConsumer - Replace the current AST consumer; the compiler instance
/// takes ownership of \p Value. /// takes ownership of \p Value.
@ -450,9 +450,9 @@ public:
assert(TheSema && "Compiler instance has no Sema object!"); assert(TheSema && "Compiler instance has no Sema object!");
return *TheSema; return *TheSema;
} }
Sema *takeSema() { return TheSema.take(); } Sema *takeSema() { return TheSema.release(); }
/// } /// }
/// @name Module Management /// @name Module Management
/// { /// {
@ -477,7 +477,7 @@ public:
/// takeCodeCompletionConsumer - Remove the current code completion consumer /// takeCodeCompletionConsumer - Remove the current code completion consumer
/// and give ownership to the caller. /// and give ownership to the caller.
CodeCompleteConsumer *takeCodeCompletionConsumer() { CodeCompleteConsumer *takeCodeCompletionConsumer() {
return CompletionConsumer.take(); return CompletionConsumer.release();
} }
/// setCodeCompletionConsumer - Replace the current code completion consumer; /// setCodeCompletionConsumer - Replace the current code completion consumer;

View File

@ -146,9 +146,7 @@ public:
return *CurrentASTUnit; return *CurrentASTUnit;
} }
ASTUnit *takeCurrentASTUnit() { ASTUnit *takeCurrentASTUnit() { return CurrentASTUnit.release(); }
return CurrentASTUnit.take();
}
void setCurrentInput(const FrontendInputFile &CurrentInput, ASTUnit *AST = 0); void setCurrentInput(const FrontendInputFile &CurrentInput, ASTUnit *AST = 0);

View File

@ -1326,13 +1326,9 @@ public:
private: private:
void PushIncludeMacroStack() { void PushIncludeMacroStack() {
IncludeMacroStack.push_back(IncludeStackInfo(CurLexerKind, IncludeMacroStack.push_back(IncludeStackInfo(
CurSubmodule, CurLexerKind, CurSubmodule, CurLexer.release(), CurPTHLexer.release(),
CurLexer.take(), CurPPLexer, CurTokenLexer.release(), CurDirLookup));
CurPTHLexer.take(),
CurPPLexer,
CurTokenLexer.take(),
CurDirLookup));
CurPPLexer = 0; CurPPLexer = 0;
} }

View File

@ -1325,7 +1325,7 @@ public:
/// Takes ownership of \p L. /// Takes ownership of \p L.
void addListener(ASTReaderListener *L) { void addListener(ASTReaderListener *L) {
if (Listener) if (Listener)
L = new ChainedASTReaderListener(L, Listener.take()); L = new ChainedASTReaderListener(L, Listener.release());
Listener.reset(L); Listener.reset(L);
} }

View File

@ -120,7 +120,7 @@ public:
/// takeGraph - Returns the exploded graph. Ownership of the graph is /// takeGraph - Returns the exploded graph. Ownership of the graph is
/// transferred to the caller. /// transferred to the caller.
ExplodedGraph* takeGraph() { return G.take(); } ExplodedGraph *takeGraph() { return G.release(); }
/// ExecuteWorkList - Run the worklist algorithm for a maximum number of /// ExecuteWorkList - Run the worklist algorithm for a maximum number of
/// steps. Returns true if there is still simulation state on the worklist. /// steps. Returns true if there is still simulation state on the worklist.

View File

@ -208,7 +208,7 @@ createInvocationForMigration(CompilerInvocation &origCI) {
CInvok->getLangOpts()->ObjCARCWeak = HasARCRuntime(origCI); CInvok->getLangOpts()->ObjCARCWeak = HasARCRuntime(origCI);
return CInvok.take(); return CInvok.release();
} }
static void emitPremigrationErrors(const CapturedDiagList &arcDiags, static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
@ -264,7 +264,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
Diags->setClient(&errRec, /*ShouldOwnClient=*/false); Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
OwningPtr<ASTUnit> Unit( OwningPtr<ASTUnit> Unit(
ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags)); ASTUnit::LoadFromCompilerInvocationAction(CInvok.release(), Diags));
if (!Unit) { if (!Unit) {
errRec.FinishCapture(); errRec.FinishCapture();
return true; return true;
@ -537,9 +537,8 @@ bool MigrationProcess::applyTransform(TransformFn trans,
OwningPtr<ARCMTMacroTrackerAction> ASTAction; OwningPtr<ARCMTMacroTrackerAction> ASTAction;
ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs)); ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
OwningPtr<ASTUnit> Unit( OwningPtr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags, CInvok.release(), Diags, ASTAction.get()));
ASTAction.get()));
if (!Unit) { if (!Unit) {
errRec.FinishCapture(); errRec.FinishCapture();
return true; return true;

View File

@ -1993,7 +1993,7 @@ public:
return true; return true;
llvm::SourceMgr SM; llvm::SourceMgr SM;
Stream YAMLStream(FileBuf.take(), SM); Stream YAMLStream(FileBuf.release(), SM);
document_iterator I = YAMLStream.begin(); document_iterator I = YAMLStream.begin();
if (I == YAMLStream.end()) if (I == YAMLStream.end())
return true; return true;

View File

@ -724,7 +724,7 @@ CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {
// Create an empty entry block that has no predecessors. // Create an empty entry block that has no predecessors.
cfg->setEntry(createBlock()); cfg->setEntry(createBlock());
return cfg.take(); return cfg.release();
} }
/// createBlock - Used to lazily create blocks that are connected /// createBlock - Used to lazily create blocks that are connected

View File

@ -1362,8 +1362,8 @@ bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock,
delete CurrStates; delete CurrStates;
if (*++SI) if (*++SI)
BlockInfo.addInfo(*SI, FalseStates.take()); BlockInfo.addInfo(*SI, FalseStates.release());
CurrStates = NULL; CurrStates = NULL;
return true; return true;
} }

View File

@ -71,7 +71,7 @@ void FileManager::addStatCache(FileSystemStatCache *statCache,
bool AtBeginning) { bool AtBeginning) {
assert(statCache && "No stat cache provided?"); assert(statCache && "No stat cache provided?");
if (AtBeginning || StatCache.get() == 0) { if (AtBeginning || StatCache.get() == 0) {
statCache->setNextStatCache(StatCache.take()); statCache->setNextStatCache(StatCache.release());
StatCache.reset(statCache); StatCache.reset(statCache);
return; return;
} }
@ -395,7 +395,7 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
if (ErrorStr) if (ErrorStr)
*ErrorStr = ec.message(); *ErrorStr = ec.message();
Entry->closeFile(); Entry->closeFile();
return Result.take(); return Result.release();
} }
// Otherwise, open the file. // Otherwise, open the file.
@ -404,7 +404,7 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
ec = FS->getBufferForFile(Filename, Result, FileSize); ec = FS->getBufferForFile(Filename, Result, FileSize);
if (ec && ErrorStr) if (ec && ErrorStr)
*ErrorStr = ec.message(); *ErrorStr = ec.message();
return Result.take(); return Result.release();
} }
SmallString<128> FilePath(Entry->getName()); SmallString<128> FilePath(Entry->getName());
@ -412,7 +412,7 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
ec = FS->getBufferForFile(FilePath.str(), Result, FileSize); ec = FS->getBufferForFile(FilePath.str(), Result, FileSize);
if (ec && ErrorStr) if (ec && ErrorStr)
*ErrorStr = ec.message(); *ErrorStr = ec.message();
return Result.take(); return Result.release();
} }
llvm::MemoryBuffer *FileManager:: llvm::MemoryBuffer *FileManager::
@ -423,7 +423,7 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) {
ec = FS->getBufferForFile(Filename, Result); ec = FS->getBufferForFile(Filename, Result);
if (ec && ErrorStr) if (ec && ErrorStr)
*ErrorStr = ec.message(); *ErrorStr = ec.message();
return Result.take(); return Result.release();
} }
SmallString<128> FilePath(Filename); SmallString<128> FilePath(Filename);
@ -431,7 +431,7 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) {
ec = FS->getBufferForFile(FilePath.c_str(), Result); ec = FS->getBufferForFile(FilePath.c_str(), Result);
if (ec && ErrorStr) if (ec && ErrorStr)
*ErrorStr = ec.message(); *ErrorStr = ec.message();
return Result.take(); return Result.release();
} }
/// getStatValue - Get the 'stat' information for the specified path, /// getStatValue - Get the 'stat' information for the specified path,

View File

@ -91,7 +91,7 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile,
if (Status) { if (Status) {
R = CacheExists; R = CacheExists;
copyStatusToFileData(*Status, Data); copyStatusToFileData(*Status, Data);
*F = OwnedFile.take(); *F = OwnedFile.release();
} else { } else {
// fstat rarely fails. If it does, claim the initial open didn't // fstat rarely fails. If it does, claim the initial open didn't
// succeed. // succeed.

View File

@ -6015,5 +6015,5 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
if (!Target->handleTargetFeatures(Opts->Features, Diags)) if (!Target->handleTargetFeatures(Opts->Features, Diags))
return 0; return 0;
return Target.take(); return Target.release();
} }

View File

@ -731,7 +731,7 @@ VFSFromYAML *VFSFromYAML::create(MemoryBuffer *Buffer,
if (!P.parse(Root, FS.get())) if (!P.parse(Root, FS.get()))
return NULL; return NULL;
return FS.take(); return FS.release();
} }
ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) { ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) {

View File

@ -119,7 +119,7 @@ public:
delete PerModulePasses; delete PerModulePasses;
delete PerFunctionPasses; delete PerFunctionPasses;
if (CodeGenOpts.DisableFree) if (CodeGenOpts.DisableFree)
BuryPointer(TM.take()); BuryPointer(TM.release());
} }
llvm::OwningPtr<TargetMachine> TM; llvm::OwningPtr<TargetMachine> TM;

View File

@ -66,8 +66,8 @@ namespace clang {
llvm::TimePassesIsEnabled = TimePasses; llvm::TimePassesIsEnabled = TimePasses;
} }
llvm::Module *takeModule() { return TheModule.take(); } llvm::Module *takeModule() { return TheModule.release(); }
llvm::Module *takeLinkModule() { return LinkModule.take(); } llvm::Module *takeLinkModule() { return LinkModule.release(); }
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) { virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
Gen->HandleCXXStaticMemberVarInstantiation(VD); Gen->HandleCXXStaticMemberVarInstantiation(VD);
@ -125,7 +125,7 @@ namespace clang {
if (!M) { if (!M) {
// The module has been released by IR gen on failures, do not double // The module has been released by IR gen on failures, do not double
// free. // free.
TheModule.take(); TheModule.release();
return; return;
} }
@ -435,9 +435,7 @@ void CodeGenAction::EndSourceFileAction() {
TheModule.reset(BEConsumer->takeModule()); TheModule.reset(BEConsumer->takeModule());
} }
llvm::Module *CodeGenAction::takeModule() { llvm::Module *CodeGenAction::takeModule() { return TheModule.release(); }
return TheModule.take();
}
llvm::LLVMContext *CodeGenAction::takeLLVMContext() { llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
OwnsVMContext = false; OwnsVMContext = false;
@ -497,12 +495,10 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
LinkModuleToUse = ModuleOrErr.get(); LinkModuleToUse = ModuleOrErr.get();
} }
BEConsumer = BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(),
new BackendConsumer(BA, CI.getDiagnostics(), CI.getTargetOpts(), CI.getLangOpts(),
CI.getCodeGenOpts(), CI.getTargetOpts(), CI.getFrontendOpts().ShowTimers, InFile,
CI.getLangOpts(), LinkModuleToUse, OS.release(), *VMContext);
CI.getFrontendOpts().ShowTimers, InFile,
LinkModuleToUse, OS.take(), *VMContext);
return BEConsumer; return BEConsumer;
} }

View File

@ -48,9 +48,7 @@ namespace {
return M.get(); return M.get();
} }
virtual llvm::Module* ReleaseModule() { virtual llvm::Module *ReleaseModule() { return M.release(); }
return M.take();
}
virtual void Initialize(ASTContext &Context) { virtual void Initialize(ASTContext &Context) {
Ctx = &Context; Ctx = &Context;

View File

@ -1215,7 +1215,7 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args,
// Queue linker inputs. // Queue linker inputs.
if (Phase == phases::Link) { if (Phase == phases::Link) {
assert((i + 1) == e && "linking must be final compilation step."); assert((i + 1) == e && "linking must be final compilation step.");
LinkerInputs.push_back(Current.take()); LinkerInputs.push_back(Current.release());
break; break;
} }
@ -1226,14 +1226,14 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args,
continue; continue;
// Otherwise construct the appropriate action. // Otherwise construct the appropriate action.
Current.reset(ConstructPhaseAction(Args, Phase, Current.take())); Current.reset(ConstructPhaseAction(Args, Phase, Current.release()));
if (Current->getType() == types::TY_Nothing) if (Current->getType() == types::TY_Nothing)
break; break;
} }
// If we ended with something, add to the output list. // If we ended with something, add to the output list.
if (Current) if (Current)
Actions.push_back(Current.take()); Actions.push_back(Current.release());
} }
// Add a link action if necessary. // Add a link action if necessary.

View File

@ -128,7 +128,7 @@ public:
Parser.CurrentLines = &Parser.PreprocessorDirectives; Parser.CurrentLines = &Parser.PreprocessorDirectives;
else if (!Parser.Line->Tokens.empty()) else if (!Parser.Line->Tokens.empty())
Parser.CurrentLines = &Parser.Line->Tokens.back().Children; Parser.CurrentLines = &Parser.Line->Tokens.back().Children;
PreBlockLine = Parser.Line.take(); PreBlockLine = Parser.Line.release();
Parser.Line.reset(new UnwrappedLine()); Parser.Line.reset(new UnwrappedLine());
Parser.Line->Level = PreBlockLine->Level; Parser.Line->Level = PreBlockLine->Level;
Parser.Line->InPPDirective = PreBlockLine->InPPDirective; Parser.Line->InPPDirective = PreBlockLine->InPPDirective;

View File

@ -781,7 +781,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
// Tell the diagnostic client that we have started a source file. // Tell the diagnostic client that we have started a source file.
AST->getDiagnostics().getClient()->BeginSourceFile(Context.getLangOpts(),&PP); AST->getDiagnostics().getClient()->BeginSourceFile(Context.getLangOpts(),&PP);
return AST.take(); return AST.release();
} }
namespace { namespace {
@ -1798,7 +1798,7 @@ ASTUnit *ASTUnit::create(CompilerInvocation *CI,
AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr, AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
UserFilesAreVolatile); UserFilesAreVolatile);
return AST.take(); return AST.release();
} }
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI, ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI,
@ -1938,7 +1938,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI,
Act->EndSourceFile(); Act->EndSourceFile();
if (OwnAST) if (OwnAST)
return OwnAST.take(); return OwnAST.release();
else else
return AST; return AST;
} }
@ -2001,7 +2001,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> > llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
DiagCleanup(Diags.getPtr()); DiagCleanup(Diags.getPtr());
return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take(); return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0
: AST.release();
} }
ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
@ -2093,7 +2094,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
return 0; return 0;
} }
return AST.take(); return AST.release();
} }
bool ASTUnit::Reparse(ArrayRef<RemappedFile> RemappedFiles) { bool ASTUnit::Reparse(ArrayRef<RemappedFile> RemappedFiles) {

View File

@ -44,7 +44,7 @@ static ASTReader *createASTReader(CompilerInstance &CI,
case ASTReader::Success: case ASTReader::Success:
// Set the predefines buffer as suggested by the PCH reader. // Set the predefines buffer as suggested by the PCH reader.
PP.setPredefines(Reader->getSuggestedPredefines()); PP.setPredefines(Reader->getSuggestedPredefines());
return Reader.take(); return Reader.release();
case ASTReader::Failure: case ASTReader::Failure:
case ASTReader::Missing: case ASTReader::Missing:
@ -98,7 +98,7 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient)); new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient));
OwningPtr<CompilerInstance> Clang(new CompilerInstance()); OwningPtr<CompilerInstance> Clang(new CompilerInstance());
Clang->setInvocation(CInvok.take()); Clang->setInvocation(CInvok.release());
Clang->setDiagnostics(Diags.getPtr()); Clang->setDiagnostics(Diags.getPtr());
Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
&Clang->getTargetOpts())); &Clang->getTargetOpts()));
@ -116,7 +116,7 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
/*isysroot=*/"", &OS)); /*isysroot=*/"", &OS));
Clang->getASTContext().setASTMutationListener( Clang->getASTContext().setASTMutationListener(
consumer->GetASTMutationListener()); consumer->GetASTMutationListener());
Clang->setASTConsumer(consumer.take()); Clang->setASTConsumer(consumer.release());
Clang->createSema(TU_Prefix, 0); Clang->createSema(TU_Prefix, 0);
if (firstInclude) { if (firstInclude) {
@ -156,7 +156,7 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
serialBufs.push_back( serialBufs.push_back(
llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(), llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(),
serialAST.size()))); serialAST.size())));
source->CIs.push_back(Clang.take()); source->CIs.push_back(Clang.release());
} }
assert(!serialBufs.empty()); assert(!serialBufs.empty());

View File

@ -156,11 +156,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
<< OutputFile << ErrorInfo; << OutputFile << ErrorInfo;
return; return;
} }
DiagnosticConsumer *SerializedConsumer =
clang::serialized_diags::create(OS.take(), DiagOpts);
DiagnosticConsumer *SerializedConsumer =
clang::serialized_diags::create(OS.release(), DiagOpts);
Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(),
SerializedConsumer)); SerializedConsumer));
} }
@ -355,7 +354,7 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path,
// Set the predefines buffer as suggested by the PCH reader. Typically, the // Set the predefines buffer as suggested by the PCH reader. Typically, the
// predefines buffer will be empty. // predefines buffer will be empty.
PP.setPredefines(Reader->getSuggestedPredefines()); PP.setPredefines(Reader->getSuggestedPredefines());
return Reader.take(); return Reader.release();
case ASTReader::Failure: case ASTReader::Failure:
// Unrecoverable failure: don't even try to process the input file. // Unrecoverable failure: don't even try to process the input file.
@ -607,7 +606,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
if (TempPathName) if (TempPathName)
*TempPathName = TempFile; *TempPathName = TempFile;
return OS.take(); return OS.release();
} }
// Initialization Utilities // Initialization Utilities
@ -671,7 +670,7 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0); SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind); SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take()); SourceMgr.overrideFileContents(File, SB.release());
} }
assert(!SourceMgr.getMainFileID().isInvalid() && assert(!SourceMgr.getMainFileID().isInvalid() &&

View File

@ -85,5 +85,5 @@ clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList,
CCArgs.size(), CCArgs.size(),
*Diags)) *Diags))
return 0; return 0;
return CI.take(); return CI.release();
} }

View File

@ -227,7 +227,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
} }
IntrusiveRefCntPtr<vfs::FileSystem> FS = IntrusiveRefCntPtr<vfs::FileSystem> FS =
vfs::getVFSFromYAML(Buffer.take(), /*DiagHandler*/0); vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/ 0);
if (!FS.getPtr()) { if (!FS.getPtr()) {
CI.getDiagnostics().Report(diag::err_invalid_vfs_overlay) << *I; CI.getDiagnostics().Report(diag::err_invalid_vfs_overlay) << *I;
goto failure; goto failure;
@ -343,7 +343,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
goto failure; goto failure;
} }
CI.setASTConsumer(Consumer.take()); CI.setASTConsumer(Consumer.release());
if (!CI.hasASTConsumer()) if (!CI.hasASTConsumer())
goto failure; goto failure;
} }

View File

@ -75,7 +75,7 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
OwningPtr<PluginASTAction> P(it->instantiate()); OwningPtr<PluginASTAction> P(it->instantiate());
if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs)) if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs))
return 0; return 0;
return P.take(); return P.release();
} }
} }
@ -238,6 +238,6 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
return false; return false;
bool Success = Clang->ExecuteAction(*Act); bool Success = Clang->ExecuteAction(*Act);
if (Clang->getFrontendOpts().DisableFree) if (Clang->getFrontendOpts().DisableFree)
BuryPointer(Act.take()); BuryPointer(Act.release());
return Success; return Success;
} }

View File

@ -103,7 +103,7 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
if (Header->Reserved != 0) return 0; if (Header->Reserved != 0) return 0;
// Okay, everything looks good, create the header map. // Okay, everything looks good, create the header map.
return new HeaderMap(FileBuffer.take(), NeedsByteSwap); return new HeaderMap(FileBuffer.release(), NeedsByteSwap);
} }
HeaderMap::~HeaderMap() { HeaderMap::~HeaderMap() {

View File

@ -524,7 +524,7 @@ bool Preprocessor::HandleEndOfTokenLexer(Token &Result) {
if (NumCachedTokenLexers == TokenLexerCacheSize) if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset(); CurTokenLexer.reset();
else else
TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.take(); TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
// Handle this like a #include file being popped off the stack. // Handle this like a #include file being popped off the stack.
return HandleEndOfFile(Result, true); return HandleEndOfFile(Result, true);
@ -541,7 +541,7 @@ void Preprocessor::RemoveTopOfLexerStack() {
if (NumCachedTokenLexers == TokenLexerCacheSize) if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset(); CurTokenLexer.reset();
else else
TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.take(); TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
} }
PopIncludeMacroStack(); PopIncludeMacroStack();

View File

@ -534,9 +534,9 @@ PTHManager *PTHManager::Create(const std::string &file,
if (!len) originalSourceBase = 0; if (!len) originalSourceBase = 0;
// Create the new PTHManager. // Create the new PTHManager.
return new PTHManager(File.take(), FL.take(), IData, PerIDCache, return new PTHManager(File.release(), FL.release(), IData, PerIDCache,
SL.take(), NumIds, spellingBase, SL.release(), NumIds, spellingBase,
(const char*) originalSourceBase); (const char *)originalSourceBase);
} }
IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {

View File

@ -247,8 +247,9 @@ GlobalModuleIndex::readIndex(StringRef Path) {
Cursor.Read(8) != 'I') { Cursor.Read(8) != 'I') {
return std::make_pair((GlobalModuleIndex *)0, EC_IOError); return std::make_pair((GlobalModuleIndex *)0, EC_IOError);
} }
return std::make_pair(new GlobalModuleIndex(Buffer.take(), Cursor), EC_None); return std::make_pair(new GlobalModuleIndex(Buffer.release(), Cursor),
EC_None);
} }
void void

View File

@ -3465,7 +3465,7 @@ void BugReporter::FlushReport(BugReport *exampleReport,
D->addMeta(*i); D->addMeta(*i);
} }
PD.HandlePathDiagnostic(D.take()); PD.HandlePathDiagnostic(D.release());
} }
void BugReporter::EmitBasicReport(const Decl *DeclWithIssue, void BugReporter::EmitBasicReport(const Decl *DeclWithIssue,

View File

@ -275,8 +275,8 @@ void PathDiagnosticConsumer::HandlePathDiagnostic(PathDiagnostic *D) {
Diags.RemoveNode(orig); Diags.RemoveNode(orig);
delete orig; delete orig;
} }
Diags.InsertNode(OwningD.take()); Diags.InsertNode(OwningD.release());
} }
static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y); static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y);

View File

@ -730,7 +730,7 @@ static ExplodedNode::Auditor* CreateUbiViz() {
OwningPtr<llvm::raw_fd_ostream> Stream; OwningPtr<llvm::raw_fd_ostream> Stream;
Stream.reset(new llvm::raw_fd_ostream(FD, true)); Stream.reset(new llvm::raw_fd_ostream(FD, true));
return new UbigraphViz(Stream.take(), P); return new UbigraphViz(Stream.release(), P);
} }
void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) { void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) {

View File

@ -123,7 +123,7 @@ CheckerManager *ento::createCheckerManager(AnalyzerOptions &opts,
<< checkerOpts[i].getName(); << checkerOpts[i].getName();
} }
return checkerMgr.take(); return checkerMgr.release();
} }
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins) { void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins) {

View File

@ -126,7 +126,7 @@ class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin {
JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage)); JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage));
if (!Database) if (!Database)
return NULL; return NULL;
return Database.take(); return Database.release();
} }
}; };
@ -152,10 +152,10 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
return NULL; return NULL;
} }
OwningPtr<JSONCompilationDatabase> Database( OwningPtr<JSONCompilationDatabase> Database(
new JSONCompilationDatabase(DatabaseBuffer.take())); new JSONCompilationDatabase(DatabaseBuffer.release()));
if (!Database->parse(ErrorMessage)) if (!Database->parse(ErrorMessage))
return NULL; return NULL;
return Database.take(); return Database.release();
} }
JSONCompilationDatabase * JSONCompilationDatabase *
@ -164,10 +164,10 @@ JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString,
OwningPtr<llvm::MemoryBuffer> DatabaseBuffer( OwningPtr<llvm::MemoryBuffer> DatabaseBuffer(
llvm::MemoryBuffer::getMemBuffer(DatabaseString)); llvm::MemoryBuffer::getMemBuffer(DatabaseString));
OwningPtr<JSONCompilationDatabase> Database( OwningPtr<JSONCompilationDatabase> Database(
new JSONCompilationDatabase(DatabaseBuffer.take())); new JSONCompilationDatabase(DatabaseBuffer.release()));
if (!Database->parse(ErrorMessage)) if (!Database->parse(ErrorMessage))
return NULL; return NULL;
return Database.take(); return Database.release();
} }
std::vector<CompileCommand> std::vector<CompileCommand>

View File

@ -228,7 +228,7 @@ bool ToolInvocation::run() {
llvm::MemoryBuffer::getMemBuffer(It->getValue()); llvm::MemoryBuffer::getMemBuffer(It->getValue());
Invocation->getPreprocessorOpts().addRemappedFile(It->getKey(), Input); Invocation->getPreprocessorOpts().addRemappedFile(It->getKey(), Input);
} }
return runInvocation(BinaryName, Compilation.get(), Invocation.take()); return runInvocation(BinaryName, Compilation.get(), Invocation.release());
} }
bool ToolInvocation::runInvocation( bool ToolInvocation::runInvocation(

View File

@ -113,7 +113,7 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
if (Clang->getFrontendOpts().DisableFree) { if (Clang->getFrontendOpts().DisableFree) {
if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats) if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats)
llvm::PrintStatistics(); llvm::PrintStatistics();
BuryPointer(Clang.take()); BuryPointer(Clang.release());
return !Success; return !Success;
} }

View File

@ -277,7 +277,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
Diags.Report(diag::err_fe_error_reading) << Opts.InputFile; Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
return false; return false;
} }
MemoryBuffer *Buffer = BufferPtr.take(); MemoryBuffer *Buffer = BufferPtr.release();
SourceMgr SrcMgr; SourceMgr SrcMgr;

View File

@ -70,7 +70,7 @@ CXRemapping clang_getRemappings(const char *migrate_dir_path) {
return 0; return 0;
} }
return remap.take(); return remap.release();
} }
CXRemapping clang_getRemappingsFromFileList(const char **filePaths, CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
@ -83,7 +83,7 @@ CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
if (Logging) if (Logging)
llvm::errs() << "clang_getRemappingsFromFileList was called with " llvm::errs() << "clang_getRemappingsFromFileList was called with "
"numFiles=0\n"; "numFiles=0\n";
return remap.take(); return remap.release();
} }
if (!filePaths) { if (!filePaths) {
@ -108,10 +108,10 @@ CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I) I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I)
llvm::errs() << I->second << '\n'; llvm::errs() << I->second << '\n';
} }
return remap.take(); return remap.release();
} }
return remap.take(); return remap.release();
} }
unsigned clang_remap_getNumFiles(CXRemapping map) { unsigned clang_remap_getNumFiles(CXRemapping map) {

View File

@ -2811,7 +2811,7 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
if (isASTReadError(Unit ? Unit.get() : ErrUnit.get())) { if (isASTReadError(Unit ? Unit.get() : ErrUnit.get())) {
PTUI->result = CXError_ASTReadError; PTUI->result = CXError_ASTReadError;
} else { } else {
*PTUI->out_TU = MakeCXTranslationUnit(CXXIdx, Unit.take()); *PTUI->out_TU = MakeCXTranslationUnit(CXXIdx, Unit.release());
PTUI->result = *PTUI->out_TU ? CXError_Success : CXError_Failure; PTUI->result = *PTUI->out_TU ? CXError_Success : CXError_Failure;
} }
} }
@ -6607,7 +6607,7 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
CXTUResourceUsage usage = { (void*) entries.get(), CXTUResourceUsage usage = { (void*) entries.get(),
(unsigned) entries->size(), (unsigned) entries->size(),
entries->size() ? &(*entries)[0] : 0 }; entries->size() ? &(*entries)[0] : 0 };
entries.take(); entries.release();
return usage; return usage;
} }

View File

@ -292,7 +292,7 @@ CXDiagnosticSet DiagLoader::load(const char *file) {
BlockID, true); BlockID, true);
switch (Res) { switch (Res) {
case Read_EndOfStream: case Read_EndOfStream:
return (CXDiagnosticSet) Diags.take(); return (CXDiagnosticSet)Diags.release();
case Read_Failure: case Read_Failure:
return 0; return 0;
case Read_Record: case Read_Record:
@ -567,7 +567,7 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream,
continue; continue;
} }
case Read_BlockEnd: case Read_BlockEnd:
Diags.appendDiagnostic(D.take()); Diags.appendDiagnostic(D.release());
return Success; return Success;
case Read_Record: case Read_Record:
break; break;

View File

@ -184,7 +184,7 @@ TEST(ExternalSemaSource, SanityCheck) {
Installer->PushWatcher(&Watcher); Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11"); std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
Installer.take(), "namespace AAA { } using namespace AAB;", Args)); Installer.release(), "namespace AAA { } using namespace AAB;", Args));
ASSERT_EQ(0, Watcher.SeenCount); ASSERT_EQ(0, Watcher.SeenCount);
} }
@ -199,7 +199,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) {
Installer->PushWatcher(&Watcher); Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11"); std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
Installer.take(), "namespace AAA { } using namespace AAB;", Args)); Installer.release(), "namespace AAA { } using namespace AAB;", Args));
ASSERT_LE(0, Provider.CallCount); ASSERT_LE(0, Provider.CallCount);
ASSERT_EQ(1, Watcher.SeenCount); ASSERT_EQ(1, Watcher.SeenCount);
} }
@ -219,7 +219,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
Installer->PushWatcher(&Watcher); Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11"); std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
Installer.take(), "namespace AAA { } using namespace AAB;", Args)); Installer.release(), "namespace AAA { } using namespace AAB;", Args));
ASSERT_LE(1, First.CallCount); ASSERT_LE(1, First.CallCount);
ASSERT_LE(1, Second.CallCount); ASSERT_LE(1, Second.CallCount);
ASSERT_EQ(0, Third.CallCount); ASSERT_EQ(0, Third.CallCount);
@ -237,7 +237,7 @@ TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
// This code hits the class template specialization/class member of a class // This code hits the class template specialization/class member of a class
// template specialization checks in Sema::RequireCompleteTypeImpl. // template specialization checks in Sema::RequireCompleteTypeImpl.
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
Installer.take(), Installer.release(),
"template <typename T> struct S { class C { }; }; S<char>::C SCInst;", "template <typename T> struct S { class C { }; }; S<char>::C SCInst;",
Args)); Args));
ASSERT_EQ(0, Diagnoser.CallCount); ASSERT_EQ(0, Diagnoser.CallCount);
@ -256,7 +256,7 @@ TEST(ExternalSemaSource, FirstDiagnoserTaken) {
Installer->PushSource(&Third); Installer->PushSource(&Third);
std::vector<std::string> Args(1, "-std=c++11"); std::vector<std::string> Args(1, "-std=c++11");
ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs( ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs(
Installer.take(), "class Incomplete; Incomplete IncompleteInstance;", Installer.release(), "class Incomplete; Incomplete IncompleteInstance;",
Args)); Args));
ASSERT_EQ(1, First.CallCount); ASSERT_EQ(1, First.CallCount);
ASSERT_EQ(1, Second.CallCount); ASSERT_EQ(1, Second.CallCount);