LLVM  13.0.0git
Classes | Public Member Functions | Static Public Member Functions | List of all members
llvm::Pattern Class Reference

#include "FileCheck/FileCheckImpl.h"

Classes

struct  Match
 
struct  MatchResult
 
struct  VariableProperties
 Parsing information about a variable. More...
 

Public Member Functions

 Pattern (Check::FileCheckType Ty, FileCheckPatternContext *Context, Optional< size_t > Line=None)
 
SMLoc getLoc () const
 
FileCheckPatternContextgetContext () const
 
bool parsePattern (StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
 Parses the pattern in PatternStr and initializes this Pattern instance accordingly. More...
 
MatchResult match (StringRef Buffer, const SourceMgr &SM) const
 Matches the pattern string against the input buffer Buffer. More...
 
void printSubstitutions (const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
 Prints the value of successful substitutions. More...
 
void printFuzzyMatch (const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
 
bool hasVariable () const
 
void printVariableDefs (const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
 
Check::FileCheckType getCheckTy () const
 
int getCount () const
 

Static Public Member Functions

static bool isValidVarNameStart (char C)
 
static Expected< VariablePropertiesparseVariable (StringRef &Str, const SourceMgr &SM)
 Parses the string at the start of Str for a variable name. More...
 
static Expected< std::unique_ptr< Expression > > parseNumericSubstitutionBlock (StringRef Expr, Optional< NumericVariable * > &DefinedNumericVariable, bool IsLegacyLineExpr, 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 LineNumber is None. More...
 

Detailed Description

Definition at line 614 of file FileCheckImpl.h.

Constructor & Destructor Documentation

◆ Pattern()

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

Definition at line 684 of file FileCheckImpl.h.

References Context.

Member Function Documentation

◆ getCheckTy()

Check::FileCheckType llvm::Pattern::getCheckTy ( ) const
inline

Definition at line 771 of file FileCheckImpl.h.

◆ getContext()

FileCheckPatternContext* llvm::Pattern::getContext ( ) const
inline
Returns
the pointer to the global state for all patterns in this FileCheck instance.

Definition at line 693 of file FileCheckImpl.h.

References Context.

◆ getCount()

int llvm::Pattern::getCount ( ) const
inline

Definition at line 773 of file FileCheckImpl.h.

References llvm::Check::FileCheckType::getCount().

◆ getLoc()

SMLoc llvm::Pattern::getLoc ( ) const
inline
Returns
the location in source code.

Definition at line 689 of file FileCheckImpl.h.

◆ hasVariable()

bool llvm::Pattern::hasVariable ( ) const
inline

Definition at line 765 of file FileCheckImpl.h.

◆ isValidVarNameStart()

bool Pattern::isValidVarNameStart ( char  C)
static
Returns
whether C is a valid first character for a variable name.

Definition at line 437 of file FileCheck.cpp.

Referenced by parseVariable().

◆ match()

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

Matches the pattern string against the input buffer Buffer.

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

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.

◆ parseNumericSubstitutionBlock()

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

Parses Expr for a numeric substitution block at line LineNumber, or before input is parsed if LineNumber is None.

Parameter IsLegacyLineExpr indicates whether Expr should be a legacy @LINE expression and Context points to the class instance holding the live string and numeric variables.

Returns
a pointer to the class instance representing the expression whose value must be substitued, or an error holding a diagnostic against SM if parsing fails. If substitution was successful, sets 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.

Definition at line 767 of file FileCheck.cpp.

References llvm::StringRef::consume_front(), llvm::StringRef::consumeInteger(), Context, llvm::StringRef::data(), llvm::StringRef::drop_front(), llvm::StringRef::empty(), llvm::StringRef::find(), llvm::ErrorDiagnostic::get(), llvm::SMLoc::getFromPointer(), llvm::ExpressionFormat::HexLower, llvm::ExpressionFormat::HexUpper, llvm::StringRef::ltrim(), move, llvm::None, llvm::StringRef::npos, popFront(), llvm::StringRef::rtrim(), llvm::ExpressionFormat::Signed, SpaceChars, llvm::StringRef::substr(), llvm::StringRef::take_front(), llvm::Expected< T >::takeError(), llvm::StringRef::trim(), and llvm::ExpressionFormat::Unsigned.

◆ parsePattern()

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

Parses the pattern in PatternStr and initializes this Pattern instance accordingly.

Prefix provides which prefix is being matched, Req describes the global options that influence the parsing such as whitespace canonicalization, SM provides the SourceMgr used for error reports.

Returns
true in case of an error, false otherwise.

Definition at line 916 of file FileCheck.cpp.

References llvm::StringRef::back(), llvm::Check::CheckEmpty, llvm::Check::CheckNot, llvm::StringRef::data(), llvm::SourceMgr::DK_Error, llvm::StringRef::empty(), llvm::StringRef::find(), llvm::SMLoc::getFromPointer(), llvm::FileCheckRequest::IgnoreCase, llvm::Check::FileCheckType::isLiteralMatch(), llvm::FileCheckRequest::MatchFullLines, llvm::FileCheckRequest::NoCanonicalizeWhiteSpace, llvm::StringRef::npos, llvm::cl::Prefix, llvm::SourceMgr::PrintMessage(), llvm::StringRef::size(), llvm::StringRef::startswith(), and llvm::StringRef::substr().

◆ parseVariable()

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

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

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 SM if parsing fail. If parsing was successful, also strips Str from the variable name.

Definition at line 440 of file FileCheck.cpp.

References E, llvm::StringRef::empty(), llvm::ErrorDiagnostic::get(), I, isValidVarNameStart(), llvm::StringRef::size(), llvm::StringRef::substr(), and llvm::StringRef::take_front().

◆ printFuzzyMatch()

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

◆ printSubstitutions()

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

Prints the value of successful substitutions.

◆ printVariableDefs()

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

The documentation for this class was generated from the following files: