[cfe-commits] r67014 - in /cfe/trunk: include/clang/Driver/ArgList.h lib/Driver/ArgList.cpp lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Sat Mar 14 17:48:17 PDT 2009


Author: ddunbar
Date: Sat Mar 14 19:48:16 2009
New Revision: 67014

URL: http://llvm.org/viewvc/llvm-project?rev=67014&view=rev
Log:
Driver: Update ArgList::{hasArg,getLastArg} to optionally claim the
arguments if they exist.

Modified:
    cfe/trunk/include/clang/Driver/ArgList.h
    cfe/trunk/lib/Driver/ArgList.cpp
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ArgList.h?rev=67014&r1=67013&r2=67014&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Sat Mar 14 19:48:16 2009
@@ -63,10 +63,16 @@
     const char *getArgString(unsigned Index) const { return ArgStrings[Index]; }
 
     /// hasArg - Does the arg list contain any option matching \arg Id.
-    bool hasArg(options::ID Id) const { return getLastArg(Id) != 0; }
+    ///
+    /// \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;
+    }
 
     /// getLastArg - Return the last argument matching \arg Id, or null.
-    Arg *getLastArg(options::ID Id) const;
+    ///
+    /// \arg Claim Whether the argument should be claimed, if it exists.
+    Arg *getLastArg(options::ID Id, bool Claim=true) const;
 
     /// @name Arg Synthesis
     /// @{

Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=67014&r1=67013&r2=67014&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Sat Mar 14 19:48:16 2009
@@ -30,13 +30,16 @@
   Args.push_back(A);
 }
 
-Arg *ArgList::getLastArg(options::ID Id) const {
+Arg *ArgList::getLastArg(options::ID Id, bool Claim) const {
   // FIXME: Make search efficient?
 
   // FIXME: This needs to not require loading of the option.
-  for (const_iterator it = begin(), ie = end(); it != ie; ++it)
-    if ((*it)->getOption().matches(Id))
+  for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
+    if ((*it)->getOption().matches(Id)) {
+      if (Claim) (*it)->claim();
       return *it;
+    }
+  }
   
   return 0;
 }

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67014&r1=67013&r2=67014&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Sat Mar 14 19:48:16 2009
@@ -378,7 +378,7 @@
           //
           // Otherwise emit an error but still use a valid type to
           // avoid spurious errors (e.g., no inputs).
-          if (!Args.hasArg(options::OPT_E))
+          if (!Args.hasArg(options::OPT_E, false))
             Diag(clang::diag::err_drv_unknown_stdin_type);
           Ty = types::TY_C;
         } else {
@@ -454,9 +454,10 @@
       (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) {
     FinalPhase = phases::Preprocess;
     
-    // -{-analyze,fsyntax-only,S} only run up to the compiler.
-  } else if ((FinalPhaseArg = Args.getLastArg(options::OPT__analyze)) ||
-             (FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
+    // -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler.
+  } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
+             (FinalPhaseArg = Args.getLastArg(options::OPT__analyze)) ||
+             (FinalPhaseArg = Args.getLastArg(options::OPT_emit_llvm)) ||
              (FinalPhaseArg = Args.getLastArg(options::OPT_S))) {
     FinalPhase = phases::Compile;
 
@@ -468,9 +469,6 @@
   } else
     FinalPhase = phases::Link;
 
-  if (FinalPhaseArg)
-    FinalPhaseArg->claim();
-
   // Reject -Z* at the top level, these options should never have been
   // exposed by gcc.
   if (Arg *A = Args.getLastArg(options::OPT_Z))





More information about the cfe-commits mailing list