LLVM 18.0.0git
CommandLine.h
Go to the documentation of this file.
1//===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This class implements a command line argument processor that is useful when
10// creating a tool. It provides a simple, minimalistic interface that is easily
11// extensible and supports nonlocal (library) command line options.
12//
13// Note that rather than trying to figure out what this code does, you should
14// read the library documentation located in docs/CommandLine.html or looks at
15// the many example usages in tools/*/*.cpp
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_SUPPORT_COMMANDLINE_H
20#define LLVM_SUPPORT_COMMANDLINE_H
21
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/STLExtras.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/Twine.h"
34#include <cassert>
35#include <climits>
36#include <cstddef>
37#include <functional>
38#include <initializer_list>
39#include <string>
40#include <type_traits>
41#include <vector>
42
43namespace llvm {
44
45namespace vfs {
46class FileSystem;
47}
48
49class StringSaver;
50
51/// This namespace contains all of the command line option processing machinery.
52/// It is intentionally a short name to make qualified usage concise.
53namespace cl {
54
55//===----------------------------------------------------------------------===//
56// Command line option processing entry point.
57//
58// Returns true on success. Otherwise, this will print the error message to
59// stderr and exit if \p Errs is not set (nullptr by default), or print the
60// error message to \p Errs and return false if \p Errs is provided.
61//
62// If EnvVar is not nullptr, command-line options are also parsed from the
63// environment variable named by EnvVar. Precedence is given to occurrences
64// from argv. This precedence is currently implemented by parsing argv after
65// the environment variable, so it is only implemented correctly for options
66// that give precedence to later occurrences. If your program supports options
67// that give precedence to earlier occurrences, you will need to extend this
68// function to support it correctly.
69bool ParseCommandLineOptions(int argc, const char *const *argv,
70 StringRef Overview = "",
71 raw_ostream *Errs = nullptr,
72 const char *EnvVar = nullptr,
73 bool LongOptionsUseDoubleDash = false);
74
75// Function pointer type for printing version information.
76using VersionPrinterTy = std::function<void(raw_ostream &)>;
77
78///===---------------------------------------------------------------------===//
79/// Override the default (LLVM specific) version printer used to print out the
80/// version when --version is given on the command line. This allows other
81/// systems using the CommandLine utilities to print their own version string.
83
84///===---------------------------------------------------------------------===//
85/// Add an extra printer to use in addition to the default one. This can be
86/// called multiple times, and each time it adds a new function to the list
87/// which will be called after the basic LLVM version printing is complete.
88/// Each can then add additional information specific to the tool.
90
91// Print option values.
92// With -print-options print the difference between option values and defaults.
93// With -print-all-options print all option values.
94// (Currently not perfect, but best-effort.)
96
97// Forward declaration - AddLiteralOption needs to be up here to make gcc happy.
98class Option;
99
100/// Adds a new option for parsing and provides the option it refers to.
101///
102/// \param O pointer to the option
103/// \param Name the string name for the option to handle during parsing
104///
105/// Literal options are used by some parsers to register special option values.
106/// This is how the PassNameParser registers pass names for opt.
108
109//===----------------------------------------------------------------------===//
110// Flags permitted to be passed to command line arguments
111//
112
113enum NumOccurrencesFlag { // Flags for the number of occurrences allowed
114 Optional = 0x00, // Zero or One occurrence
115 ZeroOrMore = 0x01, // Zero or more occurrences allowed
116 Required = 0x02, // One occurrence required
117 OneOrMore = 0x03, // One or more occurrences required
118
119 // Indicates that this option is fed anything that follows the last positional
120 // argument required by the application (it is an error if there are zero
121 // positional arguments, and a ConsumeAfter option is used).
122 // Thus, for example, all arguments to LLI are processed until a filename is
123 // found. Once a filename is found, all of the succeeding arguments are
124 // passed, unprocessed, to the ConsumeAfter option.
125 //
126 ConsumeAfter = 0x04
128
129enum ValueExpected { // Is a value required for the option?
130 // zero reserved for the unspecified value
131 ValueOptional = 0x01, // The value can appear... or not
132 ValueRequired = 0x02, // The value is required to appear!
133 ValueDisallowed = 0x03 // A value may not be specified (for flags)
135
136enum OptionHidden { // Control whether -help shows this option
137 NotHidden = 0x00, // Option included in -help & -help-hidden
138 Hidden = 0x01, // -help doesn't, but -help-hidden does
139 ReallyHidden = 0x02 // Neither -help nor -help-hidden show this arg
141
142// This controls special features that the option might have that cause it to be
143// parsed differently...
144//
145// Prefix - This option allows arguments that are otherwise unrecognized to be
146// matched by options that are a prefix of the actual value. This is useful for
147// cases like a linker, where options are typically of the form '-lfoo' or
148// '-L../../include' where -l or -L are the actual flags. When prefix is
149// enabled, and used, the value for the flag comes from the suffix of the
150// argument.
151//
152// AlwaysPrefix - Only allow the behavior enabled by the Prefix flag and reject
153// the Option=Value form.
154//
155
157 NormalFormatting = 0x00, // Nothing special
158 Positional = 0x01, // Is a positional argument, no '-' required
159 Prefix = 0x02, // Can this option directly prefix its value?
160 AlwaysPrefix = 0x03 // Can this option only directly prefix its value?
162
163enum MiscFlags { // Miscellaneous flags to adjust argument
164 CommaSeparated = 0x01, // Should this cl::list split between commas?
165 PositionalEatsArgs = 0x02, // Should this positional cl::list eat -args?
166 Sink = 0x04, // Should this cl::list eat all unknown options?
167
168 // Can this option group with other options?
169 // If this is enabled, multiple letter options are allowed to bunch together
170 // with only a single hyphen for the whole group. This allows emulation
171 // of the behavior that ls uses for example: ls -la === ls -l -a
172 Grouping = 0x08,
173
174 // Default option
175 DefaultOption = 0x10
177
178//===----------------------------------------------------------------------===//
179//
181private:
182 StringRef const Name;
183 StringRef const Description;
184
185 void registerCategory();
186
187public:
189 StringRef const Description = "")
190 : Name(Name), Description(Description) {
191 registerCategory();
192 }
193
194 StringRef getName() const { return Name; }
195 StringRef getDescription() const { return Description; }
196};
197
198// The general Option Category (used as default category).
199OptionCategory &getGeneralCategory();
200
201//===----------------------------------------------------------------------===//
202//
204private:
205 StringRef Name;
206 StringRef Description;
207
208protected:
209 void registerSubCommand();
211
212public:
213 SubCommand(StringRef Name, StringRef Description = "")
214 : Name(Name), Description(Description) {
216 }
217 SubCommand() = default;
218
219 // Get the special subcommand representing no subcommand.
220 static SubCommand &getTopLevel();
221
222 // Get the special subcommand that can be used to put an option into all
223 // subcommands.
224 static SubCommand &getAll();
225
226 void reset();
227
228 explicit operator bool() const;
229
230 StringRef getName() const { return Name; }
231 StringRef getDescription() const { return Description; }
232
236
237 Option *ConsumeAfterOpt = nullptr; // The ConsumeAfter option if it exists.
238};
239
240// A special subcommand representing no subcommand
242
243// A special subcommand that can be used to put an option into all subcommands.
245
246//===----------------------------------------------------------------------===//
247//
248class Option {
249 friend class alias;
250
251 // Overriden by subclasses to handle the value passed into an argument. Should
252 // return true if there was an error processing the argument and the program
253 // should exit.
254 //
255 virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
256 StringRef Arg) = 0;
257
258 virtual enum ValueExpected getValueExpectedFlagDefault() const {
259 return ValueOptional;
260 }
261
262 // Out of line virtual function to provide home for the class.
263 virtual void anchor();
264
265 uint16_t NumOccurrences; // The number of times specified
266 // Occurrences, HiddenFlag, and Formatting are all enum types but to avoid
267 // problems with signed enums in bitfields.
268 uint16_t Occurrences : 3; // enum NumOccurrencesFlag
269 // not using the enum type for 'Value' because zero is an implementation
270 // detail representing the non-value
271 uint16_t Value : 2;
272 uint16_t HiddenFlag : 2; // enum OptionHidden
273 uint16_t Formatting : 2; // enum FormattingFlags
274 uint16_t Misc : 5;
275 uint16_t FullyInitialized : 1; // Has addArgument been called?
276 uint16_t Position; // Position of last occurrence of the option
277 uint16_t AdditionalVals; // Greater than 0 for multi-valued option.
278
279public:
280 StringRef ArgStr; // The argument string itself (ex: "help", "o")
281 StringRef HelpStr; // The descriptive text message for -help
282 StringRef ValueStr; // String describing what the value of this option is
284 Categories; // The Categories this option belongs to
285 SmallPtrSet<SubCommand *, 1> Subs; // The subcommands this option belongs to.
286
288 return (enum NumOccurrencesFlag)Occurrences;
289 }
290
292 return Value ? ((enum ValueExpected)Value) : getValueExpectedFlagDefault();
293 }
294
295 inline enum OptionHidden getOptionHiddenFlag() const {
296 return (enum OptionHidden)HiddenFlag;
297 }
298
299 inline enum FormattingFlags getFormattingFlag() const {
300 return (enum FormattingFlags)Formatting;
301 }
302
303 inline unsigned getMiscFlags() const { return Misc; }
304 inline unsigned getPosition() const { return Position; }
305 inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
306
307 // Return true if the argstr != ""
308 bool hasArgStr() const { return !ArgStr.empty(); }
309 bool isPositional() const { return getFormattingFlag() == cl::Positional; }
310 bool isSink() const { return getMiscFlags() & cl::Sink; }
311 bool isDefaultOption() const { return getMiscFlags() & cl::DefaultOption; }
312
313 bool isConsumeAfter() const {
315 }
316
317 bool isInAllSubCommands() const {
318 return Subs.contains(&SubCommand::getAll());
319 }
320
321 //-------------------------------------------------------------------------===
322 // Accessor functions set by OptionModifiers
323 //
324 void setArgStr(StringRef S);
327 void setNumOccurrencesFlag(enum NumOccurrencesFlag Val) { Occurrences = Val; }
328 void setValueExpectedFlag(enum ValueExpected Val) { Value = Val; }
329 void setHiddenFlag(enum OptionHidden Val) { HiddenFlag = Val; }
330 void setFormattingFlag(enum FormattingFlags V) { Formatting = V; }
331 void setMiscFlag(enum MiscFlags M) { Misc |= M; }
332 void setPosition(unsigned pos) { Position = pos; }
334 void addSubCommand(SubCommand &S) { Subs.insert(&S); }
335
336protected:
337 explicit Option(enum NumOccurrencesFlag OccurrencesFlag,
338 enum OptionHidden Hidden)
339 : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
340 HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0),
341 FullyInitialized(false), Position(0), AdditionalVals(0) {
342 Categories.push_back(&getGeneralCategory());
343 }
344
345 inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
346
347public:
348 virtual ~Option() = default;
349
350 // Register this argument with the commandline system.
351 //
352 void addArgument();
353
354 /// Unregisters this option from the CommandLine system.
355 ///
356 /// This option must have been the last option registered.
357 /// For testing purposes only.
358 void removeArgument();
359
360 // Return the width of the option tag for printing...
361 virtual size_t getOptionWidth() const = 0;
362
363 // Print out information about this option. The to-be-maintained width is
364 // specified.
365 //
366 virtual void printOptionInfo(size_t GlobalWidth) const = 0;
367
368 virtual void printOptionValue(size_t GlobalWidth, bool Force) const = 0;
369
370 virtual void setDefault() = 0;
371
372 // Prints the help string for an option.
373 //
374 // This maintains the Indent for multi-line descriptions.
375 // FirstLineIndentedBy is the count of chars of the first line
376 // i.e. the one containing the --<option name>.
377 static void printHelpStr(StringRef HelpStr, size_t Indent,
378 size_t FirstLineIndentedBy);
379
380 // Prints the help string for an enum value.
381 //
382 // This maintains the Indent for multi-line descriptions.
383 // FirstLineIndentedBy is the count of chars of the first line
384 // i.e. the one containing the =<value>.
385 static void printEnumValHelpStr(StringRef HelpStr, size_t Indent,
386 size_t FirstLineIndentedBy);
387
389
390 // Wrapper around handleOccurrence that enforces Flags.
391 //
392 virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
393 bool MultiArg = false);
394
395 // Prints option name followed by message. Always returns true.
396 bool error(const Twine &Message, StringRef ArgName = StringRef(), raw_ostream &Errs = llvm::errs());
397 bool error(const Twine &Message, raw_ostream &Errs) {
398 return error(Message, StringRef(), Errs);
399 }
400
401 inline int getNumOccurrences() const { return NumOccurrences; }
402 void reset();
403};
404
405//===----------------------------------------------------------------------===//
406// Command line option modifiers that can be used to modify the behavior of
407// command line option parsers...
408//
409
410// Modifier to set the description shown in the -help output...
411struct desc {
413
414 desc(StringRef Str) : Desc(Str) {}
415
416 void apply(Option &O) const { O.setDescription(Desc); }
417};
418
419// Modifier to set the value description shown in the -help output...
422
423 value_desc(StringRef Str) : Desc(Str) {}
424
425 void apply(Option &O) const { O.setValueStr(Desc); }
426};
427
428// Specify a default (initial) value for the command line argument, if the
429// default constructor for the argument type does not give you what you want.
430// This is only valid on "opt" arguments, not on "list" arguments.
431template <class Ty> struct initializer {
432 const Ty &Init;
433 initializer(const Ty &Val) : Init(Val) {}
434
435 template <class Opt> void apply(Opt &O) const { O.setInitialValue(Init); }
436};
437
438template <class Ty> struct list_initializer {
441
442 template <class Opt> void apply(Opt &O) const { O.setInitialValues(Inits); }
443};
444
445template <class Ty> initializer<Ty> init(const Ty &Val) {
446 return initializer<Ty>(Val);
447}
448
449template <class Ty>
451 return list_initializer<Ty>(Vals);
452}
453
454// Allow the user to specify which external variable they want to store the
455// results of the command line argument processing into, if they don't want to
456// store it in the option itself.
457template <class Ty> struct LocationClass {
458 Ty &Loc;
459
460 LocationClass(Ty &L) : Loc(L) {}
461
462 template <class Opt> void apply(Opt &O) const { O.setLocation(O, Loc); }
463};
464
465template <class Ty> LocationClass<Ty> location(Ty &L) {
466 return LocationClass<Ty>(L);
467}
468
469// Specify the Option category for the command line argument to belong to.
470struct cat {
472
474
475 template <class Opt> void apply(Opt &O) const { O.addCategory(Category); }
476};
477
478// Specify the subcommand that this option belongs to.
479struct sub {
481
482 sub(SubCommand &S) : Sub(S) {}
483
484 template <class Opt> void apply(Opt &O) const { O.addSubCommand(Sub); }
485};
486
487// Specify a callback function to be called when an option is seen.
488// Can be used to set other options automatically.
489template <typename R, typename Ty> struct cb {
490 std::function<R(Ty)> CB;
491
492 cb(std::function<R(Ty)> CB) : CB(CB) {}
493
494 template <typename Opt> void apply(Opt &O) const { O.setCallback(CB); }
495};
496
497namespace detail {
498template <typename F>
499struct callback_traits : public callback_traits<decltype(&F::operator())> {};
500
501template <typename R, typename C, typename... Args>
502struct callback_traits<R (C::*)(Args...) const> {
503 using result_type = R;
504 using arg_type = std::tuple_element_t<0, std::tuple<Args...>>;
505 static_assert(sizeof...(Args) == 1, "callback function must have one and only one parameter");
506 static_assert(std::is_same_v<result_type, void>,
507 "callback return type must be void");
508 static_assert(std::is_lvalue_reference_v<arg_type> &&
509 std::is_const_v<std::remove_reference_t<arg_type>>,
510 "callback arg_type must be a const lvalue reference");
511};
512} // namespace detail
513
514template <typename F>
518 using result_type = typename detail::callback_traits<F>::result_type;
519 using arg_type = typename detail::callback_traits<F>::arg_type;
520 return cb<result_type, arg_type>(CB);
521}
522
523//===----------------------------------------------------------------------===//
524
525// Support value comparison outside the template.
527 virtual bool compare(const GenericOptionValue &V) const = 0;
528
529protected:
534
535private:
536 virtual void anchor();
537};
538
539template <class DataType> struct OptionValue;
540
541// The default value safely does nothing. Option value printing is only
542// best-effort.
543template <class DataType, bool isClass>
545 // Temporary storage for argument passing.
547
548 bool hasValue() const { return false; }
549
550 const DataType &getValue() const { llvm_unreachable("no default value"); }
551
552 // Some options may take their value from a different data type.
553 template <class DT> void setValue(const DT & /*V*/) {}
554
555 // Returns whether this instance matches the argument.
556 bool compare(const DataType & /*V*/) const { return false; }
557
558 bool compare(const GenericOptionValue & /*V*/) const override {
559 return false;
560 }
561
562protected:
563 ~OptionValueBase() = default;
564};
565
566// Simple copy of the option value.
567template <class DataType> class OptionValueCopy : public GenericOptionValue {
568 DataType Value;
569 bool Valid = false;
570
571protected:
574 ~OptionValueCopy() = default;
575
576public:
577 OptionValueCopy() = default;
578
579 bool hasValue() const { return Valid; }
580
581 const DataType &getValue() const {
582 assert(Valid && "invalid option value");
583 return Value;
584 }
585
586 void setValue(const DataType &V) {
587 Valid = true;
588 Value = V;
589 }
590
591 // Returns whether this instance matches V.
592 bool compare(const DataType &V) const { return Valid && (Value == V); }
593
594 bool compare(const GenericOptionValue &V) const override {
595 const OptionValueCopy<DataType> &VC =
596 static_cast<const OptionValueCopy<DataType> &>(V);
597 if (!VC.hasValue())
598 return false;
599 return compare(VC.getValue());
600 }
601};
602
603// Non-class option values.
604template <class DataType>
605struct OptionValueBase<DataType, false> : OptionValueCopy<DataType> {
606 using WrapperType = DataType;
607
608protected:
609 OptionValueBase() = default;
612 ~OptionValueBase() = default;
613};
614
615// Top-level option class.
616template <class DataType>
617struct OptionValue final
618 : OptionValueBase<DataType, std::is_class_v<DataType>> {
619 OptionValue() = default;
620
621 OptionValue(const DataType &V) { this->setValue(V); }
622
623 // Some options may take their value from a different data type.
624 template <class DT> OptionValue<DataType> &operator=(const DT &V) {
625 this->setValue(V);
626 return *this;
627 }
628};
629
630// Other safe-to-copy-by-value common option types.
632template <>
633struct OptionValue<cl::boolOrDefault> final
634 : OptionValueCopy<cl::boolOrDefault> {
636
637 OptionValue() = default;
638
639 OptionValue(const cl::boolOrDefault &V) { this->setValue(V); }
640
642 setValue(V);
643 return *this;
644 }
645
646private:
647 void anchor() override;
648};
649
650template <>
651struct OptionValue<std::string> final : OptionValueCopy<std::string> {
653
654 OptionValue() = default;
655
656 OptionValue(const std::string &V) { this->setValue(V); }
657
658 OptionValue<std::string> &operator=(const std::string &V) {
659 setValue(V);
660 return *this;
661 }
662
663private:
664 void anchor() override;
665};
666
667//===----------------------------------------------------------------------===//
668// Enum valued command line option
669//
670
671// This represents a single enum value, using "int" as the underlying type.
674 int Value;
676};
677
678#define clEnumVal(ENUMVAL, DESC) \
679 llvm::cl::OptionEnumValue { #ENUMVAL, int(ENUMVAL), DESC }
680#define clEnumValN(ENUMVAL, FLAGNAME, DESC) \
681 llvm::cl::OptionEnumValue { FLAGNAME, int(ENUMVAL), DESC }
682
683// For custom data types, allow specifying a group of values together as the
684// values that go into the mapping that the option handler uses.
685//
687 // Use a vector instead of a map, because the lists should be short,
688 // the overhead is less, and most importantly, it keeps them in the order
689 // inserted so we can print our option out nicely.
691
692public:
693 ValuesClass(std::initializer_list<OptionEnumValue> Options)
694 : Values(Options) {}
695
696 template <class Opt> void apply(Opt &O) const {
697 for (const auto &Value : Values)
698 O.getParser().addLiteralOption(Value.Name, Value.Value,
699 Value.Description);
700 }
701};
702
703/// Helper to build a ValuesClass by forwarding a variable number of arguments
704/// as an initializer list to the ValuesClass constructor.
705template <typename... OptsTy> ValuesClass values(OptsTy... Options) {
706 return ValuesClass({Options...});
707}
708
709//===----------------------------------------------------------------------===//
710// Parameterizable parser for different data types. By default, known data types
711// (string, int, bool) have specialized parsers, that do what you would expect.
712// The default parser, used for data types that are not built-in, uses a mapping
713// table to map specific options to values, which is used, among other things,
714// to handle enum types.
715
716//--------------------------------------------------
717// This class holds all the non-generic code that we do not need replicated for
718// every instance of the generic parser. This also allows us to put stuff into
719// CommandLine.cpp
720//
722protected:
724 public:
726 : Name(name), HelpStr(helpStr) {}
729 };
730
731public:
733
734 virtual ~generic_parser_base() = default;
735 // Base class should have virtual-destructor
736
737 // Virtual function implemented by generic subclass to indicate how many
738 // entries are in Values.
739 //
740 virtual unsigned getNumOptions() const = 0;
741
742 // Return option name N.
743 virtual StringRef getOption(unsigned N) const = 0;
744
745 // Return description N
746 virtual StringRef getDescription(unsigned N) const = 0;
747
748 // Return the width of the option tag for printing...
749 virtual size_t getOptionWidth(const Option &O) const;
750
751 virtual const GenericOptionValue &getOptionValue(unsigned N) const = 0;
752
753 // Print out information about this option. The to-be-maintained width is
754 // specified.
755 //
756 virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const;
757
758 void printGenericOptionDiff(const Option &O, const GenericOptionValue &V,
760 size_t GlobalWidth) const;
761
762 // Print the value of an option and it's default.
763 //
764 // Template definition ensures that the option and default have the same
765 // DataType (via the same AnyOptionValue).
766 template <class AnyOptionValue>
767 void printOptionDiff(const Option &O, const AnyOptionValue &V,
768 const AnyOptionValue &Default,
769 size_t GlobalWidth) const {
770 printGenericOptionDiff(O, V, Default, GlobalWidth);
771 }
772
773 void initialize() {}
774
776 // If there has been no argstr specified, that means that we need to add an
777 // argument for every possible option. This ensures that our options are
778 // vectored to us.
779 if (!Owner.hasArgStr())
780 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
781 OptionNames.push_back(getOption(i));
782 }
783
785 // If there is an ArgStr specified, then we are of the form:
786 //
787 // -opt=O2 or -opt O2 or -optO2
788 //
789 // In which case, the value is required. Otherwise if an arg str has not
790 // been specified, we are of the form:
791 //
792 // -O2 or O2 or -la (where -l and -a are separate options)
793 //
794 // If this is the case, we cannot allow a value.
795 //
796 if (Owner.hasArgStr())
797 return ValueRequired;
798 else
799 return ValueDisallowed;
800 }
801
802 // Return the option number corresponding to the specified
803 // argument string. If the option is not found, getNumOptions() is returned.
804 //
805 unsigned findOption(StringRef Name);
806
807protected:
809};
810
811// Default parser implementation - This implementation depends on having a
812// mapping of recognized options to values of some sort. In addition to this,
813// each entry in the mapping also tracks a help message that is printed with the
814// command line option for -help. Because this is a simple mapping parser, the
815// data type can be any unsupported type.
816//
817template <class DataType> class parser : public generic_parser_base {
818protected:
820 public:
821 OptionInfo(StringRef name, DataType v, StringRef helpStr)
822 : GenericOptionInfo(name, helpStr), V(v) {}
823
825 };
827
828public:
830
831 using parser_data_type = DataType;
832
833 // Implement virtual functions needed by generic_parser_base
834 unsigned getNumOptions() const override { return unsigned(Values.size()); }
835 StringRef getOption(unsigned N) const override { return Values[N].Name; }
836 StringRef getDescription(unsigned N) const override {
837 return Values[N].HelpStr;
838 }
839
840 // Return the value of option name N.
841 const GenericOptionValue &getOptionValue(unsigned N) const override {
842 return Values[N].V;
843 }
844
845 // Return true on error.
846 bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V) {
847 StringRef ArgVal;
848 if (Owner.hasArgStr())
849 ArgVal = Arg;
850 else
851 ArgVal = ArgName;
852
853 for (size_t i = 0, e = Values.size(); i != e; ++i)
854 if (Values[i].Name == ArgVal) {
855 V = Values[i].V.getValue();
856 return false;
857 }
858
859 return O.error("Cannot find option named '" + ArgVal + "'!");
860 }
861
862 /// Add an entry to the mapping table.
863 ///
864 template <class DT>
865 void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr) {
866#ifndef NDEBUG
867 if (findOption(Name) != Values.size())
868 report_fatal_error("Option " + Name + " already exists!");
869#endif
870 OptionInfo X(Name, static_cast<DataType>(V), HelpStr);
871 Values.push_back(X);
873 }
874
875 /// Remove the specified option.
876 ///
878 unsigned N = findOption(Name);
879 assert(N != Values.size() && "Option not found!");
880 Values.erase(Values.begin() + N);
881 }
882};
883
884//--------------------------------------------------
885// Super class of parsers to provide boilerplate code
886//
887class basic_parser_impl { // non-template implementation of basic_parser<t>
888public:
890
891 virtual ~basic_parser_impl() = default;
892
894 return ValueRequired;
895 }
896
898
899 void initialize() {}
900
901 // Return the width of the option tag for printing...
902 size_t getOptionWidth(const Option &O) const;
903
904 // Print out information about this option. The to-be-maintained width is
905 // specified.
906 //
907 void printOptionInfo(const Option &O, size_t GlobalWidth) const;
908
909 // Print a placeholder for options that don't yet support printOptionDiff().
910 void printOptionNoValue(const Option &O, size_t GlobalWidth) const;
911
912 // Overload in subclass to provide a better default value.
913 virtual StringRef getValueName() const { return "value"; }
914
915 // An out-of-line virtual method to provide a 'home' for this class.
916 virtual void anchor();
917
918protected:
919 // A helper for basic_parser::printOptionDiff.
920 void printOptionName(const Option &O, size_t GlobalWidth) const;
921};
922
923// The real basic parser is just a template wrapper that provides a typedef for
924// the provided data type.
925//
926template <class DataType> class basic_parser : public basic_parser_impl {
927public:
928 using parser_data_type = DataType;
930
932};
933
934//--------------------------------------------------
935
936extern template class basic_parser<bool>;
937
938template <> class parser<bool> : public basic_parser<bool> {
939public:
941
942 // Return true on error.
943 bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val);
944
945 void initialize() {}
946
948 return ValueOptional;
949 }
950
951 // Do not print =<value> at all.
952 StringRef getValueName() const override { return StringRef(); }
953
954 void printOptionDiff(const Option &O, bool V, OptVal Default,
955 size_t GlobalWidth) const;
956
957 // An out-of-line virtual method to provide a 'home' for this class.
958 void anchor() override;
959};
960
961//--------------------------------------------------
962
963extern template class basic_parser<boolOrDefault>;
964
966public:
968
969 // Return true on error.
970 bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val);
971
973 return ValueOptional;
974 }
975
976 // Do not print =<value> at all.
977 StringRef getValueName() const override { return StringRef(); }
978
980 size_t GlobalWidth) const;
981
982 // An out-of-line virtual method to provide a 'home' for this class.
983 void anchor() override;
984};
985
986//--------------------------------------------------
987
988extern template class basic_parser<int>;
989
990template <> class parser<int> : public basic_parser<int> {
991public:
993
994 // Return true on error.
995 bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val);
996
997 // Overload in subclass to provide a better default value.
998 StringRef getValueName() const override { return "int"; }
999
1000 void printOptionDiff(const Option &O, int V, OptVal Default,
1001 size_t GlobalWidth) const;
1002
1003 // An out-of-line virtual method to provide a 'home' for this class.
1004 void anchor() override;
1005};
1006
1007//--------------------------------------------------
1008
1009extern template class basic_parser<long>;
1010
1011template <> class parser<long> final : public basic_parser<long> {
1012public:
1014
1015 // Return true on error.
1016 bool parse(Option &O, StringRef ArgName, StringRef Arg, long &Val);
1017
1018 // Overload in subclass to provide a better default value.
1019 StringRef getValueName() const override { return "long"; }
1020
1021 void printOptionDiff(const Option &O, long V, OptVal Default,
1022 size_t GlobalWidth) const;
1023
1024 // An out-of-line virtual method to provide a 'home' for this class.
1025 void anchor() override;
1026};
1027
1028//--------------------------------------------------
1029
1030extern template class basic_parser<long long>;
1031
1032template <> class parser<long long> : public basic_parser<long long> {
1033public:
1035
1036 // Return true on error.
1037 bool parse(Option &O, StringRef ArgName, StringRef Arg, long long &Val);
1038
1039 // Overload in subclass to provide a better default value.
1040 StringRef getValueName() const override { return "long"; }
1041
1042 void printOptionDiff(const Option &O, long long V, OptVal Default,
1043 size_t GlobalWidth) const;
1044
1045 // An out-of-line virtual method to provide a 'home' for this class.
1046 void anchor() override;
1047};
1048
1049//--------------------------------------------------
1050
1051extern template class basic_parser<unsigned>;
1052
1053template <> class parser<unsigned> : public basic_parser<unsigned> {
1054public:
1056
1057 // Return true on error.
1058 bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val);
1059
1060 // Overload in subclass to provide a better default value.
1061 StringRef getValueName() const override { return "uint"; }
1062
1063 void printOptionDiff(const Option &O, unsigned V, OptVal Default,
1064 size_t GlobalWidth) const;
1065
1066 // An out-of-line virtual method to provide a 'home' for this class.
1067 void anchor() override;
1068};
1069
1070//--------------------------------------------------
1071
1072extern template class basic_parser<unsigned long>;
1073
1074template <>
1076public:
1078
1079 // Return true on error.
1080 bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val);
1081
1082 // Overload in subclass to provide a better default value.
1083 StringRef getValueName() const override { return "ulong"; }
1084
1085 void printOptionDiff(const Option &O, unsigned long V, OptVal Default,
1086 size_t GlobalWidth) const;
1087
1088 // An out-of-line virtual method to provide a 'home' for this class.
1089 void anchor() override;
1090};
1091
1092//--------------------------------------------------
1093
1094extern template class basic_parser<unsigned long long>;
1095
1096template <>
1098public:
1100
1101 // Return true on error.
1102 bool parse(Option &O, StringRef ArgName, StringRef Arg,
1103 unsigned long long &Val);
1104
1105 // Overload in subclass to provide a better default value.
1106 StringRef getValueName() const override { return "ulong"; }
1107
1108 void printOptionDiff(const Option &O, unsigned long long V, OptVal Default,
1109 size_t GlobalWidth) const;
1110
1111 // An out-of-line virtual method to provide a 'home' for this class.
1112 void anchor() override;
1113};
1114
1115//--------------------------------------------------
1116
1117extern template class basic_parser<double>;
1118
1119template <> class parser<double> : public basic_parser<double> {
1120public:
1122
1123 // Return true on error.
1124 bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val);
1125
1126 // Overload in subclass to provide a better default value.
1127 StringRef getValueName() const override { return "number"; }
1128
1129 void printOptionDiff(const Option &O, double V, OptVal Default,
1130 size_t GlobalWidth) const;
1131
1132 // An out-of-line virtual method to provide a 'home' for this class.
1133 void anchor() override;
1134};
1135
1136//--------------------------------------------------
1137
1138extern template class basic_parser<float>;
1139
1140template <> class parser<float> : public basic_parser<float> {
1141public:
1143
1144 // Return true on error.
1145 bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val);
1146
1147 // Overload in subclass to provide a better default value.
1148 StringRef getValueName() const override { return "number"; }
1149
1150 void printOptionDiff(const Option &O, float V, OptVal Default,
1151 size_t GlobalWidth) const;
1152
1153 // An out-of-line virtual method to provide a 'home' for this class.
1154 void anchor() override;
1155};
1156
1157//--------------------------------------------------
1158
1159extern template class basic_parser<std::string>;
1160
1162public:
1164
1165 // Return true on error.
1166 bool parse(Option &, StringRef, StringRef Arg, std::string &Value) {
1167 Value = Arg.str();
1168 return false;
1169 }
1170
1171 // Overload in subclass to provide a better default value.
1172 StringRef getValueName() const override { return "string"; }
1173
1175 size_t GlobalWidth) const;
1176
1177 // An out-of-line virtual method to provide a 'home' for this class.
1178 void anchor() override;
1179};
1180
1181//--------------------------------------------------
1182
1183extern template class basic_parser<char>;
1184
1185template <> class parser<char> : public basic_parser<char> {
1186public:
1188
1189 // Return true on error.
1190 bool parse(Option &, StringRef, StringRef Arg, char &Value) {
1191 Value = Arg[0];
1192 return false;
1193 }
1194
1195 // Overload in subclass to provide a better default value.
1196 StringRef getValueName() const override { return "char"; }
1197
1198 void printOptionDiff(const Option &O, char V, OptVal Default,
1199 size_t GlobalWidth) const;
1200
1201 // An out-of-line virtual method to provide a 'home' for this class.
1202 void anchor() override;
1203};
1204
1205//--------------------------------------------------
1206// This collection of wrappers is the intermediary between class opt and class
1207// parser to handle all the template nastiness.
1208
1209// This overloaded function is selected by the generic parser.
1210template <class ParserClass, class DT>
1211void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V,
1212 const OptionValue<DT> &Default, size_t GlobalWidth) {
1213 OptionValue<DT> OV = V;
1214 P.printOptionDiff(O, OV, Default, GlobalWidth);
1215}
1216
1217// This is instantiated for basic parsers when the parsed value has a different
1218// type than the option value. e.g. HelpPrinter.
1219template <class ParserDT, class ValDT> struct OptionDiffPrinter {
1220 void print(const Option &O, const parser<ParserDT> &P, const ValDT & /*V*/,
1221 const OptionValue<ValDT> & /*Default*/, size_t GlobalWidth) {
1222 P.printOptionNoValue(O, GlobalWidth);
1223 }
1224};
1225
1226// This is instantiated for basic parsers when the parsed value has the same
1227// type as the option value.
1228template <class DT> struct OptionDiffPrinter<DT, DT> {
1229 void print(const Option &O, const parser<DT> &P, const DT &V,
1230 const OptionValue<DT> &Default, size_t GlobalWidth) {
1231 P.printOptionDiff(O, V, Default, GlobalWidth);
1232 }
1233};
1234
1235// This overloaded function is selected by the basic parser, which may parse a
1236// different type than the option type.
1237template <class ParserClass, class ValDT>
1239 const Option &O,
1241 const ValDT &V, const OptionValue<ValDT> &Default, size_t GlobalWidth) {
1242
1244 printer.print(O, static_cast<const ParserClass &>(P), V, Default,
1245 GlobalWidth);
1246}
1247
1248//===----------------------------------------------------------------------===//
1249// This class is used because we must use partial specialization to handle
1250// literal string arguments specially (const char* does not correctly respond to
1251// the apply method). Because the syntax to use this is a pain, we have the
1252// 'apply' method below to handle the nastiness...
1253//
1254template <class Mod> struct applicator {
1255 template <class Opt> static void opt(const Mod &M, Opt &O) { M.apply(O); }
1256};
1257
1258// Handle const char* as a special case...
1259template <unsigned n> struct applicator<char[n]> {
1260 template <class Opt> static void opt(StringRef Str, Opt &O) {
1261 O.setArgStr(Str);
1262 }
1263};
1264template <unsigned n> struct applicator<const char[n]> {
1265 template <class Opt> static void opt(StringRef Str, Opt &O) {
1266 O.setArgStr(Str);
1267 }
1268};
1269template <> struct applicator<StringRef > {
1270 template <class Opt> static void opt(StringRef Str, Opt &O) {
1271 O.setArgStr(Str);
1272 }
1273};
1274
1276 static void opt(NumOccurrencesFlag N, Option &O) {
1277 O.setNumOccurrencesFlag(N);
1278 }
1279};
1280
1281template <> struct applicator<ValueExpected> {
1282 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
1283};
1284
1285template <> struct applicator<OptionHidden> {
1286 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
1287};
1288
1290 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
1291};
1292
1293template <> struct applicator<MiscFlags> {
1294 static void opt(MiscFlags MF, Option &O) {
1295 assert((MF != Grouping || O.ArgStr.size() == 1) &&
1296 "cl::Grouping can only apply to single character Options.");
1297 O.setMiscFlag(MF);
1298 }
1299};
1300
1301// Apply modifiers to an option in a type safe way.
1302template <class Opt, class Mod, class... Mods>
1303void apply(Opt *O, const Mod &M, const Mods &... Ms) {
1304 applicator<Mod>::opt(M, *O);
1305 apply(O, Ms...);
1306}
1307
1308template <class Opt, class Mod> void apply(Opt *O, const Mod &M) {
1309 applicator<Mod>::opt(M, *O);
1310}
1311
1312//===----------------------------------------------------------------------===//
1313// Default storage class definition: external storage. This implementation
1314// assumes the user will specify a variable to store the data into with the
1315// cl::location(x) modifier.
1316//
1317template <class DataType, bool ExternalStorage, bool isClass>
1319 DataType *Location = nullptr; // Where to store the object...
1320 OptionValue<DataType> Default;
1321
1322 void check_location() const {
1323 assert(Location && "cl::location(...) not specified for a command "
1324 "line option with external storage, "
1325 "or cl::init specified before cl::location()!!");
1326 }
1327
1328public:
1329 opt_storage() = default;
1330
1331 bool setLocation(Option &O, DataType &L) {
1332 if (Location)
1333 return O.error("cl::location(x) specified more than once!");
1334 Location = &L;
1335 Default = L;
1336 return false;
1337 }
1338
1339 template <class T> void setValue(const T &V, bool initial = false) {
1340 check_location();
1341 *Location = V;
1342 if (initial)
1343 Default = V;
1344 }
1345
1346 DataType &getValue() {
1347 check_location();
1348 return *Location;
1349 }
1350 const DataType &getValue() const {
1351 check_location();
1352 return *Location;
1353 }
1354
1355 operator DataType() const { return this->getValue(); }
1356
1357 const OptionValue<DataType> &getDefault() const { return Default; }
1358};
1359
1360// Define how to hold a class type object, such as a string. Since we can
1361// inherit from a class, we do so. This makes us exactly compatible with the
1362// object in all cases that it is used.
1363//
1364template <class DataType>
1365class opt_storage<DataType, false, true> : public DataType {
1366public:
1368
1369 template <class T> void setValue(const T &V, bool initial = false) {
1370 DataType::operator=(V);
1371 if (initial)
1372 Default = V;
1373 }
1374
1375 DataType &getValue() { return *this; }
1376 const DataType &getValue() const { return *this; }
1377
1378 const OptionValue<DataType> &getDefault() const { return Default; }
1379};
1380
1381// Define a partial specialization to handle things we cannot inherit from. In
1382// this case, we store an instance through containment, and overload operators
1383// to get at the value.
1384//
1385template <class DataType> class opt_storage<DataType, false, false> {
1386public:
1387 DataType Value;
1389
1390 // Make sure we initialize the value with the default constructor for the
1391 // type.
1392 opt_storage() : Value(DataType()), Default() {}
1393
1394 template <class T> void setValue(const T &V, bool initial = false) {
1395 Value = V;
1396 if (initial)
1397 Default = V;
1398 }
1399 DataType &getValue() { return Value; }
1400 DataType getValue() const { return Value; }
1401
1402 const OptionValue<DataType> &getDefault() const { return Default; }
1403
1404 operator DataType() const { return getValue(); }
1405
1406 // If the datatype is a pointer, support -> on it.
1407 DataType operator->() const { return Value; }
1408};
1409
1410//===----------------------------------------------------------------------===//
1411// A scalar command line option.
1412//
1413template <class DataType, bool ExternalStorage = false,
1414 class ParserClass = parser<DataType>>
1415class opt
1416 : public Option,
1417 public opt_storage<DataType, ExternalStorage, std::is_class_v<DataType>> {
1418 ParserClass Parser;
1419
1420 bool handleOccurrence(unsigned pos, StringRef ArgName,
1421 StringRef Arg) override {
1422 typename ParserClass::parser_data_type Val =
1423 typename ParserClass::parser_data_type();
1424 if (Parser.parse(*this, ArgName, Arg, Val))
1425 return true; // Parse error!
1426 this->setValue(Val);
1427 this->setPosition(pos);
1428 Callback(Val);
1429 return false;
1430 }
1431
1432 enum ValueExpected getValueExpectedFlagDefault() const override {
1433 return Parser.getValueExpectedFlagDefault();
1434 }
1435
1436 void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
1437 return Parser.getExtraOptionNames(OptionNames);
1438 }
1439
1440 // Forward printing stuff to the parser...
1441 size_t getOptionWidth() const override {
1442 return Parser.getOptionWidth(*this);
1443 }
1444
1445 void printOptionInfo(size_t GlobalWidth) const override {
1446 Parser.printOptionInfo(*this, GlobalWidth);
1447 }
1448
1449 void printOptionValue(size_t GlobalWidth, bool Force) const override {
1450 if (Force || !this->getDefault().compare(this->getValue())) {
1451 cl::printOptionDiff<ParserClass>(*this, Parser, this->getValue(),
1452 this->getDefault(), GlobalWidth);
1453 }
1454 }
1455
1456 template <class T, class = std::enable_if_t<std::is_assignable_v<T &, T>>>
1457 void setDefaultImpl() {
1458 const OptionValue<DataType> &V = this->getDefault();
1459 if (V.hasValue())
1460 this->setValue(V.getValue());
1461 else
1462 this->setValue(T());
1463 }
1464
1465 template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
1466 void setDefaultImpl(...) {}
1467
1468 void setDefault() override { setDefaultImpl<DataType>(); }
1469
1470 void done() {
1471 addArgument();
1472 Parser.initialize();
1473 }
1474
1475public:
1476 // Command line options should not be copyable
1477 opt(const opt &) = delete;
1478 opt &operator=(const opt &) = delete;
1479
1480 // setInitialValue - Used by the cl::init modifier...
1481 void setInitialValue(const DataType &V) { this->setValue(V, true); }
1482
1483 ParserClass &getParser() { return Parser; }
1484
1485 template <class T> DataType &operator=(const T &Val) {
1486 this->setValue(Val);
1487 Callback(Val);
1488 return this->getValue();
1489 }
1490
1491 template <class... Mods>
1492 explicit opt(const Mods &... Ms)
1493 : Option(llvm::cl::Optional, NotHidden), Parser(*this) {
1494 apply(this, Ms...);
1495 done();
1496 }
1497
1499 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1500 Callback = CB;
1501 }
1502
1503 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1504 [](const typename ParserClass::parser_data_type &) {};
1505};
1506
1507extern template class opt<unsigned>;
1508extern template class opt<int>;
1509extern template class opt<std::string>;
1510extern template class opt<char>;
1511extern template class opt<bool>;
1512
1513//===----------------------------------------------------------------------===//
1514// Default storage class definition: external storage. This implementation
1515// assumes the user will specify a variable to store the data into with the
1516// cl::location(x) modifier.
1517//
1518template <class DataType, class StorageClass> class list_storage {
1519 StorageClass *Location = nullptr; // Where to store the object...
1520 std::vector<OptionValue<DataType>> Default =
1521 std::vector<OptionValue<DataType>>();
1522 bool DefaultAssigned = false;
1523
1524public:
1525 list_storage() = default;
1526
1527 void clear() {}
1528
1530 if (Location)
1531 return O.error("cl::location(x) specified more than once!");
1532 Location = &L;
1533 return false;
1534 }
1535
1536 template <class T> void addValue(const T &V, bool initial = false) {
1537 assert(Location != nullptr &&
1538 "cl::location(...) not specified for a command "
1539 "line option with external storage!");
1540 Location->push_back(V);
1541 if (initial)
1542 Default.push_back(V);
1543 }
1544
1545 const std::vector<OptionValue<DataType>> &getDefault() const {
1546 return Default;
1547 }
1548
1549 void assignDefault() { DefaultAssigned = true; }
1550 void overwriteDefault() { DefaultAssigned = false; }
1551 bool isDefaultAssigned() { return DefaultAssigned; }
1552};
1553
1554// Define how to hold a class type object, such as a string.
1555// Originally this code inherited from std::vector. In transitioning to a new
1556// API for command line options we should change this. The new implementation
1557// of this list_storage specialization implements the minimum subset of the
1558// std::vector API required for all the current clients.
1559//
1560// FIXME: Reduce this API to a more narrow subset of std::vector
1561//
1562template <class DataType> class list_storage<DataType, bool> {
1563 std::vector<DataType> Storage;
1564 std::vector<OptionValue<DataType>> Default;
1565 bool DefaultAssigned = false;
1566
1567public:
1568 using iterator = typename std::vector<DataType>::iterator;
1569
1570 iterator begin() { return Storage.begin(); }
1571 iterator end() { return Storage.end(); }
1572
1573 using const_iterator = typename std::vector<DataType>::const_iterator;
1574
1575 const_iterator begin() const { return Storage.begin(); }
1576 const_iterator end() const { return Storage.end(); }
1577
1578 using size_type = typename std::vector<DataType>::size_type;
1579
1580 size_type size() const { return Storage.size(); }
1581
1582 bool empty() const { return Storage.empty(); }
1583
1584 void push_back(const DataType &value) { Storage.push_back(value); }
1585 void push_back(DataType &&value) { Storage.push_back(value); }
1586
1587 using reference = typename std::vector<DataType>::reference;
1588 using const_reference = typename std::vector<DataType>::const_reference;
1589
1590 reference operator[](size_type pos) { return Storage[pos]; }
1591 const_reference operator[](size_type pos) const { return Storage[pos]; }
1592
1593 void clear() {
1594 Storage.clear();
1595 }
1596
1597 iterator erase(const_iterator pos) { return Storage.erase(pos); }
1599 return Storage.erase(first, last);
1600 }
1601
1602 iterator erase(iterator pos) { return Storage.erase(pos); }
1604 return Storage.erase(first, last);
1605 }
1606
1607 iterator insert(const_iterator pos, const DataType &value) {
1608 return Storage.insert(pos, value);
1609 }
1611 return Storage.insert(pos, value);
1612 }
1613
1614 iterator insert(iterator pos, const DataType &value) {
1615 return Storage.insert(pos, value);
1616 }
1617 iterator insert(iterator pos, DataType &&value) {
1618 return Storage.insert(pos, value);
1619 }
1620
1621 reference front() { return Storage.front(); }
1622 const_reference front() const { return Storage.front(); }
1623
1624 operator std::vector<DataType> &() { return Storage; }
1625 operator ArrayRef<DataType>() const { return Storage; }
1626 std::vector<DataType> *operator&() { return &Storage; }
1627 const std::vector<DataType> *operator&() const { return &Storage; }
1628
1629 template <class T> void addValue(const T &V, bool initial = false) {
1630 Storage.push_back(V);
1631 if (initial)
1632 Default.push_back(OptionValue<DataType>(V));
1633 }
1634
1635 const std::vector<OptionValue<DataType>> &getDefault() const {
1636 return Default;
1637 }
1638
1639 void assignDefault() { DefaultAssigned = true; }
1640 void overwriteDefault() { DefaultAssigned = false; }
1641 bool isDefaultAssigned() { return DefaultAssigned; }
1642};
1643
1644//===----------------------------------------------------------------------===//
1645// A list of command line options.
1646//
1647template <class DataType, class StorageClass = bool,
1648 class ParserClass = parser<DataType>>
1649class list : public Option, public list_storage<DataType, StorageClass> {
1650 std::vector<unsigned> Positions;
1651 ParserClass Parser;
1652
1653 enum ValueExpected getValueExpectedFlagDefault() const override {
1654 return Parser.getValueExpectedFlagDefault();
1655 }
1656
1657 void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
1658 return Parser.getExtraOptionNames(OptionNames);
1659 }
1660
1661 bool handleOccurrence(unsigned pos, StringRef ArgName,
1662 StringRef Arg) override {
1663 typename ParserClass::parser_data_type Val =
1664 typename ParserClass::parser_data_type();
1666 clear();
1668 }
1669 if (Parser.parse(*this, ArgName, Arg, Val))
1670 return true; // Parse Error!
1672 setPosition(pos);
1673 Positions.push_back(pos);
1674 Callback(Val);
1675 return false;
1676 }
1677
1678 // Forward printing stuff to the parser...
1679 size_t getOptionWidth() const override {
1680 return Parser.getOptionWidth(*this);
1681 }
1682
1683 void printOptionInfo(size_t GlobalWidth) const override {
1684 Parser.printOptionInfo(*this, GlobalWidth);
1685 }
1686
1687 // Unimplemented: list options don't currently store their default value.
1688 void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
1689 }
1690
1691 void setDefault() override {
1692 Positions.clear();
1696 }
1697
1698 void done() {
1699 addArgument();
1700 Parser.initialize();
1701 }
1702
1703public:
1704 // Command line options should not be copyable
1705 list(const list &) = delete;
1706 list &operator=(const list &) = delete;
1707
1708 ParserClass &getParser() { return Parser; }
1709
1710 unsigned getPosition(unsigned optnum) const {
1711 assert(optnum < this->size() && "Invalid option index");
1712 return Positions[optnum];
1713 }
1714
1715 void clear() {
1716 Positions.clear();
1718 }
1719
1720 // setInitialValues - Used by the cl::list_init modifier...
1723 "Cannot have two default values");
1725 for (auto &Val : Vs)
1727 }
1728
1730
1731 template <class... Mods>
1732 explicit list(const Mods &... Ms)
1733 : Option(ZeroOrMore, NotHidden), Parser(*this) {
1734 apply(this, Ms...);
1735 done();
1736 }
1737
1739 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1740 Callback = CB;
1741 }
1742
1743 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1744 [](const typename ParserClass::parser_data_type &) {};
1745};
1746
1747// Modifier to set the number of additional values.
1750 explicit multi_val(unsigned N) : AdditionalVals(N) {}
1751
1752 template <typename D, typename S, typename P>
1753 void apply(list<D, S, P> &L) const {
1754 L.setNumAdditionalVals(AdditionalVals);
1755 }
1756};
1757
1758//===----------------------------------------------------------------------===//
1759// Default storage class definition: external storage. This implementation
1760// assumes the user will specify a variable to store the data into with the
1761// cl::location(x) modifier.
1762//
1763template <class DataType, class StorageClass> class bits_storage {
1764 unsigned *Location = nullptr; // Where to store the bits...
1765
1766 template <class T> static unsigned Bit(const T &V) {
1767 unsigned BitPos = static_cast<unsigned>(V);
1768 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1769 "enum exceeds width of bit vector!");
1770 return 1 << BitPos;
1771 }
1772
1773public:
1774 bits_storage() = default;
1775
1776 bool setLocation(Option &O, unsigned &L) {
1777 if (Location)
1778 return O.error("cl::location(x) specified more than once!");
1779 Location = &L;
1780 return false;
1781 }
1782
1783 template <class T> void addValue(const T &V) {
1784 assert(Location != nullptr &&
1785 "cl::location(...) not specified for a command "
1786 "line option with external storage!");
1787 *Location |= Bit(V);
1788 }
1789
1790 unsigned getBits() { return *Location; }
1791
1792 void clear() {
1793 if (Location)
1794 *Location = 0;
1795 }
1796
1797 template <class T> bool isSet(const T &V) {
1798 return (*Location & Bit(V)) != 0;
1799 }
1800};
1801
1802// Define how to hold bits. Since we can inherit from a class, we do so.
1803// This makes us exactly compatible with the bits in all cases that it is used.
1804//
1805template <class DataType> class bits_storage<DataType, bool> {
1806 unsigned Bits{0}; // Where to store the bits...
1807
1808 template <class T> static unsigned Bit(const T &V) {
1809 unsigned BitPos = static_cast<unsigned>(V);
1810 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1811 "enum exceeds width of bit vector!");
1812 return 1 << BitPos;
1813 }
1814
1815public:
1816 template <class T> void addValue(const T &V) { Bits |= Bit(V); }
1817
1818 unsigned getBits() { return Bits; }
1819
1820 void clear() { Bits = 0; }
1821
1822 template <class T> bool isSet(const T &V) { return (Bits & Bit(V)) != 0; }
1823};
1824
1825//===----------------------------------------------------------------------===//
1826// A bit vector of command options.
1827//
1828template <class DataType, class Storage = bool,
1829 class ParserClass = parser<DataType>>
1830class bits : public Option, public bits_storage<DataType, Storage> {
1831 std::vector<unsigned> Positions;
1832 ParserClass Parser;
1833
1834 enum ValueExpected getValueExpectedFlagDefault() const override {
1835 return Parser.getValueExpectedFlagDefault();
1836 }
1837
1838 void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
1839 return Parser.getExtraOptionNames(OptionNames);
1840 }
1841
1842 bool handleOccurrence(unsigned pos, StringRef ArgName,
1843 StringRef Arg) override {
1844 typename ParserClass::parser_data_type Val =
1845 typename ParserClass::parser_data_type();
1846 if (Parser.parse(*this, ArgName, Arg, Val))
1847 return true; // Parse Error!
1848 this->addValue(Val);
1849 setPosition(pos);
1850 Positions.push_back(pos);
1851 Callback(Val);
1852 return false;
1853 }
1854
1855 // Forward printing stuff to the parser...
1856 size_t getOptionWidth() const override {
1857 return Parser.getOptionWidth(*this);
1858 }
1859
1860 void printOptionInfo(size_t GlobalWidth) const override {
1861 Parser.printOptionInfo(*this, GlobalWidth);
1862 }
1863
1864 // Unimplemented: bits options don't currently store their default values.
1865 void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
1866 }
1867
1868 void setDefault() override { bits_storage<DataType, Storage>::clear(); }
1869
1870 void done() {
1871 addArgument();
1872 Parser.initialize();
1873 }
1874
1875public:
1876 // Command line options should not be copyable
1877 bits(const bits &) = delete;
1878 bits &operator=(const bits &) = delete;
1879
1880 ParserClass &getParser() { return Parser; }
1881
1882 unsigned getPosition(unsigned optnum) const {
1883 assert(optnum < this->size() && "Invalid option index");
1884 return Positions[optnum];
1885 }
1886
1887 template <class... Mods>
1888 explicit bits(const Mods &... Ms)
1889 : Option(ZeroOrMore, NotHidden), Parser(*this) {
1890 apply(this, Ms...);
1891 done();
1892 }
1893
1895 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1896 Callback = CB;
1897 }
1898
1899 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1900 [](const typename ParserClass::parser_data_type &) {};
1901};
1902
1903//===----------------------------------------------------------------------===//
1904// Aliased command line option (alias this name to a preexisting name)
1905//
1906
1907class alias : public Option {
1908 Option *AliasFor;
1909
1910 bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
1911 StringRef Arg) override {
1912 return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1913 }
1914
1915 bool addOccurrence(unsigned pos, StringRef /*ArgName*/, StringRef Value,
1916 bool MultiArg = false) override {
1917 return AliasFor->addOccurrence(pos, AliasFor->ArgStr, Value, MultiArg);
1918 }
1919
1920 // Handle printing stuff...
1921 size_t getOptionWidth() const override;
1922 void printOptionInfo(size_t GlobalWidth) const override;
1923
1924 // Aliases do not need to print their values.
1925 void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
1926 }
1927
1928 void setDefault() override { AliasFor->setDefault(); }
1929
1930 ValueExpected getValueExpectedFlagDefault() const override {
1931 return AliasFor->getValueExpectedFlag();
1932 }
1933
1934 void done() {
1935 if (!hasArgStr())
1936 error("cl::alias must have argument name specified!");
1937 if (!AliasFor)
1938 error("cl::alias must have an cl::aliasopt(option) specified!");
1939 if (!Subs.empty())
1940 error("cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!");
1941 Subs = AliasFor->Subs;
1942 Categories = AliasFor->Categories;
1943 addArgument();
1944 }
1945
1946public:
1947 // Command line options should not be copyable
1948 alias(const alias &) = delete;
1949 alias &operator=(const alias &) = delete;
1950
1952 if (AliasFor)
1953 error("cl::alias must only have one cl::aliasopt(...) specified!");
1954 AliasFor = &O;
1955 }
1956
1957 template <class... Mods>
1958 explicit alias(const Mods &... Ms)
1959 : Option(Optional, Hidden), AliasFor(nullptr) {
1960 apply(this, Ms...);
1961 done();
1962 }
1963};
1964
1965// Modifier to set the option an alias aliases.
1966struct aliasopt {
1968
1969 explicit aliasopt(Option &O) : Opt(O) {}
1970
1971 void apply(alias &A) const { A.setAliasFor(Opt); }
1972};
1973
1974// Provide additional help at the end of the normal help output. All occurrences
1975// of cl::extrahelp will be accumulated and printed to stderr at the end of the
1976// regular help, just before exit is called.
1979
1980 explicit extrahelp(StringRef help);
1981};
1982
1983void PrintVersionMessage();
1984
1985/// This function just prints the help message, exactly the same way as if the
1986/// -help or -help-hidden option had been given on the command line.
1987///
1988/// \param Hidden if true will print hidden options
1989/// \param Categorized if true print options in categories
1990void PrintHelpMessage(bool Hidden = false, bool Categorized = false);
1991
1992//===----------------------------------------------------------------------===//
1993// Public interface for accessing registered options.
1994//
1995
1996/// Use this to get a StringMap to all registered named options
1997/// (e.g. -help).
1998///
1999/// \return A reference to the StringMap used by the cl APIs to parse options.
2000///
2001/// Access to unnamed arguments (i.e. positional) are not provided because
2002/// it is expected that the client already has access to these.
2003///
2004/// Typical usage:
2005/// \code
2006/// main(int argc,char* argv[]) {
2007/// StringMap<llvm::cl::Option*> &opts = llvm::cl::getRegisteredOptions();
2008/// assert(opts.count("help") == 1)
2009/// opts["help"]->setDescription("Show alphabetical help information")
2010/// // More code
2011/// llvm::cl::ParseCommandLineOptions(argc,argv);
2012/// //More code
2013/// }
2014/// \endcode
2015///
2016/// This interface is useful for modifying options in libraries that are out of
2017/// the control of the client. The options should be modified before calling
2018/// llvm::cl::ParseCommandLineOptions().
2019///
2020/// Hopefully this API can be deprecated soon. Any situation where options need
2021/// to be modified by tools or libraries should be handled by sane APIs rather
2022/// than just handing around a global list.
2025
2026/// Use this to get all registered SubCommands from the provided parser.
2027///
2028/// \return A range of all SubCommand pointers registered with the parser.
2029///
2030/// Typical usage:
2031/// \code
2032/// main(int argc, char* argv[]) {
2033/// llvm::cl::ParseCommandLineOptions(argc, argv);
2034/// for (auto* S : llvm::cl::getRegisteredSubcommands()) {
2035/// if (*S) {
2036/// std::cout << "Executing subcommand: " << S->getName() << std::endl;
2037/// // Execute some function based on the name...
2038/// }
2039/// }
2040/// }
2041/// \endcode
2042///
2043/// This interface is useful for defining subcommands in libraries and
2044/// the dispatch from a single point (like in the main function).
2047
2048//===----------------------------------------------------------------------===//
2049// Standalone command line processing utilities.
2050//
2051
2052/// Tokenizes a command line that can contain escapes and quotes.
2053//
2054/// The quoting rules match those used by GCC and other tools that use
2055/// libiberty's buildargv() or expandargv() utilities, and do not match bash.
2056/// They differ from buildargv() on treatment of backslashes that do not escape
2057/// a special character to make it possible to accept most Windows file paths.
2058///
2059/// \param [in] Source The string to be split on whitespace with quotes.
2060/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2061/// \param [in] MarkEOLs true if tokenizing a response file and you want end of
2062/// lines and end of the response file to be marked with a nullptr string.
2063/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2064void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver,
2066 bool MarkEOLs = false);
2067
2068/// Tokenizes a string of Windows command line arguments, which may contain
2069/// quotes and escaped quotes.
2070///
2071/// See MSDN docs for CommandLineToArgvW for information on the quoting rules.
2072/// http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx
2073///
2074/// For handling a full Windows command line including the executable name at
2075/// the start, see TokenizeWindowsCommandLineFull below.
2076///
2077/// \param [in] Source The string to be split on whitespace with quotes.
2078/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2079/// \param [in] MarkEOLs true if tokenizing a response file and you want end of
2080/// lines and end of the response file to be marked with a nullptr string.
2081/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2084 bool MarkEOLs = false);
2085
2086/// Tokenizes a Windows command line while attempting to avoid copies. If no
2087/// quoting or escaping was used, this produces substrings of the original
2088/// string. If a token requires unquoting, it will be allocated with the
2089/// StringSaver.
2092
2093/// Tokenizes a Windows full command line, including command name at the start.
2094///
2095/// This uses the same syntax rules as TokenizeWindowsCommandLine for all but
2096/// the first token. But the first token is expected to be parsed as the
2097/// executable file name in the way CreateProcess would do it, rather than the
2098/// way the C library startup code would do it: CreateProcess does not consider
2099/// that \ is ever an escape character (because " is not a valid filename char,
2100/// hence there's never a need to escape it to be used literally).
2101///
2102/// Parameters are the same as for TokenizeWindowsCommandLine. In particular,
2103/// if you set MarkEOLs = true, then the first word of every line will be
2104/// parsed using the special rules for command names, making this function
2105/// suitable for parsing a file full of commands to execute.
2108 bool MarkEOLs = false);
2109
2110/// String tokenization function type. Should be compatible with either
2111/// Windows or Unix command line tokenizers.
2112using TokenizerCallback = void (*)(StringRef Source, StringSaver &Saver,
2114 bool MarkEOLs);
2115
2116/// Tokenizes content of configuration file.
2117///
2118/// \param [in] Source The string representing content of config file.
2119/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2120/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2121/// \param [in] MarkEOLs Added for compatibility with TokenizerCallback.
2122///
2123/// It works like TokenizeGNUCommandLine with ability to skip comment lines.
2124///
2125void tokenizeConfigFile(StringRef Source, StringSaver &Saver,
2127 bool MarkEOLs = false);
2128
2129/// Contains options that control response file expansion.
2131 /// Provides persistent storage for parsed strings.
2132 StringSaver Saver;
2133
2134 /// Tokenization strategy. Typically Unix or Windows.
2135 TokenizerCallback Tokenizer;
2136
2137 /// File system used for all file access when running the expansion.
2138 vfs::FileSystem *FS;
2139
2140 /// Path used to resolve relative rsp files. If empty, the file system
2141 /// current directory is used instead.
2142 StringRef CurrentDir;
2143
2144 /// Directories used for search of config files.
2145 ArrayRef<StringRef> SearchDirs;
2146
2147 /// True if names of nested response files must be resolved relative to
2148 /// including file.
2149 bool RelativeNames = false;
2150
2151 /// If true, mark end of lines and the end of the response file with nullptrs
2152 /// in the Argv vector.
2153 bool MarkEOLs = false;
2154
2155 /// If true, body of config file is expanded.
2156 bool InConfigFile = false;
2157
2158 llvm::Error expandResponseFile(StringRef FName,
2160
2161public:
2163
2165 MarkEOLs = X;
2166 return *this;
2167 }
2168
2170 RelativeNames = X;
2171 return *this;
2172 }
2173
2175 CurrentDir = X;
2176 return *this;
2177 }
2178
2180 SearchDirs = X;
2181 return *this;
2182 }
2183
2185 FS = X;
2186 return *this;
2187 }
2188
2189 /// Looks for the specified configuration file.
2190 ///
2191 /// \param[in] FileName Name of the file to search for.
2192 /// \param[out] FilePath File absolute path, if it was found.
2193 /// \return True if file was found.
2194 ///
2195 /// If the specified file name contains a directory separator, it is searched
2196 /// for by its absolute path. Otherwise looks for file sequentially in
2197 /// directories specified by SearchDirs field.
2198 bool findConfigFile(StringRef FileName, SmallVectorImpl<char> &FilePath);
2199
2200 /// Reads command line options from the given configuration file.
2201 ///
2202 /// \param [in] CfgFile Path to configuration file.
2203 /// \param [out] Argv Array to which the read options are added.
2204 /// \return true if the file was successfully read.
2205 ///
2206 /// It reads content of the specified file, tokenizes it and expands "@file"
2207 /// commands resolving file names in them relative to the directory where
2208 /// CfgFilename resides. It also expands "<CFGDIR>" to the base path of the
2209 /// current config file.
2211
2212 /// Expands constructs "@file" in the provided array of arguments recursively.
2214};
2215
2216/// A convenience helper which concatenates the options specified by the
2217/// environment variable EnvVar and command line options, then expands
2218/// response files recursively.
2219/// \return true if all @files were expanded successfully or there were none.
2220bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar,
2222
2223/// A convenience helper which supports the typical use case of expansion
2224/// function call.
2227
2228/// A convenience helper which concatenates the options specified by the
2229/// environment variable EnvVar and command line options, then expands response
2230/// files recursively. The tokenizer is a predefined GNU or Windows one.
2231/// \return true if all @files were expanded successfully or there were none.
2232bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar,
2233 StringSaver &Saver,
2235
2236/// Mark all options not part of this category as cl::ReallyHidden.
2237///
2238/// \param Category the category of options to keep displaying
2239///
2240/// Some tools (like clang-format) like to be able to hide all options that are
2241/// not specific to the tool. This function allows a tool to specify a single
2242/// option category to display in the -help output.
2245
2246/// Mark all options not part of the categories as cl::ReallyHidden.
2247///
2248/// \param Categories the categories of options to keep displaying.
2249///
2250/// Some tools (like clang-format) like to be able to hide all options that are
2251/// not specific to the tool. This function allows a tool to specify a single
2252/// option category to display in the -help output.
2255
2256/// Reset all command line options to a state that looks as if they have
2257/// never appeared on the command line. This is useful for being able to parse
2258/// a command line multiple times (especially useful for writing tests).
2260
2261/// Reset the command line parser back to its initial state. This
2262/// removes
2263/// all options, categories, and subcommands and returns the parser to a state
2264/// where no options are supported.
2266
2267/// Parses `Arg` into the option handler `Handler`.
2268bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i);
2269
2270} // end namespace cl
2271
2272} // end namespace llvm
2273
2274#endif // LLVM_SUPPORT_COMMANDLINE_H
aarch64 promote const
This file defines the StringMap class.
basic Basic Alias true
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil pretty printer
Given that RA is a live value
std::string Name
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define T
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char * name
Definition: SMEABIPass.cpp:49
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
#define error(X)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:451
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition: StringSaver.h:21
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:53
Contains options that control response file expansion.
Definition: CommandLine.h:2130
ExpansionContext & setCurrentDir(StringRef X)
Definition: CommandLine.h:2174
ExpansionContext & setVFS(vfs::FileSystem *X)
Definition: CommandLine.h:2184
ExpansionContext & setMarkEOLs(bool X)
Definition: CommandLine.h:2164
ExpansionContext & setSearchDirs(ArrayRef< StringRef > X)
Definition: CommandLine.h:2179
ExpansionContext & setRelativeNames(bool X)
Definition: CommandLine.h:2169
bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
Error readConfigFile(StringRef CfgFile, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
OptionCategory(StringRef const Name, StringRef const Description="")
Definition: CommandLine.h:188
StringRef getDescription() const
Definition: CommandLine.h:195
StringRef getName() const
Definition: CommandLine.h:194
OptionValueCopy & operator=(const OptionValueCopy &)=default
bool compare(const GenericOptionValue &V) const override
Definition: CommandLine.h:594
void setValue(const DataType &V)
Definition: CommandLine.h:586
const DataType & getValue() const
Definition: CommandLine.h:581
OptionValueCopy(const OptionValueCopy &)=default
bool compare(const DataType &V) const
Definition: CommandLine.h:592
bool isPositional() const
Definition: CommandLine.h:309
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
Definition: CommandLine.h:388
void setValueExpectedFlag(enum ValueExpected Val)
Definition: CommandLine.h:328
void setPosition(unsigned pos)
Definition: CommandLine.h:332
bool isConsumeAfter() const
Definition: CommandLine.h:313
StringRef ValueStr
Definition: CommandLine.h:282
SmallPtrSet< SubCommand *, 1 > Subs
Definition: CommandLine.h:285
StringRef ArgStr
Definition: CommandLine.h:280
int getNumOccurrences() const
Definition: CommandLine.h:401
enum ValueExpected getValueExpectedFlag() const
Definition: CommandLine.h:291
void addCategory(OptionCategory &C)
void setValueStr(StringRef S)
Definition: CommandLine.h:326
void setNumOccurrencesFlag(enum NumOccurrencesFlag Val)
Definition: CommandLine.h:327
void setNumAdditionalVals(unsigned n)
Definition: CommandLine.h:345
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void setDescription(StringRef S)
Definition: CommandLine.h:325
void setFormattingFlag(enum FormattingFlags V)
Definition: CommandLine.h:330
void setHiddenFlag(enum OptionHidden Val)
Definition: CommandLine.h:329
void setMiscFlag(enum MiscFlags M)
Definition: CommandLine.h:331
enum FormattingFlags getFormattingFlag() const
Definition: CommandLine.h:299
virtual void printOptionInfo(size_t GlobalWidth) const =0
enum NumOccurrencesFlag getNumOccurrencesFlag() const
Definition: CommandLine.h:287
SmallVector< OptionCategory *, 1 > Categories
Definition: CommandLine.h:284
bool isSink() const
Definition: CommandLine.h:310
void addSubCommand(SubCommand &S)
Definition: CommandLine.h:334
void setArgStr(StringRef S)
bool hasArgStr() const
Definition: CommandLine.h:308
bool isDefaultOption() const
Definition: CommandLine.h:311
unsigned getMiscFlags() const
Definition: CommandLine.h:303
virtual void setDefault()=0
virtual void printOptionValue(size_t GlobalWidth, bool Force) const =0
bool isInAllSubCommands() const
Definition: CommandLine.h:317
virtual ~Option()=default
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
unsigned getNumAdditionalVals() const
Definition: CommandLine.h:305
void removeArgument()
Unregisters this option from the CommandLine system.
Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden)
Definition: CommandLine.h:337
enum OptionHidden getOptionHiddenFlag() const
Definition: CommandLine.h:295
bool error(const Twine &Message, raw_ostream &Errs)
Definition: CommandLine.h:397
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
virtual size_t getOptionWidth() const =0
StringRef HelpStr
Definition: CommandLine.h:281
unsigned getPosition() const
Definition: CommandLine.h:304
StringRef getName() const
Definition: CommandLine.h:230
SubCommand(StringRef Name, StringRef Description="")
Definition: CommandLine.h:213
SmallVector< Option *, 4 > SinkOpts
Definition: CommandLine.h:234
static SubCommand & getTopLevel()
static SubCommand & getAll()
Option * ConsumeAfterOpt
Definition: CommandLine.h:237
SmallVector< Option *, 4 > PositionalOpts
Definition: CommandLine.h:233
StringMap< Option * > OptionsMap
Definition: CommandLine.h:235
StringRef getDescription() const
Definition: CommandLine.h:231
void apply(Opt &O) const
Definition: CommandLine.h:696
ValuesClass(std::initializer_list< OptionEnumValue > Options)
Definition: CommandLine.h:693
alias(const alias &)=delete
void setAliasFor(Option &O)
Definition: CommandLine.h:1951
alias & operator=(const alias &)=delete
alias(const Mods &... Ms)
Definition: CommandLine.h:1958
void printOptionInfo(const Option &O, size_t GlobalWidth) const
enum ValueExpected getValueExpectedFlagDefault() const
Definition: CommandLine.h:893
void getExtraOptionNames(SmallVectorImpl< StringRef > &)
Definition: CommandLine.h:897
virtual StringRef getValueName() const
Definition: CommandLine.h:913
virtual ~basic_parser_impl()=default
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
size_t getOptionWidth(const Option &O) const
void printOptionName(const Option &O, size_t GlobalWidth) const
OptionValue< DataType > OptVal
Definition: CommandLine.h:929
bool isSet(const T &V)
Definition: CommandLine.h:1797
void addValue(const T &V)
Definition: CommandLine.h:1783
bool setLocation(Option &O, unsigned &L)
Definition: CommandLine.h:1776
bits & operator=(const bits &)=delete
bits(const Mods &... Ms)
Definition: CommandLine.h:1888
ParserClass & getParser()
Definition: CommandLine.h:1880
unsigned getPosition(unsigned optnum) const
Definition: CommandLine.h:1882
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition: CommandLine.h:1894
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition: CommandLine.h:1899
bits(const bits &)=delete
GenericOptionInfo(StringRef name, StringRef helpStr)
Definition: CommandLine.h:725
virtual size_t getOptionWidth(const Option &O) const
virtual StringRef getDescription(unsigned N) const =0
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
virtual unsigned getNumOptions() const =0
virtual StringRef getOption(unsigned N) const =0
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
Definition: CommandLine.h:767
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
unsigned findOption(StringRef Name)
virtual ~generic_parser_base()=default
void getExtraOptionNames(SmallVectorImpl< StringRef > &OptionNames)
Definition: CommandLine.h:775
enum ValueExpected getValueExpectedFlagDefault() const
Definition: CommandLine.h:784
typename std::vector< DataType >::const_iterator const_iterator
Definition: CommandLine.h:1573
typename std::vector< DataType >::const_reference const_reference
Definition: CommandLine.h:1588
iterator erase(const_iterator first, const_iterator last)
Definition: CommandLine.h:1598
iterator insert(const_iterator pos, const DataType &value)
Definition: CommandLine.h:1607
iterator erase(iterator first, iterator last)
Definition: CommandLine.h:1603
const_reference operator[](size_type pos) const
Definition: CommandLine.h:1591
void addValue(const T &V, bool initial=false)
Definition: CommandLine.h:1629
void push_back(const DataType &value)
Definition: CommandLine.h:1584
typename std::vector< DataType >::reference reference
Definition: CommandLine.h:1587
reference operator[](size_type pos)
Definition: CommandLine.h:1590
const std::vector< DataType > * operator&() const
Definition: CommandLine.h:1627
iterator insert(iterator pos, const DataType &value)
Definition: CommandLine.h:1614
typename std::vector< DataType >::size_type size_type
Definition: CommandLine.h:1578
iterator insert(const_iterator pos, DataType &&value)
Definition: CommandLine.h:1610
std::vector< DataType > * operator&()
Definition: CommandLine.h:1626
const std::vector< OptionValue< DataType > > & getDefault() const
Definition: CommandLine.h:1635
iterator erase(const_iterator pos)
Definition: CommandLine.h:1597
iterator insert(iterator pos, DataType &&value)
Definition: CommandLine.h:1617
typename std::vector< DataType >::iterator iterator
Definition: CommandLine.h:1568
const std::vector< OptionValue< DataType > > & getDefault() const
Definition: CommandLine.h:1545
void addValue(const T &V, bool initial=false)
Definition: CommandLine.h:1536
bool setLocation(Option &O, StorageClass &L)
Definition: CommandLine.h:1529
list(const Mods &... Ms)
Definition: CommandLine.h:1732
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition: CommandLine.h:1738
list(const list &)=delete
void setInitialValues(ArrayRef< DataType > Vs)
Definition: CommandLine.h:1721
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition: CommandLine.h:1743
list & operator=(const list &)=delete
ParserClass & getParser()
Definition: CommandLine.h:1708
unsigned getPosition(unsigned optnum) const
Definition: CommandLine.h:1710
void setNumAdditionalVals(unsigned n)
Definition: CommandLine.h:1729
const OptionValue< DataType > & getDefault() const
Definition: CommandLine.h:1402
void setValue(const T &V, bool initial=false)
Definition: CommandLine.h:1394
void setValue(const T &V, bool initial=false)
Definition: CommandLine.h:1369
const OptionValue< DataType > & getDefault() const
Definition: CommandLine.h:1378
const DataType & getValue() const
Definition: CommandLine.h:1350
bool setLocation(Option &O, DataType &L)
Definition: CommandLine.h:1331
void setValue(const T &V, bool initial=false)
Definition: CommandLine.h:1339
const OptionValue< DataType > & getDefault() const
Definition: CommandLine.h:1357
DataType & getValue()
Definition: CommandLine.h:1346
ParserClass & getParser()
Definition: CommandLine.h:1483
opt & operator=(const opt &)=delete
void setInitialValue(const DataType &V)
Definition: CommandLine.h:1481
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition: CommandLine.h:1498
opt(const opt &)=delete
DataType & operator=(const T &Val)
Definition: CommandLine.h:1485
opt(const Mods &... Ms)
Definition: CommandLine.h:1492
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition: CommandLine.h:1503
OptionInfo(StringRef name, DataType v, StringRef helpStr)
Definition: CommandLine.h:821
OptionValue< DataType > V
Definition: CommandLine.h:824
bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val)
void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:977
enum ValueExpected getValueExpectedFlagDefault() const
Definition: CommandLine.h:972
enum ValueExpected getValueExpectedFlagDefault() const
Definition: CommandLine.h:947
void printOptionDiff(const Option &O, bool V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val)
StringRef getValueName() const override
Definition: CommandLine.h:952
void anchor() override
bool parse(Option &, StringRef, StringRef Arg, char &Value)
Definition: CommandLine.h:1190
void printOptionDiff(const Option &O, char V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:1196
void anchor() override
void printOptionDiff(const Option &O, double V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:1127
bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val)
bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val)
void anchor() override
StringRef getValueName() const override
Definition: CommandLine.h:1148
void printOptionDiff(const Option &O, float V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:998
void printOptionDiff(const Option &O, int V, OptVal Default, size_t GlobalWidth) const
void anchor() override
bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val)
StringRef getValueName() const override
Definition: CommandLine.h:1019
bool parse(Option &O, StringRef ArgName, StringRef Arg, long &Val)
void printOptionDiff(const Option &O, long V, OptVal Default, size_t GlobalWidth) const
void anchor() override
bool parse(Option &O, StringRef ArgName, StringRef Arg, long long &Val)
StringRef getValueName() const override
Definition: CommandLine.h:1040
void printOptionDiff(const Option &O, long long V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:1172
void printOptionDiff(const Option &O, StringRef V, const OptVal &Default, size_t GlobalWidth) const
bool parse(Option &, StringRef, StringRef Arg, std::string &Value)
Definition: CommandLine.h:1166
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val)
void printOptionDiff(const Option &O, unsigned V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
Definition: CommandLine.h:1061
StringRef getValueName() const override
Definition: CommandLine.h:1083
void printOptionDiff(const Option &O, unsigned long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val)
StringRef getValueName() const override
Definition: CommandLine.h:1106
void printOptionDiff(const Option &O, unsigned long long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long long &Val)
DataType parser_data_type
Definition: CommandLine.h:831
SmallVector< OptionInfo, 8 > Values
Definition: CommandLine.h:826
parser(Option &O)
Definition: CommandLine.h:829
void removeLiteralOption(StringRef Name)
Remove the specified option.
Definition: CommandLine.h:877
StringRef getDescription(unsigned N) const override
Definition: CommandLine.h:836
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
Add an entry to the mapping table.
Definition: CommandLine.h:865
const GenericOptionValue & getOptionValue(unsigned N) const override
Definition: CommandLine.h:841
StringRef getOption(unsigned N) const override
Definition: CommandLine.h:835
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
Definition: CommandLine.h:846
unsigned getNumOptions() const override
Definition: CommandLine.h:834
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
The virtual file system interface.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StorageClass
Definition: XCOFF.h:169
std::function< void(raw_ostream &)> VersionPrinterTy
Definition: CommandLine.h:76
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
Definition: CommandLine.h:2114
void PrintVersionMessage()
Utility function for printing version number.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a string of Windows command line arguments, which may contain quotes and escaped quotes.
list_initializer< Ty > list_init(ArrayRef< Ty > Vals)
Definition: CommandLine.h:450
OptionCategory & getGeneralCategory()
NumOccurrencesFlag
Definition: CommandLine.h:113
@ ConsumeAfter
Definition: CommandLine.h:126
@ ValueOptional
Definition: CommandLine.h:131
@ ValueDisallowed
Definition: CommandLine.h:133
@ ValueRequired
Definition: CommandLine.h:132
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
@ ReallyHidden
Definition: CommandLine.h:139
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
ManagedStatic< SubCommand > TopLevelSubCommand
void PrintOptionValues()
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
void apply(Opt *O, const Mod &M, const Mods &... Ms)
Definition: CommandLine.h:1303
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
Definition: CommandLine.h:1211
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:705
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
@ CommaSeparated
Definition: CommandLine.h:164
@ DefaultOption
Definition: CommandLine.h:175
@ PositionalEatsArgs
Definition: CommandLine.h:165
ManagedStatic< SubCommand > AllSubCommands
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:465
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
Definition: CommandLine.h:517
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
void PrintHelpMessage(bool Hidden=false, bool Categorized=false)
This function just prints the help message, exactly the same way as if the -help or -help-hidden opti...
void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
@ NormalFormatting
Definition: CommandLine.h:157
@ AlwaysPrefix
Definition: CommandLine.h:160
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1684
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Mod
The access may modify the value stored in memory.
@ Default
The result values are uniform if and only if all operands are uniform.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
Description of the encoding of one expression Op.
GenericOptionValue(const GenericOptionValue &)=default
GenericOptionValue & operator=(const GenericOptionValue &)=default
virtual bool compare(const GenericOptionValue &V) const =0
void apply(Opt &O) const
Definition: CommandLine.h:462
void print(const Option &O, const parser< DT > &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
Definition: CommandLine.h:1229
void print(const Option &O, const parser< ParserDT > &P, const ValDT &, const OptionValue< ValDT > &, size_t GlobalWidth)
Definition: CommandLine.h:1220
OptionValueBase & operator=(const OptionValueBase &)=default
OptionValueBase(const OptionValueBase &)=default
bool compare(const DataType &) const
Definition: CommandLine.h:556
const DataType & getValue() const
Definition: CommandLine.h:550
bool compare(const GenericOptionValue &) const override
Definition: CommandLine.h:558
OptionValue< DataType > WrapperType
Definition: CommandLine.h:546
void setValue(const DT &)
Definition: CommandLine.h:553
OptionValue< cl::boolOrDefault > & operator=(const cl::boolOrDefault &V)
Definition: CommandLine.h:641
OptionValue(const cl::boolOrDefault &V)
Definition: CommandLine.h:639
OptionValue< std::string > & operator=(const std::string &V)
Definition: CommandLine.h:658
OptionValue(const std::string &V)
Definition: CommandLine.h:656
OptionValue(const DataType &V)
Definition: CommandLine.h:621
OptionValue< DataType > & operator=(const DT &V)
Definition: CommandLine.h:624
void apply(alias &A) const
Definition: CommandLine.h:1971
aliasopt(Option &O)
Definition: CommandLine.h:1969
static void opt(FormattingFlags FF, Option &O)
Definition: CommandLine.h:1290
static void opt(MiscFlags MF, Option &O)
Definition: CommandLine.h:1294
static void opt(NumOccurrencesFlag N, Option &O)
Definition: CommandLine.h:1276
static void opt(OptionHidden OH, Option &O)
Definition: CommandLine.h:1286
static void opt(StringRef Str, Opt &O)
Definition: CommandLine.h:1270
static void opt(ValueExpected VE, Option &O)
Definition: CommandLine.h:1282
static void opt(StringRef Str, Opt &O)
Definition: CommandLine.h:1260
static void opt(StringRef Str, Opt &O)
Definition: CommandLine.h:1265
static void opt(const Mod &M, Opt &O)
Definition: CommandLine.h:1255
void apply(Opt &O) const
Definition: CommandLine.h:475
cat(OptionCategory &c)
Definition: CommandLine.h:473
OptionCategory & Category
Definition: CommandLine.h:471
void apply(Opt &O) const
Definition: CommandLine.h:494
cb(std::function< R(Ty)> CB)
Definition: CommandLine.h:492
std::function< R(Ty)> CB
Definition: CommandLine.h:490
desc(StringRef Str)
Definition: CommandLine.h:414
void apply(Option &O) const
Definition: CommandLine.h:416
StringRef Desc
Definition: CommandLine.h:412
std::tuple_element_t< 0, std::tuple< Args... > > arg_type
Definition: CommandLine.h:504
initializer(const Ty &Val)
Definition: CommandLine.h:433
void apply(Opt &O) const
Definition: CommandLine.h:435
list_initializer(ArrayRef< Ty > Vals)
Definition: CommandLine.h:440
void apply(Opt &O) const
Definition: CommandLine.h:442
multi_val(unsigned N)
Definition: CommandLine.h:1750
void apply(list< D, S, P > &L) const
Definition: CommandLine.h:1753
sub(SubCommand &S)
Definition: CommandLine.h:482
SubCommand & Sub
Definition: CommandLine.h:480
void apply(Opt &O) const
Definition: CommandLine.h:484
void apply(Option &O) const
Definition: CommandLine.h:425
value_desc(StringRef Str)
Definition: CommandLine.h:423