aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-04 22:41:37 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-04 22:41:37 +0000
commit70a0dbbfbd933c80722549fef2d56de85c32d752 (patch)
treed67e3ac82f31c09255aae540da4ba273b2aecfb2
parent9358dc8d1edae6f9279647084e768c6da5715f73 (diff)
Driver: Add OptTable::ParseOneArg.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66090 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/Options.h14
-rw-r--r--lib/Driver/OptTable.cpp23
2 files changed, 37 insertions, 0 deletions
diff --git a/include/clang/Driver/Options.h b/include/clang/Driver/Options.h
index d98a530bbf..f83e5ceace 100644
--- a/include/clang/Driver/Options.h
+++ b/include/clang/Driver/Options.h
@@ -24,6 +24,8 @@ namespace options {
};
}
+ class Arg;
+ class ArgList;
class Option;
/// OptTable - Provide access to the Option info table.
@@ -50,6 +52,18 @@ namespace options {
/// getOption - Get the given \arg id's Option instance, lazily
/// creating it if necessary.
const Option *getOption(options::ID id) const;
+
+ /// parseOneArg - Parse a single argument; returning the new
+ /// argument and updating Index.
+ ///
+ /// \param [in] [out] Index - The current parsing position in the
+ /// argument string list; on return this will be the index of the
+ /// next option to parse.
+ ///
+ /// \param IndexEnd - The last argument string index to consider
+ /// when parsing.
+ Arg *ParseOneArg(const ArgList &Args, unsigned &Index,
+ unsigned IndexEnd) const;
};
}
}
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp
index 070c12e154..284e3ba1e2 100644
--- a/lib/Driver/OptTable.cpp
+++ b/lib/Driver/OptTable.cpp
@@ -9,6 +9,8 @@
#include "clang/Driver/Options.h"
+#include "clang/Driver/Arg.h"
+#include "clang/Driver/ArgList.h"
#include "clang/Driver/Option.h"
#include <cassert>
@@ -115,3 +117,24 @@ Option *OptTable::constructOption(options::ID id) const {
return Opt;
}
+
+Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
+ unsigned IndexEnd) const {
+ const char *Str = Args.getArgString(Index);
+
+ // Anything that doesn't start with '-' is an input.
+ if (Str[0] != '-')
+ return new PositionalArg(getOption(InputOpt), Index++);
+
+ for (unsigned j = UnknownOpt + 1; j < getNumOptions(); ++j) {
+ const char *OptName = getOptionName((options::ID) (j + 1));
+
+ // Arguments are only accepted by options which prefix them.
+ if (memcmp(Str, OptName, strlen(OptName)) == 0)
+ if (Arg *A = getOption((options::ID) (j + 1))->accept(Args, Index))
+ return A;
+ }
+
+ return new PositionalArg(getOption(UnknownOpt), Index++);
+}
+