LLVM 17.0.0git
Functions | Variables
FileCheck.cpp File Reference
#include "llvm/FileCheck/FileCheck.h"
#include "FileCheckImpl.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/CheckedArithmetic.h"
#include "llvm/Support/FormatVariadic.h"
#include <cstdint>
#include <list>
#include <set>
#include <tuple>
#include <utility>
Include dependency graph for FileCheck.cpp:

Go to the source code of this file.

Functions

static int64_t getAsSigned (uint64_t UnsignedValue)
 
static char popFront (StringRef &S)
 
static SMRange ProcessMatchResult (FileCheckDiag::MatchType MatchTy, const SourceMgr &SM, SMLoc Loc, Check::FileCheckType CheckTy, StringRef Buffer, size_t Pos, size_t Len, std::vector< FileCheckDiag > *Diags, bool AdjustPrevDiags=false)
 
static bool IsPartOfWord (char c)
 
static std::pair< Check::FileCheckType, StringRefFindCheckType (const FileCheckRequest &Req, StringRef Buffer, StringRef Prefix, bool &Misspelled)
 
static std::pair< Check::FileCheckType, StringRefFindCheckType (const FileCheckRequest &Req, StringRef Buffer, StringRef Prefix)
 
static size_t SkipWord (StringRef Str, size_t Loc)
 
static std::pair< StringRef, StringRefFindFirstMatchingPrefix (const FileCheckRequest &Req, Regex &PrefixRE, StringRef &Buffer, unsigned &LineNumber, Check::FileCheckType &CheckTy)
 Searches the buffer for the first prefix in the prefix regular expression.
 
static Error printMatch (bool ExpectedMatch, const SourceMgr &SM, StringRef Prefix, SMLoc Loc, const Pattern &Pat, int MatchedCount, StringRef Buffer, Pattern::MatchResult MatchResult, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags)
 Returns either (1) ErrorSuccess if there was no error or (2) ErrorReported if an error was reported, such as an unexpected match.
 
static Error printNoMatch (bool ExpectedMatch, const SourceMgr &SM, StringRef Prefix, SMLoc Loc, const Pattern &Pat, int MatchedCount, StringRef Buffer, Error MatchError, bool VerboseVerbose, std::vector< FileCheckDiag > *Diags)
 Returns either (1) ErrorSuccess if there was no error, or (2) ErrorReported if an error was reported, such as an expected match not found.
 
static Error reportMatchResult (bool ExpectedMatch, const SourceMgr &SM, StringRef Prefix, SMLoc Loc, const Pattern &Pat, int MatchedCount, StringRef Buffer, Pattern::MatchResult MatchResult, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags)
 Returns either (1) ErrorSuccess if there was no error, or (2) ErrorReported if an error was reported.
 
static unsigned CountNumNewlinesBetween (StringRef Range, const char *&FirstNewLine)
 Counts the number of newlines in the specified range.
 
static bool ValidatePrefixes (StringRef Kind, StringSet<> &UniquePrefixes, ArrayRef< StringRef > SuppliedPrefixes)
 

Variables

constexpr StringLiteral SpaceChars = " \t"
 
static const charDefaultCheckPrefixes [] = {"CHECK"}
 
static const charDefaultCommentPrefixes [] = {"COM", "RUN"}
 

Function Documentation

◆ CountNumNewlinesBetween()

static unsigned CountNumNewlinesBetween ( StringRef  Range,
const char *&  FirstNewLine 
)
static

Counts the number of newlines in the specified range.

Definition at line 2242 of file FileCheck.cpp.

Referenced by llvm::FileCheckString::CheckNext(), and llvm::FileCheckString::CheckSame().

◆ FindCheckType() [1/2]

static std::pair< Check::FileCheckType, StringRef > FindCheckType ( const FileCheckRequest Req,
StringRef  Buffer,
StringRef  Prefix 
)
static

◆ FindCheckType() [2/2]

static std::pair< Check::FileCheckType, StringRef > FindCheckType ( const FileCheckRequest Req,
StringRef  Buffer,
StringRef  Prefix,
bool Misspelled 
)
static

◆ FindFirstMatchingPrefix()

static std::pair< StringRef, StringRef > FindFirstMatchingPrefix ( const FileCheckRequest Req,
Regex PrefixRE,
StringRef Buffer,
unsigned LineNumber,
Check::FileCheckType CheckTy 
)
static

Searches the buffer for the first prefix in the prefix regular expression.

This searches the buffer using the provided regular expression, however it enforces constraints beyond that: 1) The found prefix must not be a suffix of something that looks like a valid prefix. 2) The found prefix must be followed by a valid check type suffix using FindCheckType above.

Returns
a pair of StringRefs into the Buffer, which combines:
  • the first match of the regular expression to satisfy these two is returned, otherwise an empty StringRef is returned to indicate failure.
  • buffer rewound to the location right after parsed suffix, for parsing to continue from

If this routine returns a valid prefix, it will also shrink Buffer to start at the beginning of the returned prefix, increment LineNumber for each new line consumed from Buffer, and set CheckTy to the type of check found by examining the suffix.

If no valid prefix is found, the state of Buffer, LineNumber, and CheckTy is unspecified.

Definition at line 1814 of file FileCheck.cpp.

References assert(), llvm::StringRef::back(), llvm::Check::CheckNone, llvm::SmallVectorImpl< T >::clear(), llvm::StringRef::count(), llvm::StringRef::data(), llvm::StringRef::drop_front(), llvm::StringRef::empty(), FindCheckType(), IsPartOfWord(), llvm::Regex::match(), llvm::StringRef::size(), SkipWord(), and llvm::StringRef::substr().

Referenced by llvm::FileCheck::readCheckFile().

◆ getAsSigned()

static int64_t getAsSigned ( uint64_t  UnsignedValue)
static

◆ IsPartOfWord()

static bool IsPartOfWord ( char  c)
static

Definition at line 1621 of file FileCheck.cpp.

Referenced by FindFirstMatchingPrefix(), and SkipWord().

◆ popFront()

static char popFront ( StringRef S)
static

◆ printMatch()

static Error printMatch ( bool  ExpectedMatch,
const SourceMgr SM,
StringRef  Prefix,
SMLoc  Loc,
const Pattern Pat,
int  MatchedCount,
StringRef  Buffer,
Pattern::MatchResult  MatchResult,
const FileCheckRequest Req,
std::vector< FileCheckDiag > *  Diags 
)
static

◆ printNoMatch()

static Error printNoMatch ( bool  ExpectedMatch,
const SourceMgr SM,
StringRef  Prefix,
SMLoc  Loc,
const Pattern Pat,
int  MatchedCount,
StringRef  Buffer,
Error  MatchError,
bool  VerboseVerbose,
std::vector< FileCheckDiag > *  Diags 
)
static

◆ ProcessMatchResult()

static SMRange ProcessMatchResult ( FileCheckDiag::MatchType  MatchTy,
const SourceMgr SM,
SMLoc  Loc,
Check::FileCheckType  CheckTy,
StringRef  Buffer,
size_t  Pos,
size_t  Len,
std::vector< FileCheckDiag > *  Diags,
bool  AdjustPrevDiags = false 
)
static

◆ reportMatchResult()

static Error reportMatchResult ( bool  ExpectedMatch,
const SourceMgr SM,
StringRef  Prefix,
SMLoc  Loc,
const Pattern Pat,
int  MatchedCount,
StringRef  Buffer,
Pattern::MatchResult  MatchResult,
const FileCheckRequest Req,
std::vector< FileCheckDiag > *  Diags 
)
static

Returns either (1) ErrorSuccess if there was no error, or (2) ErrorReported if an error was reported.

Definition at line 2227 of file FileCheck.cpp.

References printMatch(), printNoMatch(), llvm::Pattern::MatchResult::TheError, llvm::Pattern::MatchResult::TheMatch, and llvm::FileCheckRequest::VerboseVerbose.

Referenced by llvm::FileCheckString::Check(), llvm::FileCheckString::CheckDag(), and llvm::FileCheckString::CheckNot().

◆ SkipWord()

static size_t SkipWord ( StringRef  Str,
size_t  Loc 
)
static

Definition at line 1784 of file FileCheck.cpp.

References IsPartOfWord().

Referenced by FindFirstMatchingPrefix().

◆ ValidatePrefixes()

static bool ValidatePrefixes ( StringRef  Kind,
StringSet<> &  UniquePrefixes,
ArrayRef< StringRef SuppliedPrefixes 
)
static

Variable Documentation

◆ DefaultCheckPrefixes

const char* DefaultCheckPrefixes[] = {"CHECK"}
static

◆ DefaultCommentPrefixes

const char* DefaultCommentPrefixes[] = {"COM", "RUN"}
static

◆ SpaceChars

constexpr StringLiteral SpaceChars = " \t"
constexpr

Definition at line 466 of file FileCheck.cpp.

Referenced by llvm::Pattern::parseNumericSubstitutionBlock().