summaryrefslogtreecommitdiffstats
path: root/clang/lib
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
commit78e9de56f4524215875da0e7f0ff14b5ecdc3721 (patch)
treee9875c7012d39fe98b63be539a5d9a95ca9b68b7 /clang/lib
parent250bd173741835a8b4681d8428c6f496260290c1 (diff)
downloadbcm5719-llvm-78e9de56f4524215875da0e7f0ff14b5ecdc3721.tar.gz
bcm5719-llvm-78e9de56f4524215875da0e7f0ff14b5ecdc3721.zip
OptTable: Allow option groups to be used to define "help groups", which will
collate the options inside that group. llvm-svn: 90592
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/OptTable.cpp81
1 files changed, 61 insertions, 20 deletions
diff --git a/clang/lib/Driver/OptTable.cpp b/clang/lib/Driver/OptTable.cpp
index 9c6c9b49ae9..f69d5d806d2 100644
--- a/clang/lib/Driver/OptTable.cpp
+++ b/clang/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();
}
OpenPOWER on IntegriCloud