From: Daniel Dunbar Date: Thu, 19 Nov 2009 04:00:53 +0000 (+0000) Subject: Driver: Switch to using explicit {getLast,has}ArgNoClaim functions instead of taking... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4bdae78c69d2a09ee96619cc5ccf81441674412;p=clang Driver: Switch to using explicit {getLast,has}ArgNoClaim functions instead of taking a Claim argument. - 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 --- diff --git a/include/clang/Driver/ArgList.h b/include/clang/Driver/ArgList.h index 34ca013b90..28d4648105 100644 --- a/include/clang/Driver/ArgList.h +++ b/include/clang/Driver/ArgList.h @@ -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; diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index 8d2138df85..c6c1ee60da 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -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; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index ce1ac3b756..e0cc9a7275 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -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 { diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 296e399a25..8242d31c51 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -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")); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d42751bb03..15e5f3fffd 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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)) {