@@ -30,6 +30,18 @@ class ArgList;
30
30
class InputArgList ;
31
31
class Option ;
32
32
33
+ // / Helper for overload resolution while transitioning from
34
+ // / FlagsToInclude/FlagsToExclude APIs to VisibilityMask APIs.
35
+ class Visibility {
36
+ unsigned Mask = ~0U ;
37
+
38
+ public:
39
+ explicit Visibility (unsigned Mask) : Mask(Mask) {}
40
+ Visibility () = default ;
41
+
42
+ operator unsigned () const { return Mask; }
43
+ };
44
+
33
45
// / Provide access to the Option info table.
34
46
// /
35
47
// / The OptTable class provides a layer of indirection which allows Option
@@ -51,6 +63,7 @@ class OptTable {
51
63
unsigned char Kind;
52
64
unsigned char Param;
53
65
unsigned int Flags;
66
+ unsigned int Visibility;
54
67
unsigned short GroupID;
55
68
unsigned short AliasID;
56
69
const char *AliasArgs;
@@ -180,10 +193,8 @@ class OptTable {
180
193
// / string includes prefix dashes "-" as well as values "=l".
181
194
// / \param [out] NearestString - The nearest option string found in the
182
195
// / OptTable.
183
- // / \param [in] FlagsToInclude - Only find options with any of these flags.
184
- // / Zero is the default, which includes all flags.
185
- // / \param [in] FlagsToExclude - Don't find options with this flag. Zero
186
- // / is the default, and means exclude nothing.
196
+ // / \param [in] VisibilityMask - Only include options with any of these
197
+ // / visibility flags set.
187
198
// / \param [in] MinimumLength - Don't find options shorter than this length.
188
199
// / For example, a minimum length of 3 prevents "-x" from being considered
189
200
// / near to "-S".
@@ -192,13 +203,29 @@ class OptTable {
192
203
// /
193
204
// / \return The edit distance of the nearest string found.
194
205
unsigned findNearest (StringRef Option, std::string &NearestString,
195
- unsigned FlagsToInclude = 0 , unsigned FlagsToExclude = 0 ,
206
+ Visibility VisibilityMask = Visibility() ,
196
207
unsigned MinimumLength = 4,
197
208
unsigned MaximumDistance = UINT_MAX) const ;
198
209
210
+ unsigned findNearest (StringRef Option, std::string &NearestString,
211
+ unsigned FlagsToInclude, unsigned FlagsToExclude = 0 ,
212
+ unsigned MinimumLength = 4 ,
213
+ unsigned MaximumDistance = UINT_MAX) const ;
214
+
215
+ private:
216
+ unsigned
217
+ internalFindNearest (StringRef Option, std::string &NearestString,
218
+ unsigned MinimumLength, unsigned MaximumDistance,
219
+ std::function<bool (const Info &)> ExcludeOption) const ;
220
+
221
+ public:
222
+ bool findExact (StringRef Option, std::string &ExactString,
223
+ Visibility VisibilityMask = Visibility()) const {
224
+ return findNearest (Option, ExactString, VisibilityMask, 4 , 0 ) == 0 ;
225
+ }
226
+
199
227
bool findExact (StringRef Option, std::string &ExactString,
200
- unsigned FlagsToInclude = 0 ,
201
- unsigned FlagsToExclude = 0 ) const {
228
+ unsigned FlagsToInclude, unsigned FlagsToExclude = 0 ) const {
202
229
return findNearest (Option, ExactString, FlagsToInclude, FlagsToExclude, 4 ,
203
230
0 ) == 0 ;
204
231
}
@@ -209,18 +236,26 @@ class OptTable {
209
236
// / \param [in,out] Index - The current parsing position in the argument
210
237
// / string list; on return this will be the index of the next argument
211
238
// / string to parse.
212
- // / \param [in] FlagsToInclude - Only parse options with any of these flags.
213
- // / Zero is the default which includes all flags.
214
- // / \param [in] FlagsToExclude - Don't parse options with this flag. Zero
215
- // / is the default and means exclude nothing.
239
+ // / \param [in] VisibilityMask - Only include options with any of these
240
+ // / visibility flags set.
216
241
// /
217
242
// / \return The parsed argument, or 0 if the argument is missing values
218
243
// / (in which case Index still points at the conceptual next argument string
219
244
// / to parse).
245
+ std::unique_ptr<Arg>
246
+ ParseOneArg (const ArgList &Args, unsigned &Index,
247
+ Visibility VisibilityMask = Visibility()) const ;
248
+
220
249
std::unique_ptr<Arg> ParseOneArg (const ArgList &Args, unsigned &Index,
221
- unsigned FlagsToInclude = 0 ,
222
- unsigned FlagsToExclude = 0 ) const ;
250
+ unsigned FlagsToInclude,
251
+ unsigned FlagsToExclude) const ;
252
+
253
+ private:
254
+ std::unique_ptr<Arg>
255
+ internalParseOneArg (const ArgList &Args, unsigned &Index,
256
+ std::function<bool (const Option &)> ExcludeOption) const ;
223
257
258
+ public:
224
259
// / Parse an list of arguments into an InputArgList.
225
260
// /
226
261
// / The resulting InputArgList will reference the strings in [\p ArgBegin,
@@ -233,16 +268,25 @@ class OptTable {
233
268
// / \param MissingArgIndex - On error, the index of the option which could
234
269
// / not be parsed.
235
270
// / \param MissingArgCount - On error, the number of missing options.
236
- // / \param FlagsToInclude - Only parse options with any of these flags.
237
- // / Zero is the default which includes all flags.
238
- // / \param FlagsToExclude - Don't parse options with this flag. Zero
239
- // / is the default and means exclude nothing.
271
+ // / \param VisibilityMask - Only include options with any of these
272
+ // / visibility flags set.
240
273
// / \return An InputArgList; on error this will contain all the options
241
274
// / which could be parsed.
242
275
InputArgList ParseArgs (ArrayRef<const char *> Args, unsigned &MissingArgIndex,
243
- unsigned &MissingArgCount, unsigned FlagsToInclude = 0 ,
276
+ unsigned &MissingArgCount,
277
+ Visibility VisibilityMask = Visibility()) const ;
278
+
279
+ InputArgList ParseArgs (ArrayRef<const char *> Args, unsigned &MissingArgIndex,
280
+ unsigned &MissingArgCount, unsigned FlagsToInclude,
244
281
unsigned FlagsToExclude = 0 ) const ;
245
282
283
+ private:
284
+ InputArgList
285
+ internalParseArgs (ArrayRef<const char *> Args, unsigned &MissingArgIndex,
286
+ unsigned &MissingArgCount,
287
+ std::function<bool (const Option &)> ExcludeOption) const ;
288
+
289
+ public:
246
290
// / A convenience helper which handles optional initial options populated from
247
291
// / an environment variable, expands response files recursively and parses
248
292
// / options.
@@ -253,26 +297,32 @@ class OptTable {
253
297
// / could be parsed.
254
298
InputArgList parseArgs (int Argc, char *const *Argv, OptSpecifier Unknown,
255
299
StringSaver &Saver,
256
- function_ref <void (StringRef)> ErrorFn) const ;
300
+ std::function <void (StringRef)> ErrorFn) const ;
257
301
258
302
// / Render the help text for an option table.
259
303
// /
260
304
// / \param OS - The stream to write the help text to.
261
305
// / \param Usage - USAGE: Usage
262
306
// / \param Title - OVERVIEW: Title
263
- // / \param FlagsToInclude - If non-zero, only include options with any
264
- // / of these flags set.
265
- // / \param FlagsToExclude - Exclude options with any of these flags set.
307
+ // / \param VisibilityMask - Only in Visibility VisibilityMask,clude options with any of these
308
+ // / visibility flags set.
309
+ // / \param ShowHidden - If true, display options marked as HelpHidden
266
310
// / \param ShowAllAliases - If true, display all options including aliases
267
311
// / that don't have help texts. By default, we display
268
312
// / only options that are not hidden and have help
269
313
// / texts.
314
+ void printHelp (raw_ostream &OS, const char *Usage, const char *Title,
315
+ bool ShowHidden = false , bool ShowAllAliases = false ,
316
+ Visibility VisibilityMask = Visibility()) const ;
317
+
270
318
void printHelp (raw_ostream &OS, const char *Usage, const char *Title,
271
319
unsigned FlagsToInclude, unsigned FlagsToExclude,
272
320
bool ShowAllAliases) const ;
273
321
274
- void printHelp (raw_ostream &OS, const char *Usage, const char *Title,
275
- bool ShowHidden = false , bool ShowAllAliases = false ) const ;
322
+ private:
323
+ void internalPrintHelp (raw_ostream &OS, const char *Usage, const char *Title,
324
+ bool ShowHidden, bool ShowAllAliases,
325
+ std::function<bool (const Info &)> ExcludeOption) const ;
276
326
};
277
327
278
328
// / Specialization of OptTable
@@ -305,31 +355,32 @@ class PrecomputedOptTable : public OptTable {
305
355
306
356
} // end namespace llvm
307
357
308
- #define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX (ID_PREFIX, PREFIX, PREFIXED_NAME, ID, \
309
- KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
310
- PARAM, HELPTEXT, METAVAR, VALUES) \
358
+ #define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX ( \
359
+ ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
360
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
311
361
ID_PREFIX##ID
312
362
313
363
#define LLVM_MAKE_OPT_ID (PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
314
- ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \
364
+ ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
365
+ METAVAR, VALUES) \
315
366
LLVM_MAKE_OPT_ID_WITH_ID_PREFIX (OPT_, PREFIX, PREFIXED_NAME, ID, KIND, \
316
- GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
317
- HELPTEXT, METAVAR, VALUE)
367
+ GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, \
368
+ PARAM, HELPTEXT, METAVAR, VALUE)
318
369
319
370
#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX ( \
320
371
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
321
- FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \
372
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
322
373
llvm::opt::OptTable::Info { \
323
374
PREFIX, PREFIXED_NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \
324
- llvm::opt::Option::KIND##Class, PARAM, FLAGS, ID_PREFIX##GROUP, \
325
- ID_PREFIX##ALIAS, ALIASARGS, VALUES \
375
+ llvm::opt::Option::KIND##Class, PARAM, FLAGS, VISIBILITY, \
376
+ ID_PREFIX##GROUP, ID_PREFIX## ALIAS, ALIASARGS, VALUES \
326
377
}
327
378
328
379
#define LLVM_CONSTRUCT_OPT_INFO (PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
329
- ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, \
330
- VALUES) \
331
- LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX (OPT_, PREFIX, PREFIXED_NAME, ID, \
332
- KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
333
- PARAM, HELPTEXT, METAVAR, VALUES)
380
+ ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
381
+ METAVAR, VALUES) \
382
+ LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX ( \
383
+ OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
384
+ VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES)
334
385
335
386
#endif // LLVM_OPTION_OPTTABLE_H
0 commit comments