]> granicus.if.org Git - clang/commitdiff
Driver: Add Option::getId and Option::matches taking an option
authorDaniel Dunbar <daniel@zuster.org>
Thu, 12 Mar 2009 01:34:20 +0000 (01:34 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 12 Mar 2009 01:34:20 +0000 (01:34 +0000)
identifier; we will want to use the latter in situations where we just
want to check for a match, but not load options unnecessarily.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66757 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 546f9561d8b6f001d7abe34a58828814f2941e30..3a4177afa69f272e1bcb532fcc872edeceb02dd1 100644 (file)
@@ -88,6 +88,7 @@ namespace driver {
   public:
     virtual ~Option();
 
+    options::ID getId() const { return ID; }
     OptionClass getKind() const { return Kind; }
     const char *getName() const { return Name; }
     const OptionGroup *getGroup() const { return Group; }
@@ -124,6 +125,7 @@ namespace driver {
     /// matches - Predicate for whether this option is part of the
     /// given option (which may be a group).
     bool matches(const Option *Opt) const;
+    bool matches(options::ID Id) const;
 
     /// accept - Potentially accept the current argument, returning a
     /// new Arg instance, or 0 if the option does not accept this
index f92e7aab265a39ae51409e3025db7292dfe81ce6..7a74d34a86b5e152e263faa80e34ae3dc939a524 100644 (file)
@@ -86,6 +86,22 @@ bool Option::matches(const Option *Opt) const {
   return false;
 }
 
+bool Option::matches(options::ID Id) const {
+  // FIXME: Decide what to do here; we should either pull out the
+  // handling of alias on the option for Id from the other matches, or
+  // find some other solution (which hopefully doesn't require using
+  // the option table).
+  if (Alias)
+    return Alias->matches(Id);
+  
+  if (ID == Id)
+    return true;
+  
+  if (Group)
+    return Group->matches(Id);
+  return false;
+}
+
 OptionGroup::OptionGroup(options::ID ID, const char *Name, 
                          const OptionGroup *Group)
   : Option(Option::GroupClass, ID, Name, Group, 0) {