X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FOption%2FOption.cpp;h=cdc63c353f009051d7c22faece80eca4b437cd52;hb=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;hp=5b418e845e0b8b9780ea54eba772c6afcb2dbee0;hpb=3f60fb86103f08b1d1da5f98d735fedb41f93f34;p=oota-llvm.git diff --git a/lib/Option/Option.cpp b/lib/Option/Option.cpp index 5b418e845e0..cdc63c353f0 100644 --- a/lib/Option/Option.cpp +++ b/lib/Option/Option.cpp @@ -26,6 +26,13 @@ Option::Option(const OptTable::Info *info, const OptTable *owner) // tracking, it is not an inherent limitation. assert((!Info || !getAlias().isValid() || !getAlias().getAlias().isValid()) && "Multi-level aliases are not supported."); + + if (Info && getAliasArgs()) { + assert(getAlias().isValid() && "Only alias options can have alias args."); + assert(getKind() == FlagClass && "Only Flag aliases can have alias args."); + assert(getAlias().getKind() != FlagClass && + "Cannot provide alias args to a flag option."); + } } Option::~Option() { @@ -45,13 +52,14 @@ void Option::dump() const { P(MultiArgClass); P(JoinedOrSeparateClass); P(JoinedAndSeparateClass); + P(RemainingArgsClass); #undef P } if (Info->Prefixes) { llvm::errs() << " Prefixes:["; - for (const char * const *Pre = Info->Prefixes; *Pre != 0; ++Pre) { - llvm::errs() << '"' << *Pre << (*(Pre + 1) == 0 ? "\"" : "\", "); + for (const char * const *Pre = Info->Prefixes; *Pre != nullptr; ++Pre) { + llvm::errs() << '"' << *Pre << (*(Pre + 1) == nullptr ? "\"" : "\", "); } llvm::errs() << ']'; } @@ -106,11 +114,22 @@ Arg *Option::accept(const ArgList &Args, } switch (getKind()) { - case FlagClass: + case FlagClass: { if (ArgSize != strlen(Args.getArgString(Index))) - return 0; + return nullptr; - return new Arg(UnaliasedOption, Spelling, Index++); + Arg *A = new Arg(UnaliasedOption, Spelling, Index++); + if (getAliasArgs()) { + const char *Val = getAliasArgs(); + while (*Val != '\0') { + A->getValues().push_back(Val); + + // Move past the '\0' to the next argument. + Val += strlen(Val) + 1; + } + } + return A; + } case JoinedClass: { const char *Value = Args.getArgString(Index) + ArgSize; return new Arg(UnaliasedOption, Spelling, Index++, Value); @@ -147,11 +166,12 @@ Arg *Option::accept(const ArgList &Args, // Matches iff this is an exact match. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) - return 0; + return nullptr; Index += 2; - if (Index > Args.getNumInputArgStrings()) - return 0; + if (Index > Args.getNumInputArgStrings() || + Args.getArgString(Index - 1) == nullptr) + return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 1)); @@ -159,11 +179,11 @@ Arg *Option::accept(const ArgList &Args, // Matches iff this is an exact match. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) - return 0; + return nullptr; Index += 1 + getNumArgs(); if (Index > Args.getNumInputArgStrings()) - return 0; + return nullptr; Arg *A = new Arg(UnaliasedOption, Spelling, Index - 1 - getNumArgs(), Args.getArgString(Index - getNumArgs())); @@ -181,8 +201,9 @@ Arg *Option::accept(const ArgList &Args, // Otherwise it must be separate. Index += 2; - if (Index > Args.getNumInputArgStrings()) - return 0; + if (Index > Args.getNumInputArgStrings() || + Args.getArgString(Index - 1) == nullptr) + return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 1)); @@ -190,12 +211,24 @@ Arg *Option::accept(const ArgList &Args, case JoinedAndSeparateClass: // Always matches. Index += 2; - if (Index > Args.getNumInputArgStrings()) - return 0; + if (Index > Args.getNumInputArgStrings() || + Args.getArgString(Index - 1) == nullptr) + return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 2) + ArgSize, Args.getArgString(Index - 1)); + case RemainingArgsClass: { + // Matches iff this is an exact match. + // FIXME: Avoid strlen. + if (ArgSize != strlen(Args.getArgString(Index))) + return nullptr; + Arg *A = new Arg(UnaliasedOption, Spelling, Index++); + while (Index < Args.getNumInputArgStrings() && + Args.getArgString(Index) != nullptr) + A->getValues().push_back(Args.getArgString(Index++)); + return A; + } default: llvm_unreachable("Invalid option kind!"); }