1//===-- FileCheckImpl.h - Private FileCheck Interface ------------*- C++ -*-==// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file defines the private interfaces of FileCheck. Its purpose is to 10// allow unit testing of FileCheck and to separate the interface from the 11// implementation. It is only meant to be used by FileCheck. 13//===----------------------------------------------------------------------===// 15#ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H 16#define LLVM_LIB_FILECHECK_FILECHECKIMPL_H 31//===----------------------------------------------------------------------===// 32// Numeric substitution handling code. 33//===----------------------------------------------------------------------===// 35/// Type representing the format an expression value should be textualized into 36/// for matching. Used to represent both explicit format specifiers as well as 37/// implicit format from using numeric variables. 40 /// Denote absence of format. Used for implicit format of literals and 41 /// empty expressions. 43 /// Value is an unsigned integer and should be printed as a decimal number. 45 /// Value is a signed integer and should be printed as a decimal number. 47 /// Value should be printed as an uppercase hex number. 49 /// Value should be printed as a lowercase hex number. 55unsigned Precision = 0;
56 /// printf-like "alternate form" selected. 57bool AlternateForm =
false;
60 /// Evaluates a format to true if it can be used in a match. 63 /// Define format equality: formats are equal if neither is NoFormat and 64 /// their kinds and precision are the same. 67 Precision ==
Other.Precision && AlternateForm ==
Other.AlternateForm;
71return !(*
this ==
Other);
78 /// \returns the format specifier corresponding to this format as a string. 86 :
Value(
Value), Precision(Precision), AlternateForm(AlternateForm){};
88 /// \returns a wildcard regular expression string that matches any value in 89 /// the format represented by this instance and no other value, or an error 90 /// if the format is NoFormat. 93 /// \returns the string representation of \p Value in the format represented 94 /// by this instance, or an error if conversion to this format failed or the 95 /// format is NoFormat. 98 /// \returns the value corresponding to string representation \p StrVal 99 /// according to the matching format represented by this instance. 103/// Class to represent an overflow error that might result when manipulating a 110return std::make_error_code(std::errc::value_too_large);
116/// Performs operation and \returns its result or an error in case of failure, 117/// such as if an overflow occurs. 118Expected<APInt>
exprAdd(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
119Expected<APInt>
exprSub(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
120Expected<APInt>
exprMul(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
121Expected<APInt>
exprDiv(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
122Expected<APInt>
exprMax(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
123Expected<APInt>
exprMin(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
125/// Base class representing the AST of a given expression. 137 /// Evaluates and \returns the value of the expression represented by this 138 /// AST or an error if evaluation fails. 141 /// \returns either the implicit format of this AST, a diagnostic against 142 /// \p SM if implicit formats of the AST's components conflict, or NoFormat 143 /// if the AST has no implicit format (e.g. AST is made up of a single 151/// Class representing an unsigned literal in the AST of an expression. 154 /// Actual value of the literal. 161 /// \returns the literal's value. 165/// Class to represent an undefined variable error, which quotes that 166/// variable's name when printed. 182 /// Print name of variable associated with this error. 184OS <<
"undefined variable: " << VarName;
188/// Class representing an expression and its matching format. 191 /// Pointer to AST of the expression. 192 std::unique_ptr<ExpressionAST> AST;
194 /// Format to use (e.g. hex upper case letters) when matching the value. 198 /// Generic constructor for an expression represented by the given \p AST and 199 /// whose matching format is \p Format. 201 : AST(
std::
move(AST)), Format(Format) {}
203 /// \returns pointer to AST of the expression. Pointer is guaranteed to be 204 /// valid as long as this object is. 210/// Class representing a numeric variable and its associated current value. 213 /// Name of the numeric variable. 216 /// Format to use for expressions using this variable without an explicit 220 /// Value of numeric variable, if defined, or std::nullopt otherwise. 221 std::optional<APInt>
Value;
223 /// The input buffer's string from which Value was parsed, or std::nullopt. 224 /// See comments on getStringValue for a discussion of the std::nullopt case. 225 std::optional<StringRef> StrValue;
227 /// Line number where this variable is defined, or std::nullopt if defined 228 /// before input is parsed. Used to determine whether a variable is defined on 229 /// the same line as a given use. 230 std::optional<size_t> DefLineNumber;
233 /// Constructor for a variable \p Name with implicit format \p ImplicitFormat 234 /// defined at line \p DefLineNumber or defined before input is parsed if 235 /// \p DefLineNumber is std::nullopt. 237 std::optional<size_t> DefLineNumber = std::nullopt)
238 : Name(Name), ImplicitFormat(ImplicitFormat),
239 DefLineNumber(DefLineNumber) {}
241 /// \returns name of this numeric variable. 244 /// \returns implicit format of this numeric variable. 247 /// \returns this variable's value. 250 /// \returns the input buffer's string from which this variable's value was 251 /// parsed, or std::nullopt if the value is not yet defined or was not parsed 252 /// from the input buffer. For example, the value of @LINE is not parsed from 253 /// the input buffer, and some numeric variables are parsed from the command 257 /// Sets value of this numeric variable to \p NewValue, and sets the input 258 /// buffer string from which it was parsed to \p NewStrValue. See comments on 259 /// getStringValue for a discussion of when the latter can be std::nullopt. 261 std::optional<StringRef> NewStrValue = std::nullopt) {
263 StrValue = NewStrValue;
266 /// Clears value of this numeric variable, regardless of whether it is 267 /// currently defined or not. 270 StrValue = std::nullopt;
273 /// \returns the line number where this variable is defined, if any, or 274 /// std::nullopt if defined before input is parsed. 278/// Class representing the use of a numeric variable in the AST of an 282 /// Pointer to the class instance for the variable this use is about. 288 /// \returns the value of the variable referenced by this instance. 291 /// \returns implicit format of this numeric variable. 298/// Type of functions evaluating a given binary operation. 301/// Class representing a single binary operation in the AST of an expression. 305 std::unique_ptr<ExpressionAST> LeftOperand;
308 std::unique_ptr<ExpressionAST> RightOperand;
310 /// Pointer to function that can evaluate this binary operation. 315 std::unique_ptr<ExpressionAST> LeftOp,
316 std::unique_ptr<ExpressionAST> RightOp)
318 LeftOperand = std::move(LeftOp);
319 RightOperand = std::move(RightOp);
322 /// Evaluates the value of the binary operation represented by this AST, 323 /// using EvalBinop on the result of recursively evaluating the operands. 324 /// \returns the expression value or an error if an undefined numeric 325 /// variable is used in one of the operands. 328 /// \returns the implicit format of this AST, if any, a diagnostic against 329 /// \p SM if the implicit formats of the AST's components conflict, or no 330 /// format if the AST has no implicit format (e.g. AST is made of a single 336classFileCheckPatternContext;
338/// Class representing a substitution to perform in the RegExStr string. 341 /// Pointer to a class instance holding, among other things, the table with 342 /// the values of live string variables at the start of any given CHECK line. 343 /// Used for substituting string variables with the text they were defined 344 /// as. Expressions are linked to the numeric variables they use at 345 /// parse time and directly access the value of the numeric variable to 346 /// evaluate their value. 349 /// The string that needs to be substituted for something else. For a 350 /// string variable this is its name, otherwise this is the whole expression. 353// Index in RegExStr of where to do the substitution. 363 /// \returns the string to be substituted for something else. 366 /// \returns the index where the substitution is to be performed in RegExStr. 369 /// \returns a string containing the result of the substitution represented 370 /// by this class instance or an error if substitution failed. 380 /// \returns the text that the string variable in this substitution matched 381 /// when defined, or an error if the variable is undefined. 387 /// Pointer to the class representing the expression whose value is to be 389 std::unique_ptr<Expression> ExpressionPointer;
393 std::unique_ptr<Expression> ExpressionPointer,
396 ExpressionPointer(
std::
move(ExpressionPointer)) {}
398 /// \returns a string containing the result of evaluating the expression in 399 /// this substitution, or an error if evaluation failed. 403//===----------------------------------------------------------------------===// 404// Pattern handling code. 405//===----------------------------------------------------------------------===// 407/// Class holding the Pattern global state, shared by all patterns: tables 408/// holding values of variables and whether they are defined or not at any 409/// given time in the matching process. 414 /// When matching a given pattern, this holds the value of all the string 415 /// variables defined in previous patterns. In a pattern, only the last 416 /// definition for a given variable is recorded in this table. 417 /// Back-references are used for uses after any the other definition. 420 /// Map of all string variables defined so far. Used at parse time to detect 421 /// a name conflict between a numeric variable and a string variable when 422 /// the former is defined on a later line than the latter. 425 /// When matching a given pattern, this holds the pointers to the classes 426 /// representing the numeric variables defined in previous patterns. When 427 /// matching a pattern all definitions for that pattern are recorded in the 428 /// NumericVariableDefs table in the Pattern instance of that pattern. 431 /// Pointer to the class instance representing the @LINE pseudo variable for 432 /// easily updating its value. 435 /// Vector holding pointers to all parsed numeric variables. Used to 436 /// automatically free them once they are guaranteed to no longer be used. 437 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
439 /// Vector holding pointers to all parsed expressions. Used to automatically 440 /// free the expressions once they are guaranteed to no longer be used. 441 std::vector<std::unique_ptr<Expression>> Expressions;
443 /// Vector holding pointers to all substitutions. Used to automatically free 444 /// them once they are guaranteed to no longer be used. 445 std::vector<std::unique_ptr<Substitution>> Substitutions;
448 /// \returns the value of string variable \p VarName or an error if no such 449 /// variable has been defined. 452 /// Defines string and numeric variables from definitions given on the 453 /// command line, passed as a vector of [#]VAR=VAL strings in 454 /// \p CmdlineDefines. \returns an error list containing diagnostics against 455 /// \p SM for all definition parsing failures, if any, or Success otherwise. 459 /// Create @LINE pseudo variable. Value is set when pattern are being 463 /// Undefines local variables (variables whose name does not start with a '$' 464 /// sign), i.e. removes them from GlobalVariableTable and from 465 /// GlobalNumericVariableTable and also clears the value of numeric 470 /// Makes a new numeric variable and registers it for destruction when the 471 /// context is destroyed. 474 /// Makes a new string substitution and registers it for destruction when the 475 /// context is destroyed. 478 /// Makes a new numeric substitution and registers it for destruction when 479 /// the context is destroyed. 485/// Class to represent an error holding a diagnostic with location information 486/// used when printing it. 502 /// Print diagnostic associated with this error when printing the error. 510return make_error<ErrorDiagnostic>(
529 /// Print diagnostic associated with this error when printing the error. 531OS <<
"String not found in input";
535/// An error that has already been reported. 537/// This class is designed to support a function whose callers may need to know 538/// whether the function encountered and reported an error but never need to 539/// know the nature of that error. For example, the function has a return type 540/// of \c Error and always returns either \c ErrorReported or \c ErrorSuccess. 541/// That interface is similar to that of a function returning bool to indicate 542/// an error except, in the former case, (1) there is no confusion over polarity 543/// and (2) the caller must either check the result or explicitly ignore it with 544/// a call like \c consumeError. 553 /// Print diagnostic associated with this error when printing the error. 555OS <<
"error previously reported";
560return make_error<ErrorReported>();
568 /// A fixed string to match as the pattern or empty if this pattern requires 572 /// A regex string to match as the pattern or empty if this pattern requires 573 /// a fixed string to match. 574 std::string RegExStr;
576 /// Entries in this vector represent a substitution of a string variable or 577 /// an expression in the RegExStr regex at match time. For example, in the 578 /// case of a CHECK directive with the pattern "foo[[bar]]baz[[#N+1]]", 579 /// RegExStr will contain "foobaz" and we'll get two entries in this vector 580 /// that tells us to insert the value of string variable "bar" at offset 3 581 /// and the value of expression "N+1" at offset 6. 582 std::vector<Substitution *> Substitutions;
584 /// Maps names of string variables defined in a pattern to the number of 585 /// their parenthesis group in RegExStr capturing their last definition. 587 /// E.g. for the pattern "foo[[bar:.*]]baz([[bar]][[QUUX]][[bar:.*]])", 588 /// RegExStr will be "foo(.*)baz(\1<quux value>(.*))" where <quux value> is 589 /// the value captured for QUUX on the earlier line where it was defined, and 590 /// VariableDefs will map "bar" to the third parenthesis group which captures 591 /// the second definition of "bar". 593 /// Note: uses std::map rather than StringMap to be able to get the key when 594 /// iterating over values. 595 std::map<StringRef, unsigned> VariableDefs;
597 /// Structure representing the definition of a numeric variable in a pattern. 598 /// It holds the pointer to the class instance holding the value and matching 599 /// format of the numeric variable whose value is being defined and the 600 /// number of the parenthesis group in RegExStr to capture that value. 601structNumericVariableMatch {
602 /// Pointer to class instance holding the value and matching format of the 603 /// numeric variable being defined. 606 /// Number of the parenthesis group in RegExStr that captures the value of 607 /// this numeric variable definition. 608unsigned CaptureParenGroup;
611 /// Holds the number of the parenthesis group in RegExStr and pointer to the 612 /// corresponding NumericVariable class instance of all numeric variable 613 /// definitions. Used to set the matched value of all those variables. 616 /// Pointer to a class instance holding the global state shared by all 618 /// - separate tables with the values of live string and numeric variables 619 /// respectively at the start of any given CHECK line; 620 /// - table holding whether a string variable has been defined at any given 621 /// point during the parsing phase. 626 /// Line number for this CHECK pattern or std::nullopt if it is an implicit 627 /// pattern. Used to determine whether a variable definition is made on an 628 /// earlier line to the one with this CHECK. 629 std::optional<size_t> LineNumber;
631 /// Ignore case while matching if set to true. 632bool IgnoreCase =
false;
636 std::optional<size_t> Line = std::nullopt)
637 : Context(Context), CheckTy(Ty), LineNumber(Line) {}
639 /// \returns the location in source code. 642 /// \returns the pointer to the global state for all patterns in this 643 /// FileCheck instance. 646 /// \returns whether \p C is a valid first character for a variable name. 649 /// Parsing information about a variable. 655 /// Parses the string at the start of \p Str for a variable name. \returns 656 /// a VariableProperties structure holding the variable name and whether it 657 /// is the name of a pseudo variable, or an error holding a diagnostic 658 /// against \p SM if parsing fail. If parsing was successful, also strips 659 /// \p Str from the variable name. 662 /// Parses \p Expr for a numeric substitution block at line \p LineNumber, 663 /// or before input is parsed if \p LineNumber is None. Parameter 664 /// \p IsLegacyLineExpr indicates whether \p Expr should be a legacy @LINE 665 /// expression and \p Context points to the class instance holding the live 666 /// string and numeric variables. \returns a pointer to the class instance 667 /// representing the expression whose value must be substitued, or an error 668 /// holding a diagnostic against \p SM if parsing fails. If substitution was 669 /// successful, sets \p DefinedNumericVariable to point to the class 670 /// representing the numeric variable defined in this numeric substitution 671 /// block, or std::nullopt if this block does not define any variable. 673StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
674bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
676 /// Parses the pattern in \p PatternStr and initializes this Pattern instance 679 /// \p Prefix provides which prefix is being matched, \p Req describes the 680 /// global options that influence the parsing such as whitespace 681 /// canonicalization, \p SM provides the SourceMgr used for error reports. 682 /// \returns true in case of an error, false otherwise. 697 /// Matches the pattern string against the input buffer \p Buffer. 699 /// \returns either (1) an error resulting in no match or (2) a match possibly 700 /// with an error encountered while processing the match. 702 /// The GlobalVariableTable StringMap in the FileCheckPatternContext class 703 /// instance provides the current values of FileCheck string variables and is 704 /// updated if this match defines new values. Likewise, the 705 /// GlobalNumericVariableTable StringMap in the same class provides the 706 /// current values of FileCheck numeric variables and is updated if this 707 /// match defines new numeric values. 709 /// Prints the value of successful substitutions. 712 std::vector<FileCheckDiag> *Diags)
const;
714 std::vector<FileCheckDiag> *Diags)
const;
717return !(Substitutions.empty() && VariableDefs.empty());
720 std::vector<FileCheckDiag> *Diags)
const;
728void AddBackrefToRegEx(
unsigned BackrefNum);
729 /// Computes an arbitrary estimate for the quality of matching this pattern 730 /// at the start of \p Buffer; a distance of zero should correspond to a 732unsigned computeMatchDistance(
StringRef Buffer)
const;
733 /// Finds the closing sequence of a regex variable usage or definition. 735 /// \p Str has to point in the beginning of the definition (right after the 736 /// opening sequence). \p SM holds the SourceMgr used for error reporting. 737 /// \returns the offset of the closing sequence within Str, or npos if it 741 /// Parses \p Expr for the name of a numeric variable to be defined at line 742 /// \p LineNumber, or before input is parsed if \p LineNumber is None. 743 /// \returns a pointer to the class instance representing that variable, 744 /// creating it if needed, or an error holding a diagnostic against \p SM 745 /// should defining such a variable be invalid. 750 /// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use 751 /// at line \p LineNumber, or before input is parsed if \p LineNumber is 752 /// None. Parameter \p Context points to the class instance holding the live 753 /// string and numeric variables. \returns the pointer to the class instance 754 /// representing that variable if successful, or an error holding a 755 /// diagnostic against \p SM otherwise. 757StringRefName,
bool IsPseudo, std::optional<size_t> LineNumber,
759enum class AllowedOperand { LineVar, LegacyLiteral,
Any };
760 /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or 761 /// before input is parsed if \p LineNumber is None. Accepts literal values, 762 /// numeric variables and function calls, depending on the value of \p AO. 763 /// \p MaybeInvalidConstraint indicates whether the text being parsed could 764 /// be an invalid constraint. \p Context points to the class instance holding 765 /// the live string and numeric variables. \returns the class representing 766 /// that operand in the AST of the expression or an error holding a 767 /// diagnostic against \p SM otherwise. If \p Expr starts with a "(" this 768 /// function will attempt to parse a parenthesized expression. 769static Expected<std::unique_ptr<ExpressionAST>>
770 parseNumericOperand(StringRef &Expr, AllowedOperand AO,
bool ConstraintParsed,
771 std::optional<size_t> LineNumber,
772 FileCheckPatternContext *Context,
const SourceMgr &SM);
773 /// Parses and updates \p RemainingExpr for a binary operation at line 774 /// \p LineNumber, or before input is parsed if \p LineNumber is None. The 775 /// left operand of this binary operation is given in \p LeftOp and \p Expr 776 /// holds the string for the full expression, including the left operand. 777 /// Parameter \p IsLegacyLineExpr indicates whether we are parsing a legacy 778 /// @LINE expression. Parameter \p Context points to the class instance 779 /// holding the live string and numeric variables. \returns the class 780 /// representing the binary operation in the AST of the expression, or an 781 /// error holding a diagnostic against \p SM otherwise. 782static Expected<std::unique_ptr<ExpressionAST>>
783 parseBinop(StringRef Expr, StringRef &RemainingExpr,
784 std::unique_ptr<ExpressionAST> LeftOp,
bool IsLegacyLineExpr,
785 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
788 /// Parses a parenthesized expression inside \p Expr at line \p LineNumber, or 789 /// before input is parsed if \p LineNumber is None. \p Expr must start with 790 /// a '('. Accepts both literal values and numeric variables. Parameter \p 791 /// Context points to the class instance holding the live string and numeric 792 /// variables. \returns the class representing that operand in the AST of the 793 /// expression or an error holding a diagnostic against \p SM otherwise. 794static Expected<std::unique_ptr<ExpressionAST>>
795 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
796 FileCheckPatternContext *Context,
const SourceMgr &SM);
798 /// Parses \p Expr for an argument list belonging to a call to function \p 799 /// FuncName at line \p LineNumber, or before input is parsed if \p LineNumber 800 /// is None. Parameter \p FuncLoc is the source location used for diagnostics. 801 /// Parameter \p Context points to the class instance holding the live string 802 /// and numeric variables. \returns the class representing that call in the 803 /// AST of the expression or an error holding a diagnostic against \p SM 805static Expected<std::unique_ptr<ExpressionAST>>
806 parseCallExpr(StringRef &Expr, StringRef FuncName,
807 std::optional<size_t> LineNumber,
808 FileCheckPatternContext *Context,
const SourceMgr &SM);
811//===----------------------------------------------------------------------===// 813//===----------------------------------------------------------------------===// 815/// A check that we found in the input file. 817 /// The pattern to match. 820 /// Which prefix name this check matched. 823 /// The location in the match file that the check string was specified. 826 /// Hold the information about the DAG/NOT strings in the program, which are 827 /// not explicitly stored otherwise. This allows for better and more accurate 828 /// diagnostic messages. 837 /// Hold the DAG/NOT strings occurring in the input file. 841 std::vector<DagNotPrefixInfo> &&
D)
844 /// Matches check string and its "not strings" and/or "dag strings". 847 std::vector<FileCheckDiag> *Diags)
const;
849 /// Verifies that there is a single line in the given \p Buffer. Errors are 850 /// reported against \p SM. 852 /// Verifies that there is no newline in the given \p Buffer. Errors are 853 /// reported against \p SM. 855 /// Verifies that none of the strings in \p NotStrings are found in the given 856 /// \p Buffer. Errors are reported against \p SM and diagnostics recorded in 857 /// \p Diags according to the verbosity level set in \p Req. 859const std::vector<const DagNotPrefixInfo *> &NotStrings,
861 std::vector<FileCheckDiag> *Diags)
const;
862 /// Matches "dag strings" and their mixed "not strings". 864 std::vector<const DagNotPrefixInfo *> &NotStrings,
866 std::vector<FileCheckDiag> *Diags)
const;
This file defines the StringMap class.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class representing a single binary operation in the AST of an expression.
BinaryOperation(StringRef ExpressionStr, binop_eval_t EvalBinop, std::unique_ptr< ExpressionAST > LeftOp, std::unique_ptr< ExpressionAST > RightOp)
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Expected< APInt > eval() const override
Evaluates the value of the binary operation represented by this AST, using EvalBinop on the result of...
Class to represent an error holding a diagnostic with location information used when printing it.
StringRef getMessage() const
ErrorDiagnostic(SMDiagnostic &&Diag, SMRange Range)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
static Error get(const SourceMgr &SM, StringRef Buffer, const Twine &ErrMsg)
static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg, SMRange Range=std::nullopt)
Base class for user error types.
An error that has already been reported.
static Error reportedOrSuccess(bool HasErrorReported)
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Base class representing the AST of a given expression.
ExpressionAST(StringRef ExpressionStr)
virtual Expected< APInt > eval() const =0
Evaluates and.
StringRef getExpressionStr() const
virtual ~ExpressionAST()=default
virtual Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const
Class representing an unsigned literal in the AST of an expression.
ExpressionLiteral(StringRef ExpressionStr, APInt Val)
Expected< APInt > eval() const override
Class representing an expression and its matching format.
ExpressionFormat getFormat() const
Expression(std::unique_ptr< ExpressionAST > AST, ExpressionFormat Format)
Generic constructor for an expression represented by the given AST and whose matching format is Forma...
ExpressionAST * getAST() const
Class holding the Pattern global state, shared by all patterns: tables holding values of variables an...
Error defineCmdlineVariables(ArrayRef< StringRef > CmdlineDefines, SourceMgr &SM)
Defines string and numeric variables from definitions given on the command line, passed as a vector o...
void createLineVariable()
Create @LINE pseudo variable.
Expected< StringRef > getPatternVarValue(StringRef VarName)
void clearLocalVars()
Undefines local variables (variables whose name does not start with a '$' sign), i....
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Expected< std::string > getResult() const override
NumericSubstitution(FileCheckPatternContext *Context, StringRef ExpressionStr, std::unique_ptr< Expression > ExpressionPointer, size_t InsertIdx)
Class representing the use of a numeric variable in the AST of an expression.
NumericVariableUse(StringRef Name, NumericVariable *Variable)
Expected< APInt > eval() const override
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Class representing a numeric variable and its associated current value.
void clearValue()
Clears value of this numeric variable, regardless of whether it is currently defined or not.
void setValue(APInt NewValue, std::optional< StringRef > NewStrValue=std::nullopt)
Sets value of this numeric variable to NewValue, and sets the input buffer string from which it was p...
ExpressionFormat getImplicitFormat() const
StringRef getName() const
std::optional< StringRef > getStringValue() const
std::optional< APInt > getValue() const
NumericVariable(StringRef Name, ExpressionFormat ImplicitFormat, std::optional< size_t > DefLineNumber=std::nullopt)
Constructor for a variable Name with implicit format ImplicitFormat defined at line DefLineNumber or ...
std::optional< size_t > getDefLineNumber() const
Class to represent an overflow error that might result when manipulating a value.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
static Expected< VariableProperties > parseVariable(StringRef &Str, const SourceMgr &SM)
Parses the string at the start of Str for a variable name.
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
void printFuzzyMatch(const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
void printSubstitutions(const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Prints the value of successful substitutions.
FileCheckPatternContext * getContext() const
static Expected< std::unique_ptr< Expression > > parseNumericSubstitutionBlock(StringRef Expr, std::optional< NumericVariable * > &DefinedNumericVariable, bool IsLegacyLineExpr, std::optional< size_t > LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM)
Parses Expr for a numeric substitution block at line LineNumber, or before input is parsed if LineNum...
Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, std::optional< size_t > Line=std::nullopt)
void printVariableDefs(const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
static bool isValidVarNameStart(char C)
Check::FileCheckType getCheckTy() const
bool parsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
Parses the pattern in PatternStr and initializes this Pattern instance accordingly.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
StringRef getMessage() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
Represents a range in source code.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringSubstitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
Expected< std::string > getResult() const override
Class representing a substitution to perform in the RegExStr string.
virtual ~Substitution()=default
Substitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
StringRef getFromString() const
FileCheckPatternContext * Context
Pointer to a class instance holding, among other things, the table with the values of live string var...
StringRef FromStr
The string that needs to be substituted for something else.
virtual Expected< std::string > getResult() const =0
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Class to represent an undefined variable error, which quotes that variable's name when printed.
UndefVarError(StringRef VarName)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
StringRef getVarName() const
void log(raw_ostream &OS) const override
Print name of variable associated with this error.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Expected< APInt > exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Performs operation and.
Expected< APInt > exprMul(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Expected< APInt > exprMax(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprSub(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Implement std::hash so that hash_code can be used in STL containers.
Type representing the format an expression value should be textualized into for matching.
APInt valueFromStringRepr(StringRef StrVal, const SourceMgr &SM) const
StringRef toString() const
bool operator!=(const ExpressionFormat &Other) const
bool operator==(Kind OtherValue) const
Expected< std::string > getMatchingString(APInt Value) const
Expected< std::string > getWildcardRegex() const
ExpressionFormat(Kind Value)
@ HexLower
Value should be printed as a lowercase hex number.
@ HexUpper
Value should be printed as an uppercase hex number.
@ Signed
Value is a signed integer and should be printed as a decimal number.
@ Unsigned
Value is an unsigned integer and should be printed as a decimal number.
@ NoFormat
Denote absence of format.
ExpressionFormat(Kind Value, unsigned Precision)
bool operator!=(Kind OtherValue) const
bool operator==(const ExpressionFormat &Other) const
Define format equality: formats are equal if neither is NoFormat and their kinds and precision are th...
ExpressionFormat(Kind Value, unsigned Precision, bool AlternateForm)
MatchType
What type of match result does this diagnostic describe?
Contains info about various FileCheck options.
Hold the information about the DAG/NOT strings in the program, which are not explicitly stored otherw...
DagNotPrefixInfo(const Pattern &P, StringRef S)
A check that we found in the input file.
bool CheckNext(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is a single line in the given Buffer.
Pattern Pat
The pattern to match.
bool CheckSame(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is no newline in the given Buffer.
std::vector< DagNotPrefixInfo > DagNotStrings
Hold the DAG/NOT strings occurring in the input file.
SMLoc Loc
The location in the match file that the check string was specified.
StringRef Prefix
Which prefix name this check matched.
FileCheckString(Pattern &&P, StringRef S, SMLoc L, std::vector< DagNotPrefixInfo > &&D)
size_t CheckDag(const SourceMgr &SM, StringRef Buffer, std::vector< const DagNotPrefixInfo * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Matches "dag strings" and their mixed "not strings".
bool CheckNot(const SourceMgr &SM, StringRef Buffer, const std::vector< const DagNotPrefixInfo * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Verifies that none of the strings in NotStrings are found in the given Buffer.
MatchResult(Match M, Error E)
MatchResult(size_t MatchPos, size_t MatchLen, Error E)
std::optional< Match > TheMatch
Parsing information about a variable.