File indexing completed on 2026-05-10 08:44:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_OPTION_ARG_H
0015 #define LLVM_OPTION_ARG_H
0016
0017 #include "llvm/ADT/SmallVector.h"
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/Option/Option.h"
0020 #include <string>
0021
0022 namespace llvm {
0023
0024 class raw_ostream;
0025
0026 namespace opt {
0027
0028 class ArgList;
0029
0030
0031
0032
0033
0034 class Arg {
0035 private:
0036
0037 const Option Opt;
0038
0039
0040
0041 const Arg *BaseArg;
0042
0043
0044 StringRef Spelling;
0045
0046
0047
0048 unsigned Index;
0049
0050
0051
0052
0053
0054
0055 mutable unsigned Claimed : 1;
0056
0057
0058
0059 unsigned IgnoredTargetSpecific : 1;
0060
0061
0062 mutable unsigned OwnsValues : 1;
0063
0064
0065 SmallVector<const char *, 2> Values;
0066
0067
0068
0069
0070 std::unique_ptr<Arg> Alias;
0071
0072 public:
0073 Arg(const Option Opt, StringRef Spelling, unsigned Index,
0074 const Arg *BaseArg = nullptr);
0075 Arg(const Option Opt, StringRef Spelling, unsigned Index,
0076 const char *Value0, const Arg *BaseArg = nullptr);
0077 Arg(const Option Opt, StringRef Spelling, unsigned Index,
0078 const char *Value0, const char *Value1, const Arg *BaseArg = nullptr);
0079 Arg(const Arg &) = delete;
0080 Arg &operator=(const Arg &) = delete;
0081 ~Arg();
0082
0083 const Option &getOption() const { return Opt; }
0084
0085
0086
0087
0088
0089
0090
0091 StringRef getSpelling() const { return Spelling; }
0092
0093 unsigned getIndex() const { return Index; }
0094
0095
0096
0097
0098
0099 const Arg &getBaseArg() const {
0100 return BaseArg ? *BaseArg : *this;
0101 }
0102 Arg &getBaseArg() { return BaseArg ? const_cast<Arg &>(*BaseArg) : *this; }
0103 void setBaseArg(const Arg *BaseArg) { this->BaseArg = BaseArg; }
0104
0105
0106
0107 const Arg* getAlias() const { return Alias.get(); }
0108 void setAlias(std::unique_ptr<Arg> Alias) { this->Alias = std::move(Alias); }
0109
0110 bool getOwnsValues() const { return OwnsValues; }
0111 void setOwnsValues(bool Value) const { OwnsValues = Value; }
0112
0113 bool isClaimed() const { return getBaseArg().Claimed; }
0114 void claim() const { getBaseArg().Claimed = true; }
0115
0116 bool isIgnoredTargetSpecific() const {
0117 return getBaseArg().IgnoredTargetSpecific;
0118 }
0119 void ignoreTargetSpecific() {
0120 getBaseArg().IgnoredTargetSpecific = true;
0121 }
0122
0123 unsigned getNumValues() const { return Values.size(); }
0124
0125 const char *getValue(unsigned N = 0) const {
0126 return Values[N];
0127 }
0128
0129 SmallVectorImpl<const char *> &getValues() { return Values; }
0130 const SmallVectorImpl<const char *> &getValues() const { return Values; }
0131
0132 bool containsValue(StringRef Value) const {
0133 return llvm::is_contained(Values, Value);
0134 }
0135
0136
0137 void render(const ArgList &Args, ArgStringList &Output) const;
0138
0139
0140
0141
0142
0143
0144 void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
0145
0146 void print(raw_ostream &O) const;
0147 void dump() const;
0148
0149
0150
0151
0152
0153 std::string getAsString(const ArgList &Args) const;
0154 };
0155
0156 }
0157
0158 }
0159
0160 #endif