This is a precursor to moving to std::unique_ptr.
llvm-svn: 203275
/// \brief Retrieve the next stat call cache in the chain, transferring
/// ownership of this cache (and, transitively, all of the remaining caches)
/// to the caller.
- FileSystemStatCache *takeNextStatCache() { return NextStatCache.take(); }
-
+ FileSystemStatCache *takeNextStatCache() { return NextStatCache.release(); }
+
protected:
virtual LookupResult getStat(const char *Path, FileData &Data, bool isFile,
vfs::File **F, vfs::FileSystem &FS) = 0;
/// takeASTConsumer - Remove the current AST consumer and give ownership to
/// the caller.
- ASTConsumer *takeASTConsumer() { return Consumer.take(); }
+ ASTConsumer *takeASTConsumer() { return Consumer.release(); }
/// setASTConsumer - Replace the current AST consumer; the compiler instance
/// takes ownership of \p Value.
assert(TheSema && "Compiler instance has no Sema object!");
return *TheSema;
}
-
- Sema *takeSema() { return TheSema.take(); }
-
+
+ Sema *takeSema() { return TheSema.release(); }
+
/// }
/// @name Module Management
/// {
/// takeCodeCompletionConsumer - Remove the current code completion consumer
/// and give ownership to the caller.
CodeCompleteConsumer *takeCodeCompletionConsumer() {
- return CompletionConsumer.take();
+ return CompletionConsumer.release();
}
/// setCodeCompletionConsumer - Replace the current code completion consumer;
return *CurrentASTUnit;
}
- ASTUnit *takeCurrentASTUnit() {
- return CurrentASTUnit.take();
- }
+ ASTUnit *takeCurrentASTUnit() { return CurrentASTUnit.release(); }
void setCurrentInput(const FrontendInputFile &CurrentInput, ASTUnit *AST = 0);
private:
void PushIncludeMacroStack() {
- IncludeMacroStack.push_back(IncludeStackInfo(CurLexerKind,
- CurSubmodule,
- CurLexer.take(),
- CurPTHLexer.take(),
- CurPPLexer,
- CurTokenLexer.take(),
- CurDirLookup));
+ IncludeMacroStack.push_back(IncludeStackInfo(
+ CurLexerKind, CurSubmodule, CurLexer.release(), CurPTHLexer.release(),
+ CurPPLexer, CurTokenLexer.release(), CurDirLookup));
CurPPLexer = 0;
}
/// Takes ownership of \p L.
void addListener(ASTReaderListener *L) {
if (Listener)
- L = new ChainedASTReaderListener(L, Listener.take());
+ L = new ChainedASTReaderListener(L, Listener.release());
Listener.reset(L);
}
/// takeGraph - Returns the exploded graph. Ownership of the graph is
/// transferred to the caller.
- ExplodedGraph* takeGraph() { return G.take(); }
+ ExplodedGraph *takeGraph() { return G.release(); }
/// ExecuteWorkList - Run the worklist algorithm for a maximum number of
/// steps. Returns true if there is still simulation state on the worklist.
CInvok->getLangOpts()->ObjCARCWeak = HasARCRuntime(origCI);
- return CInvok.take();
+ return CInvok.release();
}
static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
OwningPtr<ASTUnit> Unit(
- ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags));
+ ASTUnit::LoadFromCompilerInvocationAction(CInvok.release(), Diags));
if (!Unit) {
errRec.FinishCapture();
return true;
OwningPtr<ARCMTMacroTrackerAction> ASTAction;
ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
- OwningPtr<ASTUnit> Unit(
- ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags,
- ASTAction.get()));
+ OwningPtr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
+ CInvok.release(), Diags, ASTAction.get()));
if (!Unit) {
errRec.FinishCapture();
return true;
return true;
llvm::SourceMgr SM;
- Stream YAMLStream(FileBuf.take(), SM);
+ Stream YAMLStream(FileBuf.release(), SM);
document_iterator I = YAMLStream.begin();
if (I == YAMLStream.end())
return true;
// Create an empty entry block that has no predecessors.
cfg->setEntry(createBlock());
- return cfg.take();
+ return cfg.release();
}
/// createBlock - Used to lazily create blocks that are connected
delete CurrStates;
if (*++SI)
- BlockInfo.addInfo(*SI, FalseStates.take());
-
+ BlockInfo.addInfo(*SI, FalseStates.release());
+
CurrStates = NULL;
return true;
}
bool AtBeginning) {
assert(statCache && "No stat cache provided?");
if (AtBeginning || StatCache.get() == 0) {
- statCache->setNextStatCache(StatCache.take());
+ statCache->setNextStatCache(StatCache.release());
StatCache.reset(statCache);
return;
}
if (ErrorStr)
*ErrorStr = ec.message();
Entry->closeFile();
- return Result.take();
+ return Result.release();
}
// Otherwise, open the file.
ec = FS->getBufferForFile(Filename, Result, FileSize);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.take();
+ return Result.release();
}
SmallString<128> FilePath(Entry->getName());
ec = FS->getBufferForFile(FilePath.str(), Result, FileSize);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.take();
+ return Result.release();
}
llvm::MemoryBuffer *FileManager::
ec = FS->getBufferForFile(Filename, Result);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.take();
+ return Result.release();
}
SmallString<128> FilePath(Filename);
ec = FS->getBufferForFile(FilePath.c_str(), Result);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.take();
+ return Result.release();
}
/// getStatValue - Get the 'stat' information for the specified path,
if (Status) {
R = CacheExists;
copyStatusToFileData(*Status, Data);
- *F = OwnedFile.take();
+ *F = OwnedFile.release();
} else {
// fstat rarely fails. If it does, claim the initial open didn't
// succeed.
if (!Target->handleTargetFeatures(Opts->Features, Diags))
return 0;
- return Target.take();
+ return Target.release();
}
if (!P.parse(Root, FS.get()))
return NULL;
- return FS.take();
+ return FS.release();
}
ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) {
delete PerModulePasses;
delete PerFunctionPasses;
if (CodeGenOpts.DisableFree)
- BuryPointer(TM.take());
+ BuryPointer(TM.release());
}
llvm::OwningPtr<TargetMachine> TM;
llvm::TimePassesIsEnabled = TimePasses;
}
- llvm::Module *takeModule() { return TheModule.take(); }
- llvm::Module *takeLinkModule() { return LinkModule.take(); }
+ llvm::Module *takeModule() { return TheModule.release(); }
+ llvm::Module *takeLinkModule() { return LinkModule.release(); }
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
Gen->HandleCXXStaticMemberVarInstantiation(VD);
if (!M) {
// The module has been released by IR gen on failures, do not double
// free.
- TheModule.take();
+ TheModule.release();
return;
}
TheModule.reset(BEConsumer->takeModule());
}
-llvm::Module *CodeGenAction::takeModule() {
- return TheModule.take();
-}
+llvm::Module *CodeGenAction::takeModule() { return TheModule.release(); }
llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
OwnsVMContext = false;
LinkModuleToUse = ModuleOrErr.get();
}
- BEConsumer =
- new BackendConsumer(BA, CI.getDiagnostics(),
- CI.getCodeGenOpts(), CI.getTargetOpts(),
- CI.getLangOpts(),
- CI.getFrontendOpts().ShowTimers, InFile,
- LinkModuleToUse, OS.take(), *VMContext);
+ BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(),
+ CI.getTargetOpts(), CI.getLangOpts(),
+ CI.getFrontendOpts().ShowTimers, InFile,
+ LinkModuleToUse, OS.release(), *VMContext);
return BEConsumer;
}
return M.get();
}
- virtual llvm::Module* ReleaseModule() {
- return M.take();
- }
+ virtual llvm::Module *ReleaseModule() { return M.release(); }
virtual void Initialize(ASTContext &Context) {
Ctx = &Context;
// Queue linker inputs.
if (Phase == phases::Link) {
assert((i + 1) == e && "linking must be final compilation step.");
- LinkerInputs.push_back(Current.take());
+ LinkerInputs.push_back(Current.release());
break;
}
continue;
// 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)
break;
}
// If we ended with something, add to the output list.
if (Current)
- Actions.push_back(Current.take());
+ Actions.push_back(Current.release());
}
// Add a link action if necessary.
Parser.CurrentLines = &Parser.PreprocessorDirectives;
else if (!Parser.Line->Tokens.empty())
Parser.CurrentLines = &Parser.Line->Tokens.back().Children;
- PreBlockLine = Parser.Line.take();
+ PreBlockLine = Parser.Line.release();
Parser.Line.reset(new UnwrappedLine());
Parser.Line->Level = PreBlockLine->Level;
Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
// Tell the diagnostic client that we have started a source file.
AST->getDiagnostics().getClient()->BeginSourceFile(Context.getLangOpts(),&PP);
- return AST.take();
+ return AST.release();
}
namespace {
AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
UserFilesAreVolatile);
- return AST.take();
+ return AST.release();
}
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI,
Act->EndSourceFile();
if (OwnAST)
- return OwnAST.take();
+ return OwnAST.release();
else
return AST;
}
llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
DiagCleanup(Diags.getPtr());
- return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take();
+ return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0
+ : AST.release();
}
ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
return 0;
}
- return AST.take();
+ return AST.release();
}
bool ASTUnit::Reparse(ArrayRef<RemappedFile> RemappedFiles) {
case ASTReader::Success:
// Set the predefines buffer as suggested by the PCH reader.
PP.setPredefines(Reader->getSuggestedPredefines());
- return Reader.take();
+ return Reader.release();
case ASTReader::Failure:
case ASTReader::Missing:
new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient));
OwningPtr<CompilerInstance> Clang(new CompilerInstance());
- Clang->setInvocation(CInvok.take());
+ Clang->setInvocation(CInvok.release());
Clang->setDiagnostics(Diags.getPtr());
Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
&Clang->getTargetOpts()));
/*isysroot=*/"", &OS));
Clang->getASTContext().setASTMutationListener(
consumer->GetASTMutationListener());
- Clang->setASTConsumer(consumer.take());
+ Clang->setASTConsumer(consumer.release());
Clang->createSema(TU_Prefix, 0);
if (firstInclude) {
serialBufs.push_back(
llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(),
serialAST.size())));
- source->CIs.push_back(Clang.take());
+ source->CIs.push_back(Clang.release());
}
assert(!serialBufs.empty());
<< OutputFile << ErrorInfo;
return;
}
-
+
DiagnosticConsumer *SerializedConsumer =
- clang::serialized_diags::create(OS.take(), DiagOpts);
+ clang::serialized_diags::create(OS.release(), DiagOpts);
-
Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(),
SerializedConsumer));
}
// Set the predefines buffer as suggested by the PCH reader. Typically, the
// predefines buffer will be empty.
PP.setPredefines(Reader->getSuggestedPredefines());
- return Reader.take();
+ return Reader.release();
case ASTReader::Failure:
// Unrecoverable failure: don't even try to process the input file.
if (TempPathName)
*TempPathName = TempFile;
- return OS.take();
+ return OS.release();
}
// Initialization Utilities
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
- SourceMgr.overrideFileContents(File, SB.take());
+ SourceMgr.overrideFileContents(File, SB.release());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
CCArgs.size(),
*Diags))
return 0;
- return CI.take();
+ return CI.release();
}
}
IntrusiveRefCntPtr<vfs::FileSystem> FS =
- vfs::getVFSFromYAML(Buffer.take(), /*DiagHandler*/0);
+ vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/ 0);
if (!FS.getPtr()) {
CI.getDiagnostics().Report(diag::err_invalid_vfs_overlay) << *I;
goto failure;
goto failure;
}
- CI.setASTConsumer(Consumer.take());
+ CI.setASTConsumer(Consumer.release());
if (!CI.hasASTConsumer())
goto failure;
}
OwningPtr<PluginASTAction> P(it->instantiate());
if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs))
return 0;
- return P.take();
+ return P.release();
}
}
return false;
bool Success = Clang->ExecuteAction(*Act);
if (Clang->getFrontendOpts().DisableFree)
- BuryPointer(Act.take());
+ BuryPointer(Act.release());
return Success;
}
if (Header->Reserved != 0) return 0;
// Okay, everything looks good, create the header map.
- return new HeaderMap(FileBuffer.take(), NeedsByteSwap);
+ return new HeaderMap(FileBuffer.release(), NeedsByteSwap);
}
HeaderMap::~HeaderMap() {
if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset();
else
- TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.take();
+ TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
// Handle this like a #include file being popped off the stack.
return HandleEndOfFile(Result, true);
if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset();
else
- TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.take();
+ TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
}
PopIncludeMacroStack();
if (!len) originalSourceBase = 0;
// Create the new PTHManager.
- return new PTHManager(File.take(), FL.take(), IData, PerIDCache,
- SL.take(), NumIds, spellingBase,
- (const char*) originalSourceBase);
+ return new PTHManager(File.release(), FL.release(), IData, PerIDCache,
+ SL.release(), NumIds, spellingBase,
+ (const char *)originalSourceBase);
}
IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
Cursor.Read(8) != 'I') {
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
D->addMeta(*i);
}
- PD.HandlePathDiagnostic(D.take());
+ PD.HandlePathDiagnostic(D.release());
}
void BugReporter::EmitBasicReport(const Decl *DeclWithIssue,
Diags.RemoveNode(orig);
delete orig;
}
-
- Diags.InsertNode(OwningD.take());
+
+ Diags.InsertNode(OwningD.release());
}
static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y);
OwningPtr<llvm::raw_fd_ostream> Stream;
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) {
<< checkerOpts[i].getName();
}
- return checkerMgr.take();
+ return checkerMgr.release();
}
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins) {
JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage));
if (!Database)
return NULL;
- return Database.take();
+ return Database.release();
}
};
return NULL;
}
OwningPtr<JSONCompilationDatabase> Database(
- new JSONCompilationDatabase(DatabaseBuffer.take()));
+ new JSONCompilationDatabase(DatabaseBuffer.release()));
if (!Database->parse(ErrorMessage))
return NULL;
- return Database.take();
+ return Database.release();
}
JSONCompilationDatabase *
OwningPtr<llvm::MemoryBuffer> DatabaseBuffer(
llvm::MemoryBuffer::getMemBuffer(DatabaseString));
OwningPtr<JSONCompilationDatabase> Database(
- new JSONCompilationDatabase(DatabaseBuffer.take()));
+ new JSONCompilationDatabase(DatabaseBuffer.release()));
if (!Database->parse(ErrorMessage))
return NULL;
- return Database.take();
+ return Database.release();
}
std::vector<CompileCommand>
llvm::MemoryBuffer::getMemBuffer(It->getValue());
Invocation->getPreprocessorOpts().addRemappedFile(It->getKey(), Input);
}
- return runInvocation(BinaryName, Compilation.get(), Invocation.take());
+ return runInvocation(BinaryName, Compilation.get(), Invocation.release());
}
bool ToolInvocation::runInvocation(
if (Clang->getFrontendOpts().DisableFree) {
if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats)
llvm::PrintStatistics();
- BuryPointer(Clang.take());
+ BuryPointer(Clang.release());
return !Success;
}
Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
return false;
}
- MemoryBuffer *Buffer = BufferPtr.take();
+ MemoryBuffer *Buffer = BufferPtr.release();
SourceMgr SrcMgr;
return 0;
}
- return remap.take();
+ return remap.release();
}
CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
if (Logging)
llvm::errs() << "clang_getRemappingsFromFileList was called with "
"numFiles=0\n";
- return remap.take();
+ return remap.release();
}
if (!filePaths) {
I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I)
llvm::errs() << I->second << '\n';
}
- return remap.take();
+ return remap.release();
}
- return remap.take();
+ return remap.release();
}
unsigned clang_remap_getNumFiles(CXRemapping map) {
if (isASTReadError(Unit ? Unit.get() : ErrUnit.get())) {
PTUI->result = CXError_ASTReadError;
} else {
- *PTUI->out_TU = MakeCXTranslationUnit(CXXIdx, Unit.take());
+ *PTUI->out_TU = MakeCXTranslationUnit(CXXIdx, Unit.release());
PTUI->result = *PTUI->out_TU ? CXError_Success : CXError_Failure;
}
}
CXTUResourceUsage usage = { (void*) entries.get(),
(unsigned) entries->size(),
entries->size() ? &(*entries)[0] : 0 };
- entries.take();
+ entries.release();
return usage;
}
BlockID, true);
switch (Res) {
case Read_EndOfStream:
- return (CXDiagnosticSet) Diags.take();
+ return (CXDiagnosticSet)Diags.release();
case Read_Failure:
return 0;
case Read_Record:
continue;
}
case Read_BlockEnd:
- Diags.appendDiagnostic(D.take());
+ Diags.appendDiagnostic(D.release());
return Success;
case Read_Record:
break;
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
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);
}
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
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_EQ(1, Watcher.SeenCount);
}
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
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, Second.CallCount);
ASSERT_EQ(0, Third.CallCount);
// This code hits the class template specialization/class member of a class
// template specialization checks in Sema::RequireCompleteTypeImpl.
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.take(),
+ Installer.release(),
"template <typename T> struct S { class C { }; }; S<char>::C SCInst;",
Args));
ASSERT_EQ(0, Diagnoser.CallCount);
Installer->PushSource(&Third);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs(
- Installer.take(), "class Incomplete; Incomplete IncompleteInstance;",
+ Installer.release(), "class Incomplete; Incomplete IncompleteInstance;",
Args));
ASSERT_EQ(1, First.CallCount);
ASSERT_EQ(1, Second.CallCount);