Declare classes with matched tags, pointed out by a clang++ warning.
[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 NumOccurrencesFlag {      // 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, StringRef 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 NumOccurrencesFlag getNumOccurrencesFlag() const {
166     return static_cast<enum NumOccurrencesFlag>(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 NumOccurrencesFlag 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(SmallVectorImpl<const char*> &) {}
234
235   // addOccurrence - Wrapper around handleOccurrence that enforces Flags.
236   //
237   bool addOccurrence(unsigned pos, StringRef ArgName,
238                      StringRef Value, bool MultiArg = false);
239
240   // Prints option name followed by message.  Always returns true.
241   bool error(const Twine &Message, StringRef ArgName = StringRef());
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(SmallVectorImpl<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, StringRef 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 class basic_parser_impl {  // non-template implementation of basic_parser<t>
499 public:
500   virtual ~basic_parser_impl() {}
501
502   enum ValueExpected getValueExpectedFlagDefault() const {
503     return ValueRequired;
504   }
505
506   void getExtraOptionNames(SmallVectorImpl<const char*> &) {}
507
508   void initialize(Option &) {}
509
510   // Return the width of the option tag for printing...
511   size_t getOptionWidth(const Option &O) const;
512
513   // printOptionInfo - Print out information about this option.  The
514   // to-be-maintained width is specified.
515   //
516   void printOptionInfo(const Option &O, size_t GlobalWidth) const;
517
518   // getValueName - Overload in subclass to provide a better default value.
519   virtual const char *getValueName() const { return "value"; }
520
521   // An out-of-line virtual method to provide a 'home' for this class.
522   virtual void anchor();
523 };
524
525 // basic_parser - The real basic parser is just a template wrapper that provides
526 // a typedef for the provided data type.
527 //
528 template<class DataType>
529 class basic_parser : public basic_parser_impl {
530 public:
531   typedef DataType parser_data_type;
532 };
533
534 //--------------------------------------------------
535 // parser<bool>
536 //
537 template<>
538 class parser<bool> : public basic_parser<bool> {
539   const char *ArgStr;
540 public:
541
542   // parse - Return true on error.
543   bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val);
544
545   template <class Opt>
546   void initialize(Opt &O) {
547     ArgStr = O.ArgStr;
548   }
549
550   enum ValueExpected getValueExpectedFlagDefault() const {
551     return ValueOptional;
552   }
553
554   // getValueName - Do not print =<value> at all.
555   virtual const char *getValueName() const { return 0; }
556
557   // An out-of-line virtual method to provide a 'home' for this class.
558   virtual void anchor();
559 };
560
561 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<bool>);
562
563 //--------------------------------------------------
564 // parser<boolOrDefault>
565 enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
566 template<>
567 class parser<boolOrDefault> : public basic_parser<boolOrDefault> {
568 public:
569   // parse - Return true on error.
570   bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val);
571
572   enum ValueExpected getValueExpectedFlagDefault() const {
573     return ValueOptional;
574   }
575
576   // getValueName - Do not print =<value> at all.
577   virtual const char *getValueName() const { return 0; }
578
579   // An out-of-line virtual method to provide a 'home' for this class.
580   virtual void anchor();
581 };
582
583 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
584
585 //--------------------------------------------------
586 // parser<int>
587 //
588 template<>
589 class parser<int> : public basic_parser<int> {
590 public:
591   // parse - Return true on error.
592   bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val);
593
594   // getValueName - Overload in subclass to provide a better default value.
595   virtual const char *getValueName() const { return "int"; }
596
597   // An out-of-line virtual method to provide a 'home' for this class.
598   virtual void anchor();
599 };
600
601 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>);
602
603
604 //--------------------------------------------------
605 // parser<unsigned>
606 //
607 template<>
608 class parser<unsigned> : public basic_parser<unsigned> {
609 public:
610   // parse - Return true on error.
611   bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val);
612
613   // getValueName - Overload in subclass to provide a better default value.
614   virtual const char *getValueName() const { return "uint"; }
615
616   // An out-of-line virtual method to provide a 'home' for this class.
617   virtual void anchor();
618 };
619
620 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
621
622 //--------------------------------------------------
623 // parser<double>
624 //
625 template<>
626 class parser<double> : public basic_parser<double> {
627 public:
628   // parse - Return true on error.
629   bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val);
630
631   // getValueName - Overload in subclass to provide a better default value.
632   virtual const char *getValueName() const { return "number"; }
633
634   // An out-of-line virtual method to provide a 'home' for this class.
635   virtual void anchor();
636 };
637
638 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<double>);
639
640 //--------------------------------------------------
641 // parser<float>
642 //
643 template<>
644 class parser<float> : public basic_parser<float> {
645 public:
646   // parse - Return true on error.
647   bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val);
648
649   // getValueName - Overload in subclass to provide a better default value.
650   virtual const char *getValueName() const { return "number"; }
651
652   // An out-of-line virtual method to provide a 'home' for this class.
653   virtual void anchor();
654 };
655
656 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<float>);
657
658 //--------------------------------------------------
659 // parser<std::string>
660 //
661 template<>
662 class parser<std::string> : public basic_parser<std::string> {
663 public:
664   // parse - Return true on error.
665   bool parse(Option &, StringRef, StringRef Arg, std::string &Value) {
666     Value = Arg.str();
667     return false;
668   }
669
670   // getValueName - Overload in subclass to provide a better default value.
671   virtual const char *getValueName() const { return "string"; }
672
673   // An out-of-line virtual method to provide a 'home' for this class.
674   virtual void anchor();
675 };
676
677 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
678
679 //--------------------------------------------------
680 // parser<char>
681 //
682 template<>
683 class parser<char> : public basic_parser<char> {
684 public:
685   // parse - Return true on error.
686   bool parse(Option &, StringRef, StringRef Arg, char &Value) {
687     Value = Arg[0];
688     return false;
689   }
690
691   // getValueName - Overload in subclass to provide a better default value.
692   virtual const char *getValueName() const { return "char"; }
693
694   // An out-of-line virtual method to provide a 'home' for this class.
695   virtual void anchor();
696 };
697
698 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<char>);
699
700 //===----------------------------------------------------------------------===//
701 // applicator class - This class is used because we must use partial
702 // specialization to handle literal string arguments specially (const char* does
703 // not correctly respond to the apply method).  Because the syntax to use this
704 // is a pain, we have the 'apply' method below to handle the nastiness...
705 //
706 template<class Mod> struct applicator {
707   template<class Opt>
708   static void opt(const Mod &M, Opt &O) { M.apply(O); }
709 };
710
711 // Handle const char* as a special case...
712 template<unsigned n> struct applicator<char[n]> {
713   template<class Opt>
714   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
715 };
716 template<unsigned n> struct applicator<const char[n]> {
717   template<class Opt>
718   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
719 };
720 template<> struct applicator<const char*> {
721   template<class Opt>
722   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
723 };
724
725 template<> struct applicator<NumOccurrencesFlag> {
726   static void opt(NumOccurrencesFlag NO, Option &O) {
727     O.setNumOccurrencesFlag(NO);
728   }
729 };
730 template<> struct applicator<ValueExpected> {
731   static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
732 };
733 template<> struct applicator<OptionHidden> {
734   static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
735 };
736 template<> struct applicator<FormattingFlags> {
737   static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
738 };
739 template<> struct applicator<MiscFlags> {
740   static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
741 };
742
743 // apply method - Apply a modifier to an option in a type safe way.
744 template<class Mod, class Opt>
745 void apply(const Mod &M, Opt *O) {
746   applicator<Mod>::opt(M, *O);
747 }
748
749
750 //===----------------------------------------------------------------------===//
751 // opt_storage class
752
753 // Default storage class definition: external storage.  This implementation
754 // assumes the user will specify a variable to store the data into with the
755 // cl::location(x) modifier.
756 //
757 template<class DataType, bool ExternalStorage, bool isClass>
758 class opt_storage {
759   DataType *Location;   // Where to store the object...
760
761   void check() const {
762     assert(Location != 0 && "cl::location(...) not specified for a command "
763            "line option with external storage, "
764            "or cl::init specified before cl::location()!!");
765   }
766 public:
767   opt_storage() : Location(0) {}
768
769   bool setLocation(Option &O, DataType &L) {
770     if (Location)
771       return O.error("cl::location(x) specified more than once!");
772     Location = &L;
773     return false;
774   }
775
776   template<class T>
777   void setValue(const T &V) {
778     check();
779     *Location = V;
780   }
781
782   DataType &getValue() { check(); return *Location; }
783   const DataType &getValue() const { check(); return *Location; }
784 };
785
786
787 // Define how to hold a class type object, such as a string.  Since we can
788 // inherit from a class, we do so.  This makes us exactly compatible with the
789 // object in all cases that it is used.
790 //
791 template<class DataType>
792 class opt_storage<DataType,false,true> : public DataType {
793 public:
794   template<class T>
795   void setValue(const T &V) { DataType::operator=(V); }
796
797   DataType &getValue() { return *this; }
798   const DataType &getValue() const { return *this; }
799 };
800
801 // Define a partial specialization to handle things we cannot inherit from.  In
802 // this case, we store an instance through containment, and overload operators
803 // to get at the value.
804 //
805 template<class DataType>
806 class opt_storage<DataType, false, false> {
807 public:
808   DataType Value;
809
810   // Make sure we initialize the value with the default constructor for the
811   // type.
812   opt_storage() : Value(DataType()) {}
813
814   template<class T>
815   void setValue(const T &V) { Value = V; }
816   DataType &getValue() { return Value; }
817   DataType getValue() const { return Value; }
818
819   // If the datatype is a pointer, support -> on it.
820   DataType operator->() const { return Value; }
821 };
822
823
824 //===----------------------------------------------------------------------===//
825 // opt - A scalar command line option.
826 //
827 template <class DataType, bool ExternalStorage = false,
828           class ParserClass = parser<DataType> >
829 class opt : public Option,
830             public opt_storage<DataType, ExternalStorage,
831                                is_class<DataType>::value> {
832   ParserClass Parser;
833
834   virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
835                                 StringRef Arg) {
836     typename ParserClass::parser_data_type Val =
837        typename ParserClass::parser_data_type();
838     if (Parser.parse(*this, ArgName, Arg, Val))
839       return true;                            // Parse error!
840     this->setValue(Val);
841     this->setPosition(pos);
842     return false;
843   }
844
845   virtual enum ValueExpected getValueExpectedFlagDefault() const {
846     return Parser.getValueExpectedFlagDefault();
847   }
848   virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
849     return Parser.getExtraOptionNames(OptionNames);
850   }
851
852   // Forward printing stuff to the parser...
853   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
854   virtual void printOptionInfo(size_t GlobalWidth) const {
855     Parser.printOptionInfo(*this, GlobalWidth);
856   }
857
858   void done() {
859     addArgument();
860     Parser.initialize(*this);
861   }
862 public:
863   // setInitialValue - Used by the cl::init modifier...
864   void setInitialValue(const DataType &V) { this->setValue(V); }
865
866   ParserClass &getParser() { return Parser; }
867
868   operator DataType() const { return this->getValue(); }
869
870   template<class T>
871   DataType &operator=(const T &Val) {
872     this->setValue(Val);
873     return this->getValue();
874   }
875
876   // One option...
877   template<class M0t>
878   explicit opt(const M0t &M0) : Option(Optional | NotHidden) {
879     apply(M0, this);
880     done();
881   }
882
883   // Two options...
884   template<class M0t, class M1t>
885   opt(const M0t &M0, const M1t &M1) : Option(Optional | NotHidden) {
886     apply(M0, this); apply(M1, this);
887     done();
888   }
889
890   // Three options...
891   template<class M0t, class M1t, class M2t>
892   opt(const M0t &M0, const M1t &M1,
893       const M2t &M2) : Option(Optional | NotHidden) {
894     apply(M0, this); apply(M1, this); apply(M2, this);
895     done();
896   }
897   // Four options...
898   template<class M0t, class M1t, class M2t, class M3t>
899   opt(const M0t &M0, const M1t &M1, const M2t &M2,
900       const M3t &M3) : Option(Optional | NotHidden) {
901     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
902     done();
903   }
904   // Five options...
905   template<class M0t, class M1t, class M2t, class M3t, class M4t>
906   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
907       const M4t &M4) : Option(Optional | NotHidden) {
908     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
909     apply(M4, this);
910     done();
911   }
912   // Six options...
913   template<class M0t, class M1t, class M2t, class M3t,
914            class M4t, class M5t>
915   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
916       const M4t &M4, const M5t &M5) : Option(Optional | NotHidden) {
917     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
918     apply(M4, this); apply(M5, this);
919     done();
920   }
921   // Seven options...
922   template<class M0t, class M1t, class M2t, class M3t,
923            class M4t, class M5t, class M6t>
924   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
925       const M4t &M4, const M5t &M5,
926       const M6t &M6) : Option(Optional | NotHidden) {
927     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
928     apply(M4, this); apply(M5, this); apply(M6, this);
929     done();
930   }
931   // Eight options...
932   template<class M0t, class M1t, class M2t, class M3t,
933            class M4t, class M5t, class M6t, class M7t>
934   opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
935       const M4t &M4, const M5t &M5, const M6t &M6,
936       const M7t &M7) : Option(Optional | NotHidden) {
937     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
938     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
939     done();
940   }
941 };
942
943 EXTERN_TEMPLATE_INSTANTIATION(class opt<unsigned>);
944 EXTERN_TEMPLATE_INSTANTIATION(class opt<int>);
945 EXTERN_TEMPLATE_INSTANTIATION(class opt<std::string>);
946 EXTERN_TEMPLATE_INSTANTIATION(class opt<char>);
947 EXTERN_TEMPLATE_INSTANTIATION(class opt<bool>);
948
949 //===----------------------------------------------------------------------===//
950 // list_storage class
951
952 // Default storage class definition: external storage.  This implementation
953 // assumes the user will specify a variable to store the data into with the
954 // cl::location(x) modifier.
955 //
956 template<class DataType, class StorageClass>
957 class list_storage {
958   StorageClass *Location;   // Where to store the object...
959
960 public:
961   list_storage() : Location(0) {}
962
963   bool setLocation(Option &O, StorageClass &L) {
964     if (Location)
965       return O.error("cl::location(x) specified more than once!");
966     Location = &L;
967     return false;
968   }
969
970   template<class T>
971   void addValue(const T &V) {
972     assert(Location != 0 && "cl::location(...) not specified for a command "
973            "line option with external storage!");
974     Location->push_back(V);
975   }
976 };
977
978
979 // Define how to hold a class type object, such as a string.  Since we can
980 // inherit from a class, we do so.  This makes us exactly compatible with the
981 // object in all cases that it is used.
982 //
983 template<class DataType>
984 class list_storage<DataType, bool> : public std::vector<DataType> {
985 public:
986   template<class T>
987   void addValue(const T &V) { push_back(V); }
988 };
989
990
991 //===----------------------------------------------------------------------===//
992 // list - A list of command line options.
993 //
994 template <class DataType, class Storage = bool,
995           class ParserClass = parser<DataType> >
996 class list : public Option, public list_storage<DataType, Storage> {
997   std::vector<unsigned> Positions;
998   ParserClass Parser;
999
1000   virtual enum ValueExpected getValueExpectedFlagDefault() const {
1001     return Parser.getValueExpectedFlagDefault();
1002   }
1003   virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
1004     return Parser.getExtraOptionNames(OptionNames);
1005   }
1006
1007   virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
1008     typename ParserClass::parser_data_type Val =
1009       typename ParserClass::parser_data_type();
1010     if (Parser.parse(*this, ArgName, Arg, Val))
1011       return true;  // Parse Error!
1012     addValue(Val);
1013     setPosition(pos);
1014     Positions.push_back(pos);
1015     return false;
1016   }
1017
1018   // Forward printing stuff to the parser...
1019   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1020   virtual void printOptionInfo(size_t GlobalWidth) const {
1021     Parser.printOptionInfo(*this, GlobalWidth);
1022   }
1023
1024   void done() {
1025     addArgument();
1026     Parser.initialize(*this);
1027   }
1028 public:
1029   ParserClass &getParser() { return Parser; }
1030
1031   unsigned getPosition(unsigned optnum) const {
1032     assert(optnum < this->size() && "Invalid option index");
1033     return Positions[optnum];
1034   }
1035
1036   void setNumAdditionalVals(unsigned n) {
1037     Option::setNumAdditionalVals(n);
1038   }
1039
1040   // One option...
1041   template<class M0t>
1042   explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1043     apply(M0, this);
1044     done();
1045   }
1046   // Two options...
1047   template<class M0t, class M1t>
1048   list(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1049     apply(M0, this); apply(M1, this);
1050     done();
1051   }
1052   // Three options...
1053   template<class M0t, class M1t, class M2t>
1054   list(const M0t &M0, const M1t &M1, const M2t &M2)
1055     : Option(ZeroOrMore | NotHidden) {
1056     apply(M0, this); apply(M1, this); apply(M2, this);
1057     done();
1058   }
1059   // Four options...
1060   template<class M0t, class M1t, class M2t, class M3t>
1061   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1062     : Option(ZeroOrMore | NotHidden) {
1063     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1064     done();
1065   }
1066   // Five options...
1067   template<class M0t, class M1t, class M2t, class M3t, class M4t>
1068   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1069        const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1070     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1071     apply(M4, this);
1072     done();
1073   }
1074   // Six options...
1075   template<class M0t, class M1t, class M2t, class M3t,
1076            class M4t, class M5t>
1077   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1078        const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1079     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1080     apply(M4, this); apply(M5, this);
1081     done();
1082   }
1083   // Seven options...
1084   template<class M0t, class M1t, class M2t, class M3t,
1085            class M4t, class M5t, class M6t>
1086   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1087        const M4t &M4, const M5t &M5, const M6t &M6)
1088     : Option(ZeroOrMore | NotHidden) {
1089     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1090     apply(M4, this); apply(M5, this); apply(M6, this);
1091     done();
1092   }
1093   // Eight options...
1094   template<class M0t, class M1t, class M2t, class M3t,
1095            class M4t, class M5t, class M6t, class M7t>
1096   list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1097        const M4t &M4, const M5t &M5, const M6t &M6,
1098        const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1099     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1100     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1101     done();
1102   }
1103 };
1104
1105 // multi_val - Modifier to set the number of additional values.
1106 struct multi_val {
1107   unsigned AdditionalVals;
1108   explicit multi_val(unsigned N) : AdditionalVals(N) {}
1109
1110   template <typename D, typename S, typename P>
1111   void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); }
1112 };
1113
1114
1115 //===----------------------------------------------------------------------===//
1116 // bits_storage class
1117
1118 // Default storage class definition: external storage.  This implementation
1119 // assumes the user will specify a variable to store the data into with the
1120 // cl::location(x) modifier.
1121 //
1122 template<class DataType, class StorageClass>
1123 class bits_storage {
1124   unsigned *Location;   // Where to store the bits...
1125
1126   template<class T>
1127   static unsigned Bit(const T &V) {
1128     unsigned BitPos = reinterpret_cast<unsigned>(V);
1129     assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1130           "enum exceeds width of bit vector!");
1131     return 1 << BitPos;
1132   }
1133
1134 public:
1135   bits_storage() : Location(0) {}
1136
1137   bool setLocation(Option &O, unsigned &L) {
1138     if (Location)
1139       return O.error("cl::location(x) specified more than once!");
1140     Location = &L;
1141     return false;
1142   }
1143
1144   template<class T>
1145   void addValue(const T &V) {
1146     assert(Location != 0 && "cl::location(...) not specified for a command "
1147            "line option with external storage!");
1148     *Location |= Bit(V);
1149   }
1150
1151   unsigned getBits() { return *Location; }
1152
1153   template<class T>
1154   bool isSet(const T &V) {
1155     return (*Location & Bit(V)) != 0;
1156   }
1157 };
1158
1159
1160 // Define how to hold bits.  Since we can inherit from a class, we do so.
1161 // This makes us exactly compatible with the bits in all cases that it is used.
1162 //
1163 template<class DataType>
1164 class bits_storage<DataType, bool> {
1165   unsigned Bits;   // Where to store the bits...
1166
1167   template<class T>
1168   static unsigned Bit(const T &V) {
1169     unsigned BitPos = reinterpret_cast<unsigned>(V);
1170     assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1171           "enum exceeds width of bit vector!");
1172     return 1 << BitPos;
1173   }
1174
1175 public:
1176   template<class T>
1177   void addValue(const T &V) {
1178     Bits |=  Bit(V);
1179   }
1180
1181   unsigned getBits() { return Bits; }
1182
1183   template<class T>
1184   bool isSet(const T &V) {
1185     return (Bits & Bit(V)) != 0;
1186   }
1187 };
1188
1189
1190 //===----------------------------------------------------------------------===//
1191 // bits - A bit vector of command options.
1192 //
1193 template <class DataType, class Storage = bool,
1194           class ParserClass = parser<DataType> >
1195 class bits : public Option, public bits_storage<DataType, Storage> {
1196   std::vector<unsigned> Positions;
1197   ParserClass Parser;
1198
1199   virtual enum ValueExpected getValueExpectedFlagDefault() const {
1200     return Parser.getValueExpectedFlagDefault();
1201   }
1202   virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
1203     return Parser.getExtraOptionNames(OptionNames);
1204   }
1205
1206   virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
1207     typename ParserClass::parser_data_type Val =
1208       typename ParserClass::parser_data_type();
1209     if (Parser.parse(*this, ArgName, Arg, Val))
1210       return true;  // Parse Error!
1211     addValue(Val);
1212     setPosition(pos);
1213     Positions.push_back(pos);
1214     return false;
1215   }
1216
1217   // Forward printing stuff to the parser...
1218   virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
1219   virtual void printOptionInfo(size_t GlobalWidth) const {
1220     Parser.printOptionInfo(*this, GlobalWidth);
1221   }
1222
1223   void done() {
1224     addArgument();
1225     Parser.initialize(*this);
1226   }
1227 public:
1228   ParserClass &getParser() { return Parser; }
1229
1230   unsigned getPosition(unsigned optnum) const {
1231     assert(optnum < this->size() && "Invalid option index");
1232     return Positions[optnum];
1233   }
1234
1235   // One option...
1236   template<class M0t>
1237   explicit bits(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
1238     apply(M0, this);
1239     done();
1240   }
1241   // Two options...
1242   template<class M0t, class M1t>
1243   bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
1244     apply(M0, this); apply(M1, this);
1245     done();
1246   }
1247   // Three options...
1248   template<class M0t, class M1t, class M2t>
1249   bits(const M0t &M0, const M1t &M1, const M2t &M2)
1250     : Option(ZeroOrMore | NotHidden) {
1251     apply(M0, this); apply(M1, this); apply(M2, this);
1252     done();
1253   }
1254   // Four options...
1255   template<class M0t, class M1t, class M2t, class M3t>
1256   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1257     : Option(ZeroOrMore | NotHidden) {
1258     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1259     done();
1260   }
1261   // Five options...
1262   template<class M0t, class M1t, class M2t, class M3t, class M4t>
1263   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1264        const M4t &M4) : Option(ZeroOrMore | NotHidden) {
1265     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1266     apply(M4, this);
1267     done();
1268   }
1269   // Six options...
1270   template<class M0t, class M1t, class M2t, class M3t,
1271            class M4t, class M5t>
1272   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1273        const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
1274     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1275     apply(M4, this); apply(M5, this);
1276     done();
1277   }
1278   // Seven options...
1279   template<class M0t, class M1t, class M2t, class M3t,
1280            class M4t, class M5t, class M6t>
1281   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1282        const M4t &M4, const M5t &M5, const M6t &M6)
1283     : Option(ZeroOrMore | NotHidden) {
1284     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1285     apply(M4, this); apply(M5, this); apply(M6, this);
1286     done();
1287   }
1288   // Eight options...
1289   template<class M0t, class M1t, class M2t, class M3t,
1290            class M4t, class M5t, class M6t, class M7t>
1291   bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
1292        const M4t &M4, const M5t &M5, const M6t &M6,
1293        const M7t &M7) : Option(ZeroOrMore | NotHidden) {
1294     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1295     apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
1296     done();
1297   }
1298 };
1299
1300 //===----------------------------------------------------------------------===//
1301 // Aliased command line option (alias this name to a preexisting name)
1302 //
1303
1304 class alias : public Option {
1305   Option *AliasFor;
1306   virtual bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
1307                                 StringRef Arg) {
1308     return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1309   }
1310   // Handle printing stuff...
1311   virtual size_t getOptionWidth() const;
1312   virtual void printOptionInfo(size_t GlobalWidth) const;
1313
1314   void done() {
1315     if (!hasArgStr())
1316       error("cl::alias must have argument name specified!");
1317     if (AliasFor == 0)
1318       error("cl::alias must have an cl::aliasopt(option) specified!");
1319       addArgument();
1320   }
1321 public:
1322   void setAliasFor(Option &O) {
1323     if (AliasFor)
1324       error("cl::alias must only have one cl::aliasopt(...) specified!");
1325     AliasFor = &O;
1326   }
1327
1328   // One option...
1329   template<class M0t>
1330   explicit alias(const M0t &M0) : Option(Optional | Hidden), AliasFor(0) {
1331     apply(M0, this);
1332     done();
1333   }
1334   // Two options...
1335   template<class M0t, class M1t>
1336   alias(const M0t &M0, const M1t &M1) : Option(Optional | Hidden), AliasFor(0) {
1337     apply(M0, this); apply(M1, this);
1338     done();
1339   }
1340   // Three options...
1341   template<class M0t, class M1t, class M2t>
1342   alias(const M0t &M0, const M1t &M1, const M2t &M2)
1343     : Option(Optional | Hidden), AliasFor(0) {
1344     apply(M0, this); apply(M1, this); apply(M2, this);
1345     done();
1346   }
1347   // Four options...
1348   template<class M0t, class M1t, class M2t, class M3t>
1349   alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1350     : Option(Optional | Hidden), AliasFor(0) {
1351     apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1352     done();
1353   }
1354 };
1355
1356 // aliasfor - Modifier to set the option an alias aliases.
1357 struct aliasopt {
1358   Option &Opt;
1359   explicit aliasopt(Option &O) : Opt(O) {}
1360   void apply(alias &A) const { A.setAliasFor(Opt); }
1361 };
1362
1363 // extrahelp - provide additional help at the end of the normal help
1364 // output. All occurrences of cl::extrahelp will be accumulated and
1365 // printed to stderr at the end of the regular help, just before
1366 // exit is called.
1367 struct extrahelp {
1368   const char * morehelp;
1369   explicit extrahelp(const char* help);
1370 };
1371
1372 void PrintVersionMessage();
1373 // This function just prints the help message, exactly the same way as if the
1374 // --help option had been given on the command line.
1375 // NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
1376 void PrintHelpMessage();
1377
1378 } // End namespace cl
1379
1380 } // End namespace llvm
1381
1382 #endif