]> granicus.if.org Git - clang/commitdiff
Driver: Update ArgList::{hasArg,getLastArg} to optionally claim the
authorDaniel Dunbar <daniel@zuster.org>
Sun, 15 Mar 2009 00:48:16 +0000 (00:48 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 15 Mar 2009 00:48:16 +0000 (00:48 +0000)
arguments if they exist.

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

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

index bd2586ecb6ae9ebc92ae57301b8da3f2d0908171..f4ab57e0590fe87cb7aba61d006633919e30a9ed 100644 (file)
@@ -63,10 +63,16 @@ namespace driver {
     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
     /// @{
index 184725f796323e1ed1e08a63180668fbc5d93fcb..d32d9f2185642aeae28136dbdf056b8f281c837e 100644 (file)
@@ -30,13 +30,16 @@ void ArgList::append(Arg *A) {
   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;
 }
index cbd03a331bcd4b36c867b52e4f3e1814fa6220b2..2aa50180bd2dcd622338e6683b1f4c49da68b9ba 100644 (file)
@@ -378,7 +378,7 @@ void Driver::BuildActions(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))
+          if (!Args.hasArg(options::OPT_E, false))
             Diag(clang::diag::err_drv_unknown_stdin_type);
           Ty = types::TY_C;
         } else {
@@ -454,9 +454,10 @@ void Driver::BuildActions(ArgList &Args, ActionList &Actions) const {
       (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 @@ void Driver::BuildActions(ArgList &Args, ActionList &Actions) const {
   } 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))