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"
24 /// cl Namespace - This namespace contains all of the command line option
25 /// processing machinery. It is intentionally a short name to make qualified
29 //===----------------------------------------------------------------------===//
30 // ParseCommandLineOptions - Command line option processing entry point.
32 void cl::ParseCommandLineOptions(int &argc, char **argv,
33 const char *Overview = 0);
35 //===----------------------------------------------------------------------===//
36 // Flags permitted to be passed to command line arguments
39 enum NumOccurances { // Flags for the number of occurances allowed...
40 Optional = 0x01, // Zero or One occurance
41 ZeroOrMore = 0x02, // Zero or more occurances allowed
42 Required = 0x03, // One occurance required
43 OneOrMore = 0x04, // One or more occurances required
45 // ConsumeAfter - Indicates that this option is fed anything that follows the
46 // last positional argument required by the application (it is an error if
47 // there are zero positional arguments, and a ConsumeAfter option is used).
48 // Thus, for example, all arguments to LLI are processed until a filename is
49 // found. Once a filename is found, all of the succeeding arguments are
50 // passed, unprocessed, to the ConsumeAfter option.
54 OccurancesMask = 0x07,
57 enum ValueExpected { // Is a value required for the option?
58 ValueOptional = 0x08, // The value can appear... or not
59 ValueRequired = 0x10, // The value is required to appear!
60 ValueDisallowed = 0x18, // A value may not be specified (for flags)
64 enum OptionHidden { // Control whether -help shows this option
65 NotHidden = 0x20, // Option included in --help & --help-hidden
66 Hidden = 0x40, // -help doesn't, but --help-hidden does
67 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
71 // Formatting flags - This controls special features that the option might have
72 // that cause it to be parsed differently...
74 // Prefix - This option allows arguments that are otherwise unrecognized to be
75 // matched by options that are a prefix of the actual value. This is useful for
76 // cases like a linker, where options are typically of the form '-lfoo' or
77 // '-L../../include' where -l or -L are the actual flags. When prefix is
78 // enabled, and used, the value for the flag comes from the suffix of the
81 // Grouping - With this option enabled, multiple letter options are allowed to
82 // bunch together with only a single hyphen for the whole group. This allows
83 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
86 enum FormattingFlags {
87 NormalFormatting = 0x000, // Nothing special
88 Positional = 0x080, // Is a positional argument, no '-' required
89 Prefix = 0x100, // Can this option directly prefix its value?
90 Grouping = 0x180, // Can this option group with other options?
91 FormattingMask = 0x180,
94 enum MiscFlags { // Miscellaneous flags to adjust argument
95 CommaSeparated = 0x200, // Should this cl::list split between commas?
101 //===----------------------------------------------------------------------===//
106 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
109 // handleOccurances - Overriden by subclasses to handle the value passed into
110 // an argument. Should return true if there was an error processing the
111 // argument and the program should exit.
113 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0;
115 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
118 virtual enum ValueExpected getValueExpectedFlagDefault() const {
119 return ValueOptional;
121 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
124 virtual enum FormattingFlags getFormattingFlagDefault() const {
125 return NormalFormatting;
128 int NumOccurances; // The number of times specified
129 int Flags; // Flags for the argument
131 const char *ArgStr; // The argument string itself (ex: "help", "o")
132 const char *HelpStr; // The descriptive text message for --help
133 const char *ValueStr; // String describing what the value of this option is
135 inline enum NumOccurances getNumOccurancesFlag() const {
136 int NO = Flags & OccurancesMask;
137 return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
139 inline enum ValueExpected getValueExpectedFlag() const {
140 int VE = Flags & ValueMask;
141 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
143 inline enum OptionHidden getOptionHiddenFlag() const {
144 int OH = Flags & HiddenMask;
145 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
147 inline enum FormattingFlags getFormattingFlag() const {
148 int OH = Flags & FormattingMask;
149 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
151 inline unsigned getMiscFlags() const {
152 return Flags & MiscMask;
155 // hasArgStr - Return true if the argstr != ""
156 bool hasArgStr() const { return ArgStr[0] != 0; }
158 //-------------------------------------------------------------------------===
159 // Accessor functions set by OptionModifiers
161 void setArgStr(const char *S) { ArgStr = S; }
162 void setDescription(const char *S) { HelpStr = S; }
163 void setValueStr(const char *S) { ValueStr = S; }
165 void setFlag(unsigned Flag, unsigned FlagMask) {
166 if (Flags & FlagMask) {
167 error(": Specified two settings for the same option!");
174 void setNumOccurancesFlag(enum NumOccurances Val) {
175 setFlag(Val, OccurancesMask);
177 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
178 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
179 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
180 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
182 Option() : NumOccurances(0), Flags(0),
183 ArgStr(""), HelpStr(""), ValueStr("") {}
186 // addArgument - Tell the system that this Option subclass will handle all
187 // occurances of -ArgStr on the command line.
189 void addArgument(const char *ArgStr);
190 void removeArgument(const char *ArgStr);
192 // Return the width of the option tag for printing...
193 virtual unsigned getOptionWidth() const = 0;
195 // printOptionInfo - Print out information about this option. The
196 // to-be-maintained width is specified.
198 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
200 // addOccurance - Wrapper around handleOccurance that enforces Flags
202 bool addOccurance(const char *ArgName, const std::string &Value);
204 // Prints option name followed by message. Always returns true.
205 bool error(std::string Message, const char *ArgName = 0);
208 inline int getNumOccurances() const { return NumOccurances; }
213 //===----------------------------------------------------------------------===//
214 // Command line option modifiers that can be used to modify the behavior of
215 // command line option parsers...
218 // desc - Modifier to set the description shown in the --help output...
221 desc(const char *Str) : Desc(Str) {}
222 void apply(Option &O) const { O.setDescription(Desc); }
225 // value_desc - Modifier to set the value description shown in the --help
229 value_desc(const char *Str) : Desc(Str) {}
230 void apply(Option &O) const { O.setValueStr(Desc); }
234 // init - Specify a default (initial) value for the command line argument, if
235 // the default constructor for the argument type does not give you what you
236 // want. This is only valid on "opt" arguments, not on "list" arguments.
241 initializer(const Ty &Val) : Init(Val) {}
244 void apply(Opt &O) const { O.setInitialValue(Init); }
248 initializer<Ty> init(const Ty &Val) {
249 return initializer<Ty>(Val);
253 // location - Allow the user to specify which external variable they want to
254 // store the results of the command line argument processing into, if they don't
255 // want to store it in the option itself.
258 struct LocationClass {
260 LocationClass(Ty &L) : Loc(L) {}
263 void apply(Opt &O) const { O.setLocation(O, Loc); }
267 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
270 //===----------------------------------------------------------------------===//
271 // Enum valued command line option
273 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
274 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
276 // values - For custom data types, allow specifying a group of values together
277 // as the values that go into the mapping that the option handler uses. Note
278 // that the values list must always have a 0 at the end of the list to indicate
279 // that the list has ended.
281 template<class DataType>
283 // Use a vector instead of a map, because the lists should be short,
284 // the overhead is less, and most importantly, it keeps them in the order
285 // inserted so we can print our option out nicely.
286 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
287 void processValues(va_list Vals);
289 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
291 // Insert the first value, which is required.
292 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
294 // Process the varargs portion of the values...
295 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
296 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
297 const char *EnumDesc = va_arg(ValueArgs, const char *);
298 Values.push_back(std::make_pair(EnumName, // Add value to value map
299 std::make_pair(EnumVal, EnumDesc)));
304 void apply(Opt &O) const {
305 for (unsigned i = 0, e = Values.size(); i != e; ++i)
306 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
307 Values[i].second.second);
311 template<class DataType>
312 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
315 va_start(ValueArgs, Desc);
316 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
322 //===----------------------------------------------------------------------===//
323 // parser class - Parameterizable parser for different data types. By default,
324 // known data types (string, int, bool) have specialized parsers, that do what
325 // you would expect. The default parser, used for data types that are not
326 // built-in, uses a mapping table to map specific options to values, which is
327 // used, among other things, to handle enum types.
329 //--------------------------------------------------
330 // generic_parser_base - This class holds all the non-generic code that we do
331 // not need replicated for every instance of the generic parser. This also
332 // allows us to put stuff into CommandLine.cpp
334 struct generic_parser_base {
335 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
337 // getNumOptions - Virtual function implemented by generic subclass to
338 // indicate how many entries are in Values.
340 virtual unsigned getNumOptions() const = 0;
342 // getOption - Return option name N.
343 virtual const char *getOption(unsigned N) const = 0;
345 // getDescription - Return description N
346 virtual const char *getDescription(unsigned N) const = 0;
348 // Return the width of the option tag for printing...
349 virtual unsigned getOptionWidth(const Option &O) const;
351 // printOptionInfo - Print out information about this option. The
352 // to-be-maintained width is specified.
354 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
356 void initialize(Option &O) {
357 // All of the modifiers for the option have been processed by now, so the
358 // argstr field should be stable, copy it down now.
360 hasArgStr = O.hasArgStr();
362 // If there has been no argstr specified, that means that we need to add an
363 // argument for every possible option. This ensures that our options are
367 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
368 O.addArgument(getOption(i));
371 enum ValueExpected getValueExpectedFlagDefault() const {
372 // If there is an ArgStr specified, then we are of the form:
374 // -opt=O2 or -opt O2 or -optO2
376 // In which case, the value is required. Otherwise if an arg str has not
377 // been specified, we are of the form:
379 // -O2 or O2 or -la (where -l and -a are seperate options)
381 // If this is the case, we cannot allow a value.
384 return ValueRequired;
386 return ValueDisallowed;
389 // findOption - Return the option number corresponding to the specified
390 // argument string. If the option is not found, getNumOptions() is returned.
392 unsigned findOption(const char *Name);
398 // Default parser implementation - This implementation depends on having a
399 // mapping of recognized options to values of some sort. In addition to this,
400 // each entry in the mapping also tracks a help message that is printed with the
401 // command line option for --help. Because this is a simple mapping parser, the
402 // data type can be any unsupported type.
404 template <class DataType>
405 class parser : public generic_parser_base {
407 std::vector<std::pair<const char *,
408 std::pair<DataType, const char *> > > Values;
410 typedef DataType parser_data_type;
412 // Implement virtual functions needed by generic_parser_base
413 unsigned getNumOptions() const { return Values.size(); }
414 const char *getOption(unsigned N) const { return Values[N].first; }
415 const char *getDescription(unsigned N) const {
416 return Values[N].second.second;
419 // parse - Return true on error.
420 bool parse(Option &O, const char *ArgName, const std::string &Arg,
428 for (unsigned i = 0, e = Values.size(); i != e; ++i)
429 if (ArgVal == Values[i].first) {
430 V = Values[i].second.first;
434 return O.error(": Cannot find option named '" + ArgVal + "'!");
437 // addLiteralOption - Add an entry to the mapping table...
439 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
440 assert(findOption(Name) == Values.size() && "Option already exists!");
441 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
444 // removeLiteralOption - Remove the specified option.
446 void removeLiteralOption(const char *Name) {
447 unsigned N = findOption(Name);
448 assert(N != Values.size() && "Option not found!");
449 Values.erase(Values.begin()+N);
453 //--------------------------------------------------
454 // basic_parser - Super class of parsers to provide boilerplate code
456 struct basic_parser_impl { // non-template implementation of basic_parser<t>
457 virtual ~basic_parser_impl() {}
459 enum ValueExpected getValueExpectedFlagDefault() const {
460 return ValueRequired;
463 void initialize(Option &O) {}
465 // Return the width of the option tag for printing...
466 unsigned getOptionWidth(const Option &O) const;
468 // printOptionInfo - Print out information about this option. The
469 // to-be-maintained width is specified.
471 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
474 // getValueName - Overload in subclass to provide a better default value.
475 virtual const char *getValueName() const { return "value"; }
478 // basic_parser - The real basic parser is just a template wrapper that provides
479 // a typedef for the provided data type.
481 template<class DataType>
482 struct basic_parser : public basic_parser_impl {
483 typedef DataType parser_data_type;
487 //--------------------------------------------------
491 struct parser<bool> : public basic_parser<bool> {
493 // parse - Return true on error.
494 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
496 enum ValueExpected getValueExpectedFlagDefault() const {
497 return ValueOptional;
500 // getValueName - Do not print =<value> at all
501 virtual const char *getValueName() const { return 0; }
505 //--------------------------------------------------
509 struct parser<int> : public basic_parser<int> {
511 // parse - Return true on error.
512 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
514 // getValueName - Overload in subclass to provide a better default value.
515 virtual const char *getValueName() const { return "int"; }
519 //--------------------------------------------------
523 struct parser<double> : public basic_parser<double> {
524 // parse - Return true on error.
525 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
527 // getValueName - Overload in subclass to provide a better default value.
528 virtual const char *getValueName() const { return "number"; }
532 //--------------------------------------------------
536 struct parser<float> : public basic_parser<float> {
537 // parse - Return true on error.
538 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
540 // getValueName - Overload in subclass to provide a better default value.
541 virtual const char *getValueName() const { return "number"; }
545 //--------------------------------------------------
546 // parser<std::string>
549 struct parser<std::string> : public basic_parser<std::string> {
550 // parse - Return true on error.
551 bool parse(Option &O, const char *ArgName, const std::string &Arg,
552 std::string &Value) {
557 // getValueName - Overload in subclass to provide a better default value.
558 virtual const char *getValueName() const { return "string"; }
563 //===----------------------------------------------------------------------===//
564 // applicator class - This class is used because we must use partial
565 // specialization to handle literal string arguments specially (const char* does
566 // not correctly respond to the apply method). Because the syntax to use this
567 // is a pain, we have the 'apply' method below to handle the nastiness...
569 template<class Mod> struct applicator {
571 static void opt(const Mod &M, Opt &O) { M.apply(O); }
574 // Handle const char* as a special case...
575 template<unsigned n> struct applicator<char[n]> {
577 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
579 template<unsigned n> struct applicator<const char[n]> {
581 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
583 template<> struct applicator<const char*> {
585 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
588 template<> struct applicator<NumOccurances> {
589 static void opt(NumOccurances NO, Option &O) { O.setNumOccurancesFlag(NO); }
591 template<> struct applicator<ValueExpected> {
592 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
594 template<> struct applicator<OptionHidden> {
595 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
597 template<> struct applicator<FormattingFlags> {
598 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
600 template<> struct applicator<MiscFlags> {
601 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
604 // apply method - Apply a modifier to an option in a type safe way.
605 template<class Mod, class Opt>
606 void apply(const Mod &M, Opt *O) {
607 applicator<Mod>::opt(M, *O);
611 //===----------------------------------------------------------------------===//
614 // Default storage class definition: external storage. This implementation
615 // assumes the user will specify a variable to store the data into with the
616 // cl::location(x) modifier.
618 template<class DataType, bool ExternalStorage, bool isClass>
620 DataType *Location; // Where to store the object...
623 assert(Location != 0 && "cl::location(...) not specified for a command "
624 "line option with external storage!");
627 opt_storage() : Location(0) {}
629 bool setLocation(Option &O, DataType &L) {
631 return O.error(": cl::location(x) specified more than once!");
637 void setValue(const T &V) {
642 DataType &getValue() { check(); return *Location; }
643 const DataType &getValue() const { check(); return *Location; }
647 // Define how to hold a class type object, such as a string. Since we can
648 // inherit from a class, we do so. This makes us exactly compatible with the
649 // object in all cases that it is used.
651 template<class DataType>
652 struct opt_storage<DataType,false,true> : public DataType {
655 void setValue(const T &V) { DataType::operator=(V); }
657 DataType &getValue() { return *this; }
658 const DataType &getValue() const { return *this; }
661 // Define a partial specialization to handle things we cannot inherit from. In
662 // this case, we store an instance through containment, and overload operators
663 // to get at the value.
665 template<class DataType>
666 struct opt_storage<DataType, false, false> {
669 // Make sure we initialize the value with the default constructor for the
671 opt_storage() : Value(DataType()) {}
674 void setValue(const T &V) { Value = V; }
675 DataType &getValue() { return Value; }
676 DataType getValue() const { return Value; }
680 //===----------------------------------------------------------------------===//
681 // opt - A scalar command line option.
683 template <class DataType, bool ExternalStorage = false,
684 class ParserClass = parser<DataType> >
685 class opt : public Option,
686 public opt_storage<DataType, ExternalStorage,
687 ::boost::is_class<DataType>::value> {
690 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
691 typename ParserClass::parser_data_type Val;
692 if (Parser.parse(*this, ArgName, Arg, Val))
693 return true; // Parse error!
698 virtual enum ValueExpected getValueExpectedFlagDefault() const {
699 return Parser.getValueExpectedFlagDefault();
702 // Forward printing stuff to the parser...
703 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
704 virtual void printOptionInfo(unsigned GlobalWidth) const {
705 Parser.printOptionInfo(*this, GlobalWidth);
710 Parser.initialize(*this);
713 // setInitialValue - Used by the cl::init modifier...
714 void setInitialValue(const DataType &V) { setValue(V); }
716 ParserClass &getParser() { return Parser; }
718 operator DataType() const { return getValue(); }
721 DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
731 template<class M0t, class M1t>
732 opt(const M0t &M0, const M1t &M1) {
733 apply(M0, this); apply(M1, this);
738 template<class M0t, class M1t, class M2t>
739 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
740 apply(M0, this); apply(M1, this); apply(M2, this);
744 template<class M0t, class M1t, class M2t, class M3t>
745 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
746 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
750 template<class M0t, class M1t, class M2t, class M3t, class M4t>
751 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
753 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
758 template<class M0t, class M1t, class M2t, class M3t,
759 class M4t, class M5t>
760 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
761 const M4t &M4, const M5t &M5) {
762 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
763 apply(M4, this); apply(M5, this);
767 template<class M0t, class M1t, class M2t, class M3t,
768 class M4t, class M5t, class M6t>
769 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
770 const M4t &M4, const M5t &M5, const M6t &M6) {
771 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
772 apply(M4, this); apply(M5, this); apply(M6, this);
776 template<class M0t, class M1t, class M2t, class M3t,
777 class M4t, class M5t, class M6t, class M7t>
778 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
779 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
780 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
781 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
786 //===----------------------------------------------------------------------===//
787 // list_storage class
789 // Default storage class definition: external storage. This implementation
790 // assumes the user will specify a variable to store the data into with the
791 // cl::location(x) modifier.
793 template<class DataType, class StorageClass>
795 StorageClass *Location; // Where to store the object...
798 list_storage() : Location(0) {}
800 bool setLocation(Option &O, StorageClass &L) {
802 return O.error(": cl::location(x) specified more than once!");
808 void addValue(const T &V) {
809 assert(Location != 0 && "cl::location(...) not specified for a command "
810 "line option with external storage!");
811 Location->push_back(V);
816 // Define how to hold a class type object, such as a string. Since we can
817 // inherit from a class, we do so. This makes us exactly compatible with the
818 // object in all cases that it is used.
820 template<class DataType>
821 struct list_storage<DataType, bool> : public std::vector<DataType> {
824 void addValue(const T &V) { push_back(V); }
828 //===----------------------------------------------------------------------===//
829 // list - A list of command line options.
831 template <class DataType, class Storage = bool,
832 class ParserClass = parser<DataType> >
833 class list : public Option, public list_storage<DataType, Storage> {
836 virtual enum NumOccurances getNumOccurancesFlagDefault() const {
839 virtual enum ValueExpected getValueExpectedFlagDefault() const {
840 return Parser.getValueExpectedFlagDefault();
843 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
844 typename ParserClass::parser_data_type Val;
845 if (Parser.parse(*this, ArgName, Arg, Val))
846 return true; // Parse Error!
851 // Forward printing stuff to the parser...
852 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
853 virtual void printOptionInfo(unsigned GlobalWidth) const {
854 Parser.printOptionInfo(*this, GlobalWidth);
859 Parser.initialize(*this);
862 ParserClass &getParser() { return Parser; }
866 list(const M0t &M0) {
871 template<class M0t, class M1t>
872 list(const M0t &M0, const M1t &M1) {
873 apply(M0, this); apply(M1, this);
877 template<class M0t, class M1t, class M2t>
878 list(const M0t &M0, const M1t &M1, const M2t &M2) {
879 apply(M0, this); apply(M1, this); apply(M2, this);
883 template<class M0t, class M1t, class M2t, class M3t>
884 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
885 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
889 template<class M0t, class M1t, class M2t, class M3t, class M4t>
890 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
892 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
897 template<class M0t, class M1t, class M2t, class M3t,
898 class M4t, class M5t>
899 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
900 const M4t &M4, const M5t &M5) {
901 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
902 apply(M4, this); apply(M5, this);
906 template<class M0t, class M1t, class M2t, class M3t,
907 class M4t, class M5t, class M6t>
908 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
909 const M4t &M4, const M5t &M5, const M6t &M6) {
910 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
911 apply(M4, this); apply(M5, this); apply(M6, this);
915 template<class M0t, class M1t, class M2t, class M3t,
916 class M4t, class M5t, class M6t, class M7t>
917 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
918 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
919 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
920 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
927 //===----------------------------------------------------------------------===//
928 // Aliased command line option (alias this name to a preexisting name)
931 class alias : public Option {
933 virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
934 return AliasFor->handleOccurance(AliasFor->ArgStr, Arg);
936 // Aliases default to be hidden...
937 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
939 // Handle printing stuff...
940 virtual unsigned getOptionWidth() const;
941 virtual void printOptionInfo(unsigned GlobalWidth) const;
945 error(": cl::alias must have argument name specified!");
947 error(": cl::alias must have an cl::aliasopt(option) specified!");
951 void setAliasFor(Option &O) {
953 error(": cl::alias must only have one cl::aliasopt(...) specified!");
959 alias(const M0t &M0) : AliasFor(0) {
964 template<class M0t, class M1t>
965 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
966 apply(M0, this); apply(M1, this);
970 template<class M0t, class M1t, class M2t>
971 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
972 apply(M0, this); apply(M1, this); apply(M2, this);
976 template<class M0t, class M1t, class M2t, class M3t>
977 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
979 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
984 // aliasfor - Modifier to set the option an alias aliases.
987 aliasopt(Option &O) : Opt(O) {}
988 void apply(alias &A) const { A.setAliasFor(Opt); }
991 } // End namespace cl