Recommit 213308: unique_ptr-ify ownership of ASTConsumers (reverted in r213324)

After post-commit review and community discussion, this seems like a
reasonable direction to continue, making ownership semantics explicit in
the source using the type system.

llvm-svn: 215324
This commit is contained in:
David Blaikie 2014-08-10 19:56:59 +00:00
parent 6beb6aa8f0
commit 680c4c898c
7 changed files with 32 additions and 28 deletions

View File

@ -49,7 +49,8 @@ private:
FactoryAdaptor(MatchFinder &Finder, Transform &Owner)
: Finder(Finder), Owner(Owner) {}
ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
StringRef) {
return Finder.newASTConsumer();
}

View File

@ -179,10 +179,10 @@ private:
class ClangTidyASTConsumer : public MultiplexConsumer {
public:
ClangTidyASTConsumer(const SmallVectorImpl<ASTConsumer *> &Consumers,
ClangTidyASTConsumer(std::vector<std::unique_ptr<ASTConsumer>> Consumers,
std::unique_ptr<ast_matchers::MatchFinder> Finder,
std::vector<std::unique_ptr<ClangTidyCheck>> Checks)
: MultiplexConsumer(Consumers), Finder(std::move(Finder)),
: MultiplexConsumer(std::move(Consumers)), Finder(std::move(Finder)),
Checks(std::move(Checks)) {}
private:
@ -203,8 +203,8 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
}
}
clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
// FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
// modify Compiler.
@ -224,7 +224,7 @@ clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
Check->registerPPCallbacks(Compiler);
}
SmallVector<ASTConsumer *, 2> Consumers;
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
if (!Checks.empty())
Consumers.push_back(Finder->newASTConsumer());
@ -240,15 +240,16 @@ clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
AnalyzerOptions->AnalyzeNestedBlocks = true;
AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
ento::AnalysisASTConsumer *AnalysisConsumer = ento::CreateAnalysisConsumer(
Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
AnalyzerOptions, Compiler.getFrontendOpts().Plugins);
std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
ento::CreateAnalysisConsumer(
Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
AnalyzerOptions, Compiler.getFrontendOpts().Plugins);
AnalysisConsumer->AddDiagnosticConsumer(
new AnalyzerDiagnosticConsumer(Context));
Consumers.push_back(AnalysisConsumer);
Consumers.push_back(std::move(AnalysisConsumer));
}
return new ClangTidyASTConsumer(Consumers, std::move(Finder),
std::move(Checks));
return llvm::make_unique<ClangTidyASTConsumer>(
std::move(Consumers), std::move(Finder), std::move(Checks));
}
std::vector<std::string>
@ -338,8 +339,8 @@ ClangTidyStats runClangTidy(ClangTidyOptionsProvider *OptionsProvider,
class Action : public ASTFrontendAction {
public:
Action(ClangTidyASTConsumerFactory *Factory) : Factory(Factory) {}
ASTConsumer *CreateASTConsumer(CompilerInstance &Compiler,
StringRef File) override {
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
StringRef File) override {
return Factory->CreateASTConsumer(Compiler, File);
}

View File

@ -99,8 +99,8 @@ public:
ClangTidyASTConsumerFactory(ClangTidyContext &Context);
/// \brief Returns an ASTConsumer that runs the specified clang-tidy checks.
clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &Compiler,
StringRef File);
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
/// \brief Get the list of enabled checks.
std::vector<std::string> getCheckNames(GlobList &Filter);

View File

@ -652,10 +652,10 @@ public:
HadErrors(HadErrors) {}
protected:
virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
return new CollectEntitiesConsumer(Entities, PPTracker,
CI.getPreprocessor(), InFile, HadErrors);
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
return llvm::make_unique<CollectEntitiesConsumer>(
Entities, PPTracker, CI.getPreprocessor(), InFile, HadErrors);
}
private:

View File

@ -178,9 +178,10 @@ public:
ModuleMapCheckerAction(ModuleMapChecker &Checker) : Checker(Checker) {}
protected:
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
return new ModuleMapCheckerConsumer(Checker, CI.getPreprocessor());
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
return llvm::make_unique<ModuleMapCheckerConsumer>(Checker,
CI.getPreprocessor());
}
private:

View File

@ -120,9 +120,10 @@ public:
: Ignore(Ignore), CallbackCalls(CallbackCalls) {}
protected:
virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
return new PPTraceConsumer(Ignore, CallbackCalls, CI.getPreprocessor());
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
return llvm::make_unique<PPTraceConsumer>(Ignore, CallbackCalls,
CI.getPreprocessor());
}
private:

View File

@ -93,8 +93,8 @@ public:
};
struct ConsumerFactory {
ASTConsumer *newASTConsumer() {
return new TimePassingASTConsumer(&Called);
std::unique_ptr<ASTConsumer> newASTConsumer() {
return llvm::make_unique<TimePassingASTConsumer>(&Called);
}
bool Called;
};