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.

132 lines
4.0 KiB

  1. //===--- Arg.h - Parsed Argument Classes ------------------------*- 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. /// \file
  11. /// \brief Defines the llvm::Arg class for parsed arguments.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_OPTION_ARG_H
  15. #define LLVM_OPTION_ARG_H
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/Option/Option.h"
  19. #include <string>
  20. namespace llvm {
  21. namespace opt {
  22. class ArgList;
  23. /// \brief A concrete instance of a particular driver option.
  24. ///
  25. /// The Arg class encodes just enough information to be able to
  26. /// derive the argument values efficiently. In addition, Arg
  27. /// instances have an intrusive double linked list which is used by
  28. /// ArgList to provide efficient iteration over all instances of a
  29. /// particular option.
  30. class Arg {
  31. Arg(const Arg &) LLVM_DELETED_FUNCTION;
  32. void operator=(const Arg &) LLVM_DELETED_FUNCTION;
  33. private:
  34. /// \brief The option this argument is an instance of.
  35. const Option Opt;
  36. /// \brief The argument this argument was derived from (during tool chain
  37. /// argument translation), if any.
  38. const Arg *BaseArg;
  39. /// \brief How this instance of the option was spelled.
  40. StringRef Spelling;
  41. /// \brief The index at which this argument appears in the containing
  42. /// ArgList.
  43. unsigned Index;
  44. /// \brief Was this argument used to effect compilation?
  45. ///
  46. /// This is used for generating "argument unused" diagnostics.
  47. mutable unsigned Claimed : 1;
  48. /// \brief Does this argument own its values?
  49. mutable unsigned OwnsValues : 1;
  50. /// \brief The argument values, as C strings.
  51. SmallVector<const char *, 2> Values;
  52. public:
  53. Arg(const Option Opt, StringRef Spelling, unsigned Index,
  54. const Arg *BaseArg = 0);
  55. Arg(const Option Opt, StringRef Spelling, unsigned Index,
  56. const char *Value0, const Arg *BaseArg = 0);
  57. Arg(const Option Opt, StringRef Spelling, unsigned Index,
  58. const char *Value0, const char *Value1, const Arg *BaseArg = 0);
  59. ~Arg();
  60. const Option getOption() const { return Opt; }
  61. StringRef getSpelling() const { return Spelling; }
  62. unsigned getIndex() const { return Index; }
  63. /// \brief Return the base argument which generated this arg.
  64. ///
  65. /// This is either the argument itself or the argument it was
  66. /// derived from during tool chain specific argument translation.
  67. const Arg &getBaseArg() const {
  68. return BaseArg ? *BaseArg : *this;
  69. }
  70. void setBaseArg(const Arg *_BaseArg) {
  71. BaseArg = _BaseArg;
  72. }
  73. bool getOwnsValues() const { return OwnsValues; }
  74. void setOwnsValues(bool Value) const { OwnsValues = Value; }
  75. bool isClaimed() const { return getBaseArg().Claimed; }
  76. /// \brief Set the Arg claimed bit.
  77. void claim() const { getBaseArg().Claimed = true; }
  78. unsigned getNumValues() const { return Values.size(); }
  79. const char *getValue(unsigned N = 0) const {
  80. return Values[N];
  81. }
  82. SmallVectorImpl<const char*> &getValues() {
  83. return Values;
  84. }
  85. bool containsValue(StringRef Value) const {
  86. for (unsigned i = 0, e = getNumValues(); i != e; ++i)
  87. if (Values[i] == Value)
  88. return true;
  89. return false;
  90. }
  91. /// \brief Append the argument onto the given array as strings.
  92. void render(const ArgList &Args, ArgStringList &Output) const;
  93. /// \brief Append the argument, render as an input, onto the given
  94. /// array as strings.
  95. ///
  96. /// The distinction is that some options only render their values
  97. /// when rendered as a input (e.g., Xlinker).
  98. void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
  99. void dump() const;
  100. /// \brief Return a formatted version of the argument and
  101. /// its values, for debugging and diagnostics.
  102. std::string getAsString(const ArgList &Args) const;
  103. };
  104. } // end namespace opt
  105. } // end namespace llvm
  106. #endif