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 LLVM_SUPPORT_COMMANDLINE_H
14 #define LLVM_SUPPORT_COMMANDLINE_H
20 #include "boost/type_traits/object_traits.hpp"
22 namespace cl { // Short namespace to make usage concise
24 //===----------------------------------------------------------------------===//
25 // ParseCommandLineOptions - Command line option processing entry point.
27 void cl::ParseCommandLineOptions(int &argc, char **argv,
28 const char *Overview = 0);
30 //===----------------------------------------------------------------------===//
31 // Flags permitted to be passed to command line arguments
34 enum NumOccurances { // Flags for the number of occurances allowed...
35 Optional = 0x01, // Zero or One occurance
36 ZeroOrMore = 0x02, // Zero or more occurances allowed
37 Required = 0x03, // One occurance required
38 OneOrMore = 0x04, // One or more occurances required
40 // ConsumeAfter - Indicates that this option is fed anything that follows the
41 // last positional argument required by the application (it is an error if
42 // there are zero positional arguments, and a ConsumeAfter option is used).
43 // Thus, for example, all arguments to LLI are processed until a filename is
44 // found. Once a filename is found, all of the succeeding arguments are
45 // passed, unprocessed, to the ConsumeAfter option.
49 OccurancesMask = 0x07,
52 enum ValueExpected { // Is a value required for the option?
53 ValueOptional = 0x08, // The value can oppear... or not
54 ValueRequired = 0x10, // The value is required to appear!
55 ValueDisallowed = 0x18, // A value may not be specified (for flags)
59 enum OptionHidden { // Control whether -help shows this option
60 NotHidden = 0x20, // Option included in --help & --help-hidden
61 Hidden = 0x40, // -help doesn't, but --help-hidden does
62 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
66 // Formatting flags - This controls special features that the option might have
67 // that cause it to be parsed differently...
69 // Prefix - This option allows arguments that are otherwise unrecognized to be
70 // matched by options that are a prefix of the actual value. This is useful for
71 // cases like a linker, where options are typically of the form '-lfoo' or
72 // '-L../../include' where -l or -L are the actual flags. When prefix is
73 // enabled, and used, the value for the flag comes from the suffix of the
76 // Grouping - With this option enabled, multiple letter options are allowed to
77 // bunch together with only a single hyphen for the whole group. This allows
78 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
81 enum FormattingFlags {
82 NormalFormatting = 0x000, // Nothing special
83 Positional = 0x080, // Is a positional argument, no '-' required
84 Prefix = 0x100, // Can this option directly prefix its value?
85 Grouping = 0x180, // Can this option group with other options?
86 FormattingMask = 0x180,
90 //===----------------------------------------------------------------------===//
95 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
98 // handleOccurances - Overriden by subclasses to handle the value passed into
99 // an argument. Should return true if there was an error processing the
100 // argument and the program should exit.
102 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0;
104 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
107 virtual enum ValueExpected getValueExpectedFlagDefault() const {
108 return ValueOptional;
110 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
113 virtual enum FormattingFlags getFormattingFlagDefault() const {
114 return NormalFormatting;
117 int NumOccurances; // The number of times specified
118 int Flags; // Flags for the argument
120 const char *ArgStr; // The argument string itself (ex: "help", "o")
121 const char *HelpStr; // The descriptive text message for --help
122 const char *ValueStr; // String describing what the value of this option is
124 inline enum NumOccurances getNumOccurancesFlag() const {
125 int NO = Flags & OccurancesMask;
126 return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
128 inline enum ValueExpected getValueExpectedFlag() const {
129 int VE = Flags & ValueMask;
130 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
132 inline enum OptionHidden getOptionHiddenFlag() const {
133 int OH = Flags & HiddenMask;
134 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
136 inline enum FormattingFlags getFormattingFlag() const {
137 int OH = Flags & FormattingMask;
138 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
141 // hasArgStr - Return true if the argstr != ""
142 bool hasArgStr() const { return ArgStr[0] != 0; }
144 //-------------------------------------------------------------------------===
145 // Accessor functions set by OptionModifiers
147 void setArgStr(const char *S) { ArgStr = S; }
148 void setDescription(const char *S) { HelpStr = S; }
149 void setValueStr(const char *S) { ValueStr = S; }
151 void setFlag(unsigned Flag, unsigned FlagMask) {
152 if (Flags & FlagMask) {
153 error(": Specified two settings for the same option!");
160 void setNumOccurancesFlag(enum NumOccurances Val) {
161 setFlag(Val, OccurancesMask);
163 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
164 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
165 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
168 Option() : NumOccurances(0), Flags(0),
169 ArgStr(""), HelpStr(""), ValueStr("") {}
172 // addArgument - Tell the system that this Option subclass will handle all
173 // occurances of -ArgStr on the command line.
175 void addArgument(const char *ArgStr);
176 void removeArgument(const char *ArgStr);
178 // Return the width of the option tag for printing...
179 virtual unsigned getOptionWidth() const = 0;
181 // printOptionInfo - Print out information about this option. The
182 // to-be-maintained width is specified.
184 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
186 // addOccurance - Wrapper around handleOccurance that enforces Flags
188 bool addOccurance(const char *ArgName, const std::string &Value);
190 // Prints option name followed by message. Always returns true.
191 bool error(std::string Message, const char *ArgName = 0);
194 inline int getNumOccurances() const { return NumOccurances; }
199 //===----------------------------------------------------------------------===//
200 // Command line option modifiers that can be used to modify the behavior of
201 // command line option parsers...
204 // desc - Modifier to set the description shown in the --help output...
207 desc(const char *Str) : Desc(Str) {}
208 void apply(Option &O) const { O.setDescription(Desc); }
211 // value_desc - Modifier to set the value description shown in the --help
215 value_desc(const char *Str) : Desc(Str) {}
216 void apply(Option &O) const { O.setValueStr(Desc); }
220 // init - Specify a default (initial) value for the command line argument, if
221 // the default constructor for the argument type does not give you what you
222 // want. This is only valid on "opt" arguments, not on "list" arguments.
227 initializer(const Ty &Val) : Init(Val) {}
230 void apply(Opt &O) const { O.setInitialValue(Init); }
234 initializer<Ty> init(const Ty &Val) {
235 return initializer<Ty>(Val);
239 // location - Allow the user to specify which external variable they want to
240 // store the results of the command line argument processing into, if they don't
241 // want to store it in the option itself.
244 struct LocationClass {
246 LocationClass(Ty &L) : Loc(L) {}
249 void apply(Opt &O) const { O.setLocation(O, Loc); }
253 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
256 //===----------------------------------------------------------------------===//
257 // Enum valued command line option
259 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
260 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
262 // values - For custom data types, allow specifying a group of values together
263 // as the values that go into the mapping that the option handler uses. Note
264 // that the values list must always have a 0 at the end of the list to indicate
265 // that the list has ended.
267 template<class DataType>
269 // Use a vector instead of a map, because the lists should be short,
270 // the overhead is less, and most importantly, it keeps them in the order
271 // inserted so we can print our option out nicely.
272 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
273 void processValues(va_list Vals);
275 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
277 // Insert the first value, which is required.
278 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
280 // Process the varargs portion of the values...
281 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
282 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
283 const char *EnumDesc = va_arg(ValueArgs, const char *);
284 Values.push_back(std::make_pair(EnumName, // Add value to value map
285 std::make_pair(EnumVal, EnumDesc)));
290 void apply(Opt &O) const {
291 for (unsigned i = 0, e = Values.size(); i != e; ++i)
292 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
293 Values[i].second.second);
297 template<class DataType>
298 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
301 va_start(ValueArgs, Desc);
302 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
308 //===----------------------------------------------------------------------===//
309 // parser class - Parameterizable parser for different data types. By default,
310 // known data types (string, int, bool) have specialized parsers, that do what
311 // you would expect. The default parser, used for data types that are not
312 // built-in, uses a mapping table to map specific options to values, which is
313 // used, among other things, to handle enum types.
315 //--------------------------------------------------
316 // generic_parser_base - This class holds all the non-generic code that we do
317 // not need replicated for every instance of the generic parser. This also
318 // allows us to put stuff into CommandLine.cpp
320 struct generic_parser_base {
321 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
323 // getNumOptions - Virtual function implemented by generic subclass to
324 // indicate how many entries are in Values.
326 virtual unsigned getNumOptions() const = 0;
328 // getOption - Return option name N.
329 virtual const char *getOption(unsigned N) const = 0;
331 // getDescription - Return description N
332 virtual const char *getDescription(unsigned N) const = 0;
334 // Return the width of the option tag for printing...
335 virtual unsigned getOptionWidth(const Option &O) const;
337 // printOptionInfo - Print out information about this option. The
338 // to-be-maintained width is specified.
340 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
342 void initialize(Option &O) {
343 // All of the modifiers for the option have been processed by now, so the
344 // argstr field should be stable, copy it down now.
346 hasArgStr = O.hasArgStr();
348 // If there has been no argstr specified, that means that we need to add an
349 // argument for every possible option. This ensures that our options are
353 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
354 O.addArgument(getOption(i));
357 enum ValueExpected getValueExpectedFlagDefault() const {
358 // If there is an ArgStr specified, then we are of the form:
360 // -opt=O2 or -opt O2 or -optO2
362 // In which case, the value is required. Otherwise if an arg str has not
363 // been specified, we are of the form:
365 // -O2 or O2 or -la (where -l and -a are seperate options)
367 // If this is the case, we cannot allow a value.
370 return ValueRequired;
372 return ValueDisallowed;
379 // Default parser implementation - This implementation depends on having a
380 // mapping of recognized options to values of some sort. In addition to this,
381 // each entry in the mapping also tracks a help message that is printed with the
382 // command line option for --help. Because this is a simple mapping parser, the
383 // data type can be any unsupported type.
385 template <class DataType>
386 class parser : public generic_parser_base {
387 std::vector<std::pair<const char *,
388 std::pair<DataType, const char *> > > Values;
390 // Implement virtual functions needed by generic_parser_base
391 unsigned getNumOptions() const { return Values.size(); }
392 const char *getOption(unsigned N) const { return Values[N].first; }
393 const char *getDescription(unsigned N) const {
394 return Values[N].second.second;
398 // Default implementation, requires user to populate it with values somehow.
399 template<class Opt> // parse - Return true on error.
400 bool parse(Opt &O, const char *ArgName, const string &Arg) {
407 for (unsigned i = 0, e = Values.size(); i != e; ++i)
408 if (ArgVal == Values[i].first) {
409 O.addValue(Values[i].second.first);
413 return O.error(": Cannot find option named '" + ArgVal + "'!");
416 // addLiteralOption - Add an entry to the mapping table...
418 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
419 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
424 //--------------------------------------------------
429 static bool parseImpl(Option &O, const string &Arg, bool &Val);
432 template<class Opt> // parse - Return true on error.
433 bool parse(Opt &O, const char *ArgName, const string &Arg) {
435 bool Error = parseImpl(O, Arg, Val);
436 if (!Error) O.addValue(Val);
440 enum ValueExpected getValueExpectedFlagDefault() const {
441 return ValueOptional;
444 void initialize(Option &O) {}
446 // Return the width of the option tag for printing...
447 virtual unsigned getOptionWidth(const Option &O) const;
449 // printOptionInfo - Print out information about this option. The
450 // to-be-maintained width is specified.
452 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
456 //--------------------------------------------------
461 static bool parseImpl(Option &O, const string &Arg, int &Val);
464 // parse - Return true on error.
466 bool parse(Opt &O, const char *ArgName, const string &Arg) {
468 bool Error = parseImpl(O, Arg, Val);
469 if (!Error) O.addValue(Val);
473 enum ValueExpected getValueExpectedFlagDefault() const {
474 return ValueRequired;
477 void initialize(Option &O) {}
479 // Return the width of the option tag for printing...
480 virtual unsigned getOptionWidth(const Option &O) const;
482 // printOptionInfo - Print out information about this option. The
483 // to-be-maintained width is specified.
485 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
489 //--------------------------------------------------
493 class parser<double> {
494 static bool parseImpl(Option &O, const string &Arg, double &Val);
497 // parse - Return true on error.
499 bool parse(Opt &O, const char *ArgName, const string &Arg) {
501 bool Error = parseImpl(O, Arg, Val);
502 if (!Error) O.addValue(Val);
506 enum ValueExpected getValueExpectedFlagDefault() const {
507 return ValueRequired;
510 void initialize(Option &O) {}
512 // Return the width of the option tag for printing...
513 virtual unsigned getOptionWidth(const Option &O) const;
515 // printOptionInfo - Print out information about this option. The
516 // to-be-maintained width is specified.
518 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
521 // Parser<float> is the same as parser<double>
522 template<> struct parser<float> : public parser<double> {};
526 //--------------------------------------------------
530 struct parser<string> {
531 // parse - Return true on error.
533 bool parse(Opt &O, const char *ArgName, const string &Arg) {
537 enum ValueExpected getValueExpectedFlagDefault() const {
538 return ValueRequired;
541 void initialize(Option &O) {}
543 // Return the width of the option tag for printing...
544 virtual unsigned getOptionWidth(const Option &O) const;
546 // printOptionInfo - Print out information about this option. The
547 // to-be-maintained width is specified.
549 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
554 //===----------------------------------------------------------------------===//
555 // applicator class - This class is used because we must use partial
556 // specialization to handle literal string arguments specially (const char* does
557 // not correctly respond to the apply method). Because the syntax to use this
558 // is a pain, we have the 'apply' method below to handle the nastiness...
560 template<class Mod> struct applicator {
562 static void opt(const Mod &M, Opt &O) { M.apply(O); }
565 // Handle const char* as a special case...
566 template<unsigned n> struct applicator<char[n]> {
568 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
570 template<> struct applicator<const char*> {
572 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
575 template<> struct applicator<NumOccurances> {
576 static void opt(NumOccurances NO, Option &O) { O.setNumOccurancesFlag(NO); }
578 template<> struct applicator<ValueExpected> {
579 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
581 template<> struct applicator<OptionHidden> {
582 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
584 template<> struct applicator<FormattingFlags> {
585 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
588 // apply method - Apply a modifier to an option in a type safe way.
589 template<class Mod, class Opt>
590 void apply(const Mod &M, Opt *O) {
591 applicator<Mod>::opt(M, *O);
595 //===----------------------------------------------------------------------===//
598 // Default storage class definition: external storage. This implementation
599 // assumes the user will specify a variable to store the data into with the
600 // cl::location(x) modifier.
602 template<class DataType, bool ExternalStorage, bool isClass>
604 DataType *Location; // Where to store the object...
607 assert(Location != 0 && "cl::location(...) not specified for a command "
608 "line option with external storage!");
611 opt_storage() : Location(0) {}
613 bool setLocation(Option &O, DataType &L) {
615 return O.error(": cl::location(x) specified more than once!");
621 void setValue(const T &V) {
626 DataType &getValue() { check(); return *Location; }
627 const DataType &getValue() const { check(); return *Location; }
631 // Define how to hold a class type object, such as a string. Since we can
632 // inherit from a class, we do so. This makes us exactly compatible with the
633 // object in all cases that it is used.
635 template<class DataType>
636 struct opt_storage<DataType,false,true> : public DataType {
639 void setValue(const T &V) { DataType::operator=(V); }
641 DataType &getValue() { return *this; }
642 const DataType &getValue() const { return *this; }
645 // Define a partial specialization to handle things we cannot inherit from. In
646 // this case, we store an instance through containment, and overload operators
647 // to get at the value.
649 template<class DataType>
650 struct opt_storage<DataType, false, false> {
653 // Make sure we initialize the value with the default constructor for the
655 opt_storage() : Value(DataType()) {}
658 void setValue(const T &V) { Value = V; }
659 DataType &getValue() { return Value; }
660 DataType getValue() const { return Value; }
664 //===----------------------------------------------------------------------===//
665 // opt - A scalar command line option.
667 template <class DataType, bool ExternalStorage = false,
668 class ParserClass = parser<DataType> >
669 class opt : public Option,
670 public opt_storage<DataType, ExternalStorage,
671 ::boost::is_class<DataType>::value>{
674 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
675 return Parser.parse(*this, ArgName, Arg);
678 virtual enum ValueExpected getValueExpectedFlagDefault() const {
679 return Parser.getValueExpectedFlagDefault();
682 // Forward printing stuff to the parser...
683 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
684 virtual void printOptionInfo(unsigned GlobalWidth) const {
685 Parser.printOptionInfo(*this, GlobalWidth);
690 Parser.initialize(*this);
693 // setInitialValue - Used by the cl::init modifier...
694 void setInitialValue(const DataType &V) { setValue(V); }
696 // addValue - Used by the parser to add a value to the option
698 void addValue(const T &V) { setValue(V); }
699 ParserClass &getParser() { return Parser; }
701 operator DataType() const { return getValue(); }
704 DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
714 template<class M0t, class M1t>
715 opt(const M0t &M0, const M1t &M1) {
716 apply(M0, this); apply(M1, this);
721 template<class M0t, class M1t, class M2t>
722 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
723 apply(M0, this); apply(M1, this); apply(M2, this);
727 template<class M0t, class M1t, class M2t, class M3t>
728 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
729 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
733 template<class M0t, class M1t, class M2t, class M3t, class M4t>
734 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
736 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
741 template<class M0t, class M1t, class M2t, class M3t,
742 class M4t, class M5t>
743 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
744 const M4t &M4, const M5t &M5) {
745 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
746 apply(M4, this); apply(M5, this);
750 template<class M0t, class M1t, class M2t, class M3t,
751 class M4t, class M5t, class M6t>
752 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
753 const M4t &M4, const M5t &M5, const M6t &M6) {
754 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
755 apply(M4, this); apply(M5, this); apply(M6, this);
759 template<class M0t, class M1t, class M2t, class M3t,
760 class M4t, class M5t, class M6t, class M7t>
761 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
762 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
763 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
764 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
769 //===----------------------------------------------------------------------===//
770 // list_storage class
772 // Default storage class definition: external storage. This implementation
773 // assumes the user will specify a variable to store the data into with the
774 // cl::location(x) modifier.
776 template<class DataType, class StorageClass>
778 StorageClass *Location; // Where to store the object...
781 list_storage() : Location(0) {}
783 bool setLocation(Option &O, StorageClass &L) {
785 return O.error(": cl::location(x) specified more than once!");
791 void addValue(const T &V) {
792 assert(Location != 0 && "cl::location(...) not specified for a command "
793 "line option with external storage!");
794 Location->push_back(V);
799 // Define how to hold a class type object, such as a string. Since we can
800 // inherit from a class, we do so. This makes us exactly compatible with the
801 // object in all cases that it is used.
803 template<class DataType>
804 struct list_storage<DataType, bool> : public std::vector<DataType> {
807 void addValue(const T &V) { push_back(V); }
811 //===----------------------------------------------------------------------===//
812 // list - A list of command line options.
814 template <class DataType, class Storage = bool,
815 class ParserClass = parser<DataType> >
816 class list : public Option, public list_storage<DataType, Storage> {
819 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
822 virtual enum ValueExpected getValueExpectedFlagDefault() const {
823 return Parser.getValueExpectedFlagDefault();
826 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
827 return Parser.parse(*this, ArgName, Arg);
830 // Forward printing stuff to the parser...
831 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
832 virtual void printOptionInfo(unsigned GlobalWidth) const {
833 Parser.printOptionInfo(*this, GlobalWidth);
838 Parser.initialize(*this);
841 ParserClass &getParser() { return Parser; }
845 list(const M0t &M0) {
850 template<class M0t, class M1t>
851 list(const M0t &M0, const M1t &M1) {
852 apply(M0, this); apply(M1, this);
856 template<class M0t, class M1t, class M2t>
857 list(const M0t &M0, const M1t &M1, const M2t &M2) {
858 apply(M0, this); apply(M1, this); apply(M2, this);
862 template<class M0t, class M1t, class M2t, class M3t>
863 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
864 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
868 template<class M0t, class M1t, class M2t, class M3t, class M4t>
869 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
871 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
876 template<class M0t, class M1t, class M2t, class M3t,
877 class M4t, class M5t>
878 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
879 const M4t &M4, const M5t &M5) {
880 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
881 apply(M4, this); apply(M5, this);
885 template<class M0t, class M1t, class M2t, class M3t,
886 class M4t, class M5t, class M6t>
887 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
888 const M4t &M4, const M5t &M5, const M6t &M6) {
889 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
890 apply(M4, this); apply(M5, this); apply(M6, this);
894 template<class M0t, class M1t, class M2t, class M3t,
895 class M4t, class M5t, class M6t, class M7t>
896 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
897 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
898 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
899 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
906 //===----------------------------------------------------------------------===//
907 // Aliased command line option (alias this name to a preexisting name)
910 class alias : public Option {
912 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
913 return AliasFor->handleOccurance(AliasFor->ArgStr, Arg);
915 // Aliases default to be hidden...
916 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
918 // Handle printing stuff...
919 virtual unsigned getOptionWidth() const;
920 virtual void printOptionInfo(unsigned GlobalWidth) const;
924 error(": cl::alias must have argument name specified!");
926 error(": cl::alias must have an cl::aliasopt(option) specified!");
930 void setAliasFor(Option &O) {
932 error(": cl::alias must only have one cl::aliasopt(...) specified!");
938 alias(const M0t &M0) : AliasFor(0) {
943 template<class M0t, class M1t>
944 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
945 apply(M0, this); apply(M1, this);
949 template<class M0t, class M1t, class M2t>
950 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
951 apply(M0, this); apply(M1, this); apply(M2, this);
955 template<class M0t, class M1t, class M2t, class M3t>
956 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
958 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
963 // aliasfor - Modifier to set the option an alias aliases.
966 aliasopt(Option &O) : Opt(O) {}
967 void apply(alias &A) const { A.setAliasFor(Opt); }
970 } // End namespace cl