Unique_ptrify PPCallbacks ownership.

Unique_ptr creation stil needs to be moved earlier at some of the call sites.

llvm-svn: 217474
This commit is contained in:
Craig Topper 2014-09-10 04:53:53 +00:00
parent 7ff1592960
commit b8a7053055
18 changed files with 50 additions and 45 deletions

View File

@ -322,15 +322,12 @@ public:
/// \brief Simple wrapper class for chaining callbacks.
class PPChainedCallbacks : public PPCallbacks {
virtual void anchor();
PPCallbacks *First, *Second;
std::unique_ptr<PPCallbacks> First, Second;
public:
PPChainedCallbacks(PPCallbacks *_First, PPCallbacks *_Second)
: First(_First), Second(_Second) {}
~PPChainedCallbacks() {
delete Second;
delete First;
}
PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First,
std::unique_ptr<PPCallbacks> _Second)
: First(std::move(_First)), Second(std::move(_Second)) {}
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,

View File

@ -338,7 +338,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
/// \brief Actions invoked when some preprocessor activity is
/// encountered (e.g. a file is \#included, etc).
PPCallbacks *Callbacks;
std::unique_ptr<PPCallbacks> Callbacks;
struct MacroExpandsInfo {
Token Tok;
@ -575,11 +575,12 @@ public:
///
/// Note that this class takes ownership of any PPCallbacks object given to
/// it.
PPCallbacks *getPPCallbacks() const { return Callbacks; }
void addPPCallbacks(PPCallbacks *C) {
PPCallbacks *getPPCallbacks() const { return Callbacks.get(); }
void addPPCallbacks(std::unique_ptr<PPCallbacks> C) {
if (Callbacks)
C = new PPChainedCallbacks(C, Callbacks);
Callbacks = C;
C = llvm::make_unique<PPChainedCallbacks>(std::move(C),
std::move(Callbacks));
Callbacks = std::move(C);
}
/// \}

View File

@ -449,7 +449,7 @@ public:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
CI.getPreprocessor().addPPCallbacks(
new ARCMTMacroTrackerPPCallbacks(ARCMTMacroLocs));
llvm::make_unique<ARCMTMacroTrackerPPCallbacks>(ARCMTMacroLocs));
return llvm::make_unique<ASTConsumer>();
}
};

View File

@ -189,7 +189,7 @@ std::unique_ptr<ASTConsumer>
ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
PPConditionalDirectiveRecord *
PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager());
CompInst->getPreprocessor().addPPCallbacks(PPRec);
CI.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(WrapperFrontendAction::CreateASTConsumer(CI, InFile));
Consumers.push_back(llvm::make_unique<ObjCMigrateASTConsumer>(
@ -1873,7 +1873,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
ObjCMTAction |= FrontendOptions::ObjCMT_Literals |
FrontendOptions::ObjCMT_Subscripting;
}
CI.getPreprocessor().addPPCallbacks(PPRec);
CI.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
std::vector<std::string> WhiteList =
getWhiteListFilenames(CI.getFrontendOpts().ObjCMTWhiteListPath);
return llvm::make_unique<ObjCMigrateASTConsumer>(

View File

@ -646,7 +646,8 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
// Add the preprocessor callback only when the coverage mapping is generated.
if (CI.getCodeGenOpts().CoverageMapping) {
CoverageInfo = new CoverageSourceInfo;
CI.getPreprocessor().addPPCallbacks(CoverageInfo);
CI.getPreprocessor().addPPCallbacks(
std::unique_ptr<PPCallbacks>(CoverageInfo));
}
std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(),

View File

@ -887,7 +887,8 @@ public:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
CI.getPreprocessor().addPPCallbacks(
new MacroDefinitionTrackerPPCallbacks(Unit.getCurrentTopLevelHashValue()));
llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
Unit.getCurrentTopLevelHashValue()));
return llvm::make_unique<TopLevelDeclTrackerConsumer>(
Unit, Unit.getCurrentTopLevelHashValue());
}
@ -985,8 +986,9 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
if (!CI.getFrontendOpts().RelocatablePCH)
Sysroot.clear();
CI.getPreprocessor().addPPCallbacks(new MacroDefinitionTrackerPPCallbacks(
Unit.getCurrentTopLevelHashValue()));
CI.getPreprocessor().addPPCallbacks(
llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
Unit.getCurrentTopLevelHashValue()));
return llvm::make_unique<PrecompilePreambleConsumer>(
Unit, this, CI.getPreprocessor(), Sysroot, OS);
}
@ -1827,7 +1829,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
if (Persistent && !TrackerAct) {
Clang->getPreprocessor().addPPCallbacks(
new MacroDefinitionTrackerPPCallbacks(AST->getCurrentTopLevelHashValue()));
llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
AST->getCurrentTopLevelHashValue()));
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
if (Clang->hasASTConsumer())
Consumers.push_back(Clang->takeASTConsumer());

View File

@ -121,7 +121,8 @@ bool DependencyCollector::sawDependency(StringRef Filename, bool FromModule,
DependencyCollector::~DependencyCollector() { }
void DependencyCollector::attachToPreprocessor(Preprocessor &PP) {
PP.addPPCallbacks(new DepCollectorPPCallbacks(*this, PP.getSourceManager()));
PP.addPPCallbacks(
llvm::make_unique<DepCollectorPPCallbacks>(*this, PP.getSourceManager()));
}
void DependencyCollector::attachToASTReader(ASTReader &R) {
R.addListener(llvm::make_unique<DepCollectorASTListener>(*this));
@ -203,7 +204,7 @@ DependencyFileGenerator *DependencyFileGenerator::CreateAndAttachToPreprocessor(
PP.SetSuppressIncludeNotFoundError(true);
DFGImpl *Callback = new DFGImpl(&PP, Opts);
PP.addPPCallbacks(Callback); // PP owns the Callback
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callback));
return new DependencyFileGenerator(Callback);
}

View File

@ -61,7 +61,8 @@ public:
void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile,
StringRef SysRoot) {
PP.addPPCallbacks(new DependencyGraphCallback(&PP, OutputFile, SysRoot));
PP.addPPCallbacks(llvm::make_unique<DependencyGraphCallback>(&PP, OutputFile,
SysRoot));
}
void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc,

View File

@ -69,9 +69,12 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
}
}
PP.addPPCallbacks(new HeaderIncludesCallback(&PP, ShowAllHeaders,
OutputFile, OwnsOutputFile,
ShowDepth, MSStyle));
PP.addPPCallbacks(llvm::make_unique<HeaderIncludesCallback>(&PP,
ShowAllHeaders,
OutputFile,
OwnsOutputFile,
ShowDepth,
MSStyle));
}
void HeaderIncludesCallback::FileChanged(SourceLocation Loc,

View File

@ -724,7 +724,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
PP.AddPragmaHandler("clang",
new UnknownPragmaHandler("#pragma clang", Callbacks));
PP.addPPCallbacks(Callbacks);
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks));
// After we have configured the preprocessor, enter the main file.
PP.EnterMainSourceFile();

View File

@ -565,7 +565,7 @@ void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS,
Opts.ShowLineMarkers);
Rewrite->detectMainFileEOL();
PP.addPPCallbacks(Rewrite);
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Rewrite));
PP.IgnorePragmas();
// First let the preprocessor process the entire file and call callbacks.

View File

@ -84,8 +84,8 @@ void VerifyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
const_cast<Preprocessor*>(PP)->addCommentHandler(this);
#ifndef NDEBUG
// Debug build tracks parsed files.
VerifyFileTracker *V = new VerifyFileTracker(*this, *SrcManager);
const_cast<Preprocessor*>(PP)->addPPCallbacks(V);
const_cast<Preprocessor*>(PP)->addPPCallbacks(
llvm::make_unique<VerifyFileTracker>(*this, *SrcManager));
#endif
}
}

View File

@ -172,8 +172,6 @@ Preprocessor::~Preprocessor() {
// Delete the header search info, if we own it.
if (OwnsHeaderSearch)
delete &HeaderInfo;
delete Callbacks;
}
void Preprocessor::Initialize(const TargetInfo &Target) {
@ -853,5 +851,5 @@ void Preprocessor::createPreprocessingRecord() {
return;
Record = new PreprocessingRecord(getSourceManager());
addPPCallbacks(Record);
addPPCallbacks(std::unique_ptr<PPCallbacks>(Record));
}

View File

@ -425,12 +425,12 @@ public:
IndexCtx.setASTContext(CI.getASTContext());
Preprocessor &PP = CI.getPreprocessor();
PP.addPPCallbacks(new IndexPPCallbacks(PP, IndexCtx));
PP.addPPCallbacks(llvm::make_unique<IndexPPCallbacks>(PP, IndexCtx));
IndexCtx.setPreprocessor(PP);
if (SKData) {
auto *PPRec = new PPConditionalDirectiveRecord(PP.getSourceManager());
PP.addPPCallbacks(PPRec);
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
SKCtrl = llvm::make_unique<TUSkipBodyControl>(*SKData, *PPRec, PP);
}

View File

@ -303,7 +303,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
PP.addPPCallbacks(new MacroTracker(Macros));
PP.addPPCallbacks(llvm::make_unique<MacroTracker>(Macros));
PP.EnterMainSourceFile();

View File

@ -111,15 +111,15 @@ struct TestPPCallbacks : public PPCallbacks {
};
class TestPPCallbacksFrontendAction : public PreprocessorFrontendAction {
TestPPCallbacks *Callbacks;
std::unique_ptr<TestPPCallbacks> Callbacks;
public:
TestPPCallbacksFrontendAction(TestPPCallbacks *C)
: Callbacks(C), SeenEnd(false) {}
TestPPCallbacksFrontendAction(std::unique_ptr<TestPPCallbacks> C)
: Callbacks(std::move(C)), SeenEnd(false) {}
void ExecuteAction() override {
Preprocessor &PP = getCompilerInstance().getPreprocessor();
PP.addPPCallbacks(Callbacks);
PP.addPPCallbacks(std::move(Callbacks));
PP.EnterMainSourceFile();
}
void EndSourceFileAction() override { SeenEnd = Callbacks->SeenEnd; }
@ -140,8 +140,8 @@ TEST(PreprocessorFrontendAction, EndSourceFile) {
Compiler.setInvocation(Invocation);
Compiler.createDiagnostics();
TestPPCallbacks *Callbacks = new TestPPCallbacks;
TestPPCallbacksFrontendAction TestAction(Callbacks);
std::unique_ptr<TestPPCallbacks> Callbacks(new TestPPCallbacks);
TestPPCallbacksFrontendAction TestAction(std::move(Callbacks));
ASSERT_FALSE(Callbacks->SeenEnd);
ASSERT_FALSE(TestAction.SeenEnd);
ASSERT_TRUE(Compiler.ExecuteAction(TestAction));

View File

@ -176,7 +176,7 @@ protected:
/*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
PP.addPPCallbacks(Callbacks); // Takes ownership.
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks));
// Lex source text.
PP.EnterMainSourceFile();
@ -222,7 +222,7 @@ protected:
Sema S(PP, Context, Consumer);
Parser P(PP, S, false);
PragmaOpenCLExtensionCallbacks* Callbacks = new PragmaOpenCLExtensionCallbacks;
PP.addPPCallbacks(Callbacks); // Takes ownership.
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks));
// Lex source text.
PP.EnterMainSourceFile();

View File

@ -103,7 +103,7 @@ TEST_F(PPConditionalDirectiveRecordTest, PPRecAPI) {
PP.Initialize(*Target);
PPConditionalDirectiveRecord *
PPRec = new PPConditionalDirectiveRecord(SourceMgr);
PP.addPPCallbacks(PPRec);
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
PP.EnterMainSourceFile();
std::vector<Token> toks;