convert a bunch of std::strings to use StringRef. This should eliminate
[oota-llvm.git] / include / llvm / Support / CommandLine.h
1 //===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
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
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_SUPPORT_COMMANDLINE_H
21 #define LLVM_SUPPORT_COMMANDLINE_H
22
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"
27 #include <cassert>
28 #include <climits>
29 #include <cstdarg>
30 #include <utility>
31 #include <vector>
32
33 namespace llvm {
34   
35 /// cl Namespace - This namespace contains all of the command line option
36 /// processing machinery.  It is intentionally a short name to make qualified
37 /// usage concise.
38 namespace cl {
39
40 //===----------------------------------------------------------------------===//
41 // ParseCommandLineOptions - Command line option processing entry point.
42 //
43 void ParseCommandLineOptions(int argc, char **argv,
44                              const char *Overview = 0,
45                              bool ReadResponseFiles = false);
46
47 //===----------------------------------------------------------------------===//
48 // ParseEnvironmentOptions - Environment variable option processing alternate
49 //                           entry point.
50 //
51 void ParseEnvironmentOptions(const char *progName, const char *envvar,
52                              const char *Overview = 0,
53                              bool ReadResponseFiles = false);
54
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)());
61
62
63 // MarkOptionsChanged - Internal helper function.
64 void MarkOptionsChanged();
65
66 //===----------------------------------------------------------------------===//
67 // Flags permitted to be passed to command line arguments
68 //
69
70 enum NumOccurrences {          // Flags for the number of occurrences allowed
71   Optional        = 0x01,      // Zero or One occurrence
72   ZeroOrMore      = 0x02,      // Zero or more occurrences allowed
73   Required        = 0x03,      // One occurrence required
74   OneOrMore       = 0x04,      // One or more occurrences required
75
76   // ConsumeAfter - Indicates that this option is fed anything that follows the
77   // last positional argument required by the application (it is an error if
78   // there are zero positional arguments, and a ConsumeAfter option is used).
79   // Thus, for example, all arguments to LLI are processed until a filename is
80   // found.  Once a filename is found, all of the succeeding arguments are
81   // passed, unprocessed, to the ConsumeAfter option.
82   //
83   ConsumeAfter    = 0x05,
84
85   OccurrencesMask  = 0x07
86 };
87
88 enum ValueExpected {           // Is a value required for the option?
89   ValueOptional   = 0x08,      // The value can appear... or not
90   ValueRequired   = 0x10,      // The value is required to appear!
91   ValueDisallowed = 0x18,      // A value may not be specified (for flags)
92   ValueMask       = 0x18
93 };
94
95 enum OptionHidden {            // Control whether -help shows this option
96   NotHidden       = 0x20,      // Option included in --help & --help-hidden
97   Hidden          = 0x40,      // -help doesn't, but --help-hidden does
98   ReallyHidden    = 0x60,      // Neither --help nor --help-hidden show this arg
99   HiddenMask      = 0x60
100 };
101
102 // Formatting flags - This controls special features that the option might have
103 // that cause it to be parsed differently...
104 //
105 // Prefix - This option allows arguments that are otherwise unrecognized to be
106 // matched by options that are a prefix of the actual value.  This is useful for
107 // cases like a linker, where options are typically of the form '-lfoo' or
108 // '-L../../include' where -l or -L are the actual flags.  When prefix is
109 // enabled, and used, the value for the flag comes from the suffix of the
110 // argument.
111 //
112 // Grouping - With this option enabled, multiple letter options are allowed to
113 // bunch together with only a single hyphen for the whole group.  This allows
114 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
115 //
116
117 enum FormattingFlags {
118   NormalFormatting = 0x000,     // Nothing special
119   Positional       = 0x080,     // Is a positional argument, no '-' required
120   Prefix           = 0x100,     // Can this option directly prefix its value?
121   Grouping         = 0x180,     // Can this option group with other options?
122   FormattingMask   = 0x180      // Union of the above flags.
123 };
124
125 enum MiscFlags {               // Miscellaneous flags to adjust argument
126   CommaSeparated     = 0x200,  // Should this cl::list split between commas?
127   PositionalEatsArgs = 0x400,  // Should this positional cl::list eat -args?
128   Sink               = 0x800,  // Should this cl::list eat all unknown options?
129   MiscMask           = 0xE00   // Union of the above flags.
130 };
131
132
133
134 //===----------------------------------------------------------------------===//
135 // Option Base class
136 //
137 class alias;
138 class Option {
139   friend class alias;
140
141   // handleOccurrences - Overriden by subclasses to handle the value passed into
142   // an argument.  Should return true if there was an error processing the
143   // argument and the program should exit.
144   //
145   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
146                                 StringRef Arg) = 0;
147
148   virtual enum ValueExpected getValueExpectedFlagDefault() const {
149     return ValueOptional;
150   }
151
152   // Out of line virtual function to provide home for the class.
153   virtual void anchor();
154
155   int NumOccurrences;     // The number of times specified
156   int Flags;              // Flags for the argument
157   unsigned Position;      // Position of last occurrence of the option
158   unsigned AdditionalVals;// Greater than 0 for multi-valued option.
159   Option *NextRegistered; // Singly linked list of registered options.
160 public:
161   const char *ArgStr;     // The argument string itself (ex: "help", "o")
162   const char *HelpStr;    // The descriptive text message for --help
163   const char *ValueStr;   // String describing what the value of this option is
164
165   inline enum NumOccurrences getNumOccurrencesFlag() const {
166     return static_cast<enum NumOccurrences>(Flags & OccurrencesMask);
167   }
168   inline enum ValueExpected getValueExpectedFlag() const {
169     int VE = Flags & ValueMask;
170     return VE ? static_cast<enum ValueExpected>(VE)
171               : getValueExpectedFlagDefault();
172   }
173   inline enum OptionHidden getOptionHiddenFlag() const {
174     return static_cast<enum OptionHidden>(Flags & HiddenMask);
175   }
176   inline enum FormattingFlags getFormattingFlag() const {
177     return static_cast<enum FormattingFlags>(Flags & FormattingMask);
178   }
179   inline unsigned getMiscFlags() const {
180     return Flags & MiscMask;
181   }
182   inline unsigned getPosition() const { return Position; }
183   inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
184
185   // hasArgStr - Return true if the argstr != ""
186   bool hasArgStr() const { return ArgStr[0] != 0; }
187
188   //-------------------------------------------------------------------------===
189   // Accessor functions set by OptionModifiers
190   //
191   void setArgStr(const char *S) { ArgStr = S; }
192   void setDescription(const char *S) { HelpStr = S; }
193   void setValueStr(const char *S) { ValueStr = S; }
194
195   void setFlag(unsigned Flag, unsigned FlagMask) {
196     Flags &= ~FlagMask;
197     Flags |= Flag;
198   }
199
200   void setNumOccurrencesFlag(enum NumOccurrences Val) {
201     setFlag(Val, OccurrencesMask);
202   }
203   void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
204   void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
205   void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
206   void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
207   void setPosition(unsigned pos) { Position = pos; }
208 protected:
209   explicit Option(unsigned DefaultFlags)
210     : NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0),
211       AdditionalVals(0), NextRegistered(0),
212       ArgStr(""), HelpStr(""), ValueStr("") {
213     assert(getNumOccurrencesFlag() != 0 &&
214            getOptionHiddenFlag() != 0 && "Not all default flags specified!");
215   }
216
217   inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
218 public:
219   // addArgument - Register this argument with the commandline system.
220   //
221   void addArgument();
222
223   Option *getNextRegisteredOption() const { return NextRegistered; }
224
225   // Return the width of the option tag for printing...
226   virtual size_t getOptionWidth() const = 0;
227
228   // printOptionInfo - Print out information about this option.  The
229   // to-be-maintained width is specified.
230   //
231   virtual void printOptionInfo(size_t GlobalWidth) const = 0;
232
233   virtual void getExtraOptionNames(std::vector<const char*> &) {}
234
235   // addOccurrence - Wrapper around handleOccurrence that enforces Flags
236   //
237   bool addOccurrence(unsigned pos, const char *ArgName,
238                      StringRef Value, bool MultiArg = false);
239
240   // Prints option name followed by message.  Always returns true.
241   bool error(const Twine &Message, const char *ArgName = 0);
242
243 public:
244   inline int getNumOccurrences() const { return NumOccurrences; }
245   virtual ~Option() {}
246 };
247
248
249 //===----------------------------------------------------------------------===//
250 // Command line option modifiers that can be used to modify the behavior of
251 // command line option parsers...
252 //
253
254 // desc - Modifier to set the description shown in the --help output...
255 struct desc {
256   const char *Desc;
257   desc(const char *Str) : Desc(Str) {}
258   void apply(Option &O) const { O.setDescription(Desc); }
259 };
260
261 // value_desc - Modifier to set the value description shown in the --help
262 // output...
263 struct value_desc {
264   const char *Desc;
265   value_desc(const char *Str) : Desc(Str) {}
266   void apply(Option &O) const { O.setValueStr(Desc); }
267 };
268
269 // init - Specify a default (initial) value for the command line argument, if
270 // the default constructor for the argument type does not give you what you
271 // want.  This is only valid on "opt" arguments, not on "list" arguments.
272 //
273 template<class Ty>
274 struct initializer {
275   const Ty &Init;
276   initializer(const Ty &Val) : Init(Val) {}
277
278   template<class Opt>
279   void apply(Opt &O) const { O.setInitialValue(Init); }
280 };
281
282 template<class Ty>
283 initializer<Ty> init(const Ty &Val) {
284   return initializer<Ty>(Val);
285 }
286
287
288 // location - Allow the user to specify which external variable they want to
289 // store the results of the command line argument processing into, if they don't
290 // want to store it in the option itself.
291 //
292 template<class Ty>
293 struct LocationClass {
294   Ty &Loc;
295   LocationClass(Ty &L) : Loc(L) {}
296
297   template<class Opt>
298   void apply(Opt &O) const { O.setLocation(O, Loc); }
299 };
300
301 template<class Ty>
302 LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
303
304
305 //===----------------------------------------------------------------------===//
306 // Enum valued command line option
307 //
308 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, int(ENUMVAL), DESC
309 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, int(ENUMVAL), DESC
310 #define clEnumValEnd (reinterpret_cast<void*>(0))
311
312 // values - For custom data types, allow specifying a group of values together
313 // as the values that go into the mapping that the option handler uses.  Note
314 // that the values list must always have a 0 at the end of the list to indicate
315 // that the list has ended.
316 //
317 template<class DataType>
318 class ValuesClass {
319   // Use a vector instead of a map, because the lists should be short,
320   // the overhead is less, and most importantly, it keeps them in the order
321   // inserted so we can print our option out nicely.
322   SmallVector<std::pair<const char *, std::pair<int, const char *> >,4> Values;
323   void processValues(va_list Vals);
324 public:
325   ValuesClass(const char *EnumName, DataType Val, const char *Desc,
326               va_list ValueArgs) {
327     // Insert the first value, which is required.
328     Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
329
330     // Process the varargs portion of the values...
331     while (const char *enumName = va_arg(ValueArgs, const char *)) {
332       DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
333       const char *EnumDesc = va_arg(ValueArgs, const char *);
334       Values.push_back(std::make_pair(enumName,      // Add value to value map
335                                       std::make_pair(EnumVal, EnumDesc)));
336     }
337   }
338
339   template<class Opt>
340   void apply(Opt &O) const {
341     for (unsigned i = 0, e = static_cast<unsigned>(Values.size());
342          i != e; ++i)
343       O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
344                                      Values[i].second.second);
345   }
346 };
347
348 template<class DataType>
349 ValuesClass<DataType> END_WITH_NULL values(const char *Arg, DataType Val,
350                                            const char *Desc, ...) {
351     va_list ValueArgs;
352     va_start(ValueArgs, Desc);
353     ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
354     va_end(ValueArgs);
355     return Vals;
356 }
357
358
359 //===----------------------------------------------------------------------===//
360 // parser class - Parameterizable parser for different data types.  By default,
361 // known data types (string, int, bool) have specialized parsers, that do what
362 // you would expect.  The default parser, used for data types that are not
363 // built-in, uses a mapping table to map specific options to values, which is
364 // used, among other things, to handle enum types.
365
366 //--------------------------------------------------
367 // generic_parser_base - This class holds all the non-generic code that we do
368 // not need replicated for every instance of the generic parser.  This also
369 // allows us to put stuff into CommandLine.cpp
370 //
371 struct generic_parser_base {
372   virtual ~generic_parser_base() {}  // Base class should have virtual-dtor
373
374   // getNumOptions - Virtual function implemented by generic subclass to
375   // indicate how many entries are in Values.
376   //
377   virtual unsigned getNumOptions() const = 0;
378
379   // getOption - Return option name N.
380   virtual const char *getOption(unsigned N) const = 0;
381
382   // getDescription - Return description N
383   virtual const char *getDescription(unsigned N) const = 0;
384
385   // Return the width of the option tag for printing...
386   virtual size_t getOptionWidth(const Option &O) const;
387
388   // printOptionInfo - Print out information about this option.  The
389   // to-be-maintained width is specified.
390   //
391   virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const;
392
393   void initialize(Option &O) {
394     // All of the modifiers for the option have been processed by now, so the
395     // argstr field should be stable, copy it down now.
396     //
397     hasArgStr = O.hasArgStr();
398   }
399
400   void getExtraOptionNames(std::vector<const char*> &OptionNames) {
401     // If there has been no argstr specified, that means that we need to add an
402     // argument for every possible option.  This ensures that our options are
403     // vectored to us.
404     if (!hasArgStr)
405       for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
406         OptionNames.push_back(getOption(i));
407   }
408
409
410   enum ValueExpected getValueExpectedFlagDefault() const {
411     // If there is an ArgStr specified, then we are of the form:
412     //
413     //    -opt=O2   or   -opt O2  or  -optO2
414     //
415     // In which case, the value is required.  Otherwise if an arg str has not
416     // been specified, we are of the form:
417     //
418     //    -O2 or O2 or -la (where -l and -a are separate options)
419     //
420     // If this is the case, we cannot allow a value.
421     //
422     if (hasArgStr)
423       return ValueRequired;
424     else
425       return ValueDisallowed;
426   }
427
428   // findOption - Return the option number corresponding to the specified
429   // argument string.  If the option is not found, getNumOptions() is returned.
430   //
431   unsigned findOption(const char *Name);
432
433 protected:
434   bool hasArgStr;
435 };
436
437 // Default parser implementation - This implementation depends on having a
438 // mapping of recognized options to values of some sort.  In addition to this,
439 // each entry in the mapping also tracks a help message that is printed with the
440 // command line option for --help.  Because this is a simple mapping parser, the
441 // data type can be any unsupported type.
442 //
443 template <class DataType>
444 class parser : public generic_parser_base {
445 protected:
446   SmallVector<std::pair<const char *,
447                         std::pair<DataType, const char *> >, 8> Values;
448 public:
449   typedef DataType parser_data_type;
450
451   // Implement virtual functions needed by generic_parser_base
452   unsigned getNumOptions() const { return unsigned(Values.size()); }
453   const char *getOption(unsigned N) const { return Values[N].first; }
454   const char *getDescription(unsigned N) const {
455     return Values[N].second.second;
456   }
457
458   // parse - Return true on error.
459   bool parse(Option &O, const char *ArgName, StringRef Arg, DataType &V) {
460     StringRef ArgVal;
461     if (hasArgStr)
462       ArgVal = Arg;
463     else
464       ArgVal = ArgName;
465
466     for (unsigned i = 0, e = static_cast<unsigned>(Values.size());
467          i != e; ++i)
468       if (Values[i].first == ArgVal) {
469         V = Values[i].second.first;
470         return false;
471       }
472
473     return O.error("Cannot find option named '" + ArgVal + "'!");
474   }
475
476   /// addLiteralOption - Add an entry to the mapping table.
477   ///
478   template <class DT>
479   void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
480     assert(findOption(Name) == Values.size() && "Option already exists!");
481     Values.push_back(std::make_pair(Name,
482                              std::make_pair(static_cast<DataType>(V),HelpStr)));
483     MarkOptionsChanged();
484   }
485
486   /// removeLiteralOption - Remove the specified option.
487   ///
488   void removeLiteralOption(const char *Name) {
489     unsigned N = findOption(Name);
490     assert(N != Values.size() && "Option not found!");
491     Values.erase(Values.begin()+N);
492   }
493 };
494
495 //--------------------------------------------------
496 // basic_parser - Super class of parsers to provide boilerplate code
497 //
498 struct basic_parser_impl {  // non-template implementation of basic_parser<t>
499   virtual ~basic_parser_impl() {}
500
501   enum ValueExpected getValueExpectedFlagDefault() const {
502     return ValueRequired;
503   }
504
505   void getExtraOptionNames(std::vector<const char*> &) {}
506
507   void initialize(Option &) {}
508
509   // Return the width of the option tag for printing...
510   size_t getOptionWidth(const Option &O) const;
511
512   // printOptionInfo - Print out information about this option.  The
513   // to-be-maintained width is specified.
514   //
515   void printOptionInfo(const Option &O, size_t GlobalWidth) const;
516
517   // getValueName - Overload in subclass to provide a better default value.
518   virtual const char *getValueName() const { return "value"; }
519
520   // An out-of-line virtual method to provide a 'home' for this class.
521   virtual void anchor();
522 };
523
524 // basic_parser - The real basic parser is just a template wrapper that provides
525 // a typedef for the provided data type.
526 //
527 template<class DataType>
528 struct basic_parser : public basic_parser_impl {
529   typedef DataType parser_data_type;
530 };
531
532 //--------------------------------------------------
533 // parser<bool>
534 //
535 template<>
536 class parser<bool> : public basic_parser<bool> {
537   const char *ArgStr;
538 public:
539
540   // parse - Return true on error.
541   bool parse(Option &O, const char *ArgName, StringRef Arg, bool &Val);
542
543   template <class Opt>
544   void initialize(Opt &O) {
545     ArgStr = O.ArgStr;
546   }
547
548   enum ValueExpected getValueExpectedFlagDefault() const {
549     return ValueOptional;
550   }
551
552   // getValueName - Do not print =<value> at all.
553   virtual const char *getValueName() const { return 0; }
554
555   // An out-of-line virtual method to provide a 'home' for this class.
556   virtual void anchor();
557 };
558
559 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<bool>);
560
561 //--------------------------------------------------
562 // parser<boolOrDefault>
563 enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
564 template<>
565 class parser<boolOrDefault> : public basic_parser<boolOrDefault> {
566 public:
567   // parse - Return true on error.
568   bool parse(Option &O, const char *ArgName, StringRef Arg, boolOrDefault &Val);
569
570   enum ValueExpected getValueExpectedFlagDefault() const {
571     return ValueOptional;
572   }
573
574   // getValueName - Do not print =<value> at all.
575   virtual const char *getValueName() const { return 0; }
576
577   // An out-of-line virtual method to provide a 'home' for this class.
578   virtual void anchor();
579 };
580
581 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
582
583 //--------------------------------------------------
584 // parser<int>
585 //
586 template<>
587 class parser<int> : public basic_parser<int> {
588 public:
589   // parse - Return true on error.
590   bool parse(Option &O, const char *ArgName, StringRef Arg, int &Val);
591
592   // getValueName - Overload in subclass to provide a better default value.
593   virtual const char *getValueName() const { return "int"; }
594
595   // An out-of-line virtual method to provide a 'home' for this class.
596   virtual void anchor();
597 };
598
599 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>);
600
601
602 //--------------------------------------------------
603 // parser<unsigned>
604 //
605 template<>
606 class parser<unsigned> : public basic_parser<unsigned> {
607 public:
608   // parse - Return true on error.
609   bool parse(Option &O, const char *AN, StringRef Arg, unsigned &Val);
610
611   // getValueName - Overload in subclass to provide a better default value.
612   virtual const char *getValueName() const { return "uint"; }
613
614   // An out-of-line virtual method to provide a 'home' for this class.
615   virtual void anchor();
616 };
617
618 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
619
620 //--------------------------------------------------
621 // parser<double>
622 //
623 template<>
624 class parser<double> : public basic_parser<double> {
625 public:
626   // parse - Return true on error.
627   bool parse(Option &O, const char *AN, StringRef Arg, double &Val);
628
629   // getValueName - Overload in subclass to provide a better default value.
630   virtual const char *getValueName() const { return "number"; }
631
632   // An out-of-line virtual method to provide a 'home' for this class.
633   virtual void anchor();
634 };
635
636 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<double>);
637
638 //--------------------------------------------------
639 // parser<float>
640 //
641 template<>
642 class parser<float> : public basic_parser<float> {
643 public:
644   // parse - Return true on error.
645   bool parse(Option &O, const char *AN, StringRef Arg, float &Val);
646
647   // getValueName - Overload in subclass to provide a better default value.
648   virtual const char *getValueName() const { return "number"; }
649
650   // An out-of-line virtual method to provide a 'home' for this class.
651   virtual void anchor();
652 };
653
654 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<float>);
655
656 //--------------------------------------------------
657 // parser<std::string>
658 //
659 template<>
660 class parser<std::string> : public basic_parser<std::string> {
661 public:
662   // parse - Return true on error.
663   bool parse(Option &, const char *, StringRef Arg, std::string &Value) {
664     Value = Arg.str();
665     return false;
666   }
667
668   // getValueName - Overload in subclass to provide a better default value.
669   virtual const char *getValueName() const { return "string"; }
670
671   // An out-of-line virtual method to provide a 'home' for this class.
672   virtual void anchor();
673 };
674
675 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
676
677 //--------------------------------------------------
678 // parser<char>
679 //
680 template<>
681 class parser<char> : public basic_parser<char> {
682 public:
683   // parse - Return true on error.
684   bool parse(Option &, const char *, StringRef Arg, char &Value) {
685     Value = Arg[0];
686     return false;
687   }
688
689   // getValueName - Overload in subclass to provide a better default value.
690   virtual const char *getValueName() const { return "char"; }
691
692   // An out-of-line virtual method to provide a 'home' for this class.
693   virtual void anchor();
694 };
695
696 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<char>);
697
698 //===----------------------------------------------------------------------===//
699 // applicator class - This class is used because we must use partial
700 // specialization to handle literal string arguments specially (const char* does
701 // not correctly respond to the apply method).  Because the syntax to use this
702 // is a pain, we have the 'apply' method below to handle the nastiness...
703 //
704 template<class Mod> struct applicator {
705   template<class Opt>
706   static void opt(const Mod &M, Opt &O) { M.apply(O); }
707 };
708
709 // Handle const char* as a special case...
710 template<unsigned n> struct applicator<char[n]> {
711   template<class Opt>
712   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
713 };
714 template<unsigned n> struct applicator<const char[n]> {
715   template<class Opt>
716   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
717 };
718 template<> struct applicator<const char*> {
719   template<class Opt>
720   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
721 };
722
723 template<> struct applicator<NumOccurrences> {
724   static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); }
725 };
726 template<> struct applicator<ValueExpected> {
727   static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
728 };
729 template<> struct applicator<OptionHidden> {
730   static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
731 };
732 template<> struct applicator<FormattingFlags> {
733   static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
734 };
735 template<> struct applicator<MiscFlags> {
736   static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
737 };
738
739 // apply method - Apply a modifier to an option in a type safe way.
740 template<class Mod, class Opt>
741 void apply(const Mod &M, Opt *O) {
742   applicator<Mod>::opt(M, *O);
743 }
744
745
746 //===----------------------------------------------------------------------===//
747 // opt_storage class
748
749 // Default storage class definition: external storage.  This implementation
750 // assumes the user will specify a variable to store the data into with the
751 // cl::location(x) modifier.
752 //
753 template<class DataType, bool ExternalStorage, bool isClass>
754 class opt_storage {
755   DataType *Location;   // Where to store the object...
756
757   void check() const {
758     assert(Location != 0 && "cl::location(...) not specified for a command "
759            "line option with external storage, "
760            "or cl::init specified before cl::location()!!");
761   }
762 public:
763   opt_storage() : Location(0) {}
764
765   bool setLocation(Option &O, DataType &L) {
766     if (Location)
767       return O.error("cl::location(x) specified more than once!");
768     Location = &L;
769     return false;
770   }
771
772   template<class T>
773   void setValue(const T &V) {
774     check();
775     *Location = V;
776   }
777
778   DataType &getValue() { check(); return *Location; }
779   const DataType &getValue() const { check(); return *Location; }
780 };
781
782
783 // Define how to hold a class type object, such as a string.  Since we can
784 // inherit from a class, we do so.  This makes us exactly compatible with the
785 // object in all cases that it is used.
786 //
787 template<class DataType>
788 class opt_storage<DataType,false,true> : public DataType {
789 public:
790   template<class T>
791   void setValue(const T &V) { DataType::operator=(V); }
792
793   DataType &getValue() { return *this; }
794   const DataType &getValue() const { return *this; }
795 };
796
797 // Define a partial specialization to handle things we cannot inherit from.  In
798 // this case, we store an instance through containment, and overload operators
799 // to get at the value.
800 //
801 template<class DataType>
802 class opt_storage<DataType, false, false> {
803 public:
804   DataType Value;
805
806   // Make sure we initialize the value with the default constructor for the
807   // type.
808   opt_storage() : Value(DataType()) {}
809
810   template<class T>
811   void setValue(const T &V) { Value = V; }
812   DataType &getValue() { return Value; }
813   DataType getValue() const { return Value; }
814
815   // If the datatype is a pointer, support -> on it.
816   DataType operator->() const { return Value; }
817 };
818
819
820 //===----------------------------------------------------------------------===//
821 // opt - A scalar command line option.
822 //
823 template <class DataType, bool ExternalStorage = false,
824           class ParserClass = parser<DataType> >
825 class opt : public Option,
826             public opt_storage<DataType, ExternalStorage,
827                                is_class<DataType>::value> {
828   ParserClass Parser;
829
830   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
831                                 StringRef Arg) {
832     typename ParserClass::parser_data_type Val =
833        typename ParserClass::parser_data_type();
834     if (Parser.parse(*this, ArgName, Arg, Val))
835       return true;                            // Parse error!
836     this->setValue(Val);
837     this->setPosition(pos);
838     return false;
839   }
840
841   virtual enum ValueExpected getValueExpectedFlagDefault() const {
842     return Parser.getValueExpectedFlagDefault();
843   }
844   virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
845     return Parser.getExtraOptionNames(OptionNames);
846   }
847
848   // Forward printing stuff to the parser...
849   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
850   virtual void printOptionInfo(size_t GlobalWidth) const {
851     Parser.printOptionInfo(*this, GlobalWidth);
852   }
853
854   void done() {
855     addArgument();
856     Parser.initialize(*this);
857   }
858 public:
859   // setInitialValue - Used by the cl::init modifier...
860   void setInitialValue(const DataType &V) { this->setValue(V); }
861
862   ParserClass &getParser() { return Parser; }
863
864   operator DataType() const { return this->getValue(); }
865
866   template<class T>
867   DataType &operator=(const T &Val) {
868     this->setValue(Val);
869     return this->getValue();
870   }
871
872   // One option...
873   template<class M0t>
874   explicit opt(const M0t &M0) : Option(Optional | NotHidden) {
875     apply(M0, this);
876     done();
877   }
878
879   // Two options...
880   template<class M0t, class M1t>
881   opt(const M0t &M0, const M1t &M1) : Option(Optional | NotHidden) {
882     apply(M0, this); apply(M1, this);
883     done();
884   }
885
886   // Three options...
887   template<class M0t, class M1t, class M2t>
888   opt(const M0t &M0, const M1t &M1,
889       const M2t &M2) : Option(Optional | NotHidden) {
890     apply(M0, this); apply(M1, this); apply(M2, this);
891     done();
892   }
893   // Four options...
894   template<class M0t, class M1t, class M2t, class M3t>
895   opt(const M0t &M0, const M1t &M1, const M2t &M2,
896       const M3t &M3) : Option(Optional | NotHidden) {
897     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
898     done();
899   }
900   // Five options...
901   template<class M0t, class M1t, class M2t, class M3t, class M4t>
902   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
903       const M4t &M4) : Option(Optional | NotHidden) {
904     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
905     apply(M4, this);
906     done();
907   }
908   // Six options...
909   template<class M0t, class M1t, class M2t, class M3t,
910            class M4t, class M5t>
911   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
912       const M4t &M4, const M5t &M5) : Option(Optional | NotHidden) {
913     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
914     apply(M4, this); apply(M5, this);
915     done();
916   }
917   // Seven options...
918   template<class M0t, class M1t, class M2t, class M3t,
919            class M4t, class M5t, class M6t>
920   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
921       const M4t &M4, const M5t &M5,
922       const M6t &M6) : Option(Optional | NotHidden) {
923     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
924     apply(M4, this); apply(M5, this); apply(M6, this);
925     done();
926   }
927   // Eight options...
928   template<class M0t, class M1t, class M2t, class M3t,
929            class M4t, class M5t, class M6t, class M7t>
930   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
931       const M4t &M4, const M5t &M5, const M6t &M6,
932       const M7t &M7) : Option(Optional | NotHidden) {
933     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
934     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
935     done();
936   }
937 };
938
939 EXTERN_TEMPLATE_INSTANTIATION(class opt<unsigned>);
940 EXTERN_TEMPLATE_INSTANTIATION(class opt<int>);
941 EXTERN_TEMPLATE_INSTANTIATION(class opt<std::string>);
942 EXTERN_TEMPLATE_INSTANTIATION(class opt<char>);
943 EXTERN_TEMPLATE_INSTANTIATION(class opt<bool>);
944
945 //===----------------------------------------------------------------------===//
946 // list_storage class
947
948 // Default storage class definition: external storage.  This implementation
949 // assumes the user will specify a variable to store the data into with the
950 // cl::location(x) modifier.
951 //
952 template<class DataType, class StorageClass>
953 class list_storage {
954   StorageClass *Location;   // Where to store the object...
955
956 public:
957   list_storage() : Location(0) {}
958
959   bool setLocation(Option &O, StorageClass &L) {
960     if (Location)
961       return O.error("cl::location(x) specified more than once!");
962     Location = &L;
963     return false;
964   }
965
966   template<class T>
967   void addValue(const T &V) {
968     assert(Location != 0 && "cl::location(...) not specified for a command "
969            "line option with external storage!");
970     Location->push_back(V);
971   }
972 };
973
974
975 // Define how to hold a class type object, such as a string.  Since we can
976 // inherit from a class, we do so.  This makes us exactly compatible with the
977 // object in all cases that it is used.
978 //
979 template<class DataType>
980 class list_storage<DataType, bool> : public std::vector<DataType> {
981 public:
982   template<class T>
983   void addValue(const T &V) { push_back(V); }
984 };
985
986
987 //===----------------------------------------------------------------------===//
988 // list - A list of command line options.
989 //
990 template <class DataType, class Storage = bool,
991           class ParserClass = parser<DataType> >
992 class list : public Option, public list_storage<DataType, Storage> {
993   std::vector<unsigned> Positions;
994   ParserClass Parser;
995
996   virtual enum ValueExpected getValueExpectedFlagDefault() const {
997     return Parser.getValueExpectedFlagDefault();
998   }
999   virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
1000     return Parser.getExtraOptionNames(OptionNames);
1001   }
1002
1003   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
1004                                 StringRef Arg) {
1005     typename ParserClass::parser_data_type Val =
1006       typename ParserClass::parser_data_type();
1007     if (Parser.parse(*this, ArgName, Arg, Val))
1008       return true;  // Parse Error!
1009     addValue(Val);
1010     setPosition(pos);
1011     Positions.push_back(pos);
1012     return false;
1013   }
1014
1015   // Forward printing stuff to the parser...
1016   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1017   virtual void printOptionInfo(size_t GlobalWidth) const {
1018     Parser.printOptionInfo(*this, GlobalWidth);
1019   }
1020
1021   void done() {
1022     addArgument();
1023     Parser.initialize(*this);
1024   }
1025 public:
1026   ParserClass &getParser() { return Parser; }
1027
1028   unsigned getPosition(unsigned optnum) const {
1029     assert(optnum < this->size() && "Invalid option index");
1030     return Positions[optnum];
1031   }
1032
1033   void setNumAdditionalVals(unsigned n) {
1034     Option::setNumAdditionalVals(n);
1035   }
1036
1037   // One option...
1038   template<class M0t>
1039   explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1040     apply(M0, this);
1041     done();
1042   }
1043   // Two options...
1044   template<class M0t, class M1t>
1045   list(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1046     apply(M0, this); apply(M1, this);
1047     done();
1048   }
1049   // Three options...
1050   template<class M0t, class M1t, class M2t>
1051   list(const M0t &M0, const M1t &M1, const M2t &M2)
1052     : Option(ZeroOrMore | NotHidden) {
1053     apply(M0, this); apply(M1, this); apply(M2, this);
1054     done();
1055   }
1056   // Four options...
1057   template<class M0t, class M1t, class M2t, class M3t>
1058   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1059     : Option(ZeroOrMore | NotHidden) {
1060     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1061     done();
1062   }
1063   // Five options...
1064   template<class M0t, class M1t, class M2t, class M3t, class M4t>
1065   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1066        const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1067     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1068     apply(M4, this);
1069     done();
1070   }
1071   // Six options...
1072   template<class M0t, class M1t, class M2t, class M3t,
1073            class M4t, class M5t>
1074   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1075        const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1076     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1077     apply(M4, this); apply(M5, this);
1078     done();
1079   }
1080   // Seven options...
1081   template<class M0t, class M1t, class M2t, class M3t,
1082            class M4t, class M5t, class M6t>
1083   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1084        const M4t &M4, const M5t &M5, const M6t &M6)
1085     : Option(ZeroOrMore | NotHidden) {
1086     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1087     apply(M4, this); apply(M5, this); apply(M6, this);
1088     done();
1089   }
1090   // Eight options...
1091   template<class M0t, class M1t, class M2t, class M3t,
1092            class M4t, class M5t, class M6t, class M7t>
1093   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1094        const M4t &M4, const M5t &M5, const M6t &M6,
1095        const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1096     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1097     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1098     done();
1099   }
1100 };
1101
1102 // multi_val - Modifier to set the number of additional values.
1103 struct multi_val {
1104   unsigned AdditionalVals;
1105   explicit multi_val(unsigned N) : AdditionalVals(N) {}
1106
1107   template <typename D, typename S, typename P>
1108   void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); }
1109 };
1110
1111
1112 //===----------------------------------------------------------------------===//
1113 // bits_storage class
1114
1115 // Default storage class definition: external storage.  This implementation
1116 // assumes the user will specify a variable to store the data into with the
1117 // cl::location(x) modifier.
1118 //
1119 template<class DataType, class StorageClass>
1120 class bits_storage {
1121   unsigned *Location;   // Where to store the bits...
1122
1123   template<class T>
1124   static unsigned Bit(const T &V) {
1125     unsigned BitPos = reinterpret_cast<unsigned>(V);
1126     assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1127           "enum exceeds width of bit vector!");
1128     return 1 << BitPos;
1129   }
1130
1131 public:
1132   bits_storage() : Location(0) {}
1133
1134   bool setLocation(Option &O, unsigned &L) {
1135     if (Location)
1136       return O.error("cl::location(x) specified more than once!");
1137     Location = &L;
1138     return false;
1139   }
1140
1141   template<class T>
1142   void addValue(const T &V) {
1143     assert(Location != 0 && "cl::location(...) not specified for a command "
1144            "line option with external storage!");
1145     *Location |= Bit(V);
1146   }
1147
1148   unsigned getBits() { return *Location; }
1149
1150   template<class T>
1151   bool isSet(const T &V) {
1152     return (*Location & Bit(V)) != 0;
1153   }
1154 };
1155
1156
1157 // Define how to hold bits.  Since we can inherit from a class, we do so.
1158 // This makes us exactly compatible with the bits in all cases that it is used.
1159 //
1160 template<class DataType>
1161 class bits_storage<DataType, bool> {
1162   unsigned Bits;   // Where to store the bits...
1163
1164   template<class T>
1165   static unsigned Bit(const T &V) {
1166     unsigned BitPos = reinterpret_cast<unsigned>(V);
1167     assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1168           "enum exceeds width of bit vector!");
1169     return 1 << BitPos;
1170   }
1171
1172 public:
1173   template<class T>
1174   void addValue(const T &V) {
1175     Bits |=  Bit(V);
1176   }
1177
1178   unsigned getBits() { return Bits; }
1179
1180   template<class T>
1181   bool isSet(const T &V) {
1182     return (Bits & Bit(V)) != 0;
1183   }
1184 };
1185
1186
1187 //===----------------------------------------------------------------------===//
1188 // bits - A bit vector of command options.
1189 //
1190 template <class DataType, class Storage = bool,
1191           class ParserClass = parser<DataType> >
1192 class bits : public Option, public bits_storage<DataType, Storage> {
1193   std::vector<unsigned> Positions;
1194   ParserClass Parser;
1195
1196   virtual enum ValueExpected getValueExpectedFlagDefault() const {
1197     return Parser.getValueExpectedFlagDefault();
1198   }
1199   virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
1200     return Parser.getExtraOptionNames(OptionNames);
1201   }
1202
1203   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
1204                                 StringRef Arg) {
1205     typename ParserClass::parser_data_type Val =
1206       typename ParserClass::parser_data_type();
1207     if (Parser.parse(*this, ArgName, Arg, Val))
1208       return true;  // Parse Error!
1209     addValue(Val);
1210     setPosition(pos);
1211     Positions.push_back(pos);
1212     return false;
1213   }
1214
1215   // Forward printing stuff to the parser...
1216   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1217   virtual void printOptionInfo(size_t GlobalWidth) const {
1218     Parser.printOptionInfo(*this, GlobalWidth);
1219   }
1220
1221   void done() {
1222     addArgument();
1223     Parser.initialize(*this);
1224   }
1225 public:
1226   ParserClass &getParser() { return Parser; }
1227
1228   unsigned getPosition(unsigned optnum) const {
1229     assert(optnum < this->size() && "Invalid option index");
1230     return Positions[optnum];
1231   }
1232
1233   // One option...
1234   template<class M0t>
1235   explicit bits(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1236     apply(M0, this);
1237     done();
1238   }
1239   // Two options...
1240   template<class M0t, class M1t>
1241   bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1242     apply(M0, this); apply(M1, this);
1243     done();
1244   }
1245   // Three options...
1246   template<class M0t, class M1t, class M2t>
1247   bits(const M0t &M0, const M1t &M1, const M2t &M2)
1248     : Option(ZeroOrMore | NotHidden) {
1249     apply(M0, this); apply(M1, this); apply(M2, this);
1250     done();
1251   }
1252   // Four options...
1253   template<class M0t, class M1t, class M2t, class M3t>
1254   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1255     : Option(ZeroOrMore | NotHidden) {
1256     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1257     done();
1258   }
1259   // Five options...
1260   template<class M0t, class M1t, class M2t, class M3t, class M4t>
1261   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1262        const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1263     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1264     apply(M4, this);
1265     done();
1266   }
1267   // Six options...
1268   template<class M0t, class M1t, class M2t, class M3t,
1269            class M4t, class M5t>
1270   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1271        const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1272     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1273     apply(M4, this); apply(M5, this);
1274     done();
1275   }
1276   // Seven options...
1277   template<class M0t, class M1t, class M2t, class M3t,
1278            class M4t, class M5t, class M6t>
1279   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1280        const M4t &M4, const M5t &M5, const M6t &M6)
1281     : Option(ZeroOrMore | NotHidden) {
1282     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1283     apply(M4, this); apply(M5, this); apply(M6, this);
1284     done();
1285   }
1286   // Eight options...
1287   template<class M0t, class M1t, class M2t, class M3t,
1288            class M4t, class M5t, class M6t, class M7t>
1289   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1290        const M4t &M4, const M5t &M5, const M6t &M6,
1291        const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1292     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1293     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1294     done();
1295   }
1296 };
1297
1298 //===----------------------------------------------------------------------===//
1299 // Aliased command line option (alias this name to a preexisting name)
1300 //
1301
1302 class alias : public Option {
1303   Option *AliasFor;
1304   virtual bool handleOccurrence(unsigned pos, const char * /*ArgName*/,
1305                                 StringRef Arg) {
1306     return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1307   }
1308   // Handle printing stuff...
1309   virtual size_t getOptionWidth() const;
1310   virtual void printOptionInfo(size_t GlobalWidth) const;
1311
1312   void done() {
1313     if (!hasArgStr())
1314       error("cl::alias must have argument name specified!");
1315     if (AliasFor == 0)
1316       error("cl::alias must have an cl::aliasopt(option) specified!");
1317       addArgument();
1318   }
1319 public:
1320   void setAliasFor(Option &O) {
1321     if (AliasFor)
1322       error("cl::alias must only have one cl::aliasopt(...) specified!");
1323     AliasFor = &O;
1324   }
1325
1326   // One option...
1327   template<class M0t>
1328   explicit alias(const M0t &M0) : Option(Optional | Hidden), AliasFor(0) {
1329     apply(M0, this);
1330     done();
1331   }
1332   // Two options...
1333   template<class M0t, class M1t>
1334   alias(const M0t &M0, const M1t &M1) : Option(Optional | Hidden), AliasFor(0) {
1335     apply(M0, this); apply(M1, this);
1336     done();
1337   }
1338   // Three options...
1339   template<class M0t, class M1t, class M2t>
1340   alias(const M0t &M0, const M1t &M1, const M2t &M2)
1341     : Option(Optional | Hidden), AliasFor(0) {
1342     apply(M0, this); apply(M1, this); apply(M2, this);
1343     done();
1344   }
1345   // Four options...
1346   template<class M0t, class M1t, class M2t, class M3t>
1347   alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1348     : Option(Optional | Hidden), AliasFor(0) {
1349     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1350     done();
1351   }
1352 };
1353
1354 // aliasfor - Modifier to set the option an alias aliases.
1355 struct aliasopt {
1356   Option &Opt;
1357   explicit aliasopt(Option &O) : Opt(O) {}
1358   void apply(alias &A) const { A.setAliasFor(Opt); }
1359 };
1360
1361 // extrahelp - provide additional help at the end of the normal help
1362 // output. All occurrences of cl::extrahelp will be accumulated and
1363 // printed to stderr at the end of the regular help, just before
1364 // exit is called.
1365 struct extrahelp {
1366   const char * morehelp;
1367   explicit extrahelp(const char* help);
1368 };
1369
1370 void PrintVersionMessage();
1371 // This function just prints the help message, exactly the same way as if the
1372 // --help option had been given on the command line.
1373 // NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
1374 void PrintHelpMessage();
1375
1376 } // End namespace cl
1377
1378 } // End namespace llvm
1379
1380 #endif