LLVM 22.0.0git
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, std::optional< size_t > Line=std::nullopt)
SMLoc getLoc () const
FileCheckPatternContextgetContext () const
LLVM_ABI_FOR_TEST bool parsePattern (StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
 Parses the pattern in PatternStr and initializes this Pattern instance accordingly.
LLVM_ABI_FOR_TEST MatchResult match (StringRef Buffer, const SourceMgr &SM) const
 Matches the pattern string against the input buffer Buffer.
void printSubstitutions (const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
 Prints the value of successful substitutions.
void printFuzzyMatch (const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
bool hasVariable () const
LLVM_ABI_FOR_TEST 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 LLVM_ABI_FOR_TEST bool isValidVarNameStart (char C)
static LLVM_ABI_FOR_TEST Expected< VariablePropertiesparseVariable (StringRef &Str, const SourceMgr &SM)
 Parses the string at the start of Str for a variable name.
static LLVM_ABI_FOR_TEST 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 LineNumber is None.

Detailed Description

Definition at line 587 of file FileCheckImpl.h.

Constructor & Destructor Documentation

◆ Pattern()

llvm::Pattern::Pattern ( Check::FileCheckType Ty,
FileCheckPatternContext * Context,
std::optional< size_t > Line = std::nullopt )
inline

Definition at line 657 of file FileCheckImpl.h.

Member Function Documentation

◆ getCheckTy()

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

◆ getContext()

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

Definition at line 666 of file FileCheckImpl.h.

◆ getCount()

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

Definition at line 750 of file FileCheckImpl.h.

Referenced by printMatch(), and printNoMatch().

◆ getLoc()

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

Definition at line 662 of file FileCheckImpl.h.

Referenced by printFuzzyMatch(), printSubstitutions(), and printVariableDefs().

◆ hasVariable()

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

Definition at line 741 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 326 of file FileCheck.cpp.

References llvm::CallingConv::C, and llvm::isAlpha().

Referenced by parseVariable().

◆ match()

Pattern::MatchResult 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.

Definition at line 1116 of file FileCheck.cpp.

References assert(), llvm::Check::CheckEmpty, llvm::Check::CheckEOF, llvm::StringRef::data(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::StringRef::find(), llvm::StringRef::find_insensitive(), llvm::Format, llvm::NumericVariable::getImplicitFormat(), llvm::Substitution::getIndex(), llvm::Substitution::getResultRegex(), llvm::handleErrors(), llvm::Regex::IgnoreCase, llvm::joinErrors(), llvm::Pattern::Match::Len, llvm::make_error(), match(), llvm::Regex::Newline, llvm::StringRef::npos, llvm::Pattern::Match::Pos, llvm::NumericVariable::setValue(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::StringRef::size(), and llvm::Error::success().

Referenced by llvm::ifs::filterIFSSyms(), and match().

◆ parseNumericSubstitutionBlock()

Expected< std::unique_ptr< Expression > > Pattern::parseNumericSubstitutionBlock ( StringRef Expr,
std::optional< NumericVariable * > & DefinedNumericVariable,
bool IsLegacyLineExpr,
std::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 std::nullopt if this block does not define any variable.

Definition at line 654 of file FileCheck.cpp.

References llvm::StringRef::consume_front(), llvm::StringRef::consumeInteger(), llvm::StringRef::data(), llvm::StringRef::drop_front(), llvm::StringRef::empty(), llvm::StringRef::find(), llvm::Format, llvm::ErrorDiagnostic::get(), llvm::SMLoc::getFromPointer(), llvm::ExpressionFormat::HexLower, llvm::ExpressionFormat::HexUpper, llvm::StringRef::ltrim(), 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.

Referenced by llvm::FileCheckPatternContext::defineCmdlineVariables(), and parsePattern().

◆ parsePattern()

◆ 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 329 of file FileCheck.cpp.

References llvm::ErrorDiagnostic::get(), I, llvm::isAlnum(), and isValidVarNameStart().

Referenced by llvm::FileCheckPatternContext::defineCmdlineVariables(), and parsePattern().

◆ printFuzzyMatch()

◆ printSubstitutions()

◆ printVariableDefs()


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