From: Daniel Dunbar Date: Thu, 12 Mar 2009 16:03:38 +0000 (+0000) Subject: Driver: Add ArgList::getLastArg. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c562a23a6560b5736077226ab31d6a9a216ccd3;p=clang Driver: Add ArgList::getLastArg. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/ArgList.h b/include/clang/Driver/ArgList.h index 4131ff4d16..2e47ee4c39 100644 --- a/include/clang/Driver/ArgList.h +++ b/include/clang/Driver/ArgList.h @@ -58,7 +58,10 @@ 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; + bool hasArg(options::ID Id) const { return getLastArg(Id) != 0; } + + /// getLastArg - Return the last argument matching \arg Id, or null. + Arg *getLastArg(options::ID Id) const; }; } // end namespace driver } // end namespace clang diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index aaba406f14..e29977fb0e 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -30,13 +30,13 @@ void ArgList::append(Arg *A) { Args.push_back(A); } -bool ArgList::hasArg(options::ID Id) const { +Arg *ArgList::getLastArg(options::ID Id) 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)) - return true; + return *it; - return false; + return 0; }