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