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.

llvm-svn: 89308
This commit is contained in:
Daniel Dunbar
2009-11-19 04:00:53 +00:00
parent beab381d2d
commit fffd18167d
5 changed files with 39 additions and 29 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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"));

View File

@@ -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)) {