class OptTable

Declaration

class OptTable { /* full declaration omitted */ };

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.

Declared at: llvm/include/llvm/Option/OptTable.h:40

Member Variables

private std::vector<Info> OptionInfos
The option information table.
private bool IgnoreCase
private bool GroupedShortOptions = false
private const char* EnvVar = nullptr
private unsigned int InputOptionID = 0
private unsigned int UnknownOptionID = 0
private unsigned int 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).
private StringSet<> PrefixesUnion
The union of all option prefixes. If an argument does not begin with one of these, it is an input.
private std::string PrefixChars

Method Overview

  • protected OptTable(ArrayRef<llvm::opt::OptTable::Info> OptionInfos, bool IgnoreCase = false)
  • public llvm::opt::InputArgList ParseArgs(ArrayRef<const char *> Args, unsigned int & MissingArgIndex, unsigned int & MissingArgCount, unsigned int FlagsToInclude = 0, unsigned int FlagsToExclude = 0) const
  • public std::unique_ptr<Arg> ParseOneArg(const llvm::opt::ArgList & Args, unsigned int & Index, unsigned int FlagsToInclude = 0, unsigned int FlagsToExclude = 0) const
  • public bool addValues(const char * Option, const char * Values)
  • public std::vector<std::string> findByPrefix(llvm::StringRef Cur, unsigned int DisableFlags) const
  • public unsigned int findNearest(llvm::StringRef Option, std::string & NearestString, unsigned int FlagsToInclude = 0, unsigned int FlagsToExclude = 0, unsigned int MinimumLength = 4) const
  • private const llvm::opt::OptTable::Info & getInfo(llvm::opt::OptSpecifier Opt) const
  • public unsigned int getNumOptions() const
  • public const llvm::opt::Option getOption(llvm::opt::OptSpecifier Opt) const
  • public unsigned int getOptionGroupID(llvm::opt::OptSpecifier id) const
  • public const char * getOptionHelpText(llvm::opt::OptSpecifier id) const
  • public unsigned int getOptionKind(llvm::opt::OptSpecifier id) const
  • public const char * getOptionMetaVar(llvm::opt::OptSpecifier id) const
  • public const char * getOptionName(llvm::opt::OptSpecifier id) const
  • public llvm::opt::InputArgList parseArgs(int Argc, char *const * Argv, llvm::opt::OptSpecifier Unknown, llvm::StringSaver & Saver, function_ref<void (llvm::StringRef)> ErrorFn) const
  • private std::unique_ptr<Arg> parseOneArgGrouped(llvm::opt::InputArgList & Args, unsigned int & Index) const
  • public void printHelp(llvm::raw_ostream & OS, const char * Usage, const char * Title, unsigned int FlagsToInclude, unsigned int FlagsToExclude, bool ShowAllAliases) const
  • public void printHelp(llvm::raw_ostream & OS, const char * Usage, const char * Title, bool ShowHidden = false, bool ShowAllAliases = false) const
  • public void setGroupedShortOptions(bool Value)
  • public void setInitialOptionsFromEnvironment(const char * E)
  • public std::vector<std::string> suggestValueCompletions(llvm::StringRef Option, llvm::StringRef Arg) const
  • public ~OptTable()

Methods

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

Declared at: llvm/include/llvm/Option/OptTable.h:90

Parameters

ArrayRef<llvm::opt::OptTable::Info> OptionInfos
bool IgnoreCase = false

llvm::opt::InputArgList ParseArgs(
    ArrayRef<const char*> Args,
    unsigned int& MissingArgIndex,
    unsigned int& MissingArgCount,
    unsigned int FlagsToInclude = 0,
    unsigned int FlagsToExclude = 0) const

Description

Parse an list of arguments into an InputArgList. The resulting InputArgList will reference the strings in [\p ArgBegin, \p 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 \p MissingArgCount will be non-zero.

Declared at: llvm/include/llvm/Option/OptTable.h:225

Parameters

ArrayRef<const char*> Args
unsigned int& MissingArgIndex
- On error, the index of the option which could not be parsed.
unsigned int& MissingArgCount
- On error, the number of missing options.
unsigned int FlagsToInclude = 0
- Only parse options with any of these flags. Zero is the default which includes all flags.
unsigned int FlagsToExclude = 0
- 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.

std::unique_ptr<Arg> ParseOneArg(
    const llvm::opt::ArgList& Args,
    unsigned int& Index,
    unsigned int FlagsToInclude = 0,
    unsigned int FlagsToExclude = 0) const

Description

Parse a single argument; returning the new argument and updating Index.

Declared at: llvm/include/llvm/Option/OptTable.h:203

Parameters

const llvm::opt::ArgList& Args
unsigned int& Index
- The current parsing position in the argument string list; on return this will be the index of the next argument string to parse.
unsigned int FlagsToInclude = 0
- Only parse options with any of these flags. Zero is the default which includes all flags.
unsigned int FlagsToExclude = 0
- 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).

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

Description

Add Values to Option's Values class

Declared at: llvm/include/llvm/Option/OptTable.h:187

Parameters

const char* Option
- Prefix + Name of the flag which Values will be changed. For example, "-analyzer-checker".
const char* 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.

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

Declared at: llvm/include/llvm/Option/OptTable.h:155

Parameters

llvm::StringRef Cur
unsigned int DisableFlags

Returns

The vector of flags which start with Cur.

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

Description

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

Declared at: llvm/include/llvm/Option/OptTable.h:174

Parameters

llvm::StringRef 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".
std::string& NearestString
- The nearest option string found in the OptTable.
unsigned int FlagsToInclude = 0
- Only find options with any of these flags. Zero is the default, which includes all flags.
unsigned int FlagsToExclude = 0
- Don't find options with this flag. Zero is the default, and means exclude nothing.
unsigned int MinimumLength = 4
- 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.

const llvm::opt::OptTable::Info& getInfo(
    llvm::opt::OptSpecifier Opt) const

Declared at: llvm/include/llvm/Option/OptTable.h:80

Parameters

llvm::opt::OptSpecifier Opt

unsigned int getNumOptions() const

Description

Return the total number of option classes.

Declared at: llvm/include/llvm/Option/OptTable.h:96

const llvm::opt::Option getOption(
    llvm::opt::OptSpecifier Opt) const

Description

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

Declared at: llvm/include/llvm/Option/OptTable.h:102

Parameters

llvm::opt::OptSpecifier Opt

Returns

The option, or null for the INVALID option id.

unsigned int getOptionGroupID(
    llvm::opt::OptSpecifier id) const

Description

Get the group id for the given option.

Declared at: llvm/include/llvm/Option/OptTable.h:115

Parameters

llvm::opt::OptSpecifier id

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

Description

Get the help text to use to describe this option.

Declared at: llvm/include/llvm/Option/OptTable.h:120

Parameters

llvm::opt::OptSpecifier id

unsigned int getOptionKind(
    llvm::opt::OptSpecifier id) const

Description

Get the kind of the given option.

Declared at: llvm/include/llvm/Option/OptTable.h:110

Parameters

llvm::opt::OptSpecifier id

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

Description

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

Declared at: llvm/include/llvm/Option/OptTable.h:126

Parameters

llvm::opt::OptSpecifier id

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

Description

Lookup the name of the given option.

Declared at: llvm/include/llvm/Option/OptTable.h:105

Parameters

llvm::opt::OptSpecifier id

llvm::opt::InputArgList parseArgs(
    int Argc,
    char* const* Argv,
    llvm::opt::OptSpecifier Unknown,
    llvm::StringSaver& Saver,
    function_ref<void(llvm::StringRef)> ErrorFn)
    const

Description

A convenience helper which handles optional initial options populated from an environment variable, expands response files recursively and parses options.

Declared at: llvm/include/llvm/Option/OptTable.h:237

Parameters

int Argc
char* const* Argv
llvm::opt::OptSpecifier Unknown
llvm::StringSaver& Saver
function_ref<void(llvm::StringRef)> 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.

std::unique_ptr<Arg> parseOneArgGrouped(
    llvm::opt::InputArgList& Args,
    unsigned int& Index) const

Declared at: llvm/include/llvm/Option/OptTable.h:86

Parameters

llvm::opt::InputArgList& Args
unsigned int& Index

void printHelp(llvm::raw_ostream& OS,
               const char* Usage,
               const char* Title,
               unsigned int FlagsToInclude,
               unsigned int FlagsToExclude,
               bool ShowAllAliases) const

Description

Render the help text for an option table.

Declared at: llvm/include/llvm/Option/OptTable.h:253

Parameters

llvm::raw_ostream& OS
- The stream to write the help text to.
const char* Usage
- USAGE: Usage
const char* Title
- OVERVIEW: Title
unsigned int FlagsToInclude
- If non-zero, only include options with any of these flags set.
unsigned int FlagsToExclude
- Exclude options with any of these flags set.
bool 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.

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

Declared at: llvm/include/llvm/Option/OptTable.h:257

Parameters

llvm::raw_ostream& OS
const char* Usage
const char* Title
bool ShowHidden = false
bool ShowAllAliases = false

void setGroupedShortOptions(bool Value)

Description

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

Declared at: llvm/include/llvm/Option/OptTable.h:134

Parameters

bool Value

void setInitialOptionsFromEnvironment(
    const char* E)

Description

Specify the environment variable where initial options should be read.

Declared at: llvm/include/llvm/Option/OptTable.h:131

Parameters

const char* E

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

Description

Find possible value for given flags. This is used for shell autocompletion.

Declared at: llvm/include/llvm/Option/OptTable.h:146

Parameters

llvm::StringRef Option
- Key flag like "-stdlib=" when "-stdlib=l" was passed to clang.
llvm::StringRef Arg
- Value which we want to autocomplete like "l" when "-stdlib=l" was passed to clang.

Returns

The vector of possible values.

~OptTable()

Declared at: llvm/include/llvm/Option/OptTable.h:93