[clang-tools-extra] r192905 - Refactoring transform-specific options
Edwin Vane
revane at gmail.com
Thu Oct 17 10:57:36 PDT 2013
Author: revane
Date: Thu Oct 17 12:57:36 2013
New Revision: 192905
URL: http://llvm.org/viewvc/llvm-project?rev=192905&view=rev
Log:
Refactoring transform-specific options
Making the user null macros command-line option visible to the
UseNullptrTransform class instead of being visible only to the match callback.
Modified:
clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.cpp
clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.h
clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp
Modified: clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.cpp?rev=192905&r1=192904&r2=192905&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.cpp Thu Oct 17 12:57:36 2013
@@ -32,12 +32,6 @@ namespace {
const char *NullMacroName = "NULL";
-static cl::opt<std::string>
-UserNullMacroNames("user-null-macros",
- cl::desc("Comma-separated list of user-defined "
- "macro names that behave like NULL"),
- cl::cat(TransformsOptionsCategory), cl::init(""));
-
bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
const SourceManager &SM, const Transform &Owner) {
return SM.isWrittenInSameFile(StartLoc, EndLoc) &&
@@ -428,13 +422,12 @@ private:
};
} // namespace
-NullptrFixer::NullptrFixer(unsigned &AcceptedChanges, RiskLevel,
+NullptrFixer::NullptrFixer(unsigned &AcceptedChanges,
+ llvm::ArrayRef<llvm::StringRef> UserMacros,
Transform &Owner)
: AcceptedChanges(AcceptedChanges), Owner(Owner) {
- if (!UserNullMacroNames.empty()) {
- llvm::StringRef S = UserNullMacroNames;
- S.split(UserNullMacros, ",");
- }
+ UserNullMacros.insert(UserNullMacros.begin(), UserMacros.begin(),
+ UserMacros.end());
UserNullMacros.insert(UserNullMacros.begin(), llvm::StringRef(NullMacroName));
}
Modified: clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.h?rev=192905&r1=192904&r2=192905&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.h (original)
+++ clang-tools-extra/trunk/clang-modernize/UseNullptr/NullptrActions.h Thu Oct 17 12:57:36 2013
@@ -27,7 +27,8 @@ typedef llvm::SmallVector<llvm::StringRe
///
class NullptrFixer : public clang::ast_matchers::MatchFinder::MatchCallback {
public:
- NullptrFixer(unsigned &AcceptedChanges, RiskLevel, Transform &Owner);
+ NullptrFixer(unsigned &AcceptedChanges,
+ llvm::ArrayRef<llvm::StringRef> UserMacros, Transform &Owner);
/// \brief Entry point to the callback called when matches are made.
virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &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=192905&r1=192904&r2=192905&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp Thu Oct 17 12:57:36 2013
@@ -23,6 +23,13 @@
using clang::ast_matchers::MatchFinder;
using namespace clang::tooling;
using namespace clang;
+namespace cl = llvm::cl;
+
+static cl::opt<std::string>
+UserNullMacroNames("user-null-macros",
+ cl::desc("Comma-separated list of user-defined "
+ "macro names that behave like NULL"),
+ cl::cat(TransformsOptionsCategory), cl::init(""));
int UseNullptrTransform::apply(const CompilationDatabase &Database,
const std::vector<std::string> &SourcePaths) {
@@ -30,8 +37,13 @@ int UseNullptrTransform::apply(const Com
unsigned AcceptedChanges = 0;
+ llvm::SmallVector<llvm::StringRef, 1> MacroNames;
+ if (!UserNullMacroNames.empty()) {
+ llvm::StringRef S = UserNullMacroNames;
+ S.split(MacroNames, ",");
+ }
MatchFinder Finder;
- NullptrFixer Fixer(AcceptedChanges, Options().MaxRiskLevel, /*Owner=*/ *this);
+ NullptrFixer Fixer(AcceptedChanges, MacroNames, /*Owner=*/ *this);
Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
More information about the cfe-commits
mailing list