From 30bf11e181b88f7da831f80bb2ce01d4af8e6502 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 7 Apr 2009 21:08:57 +0000 Subject: [PATCH] Driver: Add default for ArgList::hasFlag and simplify implementation. llvm-svn: 68549 --- clang/include/clang/Driver/ArgList.h | 2 +- clang/lib/Driver/ArgList.cpp | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Driver/ArgList.h b/clang/include/clang/Driver/ArgList.h index a0b925279cf3..7e0427d9b5dd 100644 --- a/clang/include/clang/Driver/ArgList.h +++ b/clang/include/clang/Driver/ArgList.h @@ -91,7 +91,7 @@ namespace driver { /// negation is present, and \arg Default if neither option is /// given. If both the option and its negation are present, the /// last one wins. - bool hasFlag(options::ID Pos, options::ID Neg, bool Default) const; + bool hasFlag(options::ID Pos, options::ID Neg, bool Default=true) const; /// AddLastArg - Render only the last argument match \arg Id0, if /// present. diff --git a/clang/lib/Driver/ArgList.cpp b/clang/lib/Driver/ArgList.cpp index 69cb85b7fc34..78236730248b 100644 --- a/clang/lib/Driver/ArgList.cpp +++ b/clang/lib/Driver/ArgList.cpp @@ -50,12 +50,8 @@ Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, bool Claim) const { } bool ArgList::hasFlag(options::ID Pos, options::ID Neg, bool Default) const { - Arg *PosA = getLastArg(Pos); - Arg *NegA = getLastArg(Neg); - if (PosA && NegA) - return NegA->getIndex() < PosA->getIndex(); - if (PosA) return true; - if (NegA) return false; + if (Arg *A = getLastArg(Pos, Neg)) + return A->getOption().matches(Pos); return Default; }