LLVM 17.0.0git
|
Provide access to the Option info table. More...
#include "llvm/Option/OptTable.h"
Classes | |
struct | Info |
Entry for a single option instance in the option data table. More... | |
Public Member Functions | |
virtual | ~OptTable () |
unsigned | getNumOptions () const |
Return the total number of option classes. | |
const Option | getOption (OptSpecifier Opt) const |
Get the given Opt's Option instance, lazily creating it if necessary. | |
StringRef | getOptionName (OptSpecifier id) const |
Lookup the name of the given option. | |
unsigned | getOptionKind (OptSpecifier id) const |
Get the kind of the given option. | |
unsigned | getOptionGroupID (OptSpecifier id) const |
Get the group id for the given option. | |
const char * | getOptionHelpText (OptSpecifier id) const |
Get the help text to use to describe this option. | |
const char * | getOptionMetaVar (OptSpecifier id) const |
Get the meta-variable name to use when describing this options values in the help text. | |
void | setInitialOptionsFromEnvironment (const char *E) |
Specify the environment variable where initial options should be read. | |
void | setGroupedShortOptions (bool Value) |
Support grouped short options. e.g. -ab represents -a -b. | |
std::vector< std::string > | suggestValueCompletions (StringRef Option, StringRef Arg) const |
Find possible value for given flags. | |
std::vector< std::string > | findByPrefix (StringRef Cur, unsigned int DisableFlags) const |
Find flags from OptTable which starts with Cur. | |
unsigned | findNearest (StringRef Option, std::string &NearestString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0, unsigned MinimumLength=4, unsigned MaximumDistance=UINT_MAX) const |
Find the OptTable option that most closely matches the given string. | |
bool | findExact (StringRef Option, std::string &ExactString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const |
std::unique_ptr< Arg > | ParseOneArg (const ArgList &Args, unsigned &Index, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const |
Parse a single argument; returning the new argument and updating Index. | |
InputArgList | ParseArgs (ArrayRef< const char * > Args, unsigned &MissingArgIndex, unsigned &MissingArgCount, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const |
Parse an list of arguments into an InputArgList. | |
InputArgList | parseArgs (int Argc, char *const *Argv, OptSpecifier Unknown, StringSaver &Saver, function_ref< void(StringRef)> ErrorFn) const |
A convenience helper which handles optional initial options populated from an environment variable, expands response files recursively and parses options. | |
void | printHelp (raw_ostream &OS, const char *Usage, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const |
Render the help text for an option table. | |
void | printHelp (raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden=false, bool ShowAllAliases=false) const |
Protected Member Functions | |
virtual ArrayRef< StringLiteral > | getPrefixesUnion () const =0 |
The union of all option prefixes. | |
OptTable (ArrayRef< Info > OptionInfos, bool IgnoreCase=false) | |
Initialize OptTable using Tablegen'ed OptionInfos. | |
void | buildPrefixChars () |
Build (or rebuild) the PrefixChars member. | |
Protected Attributes | |
unsigned | FirstSearchableIndex = 0 |
The index of the first option which can be parsed (i.e., is not a special option like 'input' or 'unknown', and is not an option group). | |
SmallString< 8 > | PrefixChars |
The union of the first element of all option prefixes. | |
Provide access to the Option info table.
The OptTable class provides a layer of indirection which allows Option instance to be created lazily. In the common case, only a few options will be needed at runtime; the OptTable class maintains enough information to parse command lines without instantiating Options, while letting other parts of the driver still use Option instances where convenient.
Definition at line 40 of file OptTable.h.
Initialize OptTable using Tablegen'ed OptionInfos.
Child class must manually call buildPrefixChars
once they are fully constructed.
Definition at line 88 of file OptTable.cpp.
References assert(), llvm::opt::Option::dump(), FirstSearchableIndex, getNumOptions(), getOption(), llvm::opt::Option::GroupClass, llvm::opt::OptTable::Info::ID, llvm::opt::Option::InputClass, llvm::opt::OptTable::Info::Kind, llvm_unreachable, and llvm::opt::Option::UnknownClass.
|
virtualdefault |
|
protected |
Build (or rebuild) the PrefixChars member.
Definition at line 130 of file OptTable.cpp.
References assert(), llvm::CallingConv::C, llvm::SmallVectorBase< Size_T >::empty(), getPrefixesUnion(), llvm::is_contained(), PrefixChars, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::opt::GenericOptTable::GenericOptTable(), and llvm::opt::PrecomputedOptTable::PrecomputedOptTable().
std::vector< std::string > OptTable::findByPrefix | ( | StringRef | Cur, |
unsigned int | DisableFlags | ||
) | const |
Find flags from OptTable which starts with Cur.
[in] | Cur | - String prefix that all returned flags need |
Definition at line 208 of file OptTable.cpp.
References E, FirstSearchableIndex, I, and llvm::StringRef::startswith().
|
inline |
Definition at line 187 of file OptTable.h.
References findNearest().
unsigned OptTable::findNearest | ( | StringRef | Option, |
std::string & | NearestString, | ||
unsigned | FlagsToInclude = 0 , |
||
unsigned | FlagsToExclude = 0 , |
||
unsigned | MinimumLength = 4 , |
||
unsigned | MaximumDistance = UINT_MAX |
||
) | const |
Find the OptTable option that most closely matches the given string.
[in] | Option | - A string, such as "-stdlibs=l", that represents user input of an option that may not exist in the OptTable. Note that the string includes prefix dashes "-" as well as values "=l". |
[out] | NearestString | - The nearest option string found in the OptTable. |
[in] | FlagsToInclude | - Only find options with any of these flags. Zero is the default, which includes all flags. |
[in] | FlagsToExclude | - Don't find options with this flag. Zero is the default, and means exclude nothing. |
[in] | MinimumLength | - Don't find options shorter than this length. For example, a minimum length of 3 prevents "-x" from being considered near to "-S". |
[in] | MaximumDistance | - Don't find options whose distance is greater than this value. |
Definition at line 228 of file OptTable.cpp.
References assert(), llvm::StringRef::back(), llvm::StringRef::edit_distance(), FirstSearchableIndex, llvm::Last, RHS, llvm::SmallVectorBase< Size_T >::size(), and llvm::StringRef::size().
Referenced by findExact(), and parseArgs().
|
inline |
Return the total number of option classes.
Definition at line 104 of file OptTable.h.
References llvm::ArrayRef< T >::size().
Referenced by getOption(), getPrefixesUnion(), OptTable(), and printHelp().
const Option OptTable::getOption | ( | OptSpecifier | Opt | ) | const |
Get the given Opt's Option instance, lazily creating it if necessary.
Definition at line 143 of file OptTable.cpp.
References assert(), llvm::opt::OptSpecifier::getID(), and getNumOptions().
Referenced by llvm::opt::Option::getAlias(), llvm::opt::Option::getGroup(), getOptionHelpName(), OptTable(), ParseOneArg(), and printHelp().
|
inline |
Get the group id for the given option.
Definition at line 121 of file OptTable.h.
References llvm::opt::OptTable::Info::GroupID.
Referenced by getOptionHelpGroup().
|
inline |
Get the help text to use to describe this option.
Definition at line 126 of file OptTable.h.
References llvm::opt::OptTable::Info::HelpText.
Referenced by getOptionHelpGroup(), and printHelp().
|
inline |
Get the kind of the given option.
Definition at line 116 of file OptTable.h.
References llvm::opt::OptTable::Info::Kind.
Referenced by printHelp().
|
inline |
Get the meta-variable name to use when describing this options values in the help text.
Definition at line 132 of file OptTable.h.
References llvm::opt::OptTable::Info::MetaVar.
Referenced by getOptionHelpName().
|
inline |
Lookup the name of the given option.
Definition at line 113 of file OptTable.h.
References llvm::opt::OptTable::Info::Name.
|
protectedpure virtual |
The union of all option prefixes.
If an argument does not begin with one of these, it is an input.
Implemented in llvm::opt::GenericOptTable, and llvm::opt::PrecomputedOptTable.
References assert(), llvm::opt::OptSpecifier::getID(), and getNumOptions().
Referenced by buildPrefixChars(), and ParseOneArg().
InputArgList OptTable::ParseArgs | ( | ArrayRef< const char * > | Args, |
unsigned & | MissingArgIndex, | ||
unsigned & | MissingArgCount, | ||
unsigned | FlagsToInclude = 0 , |
||
unsigned | FlagsToExclude = 0 |
||
) | const |
Parse an list of arguments into an InputArgList.
The resulting InputArgList will reference the strings in [ArgBegin
, ArgEnd
), and their lifetime should extend past that of the returned InputArgList.
The only error that can occur in this routine is if an argument is missing values; in this case MissingArgCount
will be non-zero.
MissingArgIndex | - On error, the index of the option which could not be parsed. |
MissingArgCount | - On error, the number of missing options. |
FlagsToInclude | - Only parse options with any of these flags. Zero is the default which includes all flags. |
FlagsToExclude | - Don't parse options with this flag. Zero is the default and means exclude nothing. |
Definition at line 447 of file OptTable.cpp.
References A, assert(), llvm::ArrayRef< T >::begin(), llvm::ArrayRef< T >::end(), ParseOneArg(), and llvm::ArrayRef< T >::size().
Referenced by llvm::jitlink::COFFDirectiveParser::parse(), and parseArgs().
InputArgList OptTable::parseArgs | ( | int | Argc, |
char *const * | Argv, | ||
OptSpecifier | Unknown, | ||
StringSaver & | Saver, | ||
function_ref< void(StringRef)> | ErrorFn | ||
) | const |
A convenience helper which handles optional initial options populated from an environment variable, expands response files recursively and parses options.
ErrorFn | - Called on a formatted error message for missing arguments or unknown options. |
Definition at line 493 of file OptTable.cpp.
References A, llvm::cl::expandResponseFiles(), findNearest(), ParseArgs(), and llvm::Unknown.
std::unique_ptr< Arg > OptTable::ParseOneArg | ( | const ArgList & | Args, |
unsigned & | Index, | ||
unsigned | FlagsToInclude = 0 , |
||
unsigned | FlagsToExclude = 0 |
||
) | const |
Parse a single argument; returning the new argument and updating Index.
[in,out] | Index | - The current parsing position in the argument string list; on return this will be the index of the next argument string to parse. |
[in] | FlagsToInclude | - Only parse options with any of these flags. Zero is the default which includes all flags. |
[in] | FlagsToExclude | - Don't parse options with this flag. Zero is the default and means exclude nothing. |
Definition at line 383 of file OptTable.cpp.
References A, llvm::opt::Option::accept(), FirstSearchableIndex, getOption(), getPrefixesUnion(), llvm::opt::Option::hasFlag(), isInput(), matchOption(), Name, and PrefixChars.
Referenced by ParseArgs().
void OptTable::printHelp | ( | raw_ostream & | OS, |
const char * | Usage, | ||
const char * | Title, | ||
bool | ShowHidden = false , |
||
bool | ShowAllAliases = false |
||
) | const |
Definition at line 618 of file OptTable.cpp.
References llvm::opt::HelpHidden, OS, and printHelp().
void OptTable::printHelp | ( | raw_ostream & | OS, |
const char * | Usage, | ||
const char * | Title, | ||
unsigned | FlagsToInclude, | ||
unsigned | FlagsToExclude, | ||
bool | ShowAllAliases | ||
) | const |
Render the help text for an option table.
OS | - The stream to write the help text to. |
Usage | - USAGE: Usage |
Title | - OVERVIEW: Title |
FlagsToInclude | - If non-zero, only include options with any of these flags set. |
FlagsToExclude | - Exclude options with any of these flags set. |
ShowAllAliases | - If true, display all options including aliases that don't have help texts. By default, we display only options that are not hidden and have help texts. |
Definition at line 624 of file OptTable.cpp.
References llvm::opt::OptTable::Info::Flags, Flags, llvm::raw_ostream::flush(), llvm::opt::Option::getAlias(), llvm::opt::Option::getID(), getNumOptions(), getOption(), getOptionHelpGroup(), getOptionHelpName(), getOptionHelpText(), getOptionKind(), llvm::opt::Option::GroupClass, llvm::opt::Option::isValid(), OS, and PrintHelpOptionList().
Referenced by printHelp().
|
inline |
Support grouped short options. e.g. -ab represents -a -b.
Definition at line 140 of file OptTable.h.
Specify the environment variable where initial options should be read.
Definition at line 137 of file OptTable.h.
References E.
std::vector< std::string > OptTable::suggestValueCompletions | ( | StringRef | Option, |
StringRef | Arg | ||
) | const |
Find possible value for given flags.
This is used for shell autocompletion.
[in] | Option | - Key flag like "-stdlib=" when "-stdlib=l" was passed to clang. |
[in] | Arg | - Value which we want to autocomplete like "l" when "-stdlib=l" was passed to clang. |
Definition at line 188 of file OptTable.cpp.
References E, FirstSearchableIndex, I, optionMatches(), and llvm::StringRef::split().
|
protected |
The index of the first option which can be parsed (i.e., is not a special option like 'input' or 'unknown', and is not an option group).
Definition at line 73 of file OptTable.h.
Referenced by findByPrefix(), findNearest(), llvm::opt::GenericOptTable::GenericOptTable(), OptTable(), ParseOneArg(), and suggestValueCompletions().
|
protected |
The union of the first element of all option prefixes.
Definition at line 76 of file OptTable.h.
Referenced by buildPrefixChars(), and ParseOneArg().