blob: 01f55a81d455716cc8e8d82c652427834a90c1a6 [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===- Support/CommandLine.h - Flexible Command line parser -----*- C++ -*-===//
John Criswellb2109ce2003-10-20 19:46:57 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattnercee8f9a2001-11-27 00:03:19 +00009//
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//
Chris Lattner331de232002-07-22 02:07:59 +000014// 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
Chris Lattnercee8f9a2001-11-27 00:03:19 +000017//
18//===----------------------------------------------------------------------===//
19
Brian Gaekea9f6e4a2003-06-17 00:35:55 +000020#ifndef SUPPORT_COMMANDLINE_H
21#define SUPPORT_COMMANDLINE_H
Chris Lattnercee8f9a2001-11-27 00:03:19 +000022
23#include <string>
24#include <vector>
25#include <utility>
Chris Lattnerb3b729b2003-05-22 20:25:57 +000026#include <cstdarg>
Chris Lattnera44a4cd2003-07-25 17:23:27 +000027#include <cassert>
Chris Lattner331de232002-07-22 02:07:59 +000028#include "boost/type_traits/object_traits.hpp"
John Criswellbe583b92003-06-11 14:01:36 +000029
Chris Lattnerbf0ac3f2003-06-03 15:30:37 +000030/// cl Namespace - This namespace contains all of the command line option
31/// processing machinery. It is intentionally a short name to make qualified
32/// usage concise.
33namespace cl {
Chris Lattnercee8f9a2001-11-27 00:03:19 +000034
35//===----------------------------------------------------------------------===//
Chris Lattner331de232002-07-22 02:07:59 +000036// ParseCommandLineOptions - Command line option processing entry point.
Chris Lattnercee8f9a2001-11-27 00:03:19 +000037//
Chris Lattner20968a22003-08-14 22:04:41 +000038void ParseCommandLineOptions(int &argc, char **argv,
39 const char *Overview = 0);
Chris Lattnercee8f9a2001-11-27 00:03:19 +000040
41//===----------------------------------------------------------------------===//
Brian Gaeke06b06c52003-08-14 22:00:59 +000042// ParseEnvironmentOptions - Environment variable option processing alternate
43// entry point.
44//
Brian Gaekec48ef2a2003-08-15 21:05:57 +000045void ParseEnvironmentOptions(const char *progName, const char *envvar,
Chris Lattner20968a22003-08-14 22:04:41 +000046 const char *Overview = 0);
Brian Gaeke06b06c52003-08-14 22:00:59 +000047
48//===----------------------------------------------------------------------===//
Chris Lattner331de232002-07-22 02:07:59 +000049// Flags permitted to be passed to command line arguments
50//
Chris Lattnercee8f9a2001-11-27 00:03:19 +000051
Misha Brukmanb5c520b2003-07-10 17:05:26 +000052enum NumOccurrences { // Flags for the number of occurrences allowed
53 Optional = 0x01, // Zero or One occurrence
54 ZeroOrMore = 0x02, // Zero or more occurrences allowed
55 Required = 0x03, // One occurrence required
56 OneOrMore = 0x04, // One or more occurrences required
Chris Lattnercee8f9a2001-11-27 00:03:19 +000057
Chris Lattner331de232002-07-22 02:07:59 +000058 // ConsumeAfter - Indicates that this option is fed anything that follows the
59 // last positional argument required by the application (it is an error if
60 // there are zero positional arguments, and a ConsumeAfter option is used).
61 // Thus, for example, all arguments to LLI are processed until a filename is
62 // found. Once a filename is found, all of the succeeding arguments are
63 // passed, unprocessed, to the ConsumeAfter option.
Chris Lattnercee8f9a2001-11-27 00:03:19 +000064 //
65 ConsumeAfter = 0x05,
66
Misha Brukmandd6cb6a2003-07-10 16:49:51 +000067 OccurrencesMask = 0x07,
Chris Lattnercee8f9a2001-11-27 00:03:19 +000068};
69
70enum ValueExpected { // Is a value required for the option?
Chris Lattnerb3b729b2003-05-22 20:25:57 +000071 ValueOptional = 0x08, // The value can appear... or not
Chris Lattnercee8f9a2001-11-27 00:03:19 +000072 ValueRequired = 0x10, // The value is required to appear!
73 ValueDisallowed = 0x18, // A value may not be specified (for flags)
74 ValueMask = 0x18,
75};
76
77enum OptionHidden { // Control whether -help shows this option
78 NotHidden = 0x20, // Option included in --help & --help-hidden
79 Hidden = 0x40, // -help doesn't, but --help-hidden does
80 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
81 HiddenMask = 0x60,
82};
83
Chris Lattner331de232002-07-22 02:07:59 +000084// Formatting flags - This controls special features that the option might have
85// that cause it to be parsed differently...
86//
87// Prefix - This option allows arguments that are otherwise unrecognized to be
88// matched by options that are a prefix of the actual value. This is useful for
89// cases like a linker, where options are typically of the form '-lfoo' or
90// '-L../../include' where -l or -L are the actual flags. When prefix is
91// enabled, and used, the value for the flag comes from the suffix of the
92// argument.
93//
94// Grouping - With this option enabled, multiple letter options are allowed to
95// bunch together with only a single hyphen for the whole group. This allows
96// emulation of the behavior that ls uses for example: ls -la === ls -l -a
97//
98
99enum FormattingFlags {
100 NormalFormatting = 0x000, // Nothing special
101 Positional = 0x080, // Is a positional argument, no '-' required
102 Prefix = 0x100, // Can this option directly prefix its value?
103 Grouping = 0x180, // Can this option group with other options?
104 FormattingMask = 0x180,
105};
106
Chris Lattnerb3b729b2003-05-22 20:25:57 +0000107enum MiscFlags { // Miscellaneous flags to adjust argument
108 CommaSeparated = 0x200, // Should this cl::list split between commas?
109 MiscMask = 0x200,
110};
111
112
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000113
114//===----------------------------------------------------------------------===//
115// Option Base class
116//
Chris Lattner331de232002-07-22 02:07:59 +0000117class alias;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000118class Option {
119 friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
Chris Lattner331de232002-07-22 02:07:59 +0000120 friend class alias;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000121
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000122 // handleOccurrences - Overriden by subclasses to handle the value passed into
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000123 // an argument. Should return true if there was an error processing the
124 // argument and the program should exit.
125 //
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000126 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) = 0;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000127
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000128 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000129 return Optional;
130 }
131 virtual enum ValueExpected getValueExpectedFlagDefault() const {
132 return ValueOptional;
133 }
134 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
135 return NotHidden;
136 }
Chris Lattner331de232002-07-22 02:07:59 +0000137 virtual enum FormattingFlags getFormattingFlagDefault() const {
138 return NormalFormatting;
139 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000140
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000141 int NumOccurrences; // The number of times specified
Chris Lattner331de232002-07-22 02:07:59 +0000142 int Flags; // Flags for the argument
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000143public:
Chris Lattner331de232002-07-22 02:07:59 +0000144 const char *ArgStr; // The argument string itself (ex: "help", "o")
145 const char *HelpStr; // The descriptive text message for --help
146 const char *ValueStr; // String describing what the value of this option is
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000147
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000148 inline enum NumOccurrences getNumOccurrencesFlag() const {
149 int NO = Flags & OccurrencesMask;
150 return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000151 }
152 inline enum ValueExpected getValueExpectedFlag() const {
153 int VE = Flags & ValueMask;
154 return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
155 }
156 inline enum OptionHidden getOptionHiddenFlag() const {
157 int OH = Flags & HiddenMask;
158 return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
159 }
Chris Lattner331de232002-07-22 02:07:59 +0000160 inline enum FormattingFlags getFormattingFlag() const {
161 int OH = Flags & FormattingMask;
162 return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
163 }
Chris Lattnerb3b729b2003-05-22 20:25:57 +0000164 inline unsigned getMiscFlags() const {
165 return Flags & MiscMask;
166 }
Chris Lattner331de232002-07-22 02:07:59 +0000167
168 // hasArgStr - Return true if the argstr != ""
169 bool hasArgStr() const { return ArgStr[0] != 0; }
170
171 //-------------------------------------------------------------------------===
172 // Accessor functions set by OptionModifiers
173 //
174 void setArgStr(const char *S) { ArgStr = S; }
175 void setDescription(const char *S) { HelpStr = S; }
176 void setValueStr(const char *S) { ValueStr = S; }
177
178 void setFlag(unsigned Flag, unsigned FlagMask) {
179 if (Flags & FlagMask) {
180 error(": Specified two settings for the same option!");
181 exit(1);
182 }
183
184 Flags |= Flag;
185 }
186
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000187 void setNumOccurrencesFlag(enum NumOccurrences Val) {
188 setFlag(Val, OccurrencesMask);
Chris Lattner331de232002-07-22 02:07:59 +0000189 }
190 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
191 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
192 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
Chris Lattnerb3b729b2003-05-22 20:25:57 +0000193 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000194protected:
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000195 Option() : NumOccurrences(0), Flags(0),
Chris Lattner331de232002-07-22 02:07:59 +0000196 ArgStr(""), HelpStr(""), ValueStr("") {}
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000197
198public:
Chris Lattner331de232002-07-22 02:07:59 +0000199 // addArgument - Tell the system that this Option subclass will handle all
Misha Brukmanb5c520b2003-07-10 17:05:26 +0000200 // occurrences of -ArgStr on the command line.
Chris Lattner331de232002-07-22 02:07:59 +0000201 //
202 void addArgument(const char *ArgStr);
Chris Lattnerae1257a2002-07-23 00:44:37 +0000203 void removeArgument(const char *ArgStr);
Chris Lattner331de232002-07-22 02:07:59 +0000204
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000205 // Return the width of the option tag for printing...
Chris Lattner331de232002-07-22 02:07:59 +0000206 virtual unsigned getOptionWidth() const = 0;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000207
208 // printOptionInfo - Print out information about this option. The
209 // to-be-maintained width is specified.
210 //
Chris Lattner331de232002-07-22 02:07:59 +0000211 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000212
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000213 // addOccurrence - Wrapper around handleOccurrence that enforces Flags
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000214 //
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000215 bool addOccurrence(const char *ArgName, const std::string &Value);
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000216
217 // Prints option name followed by message. Always returns true.
Chris Lattner697954c2002-01-20 22:54:45 +0000218 bool error(std::string Message, const char *ArgName = 0);
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000219
220public:
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000221 inline int getNumOccurrences() const { return NumOccurrences; }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000222 virtual ~Option() {}
223};
224
225
226//===----------------------------------------------------------------------===//
Chris Lattner331de232002-07-22 02:07:59 +0000227// Command line option modifiers that can be used to modify the behavior of
228// command line option parsers...
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000229//
Chris Lattner331de232002-07-22 02:07:59 +0000230
231// desc - Modifier to set the description shown in the --help output...
232struct desc {
233 const char *Desc;
234 desc(const char *Str) : Desc(Str) {}
235 void apply(Option &O) const { O.setDescription(Desc); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000236};
237
Chris Lattner331de232002-07-22 02:07:59 +0000238// value_desc - Modifier to set the value description shown in the --help
239// output...
240struct value_desc {
241 const char *Desc;
242 value_desc(const char *Str) : Desc(Str) {}
243 void apply(Option &O) const { O.setValueStr(Desc); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000244};
245
246
Chris Lattner331de232002-07-22 02:07:59 +0000247// init - Specify a default (initial) value for the command line argument, if
248// the default constructor for the argument type does not give you what you
249// want. This is only valid on "opt" arguments, not on "list" arguments.
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000250//
Chris Lattner331de232002-07-22 02:07:59 +0000251template<class Ty>
252struct initializer {
253 const Ty &Init;
254 initializer(const Ty &Val) : Init(Val) {}
255
256 template<class Opt>
257 void apply(Opt &O) const { O.setInitialValue(Init); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000258};
259
Chris Lattner331de232002-07-22 02:07:59 +0000260template<class Ty>
261initializer<Ty> init(const Ty &Val) {
262 return initializer<Ty>(Val);
263}
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000264
Chris Lattner331de232002-07-22 02:07:59 +0000265
266// location - Allow the user to specify which external variable they want to
267// store the results of the command line argument processing into, if they don't
268// want to store it in the option itself.
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000269//
Chris Lattner331de232002-07-22 02:07:59 +0000270template<class Ty>
271struct LocationClass {
272 Ty &Loc;
273 LocationClass(Ty &L) : Loc(L) {}
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000274
Chris Lattner331de232002-07-22 02:07:59 +0000275 template<class Opt>
276 void apply(Opt &O) const { O.setLocation(O, Loc); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000277};
278
Chris Lattner331de232002-07-22 02:07:59 +0000279template<class Ty>
280LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000281
282
283//===----------------------------------------------------------------------===//
284// Enum valued command line option
285//
Chris Lattnerae1257a2002-07-23 00:44:37 +0000286#define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
287#define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000288
Chris Lattner331de232002-07-22 02:07:59 +0000289// values - For custom data types, allow specifying a group of values together
290// as the values that go into the mapping that the option handler uses. Note
291// that the values list must always have a 0 at the end of the list to indicate
292// that the list has ended.
293//
294template<class DataType>
295class ValuesClass {
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000296 // Use a vector instead of a map, because the lists should be short,
297 // the overhead is less, and most importantly, it keeps them in the order
298 // inserted so we can print our option out nicely.
Chris Lattner331de232002-07-22 02:07:59 +0000299 std::vector<std::pair<const char *, std::pair<int, const char *> > > Values;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000300 void processValues(va_list Vals);
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000301public:
Chris Lattner331de232002-07-22 02:07:59 +0000302 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
303 va_list ValueArgs) {
304 // Insert the first value, which is required.
305 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
306
307 // Process the varargs portion of the values...
308 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
Chris Lattnerae1257a2002-07-23 00:44:37 +0000309 DataType EnumVal = (DataType)va_arg(ValueArgs, int);
Chris Lattner331de232002-07-22 02:07:59 +0000310 const char *EnumDesc = va_arg(ValueArgs, const char *);
311 Values.push_back(std::make_pair(EnumName, // Add value to value map
312 std::make_pair(EnumVal, EnumDesc)));
313 }
314 }
315
316 template<class Opt>
317 void apply(Opt &O) const {
318 for (unsigned i = 0, e = Values.size(); i != e; ++i)
319 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
320 Values[i].second.second);
321 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000322};
323
Chris Lattner331de232002-07-22 02:07:59 +0000324template<class DataType>
325ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
326 ...) {
327 va_list ValueArgs;
328 va_start(ValueArgs, Desc);
329 ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
330 va_end(ValueArgs);
331 return Vals;
332}
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000333
Chris Lattner331de232002-07-22 02:07:59 +0000334
335//===----------------------------------------------------------------------===//
336// parser class - Parameterizable parser for different data types. By default,
337// known data types (string, int, bool) have specialized parsers, that do what
338// you would expect. The default parser, used for data types that are not
339// built-in, uses a mapping table to map specific options to values, which is
340// used, among other things, to handle enum types.
341
342//--------------------------------------------------
343// generic_parser_base - This class holds all the non-generic code that we do
344// not need replicated for every instance of the generic parser. This also
345// allows us to put stuff into CommandLine.cpp
346//
347struct generic_parser_base {
348 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
349
350 // getNumOptions - Virtual function implemented by generic subclass to
351 // indicate how many entries are in Values.
352 //
353 virtual unsigned getNumOptions() const = 0;
354
355 // getOption - Return option name N.
356 virtual const char *getOption(unsigned N) const = 0;
357
358 // getDescription - Return description N
359 virtual const char *getDescription(unsigned N) const = 0;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000360
361 // Return the width of the option tag for printing...
Chris Lattner331de232002-07-22 02:07:59 +0000362 virtual unsigned getOptionWidth(const Option &O) const;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000363
364 // printOptionInfo - Print out information about this option. The
365 // to-be-maintained width is specified.
366 //
Chris Lattner331de232002-07-22 02:07:59 +0000367 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
Chris Lattner71fb7162002-05-22 17:03:05 +0000368
Chris Lattner331de232002-07-22 02:07:59 +0000369 void initialize(Option &O) {
370 // All of the modifiers for the option have been processed by now, so the
371 // argstr field should be stable, copy it down now.
372 //
373 hasArgStr = O.hasArgStr();
374
375 // If there has been no argstr specified, that means that we need to add an
376 // argument for every possible option. This ensures that our options are
377 // vectored to us.
378 //
379 if (!hasArgStr)
380 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
381 O.addArgument(getOption(i));
382 }
383
384 enum ValueExpected getValueExpectedFlagDefault() const {
385 // If there is an ArgStr specified, then we are of the form:
386 //
387 // -opt=O2 or -opt O2 or -optO2
388 //
389 // In which case, the value is required. Otherwise if an arg str has not
390 // been specified, we are of the form:
391 //
Misha Brukmanbc0e9982003-07-14 17:20:40 +0000392 // -O2 or O2 or -la (where -l and -a are separate options)
Chris Lattner331de232002-07-22 02:07:59 +0000393 //
394 // If this is the case, we cannot allow a value.
395 //
396 if (hasArgStr)
397 return ValueRequired;
398 else
399 return ValueDisallowed;
400 }
401
Chris Lattneraf7e8212002-07-23 17:15:09 +0000402 // findOption - Return the option number corresponding to the specified
403 // argument string. If the option is not found, getNumOptions() is returned.
404 //
405 unsigned findOption(const char *Name);
406
Chris Lattner331de232002-07-22 02:07:59 +0000407protected:
408 bool hasArgStr;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000409};
410
Chris Lattner331de232002-07-22 02:07:59 +0000411// Default parser implementation - This implementation depends on having a
412// mapping of recognized options to values of some sort. In addition to this,
413// each entry in the mapping also tracks a help message that is printed with the
414// command line option for --help. Because this is a simple mapping parser, the
415// data type can be any unsupported type.
416//
417template <class DataType>
418class parser : public generic_parser_base {
Chris Lattneraf7e8212002-07-23 17:15:09 +0000419protected:
Chris Lattner331de232002-07-22 02:07:59 +0000420 std::vector<std::pair<const char *,
421 std::pair<DataType, const char *> > > Values;
Chris Lattneraf7e8212002-07-23 17:15:09 +0000422public:
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000423 typedef DataType parser_data_type;
Chris Lattner331de232002-07-22 02:07:59 +0000424
425 // Implement virtual functions needed by generic_parser_base
426 unsigned getNumOptions() const { return Values.size(); }
427 const char *getOption(unsigned N) const { return Values[N].first; }
428 const char *getDescription(unsigned N) const {
429 return Values[N].second.second;
430 }
431
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000432 // parse - Return true on error.
433 bool parse(Option &O, const char *ArgName, const std::string &Arg,
434 DataType &V) {
Chris Lattner7f4dd472002-07-24 22:08:36 +0000435 std::string ArgVal;
Chris Lattner331de232002-07-22 02:07:59 +0000436 if (hasArgStr)
437 ArgVal = Arg;
438 else
439 ArgVal = ArgName;
440
441 for (unsigned i = 0, e = Values.size(); i != e; ++i)
442 if (ArgVal == Values[i].first) {
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000443 V = Values[i].second.first;
Chris Lattner331de232002-07-22 02:07:59 +0000444 return false;
445 }
446
447 return O.error(": Cannot find option named '" + ArgVal + "'!");
448 }
449
450 // addLiteralOption - Add an entry to the mapping table...
451 template <class DT>
452 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
Chris Lattneraf7e8212002-07-23 17:15:09 +0000453 assert(findOption(Name) == Values.size() && "Option already exists!");
Chris Lattner331de232002-07-22 02:07:59 +0000454 Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
455 }
Chris Lattneraf7e8212002-07-23 17:15:09 +0000456
457 // removeLiteralOption - Remove the specified option.
458 //
459 void removeLiteralOption(const char *Name) {
460 unsigned N = findOption(Name);
461 assert(N != Values.size() && "Option not found!");
462 Values.erase(Values.begin()+N);
463 }
Chris Lattner331de232002-07-22 02:07:59 +0000464};
465
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000466//--------------------------------------------------
467// basic_parser - Super class of parsers to provide boilerplate code
468//
469struct basic_parser_impl { // non-template implementation of basic_parser<t>
470 virtual ~basic_parser_impl() {}
471
472 enum ValueExpected getValueExpectedFlagDefault() const {
473 return ValueRequired;
474 }
475
476 void initialize(Option &O) {}
477
478 // Return the width of the option tag for printing...
479 unsigned getOptionWidth(const Option &O) const;
480
481 // printOptionInfo - Print out information about this option. The
482 // to-be-maintained width is specified.
483 //
484 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
485
486
487 // getValueName - Overload in subclass to provide a better default value.
488 virtual const char *getValueName() const { return "value"; }
489};
490
491// basic_parser - The real basic parser is just a template wrapper that provides
492// a typedef for the provided data type.
493//
494template<class DataType>
495struct basic_parser : public basic_parser_impl {
496 typedef DataType parser_data_type;
497};
498
Chris Lattner331de232002-07-22 02:07:59 +0000499
500//--------------------------------------------------
501// parser<bool>
502//
503template<>
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000504struct parser<bool> : public basic_parser<bool> {
505
506 // parse - Return true on error.
507 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
Chris Lattner331de232002-07-22 02:07:59 +0000508
509 enum ValueExpected getValueExpectedFlagDefault() const {
510 return ValueOptional;
511 }
512
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000513 // getValueName - Do not print =<value> at all
514 virtual const char *getValueName() const { return 0; }
Chris Lattner331de232002-07-22 02:07:59 +0000515};
516
517
518//--------------------------------------------------
519// parser<int>
520//
521template<>
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000522struct parser<int> : public basic_parser<int> {
Chris Lattner331de232002-07-22 02:07:59 +0000523
524 // parse - Return true on error.
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000525 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
Chris Lattner331de232002-07-22 02:07:59 +0000526
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000527 // getValueName - Overload in subclass to provide a better default value.
528 virtual const char *getValueName() const { return "int"; }
Chris Lattner331de232002-07-22 02:07:59 +0000529};
530
531
532//--------------------------------------------------
Chris Lattnerd2a6fc32003-06-28 15:47:20 +0000533// parser<unsigned>
534//
535template<>
536struct parser<unsigned> : public basic_parser<unsigned> {
537
538 // parse - Return true on error.
539 bool parse(Option &O, const char *ArgName, const std::string &Arg,
540 unsigned &Val);
541
542 // getValueName - Overload in subclass to provide a better default value.
543 virtual const char *getValueName() const { return "uint"; }
544};
545
546
547//--------------------------------------------------
Chris Lattner331de232002-07-22 02:07:59 +0000548// parser<double>
549//
550template<>
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000551struct parser<double> : public basic_parser<double> {
Chris Lattner331de232002-07-22 02:07:59 +0000552 // parse - Return true on error.
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000553 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
Chris Lattner331de232002-07-22 02:07:59 +0000554
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000555 // getValueName - Overload in subclass to provide a better default value.
556 virtual const char *getValueName() const { return "number"; }
Chris Lattner331de232002-07-22 02:07:59 +0000557};
558
Chris Lattner331de232002-07-22 02:07:59 +0000559
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000560//--------------------------------------------------
561// parser<float>
562//
563template<>
564struct parser<float> : public basic_parser<float> {
565 // parse - Return true on error.
566 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
567
568 // getValueName - Overload in subclass to provide a better default value.
569 virtual const char *getValueName() const { return "number"; }
570};
Chris Lattner331de232002-07-22 02:07:59 +0000571
572
573//--------------------------------------------------
Chris Lattner7f4dd472002-07-24 22:08:36 +0000574// parser<std::string>
Chris Lattner331de232002-07-22 02:07:59 +0000575//
576template<>
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000577struct parser<std::string> : public basic_parser<std::string> {
Chris Lattner331de232002-07-22 02:07:59 +0000578 // parse - Return true on error.
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000579 bool parse(Option &O, const char *ArgName, const std::string &Arg,
580 std::string &Value) {
581 Value = Arg;
Chris Lattner331de232002-07-22 02:07:59 +0000582 return false;
583 }
Chris Lattner71fb7162002-05-22 17:03:05 +0000584
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000585 // getValueName - Overload in subclass to provide a better default value.
586 virtual const char *getValueName() const { return "string"; }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000587};
588
Chris Lattner71fb7162002-05-22 17:03:05 +0000589
Chris Lattner331de232002-07-22 02:07:59 +0000590
591//===----------------------------------------------------------------------===//
592// applicator class - This class is used because we must use partial
593// specialization to handle literal string arguments specially (const char* does
594// not correctly respond to the apply method). Because the syntax to use this
595// is a pain, we have the 'apply' method below to handle the nastiness...
596//
597template<class Mod> struct applicator {
598 template<class Opt>
599 static void opt(const Mod &M, Opt &O) { M.apply(O); }
600};
601
602// Handle const char* as a special case...
603template<unsigned n> struct applicator<char[n]> {
604 template<class Opt>
605 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
606};
Chris Lattner40423322002-09-13 14:33:39 +0000607template<unsigned n> struct applicator<const char[n]> {
608 template<class Opt>
609 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
610};
Chris Lattner331de232002-07-22 02:07:59 +0000611template<> struct applicator<const char*> {
612 template<class Opt>
613 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
614};
615
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000616template<> struct applicator<NumOccurrences> {
617 static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); }
Chris Lattner331de232002-07-22 02:07:59 +0000618};
619template<> struct applicator<ValueExpected> {
620 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
621};
622template<> struct applicator<OptionHidden> {
623 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
624};
625template<> struct applicator<FormattingFlags> {
626 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
627};
Chris Lattnerb3b729b2003-05-22 20:25:57 +0000628template<> struct applicator<MiscFlags> {
629 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
630};
Chris Lattner331de232002-07-22 02:07:59 +0000631
632// apply method - Apply a modifier to an option in a type safe way.
633template<class Mod, class Opt>
634void apply(const Mod &M, Opt *O) {
635 applicator<Mod>::opt(M, *O);
636}
637
638
639//===----------------------------------------------------------------------===//
640// opt_storage class
641
642// Default storage class definition: external storage. This implementation
643// assumes the user will specify a variable to store the data into with the
644// cl::location(x) modifier.
645//
646template<class DataType, bool ExternalStorage, bool isClass>
647class opt_storage {
648 DataType *Location; // Where to store the object...
649
650 void check() {
651 assert(Location != 0 && "cl::location(...) not specified for a command "
Chris Lattner3c7eb1f2003-08-19 21:57:00 +0000652 "line option with external storage, "
653 "or cl::init specified before cl::location()!!");
Chris Lattner331de232002-07-22 02:07:59 +0000654 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000655public:
Chris Lattner331de232002-07-22 02:07:59 +0000656 opt_storage() : Location(0) {}
657
658 bool setLocation(Option &O, DataType &L) {
659 if (Location)
660 return O.error(": cl::location(x) specified more than once!");
661 Location = &L;
662 return false;
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000663 }
664
Chris Lattner331de232002-07-22 02:07:59 +0000665 template<class T>
666 void setValue(const T &V) {
667 check();
668 *Location = V;
669 }
670
671 DataType &getValue() { check(); return *Location; }
672 const DataType &getValue() const { check(); return *Location; }
673};
674
675
676// Define how to hold a class type object, such as a string. Since we can
677// inherit from a class, we do so. This makes us exactly compatible with the
678// object in all cases that it is used.
679//
680template<class DataType>
681struct opt_storage<DataType,false,true> : public DataType {
682
683 template<class T>
684 void setValue(const T &V) { DataType::operator=(V); }
685
686 DataType &getValue() { return *this; }
687 const DataType &getValue() const { return *this; }
688};
689
690// Define a partial specialization to handle things we cannot inherit from. In
691// this case, we store an instance through containment, and overload operators
692// to get at the value.
693//
694template<class DataType>
695struct opt_storage<DataType, false, false> {
696 DataType Value;
697
698 // Make sure we initialize the value with the default constructor for the
699 // type.
700 opt_storage() : Value(DataType()) {}
701
702 template<class T>
703 void setValue(const T &V) { Value = V; }
704 DataType &getValue() { return Value; }
705 DataType getValue() const { return Value; }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000706};
707
708
709//===----------------------------------------------------------------------===//
Chris Lattner331de232002-07-22 02:07:59 +0000710// opt - A scalar command line option.
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000711//
Chris Lattner331de232002-07-22 02:07:59 +0000712template <class DataType, bool ExternalStorage = false,
713 class ParserClass = parser<DataType> >
714class opt : public Option,
715 public opt_storage<DataType, ExternalStorage,
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000716 ::boost::is_class<DataType>::value> {
Chris Lattner331de232002-07-22 02:07:59 +0000717 ParserClass Parser;
718
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000719 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000720 typename ParserClass::parser_data_type Val;
721 if (Parser.parse(*this, ArgName, Arg, Val))
722 return true; // Parse error!
723 setValue(Val);
724 return false;
Chris Lattner331de232002-07-22 02:07:59 +0000725 }
726
727 virtual enum ValueExpected getValueExpectedFlagDefault() const {
728 return Parser.getValueExpectedFlagDefault();
729 }
730
731 // Forward printing stuff to the parser...
732 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
733 virtual void printOptionInfo(unsigned GlobalWidth) const {
734 Parser.printOptionInfo(*this, GlobalWidth);
735 }
736
737 void done() {
738 addArgument(ArgStr);
739 Parser.initialize(*this);
740 }
741public:
742 // setInitialValue - Used by the cl::init modifier...
Chris Lattner31a6db02003-08-22 14:26:59 +0000743 void setInitialValue(const DataType &V) { this->setValue(V); }
Chris Lattner331de232002-07-22 02:07:59 +0000744
Chris Lattner331de232002-07-22 02:07:59 +0000745 ParserClass &getParser() { return Parser; }
746
Chris Lattner31a6db02003-08-22 14:26:59 +0000747 operator DataType() const { return this->getValue(); }
Chris Lattner331de232002-07-22 02:07:59 +0000748
749 template<class T>
Chris Lattner31a6db02003-08-22 14:26:59 +0000750 DataType &operator=(const T &Val) {
751 this->setValue(Val);
752 return this->getValue();
753 }
Chris Lattner331de232002-07-22 02:07:59 +0000754
755 // One option...
756 template<class M0t>
757 opt(const M0t &M0) {
758 apply(M0, this);
759 done();
760 }
761
762 // Two options...
763 template<class M0t, class M1t>
764 opt(const M0t &M0, const M1t &M1) {
765 apply(M0, this); apply(M1, this);
766 done();
767 }
768
769 // Three options...
770 template<class M0t, class M1t, class M2t>
771 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
772 apply(M0, this); apply(M1, this); apply(M2, this);
773 done();
774 }
775 // Four options...
776 template<class M0t, class M1t, class M2t, class M3t>
777 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
778 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
779 done();
780 }
781 // Five options...
782 template<class M0t, class M1t, class M2t, class M3t, class M4t>
783 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
784 const M4t &M4) {
785 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
786 apply(M4, this);
787 done();
788 }
789 // Six options...
790 template<class M0t, class M1t, class M2t, class M3t,
791 class M4t, class M5t>
792 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
793 const M4t &M4, const M5t &M5) {
794 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
795 apply(M4, this); apply(M5, this);
796 done();
797 }
798 // Seven options...
799 template<class M0t, class M1t, class M2t, class M3t,
800 class M4t, class M5t, class M6t>
801 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
802 const M4t &M4, const M5t &M5, const M6t &M6) {
803 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
804 apply(M4, this); apply(M5, this); apply(M6, this);
805 done();
806 }
807 // Eight options...
808 template<class M0t, class M1t, class M2t, class M3t,
809 class M4t, class M5t, class M6t, class M7t>
810 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
811 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
812 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
813 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
814 done();
815 }
816};
817
818//===----------------------------------------------------------------------===//
819// list_storage class
820
821// Default storage class definition: external storage. This implementation
822// assumes the user will specify a variable to store the data into with the
823// cl::location(x) modifier.
824//
825template<class DataType, class StorageClass>
826class list_storage {
827 StorageClass *Location; // Where to store the object...
828
829public:
830 list_storage() : Location(0) {}
831
832 bool setLocation(Option &O, StorageClass &L) {
833 if (Location)
834 return O.error(": cl::location(x) specified more than once!");
835 Location = &L;
836 return false;
837 }
838
839 template<class T>
840 void addValue(const T &V) {
841 assert(Location != 0 && "cl::location(...) not specified for a command "
842 "line option with external storage!");
843 Location->push_back(V);
844 }
845};
846
847
848// Define how to hold a class type object, such as a string. Since we can
849// inherit from a class, we do so. This makes us exactly compatible with the
850// object in all cases that it is used.
851//
852template<class DataType>
853struct list_storage<DataType, bool> : public std::vector<DataType> {
854
855 template<class T>
856 void addValue(const T &V) { push_back(V); }
857};
858
859
860//===----------------------------------------------------------------------===//
861// list - A list of command line options.
862//
863template <class DataType, class Storage = bool,
864 class ParserClass = parser<DataType> >
865class list : public Option, public list_storage<DataType, Storage> {
866 ParserClass Parser;
867
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000868 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000869 return ZeroOrMore;
870 }
871 virtual enum ValueExpected getValueExpectedFlagDefault() const {
Chris Lattner331de232002-07-22 02:07:59 +0000872 return Parser.getValueExpectedFlagDefault();
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000873 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000874
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000875 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
Chris Lattnerd23a35b2002-08-07 18:36:27 +0000876 typename ParserClass::parser_data_type Val;
877 if (Parser.parse(*this, ArgName, Arg, Val))
878 return true; // Parse Error!
879 addValue(Val);
880 return false;
Chris Lattner331de232002-07-22 02:07:59 +0000881 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000882
Chris Lattner331de232002-07-22 02:07:59 +0000883 // Forward printing stuff to the parser...
884 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
885 virtual void printOptionInfo(unsigned GlobalWidth) const {
886 Parser.printOptionInfo(*this, GlobalWidth);
887 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000888
Chris Lattner331de232002-07-22 02:07:59 +0000889 void done() {
890 addArgument(ArgStr);
891 Parser.initialize(*this);
892 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000893public:
Chris Lattner331de232002-07-22 02:07:59 +0000894 ParserClass &getParser() { return Parser; }
895
896 // One option...
897 template<class M0t>
898 list(const M0t &M0) {
899 apply(M0, this);
900 done();
901 }
902 // Two options...
903 template<class M0t, class M1t>
904 list(const M0t &M0, const M1t &M1) {
905 apply(M0, this); apply(M1, this);
906 done();
907 }
908 // Three options...
909 template<class M0t, class M1t, class M2t>
910 list(const M0t &M0, const M1t &M1, const M2t &M2) {
911 apply(M0, this); apply(M1, this); apply(M2, this);
912 done();
913 }
914 // Four options...
915 template<class M0t, class M1t, class M2t, class M3t>
916 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
917 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
918 done();
919 }
920 // Five options...
921 template<class M0t, class M1t, class M2t, class M3t, class M4t>
922 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
923 const M4t &M4) {
924 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
925 apply(M4, this);
926 done();
927 }
928 // Six options...
929 template<class M0t, class M1t, class M2t, class M3t,
930 class M4t, class M5t>
931 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
932 const M4t &M4, const M5t &M5) {
933 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
934 apply(M4, this); apply(M5, this);
935 done();
936 }
937 // Seven options...
938 template<class M0t, class M1t, class M2t, class M3t,
939 class M4t, class M5t, class M6t>
940 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
941 const M4t &M4, const M5t &M5, const M6t &M6) {
942 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
943 apply(M4, this); apply(M5, this); apply(M6, this);
944 done();
945 }
946 // Eight options...
947 template<class M0t, class M1t, class M2t, class M3t,
948 class M4t, class M5t, class M6t, class M7t>
949 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
950 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
951 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
952 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
953 done();
954 }
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000955};
956
Chris Lattner331de232002-07-22 02:07:59 +0000957
958
959//===----------------------------------------------------------------------===//
960// Aliased command line option (alias this name to a preexisting name)
961//
962
963class alias : public Option {
964 Option *AliasFor;
Misha Brukmandd6cb6a2003-07-10 16:49:51 +0000965 virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
966 return AliasFor->handleOccurrence(AliasFor->ArgStr, Arg);
Chris Lattnercee8f9a2001-11-27 00:03:19 +0000967 }
Chris Lattner331de232002-07-22 02:07:59 +0000968 // Aliases default to be hidden...
969 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
970
971 // Handle printing stuff...
972 virtual unsigned getOptionWidth() const;
973 virtual void printOptionInfo(unsigned GlobalWidth) const;
974
975 void done() {
976 if (!hasArgStr())
977 error(": cl::alias must have argument name specified!");
978 if (AliasFor == 0)
979 error(": cl::alias must have an cl::aliasopt(option) specified!");
980 addArgument(ArgStr);
981 }
982public:
983 void setAliasFor(Option &O) {
984 if (AliasFor)
985 error(": cl::alias must only have one cl::aliasopt(...) specified!");
986 AliasFor = &O;
987 }
988
989 // One option...
990 template<class M0t>
991 alias(const M0t &M0) : AliasFor(0) {
992 apply(M0, this);
993 done();
994 }
995 // Two options...
996 template<class M0t, class M1t>
997 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
998 apply(M0, this); apply(M1, this);
999 done();
1000 }
1001 // Three options...
1002 template<class M0t, class M1t, class M2t>
1003 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
1004 apply(M0, this); apply(M1, this); apply(M2, this);
1005 done();
1006 }
1007 // Four options...
1008 template<class M0t, class M1t, class M2t, class M3t>
1009 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1010 : AliasFor(0) {
1011 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1012 done();
1013 }
1014};
1015
1016// aliasfor - Modifier to set the option an alias aliases.
1017struct aliasopt {
1018 Option &Opt;
1019 aliasopt(Option &O) : Opt(O) {}
1020 void apply(alias &A) const { A.setAliasFor(Opt); }
Chris Lattnercee8f9a2001-11-27 00:03:19 +00001021};
1022
1023} // End namespace cl
1024
1025#endif