bool Option::matches(OptSpecifier Opt) const { // Aliases are never considered in matching, look through them. const Option Alias = getAlias(); if (Alias.isValid()) return Alias.matches(Opt); // Check exact match. if (getID() == Opt.getID()) return true; const Option Group = getGroup(); if (Group.isValid()) return Group.matches(Opt); return false; }
void Option::print(raw_ostream &O) const { O << "<"; switch (getKind()) { #define P(N) case N: O << #N; break P(GroupClass); P(InputClass); P(UnknownClass); P(FlagClass); P(JoinedClass); P(ValuesClass); P(SeparateClass); P(CommaJoinedClass); P(MultiArgClass); P(JoinedOrSeparateClass); P(JoinedAndSeparateClass); P(RemainingArgsClass); P(RemainingArgsJoinedClass); #undef P } if (Info->Prefixes) { O << " Prefixes:["; for (const char *const *Pre = Info->Prefixes; *Pre != nullptr; ++Pre) { O << '"' << *Pre << (*(Pre + 1) == nullptr ? "\"" : "\", "); } O << ']'; } O << " Name:\"" << getName() << '"'; const Option Group = getGroup(); if (Group.isValid()) { O << " Group:"; Group.print(O); } const Option Alias = getAlias(); if (Alias.isValid()) { O << " Alias:"; Alias.print(O); } if (getKind() == MultiArgClass) O << " NumArgs:" << getNumArgs(); O << ">\n"; }
void Option::dump() const { llvm::errs() << "<"; switch (getKind()) { #define P(N) case N: llvm::errs() << #N; break P(GroupClass); P(InputClass); P(UnknownClass); P(FlagClass); P(JoinedClass); P(SeparateClass); P(CommaJoinedClass); P(MultiArgClass); P(JoinedOrSeparateClass); P(JoinedAndSeparateClass); #undef P } if (Info->Prefixes) { llvm::errs() << " Prefixes:["; for (const char * const *Pre = Info->Prefixes; *Pre != 0; ++Pre) { llvm::errs() << '"' << *Pre << (*(Pre + 1) == 0 ? "\"" : "\", "); } llvm::errs() << ']'; } llvm::errs() << " Name:\"" << getName() << '"'; const Option Group = getGroup(); if (Group.isValid()) { llvm::errs() << " Group:"; Group.dump(); } const Option Alias = getAlias(); if (Alias.isValid()) { llvm::errs() << " Alias:"; Alias.dump(); } if (getKind() == MultiArgClass) llvm::errs() << " NumArgs:" << getNumArgs(); llvm::errs() << ">\n"; }
void ArgList::append(Arg *A) { Args.push_back(A); // Update ranges for the option and all of its groups. for (Option O = A->getOption().getUnaliasedOption(); O.isValid(); O = O.getGroup()) { auto &R = OptRanges.insert(std::make_pair(O.getID(), emptyRange())).first->second; R.first = std::min<unsigned>(R.first, Args.size() - 1); R.second = Args.size(); } }
void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const { OS << "OVERVIEW: " << Title << "\n"; OS << '\n'; OS << "USAGE: " << Name << " [options] <inputs>\n"; OS << '\n'; // Render help text into a map of group-name to a list of (option, help) // pairs. using helpmap_ty = std::map<std::string, std::vector<OptionInfo>>; helpmap_ty GroupedOptionHelp; for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { unsigned Id = i + 1; // FIXME: Split out option groups. if (getOptionKind(Id) == Option::GroupClass) continue; unsigned Flags = getInfo(Id).Flags; if (FlagsToInclude && !(Flags & FlagsToInclude)) continue; if (Flags & FlagsToExclude) continue; // If an alias doesn't have a help text, show a help text for the aliased // option instead. const char *HelpText = getOptionHelpText(Id); if (!HelpText && ShowAllAliases) { const Option Alias = getOption(Id).getAlias(); if (Alias.isValid()) HelpText = getOptionHelpText(Alias.getID()); } if (HelpText) { const char *HelpGroup = getOptionHelpGroup(*this, Id); const std::string &OptName = getOptionHelpName(*this, Id); GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText}); } } for (helpmap_ty::iterator it = GroupedOptionHelp .begin(), ie = GroupedOptionHelp.end(); it != ie; ++it) { if (it != GroupedOptionHelp .begin()) OS << "\n"; PrintHelpOptionList(OS, it->first, it->second); } OS.flush(); }