class Pattern

Declaration

class Pattern { /* full declaration omitted */ };

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:614

Member Variables

private llvm::SMLoc PatternLoc
private llvm::StringRef FixedStr
A fixed string to match as the pattern or empty if this pattern requires a regex match.
private std::string RegExStr
A regex string to match as the pattern or empty if this pattern requires a fixed string to match.
private std::vector<Substitution*> Substitutions
Entries in this vector represent a substitution of a string variable or an expression in the RegExStr regex at match time. For example, in the case of a CHECK directive with the pattern "foo[[bar]]baz[[#N+1]]", RegExStr will contain "foobaz" and we'll get two entries in this vector that tells us to insert the value of string variable "bar" at offset 3 and the value of expression "N+1" at offset 6.
private std::map<StringRef, unsigned int> VariableDefs
Note: uses std::map rather than StringMap to be able to get the key when iterating over values.
private StringMap<llvm::Pattern::NumericVariableMatch> NumericVariableDefs
Holds the number of the parenthesis group in RegExStr and pointer to the corresponding NumericVariable class instance of all numeric variable definitions. Used to set the matched value of all those variables.
private llvm::FileCheckPatternContext* Context
Pointer to a class instance holding the global state shared by all patterns: - separate tables with the values of live string and numeric variables respectively at the start of any given CHECK line; - table holding whether a string variable has been defined at any given point during the parsing phase.
private Check::FileCheckType CheckTy
private Optional<size_t> LineNumber
Line number for this CHECK pattern or None if it is an implicit pattern. Used to determine whether a variable definition is made on an earlier line to the one with this CHECK.
private bool IgnoreCase = false
Ignore case while matching if set to true.

Method Overview

  • private void AddBackrefToRegEx(unsigned int BackrefNum)
  • private bool AddRegExToRegEx(llvm::StringRef RS, unsigned int & CurParen, llvm::SourceMgr & SM)
  • private static size_t FindRegexVarEnd(llvm::StringRef Str, llvm::SourceMgr & SM)
  • public Pattern(Check::FileCheckType Ty, llvm::FileCheckPatternContext * Context, Optional<size_t> Line = None)
  • private unsigned int computeMatchDistance(llvm::StringRef Buffer) const
  • public Check::FileCheckType getCheckTy() const
  • public llvm::FileCheckPatternContext * getContext() const
  • public int getCount() const
  • public llvm::SMLoc getLoc() const
  • public bool hasVariable() const
  • public static bool isValidVarNameStart(char C)
  • public llvm::Pattern::MatchResult match(llvm::StringRef Buffer, const llvm::SourceMgr & SM) const
  • private static Expected<std::unique_ptr<ExpressionAST>> parseBinop(llvm::StringRef Expr, llvm::StringRef & RemainingExpr, std::unique_ptr<ExpressionAST> LeftOp, bool IsLegacyLineExpr, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • private static Expected<std::unique_ptr<ExpressionAST>> parseCallExpr(llvm::StringRef & Expr, llvm::StringRef FuncName, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • private static Expected<std::unique_ptr<ExpressionAST>> parseNumericOperand(llvm::StringRef & Expr, llvm::Pattern::AllowedOperand AO, bool ConstraintParsed, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • public static Expected<std::unique_ptr<Expression>> parseNumericSubstitutionBlock(llvm::StringRef Expr, Optional<llvm::NumericVariable *> & DefinedNumericVariable, bool IsLegacyLineExpr, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • private static Expected<llvm::NumericVariable *> parseNumericVariableDefinition(llvm::StringRef & Expr, llvm::FileCheckPatternContext * Context, Optional<size_t> LineNumber, llvm::ExpressionFormat ImplicitFormat, const llvm::SourceMgr & SM)
  • private static Expected<std::unique_ptr<NumericVariableUse>> parseNumericVariableUse(llvm::StringRef Name, bool IsPseudo, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • private static Expected<std::unique_ptr<ExpressionAST>> parseParenExpr(llvm::StringRef & Expr, Optional<size_t> LineNumber, llvm::FileCheckPatternContext * Context, const llvm::SourceMgr & SM)
  • public bool parsePattern(llvm::StringRef PatternStr, llvm::StringRef Prefix, llvm::SourceMgr & SM, const llvm::FileCheckRequest & Req)
  • public static Expected<llvm::Pattern::VariableProperties> parseVariable(llvm::StringRef & Str, const llvm::SourceMgr & SM)
  • public void printFuzzyMatch(const llvm::SourceMgr & SM, llvm::StringRef Buffer, std::vector<FileCheckDiag> * Diags) const
  • public void printSubstitutions(const llvm::SourceMgr & SM, llvm::StringRef Buffer, llvm::SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector<FileCheckDiag> * Diags) const
  • public void printVariableDefs(const llvm::SourceMgr & SM, FileCheckDiag::MatchType MatchTy, std::vector<FileCheckDiag> * Diags) const

Methods

void AddBackrefToRegEx(unsigned int BackrefNum)

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:777

Parameters

unsigned int BackrefNum

bool AddRegExToRegEx(llvm::StringRef RS,
                     unsigned int& CurParen,
                     llvm::SourceMgr& SM)

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:776

Parameters

llvm::StringRef RS
unsigned int& CurParen
llvm::SourceMgr& SM

static size_t FindRegexVarEnd(llvm::StringRef Str,
                              llvm::SourceMgr& SM)

Description

Finds the closing sequence of a regex variable usage or definition. \p Str has to point in the beginning of the definition (right after the opening sequence). \p SM holds the SourceMgr used for error reporting.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:788

Parameters

llvm::StringRef Str
llvm::SourceMgr& SM

Returns

the offset of the closing sequence within Str, or npos if it was not found.

Pattern(Check::FileCheckType Ty,
        llvm::FileCheckPatternContext* Context,
        Optional<size_t> Line = None)

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:684

Parameters

Check::FileCheckType Ty
llvm::FileCheckPatternContext* Context
Optional<size_t> Line = None

unsigned int computeMatchDistance(
    llvm::StringRef Buffer) const

Description

Computes an arbitrary estimate for the quality of matching this pattern at the start of \p Buffer; a distance of zero should correspond to a perfect match.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:781

Parameters

llvm::StringRef Buffer

Check::FileCheckType getCheckTy() const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:771

llvm::FileCheckPatternContext* getContext() const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:693

Returns

the pointer to the global state for all patterns in this FileCheck instance.

int getCount() const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:773

llvm::SMLoc getLoc() const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:689

Returns

the location in source code.

bool hasVariable() const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:765

static bool isValidVarNameStart(char C)

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:696

Parameters

char C

Returns

whether \p C is a valid first character for a variable name.

llvm::Pattern::MatchResult match(
    llvm::StringRef Buffer,
    const llvm::SourceMgr& SM) const

Description

Matches the pattern string against the input buffer \p Buffer. The GlobalVariableTable StringMap in the FileCheckPatternContext class instance provides the current values of FileCheck string variables and is updated if this match defines new values. Likewise, the GlobalNumericVariableTable StringMap in the same class provides the current values of FileCheck numeric variables and is updated if this match defines new numeric values.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:757

Parameters

llvm::StringRef Buffer
const llvm::SourceMgr& SM

Returns

either (1) an error resulting in no match or (2) a match possibly with an error encountered while processing the match.

static Expected<std::unique_ptr<ExpressionAST>>
parseBinop(llvm::StringRef Expr,
           llvm::StringRef& RemainingExpr,
           std::unique_ptr<ExpressionAST> LeftOp,
           bool IsLegacyLineExpr,
           Optional<size_t> LineNumber,
           llvm::FileCheckPatternContext* Context,
           const llvm::SourceMgr& SM)

Description

Parses and updates \p RemainingExpr for a binary operation at line\p LineNumber, or before input is parsed if \p LineNumber is None. The left operand of this binary operation is given in \p LeftOp and \p Expr holds the string for the full expression, including the left operand. Parameter \p IsLegacyLineExpr indicates whether we are parsing a legacy@LINEexpression. Parameter \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:832

Parameters

llvm::StringRef Expr
llvm::StringRef& RemainingExpr
std::unique_ptr<ExpressionAST> LeftOp
bool IsLegacyLineExpr
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

the class representing the binary operation in the AST of the expression, or an error holding a diagnostic against \p SM otherwise.

static Expected<std::unique_ptr<ExpressionAST>>
parseCallExpr(
    llvm::StringRef& Expr,
    llvm::StringRef FuncName,
    Optional<size_t> LineNumber,
    llvm::FileCheckPatternContext* Context,
    const llvm::SourceMgr& SM)

Description

Parses \p Expr for an argument list belonging to a call to function \p FuncName at line \p LineNumber, or before input is parsed if \p LineNumber is None. Parameter \p FuncLoc is the source location used for diagnostics. Parameter \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:855

Parameters

llvm::StringRef& Expr
llvm::StringRef FuncName
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

the class representing that call in the AST of the expression or an error holding a diagnostic against \p SM otherwise.

static Expected<std::unique_ptr<ExpressionAST>>
parseNumericOperand(
    llvm::StringRef& Expr,
    llvm::Pattern::AllowedOperand AO,
    bool ConstraintParsed,
    Optional<size_t> LineNumber,
    llvm::FileCheckPatternContext* Context,
    const llvm::SourceMgr& SM)

Description

Parses \p Expr for use of a numeric operand at line \p LineNumber, or before input is parsed if \p LineNumber is None. Accepts literal values, numeric variables and function calls, depending on the value of \p AO. \p MaybeInvalidConstraint indicates whether the text being parsed could be an invalid constraint. \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:819

Parameters

llvm::StringRef& Expr
llvm::Pattern::AllowedOperand AO
bool ConstraintParsed
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

the class representing that operand in the AST of the expression or an error holding a diagnostic against \p SM otherwise. If \p Expr starts with a "(" this function will attempt to parse a parenthesized expression.

static Expected<std::unique_ptr<Expression>>
parseNumericSubstitutionBlock(
    llvm::StringRef Expr,
    Optional<llvm::NumericVariable*>&
        DefinedNumericVariable,
    bool IsLegacyLineExpr,
    Optional<size_t> LineNumber,
    llvm::FileCheckPatternContext* Context,
    const llvm::SourceMgr& SM)

Description

Parses \p Expr for a numeric substitution block at line \p LineNumber, or before input is parsed if \p LineNumber is None. Parameter\p IsLegacyLineExpr indicates whether \p Expr should be a legacy @LINEexpression and \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:721

Parameters

llvm::StringRef Expr
Optional<llvm::NumericVariable*>& DefinedNumericVariable
bool IsLegacyLineExpr
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

a pointer to the class instance representing the expression whose value must be substitued, or an error holding a diagnostic against \p SM if parsing fails. If substitution was successful, sets \p DefinedNumericVariable to point to the class representing the numeric variable defined in this numeric substitution block, or None if this block does not define any variable.

static Expected<llvm::NumericVariable*>
parseNumericVariableDefinition(
    llvm::StringRef& Expr,
    llvm::FileCheckPatternContext* Context,
    Optional<size_t> LineNumber,
    llvm::ExpressionFormat ImplicitFormat,
    const llvm::SourceMgr& SM)

Description

Parses \p Expr for the name of a numeric variable to be defined at line\p LineNumber, or before input is parsed if \p LineNumber is None.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:795

Parameters

llvm::StringRef& Expr
llvm::FileCheckPatternContext* Context
Optional<size_t> LineNumber
llvm::ExpressionFormat ImplicitFormat
const llvm::SourceMgr& SM

Returns

a pointer to the class instance representing that variable, creating it if needed, or an error holding a diagnostic against \p SM should defining such a variable be invalid.

static Expected<
    std::unique_ptr<NumericVariableUse>>
parseNumericVariableUse(
    llvm::StringRef Name,
    bool IsPseudo,
    Optional<size_t> LineNumber,
    llvm::FileCheckPatternContext* Context,
    const llvm::SourceMgr& SM)

Description

Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use at line \p LineNumber, or before input is parsed if \p LineNumber is None. Parameter \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:805

Parameters

llvm::StringRef Name
bool IsPseudo
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

the pointer to the class instance representing that variable if successful, or an error holding a diagnostic against \p SM otherwise.

static Expected<std::unique_ptr<ExpressionAST>>
parseParenExpr(
    llvm::StringRef& Expr,
    Optional<size_t> LineNumber,
    llvm::FileCheckPatternContext* Context,
    const llvm::SourceMgr& SM)

Description

Parses a parenthesized expression inside \p Expr at line \p LineNumber, or before input is parsed if \p LineNumber is None. \p Expr must start with a '('. Accepts both literal values and numeric variables. Parameter \p Context points to the class instance holding the live string and numeric variables.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:844

Parameters

llvm::StringRef& Expr
Optional<size_t> LineNumber
llvm::FileCheckPatternContext* Context
const llvm::SourceMgr& SM

Returns

the class representing that operand in the AST of the expression or an error holding a diagnostic against \p SM otherwise.

bool parsePattern(
    llvm::StringRef PatternStr,
    llvm::StringRef Prefix,
    llvm::SourceMgr& SM,
    const llvm::FileCheckRequest& Req)

Description

Parses the pattern in \p PatternStr and initializes this Pattern instance accordingly. \p Prefix provides which prefix is being matched, \p Req describes the global options that influence the parsing such as whitespace canonicalization, \p SM provides the SourceMgr used for error reports.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:732

Parameters

llvm::StringRef PatternStr
llvm::StringRef Prefix
llvm::SourceMgr& SM
const llvm::FileCheckRequest& Req

Returns

true in case of an error, false otherwise.

static Expected<llvm::Pattern::VariableProperties>
parseVariable(llvm::StringRef& Str,
              const llvm::SourceMgr& SM)

Description

Parses the string at the start of \p Str for a variable name.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:709

Parameters

llvm::StringRef& Str
const llvm::SourceMgr& SM

Returns

a VariableProperties structure holding the variable name and whether it is the name of a pseudo variable, or an error holding a diagnostic against \p SM if parsing fail. If parsing was successful, also strips\p Str from the variable name.

void printFuzzyMatch(
    const llvm::SourceMgr& SM,
    llvm::StringRef Buffer,
    std::vector<FileCheckDiag>* Diags) const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:762

Parameters

const llvm::SourceMgr& SM
llvm::StringRef Buffer
std::vector<FileCheckDiag>* Diags

void printSubstitutions(
    const llvm::SourceMgr& SM,
    llvm::StringRef Buffer,
    llvm::SMRange MatchRange,
    FileCheckDiag::MatchType MatchTy,
    std::vector<FileCheckDiag>* Diags) const

Description

Prints the value of successful substitutions.

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:759

Parameters

const llvm::SourceMgr& SM
llvm::StringRef Buffer
llvm::SMRange MatchRange
FileCheckDiag::MatchType MatchTy
std::vector<FileCheckDiag>* Diags

void printVariableDefs(
    const llvm::SourceMgr& SM,
    FileCheckDiag::MatchType MatchTy,
    std::vector<FileCheckDiag>* Diags) const

Declared at: llvm/lib/FileCheck/FileCheckImpl.h:768

Parameters

const llvm::SourceMgr& SM
FileCheckDiag::MatchType MatchTy
std::vector<FileCheckDiag>* Diags