[cfe-commits] r66090 - in /cfe/trunk: include/clang/Driver/Options.h lib/Driver/OptTable.cpp
Daniel Dunbar
daniel at zuster.org
Wed Mar 4 14:41:37 PST 2009
Author: ddunbar
Date: Wed Mar 4 16:41:37 2009
New Revision: 66090
URL: http://llvm.org/viewvc/llvm-project?rev=66090&view=rev
Log:
Driver: Add OptTable::ParseOneArg.
Modified:
cfe/trunk/include/clang/Driver/Options.h
cfe/trunk/lib/Driver/OptTable.cpp
Modified: cfe/trunk/include/clang/Driver/Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.h?rev=66090&r1=66089&r2=66090&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.h (original)
+++ cfe/trunk/include/clang/Driver/Options.h Wed Mar 4 16:41:37 2009
@@ -24,6 +24,8 @@
};
}
+ class Arg;
+ class ArgList;
class Option;
/// OptTable - Provide access to the Option info table.
@@ -50,6 +52,18 @@
/// 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;
};
}
}
Modified: cfe/trunk/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/OptTable.cpp?rev=66090&r1=66089&r2=66090&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Wed Mar 4 16:41:37 2009
@@ -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 @@
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++);
+}
+
More information about the cfe-commits
mailing list