diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-15 00:48:16 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-15 00:48:16 +0000 |
commit | 8022fd46d45005de63306a7513aece20a1be16ed (patch) | |
tree | cab726771b33b144146ab35623ad873bdd64ab28 | |
parent | 85c491064b33e8d407166256a9e639bc1fcad4ef (diff) |
Driver: Update ArgList::{hasArg,getLastArg} to optionally claim the
arguments if they exist.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67014 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Driver/ArgList.h | 10 | ||||
-rw-r--r-- | lib/Driver/ArgList.cpp | 9 | ||||
-rw-r--r-- | lib/Driver/Driver.cpp | 12 |
3 files changed, 19 insertions, 12 deletions
diff --git a/include/clang/Driver/ArgList.h b/include/clang/Driver/ArgList.h index bd2586ecb6..f4ab57e059 100644 --- a/include/clang/Driver/ArgList.h +++ b/include/clang/Driver/ArgList.h @@ -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 /// @{ diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index 184725f796..d32d9f2185 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -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; } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index cbd03a331b..2aa50180bd 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -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)) |