llvm.org GIT mirror llvm / a2549d3
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186703 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 7 years ago
2 changed file(s) with 36 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
115115 /// \param [in,out] Index - The current parsing position in the argument
116116 /// string list; on return this will be the index of the next argument
117117 /// string to parse.
118 /// \param [in] FlagsToInclude - Only parse options with any of these flags.
119 /// Zero is the default which includes all flags.
120 /// \param [in] FlagsToExclude - Don't parse options with this flag. Zero
121 /// is the default and means exclude nothing.
118122 ///
119123 /// \return The parsed argument, or 0 if the argument is missing values
120124 /// (in which case Index still points at the conceptual next argument string
121125 /// to parse).
122 Arg *ParseOneArg(const ArgList &Args, unsigned &Index) const;
126 Arg *ParseOneArg(const ArgList &Args, unsigned &Index,
127 unsigned FlagsToInclude = 0,
128 unsigned FlagsToExclude = 0) const;
123129
124130 /// \brief Parse an list of arguments into an InputArgList.
125131 ///
135141 /// \param MissingArgIndex - On error, the index of the option which could
136142 /// not be parsed.
137143 /// \param MissingArgCount - On error, the number of missing options.
144 /// \param FlagsToInclude - Only parse options with any of these flags.
145 /// Zero is the default which includes all flags.
146 /// \param FlagsToExclude - Don't parse options with this flag. Zero
147 /// is the default and means exclude nothing.
138148 /// \return An InputArgList; on error this will contain all the options
139149 /// which could be parsed.
140150 InputArgList *ParseArgs(const char* const *ArgBegin,
141151 const char* const *ArgEnd,
142152 unsigned &MissingArgIndex,
143 unsigned &MissingArgCount) const;
153 unsigned &MissingArgCount,
154 unsigned FlagsToInclude = 0,
155 unsigned FlagsToExclude = 0) const;
144156
145157 /// \brief Render the help text for an option table.
146158 ///
179179 return 0;
180180 }
181181
182 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
182 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
183 unsigned FlagsToInclude,
184 unsigned FlagsToExclude) const {
183185 unsigned Prev = Index;
184186 const char *Str = Args.getArgString(Index);
185187
212214 if (Start == End)
213215 break;
214216
217 Option Opt(Start, this);
218
219 if (FlagsToInclude && !Opt.hasFlag(FlagsToInclude))
220 continue;
221 if (Opt.hasFlag(FlagsToExclude))
222 continue;
223
215224 // See if this option matches.
216 if (Arg *A = Option(Start, this).accept(Args, Index, ArgSize))
225 if (Arg *A = Opt.accept(Args, Index, ArgSize))
217226 return A;
218227
219228 // Otherwise, see if this argument was missing values.
221230 return 0;
222231 }
223232
233 // If we failed to find an option and this arg started with /, then it's
234 // probably an input path.
235 if (Str[0] == '/')
236 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
237
224238 return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str);
225239 }
226240
227 InputArgList *OptTable::ParseArgs(const char* const *ArgBegin,
228 const char* const *ArgEnd,
241 InputArgList *OptTable::ParseArgs(const char *const *ArgBegin,
242 const char *const *ArgEnd,
229243 unsigned &MissingArgIndex,
230 unsigned &MissingArgCount) const {
244 unsigned &MissingArgCount,
245 unsigned FlagsToInclude,
246 unsigned FlagsToExclude) const {
231247 InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
232248
233249 // FIXME: Handle '@' args (or at least error on them).
242258 }
243259
244260 unsigned Prev = Index;
245 Arg *A = ParseOneArg(*Args, Index);
261 Arg *A = ParseOneArg(*Args, Index, FlagsToInclude, FlagsToExclude);
246262 assert(Index > Prev && "Parser failed to consume argument.");
247263
248264 // Check for missing argument error.