Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.4 KiB

  1. //===--- OptTable.h - Option Table ------------------------------*- 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. #ifndef LLVM_OPTION_OPTTABLE_H
  10. #define LLVM_OPTION_OPTTABLE_H
  11. #include "llvm/ADT/StringSet.h"
  12. #include "llvm/Option/OptSpecifier.h"
  13. namespace llvm {
  14. class raw_ostream;
  15. namespace opt {
  16. class Arg;
  17. class ArgList;
  18. class InputArgList;
  19. class Option;
  20. /// \brief Provide access to the Option info table.
  21. ///
  22. /// The OptTable class provides a layer of indirection which allows Option
  23. /// instance to be created lazily. In the common case, only a few options will
  24. /// be needed at runtime; the OptTable class maintains enough information to
  25. /// parse command lines without instantiating Options, while letting other
  26. /// parts of the driver still use Option instances where convenient.
  27. class OptTable {
  28. public:
  29. /// \brief Entry for a single option instance in the option data table.
  30. struct Info {
  31. /// A null terminated array of prefix strings to apply to name while
  32. /// matching.
  33. const char *const *Prefixes;
  34. const char *Name;
  35. const char *HelpText;
  36. const char *MetaVar;
  37. unsigned ID;
  38. unsigned char Kind;
  39. unsigned char Param;
  40. unsigned short Flags;
  41. unsigned short GroupID;
  42. unsigned short AliasID;
  43. };
  44. private:
  45. /// \brief The static option information table.
  46. const Info *OptionInfos;
  47. unsigned NumOptionInfos;
  48. unsigned TheInputOptionID;
  49. unsigned TheUnknownOptionID;
  50. /// The index of the first option which can be parsed (i.e., is not a
  51. /// special option like 'input' or 'unknown', and is not an option group).
  52. unsigned FirstSearchableIndex;
  53. /// The union of all option prefixes. If an argument does not begin with
  54. /// one of these, it is an input.
  55. StringSet<> PrefixesUnion;
  56. std::string PrefixChars;
  57. private:
  58. const Info &getInfo(OptSpecifier Opt) const {
  59. unsigned id = Opt.getID();
  60. assert(id > 0 && id - 1 < getNumOptions() && "Invalid Option ID.");
  61. return OptionInfos[id - 1];
  62. }
  63. protected:
  64. OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos);
  65. public:
  66. ~OptTable();
  67. /// \brief Return the total number of option classes.
  68. unsigned getNumOptions() const { return NumOptionInfos; }
  69. /// \brief Get the given Opt's Option instance, lazily creating it
  70. /// if necessary.
  71. ///
  72. /// \return The option, or null for the INVALID option id.
  73. const Option getOption(OptSpecifier Opt) const;
  74. /// \brief Lookup the name of the given option.
  75. const char *getOptionName(OptSpecifier id) const {
  76. return getInfo(id).Name;
  77. }
  78. /// \brief Get the kind of the given option.
  79. unsigned getOptionKind(OptSpecifier id) const {
  80. return getInfo(id).Kind;
  81. }
  82. /// \brief Get the group id for the given option.
  83. unsigned getOptionGroupID(OptSpecifier id) const {
  84. return getInfo(id).GroupID;
  85. }
  86. /// \brief Should the help for the given option be hidden by default.
  87. bool isOptionHelpHidden(OptSpecifier id) const;
  88. /// \brief Get the help text to use to describe this option.
  89. const char *getOptionHelpText(OptSpecifier id) const {
  90. return getInfo(id).HelpText;
  91. }
  92. /// \brief Get the meta-variable name to use when describing
  93. /// this options values in the help text.
  94. const char *getOptionMetaVar(OptSpecifier id) const {
  95. return getInfo(id).MetaVar;
  96. }
  97. /// \brief Parse a single argument; returning the new argument and
  98. /// updating Index.
  99. ///
  100. /// \param [in,out] Index - The current parsing position in the argument
  101. /// string list; on return this will be the index of the next argument
  102. /// string to parse.
  103. ///
  104. /// \return The parsed argument, or 0 if the argument is missing values
  105. /// (in which case Index still points at the conceptual next argument string
  106. /// to parse).
  107. Arg *ParseOneArg(const ArgList &Args, unsigned &Index) const;
  108. /// \brief Parse an list of arguments into an InputArgList.
  109. ///
  110. /// The resulting InputArgList will reference the strings in [\p ArgBegin,
  111. /// \p ArgEnd), and their lifetime should extend past that of the returned
  112. /// InputArgList.
  113. ///
  114. /// The only error that can occur in this routine is if an argument is
  115. /// missing values; in this case \p MissingArgCount will be non-zero.
  116. ///
  117. /// \param ArgBegin - The beginning of the argument vector.
  118. /// \param ArgEnd - The end of the argument vector.
  119. /// \param MissingArgIndex - On error, the index of the option which could
  120. /// not be parsed.
  121. /// \param MissingArgCount - On error, the number of missing options.
  122. /// \return An InputArgList; on error this will contain all the options
  123. /// which could be parsed.
  124. InputArgList *ParseArgs(const char* const *ArgBegin,
  125. const char* const *ArgEnd,
  126. unsigned &MissingArgIndex,
  127. unsigned &MissingArgCount) const;
  128. /// \brief Render the help text for an option table.
  129. ///
  130. /// \param OS - The stream to write the help text to.
  131. /// \param Name - The name to use in the usage line.
  132. /// \param Title - The title to use in the usage line.
  133. /// \param ShowHidden - Whether help-hidden arguments should be shown.
  134. void PrintHelp(raw_ostream &OS, const char *Name,
  135. const char *Title, bool ShowHidden = false) const;
  136. };
  137. } // end namespace opt
  138. } // end namespace llvm
  139. #endif