]> granicus.if.org Git - clang/commitdiff
[driver] Add a hasFlag API that accepts a positive alias.
authorChad Rosier <mcrosier@apple.com>
Wed, 24 Apr 2013 18:01:26 +0000 (18:01 +0000)
committerChad Rosier <mcrosier@apple.com>
Wed, 24 Apr 2013 18:01:26 +0000 (18:01 +0000)
Part of rdar://13622687

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

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

index 3967dcc21d13dc0288c1ccf1c3230976bc3f057a..362cf9c080140d1a5ac62e832d1ed44f7b0259ff 100644 (file)
@@ -237,7 +237,14 @@ namespace driver {
     /// true if the option is present, false if the negation is present, and
     /// \p Default if neither option is given. If both the option and its
     /// negation are present, the last one wins.
-    bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default=true) const;
+    bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default = true) const;
+
+    /// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
+    /// form \p Neg, return true if the option or its alias is present, false if
+    /// the negation is present, and \p Default if none of the options are
+    /// given. If multiple options are present, the last one wins.
+    bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
+                 bool Default = true) const;
 
     /// AddLastArg - Render only the last argument match \p Id0, if present.
     void AddLastArg(ArgStringList &Output, OptSpecifier Id0) const;
index 6c57b622b8d2ba0eba1789c017f5eb376aa1887b..6fde8360b6c7ddabe783ea4dc9be7abecd8c69f8 100644 (file)
@@ -206,6 +206,13 @@ bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const {
   return Default;
 }
 
+bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
+                      bool Default) const {
+  if (Arg *A = getLastArg(Pos, PosAlias, Neg))
+    return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);
+  return Default;
+}
+
 StringRef ArgList::getLastArgValue(OptSpecifier Id,
                                          StringRef Default) const {
   if (Arg *A = getLastArg(Id))