diff options
| author | Alexander Kornienko <alexfh@google.com> | 2015-08-17 10:01:42 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2015-08-17 10:01:42 +0000 |
| commit | 3474b5585842797caee420af1c41f14c26aa01c5 (patch) | |
| tree | 5fd81fd689b6a416d833cdcb53ab52d1740b5cd3 | |
| parent | e1fa6da3566a7243e1273ed61b10949ad336fe9e (diff) | |
| download | bcm5719-llvm-3474b5585842797caee420af1c41f14c26aa01c5.tar.gz bcm5719-llvm-3474b5585842797caee420af1c41f14c26aa01c5.zip | |
[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!
llvm-svn: 245204
| -rw-r--r-- | clang/include/clang/Tooling/CommonOptionsParser.h | 17 | ||||
| -rw-r--r-- | clang/lib/Tooling/CommonOptionsParser.cpp | 11 |
2 files changed, 24 insertions, 4 deletions
diff --git a/clang/include/clang/Tooling/CommonOptionsParser.h b/clang/include/clang/Tooling/CommonOptionsParser.h index c23dc9211dc..65d62a3f3cf 100644 --- a/clang/include/clang/Tooling/CommonOptionsParser.h +++ b/clang/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/clang/lib/Tooling/CommonOptionsParser.cpp b/clang/lib/Tooling/CommonOptionsParser.cpp index adae1781f45..289874bfd8a 100644 --- a/clang/lib/Tooling/CommonOptionsParser.cpp +++ b/clang/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<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden); static cl::opt<std::string> BuildPath("p", cl::desc("Build path"), cl::Optional, cl::cat(Category)); static cl::list<std::string> SourcePaths( - cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore, + cl::Positional, cl::desc("<source0> [... <sourceN>]"), OccurrencesFlag, cl::cat(Category)); static cl::list<std::string> 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()) { |

