mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[FileCheck] Simplify numeric variable interface
Summary: This patch simplifies 2 aspects in the FileCheckNumericVariable code. First, setValue() method is turned into a void function since being called only on undefined variable is an invariant and is now asserted rather than returned. This remove the assert from the callers. Second, clearValue() method is also turned into a void function since the only caller does not check its return value since it may be trying to clear the value of variable that is already cleared without this being noteworthy. Reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk Subscribers: JonChesterfield, rogfer01, hfinkel, kristina, rnk, tra, arichardson, grimar, dblaikie, probinson, llvm-commits, hiraditya Tags: #llvm Differential Revision: https://reviews.llvm.org/D64231 > llvm-svn: 365249 llvm-svn: 365625
This commit is contained in:
parent
8551271d7a
commit
d63347385f
@ -69,13 +69,13 @@ public:
|
|||||||
/// \returns this variable's value.
|
/// \returns this variable's value.
|
||||||
Optional<uint64_t> getValue() const { return Value; }
|
Optional<uint64_t> getValue() const { return Value; }
|
||||||
|
|
||||||
/// Sets value of this numeric variable if not defined. \returns whether the
|
/// Sets value of this numeric variable, if undefined. Triggers an assertion
|
||||||
/// variable was already defined.
|
/// failure if the variable is actually defined.
|
||||||
bool setValue(uint64_t Value);
|
void setValue(uint64_t Value);
|
||||||
|
|
||||||
/// Clears value of this numeric variable. \returns whether the variable was
|
/// Clears value of this numeric variable, regardless of whether it is
|
||||||
/// already undefined.
|
/// currently defined or not.
|
||||||
bool clearValue();
|
void clearValue();
|
||||||
|
|
||||||
/// \returns the line number where this variable is defined.
|
/// \returns the line number where this variable is defined.
|
||||||
size_t getDefLineNumber() { return DefLineNumber; }
|
size_t getDefLineNumber() { return DefLineNumber; }
|
||||||
|
@ -24,18 +24,15 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
bool FileCheckNumericVariable::setValue(uint64_t NewValue) {
|
void FileCheckNumericVariable::setValue(uint64_t NewValue) {
|
||||||
if (Value)
|
assert(!Value && "Overwriting numeric variable's value is not allowed");
|
||||||
return true;
|
|
||||||
Value = NewValue;
|
Value = NewValue;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileCheckNumericVariable::clearValue() {
|
void FileCheckNumericVariable::clearValue() {
|
||||||
if (!Value)
|
if (!Value)
|
||||||
return true;
|
return;
|
||||||
Value = None;
|
Value = None;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<uint64_t> FileCheckExpression::eval() const {
|
Expected<uint64_t> FileCheckExpression::eval() const {
|
||||||
@ -625,8 +622,7 @@ Expected<size_t> FileCheckPattern::match(StringRef Buffer, size_t &MatchLen,
|
|||||||
if (MatchedValue.getAsInteger(10, Val))
|
if (MatchedValue.getAsInteger(10, Val))
|
||||||
return FileCheckErrorDiagnostic::get(SM, MatchedValue,
|
return FileCheckErrorDiagnostic::get(SM, MatchedValue,
|
||||||
"Unable to represent numeric value");
|
"Unable to represent numeric value");
|
||||||
if (DefinedNumericVariable->setValue(Val))
|
DefinedNumericVariable->setValue(Val);
|
||||||
llvm_unreachable("Numeric variable redefined");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like CHECK-NEXT, CHECK-EMPTY's match range is considered to start after
|
// Like CHECK-NEXT, CHECK-EMPTY's match range is considered to start after
|
||||||
|
@ -15,28 +15,23 @@ namespace {
|
|||||||
class FileCheckTest : public ::testing::Test {};
|
class FileCheckTest : public ::testing::Test {};
|
||||||
|
|
||||||
TEST_F(FileCheckTest, NumericVariable) {
|
TEST_F(FileCheckTest, NumericVariable) {
|
||||||
// Undefined variable: getValue and clearValue fails, setValue works.
|
// Undefined variable: getValue fails, setValue does not trigger assert.
|
||||||
FileCheckNumericVariable FooVar = FileCheckNumericVariable(1, "FOO");
|
FileCheckNumericVariable FooVar = FileCheckNumericVariable(1, "FOO");
|
||||||
EXPECT_EQ("FOO", FooVar.getName());
|
EXPECT_EQ("FOO", FooVar.getName());
|
||||||
llvm::Optional<uint64_t> Value = FooVar.getValue();
|
llvm::Optional<uint64_t> Value = FooVar.getValue();
|
||||||
EXPECT_FALSE(Value);
|
EXPECT_FALSE(Value);
|
||||||
EXPECT_TRUE(FooVar.clearValue());
|
FooVar.clearValue();
|
||||||
EXPECT_FALSE(FooVar.setValue(42));
|
FooVar.setValue(42);
|
||||||
|
|
||||||
// Defined variable: getValue returns value set, setValue fails.
|
// Defined variable: getValue returns value set.
|
||||||
Value = FooVar.getValue();
|
|
||||||
EXPECT_TRUE(Value);
|
|
||||||
EXPECT_EQ(42U, *Value);
|
|
||||||
EXPECT_TRUE(FooVar.setValue(43));
|
|
||||||
Value = FooVar.getValue();
|
Value = FooVar.getValue();
|
||||||
EXPECT_TRUE(Value);
|
EXPECT_TRUE(Value);
|
||||||
EXPECT_EQ(42U, *Value);
|
EXPECT_EQ(42U, *Value);
|
||||||
|
|
||||||
// Clearing variable: getValue fails, clearValue again fails.
|
// Clearing variable: getValue fails.
|
||||||
EXPECT_FALSE(FooVar.clearValue());
|
FooVar.clearValue();
|
||||||
Value = FooVar.getValue();
|
Value = FooVar.getValue();
|
||||||
EXPECT_FALSE(Value);
|
EXPECT_FALSE(Value);
|
||||||
EXPECT_TRUE(FooVar.clearValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t doAdd(uint64_t OpL, uint64_t OpR) { return OpL + OpR; }
|
uint64_t doAdd(uint64_t OpL, uint64_t OpR) { return OpL + OpR; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user