@@ -78,8 +78,7 @@ Expected<std::string> ExpressionFormat::getWildcardRegex() const {
78
78
}
79
79
80
80
Expected<std::string>
81
- ExpressionFormat::getMatchingString (ExpressionValue IntegerValue) const {
82
- APInt IntValue = IntegerValue.getAPIntValue ();
81
+ ExpressionFormat::getMatchingString (APInt IntValue) const {
83
82
if (Value != Kind::Signed && IntValue.isNegative ())
84
83
return make_error<OverflowError>();
85
84
@@ -135,7 +134,7 @@ static APInt toSigned(APInt AbsVal, bool Negative) {
135
134
return Result;
136
135
}
137
136
138
- Expected<ExpressionValue >
137
+ Expected<APInt >
139
138
ExpressionFormat::valueFromStringRepr (StringRef StrVal,
140
139
const SourceMgr &SM) const {
141
140
bool ValueIsSigned = Value == Kind::Signed;
@@ -155,76 +154,59 @@ ExpressionFormat::valueFromStringRepr(StringRef StrVal,
155
154
if (ParseFailure)
156
155
return ErrorDiagnostic::get (SM, StrVal,
157
156
" unable to represent numeric value" );
158
- return ExpressionValue ( toSigned (ResultValue, Negative) );
157
+ return toSigned (ResultValue, Negative);
159
158
}
160
159
161
- Expected<ExpressionValue> llvm::exprAdd (const ExpressionValue &LeftOperand,
162
- const ExpressionValue &RightOperand,
163
- bool &Overflow) {
164
- APInt Result = LeftOperand.getAPIntValue ().sadd_ov (
165
- RightOperand.getAPIntValue (), Overflow);
166
- return ExpressionValue (Result);
160
+ Expected<APInt> llvm::exprAdd (const APInt &LeftOperand,
161
+ const APInt &RightOperand, bool &Overflow) {
162
+ return LeftOperand.sadd_ov (RightOperand, Overflow);
167
163
}
168
164
169
- Expected<ExpressionValue> llvm::exprSub (const ExpressionValue &LeftOperand,
170
- const ExpressionValue &RightOperand,
171
- bool &Overflow) {
172
- APInt Result = LeftOperand.getAPIntValue ().ssub_ov (
173
- RightOperand.getAPIntValue (), Overflow);
174
- return ExpressionValue (Result);
165
+ Expected<APInt> llvm::exprSub (const APInt &LeftOperand,
166
+ const APInt &RightOperand, bool &Overflow) {
167
+ return LeftOperand.ssub_ov (RightOperand, Overflow);
175
168
}
176
169
177
- Expected<ExpressionValue> llvm::exprMul (const ExpressionValue &LeftOperand,
178
- const ExpressionValue &RightOperand,
179
- bool &Overflow) {
180
- APInt Result = LeftOperand.getAPIntValue ().smul_ov (
181
- RightOperand.getAPIntValue (), Overflow);
182
- return ExpressionValue (Result);
170
+ Expected<APInt> llvm::exprMul (const APInt &LeftOperand,
171
+ const APInt &RightOperand, bool &Overflow) {
172
+ return LeftOperand.smul_ov (RightOperand, Overflow);
183
173
}
184
174
185
- Expected<ExpressionValue> llvm::exprDiv (const ExpressionValue &LeftOperand,
186
- const ExpressionValue &RightOperand,
187
- bool &Overflow) {
175
+ Expected<APInt> llvm::exprDiv (const APInt &LeftOperand,
176
+ const APInt &RightOperand, bool &Overflow) {
188
177
// Check for division by zero.
189
- if (RightOperand.getAPIntValue (). isZero ())
178
+ if (RightOperand.isZero ())
190
179
return make_error<OverflowError>();
191
180
192
- APInt Result = LeftOperand.getAPIntValue ().sdiv_ov (
193
- RightOperand.getAPIntValue (), Overflow);
194
- return ExpressionValue (Result);
181
+ return LeftOperand.sdiv_ov (RightOperand, Overflow);
195
182
}
196
183
197
- Expected<ExpressionValue> llvm::exprMax (const ExpressionValue &LeftOperand,
198
- const ExpressionValue &RightOperand,
199
- bool &Overflow) {
184
+ Expected<APInt> llvm::exprMax (const APInt &LeftOperand,
185
+ const APInt &RightOperand, bool &Overflow) {
200
186
Overflow = false ;
201
- return LeftOperand.getAPIntValue ().slt (RightOperand.getAPIntValue ())
202
- ? RightOperand
203
- : LeftOperand;
187
+ return LeftOperand.slt (RightOperand) ? RightOperand : LeftOperand;
204
188
}
205
189
206
- Expected<ExpressionValue> llvm::exprMin (const ExpressionValue &LeftOperand,
207
- const ExpressionValue &RightOperand,
208
- bool &Overflow) {
190
+ Expected<APInt> llvm::exprMin (const APInt &LeftOperand,
191
+ const APInt &RightOperand, bool &Overflow) {
209
192
Overflow = false ;
210
- if (cantFail (exprMax (LeftOperand, RightOperand, Overflow)).getAPIntValue () ==
211
- LeftOperand.getAPIntValue ())
193
+ if (cantFail (exprMax (LeftOperand, RightOperand, Overflow)) == LeftOperand)
212
194
return RightOperand;
213
195
214
196
return LeftOperand;
215
197
}
216
198
217
- Expected<ExpressionValue > NumericVariableUse::eval () const {
218
- std::optional<ExpressionValue > Value = Variable->getValue ();
199
+ Expected<APInt > NumericVariableUse::eval () const {
200
+ std::optional<APInt > Value = Variable->getValue ();
219
201
if (Value)
220
202
return *Value;
221
203
222
204
return make_error<UndefVarError>(getExpressionStr ());
223
205
}
224
206
225
- Expected<ExpressionValue > BinaryOperation::eval () const {
226
- Expected<ExpressionValue > MaybeLeftOp = LeftOperand->eval ();
227
- Expected<ExpressionValue > MaybeRightOp = RightOperand->eval ();
207
+ Expected<APInt > BinaryOperation::eval () const {
208
+ Expected<APInt > MaybeLeftOp = LeftOperand->eval ();
209
+ Expected<APInt > MaybeRightOp = RightOperand->eval ();
228
210
229
211
// Bubble up any error (e.g. undefined variables) in the recursive
230
212
// evaluation.
@@ -237,8 +219,8 @@ Expected<ExpressionValue> BinaryOperation::eval() const {
237
219
return std::move (Err);
238
220
}
239
221
240
- APInt LeftOp = MaybeLeftOp-> getAPIntValue () ;
241
- APInt RightOp = MaybeRightOp-> getAPIntValue () ;
222
+ APInt LeftOp = * MaybeLeftOp;
223
+ APInt RightOp = * MaybeRightOp;
242
224
bool Overflow;
243
225
// Ensure both operands have the same bitwidth.
244
226
unsigned LeftBitWidth = LeftOp.getBitWidth ();
@@ -247,8 +229,7 @@ Expected<ExpressionValue> BinaryOperation::eval() const {
247
229
LeftOp = LeftOp.sext (NewBitWidth);
248
230
RightOp = RightOp.sext (NewBitWidth);
249
231
do {
250
- Expected<ExpressionValue> MaybeResult =
251
- EvalBinop (ExpressionValue (LeftOp), ExpressionValue (RightOp), Overflow);
232
+ Expected<APInt> MaybeResult = EvalBinop (LeftOp, RightOp, Overflow);
252
233
if (!MaybeResult)
253
234
return MaybeResult.takeError ();
254
235
@@ -291,8 +272,7 @@ BinaryOperation::getImplicitFormat(const SourceMgr &SM) const {
291
272
Expected<std::string> NumericSubstitution::getResult () const {
292
273
assert (ExpressionPointer->getAST () != nullptr &&
293
274
" Substituting empty expression" );
294
- Expected<ExpressionValue> EvaluatedValue =
295
- ExpressionPointer->getAST ()->eval ();
275
+ Expected<APInt> EvaluatedValue = ExpressionPointer->getAST ()->eval ();
296
276
if (!EvaluatedValue)
297
277
return EvaluatedValue.takeError ();
298
278
ExpressionFormat Format = ExpressionPointer->getFormat ();
@@ -1117,7 +1097,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer,
1117
1097
TmpStr = RegExStr;
1118
1098
if (LineNumber)
1119
1099
Context->LineVariable ->setValue (
1120
- ExpressionValue ( APInt (sizeof (*LineNumber) * 8 , *LineNumber) ));
1100
+ APInt (sizeof (*LineNumber) * 8 , *LineNumber));
1121
1101
1122
1102
size_t InsertOffset = 0 ;
1123
1103
// Substitute all string variables and expressions whose values are only
@@ -1196,8 +1176,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer,
1196
1176
1197
1177
StringRef MatchedValue = MatchInfo[CaptureParenGroup];
1198
1178
ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat ();
1199
- Expected<ExpressionValue> Value =
1200
- Format.valueFromStringRepr (MatchedValue, SM);
1179
+ Expected<APInt> Value = Format.valueFromStringRepr (MatchedValue, SM);
1201
1180
if (!Value)
1202
1181
return MatchResult (TheMatch, Value.takeError ());
1203
1182
DefinedNumericVariable->setValue (*Value, MatchedValue);
@@ -2583,7 +2562,7 @@ Error FileCheckPatternContext::defineCmdlineVariables(
2583
2562
// to, since the expression of a command-line variable definition should
2584
2563
// only use variables defined earlier on the command-line. If not, this
2585
2564
// is an error and we report it.
2586
- Expected<ExpressionValue > Value = Expression->getAST ()->eval ();
2565
+ Expected<APInt > Value = Expression->getAST ()->eval ();
2587
2566
if (!Value) {
2588
2567
Errs = joinErrors (std::move (Errs), Value.takeError ());
2589
2568
continue ;
0 commit comments