summaryrefslogtreecommitdiffstats
path: root/tool-template
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-08-02 08:24:10 +0000
committerAlexander Kornienko <alexfh@google.com>2014-08-02 08:24:10 +0000
commit8e023532fe6003ab5503e2f9609343f98e39cd3b (patch)
tree6c0c36a54de403e6ac5a0964c43b43acb977f27f /tool-template
parent23af33b85d310336624c971e6bd65aeddbc106c5 (diff)
Changed tool-template to use CommonOptionsParser.
Reviewers: pcc, klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4765 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@214621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tool-template')
-rw-r--r--tool-template/ToolTemplate.cpp47
1 files changed, 14 insertions, 33 deletions
diff --git a/tool-template/ToolTemplate.cpp b/tool-template/ToolTemplate.cpp
index 48a44acc..ce955d56 100644
--- a/tool-template/ToolTemplate.cpp
+++ b/tool-template/ToolTemplate.cpp
@@ -39,7 +39,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Lexer.h"
-#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
@@ -56,11 +56,11 @@ class ToolTemplateCallback : public MatchFinder::MatchCallback {
public:
ToolTemplateCallback(Replacements *Replace) : Replace(Replace) {}
- virtual void run(const MatchFinder::MatchResult &Result) {
-// TODO: This routine will get called for each thing that the matchers find.
-// At this point, you can examine the match, and do whatever you want,
-// including replacing the matched text with other text
- (void) Replace; // This to prevent an "unused member variable" warning;
+ void run(const MatchFinder::MatchResult &Result) override {
+ // TODO: This routine will get called for each thing that the matchers find.
+ // At this point, you can examine the match, and do whatever you want,
+ // including replacing the matched text with other text
+ (void)Replace; // This to prevent an "unused member variable" warning;
}
private:
@@ -69,39 +69,20 @@ class ToolTemplateCallback : public MatchFinder::MatchCallback {
} // end anonymous namespace
// Set up the command line options
-cl::opt<std::string> BuildPath(
- cl::Positional,
- cl::desc("<build-path>"));
-
-cl::list<std::string> SourcePaths(
- cl::Positional,
- cl::desc("<source0> [... <sourceN>]"),
- cl::OneOrMore);
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::OptionCategory ToolTemplateCategory("tool-template options");
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
- std::unique_ptr<CompilationDatabase> Compilations(
- FixedCompilationDatabase::loadFromCommandLine(argc, argv));
- cl::ParseCommandLineOptions(argc, argv);
- if (!Compilations) { // Couldn't find a compilation DB from the command line
- std::string ErrorMessage;
- Compilations.reset(
- !BuildPath.empty() ?
- CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage) :
- CompilationDatabase::autoDetectFromSource(SourcePaths[0], ErrorMessage)
- );
-
-// Still no compilation DB? - bail.
- if (!Compilations)
- llvm::report_fatal_error(ErrorMessage);
- }
- RefactoringTool Tool(*Compilations, SourcePaths);
+ CommonOptionsParser OptionsParser(argc, argv, ToolTemplateCategory);
+ RefactoringTool Tool(OptionsParser.getCompilations(),
+ OptionsParser.getSourcePathList());
ast_matchers::MatchFinder Finder;
ToolTemplateCallback Callback(&Tool.getReplacements());
-// TODO: Put your matchers here.
-// Use Finder.addMatcher(...) to define the patterns in the AST that you
-// want to match against. You are not limited to just one matcher!
+ // TODO: Put your matchers here.
+ // Use Finder.addMatcher(...) to define the patterns in the AST that you
+ // want to match against. You are not limited to just one matcher!
return Tool.run(newFrontendActionFactory(&Finder).get());
}