From: Alexander Kornienko Date: Mon, 17 Aug 2015 10:01:42 +0000 (+0000) Subject: [clang-tidy] Make NumOccurrenceFlag for SourcePaths configurable. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19d5024c80be82539a37d2df7d25a6655687c2ea;p=clang [clang-tidy] Make NumOccurrenceFlag for SourcePaths configurable. Added an additional ctor that takes a NumOccurrenceFlag parameter for the SourcePaths option. This frees applications from always having to pass at least one source file, e.g., -list-checks. http://reviews.llvm.org/D12069 Patch by Don Hinton! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245204 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Tooling/CommonOptionsParser.h b/include/clang/Tooling/CommonOptionsParser.h index c23dc9211d..65d62a3f3c 100644 --- a/include/clang/Tooling/CommonOptionsParser.h +++ b/include/clang/Tooling/CommonOptionsParser.h @@ -72,6 +72,23 @@ public: /// This constructor exits program in case of error. CommonOptionsParser(int &argc, const char **argv, llvm::cl::OptionCategory &Category, + const char *Overview = nullptr) + : CommonOptionsParser(argc, argv, Category, llvm::cl::OneOrMore, + Overview) {} + + /// \brief Parses command-line, initializes a compilation database. + /// + /// This constructor can change argc and argv contents, e.g. consume + /// command-line options used for creating FixedCompilationDatabase. + /// + /// All options not belonging to \p Category become hidden. + /// + /// I also allows calls to set the required number of positional parameters. + /// + /// This constructor exits program in case of error. + CommonOptionsParser(int &argc, const char **argv, + llvm::cl::OptionCategory &Category, + llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview = nullptr); /// Returns a reference to the loaded compilations database. diff --git a/lib/Tooling/CommonOptionsParser.cpp b/lib/Tooling/CommonOptionsParser.cpp index adae1781f4..289874bfd8 100644 --- a/lib/Tooling/CommonOptionsParser.cpp +++ b/lib/Tooling/CommonOptionsParser.cpp @@ -92,16 +92,16 @@ private: }; } // namespace -CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv, - cl::OptionCategory &Category, - const char *Overview) { +CommonOptionsParser::CommonOptionsParser( + int &argc, const char **argv, cl::OptionCategory &Category, + llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview) { static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden); static cl::opt BuildPath("p", cl::desc("Build path"), cl::Optional, cl::cat(Category)); static cl::list SourcePaths( - cl::Positional, cl::desc(" [... ]"), cl::OneOrMore, + cl::Positional, cl::desc(" [... ]"), OccurrencesFlag, cl::cat(Category)); static cl::list ArgsAfter( @@ -120,6 +120,9 @@ CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv, argv)); cl::ParseCommandLineOptions(argc, argv, Overview); SourcePathList = SourcePaths; + if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) && + SourcePathList.empty()) + return; if (!Compilations) { std::string ErrorMessage; if (!BuildPath.empty()) {