1 //===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements a command line argument processor that is useful when
11 // creating a tool. It provides a simple, minimalistic interface that is easily
12 // extensible and supports nonlocal (library) command line options.
14 // Note that rather than trying to figure out what this code does, you should
15 // read the library documentation located in docs/CommandLine.html or looks at
16 // the many example usages in tools/*/*.cpp
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_SUPPORT_COMMANDLINE_H
21 #define LLVM_SUPPORT_COMMANDLINE_H
23 #include "llvm/Support/type_traits.h"
24 #include "llvm/Support/Compiler.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/Twine.h"
35 /// cl Namespace - This namespace contains all of the command line option
36 /// processing machinery. It is intentionally a short name to make qualified
40 //===----------------------------------------------------------------------===//
41 // ParseCommandLineOptions - Command line option processing entry point.
43 void ParseCommandLineOptions(int argc, char **argv,
44 const char *Overview = 0,
45 bool ReadResponseFiles = false);
47 //===----------------------------------------------------------------------===//
48 // ParseEnvironmentOptions - Environment variable option processing alternate
51 void ParseEnvironmentOptions(const char *progName, const char *envvar,
52 const char *Overview = 0,
53 bool ReadResponseFiles = false);
55 ///===---------------------------------------------------------------------===//
56 /// SetVersionPrinter - Override the default (LLVM specific) version printer
57 /// used to print out the version when --version is given
58 /// on the command line. This allows other systems using the
59 /// CommandLine utilities to print their own version string.
60 void SetVersionPrinter(void (*func)());
63 // PrintOptionValues - Print option values.
64 // With -print-options print the difference between option values and defaults.
65 // With -print-all-options print all option values.
66 // (Currently not perfect, but best-effort.)
67 void PrintOptionValues();
69 // MarkOptionsChanged - Internal helper function.
70 void MarkOptionsChanged();
72 //===----------------------------------------------------------------------===//
73 // Flags permitted to be passed to command line arguments
76 enum NumOccurrencesFlag { // Flags for the number of occurrences allowed
77 Optional = 0x01, // Zero or One occurrence
78 ZeroOrMore = 0x02, // Zero or more occurrences allowed
79 Required = 0x03, // One occurrence required
80 OneOrMore = 0x04, // One or more occurrences required
82 // ConsumeAfter - Indicates that this option is fed anything that follows the
83 // last positional argument required by the application (it is an error if
84 // there are zero positional arguments, and a ConsumeAfter option is used).
85 // Thus, for example, all arguments to LLI are processed until a filename is
86 // found. Once a filename is found, all of the succeeding arguments are
87 // passed, unprocessed, to the ConsumeAfter option.
91 OccurrencesMask = 0x07
94 enum ValueExpected { // Is a value required for the option?
95 ValueOptional = 0x08, // The value can appear... or not
96 ValueRequired = 0x10, // The value is required to appear!
97 ValueDisallowed = 0x18, // A value may not be specified (for flags)
101 enum OptionHidden { // Control whether -help shows this option
102 NotHidden = 0x20, // Option included in -help & -help-hidden
103 Hidden = 0x40, // -help doesn't, but -help-hidden does
104 ReallyHidden = 0x60, // Neither -help nor -help-hidden show this arg
108 // Formatting flags - This controls special features that the option might have
109 // that cause it to be parsed differently...
111 // Prefix - This option allows arguments that are otherwise unrecognized to be
112 // matched by options that are a prefix of the actual value. This is useful for
113 // cases like a linker, where options are typically of the form '-lfoo' or
114 // '-L../../include' where -l or -L are the actual flags. When prefix is
115 // enabled, and used, the value for the flag comes from the suffix of the
118 // Grouping - With this option enabled, multiple letter options are allowed to
119 // bunch together with only a single hyphen for the whole group. This allows
120 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
123 enum FormattingFlags {
124 NormalFormatting = 0x000, // Nothing special
125 Positional = 0x080, // Is a positional argument, no '-' required
126 Prefix = 0x100, // Can this option directly prefix its value?
127 Grouping = 0x180, // Can this option group with other options?
128 FormattingMask = 0x180 // Union of the above flags.
131 enum MiscFlags { // Miscellaneous flags to adjust argument
132 CommaSeparated = 0x200, // Should this cl::list split between commas?
133 PositionalEatsArgs = 0x400, // Should this positional cl::list eat -args?
134 Sink = 0x800, // Should this cl::list eat all unknown options?
135 MiscMask = 0xE00 // Union of the above flags.
140 //===----------------------------------------------------------------------===//
147 // handleOccurrences - Overriden by subclasses to handle the value passed into
148 // an argument. Should return true if there was an error processing the
149 // argument and the program should exit.
151 virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
154 virtual enum ValueExpected getValueExpectedFlagDefault() const {
155 return ValueOptional;
158 // Out of line virtual function to provide home for the class.
159 virtual void anchor();
161 int NumOccurrences; // The number of times specified
162 int Flags; // Flags for the argument
163 unsigned Position; // Position of last occurrence of the option
164 unsigned AdditionalVals;// Greater than 0 for multi-valued option.
165 Option *NextRegistered; // Singly linked list of registered options.
167 const char *ArgStr; // The argument string itself (ex: "help", "o")
168 const char *HelpStr; // The descriptive text message for -help
169 const char *ValueStr; // String describing what the value of this option is
171 inline enum NumOccurrencesFlag getNumOccurrencesFlag() const {
172 return static_cast<enum NumOccurrencesFlag>(Flags & OccurrencesMask);
174 inline enum ValueExpected getValueExpectedFlag() const {
175 int VE = Flags & ValueMask;
176 return VE ? static_cast<enum ValueExpected>(VE)
177 : getValueExpectedFlagDefault();
179 inline enum OptionHidden getOptionHiddenFlag() const {
180 return static_cast<enum OptionHidden>(Flags & HiddenMask);
182 inline enum FormattingFlags getFormattingFlag() const {
183 return static_cast<enum FormattingFlags>(Flags & FormattingMask);
185 inline unsigned getMiscFlags() const {
186 return Flags & MiscMask;
188 inline unsigned getPosition() const { return Position; }
189 inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
191 // hasArgStr - Return true if the argstr != ""
192 bool hasArgStr() const { return ArgStr[0] != 0; }
194 //-------------------------------------------------------------------------===
195 // Accessor functions set by OptionModifiers
197 void setArgStr(const char *S) { ArgStr = S; }
198 void setDescription(const char *S) { HelpStr = S; }
199 void setValueStr(const char *S) { ValueStr = S; }
201 void setFlag(unsigned Flag, unsigned FlagMask) {
206 void setNumOccurrencesFlag(enum NumOccurrencesFlag Val) {
207 setFlag(Val, OccurrencesMask);
209 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
210 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
211 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
212 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
213 void setPosition(unsigned pos) { Position = pos; }
215 explicit Option(unsigned DefaultFlags)
216 : NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0),
217 AdditionalVals(0), NextRegistered(0),
218 ArgStr(""), HelpStr(""), ValueStr("") {
219 assert(getNumOccurrencesFlag() != 0 &&
220 getOptionHiddenFlag() != 0 && "Not all default flags specified!");
223 inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
225 // addArgument - Register this argument with the commandline system.
229 Option *getNextRegisteredOption() const { return NextRegistered; }
231 // Return the width of the option tag for printing...
232 virtual size_t getOptionWidth() const = 0;
234 // printOptionInfo - Print out information about this option. The
235 // to-be-maintained width is specified.
237 virtual void printOptionInfo(size_t GlobalWidth) const = 0;
239 virtual void printOptionValue(size_t GlobalWidth, bool Force) const = 0;
241 virtual void getExtraOptionNames(SmallVectorImpl<const char*> &) {}
243 // addOccurrence - Wrapper around handleOccurrence that enforces Flags.
245 bool addOccurrence(unsigned pos, StringRef ArgName,
246 StringRef Value, bool MultiArg = false);
248 // Prints option name followed by message. Always returns true.
249 bool error(const Twine &Message, StringRef ArgName = StringRef());
252 inline int getNumOccurrences() const { return NumOccurrences; }
257 //===----------------------------------------------------------------------===//
258 // Command line option modifiers that can be used to modify the behavior of
259 // command line option parsers...
262 // desc - Modifier to set the description shown in the -help output...
265 desc(const char *Str) : Desc(Str) {}
266 void apply(Option &O) const { O.setDescription(Desc); }
269 // value_desc - Modifier to set the value description shown in the -help
273 value_desc(const char *Str) : Desc(Str) {}
274 void apply(Option &O) const { O.setValueStr(Desc); }
277 // init - Specify a default (initial) value for the command line argument, if
278 // the default constructor for the argument type does not give you what you
279 // want. This is only valid on "opt" arguments, not on "list" arguments.
284 initializer(const Ty &Val) : Init(Val) {}
287 void apply(Opt &O) const { O.setInitialValue(Init); }
291 initializer<Ty> init(const Ty &Val) {
292 return initializer<Ty>(Val);
296 // location - Allow the user to specify which external variable they want to
297 // store the results of the command line argument processing into, if they don't
298 // want to store it in the option itself.
301 struct LocationClass {
303 LocationClass(Ty &L) : Loc(L) {}
306 void apply(Opt &O) const { O.setLocation(O, Loc); }
310 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
313 //===----------------------------------------------------------------------===//
316 // Support value comparison outside the template.
317 struct GenericOptionValue {
318 virtual ~GenericOptionValue() {}
319 virtual bool compare(const GenericOptionValue &V) const = 0;
322 template<class DataType> struct OptionValue;
324 // The default value safely does nothing. Option value printing is only
326 template<class DataType, bool isClass>
327 struct OptionValueBase : public GenericOptionValue {
328 // Temporary storage for argument passing.
329 typedef OptionValue<DataType> WrapperType;
331 bool hasValue() const { return false; }
333 const DataType &getValue() const { assert(false && "no default value"); }
335 // Some options may take their value from a different data type.
337 void setValue(const DT& /*V*/) {}
339 bool compare(const DataType &/*V*/) const { return false; }
341 virtual bool compare(const GenericOptionValue& /*V*/) const { return false; }
344 // Simple copy of the option value.
345 template<class DataType>
346 class OptionValueCopy : public GenericOptionValue {
350 OptionValueCopy() : Valid(false) {}
352 bool hasValue() const { return Valid; }
354 const DataType &getValue() const {
355 assert(Valid && "invalid option value");
359 void setValue(const DataType &V) { Valid = true; Value = V; }
361 bool compare(const DataType &V) const {
362 return Valid && (Value != V);
365 virtual bool compare(const GenericOptionValue &V) const {
366 const OptionValueCopy<DataType> &VC =
367 static_cast< const OptionValueCopy<DataType>& >(V);
368 if (!VC.hasValue()) return false;
369 return compare(VC.getValue());
373 // Non-class option values.
374 template<class DataType>
375 struct OptionValueBase<DataType, false> : OptionValueCopy<DataType> {
376 typedef DataType WrapperType;
379 // Top-level option class.
380 template<class DataType>
381 struct OptionValue : OptionValueBase<DataType, is_class<DataType>::value> {
384 OptionValue(const DataType& V) {
387 // Some options may take their value from a different data type.
389 OptionValue<DataType> &operator=(const DT& V) {
395 // Other safe-to-copy-by-value common option types.
396 enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
398 struct OptionValue<cl::boolOrDefault> : OptionValueCopy<cl::boolOrDefault> {
399 typedef cl::boolOrDefault WrapperType;
403 OptionValue(const cl::boolOrDefault& V) {
406 OptionValue<cl::boolOrDefault> &operator=(const cl::boolOrDefault& V) {
413 struct OptionValue<std::string> : OptionValueCopy<std::string> {
414 typedef StringRef WrapperType;
418 OptionValue(const std::string& V) {
421 OptionValue<std::string> &operator=(const std::string& V) {
427 //===----------------------------------------------------------------------===//
428 // Enum valued command line option
430 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, int(ENUMVAL), DESC
431 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, int(ENUMVAL), DESC
432 #define clEnumValEnd (reinterpret_cast<void*>(0))
434 // values - For custom data types, allow specifying a group of values together
435 // as the values that go into the mapping that the option handler uses. Note
436 // that the values list must always have a 0 at the end of the list to indicate
437 // that the list has ended.
439 template<class DataType>
441 // Use a vector instead of a map, because the lists should be short,
442 // the overhead is less, and most importantly, it keeps them in the order
443 // inserted so we can print our option out nicely.
444 SmallVector<std::pair<const char *, std::pair<int, const char *> >,4> Values;
445 void processValues(va_list Vals);
447 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
449 // Insert the first value, which is required.
450 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
452 // Process the varargs portion of the values...
453 while (const char *enumName = va_arg(ValueArgs, const char *)) {
454 DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
455 const char *EnumDesc = va_arg(ValueArgs, const char *);
456 Values.push_back(std::make_pair(enumName, // Add value to value map
457 std::make_pair(EnumVal, EnumDesc)));
462 void apply(Opt &O) const {
463 for (unsigned i = 0, e = static_cast<unsigned>(Values.size());
465 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
466 Values[i].second.second);
470 template<class DataType>
471 ValuesClass<DataType> END_WITH_NULL values(const char *Arg, DataType Val,
472 const char *Desc, ...) {
474 va_start(ValueArgs, Desc);
475 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
480 //===----------------------------------------------------------------------===//
481 // parser class - Parameterizable parser for different data types. By default,
482 // known data types (string, int, bool) have specialized parsers, that do what
483 // you would expect. The default parser, used for data types that are not
484 // built-in, uses a mapping table to map specific options to values, which is
485 // used, among other things, to handle enum types.
487 //--------------------------------------------------
488 // generic_parser_base - This class holds all the non-generic code that we do
489 // not need replicated for every instance of the generic parser. This also
490 // allows us to put stuff into CommandLine.cpp
492 class generic_parser_base {
494 class GenericOptionInfo {
496 GenericOptionInfo(const char *name, const char *helpStr) :
497 Name(name), HelpStr(helpStr) {}
502 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
504 // getNumOptions - Virtual function implemented by generic subclass to
505 // indicate how many entries are in Values.
507 virtual unsigned getNumOptions() const = 0;
509 // getOption - Return option name N.
510 virtual const char *getOption(unsigned N) const = 0;
512 // getDescription - Return description N
513 virtual const char *getDescription(unsigned N) const = 0;
515 // Return the width of the option tag for printing...
516 virtual size_t getOptionWidth(const Option &O) const;
518 virtual const GenericOptionValue &getOptionValue(unsigned N) const = 0;
520 // printOptionInfo - Print out information about this option. The
521 // to-be-maintained width is specified.
523 virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const;
525 void printGenericOptionDiff(const Option &O, const GenericOptionValue &V,
526 const GenericOptionValue &Default,
527 size_t GlobalWidth) const;
529 // printOptionDiff - print the value of an option and it's default.
531 // Template definition ensures that the option and default have the same
532 // DataType (via the same AnyOptionValue).
533 template<class AnyOptionValue>
534 void printOptionDiff(const Option &O, const AnyOptionValue &V,
535 const AnyOptionValue &Default,
536 size_t GlobalWidth) const {
537 printGenericOptionDiff(O, V, Default, GlobalWidth);
540 void initialize(Option &O) {
541 // All of the modifiers for the option have been processed by now, so the
542 // argstr field should be stable, copy it down now.
544 hasArgStr = O.hasArgStr();
547 void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
548 // If there has been no argstr specified, that means that we need to add an
549 // argument for every possible option. This ensures that our options are
552 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
553 OptionNames.push_back(getOption(i));
557 enum ValueExpected getValueExpectedFlagDefault() const {
558 // If there is an ArgStr specified, then we are of the form:
560 // -opt=O2 or -opt O2 or -optO2
562 // In which case, the value is required. Otherwise if an arg str has not
563 // been specified, we are of the form:
565 // -O2 or O2 or -la (where -l and -a are separate options)
567 // If this is the case, we cannot allow a value.
570 return ValueRequired;
572 return ValueDisallowed;
575 // findOption - Return the option number corresponding to the specified
576 // argument string. If the option is not found, getNumOptions() is returned.
578 unsigned findOption(const char *Name);
584 // Default parser implementation - This implementation depends on having a
585 // mapping of recognized options to values of some sort. In addition to this,
586 // each entry in the mapping also tracks a help message that is printed with the
587 // command line option for -help. Because this is a simple mapping parser, the
588 // data type can be any unsupported type.
590 template <class DataType>
591 class parser : public generic_parser_base {
593 class OptionInfo : public GenericOptionInfo {
595 OptionInfo(const char *name, DataType v, const char *helpStr) :
596 GenericOptionInfo(name, helpStr), V(v) {}
597 OptionValue<DataType> V;
599 SmallVector<OptionInfo, 8> Values;
601 typedef DataType parser_data_type;
603 // Implement virtual functions needed by generic_parser_base
604 unsigned getNumOptions() const { return unsigned(Values.size()); }
605 const char *getOption(unsigned N) const { return Values[N].Name; }
606 const char *getDescription(unsigned N) const {
607 return Values[N].HelpStr;
610 // getOptionValue - Return the value of option name N.
611 virtual const GenericOptionValue &getOptionValue(unsigned N) const {
615 // parse - Return true on error.
616 bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V) {
623 for (unsigned i = 0, e = static_cast<unsigned>(Values.size());
625 if (Values[i].Name == ArgVal) {
626 V = Values[i].V.getValue();
630 return O.error("Cannot find option named '" + ArgVal + "'!");
633 /// addLiteralOption - Add an entry to the mapping table.
636 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
637 assert(findOption(Name) == Values.size() && "Option already exists!");
638 OptionInfo X(Name, static_cast<DataType>(V), HelpStr);
640 MarkOptionsChanged();
643 /// removeLiteralOption - Remove the specified option.
645 void removeLiteralOption(const char *Name) {
646 unsigned N = findOption(Name);
647 assert(N != Values.size() && "Option not found!");
648 Values.erase(Values.begin()+N);
652 //--------------------------------------------------
653 // basic_parser - Super class of parsers to provide boilerplate code
655 class basic_parser_impl { // non-template implementation of basic_parser<t>
657 virtual ~basic_parser_impl() {}
659 enum ValueExpected getValueExpectedFlagDefault() const {
660 return ValueRequired;
663 void getExtraOptionNames(SmallVectorImpl<const char*> &) {}
665 void initialize(Option &) {}
667 // Return the width of the option tag for printing...
668 size_t getOptionWidth(const Option &O) const;
670 // printOptionInfo - Print out information about this option. The
671 // to-be-maintained width is specified.
673 void printOptionInfo(const Option &O, size_t GlobalWidth) const;
675 // printOptionNoValue - Print a placeholder for options that don't yet support
676 // printOptionDiff().
677 void printOptionNoValue(const Option &O, size_t GlobalWidth) const;
679 // getValueName - Overload in subclass to provide a better default value.
680 virtual const char *getValueName() const { return "value"; }
682 // An out-of-line virtual method to provide a 'home' for this class.
683 virtual void anchor();
686 // A helper for basic_parser::printOptionDiff.
687 void printOptionName(const Option &O, size_t GlobalWidth) const;
690 // basic_parser - The real basic parser is just a template wrapper that provides
691 // a typedef for the provided data type.
693 template<class DataType>
694 class basic_parser : public basic_parser_impl {
696 typedef DataType parser_data_type;
697 typedef OptionValue<DataType> OptVal;
700 //--------------------------------------------------
704 class parser<bool> : public basic_parser<bool> {
708 // parse - Return true on error.
709 bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val);
712 void initialize(Opt &O) {
716 enum ValueExpected getValueExpectedFlagDefault() const {
717 return ValueOptional;
720 // getValueName - Do not print =<value> at all.
721 virtual const char *getValueName() const { return 0; }
723 void printOptionDiff(const Option &O, bool V, OptVal Default,
724 size_t GlobalWidth) const;
726 // An out-of-line virtual method to provide a 'home' for this class.
727 virtual void anchor();
730 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<bool>);
732 //--------------------------------------------------
733 // parser<boolOrDefault>
735 class parser<boolOrDefault> : public basic_parser<boolOrDefault> {
737 // parse - Return true on error.
738 bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val);
740 enum ValueExpected getValueExpectedFlagDefault() const {
741 return ValueOptional;
744 // getValueName - Do not print =<value> at all.
745 virtual const char *getValueName() const { return 0; }
747 void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default,
748 size_t GlobalWidth) const;
750 // An out-of-line virtual method to provide a 'home' for this class.
751 virtual void anchor();
754 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
756 //--------------------------------------------------
760 class parser<int> : public basic_parser<int> {
762 // parse - Return true on error.
763 bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val);
765 // getValueName - Overload in subclass to provide a better default value.
766 virtual const char *getValueName() const { return "int"; }
768 void printOptionDiff(const Option &O, int V, OptVal Default,
769 size_t GlobalWidth) const;
771 // An out-of-line virtual method to provide a 'home' for this class.
772 virtual void anchor();
775 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>);
778 //--------------------------------------------------
782 class parser<unsigned> : public basic_parser<unsigned> {
784 // parse - Return true on error.
785 bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val);
787 // getValueName - Overload in subclass to provide a better default value.
788 virtual const char *getValueName() const { return "uint"; }
790 void printOptionDiff(const Option &O, unsigned V, OptVal Default,
791 size_t GlobalWidth) const;
793 // An out-of-line virtual method to provide a 'home' for this class.
794 virtual void anchor();
797 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
799 //--------------------------------------------------
803 class parser<double> : public basic_parser<double> {
805 // parse - Return true on error.
806 bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val);
808 // getValueName - Overload in subclass to provide a better default value.
809 virtual const char *getValueName() const { return "number"; }
811 void printOptionDiff(const Option &O, double V, OptVal Default,
812 size_t GlobalWidth) const;
814 // An out-of-line virtual method to provide a 'home' for this class.
815 virtual void anchor();
818 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<double>);
820 //--------------------------------------------------
824 class parser<float> : public basic_parser<float> {
826 // parse - Return true on error.
827 bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val);
829 // getValueName - Overload in subclass to provide a better default value.
830 virtual const char *getValueName() const { return "number"; }
832 void printOptionDiff(const Option &O, float V, OptVal Default,
833 size_t GlobalWidth) const;
835 // An out-of-line virtual method to provide a 'home' for this class.
836 virtual void anchor();
839 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<float>);
841 //--------------------------------------------------
842 // parser<std::string>
845 class parser<std::string> : public basic_parser<std::string> {
847 // parse - Return true on error.
848 bool parse(Option &, StringRef, StringRef Arg, std::string &Value) {
853 // getValueName - Overload in subclass to provide a better default value.
854 virtual const char *getValueName() const { return "string"; }
856 void printOptionDiff(const Option &O, StringRef V, OptVal Default,
857 size_t GlobalWidth) const;
859 // An out-of-line virtual method to provide a 'home' for this class.
860 virtual void anchor();
863 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
865 //--------------------------------------------------
869 class parser<char> : public basic_parser<char> {
871 // parse - Return true on error.
872 bool parse(Option &, StringRef, StringRef Arg, char &Value) {
877 // getValueName - Overload in subclass to provide a better default value.
878 virtual const char *getValueName() const { return "char"; }
880 void printOptionDiff(const Option &O, char V, OptVal Default,
881 size_t GlobalWidth) const;
883 // An out-of-line virtual method to provide a 'home' for this class.
884 virtual void anchor();
887 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<char>);
889 //--------------------------------------------------
892 // This collection of wrappers is the intermediary between class opt and class
893 // parser to handle all the template nastiness.
895 // This overloaded function is selected by the generic parser.
896 template<class ParserClass, class DT>
897 void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V,
898 const OptionValue<DT> &Default, size_t GlobalWidth) {
899 OptionValue<DT> OV = V;
900 P.printOptionDiff(O, OV, Default, GlobalWidth);
903 // This is instantiated for basic parsers when the parsed value has a different
904 // type than the option value. e.g. HelpPrinter.
905 template<class ParserDT, class ValDT>
906 struct OptionDiffPrinter {
907 void print(const Option &O, const parser<ParserDT> P, const ValDT &/*V*/,
908 const OptionValue<ValDT> &/*Default*/, size_t GlobalWidth) {
909 P.printOptionNoValue(O, GlobalWidth);
913 // This is instantiated for basic parsers when the parsed value has the same
914 // type as the option value.
916 struct OptionDiffPrinter<DT, DT> {
917 void print(const Option &O, const parser<DT> P, const DT &V,
918 const OptionValue<DT> &Default, size_t GlobalWidth) {
919 P.printOptionDiff(O, V, Default, GlobalWidth);
923 // This overloaded function is selected by the basic parser, which may parse a
924 // different type than the option type.
925 template<class ParserClass, class ValDT>
926 void printOptionDiff(
928 const basic_parser<typename ParserClass::parser_data_type> &P,
929 const ValDT &V, const OptionValue<ValDT> &Default,
930 size_t GlobalWidth) {
932 OptionDiffPrinter<typename ParserClass::parser_data_type, ValDT> printer;
933 printer.print(O, static_cast<const ParserClass&>(P), V, Default,
937 //===----------------------------------------------------------------------===//
938 // applicator class - This class is used because we must use partial
939 // specialization to handle literal string arguments specially (const char* does
940 // not correctly respond to the apply method). Because the syntax to use this
941 // is a pain, we have the 'apply' method below to handle the nastiness...
943 template<class Mod> struct applicator {
945 static void opt(const Mod &M, Opt &O) { M.apply(O); }
948 // Handle const char* as a special case...
949 template<unsigned n> struct applicator<char[n]> {
951 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
953 template<unsigned n> struct applicator<const char[n]> {
955 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
957 template<> struct applicator<const char*> {
959 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
962 template<> struct applicator<NumOccurrencesFlag> {
963 static void opt(NumOccurrencesFlag NO, Option &O) {
964 O.setNumOccurrencesFlag(NO);
967 template<> struct applicator<ValueExpected> {
968 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
970 template<> struct applicator<OptionHidden> {
971 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
973 template<> struct applicator<FormattingFlags> {
974 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
976 template<> struct applicator<MiscFlags> {
977 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
980 // apply method - Apply a modifier to an option in a type safe way.
981 template<class Mod, class Opt>
982 void apply(const Mod &M, Opt *O) {
983 applicator<Mod>::opt(M, *O);
986 //===----------------------------------------------------------------------===//
989 // Default storage class definition: external storage. This implementation
990 // assumes the user will specify a variable to store the data into with the
991 // cl::location(x) modifier.
993 template<class DataType, bool ExternalStorage, bool isClass>
995 DataType *Location; // Where to store the object...
996 OptionValue<DataType> Default;
999 assert(Location != 0 && "cl::location(...) not specified for a command "
1000 "line option with external storage, "
1001 "or cl::init specified before cl::location()!!");
1004 opt_storage() : Location(0) {}
1006 bool setLocation(Option &O, DataType &L) {
1008 return O.error("cl::location(x) specified more than once!");
1015 void setValue(const T &V, bool initial = false) {
1022 DataType &getValue() { check(); return *Location; }
1023 const DataType &getValue() const { check(); return *Location; }
1025 operator DataType() const { return this->getValue(); }
1027 const OptionValue<DataType> &getDefault() const { return Default; }
1030 // Define how to hold a class type object, such as a string. Since we can
1031 // inherit from a class, we do so. This makes us exactly compatible with the
1032 // object in all cases that it is used.
1034 template<class DataType>
1035 class opt_storage<DataType,false,true> : public DataType {
1037 OptionValue<DataType> Default;
1040 void setValue(const T &V, bool initial = false) {
1041 DataType::operator=(V);
1046 DataType &getValue() { return *this; }
1047 const DataType &getValue() const { return *this; }
1049 const OptionValue<DataType> &getDefault() const { return Default; }
1052 // Define a partial specialization to handle things we cannot inherit from. In
1053 // this case, we store an instance through containment, and overload operators
1054 // to get at the value.
1056 template<class DataType>
1057 class opt_storage<DataType, false, false> {
1060 OptionValue<DataType> Default;
1062 // Make sure we initialize the value with the default constructor for the
1064 opt_storage() : Value(DataType()) {}
1067 void setValue(const T &V, bool initial = false) {
1072 DataType &getValue() { return Value; }
1073 DataType getValue() const { return Value; }
1075 const OptionValue<DataType> &getDefault() const { return Default; }
1077 operator DataType() const { return getValue(); }
1079 // If the datatype is a pointer, support -> on it.
1080 DataType operator->() const { return Value; }
1084 //===----------------------------------------------------------------------===//
1085 // opt - A scalar command line option.
1087 template <class DataType, bool ExternalStorage = false,
1088 class ParserClass = parser<DataType> >
1089 class opt : public Option,
1090 public opt_storage<DataType, ExternalStorage,
1091 is_class<DataType>::value> {
1094 virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
1096 typename ParserClass::parser_data_type Val =
1097 typename ParserClass::parser_data_type();
1098 if (Parser.parse(*this, ArgName, Arg, Val))
1099 return true; // Parse error!
1100 this->setValue(Val);
1101 this->setPosition(pos);
1105 virtual enum ValueExpected getValueExpectedFlagDefault() const {
1106 return Parser.getValueExpectedFlagDefault();
1108 virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
1109 return Parser.getExtraOptionNames(OptionNames);
1112 // Forward printing stuff to the parser...
1113 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1114 virtual void printOptionInfo(size_t GlobalWidth) const {
1115 Parser.printOptionInfo(*this, GlobalWidth);
1118 virtual void printOptionValue(size_t GlobalWidth, bool Force) const {
1119 if (Force || this->getDefault().compare(this->getValue())) {
1120 cl::printOptionDiff<ParserClass>(
1121 *this, Parser, this->getValue(), this->getDefault(), GlobalWidth);
1127 Parser.initialize(*this);
1130 // setInitialValue - Used by the cl::init modifier...
1131 void setInitialValue(const DataType &V) { this->setValue(V, true); }
1133 ParserClass &getParser() { return Parser; }
1136 DataType &operator=(const T &Val) {
1137 this->setValue(Val);
1138 return this->getValue();
1143 explicit opt(const M0t &M0) : Option(Optional | NotHidden) {
1149 template<class M0t, class M1t>
1150 opt(const M0t &M0, const M1t &M1) : Option(Optional | NotHidden) {
1151 apply(M0, this); apply(M1, this);
1156 template<class M0t, class M1t, class M2t>
1157 opt(const M0t &M0, const M1t &M1,
1158 const M2t &M2) : Option(Optional | NotHidden) {
1159 apply(M0, this); apply(M1, this); apply(M2, this);
1163 template<class M0t, class M1t, class M2t, class M3t>
1164 opt(const M0t &M0, const M1t &M1, const M2t &M2,
1165 const M3t &M3) : Option(Optional | NotHidden) {
1166 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1170 template<class M0t, class M1t, class M2t, class M3t, class M4t>
1171 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1172 const M4t &M4) : Option(Optional | NotHidden) {
1173 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1178 template<class M0t, class M1t, class M2t, class M3t,
1179 class M4t, class M5t>
1180 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1181 const M4t &M4, const M5t &M5) : Option(Optional | NotHidden) {
1182 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1183 apply(M4, this); apply(M5, this);
1187 template<class M0t, class M1t, class M2t, class M3t,
1188 class M4t, class M5t, class M6t>
1189 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1190 const M4t &M4, const M5t &M5,
1191 const M6t &M6) : Option(Optional | NotHidden) {
1192 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1193 apply(M4, this); apply(M5, this); apply(M6, this);
1197 template<class M0t, class M1t, class M2t, class M3t,
1198 class M4t, class M5t, class M6t, class M7t>
1199 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1200 const M4t &M4, const M5t &M5, const M6t &M6,
1201 const M7t &M7) : Option(Optional | NotHidden) {
1202 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1203 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1208 EXTERN_TEMPLATE_INSTANTIATION(class opt<unsigned>);
1209 EXTERN_TEMPLATE_INSTANTIATION(class opt<int>);
1210 EXTERN_TEMPLATE_INSTANTIATION(class opt<std::string>);
1211 EXTERN_TEMPLATE_INSTANTIATION(class opt<char>);
1212 EXTERN_TEMPLATE_INSTANTIATION(class opt<bool>);
1214 //===----------------------------------------------------------------------===//
1215 // list_storage class
1217 // Default storage class definition: external storage. This implementation
1218 // assumes the user will specify a variable to store the data into with the
1219 // cl::location(x) modifier.
1221 template<class DataType, class StorageClass>
1222 class list_storage {
1223 StorageClass *Location; // Where to store the object...
1226 list_storage() : Location(0) {}
1228 bool setLocation(Option &O, StorageClass &L) {
1230 return O.error("cl::location(x) specified more than once!");
1236 void addValue(const T &V) {
1237 assert(Location != 0 && "cl::location(...) not specified for a command "
1238 "line option with external storage!");
1239 Location->push_back(V);
1244 // Define how to hold a class type object, such as a string. Since we can
1245 // inherit from a class, we do so. This makes us exactly compatible with the
1246 // object in all cases that it is used.
1248 template<class DataType>
1249 class list_storage<DataType, bool> : public std::vector<DataType> {
1252 void addValue(const T &V) { std::vector<DataType>::push_back(V); }
1256 //===----------------------------------------------------------------------===//
1257 // list - A list of command line options.
1259 template <class DataType, class Storage = bool,
1260 class ParserClass = parser<DataType> >
1261 class list : public Option, public list_storage<DataType, Storage> {
1262 std::vector<unsigned> Positions;
1265 virtual enum ValueExpected getValueExpectedFlagDefault() const {
1266 return Parser.getValueExpectedFlagDefault();
1268 virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
1269 return Parser.getExtraOptionNames(OptionNames);
1272 virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
1273 typename ParserClass::parser_data_type Val =
1274 typename ParserClass::parser_data_type();
1275 if (Parser.parse(*this, ArgName, Arg, Val))
1276 return true; // Parse Error!
1277 list_storage<DataType, Storage>::addValue(Val);
1279 Positions.push_back(pos);
1283 // Forward printing stuff to the parser...
1284 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1285 virtual void printOptionInfo(size_t GlobalWidth) const {
1286 Parser.printOptionInfo(*this, GlobalWidth);
1289 // Unimplemented: list options don't currently store their default value.
1290 virtual void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const {}
1294 Parser.initialize(*this);
1297 ParserClass &getParser() { return Parser; }
1299 unsigned getPosition(unsigned optnum) const {
1300 assert(optnum < this->size() && "Invalid option index");
1301 return Positions[optnum];
1304 void setNumAdditionalVals(unsigned n) {
1305 Option::setNumAdditionalVals(n);
1310 explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1315 template<class M0t, class M1t>
1316 list(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1317 apply(M0, this); apply(M1, this);
1321 template<class M0t, class M1t, class M2t>
1322 list(const M0t &M0, const M1t &M1, const M2t &M2)
1323 : Option(ZeroOrMore | NotHidden) {
1324 apply(M0, this); apply(M1, this); apply(M2, this);
1328 template<class M0t, class M1t, class M2t, class M3t>
1329 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1330 : Option(ZeroOrMore | NotHidden) {
1331 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1335 template<class M0t, class M1t, class M2t, class M3t, class M4t>
1336 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1337 const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1338 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1343 template<class M0t, class M1t, class M2t, class M3t,
1344 class M4t, class M5t>
1345 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1346 const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1347 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1348 apply(M4, this); apply(M5, this);
1352 template<class M0t, class M1t, class M2t, class M3t,
1353 class M4t, class M5t, class M6t>
1354 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1355 const M4t &M4, const M5t &M5, const M6t &M6)
1356 : Option(ZeroOrMore | NotHidden) {
1357 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1358 apply(M4, this); apply(M5, this); apply(M6, this);
1362 template<class M0t, class M1t, class M2t, class M3t,
1363 class M4t, class M5t, class M6t, class M7t>
1364 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1365 const M4t &M4, const M5t &M5, const M6t &M6,
1366 const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1367 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1368 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1373 // multi_val - Modifier to set the number of additional values.
1375 unsigned AdditionalVals;
1376 explicit multi_val(unsigned N) : AdditionalVals(N) {}
1378 template <typename D, typename S, typename P>
1379 void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); }
1383 //===----------------------------------------------------------------------===//
1384 // bits_storage class
1386 // Default storage class definition: external storage. This implementation
1387 // assumes the user will specify a variable to store the data into with the
1388 // cl::location(x) modifier.
1390 template<class DataType, class StorageClass>
1391 class bits_storage {
1392 unsigned *Location; // Where to store the bits...
1395 static unsigned Bit(const T &V) {
1396 unsigned BitPos = reinterpret_cast<unsigned>(V);
1397 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1398 "enum exceeds width of bit vector!");
1403 bits_storage() : Location(0) {}
1405 bool setLocation(Option &O, unsigned &L) {
1407 return O.error("cl::location(x) specified more than once!");
1413 void addValue(const T &V) {
1414 assert(Location != 0 && "cl::location(...) not specified for a command "
1415 "line option with external storage!");
1416 *Location |= Bit(V);
1419 unsigned getBits() { return *Location; }
1422 bool isSet(const T &V) {
1423 return (*Location & Bit(V)) != 0;
1428 // Define how to hold bits. Since we can inherit from a class, we do so.
1429 // This makes us exactly compatible with the bits in all cases that it is used.
1431 template<class DataType>
1432 class bits_storage<DataType, bool> {
1433 unsigned Bits; // Where to store the bits...
1436 static unsigned Bit(const T &V) {
1437 unsigned BitPos = (unsigned)V;
1438 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1439 "enum exceeds width of bit vector!");
1445 void addValue(const T &V) {
1449 unsigned getBits() { return Bits; }
1452 bool isSet(const T &V) {
1453 return (Bits & Bit(V)) != 0;
1458 //===----------------------------------------------------------------------===//
1459 // bits - A bit vector of command options.
1461 template <class DataType, class Storage = bool,
1462 class ParserClass = parser<DataType> >
1463 class bits : public Option, public bits_storage<DataType, Storage> {
1464 std::vector<unsigned> Positions;
1467 virtual enum ValueExpected getValueExpectedFlagDefault() const {
1468 return Parser.getValueExpectedFlagDefault();
1470 virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
1471 return Parser.getExtraOptionNames(OptionNames);
1474 virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
1475 typename ParserClass::parser_data_type Val =
1476 typename ParserClass::parser_data_type();
1477 if (Parser.parse(*this, ArgName, Arg, Val))
1478 return true; // Parse Error!
1481 Positions.push_back(pos);
1485 // Forward printing stuff to the parser...
1486 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1487 virtual void printOptionInfo(size_t GlobalWidth) const {
1488 Parser.printOptionInfo(*this, GlobalWidth);
1491 // Unimplemented: bits options don't currently store their default values.
1492 virtual void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const {}
1496 Parser.initialize(*this);
1499 ParserClass &getParser() { return Parser; }
1501 unsigned getPosition(unsigned optnum) const {
1502 assert(optnum < this->size() && "Invalid option index");
1503 return Positions[optnum];
1508 explicit bits(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1513 template<class M0t, class M1t>
1514 bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1515 apply(M0, this); apply(M1, this);
1519 template<class M0t, class M1t, class M2t>
1520 bits(const M0t &M0, const M1t &M1, const M2t &M2)
1521 : Option(ZeroOrMore | NotHidden) {
1522 apply(M0, this); apply(M1, this); apply(M2, this);
1526 template<class M0t, class M1t, class M2t, class M3t>
1527 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1528 : Option(ZeroOrMore | NotHidden) {
1529 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1533 template<class M0t, class M1t, class M2t, class M3t, class M4t>
1534 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1535 const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1536 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1541 template<class M0t, class M1t, class M2t, class M3t,
1542 class M4t, class M5t>
1543 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1544 const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1545 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1546 apply(M4, this); apply(M5, this);
1550 template<class M0t, class M1t, class M2t, class M3t,
1551 class M4t, class M5t, class M6t>
1552 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1553 const M4t &M4, const M5t &M5, const M6t &M6)
1554 : Option(ZeroOrMore | NotHidden) {
1555 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1556 apply(M4, this); apply(M5, this); apply(M6, this);
1560 template<class M0t, class M1t, class M2t, class M3t,
1561 class M4t, class M5t, class M6t, class M7t>
1562 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1563 const M4t &M4, const M5t &M5, const M6t &M6,
1564 const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1565 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1566 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1571 //===----------------------------------------------------------------------===//
1572 // Aliased command line option (alias this name to a preexisting name)
1575 class alias : public Option {
1577 virtual bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
1579 return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1581 // Handle printing stuff...
1582 virtual size_t getOptionWidth() const;
1583 virtual void printOptionInfo(size_t GlobalWidth) const;
1585 // Aliases do not need to print their values.
1586 virtual void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const {}
1590 error("cl::alias must have argument name specified!");
1592 error("cl::alias must have an cl::aliasopt(option) specified!");
1596 void setAliasFor(Option &O) {
1598 error("cl::alias must only have one cl::aliasopt(...) specified!");
1604 explicit alias(const M0t &M0) : Option(Optional | Hidden), AliasFor(0) {
1609 template<class M0t, class M1t>
1610 alias(const M0t &M0, const M1t &M1) : Option(Optional | Hidden), AliasFor(0) {
1611 apply(M0, this); apply(M1, this);
1615 template<class M0t, class M1t, class M2t>
1616 alias(const M0t &M0, const M1t &M1, const M2t &M2)
1617 : Option(Optional | Hidden), AliasFor(0) {
1618 apply(M0, this); apply(M1, this); apply(M2, this);
1622 template<class M0t, class M1t, class M2t, class M3t>
1623 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1624 : Option(Optional | Hidden), AliasFor(0) {
1625 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1630 // aliasfor - Modifier to set the option an alias aliases.
1633 explicit aliasopt(Option &O) : Opt(O) {}
1634 void apply(alias &A) const { A.setAliasFor(Opt); }
1637 // extrahelp - provide additional help at the end of the normal help
1638 // output. All occurrences of cl::extrahelp will be accumulated and
1639 // printed to stderr at the end of the regular help, just before
1642 const char * morehelp;
1643 explicit extrahelp(const char* help);
1646 void PrintVersionMessage();
1647 // This function just prints the help message, exactly the same way as if the
1648 // -help option had been given on the command line.
1649 // NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
1650 void PrintHelpMessage();
1652 } // End namespace cl
1654 } // End namespace llvm