clang  6.0.0svn
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
clang::tooling::CommonOptionsParser Class Reference

A parser for options common to all command-line Clang tools. More...

#include "clang/Tooling/CommonOptionsParser.h"

Collaboration diagram for clang::tooling::CommonOptionsParser:
Collaboration graph
[legend]

Public Member Functions

 CommonOptionsParser (int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview=nullptr)
 Parses command-line, initializes a compilation database. More...
 
 CommonOptionsParser (int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview=nullptr)
 Parses command-line, initializes a compilation database. More...
 
CompilationDatabasegetCompilations ()
 Returns a reference to the loaded compilations database. More...
 
const std::vector< std::string > & getSourcePathList () const
 Returns a list of source file paths to process. More...
 
ArgumentsAdjuster getArgumentsAdjuster ()
 Returns the argument adjuster calculated from "--extra-arg" and. More...
 

Static Public Member Functions

static llvm::Expected< CommonOptionsParsercreate (int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview=nullptr)
 A factory method that is similar to the above constructor, except this returns an error instead exiting the program on error. More...
 

Static Public Attributes

static const char *const HelpMessage
 

Detailed Description

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 "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.getSourcePathList());
return Tool.run(newFrontendActionFactory<SyntaxOnlyAction>().get());
}

Definition at line 66 of file CommonOptionsParser.h.

Constructor & Destructor Documentation

◆ CommonOptionsParser() [1/2]

clang::tooling::CommonOptionsParser::CommonOptionsParser ( int &  argc,
const char **  argv,
llvm::cl::OptionCategory &  Category,
const char *  Overview = nullptr 
)
inline

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 76 of file CommonOptionsParser.h.

References Category, and create().

◆ CommonOptionsParser() [2/2]

clang::tooling::CommonOptionsParser::CommonOptionsParser ( int &  argc,
const char **  argv,
llvm::cl::OptionCategory &  Category,
llvm::cl::NumOccurrencesFlag  OccurrencesFlag,
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.

It also allows calls to set the required number of positional parameters.

Member Function Documentation

◆ create()

llvm::Expected< CommonOptionsParser > CommonOptionsParser::create ( int &  argc,
const char **  argv,
llvm::cl::OptionCategory &  Category,
llvm::cl::NumOccurrencesFlag  OccurrencesFlag,
const char *  Overview = nullptr 
)
static

A factory method that is similar to the above constructor, except this returns an error instead exiting the program on error.

Definition at line 160 of file CommonOptionsParser.cpp.

References Category, clang::Error, and clang::threadSafety::sx::toString().

Referenced by CommonOptionsParser(), and clang::tooling::internal::createExecutorFromCommandLineArgsImpl().

◆ getArgumentsAdjuster()

ArgumentsAdjuster clang::tooling::CommonOptionsParser::getArgumentsAdjuster ( )
inline

Returns the argument adjuster calculated from "--extra-arg" and.

Definition at line 114 of file CommonOptionsParser.h.

◆ getCompilations()

CompilationDatabase& clang::tooling::CommonOptionsParser::getCompilations ( )
inline

Returns a reference to the loaded compilations database.

Definition at line 103 of file CommonOptionsParser.h.

◆ getSourcePathList()

const std::vector<std::string>& clang::tooling::CommonOptionsParser::getSourcePathList ( ) const
inline

Returns a list of source file paths to process.

Definition at line 108 of file CommonOptionsParser.h.

Referenced by clang::tooling::StandaloneToolExecutorPlugin::create().

Member Data Documentation

◆ HelpMessage

const char *const CommonOptionsParser::HelpMessage
static
Initial value:
=
"\n"
"-p <build-path> is used to read a compile command database.\n"
"\n"
"\tFor example, it can be a CMake build directory in which a file named\n"
"\tcompile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\n"
"\tCMake option to get this output). When no build path is specified,\n"
"\ta search for compile_commands.json will be attempted through all\n"
"\tparent paths of the first input file . See:\n"
"\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\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"

Definition at line 116 of file CommonOptionsParser.h.


The documentation for this class was generated from the following files: