[PATCH] D64231: [FileCheck] Simplify numeric variable interface

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 07:34:38 PDT 2019


thopre updated this revision to Diff 208182.
thopre marked 3 inline comments as done.
thopre added a comment.

Rebase on top of latest changes in patch series


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64231/new/

https://reviews.llvm.org/D64231

Files:
  llvm/include/llvm/Support/FileCheck.h
  llvm/lib/Support/FileCheck.cpp
  llvm/unittests/Support/FileCheckTest.cpp


Index: llvm/unittests/Support/FileCheckTest.cpp
===================================================================
--- llvm/unittests/Support/FileCheckTest.cpp
+++ llvm/unittests/Support/FileCheckTest.cpp
@@ -15,28 +15,23 @@
 class FileCheckTest : public ::testing::Test {};
 
 TEST_F(FileCheckTest, NumericVariable) {
-  // Undefined variable: getValue and clearValue fails, setValue works.
+  // Undefined variable: getValue fails, setValue does not trigger assert.
   FileCheckNumericVariable FooVar = FileCheckNumericVariable("FOO", 1);
   EXPECT_EQ("FOO", FooVar.getName());
   llvm::Optional<uint64_t> Value = FooVar.getValue();
   EXPECT_FALSE(Value);
-  EXPECT_TRUE(FooVar.clearValue());
-  EXPECT_FALSE(FooVar.setValue(42));
+  FooVar.clearValue();
+  FooVar.setValue(42);
 
-  // Defined variable: getValue returns value set, setValue fails.
-  Value = FooVar.getValue();
-  EXPECT_TRUE(Value);
-  EXPECT_EQ(42U, *Value);
-  EXPECT_TRUE(FooVar.setValue(43));
+  // Defined variable: getValue returns value set.
   Value = FooVar.getValue();
   EXPECT_TRUE(Value);
   EXPECT_EQ(42U, *Value);
 
-  // Clearing variable: getValue fails, clearValue again fails.
-  EXPECT_FALSE(FooVar.clearValue());
+  // Clearing variable: getValue fails.
+  FooVar.clearValue();
   Value = FooVar.getValue();
   EXPECT_FALSE(Value);
-  EXPECT_TRUE(FooVar.clearValue());
 }
 
 uint64_t doAdd(uint64_t OpL, uint64_t OpR) { return OpL + OpR; }
Index: llvm/lib/Support/FileCheck.cpp
===================================================================
--- llvm/lib/Support/FileCheck.cpp
+++ llvm/lib/Support/FileCheck.cpp
@@ -24,18 +24,15 @@
 
 using namespace llvm;
 
-bool FileCheckNumericVariable::setValue(uint64_t NewValue) {
-  if (Value)
-    return true;
+void FileCheckNumericVariable::setValue(uint64_t NewValue) {
+  assert(!Value && "Overwriting numeric variable's value");
   Value = NewValue;
-  return false;
 }
 
-bool FileCheckNumericVariable::clearValue() {
+void FileCheckNumericVariable::clearValue() {
   if (!Value)
-    return true;
+    return;
   Value = None;
-  return false;
 }
 
 Expected<uint64_t> FileCheckExpression::eval() const {
@@ -624,8 +621,7 @@
     if (MatchedValue.getAsInteger(10, Val))
       return FileCheckErrorDiagnostic::get(SM, MatchedValue,
                                            "Unable to represent numeric value");
-    if (DefinedNumericVariable->setValue(Val))
-      llvm_unreachable("Numeric variable redefined");
+    DefinedNumericVariable->setValue(Val);
   }
 
   // Like CHECK-NEXT, CHECK-EMPTY's match range is considered to start after
Index: llvm/include/llvm/Support/FileCheck.h
===================================================================
--- llvm/include/llvm/Support/FileCheck.h
+++ llvm/include/llvm/Support/FileCheck.h
@@ -71,13 +71,13 @@
   /// \returns this variable's value.
   Optional<uint64_t> getValue() const { return Value; }
 
-  /// Sets value of this numeric variable if not defined. \returns whether the
-  /// variable was already defined.
-  bool setValue(uint64_t Value);
+  /// Sets value of this numeric variable, if undefined. Triggers an assertion
+  /// failure if the variable is actually defined.
+  void setValue(uint64_t Value);
 
-  /// Clears value of this numeric variable. \returns whether the variable was
-  /// already undefined.
-  bool clearValue();
+  /// Clears value of this numeric variable, regardless of whether it is
+  /// currently defined or not.
+  void clearValue();
 
   /// \returns the line number where this variable's value becomes available.
   size_t getAvailLineNumber() { return AvailLineNumber; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64231.208182.patch
Type: text/x-patch
Size: 3624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190705/4e344424/attachment.bin>


More information about the llvm-commits mailing list