# Changeset View

Changeset View

# Standalone View

Standalone View

# llvm/include/llvm/Support/FileCheck.h

Show All 34 Lines | 26 | struct FileCheckRequest { | |||
---|---|---|---|---|---|

35 | bool Verbose = false; | 35 | bool Verbose = false; | ||

36 | bool VerboseVerbose = false; | 36 | bool VerboseVerbose = false; | ||

37 | }; | 37 | }; | ||

38 | 38 | | |||

39 | //===----------------------------------------------------------------------===// | 39 | //===----------------------------------------------------------------------===// | ||

40 | // Numeric expression handling code. | 40 | // Numeric expression handling code. | ||

41 | //===----------------------------------------------------------------------===// | 41 | //===----------------------------------------------------------------------===// | ||

42 | 42 | | |||

43 | class FileCheckNumExprVal; | ||||

44 | | ||||

43 | /// Bitfield representing the format a numeric expression value should be | 45 | /// Bitfield representing the format a numeric expression value should be | ||

44 | /// printed into for matching. Used to represent both explicit format | 46 | /// printed into for matching. Used to represent both explicit format | ||

45 | /// specifiers as well as implicit format from using numeric variables. | 47 | /// specifiers as well as implicit format from using numeric variables. | ||

46 | struct FileCheckNumExprFmt { | 48 | struct FileCheckNumExprFmt { | ||

49 | /// Value is a signed integer. | ||||

50 | unsigned Signed : 1; | ||||

47 | /// Value should be printed as hex number. | 51 | /// Value should be printed as hex number. | ||

48 | unsigned Hex : 1; | 52 | unsigned Hex : 1; | ||

49 | /// Value should be printed using upper case letters, only used for hex | 53 | /// Value should be printed using upper case letters, only used for hex | ||

50 | /// numbers. | 54 | /// numbers. | ||

51 | unsigned Cap : 1; | 55 | unsigned Cap : 1; | ||

52 | 56 | | |||

53 | /// When unset, denote absence of format and thus that all of the other | 57 | /// When unset, denote absence of format and thus that all of the other | ||

54 | /// fields are to be ignored. Used for implicit format of literals and empty | 58 | /// fields are to be ignored. Used for implicit format of literals and empty | ||

Show All 10 Lines | |||||

65 | } | 69 | } | ||

66 | 70 | | |||

67 | /// Return wildcard regexp StringRef to match any value in the format | 71 | /// Return wildcard regexp StringRef to match any value in the format | ||

68 | /// represented by this instance. | 72 | /// represented by this instance. | ||

69 | StringRef getWildcardRegex() const; | 73 | StringRef getWildcardRegex() const; | ||

70 | 74 | | |||

71 | /// Return the string representation of \p Value in the format represented by | 75 | /// Return the string representation of \p Value in the format represented by | ||

72 | /// this instance. | 76 | /// this instance. | ||

73 | std::string getMatchingString(uint64_t Value) const; | 77 | llvm::Optional<std::string> | ||

78 | getMatchingString(FileCheckNumExprVal &Value) const; | ||||

74 | 79 | | |||

75 | /// Return the value corresponding to string representation \p StrVal | 80 | /// Return the value corresponding to string representation \p StrVal | ||

76 | /// according to the matching format represented by this instance or nothing | 81 | /// according to the matching format represented by this instance or an | ||

77 | /// if \p StrVal does not correspond to a valid and representable value. | 82 | /// invalid value if \p StrVal does not correspond to a valid and | ||

78 | llvm::Optional<uint64_t> valueFromStringRepr(StringRef StrVal) const; | 83 | /// representable value. | ||

79 | 84 | FileCheckNumExprVal valueFromStringRepr(StringRef StrVal) const; | |||

80 | }; | 85 | }; | ||

81 | 86 | | |||

82 | /// Initializer for numeric expression without format. | 87 | /// Initializer for numeric expression without format. | ||

83 | const FileCheckNumExprFmt FmtNone = {0, 0, 0, 0}; | 88 | const FileCheckNumExprFmt FmtNone = {0, 0, 0, 0, 0}; | ||

84 | /// Initializer for numeric expression matched as unsigned value. | 89 | /// Initializer for numeric expression matched as unsigned value. | ||

85 | const FileCheckNumExprFmt FmtUnsigned = {0, 0, 1, 0}; | 90 | const FileCheckNumExprFmt FmtUnsigned = {0, 0, 0, 1, 0}; | ||

91 | /// Initializer for numeric expression matched as signed value. | ||||

92 | const FileCheckNumExprFmt FmtSigned = {1, 0, 0, 1, 0}; | ||||

86 | /// Initializer for numeric expression matched as lower case hex value. | 93 | /// Initializer for numeric expression matched as lower case hex value. | ||

87 | const FileCheckNumExprFmt FmtLowHex = {1, 0, 1, 0}; | 94 | const FileCheckNumExprFmt FmtLowHex = {0, 1, 0, 1, 0}; | ||

88 | /// Initializer for numeric expression matched as capital case hex value. | 95 | /// Initializer for numeric expression matched as capital case hex value. | ||

89 | const FileCheckNumExprFmt FmtCapHex = {1, 1, 1, 0}; | 96 | const FileCheckNumExprFmt FmtCapHex = {0, 1, 1, 1, 0}; | ||

97 | | ||||

98 | /// Class representing a numeric value. | ||||

99 | class FileCheckNumExprVal { | ||||

100 | private: | ||||

101 | union { | ||||

102 | int64_t SignedValue; | ||||

103 | uint64_t UnsignedValue; | ||||

104 | }; | ||||

105 | | ||||

106 | /// Whether value is signed (and thus is stored in SignedValue) or not (in | ||||

107 | /// which case it is stored in UnsignedValue). | ||||

108 | bool Signed; | ||||

109 | | ||||

110 | /// Whether this holds an actual value. Examples of where this would be | ||||

111 | /// false: | ||||

112 | /// - underflow or overflow of one of the binary operation in the expression; | ||||

113 | /// - unset variable's value. | ||||

114 | bool Valid; | ||||

115 | | ||||

116 | public: | ||||

117 | /// Constructor for an invalid value. | ||||

118 | FileCheckNumExprVal() : Valid(false) {} | ||||

119 | | ||||

120 | /// Constructor for a signed value. | ||||

121 | explicit FileCheckNumExprVal(int64_t Val) | ||||

122 | : SignedValue(Val), Signed(true), Valid(true) {} | ||||

123 | | ||||

124 | /// Constructor for an unsigned value. | ||||

125 | explicit FileCheckNumExprVal(uint64_t Val) | ||||

126 | : UnsignedValue(Val), Signed(false), Valid(true) {} | ||||

127 | | ||||

128 | /// Define equality to be true only if both values are valid and they have | ||||

129 | /// the same signedness and corresponding value. Tentative bit is ignored to | ||||

130 | /// allow the evaluation of a numeric expression using variables with | ||||

131 | /// tentative value to compare equal to a matched value. | ||||

132 | bool operator==(const FileCheckNumExprVal &other); | ||||

133 | bool operator!=(const FileCheckNumExprVal &other) { | ||||

134 | return !(*this == other); | ||||

135 | } | ||||

136 | | ||||

137 | bool isSigned() const { return Signed; } | ||||

138 | | ||||

139 | bool isValid() const { return Valid; } | ||||

140 | | ||||

141 | /// Return the signed value. Must only be called if value is signed in the | ||||

142 | /// first place. | ||||

143 | int64_t getSignedValue() const { | ||||

144 | assert(Signed); | ||||

145 | return SignedValue; | ||||

146 | } | ||||

147 | | ||||

148 | /// Return the unsigned value. Must only be called if value is unsigned in | ||||

149 | /// the first place. | ||||

150 | uint64_t getUnsignedValue() const { | ||||

151 | assert(!Signed); | ||||

152 | return UnsignedValue; | ||||

153 | } | ||||

154 | | ||||

155 | /// Convert value to a signed value, or mark value invalid if not possible | ||||

156 | /// (original value was not within range for a signed integer). | ||||

157 | void convertSigned(); | ||||

158 | | ||||

159 | /// Convert value to an unsigned value, or mark value invalid if not possible | ||||

160 | /// (original value was not within range for an unsigned integer). | ||||

161 | void convertUnsigned(); | ||||

162 | | ||||

163 | /// Return an invalid value in case of underflow or overflow. | ||||

164 | friend FileCheckNumExprVal operator+(const FileCheckNumExprVal &lhs, | ||||

165 | const FileCheckNumExprVal &rhs); | ||||

166 | friend FileCheckNumExprVal operator-(const FileCheckNumExprVal &lhs, | ||||

167 | const FileCheckNumExprVal &rhs); | ||||

168 | }; | ||||

90 | 169 | | |||

91 | /// Base class representing the AST of a given numeric expression. | 170 | /// Base class representing the AST of a given numeric expression. | ||

92 | class FileCheckNumExprAST { | 171 | class FileCheckNumExprAST { | ||

93 | public: | 172 | public: | ||

94 | virtual ~FileCheckNumExprAST() = default; | 173 | virtual ~FileCheckNumExprAST() = default; | ||

95 | 174 | | |||

96 | /// Evaluate the value of the expression represented by this AST. | 175 | /// Evaluate the value of the expression represented by this AST. | ||

97 | virtual llvm::Optional<uint64_t> eval() const = 0; | 176 | virtual FileCheckNumExprVal eval() const = 0; | ||

98 | 177 | | |||

99 | /// Return implicit format of this AST, FmtConflict if implicit formats of | 178 | /// Return implicit format of this AST, FmtConflict if implicit formats of | ||

100 | /// the AST's components conflict and Fmt none if the AST has no implicit | 179 | /// the AST's components conflict and Fmt none if the AST has no implicit | ||

101 | /// format (e.g. AST is made of a single literal). | 180 | /// format (e.g. AST is made of a single literal). | ||

102 | virtual FileCheckNumExprFmt getImplicitFmt() const = 0; | 181 | virtual FileCheckNumExprFmt getImplicitFmt() const = 0; | ||

103 | 182 | | |||

104 | /// Append names of undefined variables used in the expression represented by | 183 | /// Append names of undefined variables used in the expression represented by | ||

105 | /// this AST. Must be overriden in any subclass representing an expression | 184 | /// this AST. Must be overriden in any subclass representing an expression | ||

106 | /// that can contain a variable. | 185 | /// that can contain a variable. | ||

107 | virtual void | 186 | virtual void | ||

108 | appendUndefVarNames(std::vector<StringRef> &UndefVarNames) const {} | 187 | appendUndefVarNames(std::vector<StringRef> &UndefVarNames) const {} | ||

109 | }; | 188 | }; | ||

110 | 189 | | |||

111 | /// Class representing a literal in the AST of a numeric expression. | 190 | /// Class representing a literal in the AST of a numeric expression. | ||

112 | class FileCheckNumExprLiteral : public FileCheckNumExprAST { | 191 | class FileCheckNumExprLiteral : public FileCheckNumExprAST { | ||

113 | private: | 192 | private: | ||

114 | /// Actual value of the literal. | 193 | /// Actual value of the literal. | ||

115 | uint64_t Value; | 194 | FileCheckNumExprVal Value; | ||

116 | 195 | | |||

117 | public: | 196 | public: | ||

197 | /// Constructor for a signed literal. | ||||

198 | FileCheckNumExprLiteral(int64_t Val) : Value(Val) {} | ||||

199 | | ||||

118 | /// Constructor for an unsigned literal. | 200 | /// Constructor for an unsigned literal. | ||

119 | FileCheckNumExprLiteral(uint64_t Val) : Value(Val) {} | 201 | FileCheckNumExprLiteral(uint64_t Val) : Value(Val) {} | ||

120 | 202 | | |||

121 | /// Evaluate the value of the expression represented by this AST. Therefore, | 203 | /// Evaluate the value of the expression represented by this AST. Therefore, | ||

122 | /// return the literal's value. | 204 | /// return the literal's value. | ||

123 | llvm::Optional<uint64_t> eval() const { return Value; } | 205 | FileCheckNumExprVal eval() const { return Value; } | ||

124 | 206 | | |||

125 | /// Return implicit format of this AST, therefore FmtNone. | 207 | /// Return implicit format of this AST, therefore FmtNone. | ||

126 | FileCheckNumExprFmt getImplicitFmt() const { return FmtNone; } | 208 | FileCheckNumExprFmt getImplicitFmt() const { return FmtNone; } | ||

127 | }; | 209 | }; | ||

128 | 210 | | |||

129 | /// Class representing a numeric expression and its matching format. | 211 | /// Class representing a numeric expression and its matching format. | ||

130 | class FileCheckNumExpr { | 212 | class FileCheckNumExpr { | ||

131 | private: | 213 | private: | ||

Show All 32 Lines | 244 | private: | |||

164 | StringRef Name; | 246 | StringRef Name; | ||

165 | 247 | | |||

166 | /// Pointer to numeric expression defining this numeric variable. Only null | 248 | /// Pointer to numeric expression defining this numeric variable. Only null | ||

167 | /// for pseudo variable whose value is known at parse time (e.g. @LINE pseudo | 249 | /// for pseudo variable whose value is known at parse time (e.g. @LINE pseudo | ||

168 | /// variable). If numeric expression is empty NumExpr points to a | 250 | /// variable). If numeric expression is empty NumExpr points to a | ||

169 | /// FileCheckNumExpr with a null AST. | 251 | /// FileCheckNumExpr with a null AST. | ||

170 | std::shared_ptr<FileCheckNumExpr> NumExpr; | 252 | std::shared_ptr<FileCheckNumExpr> NumExpr; | ||

171 | 253 | | |||

172 | /// Whether variable is defined and thus Value is set. | 254 | /// Value of numeric variable. | ||

173 | bool Defined; | 255 | FileCheckNumExprVal Value; | ||

174 | | ||||

175 | /// Value of numeric variable if defined. | | |||

176 | uint64_t Value; | | |||

177 | 256 | | |||

178 | /// Line number where this variable is defined. Used to determine whether a | 257 | /// Line number where this variable is defined. Used to determine whether a | ||

179 | /// variable is defined on the same line as a given use. | 258 | /// variable is defined on the same line as a given use. | ||

180 | unsigned DefLineNumber; | 259 | unsigned DefLineNumber; | ||

181 | 260 | | |||

182 | public: | 261 | public: | ||

183 | /// Constructor for a variable \p Name defined at line \p DefLineNumber to | 262 | /// Constructor for a variable \p Name defined at line \p DefLineNumber to | ||

184 | /// the numeric expression represented by NumExpr. | 263 | /// the numeric expression represented by NumExpr. | ||

185 | FileCheckNumExprVar(StringRef Name, std::shared_ptr<FileCheckNumExpr> NumExpr, | 264 | FileCheckNumExprVar(StringRef Name, std::shared_ptr<FileCheckNumExpr> NumExpr, | ||

186 | unsigned DefLineNumber) | 265 | unsigned DefLineNumber) | ||

187 | : Name(Name), NumExpr(NumExpr), Defined(false), | 266 | : Name(Name), NumExpr(NumExpr), DefLineNumber(DefLineNumber) { | ||

188 | DefLineNumber(DefLineNumber) {} | 267 | Value = FileCheckNumExprVal(); | ||

268 | } | ||||

189 | 269 | | |||

190 | /// Constructor for numeric variable \p Name with a known \p Value at parse | 270 | /// Constructor for numeric variable \p Name with a known \p Value at parse | ||

191 | /// time (e.g. the @LINE numeric variable). | 271 | /// time (e.g. the @LINE numeric variable). | ||

192 | explicit FileCheckNumExprVar(StringRef Name, uint64_t Value) | 272 | FileCheckNumExprVar(StringRef Name, FileCheckNumExprVal &Value) | ||

193 | : Name(Name), NumExpr(nullptr), Defined(true), Value(Value) {} | 273 | : Name(Name), NumExpr(nullptr), Value(Value) {} | ||

194 | 274 | | |||

195 | /// Return name of that numeric variable. | 275 | /// Return name of that numeric variable. | ||

196 | StringRef getName() const { return Name; } | 276 | StringRef getName() const { return Name; } | ||

197 | 277 | | |||

198 | /// Return numeric expression associated with this numeric variable. | 278 | /// Return numeric expression associated with this numeric variable. | ||

199 | std::shared_ptr<FileCheckNumExpr> getNumExpr() const { return NumExpr; } | 279 | std::shared_ptr<FileCheckNumExpr> getNumExpr() const { return NumExpr; } | ||

200 | 280 | | |||

201 | /// Evaluate the value of the expression represented by this AST. Therefore, | 281 | /// Evaluate the value of the expression represented by this AST. Therefore, | ||

202 | /// return this variable's value or the value of its associated numeric | 282 | /// return this variable's value or the value of its associated numeric | ||

203 | /// expression if any. | 283 | /// expression if any. | ||

204 | llvm::Optional<uint64_t> eval() const; | 284 | FileCheckNumExprVal eval() const; | ||

205 | 285 | | |||

206 | /// Return whether this variable's value is known at match time, when | 286 | /// Return whether this variable's value is known at match time, when | ||

207 | /// performing the substitutions. | 287 | /// performing the substitutions. | ||

208 | bool isMatchTimeKnown() const; | 288 | bool isMatchTimeKnown() const; | ||

209 | 289 | | |||

210 | /// Return implicit format of this numeric variable. | 290 | /// Return implicit format of this numeric variable. | ||

211 | FileCheckNumExprFmt getImplicitFmt() const; | 291 | FileCheckNumExprFmt getImplicitFmt() const; | ||

212 | 292 | | |||

213 | /// Append numeric variable's name to UndefVarNames if undefined. | 293 | /// Append numeric variable's name to UndefVarNames if undefined. | ||

214 | void appendUndefVarNames(std::vector<StringRef> &UndefVarNames) const; | 294 | void appendUndefVarNames(std::vector<StringRef> &UndefVarNames) const; | ||

215 | 295 | | |||

216 | /// Set value of this numeric variable if not defined. Return whether | 296 | /// Set value of this numeric variable if not defined. Return whether | ||

217 | /// variable was already defined. | 297 | /// variable was already defined. | ||

218 | bool setValue(uint64_t Value); | 298 | bool setValue(FileCheckNumExprVal Value); | ||

219 | 299 | | |||

220 | /// Clear value of this numeric variable. Return whether value was already | 300 | /// Clear value of this numeric variable. Return whether value was already | ||

221 | /// undefined. | 301 | /// undefined. | ||

222 | bool clearValue(); | 302 | bool clearValue(); | ||

223 | 303 | | |||

224 | /// Return line number where this variable is defined. | 304 | /// Return line number where this variable is defined. | ||

225 | unsigned getDefLineNumber() { return DefLineNumber; } | 305 | unsigned getDefLineNumber() { return DefLineNumber; } | ||

226 | }; | 306 | }; | ||

227 | 307 | | |||

228 | /// Type of functions evaluating a given binary operation. | 308 | /// Type of functions evaluating a given binary operation. | ||

229 | using binop_eval_t = uint64_t (*)(uint64_t, uint64_t); | 309 | using binop_eval_t = FileCheckNumExprVal (*)(const FileCheckNumExprVal &, | ||

310 | const FileCheckNumExprVal &); | ||||

230 | 311 | | |||

231 | /// Class representing a single binary operation in the AST of a numeric | 312 | /// Class representing a single binary operation in the AST of a numeric | ||

232 | /// expression. | 313 | /// expression. | ||

233 | class FileCheckASTBinop : public FileCheckNumExprAST { | 314 | class FileCheckASTBinop : public FileCheckNumExprAST { | ||

234 | private: | 315 | private: | ||

235 | /// Left operand. | 316 | /// Left operand. | ||

236 | std::shared_ptr<FileCheckNumExprAST> Opl; | 317 | std::shared_ptr<FileCheckNumExprAST> Opl; | ||

237 | 318 | | |||

238 | /// Right operand. | 319 | /// Right operand. | ||

239 | std::shared_ptr<FileCheckNumExprAST> Opr; | 320 | std::shared_ptr<FileCheckNumExprAST> Opr; | ||

240 | 321 | | |||

241 | /// Pointer to function that can evaluate this binary operation. | 322 | /// Pointer to function that can evaluate this binary operation. | ||

242 | binop_eval_t EvalBinop; | 323 | binop_eval_t EvalBinop; | ||

243 | 324 | | |||

244 | public: | 325 | public: | ||

245 | FileCheckASTBinop(binop_eval_t EvalBinop, | 326 | FileCheckASTBinop(binop_eval_t EvalBinop, | ||

246 | std::shared_ptr<FileCheckNumExprAST> OperandLeft, | 327 | std::shared_ptr<FileCheckNumExprAST> OperandLeft, | ||

247 | std::shared_ptr<FileCheckNumExprAST> OperandRight) | 328 | std::shared_ptr<FileCheckNumExprAST> OperandRight) | ||

248 | : Opl(OperandLeft), Opr(OperandRight), EvalBinop(EvalBinop) {} | 329 | : Opl(OperandLeft), Opr(OperandRight), EvalBinop(EvalBinop) {} | ||

249 | 330 | | |||

250 | /// Evaluate the value of the binary operation represented by this AST. Uses | 331 | /// Evaluate the value of the binary operation represented by this AST. Uses | ||

251 | /// EvalBinop to perform the binary operation on the values of recursively | 332 | /// EvalBinop to perform the binary operation on the values of recursively | ||

252 | /// evaluating the left and right operands. | 333 | /// evaluating the left and right operands. | ||

253 | llvm::Optional<uint64_t> eval() const; | 334 | FileCheckNumExprVal eval() const; | ||

254 | 335 | | |||

255 | /// Return implicit format of this AST, FmtConflict if implicit formats of | 336 | /// Return implicit format of this AST, FmtConflict if implicit formats of | ||

256 | /// the AST's components conflict and Fmt none if the AST has no implicit | 337 | /// the AST's components conflict and Fmt none if the AST has no implicit | ||

257 | /// format (e.g. AST is made of a single literal). | 338 | /// format (e.g. AST is made of a single literal). | ||

258 | FileCheckNumExprFmt getImplicitFmt() const; | 339 | FileCheckNumExprFmt getImplicitFmt() const; | ||

259 | 340 | | |||

260 | /// Append names of undefined variables used in any of the operands of this | 341 | /// Append names of undefined variables used in any of the operands of this | ||

261 | /// binary operation. | 342 | /// binary operation. | ||

▲ Show 20 Lines • Show All 395 Lines • Show Last 20 Lines |