[clang-tools-extra] r215214 - clang-modernize: Transform::createActionFactory return ownership by unique_ptr instead of raw pointer.
David Blaikie
dblaikie at gmail.com
Fri Aug 8 09:06:08 PDT 2014
Author: dblaikie
Date: Fri Aug 8 11:06:07 2014
New Revision: 215214
URL: http://llvm.org/viewvc/llvm-project?rev=215214&view=rev
Log:
clang-modernize: Transform::createActionFactory return ownership by unique_ptr instead of raw pointer.
Follow up to r213851 to simplify code and reduce the chance of future
leaks.
Modified:
clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp
clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
clang-tools-extra/trunk/clang-modernize/Core/Transform.h
clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp
clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp
clang-tools-extra/trunk/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp
clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp
clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp
clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
clang-tools-extra/trunk/remove-cstr-calls/RemoveCStrCalls.cpp
Modified: clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp Fri Aug 8 11:06:07 2014
@@ -40,8 +40,7 @@ int AddOverrideTransform::apply(const Co
// Make Fixer available to handleBeginSource().
this->Fixer = &Fixer;
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (int result = AddOverrideTool.run(Factory.get())) {
+ if (int result = AddOverrideTool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return result;
}
Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp Fri Aug 8 11:06:07 2014
@@ -128,8 +128,9 @@ Transform::addReplacementForCurrentTU(co
return true;
}
-FrontendActionFactory *Transform::createActionFactory(MatchFinder &Finder) {
- return new ActionFactory(Finder, /*Owner=*/ *this);
+std::unique_ptr<FrontendActionFactory>
+Transform::createActionFactory(MatchFinder &Finder) {
+ return llvm::make_unique<ActionFactory>(Finder, /*Owner=*/*this);
}
Version Version::getFromString(llvm::StringRef VersionStr) {
Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.h?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/Core/Transform.h (original)
+++ clang-tools-extra/trunk/clang-modernize/Core/Transform.h Fri Aug 8 11:06:07 2014
@@ -208,8 +208,8 @@ protected:
///
/// The factory returned by this function is responsible for calling back to
/// Transform to call handleBeginSource() and handleEndSource().
- clang::tooling::FrontendActionFactory *
- createActionFactory(clang::ast_matchers::MatchFinder &Finder);
+ std::unique_ptr<clang::tooling::FrontendActionFactory>
+ createActionFactory(clang::ast_matchers::MatchFinder &Finder);
private:
const std::string Name;
Modified: clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp Fri Aug 8 11:06:07 2014
@@ -48,8 +48,7 @@ int LoopConvertTransform::apply(const Co
LFK_PseudoArray, /*Owner=*/ *this);
Finder.addMatcher(makePseudoArrayLoopMatcher(), &PseudoarrrayLoopFixer);
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (int result = LoopTool.run(Factory.get())) {
+ if (int result = LoopTool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return result;
}
Modified: clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp Fri Aug 8 11:06:07 2014
@@ -35,8 +35,7 @@ int PassByValueTransform::apply(const to
// make the replacer available to handleBeginSource()
this->Replacer = &Replacer;
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (Tool.run(Factory.get())) {
+ if (Tool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return 1;
}
Modified: clang-tools-extra/trunk/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp Fri Aug 8 11:06:07 2014
@@ -34,8 +34,7 @@ ReplaceAutoPtrTransform::apply(const Com
Finder.addMatcher(makeAutoPtrUsingDeclMatcher(), &Replacer);
Finder.addMatcher(makeTransferOwnershipExprMatcher(), &Fixer);
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (Tool.run(Factory.get())) {
+ if (Tool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return 1;
}
Modified: clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp Fri Aug 8 11:06:07 2014
@@ -36,8 +36,7 @@ int UseAutoTransform::apply(const clang:
Finder.addMatcher(makeIteratorDeclMatcher(), &ReplaceIterators);
Finder.addMatcher(makeDeclWithNewMatcher(), &ReplaceNew);
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (int Result = UseAutoTool.run(Factory.get())) {
+ if (int Result = UseAutoTool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return Result;
}
Modified: clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp Fri Aug 8 11:06:07 2014
@@ -46,8 +46,7 @@ int UseNullptrTransform::apply(const Com
NullptrFixer Fixer(AcceptedChanges, MacroNames, /*Owner=*/ *this);
Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
- std::unique_ptr<FrontendActionFactory> Factory(createActionFactory(Finder));
- if (int result = UseNullptrTool.run(Factory.get())) {
+ if (int result = UseNullptrTool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return result;
}
Modified: clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp Fri Aug 8 11:06:07 2014
@@ -248,17 +248,17 @@ static CompilerVersions handleSupportedC
return RequiredVersions;
}
-CompilationDatabase *autoDetectCompilations(std::string &ErrorMessage) {
+std::unique_ptr<CompilationDatabase>
+autoDetectCompilations(std::string &ErrorMessage) {
// Auto-detect a compilation database from BuildPath.
if (BuildPath.getNumOccurrences() > 0)
return CompilationDatabase::autoDetectFromDirectory(BuildPath,
ErrorMessage);
// Try to auto-detect a compilation database from the first source.
if (!SourcePaths.empty()) {
- std::unique_ptr<CompilationDatabase> Compilations(
- CompilationDatabase::autoDetectFromSource(SourcePaths[0],
- ErrorMessage));
- if (Compilations) {
+ if (std::unique_ptr<CompilationDatabase> Compilations =
+ CompilationDatabase::autoDetectFromSource(SourcePaths[0],
+ ErrorMessage)) {
// FIXME: just pass SourcePaths[0] once getCompileCommands supports
// non-absolute paths.
SmallString<64> Path(SourcePaths[0]);
@@ -268,7 +268,7 @@ CompilationDatabase *autoDetectCompilati
// Ignore a detected compilation database that doesn't contain source0
// since it is probably an unrelated compilation database.
if (!Commands.empty())
- return Compilations.release();
+ return Compilations;
}
// Reset ErrorMessage since a fix compilation database will be created if
// it fails to detect one from source.
@@ -276,7 +276,7 @@ CompilationDatabase *autoDetectCompilati
// If no compilation database can be detected from source then we create a
// fixed compilation database with c++11 support.
std::string CommandLine[] = { "-std=c++11" };
- return new FixedCompilationDatabase(".", CommandLine);
+ return llvm::make_unique<FixedCompilationDatabase>(".", CommandLine);
}
ErrorMessage = "Could not determine sources to transform";
@@ -335,7 +335,7 @@ int main(int argc, const char **argv) {
if (!Compilations) {
std::string ErrorMessage;
- Compilations.reset(autoDetectCompilations(ErrorMessage));
+ Compilations = autoDetectCompilations(ErrorMessage);
if (!Compilations) {
llvm::errs() << llvm::sys::path::filename(argv[0]) << ": " << ErrorMessage
<< "\n";
Modified: clang-tools-extra/trunk/remove-cstr-calls/RemoveCStrCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/remove-cstr-calls/RemoveCStrCalls.cpp?rev=215214&r1=215213&r2=215214&view=diff
==============================================================================
--- clang-tools-extra/trunk/remove-cstr-calls/RemoveCStrCalls.cpp (original)
+++ clang-tools-extra/trunk/remove-cstr-calls/RemoveCStrCalls.cpp Fri Aug 8 11:06:07 2014
@@ -183,11 +183,11 @@ int main(int argc, const char **argv) {
cl::ParseCommandLineOptions(argc, argv);
if (!Compilations) {
std::string ErrorMessage;
- Compilations.reset(
- CompilationDatabase::loadFromDirectory(BuildPath, ErrorMessage));
+ Compilations =
+ CompilationDatabase::loadFromDirectory(BuildPath, ErrorMessage);
if (!Compilations)
llvm::report_fatal_error(ErrorMessage);
- }
+ }
tooling::RefactoringTool Tool(*Compilations, SourcePaths);
ast_matchers::MatchFinder Finder;
FixCStrCall Callback(&Tool.getReplacements());
More information about the cfe-commits
mailing list