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. llvm-svn: 192905
This commit is contained in:
parent
fd541f001b
commit
dd8cc29ce5
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ typedef llvm::SmallVector<llvm::StringRef, 1> UserMacroNames;
|
|||
///
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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 CompilationDatabase &Database,
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue