diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Tooling/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib/Tooling/CommonOptionsParser.cpp (renamed from lib/Tooling/CommandLineClangTool.cpp) | 61 |
2 files changed, 31 insertions, 32 deletions
diff --git a/lib/Tooling/CMakeLists.txt b/lib/Tooling/CMakeLists.txt index 49d3101f0e..750dcc88a8 100644 --- a/lib/Tooling/CMakeLists.txt +++ b/lib/Tooling/CMakeLists.txt @@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS support) add_clang_library(clangTooling ArgumentsAdjusters.cpp - CommandLineClangTool.cpp + CommonOptionsParser.cpp CompilationDatabase.cpp Refactoring.cpp RefactoringCallbacks.cpp diff --git a/lib/Tooling/CommandLineClangTool.cpp b/lib/Tooling/CommonOptionsParser.cpp index 8da2a335a5..eefd468ac1 100644 --- a/lib/Tooling/CommandLineClangTool.cpp +++ b/lib/Tooling/CommonOptionsParser.cpp @@ -1,4 +1,4 @@ -//===--- CommandLineClangTool.cpp - command-line clang tools driver -------===// +//===--- CommonOptionsParser.cpp - common options for clang tools ---------===// // // The LLVM Compiler Infrastructure // @@ -7,28 +7,31 @@ // //===----------------------------------------------------------------------===// // -// This file implements the CommandLineClangTool class used to run clang -// tools as separate command-line applications with a consistent common -// interface for handling compilation database and input files. +// This file implements the CommonOptionsParser class used to parse common +// command-line options for clang tools, so that they can be run as separate +// command-line applications with a consistent common interface for handling +// compilation database and input files. // // It provides a common subset of command-line options, common algorithm // for locating a compilation database and source files, and help messages // for the basic command-line interface. // -// It creates a CompilationDatabase, initializes a ClangTool and runs a -// user-specified FrontendAction over all TUs in which the given files are -// compiled. +// It creates a CompilationDatabase and reads common command-line options. +// +// This class uses the Clang Tooling infrastructure, see +// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +// for details on setting it up with LLVM source tree. // //===----------------------------------------------------------------------===// -#include "clang/Frontend/FrontendActions.h" -#include "clang/Tooling/CommandLineClangTool.h" +#include "llvm/Support/CommandLine.h" +#include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" using namespace clang::tooling; using namespace llvm; -static const char *MoreHelpText = +const char *const clang::tooling::CommonHelpMessage = "\n" "-p <build-path> is used to read a compile command database.\n" "\n" @@ -40,26 +43,27 @@ static const char *MoreHelpText = "\thttp://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an\n" "\texample of setting up Clang Tooling on a source tree.\n" "\n" - "<source0> ... specify the paths of source files. These paths are looked\n" - "\tup in the compile command database. If the path of a file is absolute,\n" - "\tit needs to point into CMake's source tree. If the path is relative,\n" - "\tthe current working directory needs to be in the CMake source tree and\n" - "\tthe file must be in a subdirectory of the current working directory.\n" - "\t\"./\" prefixes in the relative files will be automatically removed,\n" - "\tbut the rest of a relative path must be a suffix of a path in the\n" - "\tcompile command database.\n" + "<source0> ... specify the paths of source files. These paths are\n" + "\tlooked up in the compile command database. If the path of a file is\n" + "\tabsolute, it needs to point into CMake's source tree. If the path is\n" + "\trelative, the current working directory needs to be in the CMake\n" + "\tsource tree and the file must be in a subdirectory of the current\n" + "\tworking directory. \"./\" prefixes in the relative files will be\n" + "\tautomatically removed, but the rest of a relative path must be a\n" + "\tsuffix of a path in the compile command database.\n" "\n"; -CommandLineClangTool::CommandLineClangTool() : - BuildPath("p", cl::desc("Build path"), cl::Optional), - SourcePaths(cl::Positional, cl::desc("<source0> [... <sourceN>]"), - cl::OneOrMore), - MoreHelp(MoreHelpText) { -} +static cl::opt<std::string> BuildPath( + "p", cl::desc("Build path"), cl::Optional); + +static cl::list<std::string> SourcePaths( + cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore); -void CommandLineClangTool::initialize(int argc, const char **argv) { - Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv)); +CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv) { + Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, + argv)); cl::ParseCommandLineOptions(argc, argv); + SourcePathList = SourcePaths; if (!Compilations) { std::string ErrorMessage; if (!BuildPath.empty()) { @@ -73,8 +77,3 @@ void CommandLineClangTool::initialize(int argc, const char **argv) { llvm::report_fatal_error(ErrorMessage); } } - -int CommandLineClangTool::run(FrontendActionFactory *ActionFactory) { - ClangTool Tool(*Compilations, SourcePaths); - return Tool.run(ActionFactory); -} |