CommandLine.h revision 194612
1//===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This class implements a command line argument processor that is useful when 11// creating a tool. It provides a simple, minimalistic interface that is easily 12// extensible and supports nonlocal (library) command line options. 13// 14// Note that rather than trying to figure out what this code does, you should 15// read the library documentation located in docs/CommandLine.html or looks at 16// the many example usages in tools/*/*.cpp 17// 18//===----------------------------------------------------------------------===// 19 20#ifndef LLVM_SUPPORT_COMMANDLINE_H 21#define LLVM_SUPPORT_COMMANDLINE_H 22 23#include "llvm/Support/type_traits.h" 24#include "llvm/Support/DataTypes.h" 25#include "llvm/Support/Compiler.h" 26#include "llvm/ADT/SmallVector.h" 27#include <cassert> 28#include <climits> 29#include <cstdarg> 30#include <string> 31#include <utility> 32#include <vector> 33 34namespace llvm { 35 36/// cl Namespace - This namespace contains all of the command line option 37/// processing machinery. It is intentionally a short name to make qualified 38/// usage concise. 39namespace cl { 40 41//===----------------------------------------------------------------------===// 42// ParseCommandLineOptions - Command line option processing entry point. 43// 44void ParseCommandLineOptions(int argc, char **argv, 45 const char *Overview = 0, 46 bool ReadResponseFiles = false); 47 48//===----------------------------------------------------------------------===// 49// ParseEnvironmentOptions - Environment variable option processing alternate 50// entry point. 51// 52void ParseEnvironmentOptions(const char *progName, const char *envvar, 53 const char *Overview = 0, 54 bool ReadResponseFiles = false); 55 56///===---------------------------------------------------------------------===// 57/// SetVersionPrinter - Override the default (LLVM specific) version printer 58/// used to print out the version when --version is given 59/// on the command line. This allows other systems using the 60/// CommandLine utilities to print their own version string. 61void SetVersionPrinter(void (*func)()); 62 63 64// MarkOptionsChanged - Internal helper function. 65void MarkOptionsChanged(); 66 67//===----------------------------------------------------------------------===// 68// Flags permitted to be passed to command line arguments 69// 70 71enum NumOccurrences { // Flags for the number of occurrences allowed 72 Optional = 0x01, // Zero or One occurrence 73 ZeroOrMore = 0x02, // Zero or more occurrences allowed 74 Required = 0x03, // One occurrence required 75 OneOrMore = 0x04, // One or more occurrences required 76 77 // ConsumeAfter - Indicates that this option is fed anything that follows the 78 // last positional argument required by the application (it is an error if 79 // there are zero positional arguments, and a ConsumeAfter option is used). 80 // Thus, for example, all arguments to LLI are processed until a filename is 81 // found. Once a filename is found, all of the succeeding arguments are 82 // passed, unprocessed, to the ConsumeAfter option. 83 // 84 ConsumeAfter = 0x05, 85 86 OccurrencesMask = 0x07 87}; 88 89enum ValueExpected { // Is a value required for the option? 90 ValueOptional = 0x08, // The value can appear... or not 91 ValueRequired = 0x10, // The value is required to appear! 92 ValueDisallowed = 0x18, // A value may not be specified (for flags) 93 ValueMask = 0x18 94}; 95 96enum OptionHidden { // Control whether -help shows this option 97 NotHidden = 0x20, // Option included in --help & --help-hidden 98 Hidden = 0x40, // -help doesn't, but --help-hidden does 99 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg 100 HiddenMask = 0x60 101}; 102 103// Formatting flags - This controls special features that the option might have 104// that cause it to be parsed differently... 105// 106// Prefix - This option allows arguments that are otherwise unrecognized to be 107// matched by options that are a prefix of the actual value. This is useful for 108// cases like a linker, where options are typically of the form '-lfoo' or 109// '-L../../include' where -l or -L are the actual flags. When prefix is 110// enabled, and used, the value for the flag comes from the suffix of the 111// argument. 112// 113// Grouping - With this option enabled, multiple letter options are allowed to 114// bunch together with only a single hyphen for the whole group. This allows 115// emulation of the behavior that ls uses for example: ls -la === ls -l -a 116// 117 118enum FormattingFlags { 119 NormalFormatting = 0x000, // Nothing special 120 Positional = 0x080, // Is a positional argument, no '-' required 121 Prefix = 0x100, // Can this option directly prefix its value? 122 Grouping = 0x180, // Can this option group with other options? 123 FormattingMask = 0x180 // Union of the above flags. 124}; 125 126enum MiscFlags { // Miscellaneous flags to adjust argument 127 CommaSeparated = 0x200, // Should this cl::list split between commas? 128 PositionalEatsArgs = 0x400, // Should this positional cl::list eat -args? 129 Sink = 0x800, // Should this cl::list eat all unknown options? 130 MiscMask = 0xE00 // 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 const char *ArgStr; 541public: 542 543 // parse - Return true on error. 544 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val); 545 546 template <class Opt> 547 void initialize(Opt &O) { 548 ArgStr = O.ArgStr; 549 } 550 551 enum ValueExpected getValueExpectedFlagDefault() const { 552 return ValueOptional; 553 } 554 555 // getValueName - Do not print =<value> at all. 556 virtual const char *getValueName() const { return 0; } 557 558 // An out-of-line virtual method to provide a 'home' for this class. 559 virtual void anchor(); 560}; 561 562EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<bool>); 563 564//-------------------------------------------------- 565// parser<boolOrDefault> 566enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE }; 567template<> 568class parser<boolOrDefault> : public basic_parser<boolOrDefault> { 569public: 570 // parse - Return true on error. 571 bool parse(Option &O, const char *ArgName, const std::string &Arg, 572 boolOrDefault &Val); 573 574 enum ValueExpected getValueExpectedFlagDefault() const { 575 return ValueOptional; 576 } 577 578 // getValueName - Do not print =<value> at all. 579 virtual const char *getValueName() const { return 0; } 580 581 // An out-of-line virtual method to provide a 'home' for this class. 582 virtual void anchor(); 583}; 584 585EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>); 586 587//-------------------------------------------------- 588// parser<int> 589// 590template<> 591class parser<int> : public basic_parser<int> { 592public: 593 // parse - Return true on error. 594 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val); 595 596 // getValueName - Overload in subclass to provide a better default value. 597 virtual const char *getValueName() const { return "int"; } 598 599 // An out-of-line virtual method to provide a 'home' for this class. 600 virtual void anchor(); 601}; 602 603EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>); 604 605 606//-------------------------------------------------- 607// parser<unsigned> 608// 609template<> 610class parser<unsigned> : public basic_parser<unsigned> { 611public: 612 // parse - Return true on error. 613 bool parse(Option &O, const char *AN, const std::string &Arg, unsigned &Val); 614 615 // getValueName - Overload in subclass to provide a better default value. 616 virtual const char *getValueName() const { return "uint"; } 617 618 // An out-of-line virtual method to provide a 'home' for this class. 619 virtual void anchor(); 620}; 621 622EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned>); 623 624//-------------------------------------------------- 625// parser<double> 626// 627template<> 628class parser<double> : public basic_parser<double> { 629public: 630 // parse - Return true on error. 631 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val); 632 633 // getValueName - Overload in subclass to provide a better default value. 634 virtual const char *getValueName() const { return "number"; } 635 636 // An out-of-line virtual method to provide a 'home' for this class. 637 virtual void anchor(); 638}; 639 640EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<double>); 641 642//-------------------------------------------------- 643// parser<float> 644// 645template<> 646class parser<float> : public basic_parser<float> { 647public: 648 // parse - Return true on error. 649 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val); 650 651 // getValueName - Overload in subclass to provide a better default value. 652 virtual const char *getValueName() const { return "number"; } 653 654 // An out-of-line virtual method to provide a 'home' for this class. 655 virtual void anchor(); 656}; 657 658EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<float>); 659 660//-------------------------------------------------- 661// parser<std::string> 662// 663template<> 664class parser<std::string> : public basic_parser<std::string> { 665public: 666 // parse - Return true on error. 667 bool parse(Option &, const char *, const std::string &Arg, 668 std::string &Value) { 669 Value = Arg; 670 return false; 671 } 672 673 // getValueName - Overload in subclass to provide a better default value. 674 virtual const char *getValueName() const { return "string"; } 675 676 // An out-of-line virtual method to provide a 'home' for this class. 677 virtual void anchor(); 678}; 679 680EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<std::string>); 681 682//-------------------------------------------------- 683// parser<char> 684// 685template<> 686class parser<char> : public basic_parser<char> { 687public: 688 // parse - Return true on error. 689 bool parse(Option &, const char *, const std::string &Arg, 690 char &Value) { 691 Value = Arg[0]; 692 return false; 693 } 694 695 // getValueName - Overload in subclass to provide a better default value. 696 virtual const char *getValueName() const { return "char"; } 697 698 // An out-of-line virtual method to provide a 'home' for this class. 699 virtual void anchor(); 700}; 701 702EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<char>); 703 704//===----------------------------------------------------------------------===// 705// applicator class - This class is used because we must use partial 706// specialization to handle literal string arguments specially (const char* does 707// not correctly respond to the apply method). Because the syntax to use this 708// is a pain, we have the 'apply' method below to handle the nastiness... 709// 710template<class Mod> struct applicator { 711 template<class Opt> 712 static void opt(const Mod &M, Opt &O) { M.apply(O); } 713}; 714 715// Handle const char* as a special case... 716template<unsigned n> struct applicator<char[n]> { 717 template<class Opt> 718 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); } 719}; 720template<unsigned n> struct applicator<const char[n]> { 721 template<class Opt> 722 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); } 723}; 724template<> struct applicator<const char*> { 725 template<class Opt> 726 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); } 727}; 728 729template<> struct applicator<NumOccurrences> { 730 static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); } 731}; 732template<> struct applicator<ValueExpected> { 733 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); } 734}; 735template<> struct applicator<OptionHidden> { 736 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); } 737}; 738template<> struct applicator<FormattingFlags> { 739 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); } 740}; 741template<> struct applicator<MiscFlags> { 742 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); } 743}; 744 745// apply method - Apply a modifier to an option in a type safe way. 746template<class Mod, class Opt> 747void apply(const Mod &M, Opt *O) { 748 applicator<Mod>::opt(M, *O); 749} 750 751 752//===----------------------------------------------------------------------===// 753// opt_storage class 754 755// Default storage class definition: external storage. This implementation 756// assumes the user will specify a variable to store the data into with the 757// cl::location(x) modifier. 758// 759template<class DataType, bool ExternalStorage, bool isClass> 760class opt_storage { 761 DataType *Location; // Where to store the object... 762 763 void check() const { 764 assert(Location != 0 && "cl::location(...) not specified for a command " 765 "line option with external storage, " 766 "or cl::init specified before cl::location()!!"); 767 } 768public: 769 opt_storage() : Location(0) {} 770 771 bool setLocation(Option &O, DataType &L) { 772 if (Location) 773 return O.error(": cl::location(x) specified more than once!"); 774 Location = &L; 775 return false; 776 } 777 778 template<class T> 779 void setValue(const T &V) { 780 check(); 781 *Location = V; 782 } 783 784 DataType &getValue() { check(); return *Location; } 785 const DataType &getValue() const { check(); return *Location; } 786}; 787 788 789// Define how to hold a class type object, such as a string. Since we can 790// inherit from a class, we do so. This makes us exactly compatible with the 791// object in all cases that it is used. 792// 793template<class DataType> 794class opt_storage<DataType,false,true> : public DataType { 795public: 796 template<class T> 797 void setValue(const T &V) { DataType::operator=(V); } 798 799 DataType &getValue() { return *this; } 800 const DataType &getValue() const { return *this; } 801}; 802 803// Define a partial specialization to handle things we cannot inherit from. In 804// this case, we store an instance through containment, and overload operators 805// to get at the value. 806// 807template<class DataType> 808class opt_storage<DataType, false, false> { 809public: 810 DataType Value; 811 812 // Make sure we initialize the value with the default constructor for the 813 // type. 814 opt_storage() : Value(DataType()) {} 815 816 template<class T> 817 void setValue(const T &V) { Value = V; } 818 DataType &getValue() { return Value; } 819 DataType getValue() const { return Value; } 820 821 // If the datatype is a pointer, support -> on it. 822 DataType operator->() const { return Value; } 823}; 824 825 826//===----------------------------------------------------------------------===// 827// opt - A scalar command line option. 828// 829template <class DataType, bool ExternalStorage = false, 830 class ParserClass = parser<DataType> > 831class opt : public Option, 832 public opt_storage<DataType, ExternalStorage, 833 is_class<DataType>::value> { 834 ParserClass Parser; 835 836 virtual bool handleOccurrence(unsigned pos, const char *ArgName, 837 const std::string &Arg) { 838 typename ParserClass::parser_data_type Val = 839 typename ParserClass::parser_data_type(); 840 if (Parser.parse(*this, ArgName, Arg, Val)) 841 return true; // Parse error! 842 this->setValue(Val); 843 this->setPosition(pos); 844 return false; 845 } 846 847 virtual enum ValueExpected getValueExpectedFlagDefault() const { 848 return Parser.getValueExpectedFlagDefault(); 849 } 850 virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) { 851 return Parser.getExtraOptionNames(OptionNames); 852 } 853 854 // Forward printing stuff to the parser... 855 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);} 856 virtual void printOptionInfo(size_t GlobalWidth) const { 857 Parser.printOptionInfo(*this, GlobalWidth); 858 } 859 860 void done() { 861 addArgument(); 862 Parser.initialize(*this); 863 } 864public: 865 // setInitialValue - Used by the cl::init modifier... 866 void setInitialValue(const DataType &V) { this->setValue(V); } 867 868 ParserClass &getParser() { return Parser; } 869 870 operator DataType() const { return this->getValue(); } 871 872 template<class T> 873 DataType &operator=(const T &Val) { 874 this->setValue(Val); 875 return this->getValue(); 876 } 877 878 // One option... 879 template<class M0t> 880 explicit opt(const M0t &M0) : Option(Optional | NotHidden) { 881 apply(M0, this); 882 done(); 883 } 884 885 // Two options... 886 template<class M0t, class M1t> 887 opt(const M0t &M0, const M1t &M1) : Option(Optional | NotHidden) { 888 apply(M0, this); apply(M1, this); 889 done(); 890 } 891 892 // Three options... 893 template<class M0t, class M1t, class M2t> 894 opt(const M0t &M0, const M1t &M1, 895 const M2t &M2) : Option(Optional | NotHidden) { 896 apply(M0, this); apply(M1, this); apply(M2, this); 897 done(); 898 } 899 // Four options... 900 template<class M0t, class M1t, class M2t, class M3t> 901 opt(const M0t &M0, const M1t &M1, const M2t &M2, 902 const M3t &M3) : Option(Optional | NotHidden) { 903 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 904 done(); 905 } 906 // Five options... 907 template<class M0t, class M1t, class M2t, class M3t, class M4t> 908 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 909 const M4t &M4) : Option(Optional | NotHidden) { 910 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 911 apply(M4, this); 912 done(); 913 } 914 // Six options... 915 template<class M0t, class M1t, class M2t, class M3t, 916 class M4t, class M5t> 917 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 918 const M4t &M4, const M5t &M5) : Option(Optional | NotHidden) { 919 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 920 apply(M4, this); apply(M5, this); 921 done(); 922 } 923 // Seven options... 924 template<class M0t, class M1t, class M2t, class M3t, 925 class M4t, class M5t, class M6t> 926 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 927 const M4t &M4, const M5t &M5, 928 const M6t &M6) : Option(Optional | NotHidden) { 929 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 930 apply(M4, this); apply(M5, this); apply(M6, this); 931 done(); 932 } 933 // Eight options... 934 template<class M0t, class M1t, class M2t, class M3t, 935 class M4t, class M5t, class M6t, class M7t> 936 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 937 const M4t &M4, const M5t &M5, const M6t &M6, 938 const M7t &M7) : Option(Optional | NotHidden) { 939 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 940 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this); 941 done(); 942 } 943}; 944 945EXTERN_TEMPLATE_INSTANTIATION(class opt<unsigned>); 946EXTERN_TEMPLATE_INSTANTIATION(class opt<int>); 947EXTERN_TEMPLATE_INSTANTIATION(class opt<std::string>); 948EXTERN_TEMPLATE_INSTANTIATION(class opt<char>); 949EXTERN_TEMPLATE_INSTANTIATION(class opt<bool>); 950 951//===----------------------------------------------------------------------===// 952// list_storage class 953 954// Default storage class definition: external storage. This implementation 955// assumes the user will specify a variable to store the data into with the 956// cl::location(x) modifier. 957// 958template<class DataType, class StorageClass> 959class list_storage { 960 StorageClass *Location; // Where to store the object... 961 962public: 963 list_storage() : Location(0) {} 964 965 bool setLocation(Option &O, StorageClass &L) { 966 if (Location) 967 return O.error(": cl::location(x) specified more than once!"); 968 Location = &L; 969 return false; 970 } 971 972 template<class T> 973 void addValue(const T &V) { 974 assert(Location != 0 && "cl::location(...) not specified for a command " 975 "line option with external storage!"); 976 Location->push_back(V); 977 } 978}; 979 980 981// Define how to hold a class type object, such as a string. Since we can 982// inherit from a class, we do so. This makes us exactly compatible with the 983// object in all cases that it is used. 984// 985template<class DataType> 986class list_storage<DataType, bool> : public std::vector<DataType> { 987public: 988 template<class T> 989 void addValue(const T &V) { push_back(V); } 990}; 991 992 993//===----------------------------------------------------------------------===// 994// list - A list of command line options. 995// 996template <class DataType, class Storage = bool, 997 class ParserClass = parser<DataType> > 998class list : public Option, public list_storage<DataType, Storage> { 999 std::vector<unsigned> Positions; 1000 ParserClass Parser; 1001 1002 virtual enum ValueExpected getValueExpectedFlagDefault() const { 1003 return Parser.getValueExpectedFlagDefault(); 1004 } 1005 virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) { 1006 return Parser.getExtraOptionNames(OptionNames); 1007 } 1008 1009 virtual bool handleOccurrence(unsigned pos, const char *ArgName, 1010 const std::string &Arg) { 1011 typename ParserClass::parser_data_type Val = 1012 typename ParserClass::parser_data_type(); 1013 if (Parser.parse(*this, ArgName, Arg, Val)) 1014 return true; // Parse Error! 1015 addValue(Val); 1016 setPosition(pos); 1017 Positions.push_back(pos); 1018 return false; 1019 } 1020 1021 // Forward printing stuff to the parser... 1022 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);} 1023 virtual void printOptionInfo(size_t GlobalWidth) const { 1024 Parser.printOptionInfo(*this, GlobalWidth); 1025 } 1026 1027 void done() { 1028 addArgument(); 1029 Parser.initialize(*this); 1030 } 1031public: 1032 ParserClass &getParser() { return Parser; } 1033 1034 unsigned getPosition(unsigned optnum) const { 1035 assert(optnum < this->size() && "Invalid option index"); 1036 return Positions[optnum]; 1037 } 1038 1039 void setNumAdditionalVals(unsigned n) { 1040 Option::setNumAdditionalVals(n); 1041 } 1042 1043 // One option... 1044 template<class M0t> 1045 explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) { 1046 apply(M0, this); 1047 done(); 1048 } 1049 // Two options... 1050 template<class M0t, class M1t> 1051 list(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) { 1052 apply(M0, this); apply(M1, this); 1053 done(); 1054 } 1055 // Three options... 1056 template<class M0t, class M1t, class M2t> 1057 list(const M0t &M0, const M1t &M1, const M2t &M2) 1058 : Option(ZeroOrMore | NotHidden) { 1059 apply(M0, this); apply(M1, this); apply(M2, this); 1060 done(); 1061 } 1062 // Four options... 1063 template<class M0t, class M1t, class M2t, class M3t> 1064 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) 1065 : Option(ZeroOrMore | NotHidden) { 1066 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1067 done(); 1068 } 1069 // Five options... 1070 template<class M0t, class M1t, class M2t, class M3t, class M4t> 1071 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1072 const M4t &M4) : Option(ZeroOrMore | NotHidden) { 1073 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1074 apply(M4, this); 1075 done(); 1076 } 1077 // Six options... 1078 template<class M0t, class M1t, class M2t, class M3t, 1079 class M4t, class M5t> 1080 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1081 const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) { 1082 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1083 apply(M4, this); apply(M5, this); 1084 done(); 1085 } 1086 // Seven options... 1087 template<class M0t, class M1t, class M2t, class M3t, 1088 class M4t, class M5t, class M6t> 1089 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1090 const M4t &M4, const M5t &M5, const M6t &M6) 1091 : Option(ZeroOrMore | NotHidden) { 1092 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1093 apply(M4, this); apply(M5, this); apply(M6, this); 1094 done(); 1095 } 1096 // Eight options... 1097 template<class M0t, class M1t, class M2t, class M3t, 1098 class M4t, class M5t, class M6t, class M7t> 1099 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1100 const M4t &M4, const M5t &M5, const M6t &M6, 1101 const M7t &M7) : Option(ZeroOrMore | NotHidden) { 1102 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1103 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this); 1104 done(); 1105 } 1106}; 1107 1108// multi_val - Modifier to set the number of additional values. 1109struct multi_val { 1110 unsigned AdditionalVals; 1111 explicit multi_val(unsigned N) : AdditionalVals(N) {} 1112 1113 template <typename D, typename S, typename P> 1114 void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); } 1115}; 1116 1117 1118//===----------------------------------------------------------------------===// 1119// bits_storage class 1120 1121// Default storage class definition: external storage. This implementation 1122// assumes the user will specify a variable to store the data into with the 1123// cl::location(x) modifier. 1124// 1125template<class DataType, class StorageClass> 1126class bits_storage { 1127 unsigned *Location; // Where to store the bits... 1128 1129 template<class T> 1130 static unsigned Bit(const T &V) { 1131 unsigned BitPos = reinterpret_cast<unsigned>(V); 1132 assert(BitPos < sizeof(unsigned) * CHAR_BIT && 1133 "enum exceeds width of bit vector!"); 1134 return 1 << BitPos; 1135 } 1136 1137public: 1138 bits_storage() : Location(0) {} 1139 1140 bool setLocation(Option &O, unsigned &L) { 1141 if (Location) 1142 return O.error(": cl::location(x) specified more than once!"); 1143 Location = &L; 1144 return false; 1145 } 1146 1147 template<class T> 1148 void addValue(const T &V) { 1149 assert(Location != 0 && "cl::location(...) not specified for a command " 1150 "line option with external storage!"); 1151 *Location |= Bit(V); 1152 } 1153 1154 unsigned getBits() { return *Location; } 1155 1156 template<class T> 1157 bool isSet(const T &V) { 1158 return (*Location & Bit(V)) != 0; 1159 } 1160}; 1161 1162 1163// Define how to hold bits. Since we can inherit from a class, we do so. 1164// This makes us exactly compatible with the bits in all cases that it is used. 1165// 1166template<class DataType> 1167class bits_storage<DataType, bool> { 1168 unsigned Bits; // Where to store the bits... 1169 1170 template<class T> 1171 static unsigned Bit(const T &V) { 1172 unsigned BitPos = reinterpret_cast<unsigned>(V); 1173 assert(BitPos < sizeof(unsigned) * CHAR_BIT && 1174 "enum exceeds width of bit vector!"); 1175 return 1 << BitPos; 1176 } 1177 1178public: 1179 template<class T> 1180 void addValue(const T &V) { 1181 Bits |= Bit(V); 1182 } 1183 1184 unsigned getBits() { return Bits; } 1185 1186 template<class T> 1187 bool isSet(const T &V) { 1188 return (Bits & Bit(V)) != 0; 1189 } 1190}; 1191 1192 1193//===----------------------------------------------------------------------===// 1194// bits - A bit vector of command options. 1195// 1196template <class DataType, class Storage = bool, 1197 class ParserClass = parser<DataType> > 1198class bits : public Option, public bits_storage<DataType, Storage> { 1199 std::vector<unsigned> Positions; 1200 ParserClass Parser; 1201 1202 virtual enum ValueExpected getValueExpectedFlagDefault() const { 1203 return Parser.getValueExpectedFlagDefault(); 1204 } 1205 virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) { 1206 return Parser.getExtraOptionNames(OptionNames); 1207 } 1208 1209 virtual bool handleOccurrence(unsigned pos, const char *ArgName, 1210 const std::string &Arg) { 1211 typename ParserClass::parser_data_type Val = 1212 typename ParserClass::parser_data_type(); 1213 if (Parser.parse(*this, ArgName, Arg, Val)) 1214 return true; // Parse Error! 1215 addValue(Val); 1216 setPosition(pos); 1217 Positions.push_back(pos); 1218 return false; 1219 } 1220 1221 // Forward printing stuff to the parser... 1222 virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);} 1223 virtual void printOptionInfo(size_t GlobalWidth) const { 1224 Parser.printOptionInfo(*this, GlobalWidth); 1225 } 1226 1227 void done() { 1228 addArgument(); 1229 Parser.initialize(*this); 1230 } 1231public: 1232 ParserClass &getParser() { return Parser; } 1233 1234 unsigned getPosition(unsigned optnum) const { 1235 assert(optnum < this->size() && "Invalid option index"); 1236 return Positions[optnum]; 1237 } 1238 1239 // One option... 1240 template<class M0t> 1241 explicit bits(const M0t &M0) : Option(ZeroOrMore | NotHidden) { 1242 apply(M0, this); 1243 done(); 1244 } 1245 // Two options... 1246 template<class M0t, class M1t> 1247 bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) { 1248 apply(M0, this); apply(M1, this); 1249 done(); 1250 } 1251 // Three options... 1252 template<class M0t, class M1t, class M2t> 1253 bits(const M0t &M0, const M1t &M1, const M2t &M2) 1254 : Option(ZeroOrMore | NotHidden) { 1255 apply(M0, this); apply(M1, this); apply(M2, this); 1256 done(); 1257 } 1258 // Four options... 1259 template<class M0t, class M1t, class M2t, class M3t> 1260 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) 1261 : Option(ZeroOrMore | NotHidden) { 1262 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1263 done(); 1264 } 1265 // Five options... 1266 template<class M0t, class M1t, class M2t, class M3t, class M4t> 1267 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1268 const M4t &M4) : Option(ZeroOrMore | NotHidden) { 1269 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1270 apply(M4, this); 1271 done(); 1272 } 1273 // Six options... 1274 template<class M0t, class M1t, class M2t, class M3t, 1275 class M4t, class M5t> 1276 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1277 const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) { 1278 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1279 apply(M4, this); apply(M5, this); 1280 done(); 1281 } 1282 // Seven options... 1283 template<class M0t, class M1t, class M2t, class M3t, 1284 class M4t, class M5t, class M6t> 1285 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1286 const M4t &M4, const M5t &M5, const M6t &M6) 1287 : Option(ZeroOrMore | NotHidden) { 1288 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1289 apply(M4, this); apply(M5, this); apply(M6, this); 1290 done(); 1291 } 1292 // Eight options... 1293 template<class M0t, class M1t, class M2t, class M3t, 1294 class M4t, class M5t, class M6t, class M7t> 1295 bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, 1296 const M4t &M4, const M5t &M5, const M6t &M6, 1297 const M7t &M7) : Option(ZeroOrMore | NotHidden) { 1298 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1299 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this); 1300 done(); 1301 } 1302}; 1303 1304//===----------------------------------------------------------------------===// 1305// Aliased command line option (alias this name to a preexisting name) 1306// 1307 1308class alias : public Option { 1309 Option *AliasFor; 1310 virtual bool handleOccurrence(unsigned pos, const char * /*ArgName*/, 1311 const std::string &Arg) { 1312 return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg); 1313 } 1314 // Handle printing stuff... 1315 virtual size_t getOptionWidth() const; 1316 virtual void printOptionInfo(size_t GlobalWidth) const; 1317 1318 void done() { 1319 if (!hasArgStr()) 1320 error(": cl::alias must have argument name specified!"); 1321 if (AliasFor == 0) 1322 error(": cl::alias must have an cl::aliasopt(option) specified!"); 1323 addArgument(); 1324 } 1325public: 1326 void setAliasFor(Option &O) { 1327 if (AliasFor) 1328 error(": cl::alias must only have one cl::aliasopt(...) specified!"); 1329 AliasFor = &O; 1330 } 1331 1332 // One option... 1333 template<class M0t> 1334 explicit alias(const M0t &M0) : Option(Optional | Hidden), AliasFor(0) { 1335 apply(M0, this); 1336 done(); 1337 } 1338 // Two options... 1339 template<class M0t, class M1t> 1340 alias(const M0t &M0, const M1t &M1) : Option(Optional | Hidden), AliasFor(0) { 1341 apply(M0, this); apply(M1, this); 1342 done(); 1343 } 1344 // Three options... 1345 template<class M0t, class M1t, class M2t> 1346 alias(const M0t &M0, const M1t &M1, const M2t &M2) 1347 : Option(Optional | Hidden), AliasFor(0) { 1348 apply(M0, this); apply(M1, this); apply(M2, this); 1349 done(); 1350 } 1351 // Four options... 1352 template<class M0t, class M1t, class M2t, class M3t> 1353 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) 1354 : Option(Optional | Hidden), AliasFor(0) { 1355 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this); 1356 done(); 1357 } 1358}; 1359 1360// aliasfor - Modifier to set the option an alias aliases. 1361struct aliasopt { 1362 Option &Opt; 1363 explicit aliasopt(Option &O) : Opt(O) {} 1364 void apply(alias &A) const { A.setAliasFor(Opt); } 1365}; 1366 1367// extrahelp - provide additional help at the end of the normal help 1368// output. All occurrences of cl::extrahelp will be accumulated and 1369// printed to std::cerr at the end of the regular help, just before 1370// exit is called. 1371struct extrahelp { 1372 const char * morehelp; 1373 explicit extrahelp(const char* help); 1374}; 1375 1376void PrintVersionMessage(); 1377// This function just prints the help message, exactly the same way as if the 1378// --help option had been given on the command line. 1379// NOTE: THIS FUNCTION TERMINATES THE PROGRAM! 1380void PrintHelpMessage(); 1381 1382} // End namespace cl 1383 1384} // End namespace llvm 1385 1386#endif 1387