/// \returns this variable's value.
Optional<uint64_t> getValue() const { return Value; }
- /// Sets value of this numeric variable, if undefined. Triggers an assertion
- /// failure if the variable is actually defined.
- void setValue(uint64_t Value);
+ /// Sets value of this numeric variable to \p NewValue.
+ void setValue(uint64_t NewValue) { Value = NewValue; }
/// Clears value of this numeric variable, regardless of whether it is
/// currently defined or not.
- void clearValue();
+ void clearValue() { Value = None; }
/// \returns the line number where this variable is defined, if any, or None
/// if defined before input is parsed.
using namespace llvm;
-void FileCheckNumericVariable::setValue(uint64_t NewValue) {
- assert(!Value && "Overwriting numeric variable's value is not allowed");
- Value = NewValue;
-}
-
-void FileCheckNumericVariable::clearValue() {
- if (!Value)
- return;
- Value = None;
-}
-
Expected<uint64_t> FileCheckNumericVariableUse::eval() const {
Optional<uint64_t> Value = NumericVariable->getValue();
if (Value)
for (const auto &Substitution : Substitutions) {
// Substitute and check for failure (e.g. use of undefined variable).
Expected<std::string> Value = Substitution->getResult();
- if (!Value) {
- Context->LineVariable->clearValue();
+ if (!Value)
return Value.takeError();
- }
// Plop it into the regex at the adjusted offset.
TmpStr.insert(TmpStr.begin() + Substitution->getIndex() + InsertOffset,
// Match the newly constructed regex.
RegExToMatch = TmpStr;
- Context->LineVariable->clearValue();
}
SmallVector<StringRef, 4> MatchInfo;
55 BAD11: [[@LINE-1x]]
56 ERR11: line-count.txt:[[#@LINE-1]]:20: error: unexpected characters at end of expression 'x'
57
-58 CHECK: [[#@LINE]] CHECK
-59 CHECK: [[# @LINE]] CHECK
-60 CHECK: [[# @LINE ]] CHECK
-61
-62 CHECK: [[#@LINE-1]]
-63 CHECK: [[# @LINE-1]] CHECK
-64 CHECK: [[# @LINE -1]] CHECK
-65 CHECK: [[# @LINE - 1]] CHECK
-66 CHECK: [[# @LINE - 1 ]] CHECK
+; RUN: not FileCheck -check-prefix BAD12 -input-file %s %s 2>&1 \
+; RUN: | FileCheck -check-prefix ERR12 %s
+60
+61 BAD12: [[#@LINE-1]] NOT HERE
+62 ERR12: note: with "@LINE-1" equal to "60"
+63
+64 CHECK: [[#@LINE]] CHECK
+65 CHECK: [[# @LINE]] CHECK
+66 CHECK: [[# @LINE ]] CHECK
+67
+68 CHECK: [[#@LINE-1]]
+69 CHECK: [[# @LINE-1]] CHECK
+70 CHECK: [[# @LINE -1]] CHECK
+71 CHECK: [[# @LINE - 1]] CHECK
+72 CHECK: [[# @LINE - 1 ]] CHECK
; Numeric variable definition without spaces.
DEF NO SPC
-11
+10
CHECK-LABEL: DEF NO SPC
CHECK-NEXT: [[#VAR1:]]
CHECK-NEXT: [[# VAR1b :]]
CHECK-NEXT: [[# VAR1c : ]]
+; Numeric variable redefinition.
+REDEF NO SPC
+11
+CHECK-LABEL: REDEF
+CHECK-NEXT: [[#VAR1:]]
+
; Numeric expressions using variables defined on other lines without spaces.
USE NO SPC
11
TEST_F(FileCheckTest, NumericVariable) {
// Undefined variable: getValue and eval fail, error returned by eval holds
- // the name of the undefined variable and setValue does not trigger assert.
+ // the name of the undefined variable.
FileCheckNumericVariable FooVar = FileCheckNumericVariable("FOO", 1);
EXPECT_EQ("FOO", FooVar.getName());
FileCheckNumericVariableUse FooVarUse =
Expected<uint64_t> EvalResult = FooVarUse.eval();
EXPECT_FALSE(EvalResult);
expectUndefError("FOO", EvalResult.takeError());
+
FooVar.setValue(42);
// Defined variable: getValue and eval return value set.