LLVM  14.0.0git
Classes | Public Member Functions | Protected Member Functions | List of all members
llvm::opt::OptTable Class Reference

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

 ~OptTable ()
 
unsigned getNumOptions () const
 Return the total number of option classes. More...
 
const Option getOption (OptSpecifier Opt) const
 Get the given Opt's Option instance, lazily creating it if necessary. More...
 
const char * getOptionName (OptSpecifier id) const
 Lookup the name of the given option. More...
 
unsigned getOptionKind (OptSpecifier id) const
 Get the kind of the given option. More...
 
unsigned getOptionGroupID (OptSpecifier id) const
 Get the group id for the given option. More...
 
const char * getOptionHelpText (OptSpecifier id) const
 Get the help text to use to describe this option. More...
 
const char * getOptionMetaVar (OptSpecifier id) const
 Get the meta-variable name to use when describing this options values in the help text. More...
 
void setInitialOptionsFromEnvironment (const char *E)
 Specify the environment variable where initial options should be read. More...
 
void setGroupedShortOptions (bool Value)
 Support grouped short options. e.g. -ab represents -a -b. More...
 
std::vector< std::string > suggestValueCompletions (StringRef Option, StringRef Arg) const
 Find possible value for given flags. More...
 
std::vector< std::string > findByPrefix (StringRef Cur, unsigned int DisableFlags) const
 Find flags from OptTable which starts with Cur. More...
 
unsigned findNearest (StringRef Option, std::string &NearestString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0, unsigned MinimumLength=4) const
 Find the OptTable option that most closely matches the given string. More...
 
bool addValues (const char *Option, const char *Values)
 Add Values to Option's Values class. More...
 
std::unique_ptr< ArgParseOneArg (const ArgList &Args, unsigned &Index, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
 Parse a single argument; returning the new argument and updating Index. More...
 
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. More...
 
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. More...
 
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. More...
 
void printHelp (raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden=false, bool ShowAllAliases=false) const
 

Protected Member Functions

 OptTable (ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OptTable()

OptTable::OptTable ( ArrayRef< Info OptionInfos,
bool  IgnoreCase = false 
)
protected

◆ ~OptTable()

OptTable::~OptTable ( )
default

Member Function Documentation

◆ addValues()

bool OptTable::addValues ( const char *  Option,
const char *  Values 
)

Add Values to Option's Values class.

Parameters
[in]Option- Prefix + Name of the flag which Values will be changed. For example, "-analyzer-checker".
[in]Values- String of Values seperated by ",", such as "foo, bar..", where foo and bar is the argument which the Option flag takes
Returns
true in success, and false in fail.

Definition at line 325 of file OptTable.cpp.

References E, I, llvm::tgtok::In, and optionMatches().

◆ findByPrefix()

std::vector< std::string > OptTable::findByPrefix ( StringRef  Cur,
unsigned int  DisableFlags 
) const

Find flags from OptTable which starts with Cur.

Parameters
[in]Cur- String prefix that all returned flags need
Returns
The vector of flags which start with Cur.

Definition at line 232 of file OptTable.cpp.

References E, I, llvm::tgtok::In, llvm::MipsISD::Ret, S, and startswith().

◆ findNearest()

unsigned OptTable::findNearest ( StringRef  Option,
std::string &  NearestString,
unsigned  FlagsToInclude = 0,
unsigned  FlagsToExclude = 0,
unsigned  MinimumLength = 4 
) const

Find the OptTable option that most closely matches the given string.

Parameters
[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".
Returns
The edit distance of the nearest string found.

Definition at line 252 of file OptTable.cpp.

References assert(), llvm::StringRef::back(), llvm::StringRef::edit_distance(), llvm::StringRef::empty(), P, and llvm::StringRef::size().

Referenced by parseArgs().

◆ getNumOptions()

unsigned llvm::opt::OptTable::getNumOptions ( ) const
inline

Return the total number of option classes.

Definition at line 96 of file OptTable.h.

Referenced by getOption(), OptTable(), and printHelp().

◆ getOption()

const Option OptTable::getOption ( OptSpecifier  Opt) const

Get the given Opt's Option instance, lazily creating it if necessary.

Returns
The option, or null for the INVALID option id.

Definition at line 162 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().

◆ getOptionGroupID()

unsigned llvm::opt::OptTable::getOptionGroupID ( OptSpecifier  id) const
inline

Get the group id for the given option.

Definition at line 115 of file OptTable.h.

References llvm::opt::OptTable::Info::GroupID.

Referenced by getOptionHelpGroup().

◆ getOptionHelpText()

const char* llvm::opt::OptTable::getOptionHelpText ( OptSpecifier  id) const
inline

Get the help text to use to describe this option.

Definition at line 120 of file OptTable.h.

References llvm::opt::OptTable::Info::HelpText.

Referenced by getOptionHelpGroup(), and printHelp().

◆ getOptionKind()

unsigned llvm::opt::OptTable::getOptionKind ( OptSpecifier  id) const
inline

Get the kind of the given option.

Definition at line 110 of file OptTable.h.

References llvm::opt::OptTable::Info::Kind.

Referenced by printHelp().

◆ getOptionMetaVar()

const char* llvm::opt::OptTable::getOptionMetaVar ( OptSpecifier  id) const
inline

Get the meta-variable name to use when describing this options values in the help text.

Definition at line 126 of file OptTable.h.

References llvm::opt::OptTable::Info::MetaVar.

Referenced by getOptionHelpName().

◆ getOptionName()

const char* llvm::opt::OptTable::getOptionName ( OptSpecifier  id) const
inline

Lookup the name of the given option.

Definition at line 105 of file OptTable.h.

References llvm::opt::OptTable::Info::Name.

◆ ParseArgs()

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.

Parameters
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.
Returns
An InputArgList; on error this will contain all the options which could be parsed.

Definition at line 464 of file OptTable.cpp.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, llvm::ArrayRef< T >::begin(), llvm::ArrayRef< T >::end(), and Index.

Referenced by parseArgs().

◆ 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.

Parameters
ErrorFn- Called on a formatted error message for missing arguments or unknown options.
Returns
An InputArgList; on error this will contain all the options which could be parsed.

Definition at line 510 of file OptTable.cpp.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, llvm::cl::expandResponseFiles(), findNearest(), llvm::makeArrayRef(), and ParseArgs().

◆ ParseOneArg()

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.

Parameters
[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.
Returns
The parsed argument, or 0 if the argument is missing values (in which case Index still points at the conceptual next argument string to parse).

Definition at line 403 of file OptTable.cpp.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, getOption(), Index, and isInput().

◆ printHelp() [1/2]

void OptTable::printHelp ( raw_ostream OS,
const char *  Usage,
const char *  Title,
bool  ShowHidden = false,
bool  ShowAllAliases = false 
) const

Definition at line 635 of file OptTable.cpp.

References llvm::opt::HelpHidden, and printHelp().

◆ printHelp() [2/2]

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.

Parameters
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 641 of file OptTable.cpp.

References llvm::numbers::e, llvm::opt::OptTable::Info::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(), and PrintHelpOptionList().

Referenced by printHelp().

◆ setGroupedShortOptions()

void llvm::opt::OptTable::setGroupedShortOptions ( bool  Value)
inline

Support grouped short options. e.g. -ab represents -a -b.

Definition at line 134 of file OptTable.h.

◆ setInitialOptionsFromEnvironment()

void llvm::opt::OptTable::setInitialOptionsFromEnvironment ( const char *  E)
inline

Specify the environment variable where initial options should be read.

Definition at line 131 of file OptTable.h.

References E.

◆ suggestValueCompletions()

std::vector< std::string > OptTable::suggestValueCompletions ( StringRef  Option,
StringRef  Arg 
) const

Find possible value for given flags.

This is used for shell autocompletion.

Parameters
[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.
Returns
The vector of possible values.

Definition at line 212 of file OptTable.cpp.

References E, I, llvm::tgtok::In, optionMatches(), and llvm::StringRef::split().


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