1 //===- Support/CommandLine.h - Flexible Command line parser ------*- C++ -*--=//
3 // This class implements a command line argument processor that is useful when
4 // creating a tool. It provides a simple, minimalistic interface that is easily
5 // extensible and supports nonlocal (library) command line options.
7 // Note that rather than trying to figure out what this code does, you should
8 // read the library documentation located in docs/CommandLine.html or looks at
9 // the many example usages in tools/*/*.cpp
11 //===----------------------------------------------------------------------===//
13 #ifndef SUPPORT_COMMANDLINE_H
14 #define SUPPORT_COMMANDLINE_H
20 #include "boost/type_traits/object_traits.hpp"
22 /// cl Namespace - This namespace contains all of the command line option
23 /// processing machinery. It is intentionally a short name to make qualified
27 //===----------------------------------------------------------------------===//
28 // ParseCommandLineOptions - Command line option processing entry point.
30 void cl::ParseCommandLineOptions(int &argc, char **argv,
31 const char *Overview = 0);
33 //===----------------------------------------------------------------------===//
34 // Flags permitted to be passed to command line arguments
37 enum NumOccurrences { // Flags for the number of occurrences allowed
38 Optional = 0x01, // Zero or One occurrence
39 ZeroOrMore = 0x02, // Zero or more occurrences allowed
40 Required = 0x03, // One occurrence required
41 OneOrMore = 0x04, // One or more occurrences required
43 // ConsumeAfter - Indicates that this option is fed anything that follows the
44 // last positional argument required by the application (it is an error if
45 // there are zero positional arguments, and a ConsumeAfter option is used).
46 // Thus, for example, all arguments to LLI are processed until a filename is
47 // found. Once a filename is found, all of the succeeding arguments are
48 // passed, unprocessed, to the ConsumeAfter option.
52 OccurrencesMask = 0x07,
55 enum ValueExpected { // Is a value required for the option?
56 ValueOptional = 0x08, // The value can appear... or not
57 ValueRequired = 0x10, // The value is required to appear!
58 ValueDisallowed = 0x18, // A value may not be specified (for flags)
62 enum OptionHidden { // Control whether -help shows this option
63 NotHidden = 0x20, // Option included in --help & --help-hidden
64 Hidden = 0x40, // -help doesn't, but --help-hidden does
65 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
69 // Formatting flags - This controls special features that the option might have
70 // that cause it to be parsed differently...
72 // Prefix - This option allows arguments that are otherwise unrecognized to be
73 // matched by options that are a prefix of the actual value. This is useful for
74 // cases like a linker, where options are typically of the form '-lfoo' or
75 // '-L../../include' where -l or -L are the actual flags. When prefix is
76 // enabled, and used, the value for the flag comes from the suffix of the
79 // Grouping - With this option enabled, multiple letter options are allowed to
80 // bunch together with only a single hyphen for the whole group. This allows
81 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
84 enum FormattingFlags {
85 NormalFormatting = 0x000, // Nothing special
86 Positional = 0x080, // Is a positional argument, no '-' required
87 Prefix = 0x100, // Can this option directly prefix its value?
88 Grouping = 0x180, // Can this option group with other options?
89 FormattingMask = 0x180,
92 enum MiscFlags { // Miscellaneous flags to adjust argument
93 CommaSeparated = 0x200, // Should this cl::list split between commas?
99 //===----------------------------------------------------------------------===//
104 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
107 // handleOccurrences - Overriden by subclasses to handle the value passed into
108 // an argument. Should return true if there was an error processing the
109 // argument and the program should exit.
111 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) = 0;
113 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
116 virtual enum ValueExpected getValueExpectedFlagDefault() const {
117 return ValueOptional;
119 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
122 virtual enum FormattingFlags getFormattingFlagDefault() const {
123 return NormalFormatting;
126 int NumOccurrences; // The number of times specified
127 int Flags; // Flags for the argument
129 const char *ArgStr; // The argument string itself (ex: "help", "o")
130 const char *HelpStr; // The descriptive text message for --help
131 const char *ValueStr; // String describing what the value of this option is
133 inline enum NumOccurrences getNumOccurrencesFlag() const {
134 int NO = Flags & OccurrencesMask;
135 return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
137 inline enum ValueExpected getValueExpectedFlag() const {
138 int VE = Flags & ValueMask;
139 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
141 inline enum OptionHidden getOptionHiddenFlag() const {
142 int OH = Flags & HiddenMask;
143 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
145 inline enum FormattingFlags getFormattingFlag() const {
146 int OH = Flags & FormattingMask;
147 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
149 inline unsigned getMiscFlags() const {
150 return Flags & MiscMask;
153 // hasArgStr - Return true if the argstr != ""
154 bool hasArgStr() const { return ArgStr[0] != 0; }
156 //-------------------------------------------------------------------------===
157 // Accessor functions set by OptionModifiers
159 void setArgStr(const char *S) { ArgStr = S; }
160 void setDescription(const char *S) { HelpStr = S; }
161 void setValueStr(const char *S) { ValueStr = S; }
163 void setFlag(unsigned Flag, unsigned FlagMask) {
164 if (Flags & FlagMask) {
165 error(": Specified two settings for the same option!");
172 void setNumOccurrencesFlag(enum NumOccurrences Val) {
173 setFlag(Val, OccurrencesMask);
175 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
176 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
177 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
178 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
180 Option() : NumOccurrences(0), Flags(0),
181 ArgStr(""), HelpStr(""), ValueStr("") {}
184 // addArgument - Tell the system that this Option subclass will handle all
185 // occurrences of -ArgStr on the command line.
187 void addArgument(const char *ArgStr);
188 void removeArgument(const char *ArgStr);
190 // Return the width of the option tag for printing...
191 virtual unsigned getOptionWidth() const = 0;
193 // printOptionInfo - Print out information about this option. The
194 // to-be-maintained width is specified.
196 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
198 // addOccurrence - Wrapper around handleOccurrence that enforces Flags
200 bool addOccurrence(const char *ArgName, const std::string &Value);
202 // Prints option name followed by message. Always returns true.
203 bool error(std::string Message, const char *ArgName = 0);
206 inline int getNumOccurrences() const { return NumOccurrences; }
211 //===----------------------------------------------------------------------===//
212 // Command line option modifiers that can be used to modify the behavior of
213 // command line option parsers...
216 // desc - Modifier to set the description shown in the --help output...
219 desc(const char *Str) : Desc(Str) {}
220 void apply(Option &O) const { O.setDescription(Desc); }
223 // value_desc - Modifier to set the value description shown in the --help
227 value_desc(const char *Str) : Desc(Str) {}
228 void apply(Option &O) const { O.setValueStr(Desc); }
232 // init - Specify a default (initial) value for the command line argument, if
233 // the default constructor for the argument type does not give you what you
234 // want. This is only valid on "opt" arguments, not on "list" arguments.
239 initializer(const Ty &Val) : Init(Val) {}
242 void apply(Opt &O) const { O.setInitialValue(Init); }
246 initializer<Ty> init(const Ty &Val) {
247 return initializer<Ty>(Val);
251 // location - Allow the user to specify which external variable they want to
252 // store the results of the command line argument processing into, if they don't
253 // want to store it in the option itself.
256 struct LocationClass {
258 LocationClass(Ty &L) : Loc(L) {}
261 void apply(Opt &O) const { O.setLocation(O, Loc); }
265 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
268 //===----------------------------------------------------------------------===//
269 // Enum valued command line option
271 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
272 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
274 // values - For custom data types, allow specifying a group of values together
275 // as the values that go into the mapping that the option handler uses. Note
276 // that the values list must always have a 0 at the end of the list to indicate
277 // that the list has ended.
279 template<class DataType>
281 // Use a vector instead of a map, because the lists should be short,
282 // the overhead is less, and most importantly, it keeps them in the order
283 // inserted so we can print our option out nicely.
284 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
285 void processValues(va_list Vals);
287 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
289 // Insert the first value, which is required.
290 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
292 // Process the varargs portion of the values...
293 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
294 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
295 const char *EnumDesc = va_arg(ValueArgs, const char *);
296 Values.push_back(std::make_pair(EnumName, // Add value to value map
297 std::make_pair(EnumVal, EnumDesc)));
302 void apply(Opt &O) const {
303 for (unsigned i = 0, e = Values.size(); i != e; ++i)
304 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
305 Values[i].second.second);
309 template<class DataType>
310 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
313 va_start(ValueArgs, Desc);
314 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
320 //===----------------------------------------------------------------------===//
321 // parser class - Parameterizable parser for different data types. By default,
322 // known data types (string, int, bool) have specialized parsers, that do what
323 // you would expect. The default parser, used for data types that are not
324 // built-in, uses a mapping table to map specific options to values, which is
325 // used, among other things, to handle enum types.
327 //--------------------------------------------------
328 // generic_parser_base - This class holds all the non-generic code that we do
329 // not need replicated for every instance of the generic parser. This also
330 // allows us to put stuff into CommandLine.cpp
332 struct generic_parser_base {
333 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
335 // getNumOptions - Virtual function implemented by generic subclass to
336 // indicate how many entries are in Values.
338 virtual unsigned getNumOptions() const = 0;
340 // getOption - Return option name N.
341 virtual const char *getOption(unsigned N) const = 0;
343 // getDescription - Return description N
344 virtual const char *getDescription(unsigned N) const = 0;
346 // Return the width of the option tag for printing...
347 virtual unsigned getOptionWidth(const Option &O) const;
349 // printOptionInfo - Print out information about this option. The
350 // to-be-maintained width is specified.
352 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
354 void initialize(Option &O) {
355 // All of the modifiers for the option have been processed by now, so the
356 // argstr field should be stable, copy it down now.
358 hasArgStr = O.hasArgStr();
360 // If there has been no argstr specified, that means that we need to add an
361 // argument for every possible option. This ensures that our options are
365 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
366 O.addArgument(getOption(i));
369 enum ValueExpected getValueExpectedFlagDefault() const {
370 // If there is an ArgStr specified, then we are of the form:
372 // -opt=O2 or -opt O2 or -optO2
374 // In which case, the value is required. Otherwise if an arg str has not
375 // been specified, we are of the form:
377 // -O2 or O2 or -la (where -l and -a are separate options)
379 // If this is the case, we cannot allow a value.
382 return ValueRequired;
384 return ValueDisallowed;
387 // findOption - Return the option number corresponding to the specified
388 // argument string. If the option is not found, getNumOptions() is returned.
390 unsigned findOption(const char *Name);
396 // Default parser implementation - This implementation depends on having a
397 // mapping of recognized options to values of some sort. In addition to this,
398 // each entry in the mapping also tracks a help message that is printed with the
399 // command line option for --help. Because this is a simple mapping parser, the
400 // data type can be any unsupported type.
402 template <class DataType>
403 class parser : public generic_parser_base {
405 std::vector<std::pair<const char *,
406 std::pair<DataType, const char *> > > Values;
408 typedef DataType parser_data_type;
410 // Implement virtual functions needed by generic_parser_base
411 unsigned getNumOptions() const { return Values.size(); }
412 const char *getOption(unsigned N) const { return Values[N].first; }
413 const char *getDescription(unsigned N) const {
414 return Values[N].second.second;
417 // parse - Return true on error.
418 bool parse(Option &O, const char *ArgName, const std::string &Arg,
426 for (unsigned i = 0, e = Values.size(); i != e; ++i)
427 if (ArgVal == Values[i].first) {
428 V = Values[i].second.first;
432 return O.error(": Cannot find option named '" + ArgVal + "'!");
435 // addLiteralOption - Add an entry to the mapping table...
437 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
438 assert(findOption(Name) == Values.size() && "Option already exists!");
439 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
442 // removeLiteralOption - Remove the specified option.
444 void removeLiteralOption(const char *Name) {
445 unsigned N = findOption(Name);
446 assert(N != Values.size() && "Option not found!");
447 Values.erase(Values.begin()+N);
451 //--------------------------------------------------
452 // basic_parser - Super class of parsers to provide boilerplate code
454 struct basic_parser_impl { // non-template implementation of basic_parser<t>
455 virtual ~basic_parser_impl() {}
457 enum ValueExpected getValueExpectedFlagDefault() const {
458 return ValueRequired;
461 void initialize(Option &O) {}
463 // Return the width of the option tag for printing...
464 unsigned getOptionWidth(const Option &O) const;
466 // printOptionInfo - Print out information about this option. The
467 // to-be-maintained width is specified.
469 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
472 // getValueName - Overload in subclass to provide a better default value.
473 virtual const char *getValueName() const { return "value"; }
476 // basic_parser - The real basic parser is just a template wrapper that provides
477 // a typedef for the provided data type.
479 template<class DataType>
480 struct basic_parser : public basic_parser_impl {
481 typedef DataType parser_data_type;
485 //--------------------------------------------------
489 struct parser<bool> : public basic_parser<bool> {
491 // parse - Return true on error.
492 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
494 enum ValueExpected getValueExpectedFlagDefault() const {
495 return ValueOptional;
498 // getValueName - Do not print =<value> at all
499 virtual const char *getValueName() const { return 0; }
503 //--------------------------------------------------
507 struct parser<int> : public basic_parser<int> {
509 // parse - Return true on error.
510 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
512 // getValueName - Overload in subclass to provide a better default value.
513 virtual const char *getValueName() const { return "int"; }
517 //--------------------------------------------------
521 struct parser<unsigned> : public basic_parser<unsigned> {
523 // parse - Return true on error.
524 bool parse(Option &O, const char *ArgName, const std::string &Arg,
527 // getValueName - Overload in subclass to provide a better default value.
528 virtual const char *getValueName() const { return "uint"; }
532 //--------------------------------------------------
536 struct parser<double> : public basic_parser<double> {
537 // parse - Return true on error.
538 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
540 // getValueName - Overload in subclass to provide a better default value.
541 virtual const char *getValueName() const { return "number"; }
545 //--------------------------------------------------
549 struct parser<float> : public basic_parser<float> {
550 // parse - Return true on error.
551 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
553 // getValueName - Overload in subclass to provide a better default value.
554 virtual const char *getValueName() const { return "number"; }
558 //--------------------------------------------------
559 // parser<std::string>
562 struct parser<std::string> : public basic_parser<std::string> {
563 // parse - Return true on error.
564 bool parse(Option &O, const char *ArgName, const std::string &Arg,
565 std::string &Value) {
570 // getValueName - Overload in subclass to provide a better default value.
571 virtual const char *getValueName() const { return "string"; }
576 //===----------------------------------------------------------------------===//
577 // applicator class - This class is used because we must use partial
578 // specialization to handle literal string arguments specially (const char* does
579 // not correctly respond to the apply method). Because the syntax to use this
580 // is a pain, we have the 'apply' method below to handle the nastiness...
582 template<class Mod> struct applicator {
584 static void opt(const Mod &M, Opt &O) { M.apply(O); }
587 // Handle const char* as a special case...
588 template<unsigned n> struct applicator<char[n]> {
590 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
592 template<unsigned n> struct applicator<const char[n]> {
594 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
596 template<> struct applicator<const char*> {
598 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
601 template<> struct applicator<NumOccurrences> {
602 static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); }
604 template<> struct applicator<ValueExpected> {
605 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
607 template<> struct applicator<OptionHidden> {
608 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
610 template<> struct applicator<FormattingFlags> {
611 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
613 template<> struct applicator<MiscFlags> {
614 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
617 // apply method - Apply a modifier to an option in a type safe way.
618 template<class Mod, class Opt>
619 void apply(const Mod &M, Opt *O) {
620 applicator<Mod>::opt(M, *O);
624 //===----------------------------------------------------------------------===//
627 // Default storage class definition: external storage. This implementation
628 // assumes the user will specify a variable to store the data into with the
629 // cl::location(x) modifier.
631 template<class DataType, bool ExternalStorage, bool isClass>
633 DataType *Location; // Where to store the object...
636 assert(Location != 0 && "cl::location(...) not specified for a command "
637 "line option with external storage!");
640 opt_storage() : Location(0) {}
642 bool setLocation(Option &O, DataType &L) {
644 return O.error(": cl::location(x) specified more than once!");
650 void setValue(const T &V) {
655 DataType &getValue() { check(); return *Location; }
656 const DataType &getValue() const { check(); return *Location; }
660 // Define how to hold a class type object, such as a string. Since we can
661 // inherit from a class, we do so. This makes us exactly compatible with the
662 // object in all cases that it is used.
664 template<class DataType>
665 struct opt_storage<DataType,false,true> : public DataType {
668 void setValue(const T &V) { DataType::operator=(V); }
670 DataType &getValue() { return *this; }
671 const DataType &getValue() const { return *this; }
674 // Define a partial specialization to handle things we cannot inherit from. In
675 // this case, we store an instance through containment, and overload operators
676 // to get at the value.
678 template<class DataType>
679 struct opt_storage<DataType, false, false> {
682 // Make sure we initialize the value with the default constructor for the
684 opt_storage() : Value(DataType()) {}
687 void setValue(const T &V) { Value = V; }
688 DataType &getValue() { return Value; }
689 DataType getValue() const { return Value; }
693 //===----------------------------------------------------------------------===//
694 // opt - A scalar command line option.
696 template <class DataType, bool ExternalStorage = false,
697 class ParserClass = parser<DataType> >
698 class opt : public Option,
699 public opt_storage<DataType, ExternalStorage,
700 ::boost::is_class<DataType>::value> {
703 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
704 typename ParserClass::parser_data_type Val;
705 if (Parser.parse(*this, ArgName, Arg, Val))
706 return true; // Parse error!
711 virtual enum ValueExpected getValueExpectedFlagDefault() const {
712 return Parser.getValueExpectedFlagDefault();
715 // Forward printing stuff to the parser...
716 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
717 virtual void printOptionInfo(unsigned GlobalWidth) const {
718 Parser.printOptionInfo(*this, GlobalWidth);
723 Parser.initialize(*this);
726 // setInitialValue - Used by the cl::init modifier...
727 void setInitialValue(const DataType &V) { setValue(V); }
729 ParserClass &getParser() { return Parser; }
731 operator DataType() const { return getValue(); }
734 DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
744 template<class M0t, class M1t>
745 opt(const M0t &M0, const M1t &M1) {
746 apply(M0, this); apply(M1, this);
751 template<class M0t, class M1t, class M2t>
752 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
753 apply(M0, this); apply(M1, this); apply(M2, this);
757 template<class M0t, class M1t, class M2t, class M3t>
758 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
759 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
763 template<class M0t, class M1t, class M2t, class M3t, class M4t>
764 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
766 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
771 template<class M0t, class M1t, class M2t, class M3t,
772 class M4t, class M5t>
773 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
774 const M4t &M4, const M5t &M5) {
775 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
776 apply(M4, this); apply(M5, this);
780 template<class M0t, class M1t, class M2t, class M3t,
781 class M4t, class M5t, class M6t>
782 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
783 const M4t &M4, const M5t &M5, const M6t &M6) {
784 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
785 apply(M4, this); apply(M5, this); apply(M6, this);
789 template<class M0t, class M1t, class M2t, class M3t,
790 class M4t, class M5t, class M6t, class M7t>
791 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
792 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
793 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
794 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
799 //===----------------------------------------------------------------------===//
800 // list_storage class
802 // Default storage class definition: external storage. This implementation
803 // assumes the user will specify a variable to store the data into with the
804 // cl::location(x) modifier.
806 template<class DataType, class StorageClass>
808 StorageClass *Location; // Where to store the object...
811 list_storage() : Location(0) {}
813 bool setLocation(Option &O, StorageClass &L) {
815 return O.error(": cl::location(x) specified more than once!");
821 void addValue(const T &V) {
822 assert(Location != 0 && "cl::location(...) not specified for a command "
823 "line option with external storage!");
824 Location->push_back(V);
829 // Define how to hold a class type object, such as a string. Since we can
830 // inherit from a class, we do so. This makes us exactly compatible with the
831 // object in all cases that it is used.
833 template<class DataType>
834 struct list_storage<DataType, bool> : public std::vector<DataType> {
837 void addValue(const T &V) { push_back(V); }
841 //===----------------------------------------------------------------------===//
842 // list - A list of command line options.
844 template <class DataType, class Storage = bool,
845 class ParserClass = parser<DataType> >
846 class list : public Option, public list_storage<DataType, Storage> {
849 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
852 virtual enum ValueExpected getValueExpectedFlagDefault() const {
853 return Parser.getValueExpectedFlagDefault();
856 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
857 typename ParserClass::parser_data_type Val;
858 if (Parser.parse(*this, ArgName, Arg, Val))
859 return true; // Parse Error!
864 // Forward printing stuff to the parser...
865 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
866 virtual void printOptionInfo(unsigned GlobalWidth) const {
867 Parser.printOptionInfo(*this, GlobalWidth);
872 Parser.initialize(*this);
875 ParserClass &getParser() { return Parser; }
879 list(const M0t &M0) {
884 template<class M0t, class M1t>
885 list(const M0t &M0, const M1t &M1) {
886 apply(M0, this); apply(M1, this);
890 template<class M0t, class M1t, class M2t>
891 list(const M0t &M0, const M1t &M1, const M2t &M2) {
892 apply(M0, this); apply(M1, this); apply(M2, this);
896 template<class M0t, class M1t, class M2t, class M3t>
897 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
898 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
902 template<class M0t, class M1t, class M2t, class M3t, class M4t>
903 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
905 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
910 template<class M0t, class M1t, class M2t, class M3t,
911 class M4t, class M5t>
912 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
913 const M4t &M4, const M5t &M5) {
914 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
915 apply(M4, this); apply(M5, this);
919 template<class M0t, class M1t, class M2t, class M3t,
920 class M4t, class M5t, class M6t>
921 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
922 const M4t &M4, const M5t &M5, const M6t &M6) {
923 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
924 apply(M4, this); apply(M5, this); apply(M6, this);
928 template<class M0t, class M1t, class M2t, class M3t,
929 class M4t, class M5t, class M6t, class M7t>
930 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
931 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
932 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
933 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
940 //===----------------------------------------------------------------------===//
941 // Aliased command line option (alias this name to a preexisting name)
944 class alias : public Option {
946 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
947 return AliasFor->handleOccurrence(AliasFor->ArgStr, Arg);
949 // Aliases default to be hidden...
950 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
952 // Handle printing stuff...
953 virtual unsigned getOptionWidth() const;
954 virtual void printOptionInfo(unsigned GlobalWidth) const;
958 error(": cl::alias must have argument name specified!");
960 error(": cl::alias must have an cl::aliasopt(option) specified!");
964 void setAliasFor(Option &O) {
966 error(": cl::alias must only have one cl::aliasopt(...) specified!");
972 alias(const M0t &M0) : AliasFor(0) {
977 template<class M0t, class M1t>
978 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
979 apply(M0, this); apply(M1, this);
983 template<class M0t, class M1t, class M2t>
984 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
985 apply(M0, this); apply(M1, this); apply(M2, this);
989 template<class M0t, class M1t, class M2t, class M3t>
990 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
992 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
997 // aliasfor - Modifier to set the option an alias aliases.
1000 aliasopt(Option &O) : Opt(O) {}
1001 void apply(alias &A) const { A.setAliasFor(Opt); }
1004 } // End namespace cl