[cfe-commits] r90592 - in /cfe/trunk: include/clang/Driver/OptParser.td include/clang/Driver/OptTable.h lib/Driver/OptTable.cpp
Daniel Dunbar
daniel at zuster.org
Fri Dec 4 13:08:40 PST 2009
Author: ddunbar
Date: Fri Dec 4 15:08:40 2009
New Revision: 90592
URL: http://llvm.org/viewvc/llvm-project?rev=90592&view=rev
Log:
OptTable: Allow option groups to be used to define "help groups", which will
collate the options inside that group.
Modified:
cfe/trunk/include/clang/Driver/OptParser.td
cfe/trunk/include/clang/Driver/OptTable.h
cfe/trunk/lib/Driver/OptTable.cpp
Modified: cfe/trunk/include/clang/Driver/OptParser.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/OptParser.td?rev=90592&r1=90591&r2=90592&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/OptParser.td (original)
+++ cfe/trunk/include/clang/Driver/OptParser.td Fri Dec 4 15:08:40 2009
@@ -87,6 +87,7 @@
class OptionGroup<string name> {
string EnumName = ?; // Uses the def name if undefined.
string Name = name;
+ string HelpText = ?;
OptionGroup Group = ?;
}
Modified: cfe/trunk/include/clang/Driver/OptTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/OptTable.h?rev=90592&r1=90591&r2=90592&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/OptTable.h (original)
+++ cfe/trunk/include/clang/Driver/OptTable.h Fri Dec 4 15:08:40 2009
@@ -118,6 +118,11 @@
return getInfo(id).Kind;
}
+ /// getOptionGroupID - Get the group id for the given option.
+ unsigned getOptionGroupID(OptSpecifier id) const {
+ return getInfo(id).GroupID;
+ }
+
/// isOptionHelpHidden - Should the help for the given option be hidden by
/// default.
bool isOptionHelpHidden(OptSpecifier id) const {
Modified: cfe/trunk/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/OptTable.cpp?rev=90592&r1=90591&r2=90592&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Fri Dec 4 15:08:40 2009
@@ -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 @@
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 @@
}
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();
}
More information about the cfe-commits
mailing list