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"
23 /// cl Namespace - This namespace contains all of the command line option
24 /// processing machinery. It is intentionally a short name to make qualified
28 //===----------------------------------------------------------------------===//
29 // ParseCommandLineOptions - Command line option processing entry point.
31 void cl::ParseCommandLineOptions(int &argc, char **argv,
32 const char *Overview = 0);
34 //===----------------------------------------------------------------------===//
35 // Flags permitted to be passed to command line arguments
38 enum NumOccurances { // Flags for the number of occurances allowed...
39 Optional = 0x01, // Zero or One occurance
40 ZeroOrMore = 0x02, // Zero or more occurances allowed
41 Required = 0x03, // One occurance required
42 OneOrMore = 0x04, // One or more occurances required
44 // ConsumeAfter - Indicates that this option is fed anything that follows the
45 // last positional argument required by the application (it is an error if
46 // there are zero positional arguments, and a ConsumeAfter option is used).
47 // Thus, for example, all arguments to LLI are processed until a filename is
48 // found. Once a filename is found, all of the succeeding arguments are
49 // passed, unprocessed, to the ConsumeAfter option.
53 OccurancesMask = 0x07,
56 enum ValueExpected { // Is a value required for the option?
57 ValueOptional = 0x08, // The value can appear... or not
58 ValueRequired = 0x10, // The value is required to appear!
59 ValueDisallowed = 0x18, // A value may not be specified (for flags)
63 enum OptionHidden { // Control whether -help shows this option
64 NotHidden = 0x20, // Option included in --help & --help-hidden
65 Hidden = 0x40, // -help doesn't, but --help-hidden does
66 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
70 // Formatting flags - This controls special features that the option might have
71 // that cause it to be parsed differently...
73 // Prefix - This option allows arguments that are otherwise unrecognized to be
74 // matched by options that are a prefix of the actual value. This is useful for
75 // cases like a linker, where options are typically of the form '-lfoo' or
76 // '-L../../include' where -l or -L are the actual flags. When prefix is
77 // enabled, and used, the value for the flag comes from the suffix of the
80 // Grouping - With this option enabled, multiple letter options are allowed to
81 // bunch together with only a single hyphen for the whole group. This allows
82 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
85 enum FormattingFlags {
86 NormalFormatting = 0x000, // Nothing special
87 Positional = 0x080, // Is a positional argument, no '-' required
88 Prefix = 0x100, // Can this option directly prefix its value?
89 Grouping = 0x180, // Can this option group with other options?
90 FormattingMask = 0x180,
93 enum MiscFlags { // Miscellaneous flags to adjust argument
94 CommaSeparated = 0x200, // Should this cl::list split between commas?
100 //===----------------------------------------------------------------------===//
105 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
108 // handleOccurances - Overriden by subclasses to handle the value passed into
109 // an argument. Should return true if there was an error processing the
110 // argument and the program should exit.
112 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0;
114 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
117 virtual enum ValueExpected getValueExpectedFlagDefault() const {
118 return ValueOptional;
120 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
123 virtual enum FormattingFlags getFormattingFlagDefault() const {
124 return NormalFormatting;
127 int NumOccurances; // The number of times specified
128 int Flags; // Flags for the argument
130 const char *ArgStr; // The argument string itself (ex: "help", "o")
131 const char *HelpStr; // The descriptive text message for --help
132 const char *ValueStr; // String describing what the value of this option is
134 inline enum NumOccurances getNumOccurancesFlag() const {
135 int NO = Flags & OccurancesMask;
136 return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
138 inline enum ValueExpected getValueExpectedFlag() const {
139 int VE = Flags & ValueMask;
140 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
142 inline enum OptionHidden getOptionHiddenFlag() const {
143 int OH = Flags & HiddenMask;
144 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
146 inline enum FormattingFlags getFormattingFlag() const {
147 int OH = Flags & FormattingMask;
148 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
150 inline unsigned getMiscFlags() const {
151 return Flags & MiscMask;
154 // hasArgStr - Return true if the argstr != ""
155 bool hasArgStr() const { return ArgStr[0] != 0; }
157 //-------------------------------------------------------------------------===
158 // Accessor functions set by OptionModifiers
160 void setArgStr(const char *S) { ArgStr = S; }
161 void setDescription(const char *S) { HelpStr = S; }
162 void setValueStr(const char *S) { ValueStr = S; }
164 void setFlag(unsigned Flag, unsigned FlagMask) {
165 if (Flags & FlagMask) {
166 error(": Specified two settings for the same option!");
173 void setNumOccurancesFlag(enum NumOccurances Val) {
174 setFlag(Val, OccurancesMask);
176 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
177 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
178 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
179 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
181 Option() : NumOccurances(0), Flags(0),
182 ArgStr(""), HelpStr(""), ValueStr("") {}
185 // addArgument - Tell the system that this Option subclass will handle all
186 // occurances of -ArgStr on the command line.
188 void addArgument(const char *ArgStr);
189 void removeArgument(const char *ArgStr);
191 // Return the width of the option tag for printing...
192 virtual unsigned getOptionWidth() const = 0;
194 // printOptionInfo - Print out information about this option. The
195 // to-be-maintained width is specified.
197 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
199 // addOccurance - Wrapper around handleOccurance that enforces Flags
201 bool addOccurance(const char *ArgName, const std::string &Value);
203 // Prints option name followed by message. Always returns true.
204 bool error(std::string Message, const char *ArgName = 0);
207 inline int getNumOccurances() const { return NumOccurances; }
212 //===----------------------------------------------------------------------===//
213 // Command line option modifiers that can be used to modify the behavior of
214 // command line option parsers...
217 // desc - Modifier to set the description shown in the --help output...
220 desc(const char *Str) : Desc(Str) {}
221 void apply(Option &O) const { O.setDescription(Desc); }
224 // value_desc - Modifier to set the value description shown in the --help
228 value_desc(const char *Str) : Desc(Str) {}
229 void apply(Option &O) const { O.setValueStr(Desc); }
233 // init - Specify a default (initial) value for the command line argument, if
234 // the default constructor for the argument type does not give you what you
235 // want. This is only valid on "opt" arguments, not on "list" arguments.
240 initializer(const Ty &Val) : Init(Val) {}
243 void apply(Opt &O) const { O.setInitialValue(Init); }
247 initializer<Ty> init(const Ty &Val) {
248 return initializer<Ty>(Val);
252 // location - Allow the user to specify which external variable they want to
253 // store the results of the command line argument processing into, if they don't
254 // want to store it in the option itself.
257 struct LocationClass {
259 LocationClass(Ty &L) : Loc(L) {}
262 void apply(Opt &O) const { O.setLocation(O, Loc); }
266 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
269 //===----------------------------------------------------------------------===//
270 // Enum valued command line option
272 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
273 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
275 // values - For custom data types, allow specifying a group of values together
276 // as the values that go into the mapping that the option handler uses. Note
277 // that the values list must always have a 0 at the end of the list to indicate
278 // that the list has ended.
280 template<class DataType>
282 // Use a vector instead of a map, because the lists should be short,
283 // the overhead is less, and most importantly, it keeps them in the order
284 // inserted so we can print our option out nicely.
285 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
286 void processValues(va_list Vals);
288 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
290 // Insert the first value, which is required.
291 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
293 // Process the varargs portion of the values...
294 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
295 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
296 const char *EnumDesc = va_arg(ValueArgs, const char *);
297 Values.push_back(std::make_pair(EnumName, // Add value to value map
298 std::make_pair(EnumVal, EnumDesc)));
303 void apply(Opt &O) const {
304 for (unsigned i = 0, e = Values.size(); i != e; ++i)
305 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
306 Values[i].second.second);
310 template<class DataType>
311 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
314 va_start(ValueArgs, Desc);
315 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
321 //===----------------------------------------------------------------------===//
322 // parser class - Parameterizable parser for different data types. By default,
323 // known data types (string, int, bool) have specialized parsers, that do what
324 // you would expect. The default parser, used for data types that are not
325 // built-in, uses a mapping table to map specific options to values, which is
326 // used, among other things, to handle enum types.
328 //--------------------------------------------------
329 // generic_parser_base - This class holds all the non-generic code that we do
330 // not need replicated for every instance of the generic parser. This also
331 // allows us to put stuff into CommandLine.cpp
333 struct generic_parser_base {
334 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
336 // getNumOptions - Virtual function implemented by generic subclass to
337 // indicate how many entries are in Values.
339 virtual unsigned getNumOptions() const = 0;
341 // getOption - Return option name N.
342 virtual const char *getOption(unsigned N) const = 0;
344 // getDescription - Return description N
345 virtual const char *getDescription(unsigned N) const = 0;
347 // Return the width of the option tag for printing...
348 virtual unsigned getOptionWidth(const Option &O) const;
350 // printOptionInfo - Print out information about this option. The
351 // to-be-maintained width is specified.
353 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
355 void initialize(Option &O) {
356 // All of the modifiers for the option have been processed by now, so the
357 // argstr field should be stable, copy it down now.
359 hasArgStr = O.hasArgStr();
361 // If there has been no argstr specified, that means that we need to add an
362 // argument for every possible option. This ensures that our options are
366 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
367 O.addArgument(getOption(i));
370 enum ValueExpected getValueExpectedFlagDefault() const {
371 // If there is an ArgStr specified, then we are of the form:
373 // -opt=O2 or -opt O2 or -optO2
375 // In which case, the value is required. Otherwise if an arg str has not
376 // been specified, we are of the form:
378 // -O2 or O2 or -la (where -l and -a are seperate options)
380 // If this is the case, we cannot allow a value.
383 return ValueRequired;
385 return ValueDisallowed;
388 // findOption - Return the option number corresponding to the specified
389 // argument string. If the option is not found, getNumOptions() is returned.
391 unsigned findOption(const char *Name);
397 // Default parser implementation - This implementation depends on having a
398 // mapping of recognized options to values of some sort. In addition to this,
399 // each entry in the mapping also tracks a help message that is printed with the
400 // command line option for --help. Because this is a simple mapping parser, the
401 // data type can be any unsupported type.
403 template <class DataType>
404 class parser : public generic_parser_base {
406 std::vector<std::pair<const char *,
407 std::pair<DataType, const char *> > > Values;
409 typedef DataType parser_data_type;
411 // Implement virtual functions needed by generic_parser_base
412 unsigned getNumOptions() const { return Values.size(); }
413 const char *getOption(unsigned N) const { return Values[N].first; }
414 const char *getDescription(unsigned N) const {
415 return Values[N].second.second;
418 // parse - Return true on error.
419 bool parse(Option &O, const char *ArgName, const std::string &Arg,
427 for (unsigned i = 0, e = Values.size(); i != e; ++i)
428 if (ArgVal == Values[i].first) {
429 V = Values[i].second.first;
433 return O.error(": Cannot find option named '" + ArgVal + "'!");
436 // addLiteralOption - Add an entry to the mapping table...
438 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
439 assert(findOption(Name) == Values.size() && "Option already exists!");
440 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
443 // removeLiteralOption - Remove the specified option.
445 void removeLiteralOption(const char *Name) {
446 unsigned N = findOption(Name);
447 assert(N != Values.size() && "Option not found!");
448 Values.erase(Values.begin()+N);
452 //--------------------------------------------------
453 // basic_parser - Super class of parsers to provide boilerplate code
455 struct basic_parser_impl { // non-template implementation of basic_parser<t>
456 virtual ~basic_parser_impl() {}
458 enum ValueExpected getValueExpectedFlagDefault() const {
459 return ValueRequired;
462 void initialize(Option &O) {}
464 // Return the width of the option tag for printing...
465 unsigned getOptionWidth(const Option &O) const;
467 // printOptionInfo - Print out information about this option. The
468 // to-be-maintained width is specified.
470 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
473 // getValueName - Overload in subclass to provide a better default value.
474 virtual const char *getValueName() const { return "value"; }
477 // basic_parser - The real basic parser is just a template wrapper that provides
478 // a typedef for the provided data type.
480 template<class DataType>
481 struct basic_parser : public basic_parser_impl {
482 typedef DataType parser_data_type;
486 //--------------------------------------------------
490 struct parser<bool> : public basic_parser<bool> {
492 // parse - Return true on error.
493 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
495 enum ValueExpected getValueExpectedFlagDefault() const {
496 return ValueOptional;
499 // getValueName - Do not print =<value> at all
500 virtual const char *getValueName() const { return 0; }
504 //--------------------------------------------------
508 struct parser<int> : public basic_parser<int> {
510 // parse - Return true on error.
511 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
513 // getValueName - Overload in subclass to provide a better default value.
514 virtual const char *getValueName() const { return "int"; }
518 //--------------------------------------------------
522 struct parser<double> : public basic_parser<double> {
523 // parse - Return true on error.
524 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
526 // getValueName - Overload in subclass to provide a better default value.
527 virtual const char *getValueName() const { return "number"; }
531 //--------------------------------------------------
535 struct parser<float> : public basic_parser<float> {
536 // parse - Return true on error.
537 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
539 // getValueName - Overload in subclass to provide a better default value.
540 virtual const char *getValueName() const { return "number"; }
544 //--------------------------------------------------
545 // parser<std::string>
548 struct parser<std::string> : public basic_parser<std::string> {
549 // parse - Return true on error.
550 bool parse(Option &O, const char *ArgName, const std::string &Arg,
551 std::string &Value) {
556 // getValueName - Overload in subclass to provide a better default value.
557 virtual const char *getValueName() const { return "string"; }
562 //===----------------------------------------------------------------------===//
563 // applicator class - This class is used because we must use partial
564 // specialization to handle literal string arguments specially (const char* does
565 // not correctly respond to the apply method). Because the syntax to use this
566 // is a pain, we have the 'apply' method below to handle the nastiness...
568 template<class Mod> struct applicator {
570 static void opt(const Mod &M, Opt &O) { M.apply(O); }
573 // Handle const char* as a special case...
574 template<unsigned n> struct applicator<char[n]> {
576 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
578 template<unsigned n> struct applicator<const char[n]> {
580 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
582 template<> struct applicator<const char*> {
584 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
587 template<> struct applicator<NumOccurances> {
588 static void opt(NumOccurances NO, Option &O) { O.setNumOccurancesFlag(NO); }
590 template<> struct applicator<ValueExpected> {
591 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
593 template<> struct applicator<OptionHidden> {
594 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
596 template<> struct applicator<FormattingFlags> {
597 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
599 template<> struct applicator<MiscFlags> {
600 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
603 // apply method - Apply a modifier to an option in a type safe way.
604 template<class Mod, class Opt>
605 void apply(const Mod &M, Opt *O) {
606 applicator<Mod>::opt(M, *O);
610 //===----------------------------------------------------------------------===//
613 // Default storage class definition: external storage. This implementation
614 // assumes the user will specify a variable to store the data into with the
615 // cl::location(x) modifier.
617 template<class DataType, bool ExternalStorage, bool isClass>
619 DataType *Location; // Where to store the object...
622 assert(Location != 0 && "cl::location(...) not specified for a command "
623 "line option with external storage!");
626 opt_storage() : Location(0) {}
628 bool setLocation(Option &O, DataType &L) {
630 return O.error(": cl::location(x) specified more than once!");
636 void setValue(const T &V) {
641 DataType &getValue() { check(); return *Location; }
642 const DataType &getValue() const { check(); return *Location; }
646 // Define how to hold a class type object, such as a string. Since we can
647 // inherit from a class, we do so. This makes us exactly compatible with the
648 // object in all cases that it is used.
650 template<class DataType>
651 struct opt_storage<DataType,false,true> : public DataType {
654 void setValue(const T &V) { DataType::operator=(V); }
656 DataType &getValue() { return *this; }
657 const DataType &getValue() const { return *this; }
660 // Define a partial specialization to handle things we cannot inherit from. In
661 // this case, we store an instance through containment, and overload operators
662 // to get at the value.
664 template<class DataType>
665 struct opt_storage<DataType, false, false> {
668 // Make sure we initialize the value with the default constructor for the
670 opt_storage() : Value(DataType()) {}
673 void setValue(const T &V) { Value = V; }
674 DataType &getValue() { return Value; }
675 DataType getValue() const { return Value; }
679 //===----------------------------------------------------------------------===//
680 // opt - A scalar command line option.
682 template <class DataType, bool ExternalStorage = false,
683 class ParserClass = parser<DataType> >
684 class opt : public Option,
685 public opt_storage<DataType, ExternalStorage,
686 ::boost::is_class<DataType>::value> {
689 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
690 typename ParserClass::parser_data_type Val;
691 if (Parser.parse(*this, ArgName, Arg, Val))
692 return true; // Parse error!
697 virtual enum ValueExpected getValueExpectedFlagDefault() const {
698 return Parser.getValueExpectedFlagDefault();
701 // Forward printing stuff to the parser...
702 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
703 virtual void printOptionInfo(unsigned GlobalWidth) const {
704 Parser.printOptionInfo(*this, GlobalWidth);
709 Parser.initialize(*this);
712 // setInitialValue - Used by the cl::init modifier...
713 void setInitialValue(const DataType &V) { setValue(V); }
715 ParserClass &getParser() { return Parser; }
717 operator DataType() const { return getValue(); }
720 DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
730 template<class M0t, class M1t>
731 opt(const M0t &M0, const M1t &M1) {
732 apply(M0, this); apply(M1, this);
737 template<class M0t, class M1t, class M2t>
738 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
739 apply(M0, this); apply(M1, this); apply(M2, this);
743 template<class M0t, class M1t, class M2t, class M3t>
744 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
745 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
749 template<class M0t, class M1t, class M2t, class M3t, class M4t>
750 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
752 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
757 template<class M0t, class M1t, class M2t, class M3t,
758 class M4t, class M5t>
759 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
760 const M4t &M4, const M5t &M5) {
761 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
762 apply(M4, this); apply(M5, this);
766 template<class M0t, class M1t, class M2t, class M3t,
767 class M4t, class M5t, class M6t>
768 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
769 const M4t &M4, const M5t &M5, const M6t &M6) {
770 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
771 apply(M4, this); apply(M5, this); apply(M6, this);
775 template<class M0t, class M1t, class M2t, class M3t,
776 class M4t, class M5t, class M6t, class M7t>
777 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
778 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
779 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
780 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
785 //===----------------------------------------------------------------------===//
786 // list_storage class
788 // Default storage class definition: external storage. This implementation
789 // assumes the user will specify a variable to store the data into with the
790 // cl::location(x) modifier.
792 template<class DataType, class StorageClass>
794 StorageClass *Location; // Where to store the object...
797 list_storage() : Location(0) {}
799 bool setLocation(Option &O, StorageClass &L) {
801 return O.error(": cl::location(x) specified more than once!");
807 void addValue(const T &V) {
808 assert(Location != 0 && "cl::location(...) not specified for a command "
809 "line option with external storage!");
810 Location->push_back(V);
815 // Define how to hold a class type object, such as a string. Since we can
816 // inherit from a class, we do so. This makes us exactly compatible with the
817 // object in all cases that it is used.
819 template<class DataType>
820 struct list_storage<DataType, bool> : public std::vector<DataType> {
823 void addValue(const T &V) { push_back(V); }
827 //===----------------------------------------------------------------------===//
828 // list - A list of command line options.
830 template <class DataType, class Storage = bool,
831 class ParserClass = parser<DataType> >
832 class list : public Option, public list_storage<DataType, Storage> {
835 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
838 virtual enum ValueExpected getValueExpectedFlagDefault() const {
839 return Parser.getValueExpectedFlagDefault();
842 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
843 typename ParserClass::parser_data_type Val;
844 if (Parser.parse(*this, ArgName, Arg, Val))
845 return true; // Parse Error!
850 // Forward printing stuff to the parser...
851 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
852 virtual void printOptionInfo(unsigned GlobalWidth) const {
853 Parser.printOptionInfo(*this, GlobalWidth);
858 Parser.initialize(*this);
861 ParserClass &getParser() { return Parser; }
865 list(const M0t &M0) {
870 template<class M0t, class M1t>
871 list(const M0t &M0, const M1t &M1) {
872 apply(M0, this); apply(M1, this);
876 template<class M0t, class M1t, class M2t>
877 list(const M0t &M0, const M1t &M1, const M2t &M2) {
878 apply(M0, this); apply(M1, this); apply(M2, this);
882 template<class M0t, class M1t, class M2t, class M3t>
883 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
884 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
888 template<class M0t, class M1t, class M2t, class M3t, class M4t>
889 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
891 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
896 template<class M0t, class M1t, class M2t, class M3t,
897 class M4t, class M5t>
898 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
899 const M4t &M4, const M5t &M5) {
900 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
901 apply(M4, this); apply(M5, this);
905 template<class M0t, class M1t, class M2t, class M3t,
906 class M4t, class M5t, class M6t>
907 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
908 const M4t &M4, const M5t &M5, const M6t &M6) {
909 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
910 apply(M4, this); apply(M5, this); apply(M6, this);
914 template<class M0t, class M1t, class M2t, class M3t,
915 class M4t, class M5t, class M6t, class M7t>
916 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
917 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
918 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
919 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
926 //===----------------------------------------------------------------------===//
927 // Aliased command line option (alias this name to a preexisting name)
930 class alias : public Option {
932 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
933 return AliasFor->handleOccurance(AliasFor->ArgStr, Arg);
935 // Aliases default to be hidden...
936 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
938 // Handle printing stuff...
939 virtual unsigned getOptionWidth() const;
940 virtual void printOptionInfo(unsigned GlobalWidth) const;
944 error(": cl::alias must have argument name specified!");
946 error(": cl::alias must have an cl::aliasopt(option) specified!");
950 void setAliasFor(Option &O) {
952 error(": cl::alias must only have one cl::aliasopt(...) specified!");
958 alias(const M0t &M0) : AliasFor(0) {
963 template<class M0t, class M1t>
964 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
965 apply(M0, this); apply(M1, this);
969 template<class M0t, class M1t, class M2t>
970 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
971 apply(M0, this); apply(M1, this); apply(M2, this);
975 template<class M0t, class M1t, class M2t, class M3t>
976 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
978 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
983 // aliasfor - Modifier to set the option an alias aliases.
986 aliasopt(Option &O) : Opt(O) {}
987 void apply(alias &A) const { A.setAliasFor(Opt); }
990 } // End namespace cl