]> granicus.if.org Git - clang/commitdiff
Driver: Switch to using explicit {getLast,has}ArgNoClaim functions instead of taking...
authorDaniel Dunbar <daniel@zuster.org>
Thu, 19 Nov 2009 04:00:53 +0000 (04:00 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 19 Nov 2009 04:00:53 +0000 (04:00 +0000)
 - Most driver code always claims, and bool arguments don't play nice with the overloads.

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

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

index 34ca013b901cb117c7c42032c9cfee476fbc5e28..28d464810571f77ee16a35bf7727c088a2f2c80a 100644 (file)
@@ -78,20 +78,27 @@ namespace driver {
     /// hasArg - Does the arg list contain any option matching \arg Id.
     ///
     /// \arg Claim Whether the argument should be claimed, if it exists.
-    bool hasArg(options::ID Id, bool Claim=true) const {
-      return getLastArg(Id, Claim) != 0;
+    bool hasArgNoClaim(options::ID Id) const {
+      return getLastArgNoClaim(Id) != 0;
     }
-    bool hasArg(options::ID Id0, options::ID Id1, bool Claim=true) const {
-      return getLastArg(Id0, Id1, Claim) != 0;
+    bool hasArg(options::ID Id) const {
+      return getLastArg(Id) != 0;
+    }
+    bool hasArg(options::ID Id0, options::ID Id1) const {
+      return getLastArg(Id0, Id1) != 0;
+    }
+    bool hasArg(options::ID Id0, options::ID Id1, options::ID Id2) const {
+      return getLastArg(Id0, Id1, Id2) != 0;
     }
 
     /// getLastArg - Return the last argument matching \arg Id, or null.
     ///
     /// \arg Claim Whether the argument should be claimed, if it exists.
-    Arg *getLastArg(options::ID Id, bool Claim=true) const;
-    Arg *getLastArg(options::ID Id0, options::ID Id1, bool Claim=true) const;
-    Arg *getLastArg(options::ID Id0, options::ID Id1, options::ID Id2,
-                    bool Claim=true) const;
+    Arg *getLastArgNoClaim(options::ID Id) const;
+    Arg *getLastArg(options::ID Id) const;
+    Arg *getLastArg(options::ID Id0, options::ID Id1) const;
+    Arg *getLastArg(options::ID Id0, options::ID Id1,
+                    options::ID Id2) const;
 
     /// getArgString - Return the input argument string at \arg Index.
     virtual const char *getArgString(unsigned Index) const = 0;
index 8d2138df85e83dcf2d4a728d227743ba99dbc148..c6c1ee60da6f0d6d8f7e663d0868ef62c1a811b9 100644 (file)
@@ -27,38 +27,41 @@ void ArgList::append(Arg *A) {
   Args.push_back(A);
 }
 
-Arg *ArgList::getLastArg(options::ID Id, bool Claim) const {
+Arg *ArgList::getLastArgNoClaim(options::ID Id) const {
   // FIXME: Make search efficient?
-  for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it) {
-    if ((*it)->getOption().matches(Id)) {
-      if (Claim) (*it)->claim();
+  for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it)
+    if ((*it)->getOption().matches(Id))
       return *it;
-    }
-  }
-
   return 0;
 }
 
-Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, bool Claim) const {
-  Arg *Res, *A0 = getLastArg(Id0, false), *A1 = getLastArg(Id1, false);
+Arg *ArgList::getLastArg(options::ID Id) const {
+  Arg *A = getLastArgNoClaim(Id);
+  if (A)
+    A->claim();
+  return A;
+}
+
+Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1) const {
+  Arg *Res, *A0 = getLastArgNoClaim(Id0), *A1 = getLastArgNoClaim(Id1);
 
   if (A0 && A1)
     Res = A0->getIndex() > A1->getIndex() ? A0 : A1;
   else
     Res = A0 ? A0 : A1;
 
-  if (Claim && Res)
+  if (Res)
     Res->claim();
 
   return Res;
 }
 
-Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, options::ID Id2,
-                         bool Claim) const {
+Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1,
+                         options::ID Id2) const {
   Arg *Res = 0;
-  Arg *A0 = getLastArg(Id0, false);
-  Arg *A1 = getLastArg(Id1, false);
-  Arg *A2 = getLastArg(Id2, false);
+  Arg *A0 = getLastArgNoClaim(Id0);
+  Arg *A1 = getLastArgNoClaim(Id1);
+  Arg *A2 = getLastArgNoClaim(Id2);
 
   int A0Idx = A0 ? A0->getIndex() : -1;
   int A1Idx = A1 ? A1->getIndex() : -1;
@@ -76,7 +79,7 @@ Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, options::ID Id2,
       Res = A2;
   }
 
-  if (Claim && Res)
+  if (Res)
     Res->claim();
 
   return Res;
index ce1ac3b75690a6ed017e12ffa332cf2c4e335f3e..e0cc9a72753af3031c6a0ea6ae118811b34031a7 100644 (file)
@@ -687,7 +687,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
           //
           // Otherwise emit an error but still use a valid type to avoid
           // spurious errors (e.g., no inputs).
-          if (!Args.hasArg(options::OPT_E, false))
+          if (!Args.hasArgNoClaim(options::OPT_E))
             Diag(clang::diag::err_drv_unknown_stdin_type);
           Ty = types::TY_C;
         } else {
index 296e399a258763266f938f0d3222b6bdd5d7d2de..8242d31c512d1c707d9fc76f2bd5a320cc1372e2 100644 (file)
@@ -304,9 +304,9 @@ DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
   // and try to push it down into tool specific logic.
 
   Arg *OSXVersion =
-    Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
+    Args.getLastArgNoClaim(options::OPT_mmacosx_version_min_EQ);
   Arg *iPhoneVersion =
-    Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
+    Args.getLastArgNoClaim(options::OPT_miphoneos_version_min_EQ);
   if (OSXVersion && iPhoneVersion) {
     getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
           << OSXVersion->getAsString(Args)
@@ -440,7 +440,7 @@ DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
 
   if (getTriple().getArch() == llvm::Triple::x86 ||
       getTriple().getArch() == llvm::Triple::x86_64)
-    if (!Args.hasArg(options::OPT_mtune_EQ, false))
+    if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
       DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
                                      "core2"));
 
index d42751bb03c648b69532acf7c2f02de25942ce2e..15e5f3fffded6d84a07d8a79d8c8fa2549ea5aee 100644 (file)
@@ -864,7 +864,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(A->getValue(Args));
   }
 
-  if (Args.hasArg(options::OPT__relocatable_pch, true))
+  if (Args.hasArg(options::OPT__relocatable_pch))
     CmdArgs.push_back("--relocatable-pch");
 
   if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {