r217474 - Unique_ptrify PPCallbacks ownership.
Craig Topper
craig.topper at gmail.com
Tue Sep 9 21:53:53 PDT 2014
Author: ctopper
Date: Tue Sep 9 23:53:53 2014
New Revision: 217474
URL: http://llvm.org/viewvc/llvm-project?rev=217474&view=rev
Log:
Unique_ptrify PPCallbacks ownership.
Unique_ptr creation stil needs to be moved earlier at some of the call sites.
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/ARCMigrate/ARCMT.cpp
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/DependencyFile.cpp
cfe/trunk/lib/Frontend/DependencyGraph.cpp
cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/unittests/Basic/SourceManagerTest.cpp
cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Tue Sep 9 23:53:53 2014
@@ -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,
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Sep 9 23:53:53 2014
@@ -338,7 +338,7 @@ class Preprocessor : public RefCountedBa
/// \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);
}
/// \}
Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Tue Sep 9 23:53:53 2014
@@ -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>();
}
};
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Sep 9 23:53:53 2014
@@ -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(C
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>(
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Sep 9 23:53:53 2014
@@ -646,7 +646,8 @@ CodeGenAction::CreateASTConsumer(Compile
// 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(),
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Sep 9 23:53:53 2014
@@ -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::CreateASTConsu
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::LoadFromCompilerInvoca
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());
Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Tue Sep 9 23:53:53 2014
@@ -121,7 +121,8 @@ bool DependencyCollector::sawDependency(
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 *DependencyFileG
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);
}
Modified: cfe/trunk/lib/Frontend/DependencyGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyGraph.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DependencyGraph.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyGraph.cpp Tue Sep 9 23:53:53 2014
@@ -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,
Modified: cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp (original)
+++ cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp Tue Sep 9 23:53:53 2014
@@ -69,9 +69,12 @@ void clang::AttachHeaderIncludeGen(Prepr
}
}
- 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,
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Sep 9 23:53:53 2014
@@ -724,7 +724,7 @@ void clang::DoPrintPreprocessedInput(Pre
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();
Modified: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Tue Sep 9 23:53:53 2014
@@ -565,7 +565,7 @@ void clang::RewriteIncludesInInput(Prepr
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.
Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp Tue Sep 9 23:53:53 2014
@@ -84,8 +84,8 @@ void VerifyDiagnosticConsumer::BeginSour
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
}
}
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Sep 9 23:53:53 2014
@@ -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::createPreprocessingRe
return;
Record = new PreprocessingRecord(getSourceManager());
- addPPCallbacks(Record);
+ addPPCallbacks(std::unique_ptr<PPCallbacks>(Record));
}
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Tue Sep 9 23:53:53 2014
@@ -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);
}
Modified: cfe/trunk/unittests/Basic/SourceManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/SourceManagerTest.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/SourceManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/SourceManagerTest.cpp Tue Sep 9 23:53:53 2014
@@ -303,7 +303,7 @@ TEST_F(SourceManagerTest, isBeforeInTran
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
- PP.addPPCallbacks(new MacroTracker(Macros));
+ PP.addPPCallbacks(llvm::make_unique<MacroTracker>(Macros));
PP.EnterMainSourceFile();
Modified: cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/FrontendActionTest.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/unittests/Frontend/FrontendActionTest.cpp (original)
+++ cfe/trunk/unittests/Frontend/FrontendActionTest.cpp Tue Sep 9 23:53:53 2014
@@ -111,15 +111,15 @@ struct TestPPCallbacks : public PPCallba
};
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, EndSour
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));
Modified: cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPCallbacksTest.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPCallbacksTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPCallbacksTest.cpp Tue Sep 9 23:53:53 2014
@@ -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();
Modified: cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp?rev=217474&r1=217473&r2=217474&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp Tue Sep 9 23:53:53 2014
@@ -103,7 +103,7 @@ TEST_F(PPConditionalDirectiveRecordTest,
PP.Initialize(*Target);
PPConditionalDirectiveRecord *
PPRec = new PPConditionalDirectiveRecord(SourceMgr);
- PP.addPPCallbacks(PPRec);
+ PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(PPRec));
PP.EnterMainSourceFile();
std::vector<Token> toks;
More information about the cfe-commits
mailing list