llvm.org GIT mirror llvm / c974c7b
Revert "[FileCheck] Simplify numeric variable interface" This reverts commit 096600a4b073dd94a366cc8e57bff93c34ff6966. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365251 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao 3 months ago
3 changed file(s) with 31 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
6868 /// \returns this variable's value.
6969 Optional getValue() const { return Value; }
7070
71 /// Sets value of this numeric variable, if undefined. Triggers an assertion
72 /// failure if the variable is actually defined.
73 void setValue(uint64_t Value);
74
75 /// Clears value of this numeric variable, regardless of whether it is
76 /// currently defined or not.
77 void clearValue();
71 /// Sets value of this numeric variable if not defined. \returns whether the
72 /// variable was already defined.
73 bool setValue(uint64_t Value);
74
75 /// Clears value of this numeric variable. \returns whether the variable was
76 /// already undefined.
77 bool clearValue();
7878
7979 /// \returns the line number where this variable is defined.
8080 size_t getDefLineNumber() { return DefLineNumber; }
2323
2424 using namespace llvm;
2525
26 void FileCheckNumericVariable::setValue(uint64_t NewValue) {
27 assert(!Value && "Overwriting numeric variable's value is not allowed");
26 bool FileCheckNumericVariable::setValue(uint64_t NewValue) {
27 if (Value)
28 return true;
2829 Value = NewValue;
29 }
30
31 void FileCheckNumericVariable::clearValue() {
30 return false;
31 }
32
33 bool FileCheckNumericVariable::clearValue() {
3234 if (!Value)
33 return;
35 return true;
3436 Value = None;
37 return false;
3538 }
3639
3740 Expected FileCheckExpression::eval() const {
619622 if (MatchedValue.getAsInteger(10, Val))
620623 return FileCheckErrorDiagnostic::get(SM, MatchedValue,
621624 "Unable to represent numeric value");
622 DefinedNumericVariable->setValue(Val);
625 if (DefinedNumericVariable->setValue(Val))
626 llvm_unreachable("Numeric variable redefined");
623627 }
624628
625629 // Like CHECK-NEXT, CHECK-EMPTY's match range is considered to start after
1414 class FileCheckTest : public ::testing::Test {};
1515
1616 TEST_F(FileCheckTest, NumericVariable) {
17 // Undefined variable: getValue fails, setValue does not trigger assert.
17 // Undefined variable: getValue and clearValue fails, setValue works.
1818 FileCheckNumericVariable FooVar = FileCheckNumericVariable(1, "FOO");
1919 EXPECT_EQ("FOO", FooVar.getName());
2020 llvm::Optional Value = FooVar.getValue();
2121 EXPECT_FALSE(Value);
22 FooVar.clearValue();
23 FooVar.setValue(42);
24
25 // Defined variable: getValue returns value set.
22 EXPECT_TRUE(FooVar.clearValue());
23 EXPECT_FALSE(FooVar.setValue(42));
24
25 // Defined variable: getValue returns value set, setValue fails.
2626 Value = FooVar.getValue();
2727 EXPECT_TRUE(Value);
2828 EXPECT_EQ(42U, *Value);
29
30 // Clearing variable: getValue fails.
31 FooVar.clearValue();
29 EXPECT_TRUE(FooVar.setValue(43));
30 Value = FooVar.getValue();
31 EXPECT_TRUE(Value);
32 EXPECT_EQ(42U, *Value);
33
34 // Clearing variable: getValue fails, clearValue again fails.
35 EXPECT_FALSE(FooVar.clearValue());
3236 Value = FooVar.getValue();
3337 EXPECT_FALSE(Value);
38 EXPECT_TRUE(FooVar.clearValue());
3439 }
3540
3641 uint64_t doAdd(uint64_t OpL, uint64_t OpR) { return OpL + OpR; }