#include "llvm/Option/OptTable.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/OptionStrCmp.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstring>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
usingnamespacellvm;
usingnamespacellvm::opt;
namespace llvm::opt {
#ifndef NDEBUG
static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
if (&A == &B)
return false;
if (int Cmp = StrCmpOptionName(A.getName(), B.getName()))
return Cmp < 0;
static_assert(sizeof(StringRef) == sizeof(StringLiteral));
ArrayRef<StringRef> APrefixes(A.Prefixes.data(), A.Prefixes.size());
ArrayRef<StringRef> BPrefixes(B.Prefixes.data(), B.Prefixes.size());
if (int Cmp = StrCmpOptionPrefixes(APrefixes, BPrefixes))
return Cmp < 0;
assert(((A.Kind == Option::JoinedClass) ^ (B.Kind == Option::JoinedClass)) &&
"Unexpected classes for options with same name.");
return B.Kind == Option::JoinedClass;
}
#endif
static inline bool operator<(const OptTable::Info &I, StringRef Name) { … }
}
OptSpecifier::OptSpecifier(const Option *Opt) : … { … }
OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
: … { … }
void OptTable::buildPrefixChars() { … }
OptTable::~OptTable() = default;
const Option OptTable::getOption(OptSpecifier Opt) const { … }
static bool isInput(const ArrayRef<StringLiteral> &Prefixes, StringRef Arg) { … }
static unsigned matchOption(const OptTable::Info *I, StringRef Str,
bool IgnoreCase) { … }
static bool optionMatches(const OptTable::Info &In, StringRef Option) { … }
std::vector<std::string>
OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const { … }
std::vector<std::string>
OptTable::findByPrefix(StringRef Cur, Visibility VisibilityMask,
unsigned int DisableFlags) const { … }
unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
Visibility VisibilityMask,
unsigned MinimumLength,
unsigned MaximumDistance) const { … }
unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
unsigned FlagsToInclude, unsigned FlagsToExclude,
unsigned MinimumLength,
unsigned MaximumDistance) const { … }
unsigned OptTable::internalFindNearest(
StringRef Option, std::string &NearestString, unsigned MinimumLength,
unsigned MaximumDistance,
std::function<bool(const Info &)> ExcludeOption) const { … }
std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
unsigned &Index) const { … }
std::unique_ptr<Arg> OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
Visibility VisibilityMask) const { … }
std::unique_ptr<Arg> OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const { … }
std::unique_ptr<Arg> OptTable::internalParseOneArg(
const ArgList &Args, unsigned &Index,
std::function<bool(const Option &)> ExcludeOption) const { … }
InputArgList OptTable::ParseArgs(ArrayRef<const char *> Args,
unsigned &MissingArgIndex,
unsigned &MissingArgCount,
Visibility VisibilityMask) const { … }
InputArgList OptTable::ParseArgs(ArrayRef<const char *> Args,
unsigned &MissingArgIndex,
unsigned &MissingArgCount,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const { … }
InputArgList OptTable::internalParseArgs(
ArrayRef<const char *> ArgArr, unsigned &MissingArgIndex,
unsigned &MissingArgCount,
std::function<bool(const Option &)> ExcludeOption) const { … }
InputArgList OptTable::parseArgs(int Argc, char *const *Argv,
OptSpecifier Unknown, StringSaver &Saver,
std::function<void(StringRef)> ErrorFn) const { … }
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { … }
namespace {
struct OptionInfo { … };
}
static void PrintHelpOptionList(raw_ostream &OS, StringRef Title,
std::vector<OptionInfo> &OptionHelp) { … }
static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) { … }
void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
bool ShowHidden, bool ShowAllAliases,
Visibility VisibilityMask) const { … }
void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
unsigned FlagsToInclude, unsigned FlagsToExclude,
bool ShowAllAliases) const { … }
void OptTable::internalPrintHelp(
raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden,
bool ShowAllAliases, std::function<bool(const Info &)> ExcludeOption,
Visibility VisibilityMask) const { … }
GenericOptTable::GenericOptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
: … { … }