[PATCH] D35476: [libOption] - Add flag allowing to print options aliases in help text.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 10:21:39 PDT 2017
LGTM
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar updated this revision to Diff 108052.
> grimar added a comment.
>
> - Updated in according to my latest comment. (renamed argument to ShowAllAliases).
>
>
> https://reviews.llvm.org/D35476
>
> Files:
> include/llvm/Option/OptTable.h
> lib/Option/OptTable.cpp
>
>
> Index: lib/Option/OptTable.cpp
> ===================================================================
> --- lib/Option/OptTable.cpp
> +++ lib/Option/OptTable.cpp
> @@ -444,15 +444,14 @@
> }
>
> void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> - bool ShowHidden) const {
> + bool ShowHidden, bool ShowAllAliases) const {
> PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
> - (ShowHidden ? 0 : HelpHidden));
> + (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
> }
>
> -
> void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> - unsigned FlagsToInclude,
> - unsigned FlagsToExclude) const {
> + unsigned FlagsToInclude, unsigned FlagsToExclude,
> + bool ShowAllAliases) const {
> OS << "OVERVIEW: " << Title << "\n";
> OS << '\n';
> OS << "USAGE: " << Name << " [options] <inputs>\n";
> @@ -476,10 +475,21 @@
> if (Flags & FlagsToExclude)
> continue;
>
> - if (const char *Text = getOptionHelpText(Id)) {
> + // Aliases usually do not have help text set explicitly. If we want to show
> + // such aliases in help, we use associated aliased option help text value.
> + // If both alias and aliased option has no text, that proably means option
> + // is ignored.
> + 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, Text});
> + GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
> }
> }
>
> Index: include/llvm/Option/OptTable.h
> ===================================================================
> --- include/llvm/Option/OptTable.h
> +++ include/llvm/Option/OptTable.h
> @@ -191,12 +191,15 @@
> /// \param FlagsToInclude - If non-zero, only include options with any
> /// of these flags set.
> /// \param FlagsToExclude - Exclude options with any of these flags set.
> - void PrintHelp(raw_ostream &OS, const char *Name,
> - const char *Title, unsigned FlagsToInclude,
> - unsigned FlagsToExclude) const;
> + /// \param ShowAllAliases - If true then aliases without explicitly set
> + /// HelpText will be rendered, inheriting it from
> + /// aliased option.
> + void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> + unsigned FlagsToInclude, unsigned FlagsToExclude,
> + bool ShowAllAliases) const;
>
> - void PrintHelp(raw_ostream &OS, const char *Name,
> - const char *Title, bool ShowHidden = false) const;
> + void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> + bool ShowHidden = false, bool ShowAllAliases = false) const;
> };
>
> } // end namespace opt
>
>
> Index: lib/Option/OptTable.cpp
> ===================================================================
> --- lib/Option/OptTable.cpp
> +++ lib/Option/OptTable.cpp
> @@ -444,15 +444,14 @@
> }
>
> void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> - bool ShowHidden) const {
> + bool ShowHidden, bool ShowAllAliases) const {
> PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
> - (ShowHidden ? 0 : HelpHidden));
> + (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
> }
>
> -
> void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> - unsigned FlagsToInclude,
> - unsigned FlagsToExclude) const {
> + unsigned FlagsToInclude, unsigned FlagsToExclude,
> + bool ShowAllAliases) const {
> OS << "OVERVIEW: " << Title << "\n";
> OS << '\n';
> OS << "USAGE: " << Name << " [options] <inputs>\n";
> @@ -476,10 +475,21 @@
> if (Flags & FlagsToExclude)
> continue;
>
> - if (const char *Text = getOptionHelpText(Id)) {
> + // Aliases usually do not have help text set explicitly. If we want to show
> + // such aliases in help, we use associated aliased option help text value.
> + // If both alias and aliased option has no text, that proably means option
> + // is ignored.
> + 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, Text});
> + GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
> }
> }
>
> Index: include/llvm/Option/OptTable.h
> ===================================================================
> --- include/llvm/Option/OptTable.h
> +++ include/llvm/Option/OptTable.h
> @@ -191,12 +191,15 @@
> /// \param FlagsToInclude - If non-zero, only include options with any
> /// of these flags set.
> /// \param FlagsToExclude - Exclude options with any of these flags set.
> - void PrintHelp(raw_ostream &OS, const char *Name,
> - const char *Title, unsigned FlagsToInclude,
> - unsigned FlagsToExclude) const;
> + /// \param ShowAllAliases - If true then aliases without explicitly set
> + /// HelpText will be rendered, inheriting it from
> + /// aliased option.
> + void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> + unsigned FlagsToInclude, unsigned FlagsToExclude,
> + bool ShowAllAliases) const;
>
> - void PrintHelp(raw_ostream &OS, const char *Name,
> - const char *Title, bool ShowHidden = false) const;
> + void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
> + bool ShowHidden = false, bool ShowAllAliases = false) const;
> };
>
> } // end namespace opt
More information about the llvm-commits
mailing list