aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/OptTable.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-12-04 21:08:40 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-12-04 21:08:40 +0000
commit2658f05caf1c1d86608a46ebc7be0b3bb21fef2a (patch)
treeadecff53e35cade667cd0566d1409adf355da805 /lib/Driver/OptTable.cpp
parent9a242512a8b319cc4df7d050166a1c65bf66abeb (diff)
OptTable: Allow option groups to be used to define "help groups", which will
collate the options inside that group. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90592 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/OptTable.cpp')
-rw-r--r--lib/Driver/OptTable.cpp81
1 files changed, 61 insertions, 20 deletions
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp
index 9c6c9b49ae..f69d5d806d 100644
--- a/lib/Driver/OptTable.cpp
+++ b/lib/Driver/OptTable.cpp
@@ -14,7 +14,7 @@
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
-
+#include <map>
using namespace clang::driver;
using namespace clang::driver::options;
@@ -285,25 +285,10 @@ static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) {
return Name;
}
-void OptTable::PrintHelp(llvm::raw_ostream &OS, const char *Name,
- const char *Title, bool ShowHidden) const {
- OS << "OVERVIEW: " << Title << "\n";
- OS << '\n';
- OS << "USAGE: " << Name << " [options] <inputs>\n";
- OS << '\n';
- OS << "OPTIONS:\n";
-
- // Render help text into (option, help) pairs.
- std::vector< std::pair<std::string, const char*> > OptionHelp;
- for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
- unsigned Id = i + 1;
-
- if (!ShowHidden && isOptionHelpHidden(Id))
- continue;
-
- if (const char *Text = getOptionHelpText(Id))
- OptionHelp.push_back(std::make_pair(getOptionHelpName(*this, Id), Text));
- }
+static void PrintHelpOptionList(llvm::raw_ostream &OS, llvm::StringRef Title,
+ std::vector<std::pair<std::string,
+ const char*> > &OptionHelp) {
+ OS << Title << ":\n";
// Find the maximum option length.
unsigned OptionFieldWidth = 0;
@@ -331,6 +316,62 @@ void OptTable::PrintHelp(llvm::raw_ostream &OS, const char *Name,
}
OS.indent(Pad + 1) << OptionHelp[i].second << '\n';
}
+}
+
+static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
+ unsigned GroupID = Opts.getOptionGroupID(Id);
+
+ // If not in a group, return the default help group.
+ if (!GroupID)
+ return "OPTIONS";
+
+ // Abuse the help text of the option groups to store the "help group"
+ // name.
+ //
+ // FIXME: Split out option groups.
+ if (const char *GroupHelp = Opts.getOptionHelpText(GroupID))
+ return GroupHelp;
+
+ // Otherwise keep looking.
+ return getOptionHelpGroup(Opts, GroupID);
+}
+
+void OptTable::PrintHelp(llvm::raw_ostream &OS, const char *Name,
+ const char *Title, bool ShowHidden) 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.
+ typedef std::map<std::string,
+ std::vector<std::pair<std::string, const char*> > > helpmap_ty;
+ 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;
+
+ if (!ShowHidden && isOptionHelpHidden(Id))
+ continue;
+
+ if (const char *Text = getOptionHelpText(Id)) {
+ const char *HelpGroup = getOptionHelpGroup(*this, Id);
+ const std::string &OptName = getOptionHelpName(*this, Id);
+ GroupedOptionHelp[HelpGroup].push_back(std::make_pair(OptName, Text));
+ }
+ }
+
+ 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();
}