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 appear... 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,
89 enum MiscFlags { // Miscellaneous flags to adjust argument
90 CommaSeparated = 0x200, // Should this cl::list split between commas?
96 //===----------------------------------------------------------------------===//
101 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
104 // handleOccurances - Overriden by subclasses to handle the value passed into
105 // an argument. Should return true if there was an error processing the
106 // argument and the program should exit.
108 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0;
110 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
113 virtual enum ValueExpected getValueExpectedFlagDefault() const {
114 return ValueOptional;
116 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
119 virtual enum FormattingFlags getFormattingFlagDefault() const {
120 return NormalFormatting;
123 int NumOccurances; // The number of times specified
124 int Flags; // Flags for the argument
126 const char *ArgStr; // The argument string itself (ex: "help", "o")
127 const char *HelpStr; // The descriptive text message for --help
128 const char *ValueStr; // String describing what the value of this option is
130 inline enum NumOccurances getNumOccurancesFlag() const {
131 int NO = Flags & OccurancesMask;
132 return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
134 inline enum ValueExpected getValueExpectedFlag() const {
135 int VE = Flags & ValueMask;
136 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
138 inline enum OptionHidden getOptionHiddenFlag() const {
139 int OH = Flags & HiddenMask;
140 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
142 inline enum FormattingFlags getFormattingFlag() const {
143 int OH = Flags & FormattingMask;
144 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
146 inline unsigned getMiscFlags() const {
147 return Flags & MiscMask;
150 // hasArgStr - Return true if the argstr != ""
151 bool hasArgStr() const { return ArgStr[0] != 0; }
153 //-------------------------------------------------------------------------===
154 // Accessor functions set by OptionModifiers
156 void setArgStr(const char *S) { ArgStr = S; }
157 void setDescription(const char *S) { HelpStr = S; }
158 void setValueStr(const char *S) { ValueStr = S; }
160 void setFlag(unsigned Flag, unsigned FlagMask) {
161 if (Flags & FlagMask) {
162 error(": Specified two settings for the same option!");
169 void setNumOccurancesFlag(enum NumOccurances Val) {
170 setFlag(Val, OccurancesMask);
172 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
173 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
174 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
175 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
177 Option() : NumOccurances(0), Flags(0),
178 ArgStr(""), HelpStr(""), ValueStr("") {}
181 // addArgument - Tell the system that this Option subclass will handle all
182 // occurances of -ArgStr on the command line.
184 void addArgument(const char *ArgStr);
185 void removeArgument(const char *ArgStr);
187 // Return the width of the option tag for printing...
188 virtual unsigned getOptionWidth() const = 0;
190 // printOptionInfo - Print out information about this option. The
191 // to-be-maintained width is specified.
193 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
195 // addOccurance - Wrapper around handleOccurance that enforces Flags
197 bool addOccurance(const char *ArgName, const std::string &Value);
199 // Prints option name followed by message. Always returns true.
200 bool error(std::string Message, const char *ArgName = 0);
203 inline int getNumOccurances() const { return NumOccurances; }
208 //===----------------------------------------------------------------------===//
209 // Command line option modifiers that can be used to modify the behavior of
210 // command line option parsers...
213 // desc - Modifier to set the description shown in the --help output...
216 desc(const char *Str) : Desc(Str) {}
217 void apply(Option &O) const { O.setDescription(Desc); }
220 // value_desc - Modifier to set the value description shown in the --help
224 value_desc(const char *Str) : Desc(Str) {}
225 void apply(Option &O) const { O.setValueStr(Desc); }
229 // init - Specify a default (initial) value for the command line argument, if
230 // the default constructor for the argument type does not give you what you
231 // want. This is only valid on "opt" arguments, not on "list" arguments.
236 initializer(const Ty &Val) : Init(Val) {}
239 void apply(Opt &O) const { O.setInitialValue(Init); }
243 initializer<Ty> init(const Ty &Val) {
244 return initializer<Ty>(Val);
248 // location - Allow the user to specify which external variable they want to
249 // store the results of the command line argument processing into, if they don't
250 // want to store it in the option itself.
253 struct LocationClass {
255 LocationClass(Ty &L) : Loc(L) {}
258 void apply(Opt &O) const { O.setLocation(O, Loc); }
262 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
265 //===----------------------------------------------------------------------===//
266 // Enum valued command line option
268 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
269 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
271 // values - For custom data types, allow specifying a group of values together
272 // as the values that go into the mapping that the option handler uses. Note
273 // that the values list must always have a 0 at the end of the list to indicate
274 // that the list has ended.
276 template<class DataType>
278 // Use a vector instead of a map, because the lists should be short,
279 // the overhead is less, and most importantly, it keeps them in the order
280 // inserted so we can print our option out nicely.
281 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
282 void processValues(va_list Vals);
284 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
286 // Insert the first value, which is required.
287 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
289 // Process the varargs portion of the values...
290 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
291 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
292 const char *EnumDesc = va_arg(ValueArgs, const char *);
293 Values.push_back(std::make_pair(EnumName, // Add value to value map
294 std::make_pair(EnumVal, EnumDesc)));
299 void apply(Opt &O) const {
300 for (unsigned i = 0, e = Values.size(); i != e; ++i)
301 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
302 Values[i].second.second);
306 template<class DataType>
307 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
310 va_start(ValueArgs, Desc);
311 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
317 //===----------------------------------------------------------------------===//
318 // parser class - Parameterizable parser for different data types. By default,
319 // known data types (string, int, bool) have specialized parsers, that do what
320 // you would expect. The default parser, used for data types that are not
321 // built-in, uses a mapping table to map specific options to values, which is
322 // used, among other things, to handle enum types.
324 //--------------------------------------------------
325 // generic_parser_base - This class holds all the non-generic code that we do
326 // not need replicated for every instance of the generic parser. This also
327 // allows us to put stuff into CommandLine.cpp
329 struct generic_parser_base {
330 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
332 // getNumOptions - Virtual function implemented by generic subclass to
333 // indicate how many entries are in Values.
335 virtual unsigned getNumOptions() const = 0;
337 // getOption - Return option name N.
338 virtual const char *getOption(unsigned N) const = 0;
340 // getDescription - Return description N
341 virtual const char *getDescription(unsigned N) const = 0;
343 // Return the width of the option tag for printing...
344 virtual unsigned getOptionWidth(const Option &O) const;
346 // printOptionInfo - Print out information about this option. The
347 // to-be-maintained width is specified.
349 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
351 void initialize(Option &O) {
352 // All of the modifiers for the option have been processed by now, so the
353 // argstr field should be stable, copy it down now.
355 hasArgStr = O.hasArgStr();
357 // If there has been no argstr specified, that means that we need to add an
358 // argument for every possible option. This ensures that our options are
362 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
363 O.addArgument(getOption(i));
366 enum ValueExpected getValueExpectedFlagDefault() const {
367 // If there is an ArgStr specified, then we are of the form:
369 // -opt=O2 or -opt O2 or -optO2
371 // In which case, the value is required. Otherwise if an arg str has not
372 // been specified, we are of the form:
374 // -O2 or O2 or -la (where -l and -a are seperate options)
376 // If this is the case, we cannot allow a value.
379 return ValueRequired;
381 return ValueDisallowed;
384 // findOption - Return the option number corresponding to the specified
385 // argument string. If the option is not found, getNumOptions() is returned.
387 unsigned findOption(const char *Name);
393 // Default parser implementation - This implementation depends on having a
394 // mapping of recognized options to values of some sort. In addition to this,
395 // each entry in the mapping also tracks a help message that is printed with the
396 // command line option for --help. Because this is a simple mapping parser, the
397 // data type can be any unsupported type.
399 template <class DataType>
400 class parser : public generic_parser_base {
402 std::vector<std::pair<const char *,
403 std::pair<DataType, const char *> > > Values;
405 typedef DataType parser_data_type;
407 // Implement virtual functions needed by generic_parser_base
408 unsigned getNumOptions() const { return Values.size(); }
409 const char *getOption(unsigned N) const { return Values[N].first; }
410 const char *getDescription(unsigned N) const {
411 return Values[N].second.second;
414 // parse - Return true on error.
415 bool parse(Option &O, const char *ArgName, const std::string &Arg,
423 for (unsigned i = 0, e = Values.size(); i != e; ++i)
424 if (ArgVal == Values[i].first) {
425 V = Values[i].second.first;
429 return O.error(": Cannot find option named '" + ArgVal + "'!");
432 // addLiteralOption - Add an entry to the mapping table...
434 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
435 assert(findOption(Name) == Values.size() && "Option already exists!");
436 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
439 // removeLiteralOption - Remove the specified option.
441 void removeLiteralOption(const char *Name) {
442 unsigned N = findOption(Name);
443 assert(N != Values.size() && "Option not found!");
444 Values.erase(Values.begin()+N);
448 //--------------------------------------------------
449 // basic_parser - Super class of parsers to provide boilerplate code
451 struct basic_parser_impl { // non-template implementation of basic_parser<t>
452 virtual ~basic_parser_impl() {}
454 enum ValueExpected getValueExpectedFlagDefault() const {
455 return ValueRequired;
458 void initialize(Option &O) {}
460 // Return the width of the option tag for printing...
461 unsigned getOptionWidth(const Option &O) const;
463 // printOptionInfo - Print out information about this option. The
464 // to-be-maintained width is specified.
466 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
469 // getValueName - Overload in subclass to provide a better default value.
470 virtual const char *getValueName() const { return "value"; }
473 // basic_parser - The real basic parser is just a template wrapper that provides
474 // a typedef for the provided data type.
476 template<class DataType>
477 struct basic_parser : public basic_parser_impl {
478 typedef DataType parser_data_type;
482 //--------------------------------------------------
486 struct parser<bool> : public basic_parser<bool> {
488 // parse - Return true on error.
489 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
491 enum ValueExpected getValueExpectedFlagDefault() const {
492 return ValueOptional;
495 // getValueName - Do not print =<value> at all
496 virtual const char *getValueName() const { return 0; }
500 //--------------------------------------------------
504 struct parser<int> : public basic_parser<int> {
506 // parse - Return true on error.
507 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
509 // getValueName - Overload in subclass to provide a better default value.
510 virtual const char *getValueName() const { return "int"; }
514 //--------------------------------------------------
518 struct parser<double> : public basic_parser<double> {
519 // parse - Return true on error.
520 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
522 // getValueName - Overload in subclass to provide a better default value.
523 virtual const char *getValueName() const { return "number"; }
527 //--------------------------------------------------
531 struct parser<float> : public basic_parser<float> {
532 // parse - Return true on error.
533 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
535 // getValueName - Overload in subclass to provide a better default value.
536 virtual const char *getValueName() const { return "number"; }
540 //--------------------------------------------------
541 // parser<std::string>
544 struct parser<std::string> : public basic_parser<std::string> {
545 // parse - Return true on error.
546 bool parse(Option &O, const char *ArgName, const std::string &Arg,
547 std::string &Value) {
552 // getValueName - Overload in subclass to provide a better default value.
553 virtual const char *getValueName() const { return "string"; }
558 //===----------------------------------------------------------------------===//
559 // applicator class - This class is used because we must use partial
560 // specialization to handle literal string arguments specially (const char* does
561 // not correctly respond to the apply method). Because the syntax to use this
562 // is a pain, we have the 'apply' method below to handle the nastiness...
564 template<class Mod> struct applicator {
566 static void opt(const Mod &M, Opt &O) { M.apply(O); }
569 // Handle const char* as a special case...
570 template<unsigned n> struct applicator<char[n]> {
572 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
574 template<unsigned n> struct applicator<const char[n]> {
576 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
578 template<> struct applicator<const char*> {
580 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
583 template<> struct applicator<NumOccurances> {
584 static void opt(NumOccurances NO, Option &O) { O.setNumOccurancesFlag(NO); }
586 template<> struct applicator<ValueExpected> {
587 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
589 template<> struct applicator<OptionHidden> {
590 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
592 template<> struct applicator<FormattingFlags> {
593 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
595 template<> struct applicator<MiscFlags> {
596 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
599 // apply method - Apply a modifier to an option in a type safe way.
600 template<class Mod, class Opt>
601 void apply(const Mod &M, Opt *O) {
602 applicator<Mod>::opt(M, *O);
606 //===----------------------------------------------------------------------===//
609 // Default storage class definition: external storage. This implementation
610 // assumes the user will specify a variable to store the data into with the
611 // cl::location(x) modifier.
613 template<class DataType, bool ExternalStorage, bool isClass>
615 DataType *Location; // Where to store the object...
618 assert(Location != 0 && "cl::location(...) not specified for a command "
619 "line option with external storage!");
622 opt_storage() : Location(0) {}
624 bool setLocation(Option &O, DataType &L) {
626 return O.error(": cl::location(x) specified more than once!");
632 void setValue(const T &V) {
637 DataType &getValue() { check(); return *Location; }
638 const DataType &getValue() const { check(); return *Location; }
642 // Define how to hold a class type object, such as a string. Since we can
643 // inherit from a class, we do so. This makes us exactly compatible with the
644 // object in all cases that it is used.
646 template<class DataType>
647 struct opt_storage<DataType,false,true> : public DataType {
650 void setValue(const T &V) { DataType::operator=(V); }
652 DataType &getValue() { return *this; }
653 const DataType &getValue() const { return *this; }
656 // Define a partial specialization to handle things we cannot inherit from. In
657 // this case, we store an instance through containment, and overload operators
658 // to get at the value.
660 template<class DataType>
661 struct opt_storage<DataType, false, false> {
664 // Make sure we initialize the value with the default constructor for the
666 opt_storage() : Value(DataType()) {}
669 void setValue(const T &V) { Value = V; }
670 DataType &getValue() { return Value; }
671 DataType getValue() const { return Value; }
675 //===----------------------------------------------------------------------===//
676 // opt - A scalar command line option.
678 template <class DataType, bool ExternalStorage = false,
679 class ParserClass = parser<DataType> >
680 class opt : public Option,
681 public opt_storage<DataType, ExternalStorage,
682 ::boost::is_class<DataType>::value> {
685 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
686 typename ParserClass::parser_data_type Val;
687 if (Parser.parse(*this, ArgName, Arg, Val))
688 return true; // Parse error!
693 virtual enum ValueExpected getValueExpectedFlagDefault() const {
694 return Parser.getValueExpectedFlagDefault();
697 // Forward printing stuff to the parser...
698 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
699 virtual void printOptionInfo(unsigned GlobalWidth) const {
700 Parser.printOptionInfo(*this, GlobalWidth);
705 Parser.initialize(*this);
708 // setInitialValue - Used by the cl::init modifier...
709 void setInitialValue(const DataType &V) { setValue(V); }
711 ParserClass &getParser() { return Parser; }
713 operator DataType() const { return getValue(); }
716 DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
726 template<class M0t, class M1t>
727 opt(const M0t &M0, const M1t &M1) {
728 apply(M0, this); apply(M1, this);
733 template<class M0t, class M1t, class M2t>
734 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
735 apply(M0, this); apply(M1, this); apply(M2, this);
739 template<class M0t, class M1t, class M2t, class M3t>
740 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
741 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
745 template<class M0t, class M1t, class M2t, class M3t, class M4t>
746 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
748 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
753 template<class M0t, class M1t, class M2t, class M3t,
754 class M4t, class M5t>
755 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
756 const M4t &M4, const M5t &M5) {
757 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
758 apply(M4, this); apply(M5, this);
762 template<class M0t, class M1t, class M2t, class M3t,
763 class M4t, class M5t, class M6t>
764 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
765 const M4t &M4, const M5t &M5, const M6t &M6) {
766 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
767 apply(M4, this); apply(M5, this); apply(M6, this);
771 template<class M0t, class M1t, class M2t, class M3t,
772 class M4t, class M5t, class M6t, class M7t>
773 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
774 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
775 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
776 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
781 //===----------------------------------------------------------------------===//
782 // list_storage class
784 // Default storage class definition: external storage. This implementation
785 // assumes the user will specify a variable to store the data into with the
786 // cl::location(x) modifier.
788 template<class DataType, class StorageClass>
790 StorageClass *Location; // Where to store the object...
793 list_storage() : Location(0) {}
795 bool setLocation(Option &O, StorageClass &L) {
797 return O.error(": cl::location(x) specified more than once!");
803 void addValue(const T &V) {
804 assert(Location != 0 && "cl::location(...) not specified for a command "
805 "line option with external storage!");
806 Location->push_back(V);
811 // Define how to hold a class type object, such as a string. Since we can
812 // inherit from a class, we do so. This makes us exactly compatible with the
813 // object in all cases that it is used.
815 template<class DataType>
816 struct list_storage<DataType, bool> : public std::vector<DataType> {
819 void addValue(const T &V) { push_back(V); }
823 //===----------------------------------------------------------------------===//
824 // list - A list of command line options.
826 template <class DataType, class Storage = bool,
827 class ParserClass = parser<DataType> >
828 class list : public Option, public list_storage<DataType, Storage> {
831 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
834 virtual enum ValueExpected getValueExpectedFlagDefault() const {
835 return Parser.getValueExpectedFlagDefault();
838 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
839 typename ParserClass::parser_data_type Val;
840 if (Parser.parse(*this, ArgName, Arg, Val))
841 return true; // Parse Error!
846 // Forward printing stuff to the parser...
847 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
848 virtual void printOptionInfo(unsigned GlobalWidth) const {
849 Parser.printOptionInfo(*this, GlobalWidth);
854 Parser.initialize(*this);
857 ParserClass &getParser() { return Parser; }
861 list(const M0t &M0) {
866 template<class M0t, class M1t>
867 list(const M0t &M0, const M1t &M1) {
868 apply(M0, this); apply(M1, this);
872 template<class M0t, class M1t, class M2t>
873 list(const M0t &M0, const M1t &M1, const M2t &M2) {
874 apply(M0, this); apply(M1, this); apply(M2, this);
878 template<class M0t, class M1t, class M2t, class M3t>
879 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
880 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
884 template<class M0t, class M1t, class M2t, class M3t, class M4t>
885 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
887 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
892 template<class M0t, class M1t, class M2t, class M3t,
893 class M4t, class M5t>
894 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
895 const M4t &M4, const M5t &M5) {
896 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
897 apply(M4, this); apply(M5, this);
901 template<class M0t, class M1t, class M2t, class M3t,
902 class M4t, class M5t, class M6t>
903 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
904 const M4t &M4, const M5t &M5, const M6t &M6) {
905 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
906 apply(M4, this); apply(M5, this); apply(M6, this);
910 template<class M0t, class M1t, class M2t, class M3t,
911 class M4t, class M5t, class M6t, class M7t>
912 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
913 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
914 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
915 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
922 //===----------------------------------------------------------------------===//
923 // Aliased command line option (alias this name to a preexisting name)
926 class alias : public Option {
928 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
929 return AliasFor->handleOccurance(AliasFor->ArgStr, Arg);
931 // Aliases default to be hidden...
932 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
934 // Handle printing stuff...
935 virtual unsigned getOptionWidth() const;
936 virtual void printOptionInfo(unsigned GlobalWidth) const;
940 error(": cl::alias must have argument name specified!");
942 error(": cl::alias must have an cl::aliasopt(option) specified!");
946 void setAliasFor(Option &O) {
948 error(": cl::alias must only have one cl::aliasopt(...) specified!");
954 alias(const M0t &M0) : AliasFor(0) {
959 template<class M0t, class M1t>
960 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
961 apply(M0, this); apply(M1, this);
965 template<class M0t, class M1t, class M2t>
966 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
967 apply(M0, this); apply(M1, this); apply(M2, this);
971 template<class M0t, class M1t, class M2t, class M3t>
972 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
974 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
979 // aliasfor - Modifier to set the option an alias aliases.
982 aliasopt(Option &O) : Opt(O) {}
983 void apply(alias &A) const { A.setAliasFor(Opt); }
986 } // End namespace cl