clang  3.7.0
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 <CommonOptionsParser.h>

Collaboration diagram for clang::tooling::CommonOptionsParser:
[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...
 
CompilationDatabasegetCompilations ()
 Returns a reference to the loaded compilations database. More...
 
std::vector< std::string > getSourcePathList ()
 Returns a list of source file paths to process. 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.getSourcePathListi());
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
}

Definition at line 63 of file CommonOptionsParser.h.

Constructor & Destructor Documentation

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 95 of file CommonOptionsParser.cpp.

References clang::tooling::CompilationDatabase::autoDetectFromDirectory(), clang::tooling::CompilationDatabase::autoDetectFromSource(), clang::tooling::BEGIN, clang::tooling::END, clang::tooling::getInsertArgumentAdjuster(), and clang::tooling::FixedCompilationDatabase::loadFromCommandLine().

Member Function Documentation

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

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.

Member Data Documentation

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


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