Skip to content

Commit

Permalink
[Tooling] [1/1] Refactor FrontendActionFactory::create() to return st…
Browse files Browse the repository at this point in the history
…d::unique_ptr<>

Summary:
I'm not sure whether there are any principal reasons why it returns raw owning pointer,
or it is just a old code that was not updated post-C++11.

I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason,
but it does not //appear// asif those failures are related to these changes.

This is Clang-tools-extra part.
Clang part is D43779.

Reviewers: klimek, bkramer, alexfh, pcc

Reviewed By: alexfh

Subscribers: ioeric, jkorous-apple, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D43780

llvm-svn: 326202
  • Loading branch information
LebedevRI committed Feb 27, 2018
1 parent 6017bf4 commit 6b56a11
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-move/ClangMove.h
Expand Up @@ -217,8 +217,8 @@ class ClangMoveActionFactory : public tooling::FrontendActionFactory {
DeclarationReporter *const Reporter = nullptr)
: Context(Context), Reporter(Reporter) {}

clang::FrontendAction *create() override {
return new ClangMoveAction(Context, Reporter);
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<ClangMoveAction>(Context, Reporter);
}

private:
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-tidy/ClangTidy.cpp
Expand Up @@ -527,7 +527,9 @@ void runClangTidy(clang::tidy::ClangTidyContext &Context,
class ActionFactory : public FrontendActionFactory {
public:
ActionFactory(ClangTidyContext &Context) : ConsumerFactory(Context) {}
FrontendAction *create() override { return new Action(&ConsumerFactory); }
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<Action>(&ConsumerFactory);
}

private:
class Action : public ASTFrontendAction {
Expand Down
Expand Up @@ -53,7 +53,7 @@ class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
public:
SymbolIndexActionFactory(tooling::ExecutionContext *Ctx) : Ctx(Ctx) {}

clang::FrontendAction *create() override {
std::unique_ptr<clang::FrontendAction> create() override {
// Wraps the index action and reports collected symbols to the execution
// context at the end of each translation unit.
class WrappedIndexAction : public WrapperFrontendAction {
Expand Down Expand Up @@ -102,7 +102,8 @@ class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
auto Includes = llvm::make_unique<CanonicalIncludes>();
addSystemHeadersMapping(Includes.get());
CollectorOpts.Includes = Includes.get();
return new WrappedIndexAction(

return llvm::make_unique<WrappedIndexAction>(
std::make_shared<SymbolCollector>(std::move(CollectorOpts)),
std::move(Includes), IndexOpts, Ctx);
}
Expand Down
Expand Up @@ -48,8 +48,8 @@ class FindAllSymbolsActionFactory : public tooling::FrontendActionFactory {
const HeaderMapCollector::RegexHeaderMap *RegexHeaderMap = nullptr)
: Reporter(Reporter), RegexHeaderMap(RegexHeaderMap) {}

clang::FrontendAction *create() override {
return new FindAllSymbolsAction(Reporter, RegexHeaderMap);
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<FindAllSymbolsAction>(Reporter, RegexHeaderMap);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/modularize/CoverageChecker.cpp
Expand Up @@ -129,8 +129,8 @@ class CoverageCheckerFrontendActionFactory : public FrontendActionFactory {
CoverageCheckerFrontendActionFactory(CoverageChecker &Checker)
: Checker(Checker) {}

CoverageCheckerAction *create() override {
return new CoverageCheckerAction(Checker);
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<CoverageCheckerAction>(Checker);
}

private:
Expand Down
9 changes: 5 additions & 4 deletions clang-tools-extra/modularize/Modularize.cpp
Expand Up @@ -722,8 +722,9 @@ class ModularizeFrontendActionFactory : public FrontendActionFactory {
: Entities(Entities), PPTracker(preprocessorTracker),
HadErrors(HadErrors) {}

CollectEntitiesAction *create() override {
return new CollectEntitiesAction(Entities, PPTracker, HadErrors);
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<CollectEntitiesAction>(Entities, PPTracker,
HadErrors);
}

private:
Expand Down Expand Up @@ -802,8 +803,8 @@ class CompileCheckFrontendActionFactory : public FrontendActionFactory {
public:
CompileCheckFrontendActionFactory() {}

CompileCheckAction *create() override {
return new CompileCheckAction();
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<CompileCheckAction>();
}
};

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/pp-trace/PPTrace.cpp
Expand Up @@ -139,8 +139,8 @@ class PPTraceFrontendActionFactory : public FrontendActionFactory {
std::vector<CallbackCall> &CallbackCalls)
: Ignore(Ignore), CallbackCalls(CallbackCalls) {}

PPTraceAction *create() override {
return new PPTraceAction(Ignore, CallbackCalls);
std::unique_ptr<clang::FrontendAction> create() override {
return llvm::make_unique<PPTraceAction>(Ignore, CallbackCalls);
}

private:
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
Expand Up @@ -107,7 +107,8 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks;
CheckFactory<CheckList...>::createChecks(&Context, Checks);
tooling::ToolInvocation Invocation(
Args, new TestClangTidyAction(Checks, Finder, Context), Files.get());
Args, llvm::make_unique<TestClangTidyAction>(Checks, Finder, Context),
Files.get());
InMemoryFileSystem->addFile(Filename, 0,
llvm::MemoryBuffer::getMemBuffer(Code));
for (const auto &FileContent : PathsToContent) {
Expand Down
7 changes: 4 additions & 3 deletions clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
Expand Up @@ -69,7 +69,7 @@ class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
CommentHandler *PragmaHandler)
: COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}

clang::FrontendAction *create() override {
std::unique_ptr<clang::FrontendAction> create() override {
class WrappedIndexAction : public WrapperFrontendAction {
public:
WrappedIndexAction(std::shared_ptr<SymbolCollector> C,
Expand All @@ -95,8 +95,9 @@ class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
index::IndexingOptions::SystemSymbolFilterKind::All;
IndexOpts.IndexFunctionLocals = false;
Collector = std::make_shared<SymbolCollector>(COpts);
return new WrappedIndexAction(Collector, std::move(IndexOpts),
PragmaHandler);

return llvm::make_unique<WrappedIndexAction>(
Collector, std::move(IndexOpts), PragmaHandler);
}

std::shared_ptr<SymbolCollector> Collector;
Expand Down

0 comments on commit 6b56a11

Please sign in to comment.