clang 20.0.0git
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | 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"

Public Member Functions

CompilationDatabasegetCompilations ()
 Returns a reference to the loaded compilations database.
 
const std::vector< std::string > & getSourcePathList () const
 Returns a list of source file paths to process.
 
ArgumentsAdjuster getArgumentsAdjuster ()
 Returns the argument adjuster calculated from "--extra-arg" and.
 

Static Public Member Functions

static llvm::Expected< CommonOptionsParsercreate (int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag=llvm::cl::OneOrMore, 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.
 

Static Public Attributes

static const char *const HelpMessage
 

Protected Member Functions

 CommonOptionsParser (int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag=llvm::cl::OneOrMore, const char *Overview=nullptr)
 Parses command-line, initializes a compilation database.
 

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...\n");
int main(int argc, const char **argv) {
auto ExpectedParser =
CommonOptionsParser::create(argc, argv, MyToolCategory);
if (!ExpectedParser) {
llvm::errs() << ExpectedParser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = ExpectedParser.get();
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(
newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
}
Utility to run a FrontendAction over a set of files.
Definition: Tooling.h:317
A parser for options common to all command-line Clang tools.
static llvm::Expected< CommonOptionsParser > create(int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag=llvm::cl::OneOrMore, const char *Overview=nullptr)
A factory method that is similar to the above constructor, except this returns an error instead exiti...
const std::vector< std::string > & getSourcePathList() const
Returns a list of source file paths to process.
CompilationDatabase & getCompilations()
Returns a reference to the loaded compilations database.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30

Definition at line 70 of file CommonOptionsParser.h.

Constructor & Destructor Documentation

◆ CommonOptionsParser()

clang::tooling::CommonOptionsParser::CommonOptionsParser (