aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-07-19 18:04:57 +0000
committerReid Kleckner <reid@kleckner.net>2013-07-19 18:04:57 +0000
commiteadb765f42ddc8170eaef39b6b45b43031b0d5e7 (patch)
tree7b288f0bfcd494b58fdc2b636f8b16a4fe1035b9 /llvm/lib/Option/OptTable.cpp
parent25723ce6fce0a96e1a126502aab684e2c238f571 (diff)
downloadllvm-eadb765f42ddc8170eaef39b6b45b43031b0d5e7.zip
llvm-eadb765f42ddc8170eaef39b6b45b43031b0d5e7.tar.gz
llvm-eadb765f42ddc8170eaef39b6b45b43031b0d5e7.tar.bz2
[Option] Add inclusion and exclusion flags to option parsing
Summary: This allows the clang driver to put MSVC compatible options in the same enumerator space as its normal options but exclude them from normal option parsing. Also changes the standard ParseArgs() method to consider unknown arguments with a leading slash as being inputs rather than flags. High level discussion for clang-cl is here: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-June/030404.html CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1049 llvm-svn: 186703
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index bbb28a5..11439d3 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -180,7 +180,9 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str) {
return 0;
}
-Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
+Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
+ unsigned FlagsToInclude,
+ unsigned FlagsToExclude) const {
unsigned Prev = Index;
const char *Str = Args.getArgString(Index);
@@ -213,8 +215,15 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
if (Start == End)
break;
+ Option Opt(Start, this);
+
+ if (FlagsToInclude && !Opt.hasFlag(FlagsToInclude))
+ continue;
+ if (Opt.hasFlag(FlagsToExclude))
+ continue;
+
// See if this option matches.
- if (Arg *A = Option(Start, this).accept(Args, Index, ArgSize))
+ if (Arg *A = Opt.accept(Args, Index, ArgSize))
return A;
// Otherwise, see if this argument was missing values.
@@ -222,13 +231,20 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
return 0;
}
+ // If we failed to find an option and this arg started with /, then it's
+ // probably an input path.
+ if (Str[0] == '/')
+ return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
+
return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str);
}
-InputArgList *OptTable::ParseArgs(const char* const *ArgBegin,
- const char* const *ArgEnd,
+InputArgList *OptTable::ParseArgs(const char *const *ArgBegin,
+ const char *const *ArgEnd,
unsigned &MissingArgIndex,
- unsigned &MissingArgCount) const {
+ unsigned &MissingArgCount,
+ unsigned FlagsToInclude,
+ unsigned FlagsToExclude) const {
InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
// FIXME: Handle '@' args (or at least error on them).
@@ -243,7 +259,7 @@ InputArgList *OptTable::ParseArgs(const char* const *ArgBegin,
}
unsigned Prev = Index;
- Arg *A = ParseOneArg(*Args, Index);
+ Arg *A = ParseOneArg(*Args, Index, FlagsToInclude, FlagsToExclude);
assert(Index > Prev && "Parser failed to consume argument.");
// Check for missing argument error.