diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
| commit | 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (patch) | |
| tree | 80108f0f128657f8623f8f66ad9735b4d88e7b47 /lib/Option/OptTable.cpp | |
| parent | 7c7aba6e5fef47a01a136be655b0a92cfd7090f6 (diff) | |
Notes
Diffstat (limited to 'lib/Option/OptTable.cpp')
| -rw-r--r-- | lib/Option/OptTable.cpp | 34 | 
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Option/OptTable.cpp b/lib/Option/OptTable.cpp index 52a81ff0e159..acb9e8d015bc 100644 --- a/lib/Option/OptTable.cpp +++ b/lib/Option/OptTable.cpp @@ -194,6 +194,37 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,    return 0;  } +// Returns true if one of the Prefixes + In.Names matches Option +static bool optionMatches(const OptTable::Info &In, StringRef Option) { +  if (In.Values && In.Prefixes) +    for (size_t I = 0; In.Prefixes[I]; I++) +      if (Option == std::string(In.Prefixes[I]) + In.Name) +        return true; +  return false; +} + +// This function is for flag value completion. +// Eg. When "-stdlib=" and "l" was passed to this function, it will return +// appropiriate values for stdlib, which starts with l. +std::vector<std::string> +OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const { +  // Search all options and return possible values. +  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) { +    if (!optionMatches(In, Option)) +      continue; + +    SmallVector<StringRef, 8> Candidates; +    StringRef(In.Values).split(Candidates, ",", -1, false); + +    std::vector<std::string> Result; +    for (StringRef Val : Candidates) +      if (Val.startswith(Arg)) +        Result.push_back(Val); +    return Result; +  } +  return {}; +} +  std::vector<std::string> OptTable::findByPrefix(StringRef Cur) const {    std::vector<std::string> Ret;    for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) { @@ -336,6 +367,9 @@ static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) {    case Option::FlagClass:      break; +  case Option::ValuesClass: +    break; +    case Option::SeparateClass: case Option::JoinedOrSeparateClass:    case Option::RemainingArgsClass: case Option::RemainingArgsJoinedClass:      Name += ' ';  | 
