]> granicus.if.org Git - llvm/commitdiff
Generalize ArgList::AddAllArgs more
authorDouglas Katzman <dougk@google.com>
Thu, 29 Sep 2016 19:47:58 +0000 (19:47 +0000)
committerDouglas Katzman <dougk@google.com>
Thu, 29 Sep 2016 19:47:58 +0000 (19:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282755 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Option/ArgList.h
lib/Option/ArgList.cpp

index 89771b5c3cf11392766aec5ea4bc8b814b809ef8..53cb0d8dec4d4356926dddb8543768e9bacab15e 100644 (file)
@@ -259,6 +259,10 @@ public:
   void AddLastArg(ArgStringList &Output, OptSpecifier Id0,
                   OptSpecifier Id1) const;
 
+  /// AddAllArgsExcept - Render all arguments matching any of the given ids
+  /// and not matching any of the excluded ids.
+  void AddAllArgsExcept(ArgStringList &Output, ArrayRef<OptSpecifier> Ids,
+                        ArrayRef<OptSpecifier> ExcludeIds) const;
   /// AddAllArgs - Render all arguments matching any of the given ids.
   void AddAllArgs(ArgStringList &Output, ArrayRef<OptSpecifier> Ids) const;
 
index d5c4a7e458bff2de83ba8d0cd7ef2832cf3831cd..f94de866ef34893f8311d75ffffa39352187eb1b 100644 (file)
@@ -259,19 +259,36 @@ void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id0,
   }
 }
 
-void ArgList::AddAllArgs(ArgStringList &Output,
-                         ArrayRef<OptSpecifier> Ids) const {
+void ArgList::AddAllArgsExcept(ArgStringList &Output,
+                               ArrayRef<OptSpecifier> Ids,
+                               ArrayRef<OptSpecifier> ExcludeIds) const {
   for (const Arg *Arg : Args) {
-    for (OptSpecifier Id : Ids) {
+    bool Excluded = false;
+    for (OptSpecifier Id : ExcludeIds) {
       if (Arg->getOption().matches(Id)) {
-        Arg->claim();
-        Arg->render(*this, Output);
+        Excluded = true;
         break;
       }
     }
+    if (!Excluded) {
+      for (OptSpecifier Id : Ids) {
+        if (Arg->getOption().matches(Id)) {
+          Arg->claim();
+          Arg->render(*this, Output);
+          break;
+        }
+      }
+    }
   }
 }
 
+/// This is a nicer interface when you don't have a list of Ids to exclude.
+void ArgList::AddAllArgs(ArgStringList &Output,
+                         ArrayRef<OptSpecifier> Ids) const {
+  ArrayRef<OptSpecifier> Exclude = None;
+  AddAllArgsExcept(Output, Ids, Exclude);
+}
+
 /// This 3-opt variant of AddAllArgs could be eliminated in favor of one
 /// that accepts a single specifier, given the above which accepts any number.
 void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0,