LLVM  6.0.0svn
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 chargetOptionName (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 chargetOptionHelpText (OptSpecifier id) const
 Get the help text to use to describe this option. More...
 
const chargetOptionMetaVar (OptSpecifier id) const
 Get the meta-variable name to use when describing this options values in the help text. 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 short DisableFlags) const
 Find flags from OptTable which starts with Cur. More...
 
bool addValues (const char *Option, const char *Values)
 Add Values to Option's Values class. More...
 
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...
 
void PrintHelp (raw_ostream &OS, const char *Name, 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 *Name, 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 39 of file OptTable.h.

Constructor & Destructor Documentation

◆ OptTable()

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

◆ ~OptTable()

OptTable::~OptTable ( )
default

Referenced by OptTable().

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

References E, I, llvm::tgtok::In, optionMatches(), and llvm::opt::OptTable::Info::Values.

Referenced by getOptionMetaVar().

◆ findByPrefix()

std::vector< std::string > OptTable::findByPrefix ( StringRef  Cur,
unsigned short  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 230 of file OptTable.cpp.

References E, llvm::opt::OptTable::Info::Flags, llvm::opt::OptTable::Info::GroupID, llvm::opt::OptTable::Info::HelpText, I, llvm::tgtok::In, llvm::opt::OptTable::Info::Name, llvm::opt::OptTable::Info::Prefixes, llvm::MipsISD::Ret, and startswith().

Referenced by getOptionMetaVar().

◆ getNumOptions()

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

Return the total number of option classes.

Definition at line 90 of file OptTable.h.

References getOption(), and llvm::ArrayRef< T >::size().

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(), getNumOptions(), 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 109 of file OptTable.h.

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 114 of file OptTable.h.

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 104 of file OptTable.h.

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 120 of file OptTable.h.

References addValues(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, findByPrefix(), llvm::opt::OptTable::Info::Name, ParseArgs(), ParseOneArg(), PrintHelp(), suggestValueCompletions(), and llvm::opt::OptTable::Info::Values.

Referenced by getOptionHelpName().

◆ getOptionName()

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

Lookup the name of the given option.

Definition at line 99 of file OptTable.h.

◆ 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 320 of file OptTable.cpp.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), llvm::ArrayRef< T >::begin(), llvm::ArrayRef< T >::end(), llvm::WebAssembly::End, ParseOneArg(), and llvm::ArrayRef< T >::size().

Referenced by getOptionMetaVar().

◆ ParseOneArg()

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

References llvm::opt::Option::accept(), Arg, llvm::StringRef::data(), llvm::WebAssembly::End, llvm::opt::ArgList::getArgString(), getOption(), llvm::opt::Option::hasFlag(), isInput(), llvm::lower_bound(), llvm::StringRef::ltrim(), and matchOption().

Referenced by getOptionMetaVar(), and ParseArgs().

◆ PrintHelp() [1/2]

void OptTable::PrintHelp ( raw_ostream OS,
const char Name,
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.
Name- The name to use in the usage line.
Title- The title to use in the usage line.
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 467 of file OptTable.cpp.

References llvm::sys::path::begin(), llvm::sys::path::const_iterator::end, 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 getOptionMetaVar(), and PrintHelp().

◆ PrintHelp() [2/2]

void OptTable::PrintHelp ( raw_ostream OS,
const char Name,
const char Title,
bool  ShowHidden = false,
bool  ShowAllAliases = false 
) const

Definition at line 461 of file OptTable.cpp.

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

◆ 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 210 of file OptTable.cpp.

References E, I, llvm::tgtok::In, optionMatches(), llvm::StringRef::split(), and llvm::opt::OptTable::Info::Values.

Referenced by getOptionMetaVar().


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