LLVM  10.0.0svn
Classes | Public Member Functions | Static Public Member Functions | List of all members
llvm::FileCheckPattern Class Reference

#include "llvm/Support/FileCheck.h"

Classes

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

Public Member Functions

 FileCheckPattern (Check::FileCheckType Ty, FileCheckPatternContext *Context, Optional< size_t > Line=None)
 
SMLoc getLoc () const
 
FileCheckPatternContextgetContext () const
 
Expected< std::unique_ptr< FileCheckExpressionAST > > parseNumericSubstitutionBlock (StringRef Expr, Optional< FileCheckNumericVariable *> &DefinedNumericVariable, bool IsLegacyLineExpr, const SourceMgr &SM) const
 Parses Expr for a numeric substitution block. More...
 
bool parsePattern (StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
 Parses the pattern in PatternStr and initializes this FileCheckPattern instance accordingly. More...
 
Expected< size_t > match (StringRef Buffer, size_t &MatchLen, const SourceMgr &SM) const
 Matches the pattern string against the input buffer Buffer. More...
 
void printSubstitutions (const SourceMgr &SM, StringRef Buffer, SMRange MatchRange=None) const
 Prints the value of successful substitutions or the name of the undefined string or numeric variables preventing a successful substitution. More...
 
void printFuzzyMatch (const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
 
bool hasVariable () 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< FileCheckNumericVariable * > parseNumericVariableDefinition (StringRef &Expr, FileCheckPatternContext *Context, Optional< size_t > LineNumber, const SourceMgr &SM)
 Parses Expr for the name of a numeric variable to be defined at line LineNumber or before input is parsed if LineNumber is None. More...
 

Detailed Description

Definition at line 415 of file FileCheck.h.

Constructor & Destructor Documentation

◆ FileCheckPattern()

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

Definition at line 483 of file FileCheck.h.

Member Function Documentation

◆ getCheckTy()

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

Definition at line 565 of file FileCheck.h.

Referenced by llvm::FileCheck::CheckInput(), PrintMatch(), and PrintNoMatch().

◆ getContext()

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

Definition at line 492 of file FileCheck.h.

References C, and Context.

◆ getCount()

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

Definition at line 567 of file FileCheck.h.

References llvm::Check::FileCheckType::getCount(), llvm::Literal, and Name.

Referenced by PrintMatch(), and PrintNoMatch().

◆ getLoc()

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

Definition at line 488 of file FileCheck.h.

◆ hasVariable()

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

Definition at line 561 of file FileCheck.h.

◆ isValidVarNameStart()

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

Definition at line 67 of file FileCheck.cpp.

◆ match()

Expected< size_t > FileCheckPattern::match ( StringRef  Buffer,
size_t &  MatchLen,
const SourceMgr SM 
) const

Matches the pattern string against the input buffer Buffer.

Returns
the position that is matched or an error indicating why matching failed. If there is a match, updates MatchLen with the size of the matched string.

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

References assert(), llvm::Check::CheckEmpty, llvm::Check::CheckEOF, Context, llvm::StringRef::data(), llvm::StringRef::edit_distance(), llvm::SmallVectorBase::empty(), llvm::StringRef::empty(), llvm::StringRef::find(), llvm::FileCheckErrorDiagnostic::get(), llvm::StringRef::getAsInteger(), llvm::PatternMatch::match(), llvm::Regex::Newline, llvm::StringRef::npos, llvm::SmallVectorBase::size(), llvm::StringRef::size(), llvm::StringRef::split(), llvm::StringRef::substr(), and llvm::Expected< T >::takeError().

◆ parseNumericSubstitutionBlock()

Expected< std::unique_ptr< FileCheckExpressionAST > > FileCheckPattern::parseNumericSubstitutionBlock ( StringRef  Expr,
Optional< FileCheckNumericVariable *> &  DefinedNumericVariable,
bool  IsLegacyLineExpr,
const SourceMgr SM 
) const

Parses Expr for a numeric substitution block.

Parameter IsLegacyLineExpr indicates whether Expr should be a legacy expression.

Returns
a pointer to the class instance representing the AST of the expression whose value must be substituted, 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 being defined in this numeric substitution block, or None if this block does not define any variable.

Definition at line 259 of file FileCheck.cpp.

References llvm::SystemZICMP::Any, Context, llvm::StringRef::empty(), llvm::StringRef::find(), llvm::FileCheckErrorDiagnostic::get(), llvm::StringRef::ltrim(), llvm::None, llvm::StringRef::npos, llvm::StringRef::substr(), and llvm::Expected< T >::takeError().

◆ parseNumericVariableDefinition()

Expected< FileCheckNumericVariable * > FileCheckPattern::parseNumericVariableDefinition ( StringRef Expr,
FileCheckPatternContext Context,
Optional< size_t >  LineNumber,
const SourceMgr SM 
)
static

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

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

Definition at line 115 of file FileCheck.cpp.

References llvm::SystemZICMP::Any, llvm::consumeError(), llvm::StringRef::consumeInteger(), Context, llvm::StringRef::empty(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringRef::equals(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::FileCheckErrorDiagnostic::get(), llvm::FileCheckNumericVariable::getDefLineNumber(), llvm::StringRef::ltrim(), and llvm::Expected< T >::takeError().

Referenced by llvm::FileCheckPatternContext::defineCmdlineVariables().

◆ parsePattern()

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

Parses the pattern in PatternStr and initializes this FileCheckPattern 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 308 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::MatchFullLines, llvm::FileCheckRequest::NoCanonicalizeWhiteSpace, llvm::StringRef::npos, llvm::SourceMgr::PrintMessage(), llvm::StringRef::size(), llvm::StringRef::startswith(), and llvm::StringRef::substr().

◆ parseVariable()

Expected< FileCheckPattern::VariableProperties > FileCheckPattern::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 72 of file FileCheck.cpp.

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

Referenced by llvm::FileCheckPatternContext::defineCmdlineVariables().

◆ printFuzzyMatch()

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

◆ printSubstitutions()

void FileCheckPattern::printSubstitutions ( const SourceMgr SM,
StringRef  Buffer,
SMRange  MatchRange = None 
) const

Prints the value of successful substitutions or the name of the undefined string or numeric variables preventing a successful substitution.

Definition at line 693 of file FileCheck.cpp.

References llvm::StringRef::data(), llvm::SourceMgr::DK_Note, E, llvm::SMLoc::getFromPointer(), llvm::handleAllErrors(), llvm::SMRange::isValid(), llvm::SourceMgr::PrintMessage(), llvm::SMRange::Start, llvm::raw_svector_ostream::str(), llvm::Expected< T >::takeError(), and llvm::raw_ostream::write_escaped().

Referenced by PrintMatch(), and PrintNoMatch().


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