diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-19 06:35:06 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-19 06:35:06 +0000 |
commit | 847abaa62883b6c20005bdd3346ebbd44e46dbac (patch) | |
tree | b27934d88fedf88d4ef1fe9395246b3ee8ae7e3a /lib/Driver/OptTable.cpp | |
parent | c720a4d6a69b33bc69729ad269c251bd32215851 (diff) |
Factor out OptTable::ParseArgs, for parsing an entire argument vector.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89327 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/OptTable.cpp')
-rw-r--r-- | lib/Driver/OptTable.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp index 890907b2a7..f68a1d8db7 100644 --- a/lib/Driver/OptTable.cpp +++ b/lib/Driver/OptTable.cpp @@ -220,3 +220,38 @@ Arg *OptTable::ParseOneArg(const InputArgList &Args, unsigned &Index) const { return new PositionalArg(TheUnknownOption, Index++); } + +InputArgList *OptTable::ParseArgs(const char **ArgBegin, const char **ArgEnd, + unsigned &MissingArgIndex, + unsigned &MissingArgCount) const { + InputArgList *Args = new InputArgList(ArgBegin, ArgEnd); + + // FIXME: Handle '@' args (or at least error on them). + + MissingArgIndex = MissingArgCount = 0; + unsigned Index = 0, End = ArgEnd - ArgBegin; + while (Index < End) { + // Ignore empty arguments (other things may still take them as arguments). + if (Args->getArgString(Index)[0] == '\0') { + ++Index; + continue; + } + + unsigned Prev = Index; + Arg *A = ParseOneArg(*Args, Index); + assert(Index > Prev && "Parser failed to consume argument."); + + // Check for missing argument error. + if (!A) { + assert(Index >= End && "Unexpected parser error."); + assert(Index - Prev - 1 && "No missing arguments!"); + MissingArgIndex = Prev; + MissingArgCount = Index - Prev - 1; + break; + } + + Args->append(A); + } + + return Args; +} |