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";
 | 
					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,
 | 
					bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
 | 
				
			||||||
                        const SourceManager &SM, const Transform &Owner) {
 | 
					                        const SourceManager &SM, const Transform &Owner) {
 | 
				
			||||||
  return SM.isWrittenInSameFile(StartLoc, EndLoc) &&
 | 
					  return SM.isWrittenInSameFile(StartLoc, EndLoc) &&
 | 
				
			||||||
| 
						 | 
					@ -428,13 +422,12 @@ private:
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
} // namespace
 | 
					} // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
NullptrFixer::NullptrFixer(unsigned &AcceptedChanges, RiskLevel,
 | 
					NullptrFixer::NullptrFixer(unsigned &AcceptedChanges,
 | 
				
			||||||
 | 
					                           llvm::ArrayRef<llvm::StringRef> UserMacros,
 | 
				
			||||||
                           Transform &Owner)
 | 
					                           Transform &Owner)
 | 
				
			||||||
    : AcceptedChanges(AcceptedChanges), Owner(Owner) {
 | 
					    : AcceptedChanges(AcceptedChanges), Owner(Owner) {
 | 
				
			||||||
  if (!UserNullMacroNames.empty()) {
 | 
					  UserNullMacros.insert(UserNullMacros.begin(), UserMacros.begin(),
 | 
				
			||||||
    llvm::StringRef S = UserNullMacroNames;
 | 
					                        UserMacros.end());
 | 
				
			||||||
    S.split(UserNullMacros, ",");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  UserNullMacros.insert(UserNullMacros.begin(), llvm::StringRef(NullMacroName));
 | 
					  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 {
 | 
					class NullptrFixer : public clang::ast_matchers::MatchFinder::MatchCallback {
 | 
				
			||||||
public:
 | 
					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.
 | 
					  /// \brief Entry point to the callback called when matches are made.
 | 
				
			||||||
  virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &Result);
 | 
					  virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &Result);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,13 @@
 | 
				
			||||||
using clang::ast_matchers::MatchFinder;
 | 
					using clang::ast_matchers::MatchFinder;
 | 
				
			||||||
using namespace clang::tooling;
 | 
					using namespace clang::tooling;
 | 
				
			||||||
using namespace clang;
 | 
					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,
 | 
					int UseNullptrTransform::apply(const CompilationDatabase &Database,
 | 
				
			||||||
                               const std::vector<std::string> &SourcePaths) {
 | 
					                               const std::vector<std::string> &SourcePaths) {
 | 
				
			||||||
| 
						 | 
					@ -30,8 +37,13 @@ int UseNullptrTransform::apply(const CompilationDatabase &Database,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned AcceptedChanges = 0;
 | 
					  unsigned AcceptedChanges = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  llvm::SmallVector<llvm::StringRef, 1> MacroNames;
 | 
				
			||||||
 | 
					  if (!UserNullMacroNames.empty()) {
 | 
				
			||||||
 | 
					    llvm::StringRef S = UserNullMacroNames;
 | 
				
			||||||
 | 
					    S.split(MacroNames, ",");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  MatchFinder Finder;
 | 
					  MatchFinder Finder;
 | 
				
			||||||
  NullptrFixer Fixer(AcceptedChanges, Options().MaxRiskLevel, /*Owner=*/ *this);
 | 
					  NullptrFixer Fixer(AcceptedChanges, MacroNames, /*Owner=*/ *this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
 | 
					  Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue