@@ -94,6 +94,11 @@ class FileCheckNumericVariable {
94
94
// / Name of the numeric variable.
95
95
StringRef Name;
96
96
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
+
97
102
// / Value of numeric variable, if defined, or None otherwise.
98
103
Optional<uint64_t > Value;
99
104
@@ -104,23 +109,40 @@ class FileCheckNumericVariable {
104
109
105
110
public:
106
111
// / Constructor for a variable \p Name defined at line \p DefLineNumber or
107
- // / defined before input is parsed if DefLineNumber is None.
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.
108
115
FileCheckNumericVariable (StringRef Name,
109
- Optional<size_t > DefLineNumber = None)
110
- : Name(Name), DefLineNumber(DefLineNumber) {}
116
+ Optional<size_t > DefLineNumber = None,
117
+ FileCheckExpressionAST *ExpressionAST = nullptr )
118
+ : Name(Name), ExpressionAST(ExpressionAST), DefLineNumber(DefLineNumber) {
119
+ }
111
120
112
121
// / \returns name of this numeric variable.
113
122
StringRef getName () const { return Name; }
114
123
115
124
// / \returns this variable's value.
116
125
Optional<uint64_t > getValue () const { return Value; }
117
126
118
- // / Sets value of this numeric variable to \p NewValue.
119
- void setValue (uint64_t NewValue) { Value = NewValue; }
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);
120
139
121
140
// / Clears value of this numeric variable, regardless of whether it is
122
141
// / currently defined or not.
123
- void clearValue () { Value = None; }
142
+ void clearValue () {
143
+ Value = None;
144
+ ExpressionAST = nullptr ;
145
+ }
124
146
125
147
// / \returns the line number where this variable is defined, if any, or None
126
148
// / if defined before input is parsed.
@@ -507,27 +529,22 @@ class FileCheckPattern {
507
529
// / \p Str from the variable name.
508
530
static Expected<VariableProperties> parseVariable (StringRef &Str,
509
531
const SourceMgr &SM);
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
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
519
534
// / \p IsLegacyLineExpr indicates whether \p Expr should be a legacy @LINE
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
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
525
541
// / substitution block, or None if this block does not define any variable.
526
- Expected<std::unique_ptr<FileCheckExpressionAST>>
542
+ static Expected<std::unique_ptr<FileCheckExpressionAST>>
527
543
parseNumericSubstitutionBlock (
528
544
StringRef Expr,
529
545
Optional<FileCheckNumericVariable *> &DefinedNumericVariable,
530
- bool IsLegacyLineExpr, const SourceMgr &SM) const ;
546
+ bool IsLegacyLineExpr, Optional<size_t > LineNumber,
547
+ FileCheckPatternContext *Context, const SourceMgr &SM);
531
548
// / Parses the pattern in \p PatternStr and initializes this FileCheckPattern
532
549
// / instance accordingly.
533
550
// /
@@ -581,28 +598,49 @@ class FileCheckPattern {
581
598
// / was not found.
582
599
size_t FindRegexVarEnd (StringRef Str, SourceMgr &SM);
583
600
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>>
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>>
588
617
parseNumericVariableUse (StringRef Name, bool IsPseudo,
589
- const SourceMgr &SM) const ;
618
+ Optional<size_t > LineNumber,
619
+ FileCheckPatternContext *Context,
620
+ const SourceMgr &SM);
590
621
enum class AllowedOperand { LineVar, Literal, Any };
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>>
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>>
596
630
parseNumericOperand (StringRef &Expr, AllowedOperand AO,
597
- const SourceMgr &SM) const ;
598
- // / Parses \p Expr for a binary operation. The left operand of this binary
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
599
635
// / operation is given in \p LeftOp and \p IsLegacyLineExpr indicates whether
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>>
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>>
604
641
parseBinop (StringRef &Expr, std::unique_ptr<FileCheckExpressionAST> LeftOp,
605
- bool IsLegacyLineExpr, const SourceMgr &SM) const ;
642
+ bool IsLegacyLineExpr, Optional<size_t > LineNumber,
643
+ FileCheckPatternContext *Context, const SourceMgr &SM);
606
644
};
607
645
608
646
// ===----------------------------------------------------------------------===//
0 commit comments