]> granicus.if.org Git - clang/commitdiff
[Options] Store the owning OptTable in Option so it can construct Group and Alias.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Wed, 3 Oct 2012 19:58:10 +0000 (19:58 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Wed, 3 Oct 2012 19:58:10 +0000 (19:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165150 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Option.h
lib/Driver/OptTable.cpp
lib/Driver/Option.cpp

index 2adba6b4b7874ca8a6e573d453262ed6676c1908..6fc8bef5daaae48d413200f6b95a310db66198ba 100644 (file)
@@ -70,23 +70,17 @@ namespace options {
 
   private:
     const OptTable::Info *Info;
-
-    /// Group this option is a member of, if any.
-    const Option *Group;
-
-    /// Option that this is an alias for, if any.
-    const Option *Alias;
+    const OptTable *Owner;
 
   public:
-    Option(const OptTable::Info *Info,
-           const Option *Group, const Option *Alias);
+    Option(const OptTable::Info *Info, const OptTable *Owner);
     ~Option();
 
     unsigned getID() const { return Info->ID; }
     OptionClass getKind() const { return OptionClass(Info->Kind); }
     StringRef getName() const { return Info->Name; }
-    const Option *getGroup() const { return Group; }
-    const Option *getAlias() const { return Alias; }
+    const Option *getGroup() const { return Owner->getOption(Info->GroupID); }
+    const Option *getAlias() const { return Owner->getOption(Info->AliasID); }
 
     unsigned getNumArgs() const { return Info->Param; }
 
@@ -137,6 +131,7 @@ namespace options {
     /// getUnaliasedOption - Return the final option this option
     /// aliases (itself, if the option has no alias).
     const Option *getUnaliasedOption() const {
+      const Option *Alias = getAlias();
       if (Alias) return Alias->getUnaliasedOption();
       return this;
     }
index a6d3cb314990a8120dc07fa151db5e3e755e70cf..680ea9938fed62f26edd45d223620a7d1667ab55 100644 (file)
@@ -134,13 +134,7 @@ bool OptTable::isOptionHelpHidden(OptSpecifier id) const {
 }
 
 Option *OptTable::CreateOption(unsigned id) const {
-  const Info &info = getInfo(id);
-  const Option *Group = getOption(info.GroupID);
-  const Option *Alias = getOption(info.AliasID);
-
-  Option *Opt = new Option(&info, Group, Alias);
-
-  return Opt;
+  return new Option(&getInfo(id), this);
 }
 
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
index 3be141e61da056f72772a7dbaa1322cafdc33ab7..117021b880ce4a5071321e94041024ad6244b90a 100644 (file)
 #include <algorithm>
 using namespace clang::driver;
 
-Option::Option(const OptTable::Info *info,
-               const Option *_Group, const Option *_Alias)
-  : Info(info), Group(_Group), Alias(_Alias) {
+Option::Option(const OptTable::Info *info, const OptTable *owner)
+  : Info(info), Owner(owner) {
 
   // Multi-level aliases are not supported, and alias options cannot
   // have groups. This just simplifies option tracking, it is not an
   // inherent limitation.
-  assert((!Alias || (!Alias->Alias && !Group)) &&
+  assert((!getAlias() || (!getAlias()->getAlias() && !getGroup())) &&
          "Multi-level aliases and aliases with groups are unsupported.");
 }
 
@@ -50,11 +49,13 @@ void Option::dump() const {
 
   llvm::errs() << " Name:\"" << getName() << '"';
 
+  const Option *Group = getGroup();
   if (Group) {
     llvm::errs() << " Group:";
     Group->dump();
   }
 
+  const Option *Alias = getAlias();
   if (Alias) {
     llvm::errs() << " Alias:";
     Alias->dump();
@@ -68,6 +69,7 @@ void Option::dump() const {
 
 bool Option::matches(OptSpecifier Opt) const {
   // Aliases are never considered in matching, look through them.
+  const Option *Alias = getAlias();
   if (Alias)
     return Alias->matches(Opt);
 
@@ -75,6 +77,7 @@ bool Option::matches(OptSpecifier Opt) const {
   if (getID() == Opt.getID())
     return true;
 
+  const Option *Group = getGroup();
   if (Group)
     return Group->matches(Opt);
   return false;