@@ -30,6 +30,18 @@ class ArgList;
3030class InputArgList ;
3131class Option ;
3232
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+
3345// / Provide access to the Option info table.
3446// /
3547// / The OptTable class provides a layer of indirection which allows Option
@@ -51,6 +63,7 @@ class OptTable {
5163 unsigned char Kind;
5264 unsigned char Param;
5365 unsigned int Flags;
66+ unsigned int Visibility;
5467 unsigned short GroupID;
5568 unsigned short AliasID;
5669 const char *AliasArgs;
@@ -180,10 +193,8 @@ class OptTable {
180193 // / string includes prefix dashes "-" as well as values "=l".
181194 // / \param [out] NearestString - The nearest option string found in the
182195 // / 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.
187198 // / \param [in] MinimumLength - Don't find options shorter than this length.
188199 // / For example, a minimum length of 3 prevents "-x" from being considered
189200 // / near to "-S".
@@ -192,13 +203,29 @@ class OptTable {
192203 // /
193204 // / \return The edit distance of the nearest string found.
194205 unsigned findNearest (StringRef Option, std::string &NearestString,
195- unsigned FlagsToInclude = 0 , unsigned FlagsToExclude = 0 ,
206+ Visibility VisibilityMask = Visibility() ,
196207 unsigned MinimumLength = 4,
197208 unsigned MaximumDistance = UINT_MAX) const ;
198209
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+
199227 bool findExact (StringRef Option, std::string &ExactString,
200- unsigned FlagsToInclude = 0 ,
201- unsigned FlagsToExclude = 0 ) const {
228+ unsigned FlagsToInclude, unsigned FlagsToExclude = 0 ) const {
202229 return findNearest (Option, ExactString, FlagsToInclude, FlagsToExclude, 4 ,
203230 0 ) == 0 ;
204231 }
@@ -209,18 +236,26 @@ class OptTable {
209236 // / \param [in,out] Index - The current parsing position in the argument
210237 // / string list; on return this will be the index of the next argument
211238 // / 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.
216241 // /
217242 // / \return The parsed argument, or 0 if the argument is missing values
218243 // / (in which case Index still points at the conceptual next argument string
219244 // / to parse).
245+ std::unique_ptr<Arg>
246+ ParseOneArg (const ArgList &Args, unsigned &Index,
247+ Visibility VisibilityMask = Visibility()) const ;
248+
220249 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 ;
223257
258+ public:
224259 // / Parse an list of arguments into an InputArgList.
225260 // /
226261 // / The resulting InputArgList will reference the strings in [\p ArgBegin,
@@ -233,16 +268,25 @@ class OptTable {
233268 // / \param MissingArgIndex - On error, the index of the option which could
234269 // / not be parsed.
235270 // / \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.
240273 // / \return An InputArgList; on error this will contain all the options
241274 // / which could be parsed.
242275 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,
244281 unsigned FlagsToExclude = 0 ) const ;
245282
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:
246290 // / A convenience helper which handles optional initial options populated from
247291 // / an environment variable, expands response files recursively and parses
248292 // / options.
@@ -253,26 +297,32 @@ class OptTable {
253297 // / could be parsed.
254298 InputArgList parseArgs (int Argc, char *const *Argv, OptSpecifier Unknown,
255299 StringSaver &Saver,
256- function_ref <void (StringRef)> ErrorFn) const ;
300+ std::function <void (StringRef)> ErrorFn) const ;
257301
258302 // / Render the help text for an option table.
259303 // /
260304 // / \param OS - The stream to write the help text to.
261305 // / \param Usage - USAGE: Usage
262306 // / \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
266310 // / \param ShowAllAliases - If true, display all options including aliases
267311 // / that don't have help texts. By default, we display
268312 // / only options that are not hidden and have help
269313 // / 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+
270318 void printHelp (raw_ostream &OS, const char *Usage, const char *Title,
271319 unsigned FlagsToInclude, unsigned FlagsToExclude,
272320 bool ShowAllAliases) const ;
273321
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 ;
276326};
277327
278328// / Specialization of OptTable
@@ -305,31 +355,32 @@ class PrecomputedOptTable : public OptTable {
305355
306356} // end namespace llvm
307357
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) \
311361 ID_PREFIX##ID
312362
313363#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) \
315366 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)
318369
319370#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX ( \
320371 ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
321- FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \
372+ FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
322373 llvm::opt::OptTable::Info { \
323374 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 \
326377 }
327378
328379#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)
334385
335386#endif // LLVM_OPTION_OPTTABLE_H
0 commit comments