Skip to content

Commit 5ecb880

Browse files
author
Thomas Preud'homme
committed
Revert "FileCheck [8/12]: Define numeric var from expr"
This reverts commit 1b05977. llvm-svn: 366872
1 parent 75299de commit 5ecb880

File tree

7 files changed

+251
-475
lines changed

7 files changed

+251
-475
lines changed

llvm/docs/CommandGuide/FileCheck.rst

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ and from the command line.
107107
Sets a filecheck pattern variable ``VAR`` with value ``VALUE`` that can be
108108
used in ``CHECK:`` lines.
109109

110-
.. option:: -D#<NUMVAR>=<NUMERIC EXPRESSION>
110+
.. option:: -D#<NUMVAR>=<VALUE EXPRESSION>
111111

112112
Sets a filecheck numeric variable ``NUMVAR`` to the result of evaluating
113-
``<NUMERIC EXPRESSION>`` that can be used in ``CHECK:`` lines. See section
114-
``FileCheck Numeric Variables and Expressions`` for details on supported
115-
numeric expressions.
113+
``<VALUE EXPRESSION>`` that can be used in ``CHECK:`` lines. See section
114+
``FileCheck Numeric Variables and Expressions`` for details on the format
115+
and meaning of ``<VALUE EXPRESSION>``.
116116

117117
.. option:: -version
118118

@@ -625,27 +625,11 @@ but would not match the text:
625625
626626
due to ``7`` being unequal to ``5 + 1``.
627627

628-
The syntax also supports an empty expression, equivalent to writing {{[0-9]+}},
629-
for cases where the input must contain a numeric value but the value itself
630-
does not matter:
631-
632-
.. code-block:: gas
633-
634-
; CHECK-NOT: mov r0, r[[#]]
635-
636-
to check that a value is synthesized rather than moved around.
637-
638-
A numeric variable can also be defined to the result of a numeric expression,
639-
in which case the numeric expression is checked and if verified the variable is
640-
assigned to the value. The unified syntax for both defining numeric variables
641-
and checking a numeric expression is thus ``[[#<NUMVAR>: <expr>]]`` with each
642-
element as described previously.
643-
644628
The ``--enable-var-scope`` option has the same effect on numeric variables as
645629
on string variables.
646630

647631
Important note: In its current implementation, an expression cannot use a
648-
numeric variable with a non-empty expression defined on the same line.
632+
numeric variable defined on the same line.
649633

650634
FileCheck Pseudo Numeric Variables
651635
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

llvm/include/llvm/Support/FileCheck.h

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ class FileCheckNumericVariable {
9494
/// Name of the numeric variable.
9595
StringRef Name;
9696

97-
/// Pointer to expression defining this numeric variable. Null for pseudo
98-
/// variable whose value is known at parse time (e.g. @LINE pseudo variable)
99-
/// or cleared local variable.
100-
FileCheckExpressionAST *ExpressionAST;
101-
10297
/// Value of numeric variable, if defined, or None otherwise.
10398
Optional<uint64_t> Value;
10499

@@ -109,40 +104,23 @@ class FileCheckNumericVariable {
109104

110105
public:
111106
/// Constructor for a variable \p Name defined at line \p DefLineNumber or
112-
/// defined before input is parsed if \p DefLineNumber is None. If not null,
113-
/// the value set with setValue must match the result of evaluating
114-
/// \p ExpressionAST.
107+
/// defined before input is parsed if DefLineNumber is None.
115108
FileCheckNumericVariable(StringRef Name,
116-
Optional<size_t> DefLineNumber = None,
117-
FileCheckExpressionAST *ExpressionAST = nullptr)
118-
: Name(Name), ExpressionAST(ExpressionAST), DefLineNumber(DefLineNumber) {
119-
}
109+
Optional<size_t> DefLineNumber = None)
110+
: Name(Name), DefLineNumber(DefLineNumber) {}
120111

121112
/// \returns name of this numeric variable.
122113
StringRef getName() const { return Name; }
123114

124115
/// \returns this variable's value.
125116
Optional<uint64_t> getValue() const { return Value; }
126117

127-
/// \returns the pointer to the expression defining this numeric variable, if
128-
/// any, or null otherwise.
129-
FileCheckExpressionAST *getExpressionAST() const { return ExpressionAST; }
130-
131-
/// \returns whether this variable's value is known when performing the
132-
/// substitutions of the line where it is defined.
133-
bool isValueKnownAtMatchTime() const;
134-
135-
/// Sets value of this numeric variable to \p NewValue. Triggers an assertion
136-
/// failure if the variable is defined by an expression and the expression
137-
/// cannot be evaluated to be equal to \p NewValue.
138-
void setValue(uint64_t NewValue);
118+
/// Sets value of this numeric variable to \p NewValue.
119+
void setValue(uint64_t NewValue) { Value = NewValue; }
139120

140121
/// Clears value of this numeric variable, regardless of whether it is
141122
/// currently defined or not.
142-
void clearValue() {
143-
Value = None;
144-
ExpressionAST = nullptr;
145-
}
123+
void clearValue() { Value = None; }
146124

147125
/// \returns the line number where this variable is defined, if any, or None
148126
/// if defined before input is parsed.
@@ -529,22 +507,27 @@ class FileCheckPattern {
529507
/// \p Str from the variable name.
530508
static Expected<VariableProperties> parseVariable(StringRef &Str,
531509
const SourceMgr &SM);
532-
/// Parses \p Expr for a numeric substitution block at line \p LineNumber,
533-
/// or before input is parsed if \p LineNumber is None. Parameter
510+
/// Parses \p Expr for the name of a numeric variable to be defined at line
511+
/// \p LineNumber or before input is parsed if \p LineNumber is None.
512+
/// \returns a pointer to the class instance representing that variable,
513+
/// creating it if needed, or an error holding a diagnostic against \p SM
514+
/// should defining such a variable be invalid.
515+
static Expected<FileCheckNumericVariable *> parseNumericVariableDefinition(
516+
StringRef &Expr, FileCheckPatternContext *Context,
517+
Optional<size_t> LineNumber, const SourceMgr &SM);
518+
/// Parses \p Expr for a numeric substitution block. Parameter
534519
/// \p IsLegacyLineExpr indicates whether \p Expr should be a legacy @LINE
535-
/// expression and \p Context points to the class instance holding the live
536-
/// string and numeric variables. \returns a pointer to the class instance
537-
/// representing the AST of the expression whose value must be substitued, or
538-
/// an error holding a diagnostic against \p SM if parsing fails. If
539-
/// substitution was successful, sets \p DefinedNumericVariable to point to
540-
/// the class representing the numeric variable defined in this numeric
520+
/// expression. \returns a pointer to the class instance representing the AST
521+
/// of the expression whose value must be substituted, or an error holding a
522+
/// diagnostic against \p SM if parsing fails. If substitution was
523+
/// successful, sets \p DefinedNumericVariable to point to the class
524+
/// representing the numeric variable being defined in this numeric
541525
/// substitution block, or None if this block does not define any variable.
542-
static Expected<std::unique_ptr<FileCheckExpressionAST>>
526+
Expected<std::unique_ptr<FileCheckExpressionAST>>
543527
parseNumericSubstitutionBlock(
544528
StringRef Expr,
545529
Optional<FileCheckNumericVariable *> &DefinedNumericVariable,
546-
bool IsLegacyLineExpr, Optional<size_t> LineNumber,
547-
FileCheckPatternContext *Context, const SourceMgr &SM);
530+
bool IsLegacyLineExpr, const SourceMgr &SM) const;
548531
/// Parses the pattern in \p PatternStr and initializes this FileCheckPattern
549532
/// instance accordingly.
550533
///
@@ -598,49 +581,28 @@ class FileCheckPattern {
598581
/// was not found.
599582
size_t FindRegexVarEnd(StringRef Str, SourceMgr &SM);
600583

601-
/// Parses \p Expr for the name of a numeric variable to be defined at line
602-
/// \p LineNumber, or before input is parsed if \p LineNumber is None.
603-
/// \returns a pointer to the class instance representing that variable,
604-
/// creating it if needed, or an error holding a diagnostic against \p SM
605-
/// should defining such a variable be invalid.
606-
static Expected<FileCheckNumericVariable *> parseNumericVariableDefinition(
607-
StringRef &Expr, FileCheckPatternContext *Context,
608-
Optional<size_t> LineNumber, FileCheckExpressionAST *ExpressionAST,
609-
const SourceMgr &SM);
610-
/// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use
611-
/// at line \p LineNumber, or before input is parsed if \p LineNumber is
612-
/// None. Parameter \p Context points to the class instance holding the live
613-
/// string and numeric variables. \returns the pointer to the class instance
614-
/// representing that variable if successful, or an error holding a
615-
/// diagnostic against \p SM otherwise.
616-
static Expected<std::unique_ptr<FileCheckNumericVariableUse>>
584+
/// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use.
585+
/// \returns the pointer to the class instance representing that variable if
586+
/// successful, or an error holding a diagnostic against \p SM otherwise.
587+
Expected<std::unique_ptr<FileCheckNumericVariableUse>>
617588
parseNumericVariableUse(StringRef Name, bool IsPseudo,
618-
Optional<size_t> LineNumber,
619-
FileCheckPatternContext *Context,
620-
const SourceMgr &SM);
589+
const SourceMgr &SM) const;
621590
enum class AllowedOperand { LineVar, Literal, Any };
622-
/// Parses \p Expr for use of a numeric operand at line \p LineNumber, or
623-
/// before input is parsed if \p LineNumber is None. Accepts both literal
624-
/// values and numeric variables, depending on the value of \p AO. Parameter
625-
/// \p Context points to the class instance holding the live string and
626-
/// numeric variables. \returns the class representing that operand in the
627-
/// AST of the expression or an error holding a diagnostic against \p SM
628-
/// otherwise.
629-
static Expected<std::unique_ptr<FileCheckExpressionAST>>
591+
/// Parses \p Expr for use of a numeric operand. Accepts both literal values
592+
/// and numeric variables, depending on the value of \p AO. \returns the
593+
/// class representing that operand in the AST of the expression or an error
594+
/// holding a diagnostic against \p SM otherwise.
595+
Expected<std::unique_ptr<FileCheckExpressionAST>>
630596
parseNumericOperand(StringRef &Expr, AllowedOperand AO,
631-
Optional<size_t> LineNumber,
632-
FileCheckPatternContext *Context, const SourceMgr &SM);
633-
/// Parses \p Expr for a binary operation at line \p LineNumber, or before
634-
/// input is parsed if \p LineNumber is None. The left operand of this binary
597+
const SourceMgr &SM) const;
598+
/// Parses \p Expr for a binary operation. The left operand of this binary
635599
/// operation is given in \p LeftOp and \p IsLegacyLineExpr indicates whether
636-
/// we are parsing a legacy @LINE expression. Parameter \p Context points to
637-
/// the class instance holding the live string and numeric variables.
638-
/// \returns the class representing the binary operation in the AST of the
639-
/// expression, or an error holding a diagnostic against \p SM otherwise.
640-
static Expected<std::unique_ptr<FileCheckExpressionAST>>
600+
/// we are parsing a legacy @LINE expression. \returns the class representing
601+
/// the binary operation in the AST of the expression, or an error holding a
602+
/// diagnostic against \p SM otherwise.
603+
Expected<std::unique_ptr<FileCheckExpressionAST>>
641604
parseBinop(StringRef &Expr, std::unique_ptr<FileCheckExpressionAST> LeftOp,
642-
bool IsLegacyLineExpr, Optional<size_t> LineNumber,
643-
FileCheckPatternContext *Context, const SourceMgr &SM);
605+
bool IsLegacyLineExpr, const SourceMgr &SM) const;
644606
};
645607

646608
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)