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