clang API Documentation
A parser for options common to all command-line Clang tools. More...
#include <CommonOptionsParser.h>
Public Member Functions | |
CommonOptionsParser (int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview=nullptr) | |
Parses command-line, initializes a compilation database. | |
CompilationDatabase & | getCompilations () |
Returns a reference to the loaded compilations database. | |
std::vector< std::string > | getSourcePathList () |
Returns a list of source file paths to process. | |
Static Public Attributes | |
static const char *const | HelpMessage = "\n" |
A parser for options common to all command-line Clang tools.
Parses a common subset of command-line arguments, locates and loads a compilation commands database and runs a tool with user-specified action. It also contains a help message for the common command-line options.
An example of usage:
#include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "llvm/Support/CommandLine.h" using namespace clang::tooling; using namespace llvm; static cl::OptionCategory MyToolCategory("My tool options"); static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); static cl::extrahelp MoreHelp("\nMore help text..."); static cl::opt<bool> YourOwnOption(...); ... int main(int argc, const char **argv) { CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathListi()); return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>()); }
Definition at line 63 of file CommonOptionsParser.h.
CommonOptionsParser::CommonOptionsParser | ( | int & | argc, |
const char ** | argv, | ||
llvm::cl::OptionCategory & | Category, | ||
const char * | Overview = nullptr |
||
) |
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 Category
become hidden.
This constructor exits program in case of error.
Definition at line 93 of file CommonOptionsParser.cpp.
References clang::tooling::CompilationDatabase::autoDetectFromDirectory(), clang::tooling::CompilationDatabase::autoDetectFromSource(), clang::tooling::InsertArgumentAdjuster::BEGIN, clang::tooling::InsertArgumentAdjuster::END, clang::tooling::FixedCompilationDatabase::loadFromCommandLine(), and Options.
Returns a reference to the loaded compilations database.
Definition at line 78 of file CommonOptionsParser.h.
std::vector<std::string> clang::tooling::CommonOptionsParser::getSourcePathList | ( | ) | [inline] |
Returns a list of source file paths to process.
Definition at line 83 of file CommonOptionsParser.h.
const char *const CommonOptionsParser::HelpMessage = "\n" [static] |
Definition at line 87 of file CommonOptionsParser.h.