15#ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
16#define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
56 unsigned Precision = 0;
58 bool AlternateForm =
false;
68 Precision ==
Other.Precision && AlternateForm ==
Other.AlternateForm;
72 return !(*
this ==
Other);
87 :
Value(
Value), Precision(Precision), AlternateForm(AlternateForm){};
114 return std::make_error_code(std::errc::value_too_large);
135 return !(*
this ==
Other);
140 assert((
Value != 0 || !Negative) &&
"Unexpected negative zero!");
159Expected<ExpressionValue>
operator+(
const ExpressionValue &Lhs,
160 const ExpressionValue &Rhs);
161Expected<ExpressionValue>
operator-(
const ExpressionValue &Lhs,
162 const ExpressionValue &Rhs);
163Expected<ExpressionValue>
operator*(
const ExpressionValue &Lhs,
164 const ExpressionValue &Rhs);
165Expected<ExpressionValue>
operator/(
const ExpressionValue &Lhs,
166 const ExpressionValue &Rhs);
167Expected<ExpressionValue>
max(
const ExpressionValue &Lhs,
168 const ExpressionValue &Rhs);
169Expected<ExpressionValue>
min(
const ExpressionValue &Lhs,
170 const ExpressionValue &Rhs);
232 OS <<
"undefined variable: " << VarName;
240 std::unique_ptr<ExpressionAST> AST;
249 : AST(
std::
move(AST)), Format(Format) {}
269 std::optional<ExpressionValue>
Value;
273 std::optional<StringRef> StrValue;
278 std::optional<size_t> DefLineNumber;
285 std::optional<size_t> DefLineNumber = std::nullopt)
286 : Name(Name), ImplicitFormat(ImplicitFormat),
287 DefLineNumber(DefLineNumber) {}
309 std::optional<StringRef> NewStrValue = std::nullopt) {
311 StrValue = NewStrValue;
317 Value = std::nullopt;
318 StrValue = std::nullopt;
354 std::unique_ptr<ExpressionAST> LeftOperand;
357 std::unique_ptr<ExpressionAST> RightOperand;
364 std::unique_ptr<ExpressionAST> LeftOp,
365 std::unique_ptr<ExpressionAST> RightOp)
367 LeftOperand = std::move(LeftOp);
368 RightOperand = std::move(RightOp);
385class FileCheckPatternContext;
438 std::unique_ptr<Expression> ExpressionPointer;
442 std::unique_ptr<Expression> ExpressionPointer,
445 ExpressionPointer(
std::
move(ExpressionPointer)) {}
486 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
490 std::vector<std::unique_ptr<Expression>> Expressions;
494 std::vector<std::unique_ptr<Substitution>> Substitutions;
545 : Diagnostic(Diag), Range(Range) {}
558 SMRange Range = std::nullopt) {
559 return make_error<ErrorDiagnostic>(
580 OS <<
"String not found in input";
604 OS <<
"error previously reported";
608 if (HasErrorReported)
609 return make_error<ErrorReported>();
623 std::string RegExStr;
631 std::vector<Substitution *> Substitutions;
644 std::map<StringRef, unsigned> VariableDefs;
650 struct NumericVariableMatch {
657 unsigned CaptureParenGroup;
678 std::optional<size_t> LineNumber;
681 bool IgnoreCase =
false;
685 std::optional<size_t> Line = std::nullopt)
722 StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
723 bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
761 std::vector<FileCheckDiag> *Diags)
const;
763 std::vector<FileCheckDiag> *Diags)
const;
766 return !(Substitutions.empty() && VariableDefs.empty());
769 std::vector<FileCheckDiag> *Diags)
const;
777 void AddBackrefToRegEx(
unsigned BackrefNum);
781 unsigned computeMatchDistance(
StringRef Buffer)
const;
806 StringRef Name,
bool IsPseudo, std::optional<size_t> LineNumber,
808 enum class AllowedOperand { LineVar, LegacyLiteral,
Any };
818 static Expected<std::unique_ptr<ExpressionAST>>
819 parseNumericOperand(StringRef &Expr, AllowedOperand AO,
bool ConstraintParsed,
820 std::optional<size_t> LineNumber,
821 FileCheckPatternContext *Context,
const SourceMgr &SM);
831 static Expected<std::unique_ptr<ExpressionAST>>
832 parseBinop(StringRef Expr, StringRef &RemainingExpr,
833 std::unique_ptr<ExpressionAST> LeftOp,
bool IsLegacyLineExpr,
834 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
835 const SourceMgr &SM);
843 static Expected<std::unique_ptr<ExpressionAST>>
844 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
845 FileCheckPatternContext *Context,
const SourceMgr &SM);
854 static Expected<std::unique_ptr<ExpressionAST>>
855 parseCallExpr(StringRef &Expr, StringRef FuncName,
856 std::optional<size_t> LineNumber,
857 FileCheckPatternContext *Context,
const SourceMgr &SM);
885 std::vector<FileCheckDiag> *Diags)
const;
897 const std::vector<const Pattern *> &NotStrings,
899 std::vector<FileCheckDiag> *Diags)
const;
902 std::vector<const Pattern *> &NotStrings,
904 std::vector<FileCheckDiag> *Diags)
const;
This file defines the StringMap class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class representing a single binary operation in the AST of an expression.
BinaryOperation(StringRef ExpressionStr, binop_eval_t EvalBinop, std::unique_ptr< ExpressionAST > LeftOp, std::unique_ptr< ExpressionAST > RightOp)
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Expected< ExpressionValue > eval() const override
Evaluates the value of the binary operation represented by this AST, using EvalBinop on the result of...
Class to represent an error holding a diagnostic with location information used when printing it.
StringRef getMessage() const
ErrorDiagnostic(SMDiagnostic &&Diag, SMRange Range)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
static Error get(const SourceMgr &SM, StringRef Buffer, const Twine &ErrMsg)
static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg, SMRange Range=std::nullopt)
Base class for user error types.
An error that has already been reported.
static Error reportedOrSuccess(bool HasErrorReported)
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Base class representing the AST of a given expression.
virtual Expected< ExpressionValue > eval() const =0
Evaluates and.
ExpressionAST(StringRef ExpressionStr)
StringRef getExpressionStr() const
virtual ~ExpressionAST()=default
virtual Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const
Class representing an unsigned literal in the AST of an expression.
ExpressionLiteral(StringRef ExpressionStr, T Val)
Expected< ExpressionValue > eval() const override
Class representing a numeric value.
bool operator!=(const ExpressionValue &Other) const
bool operator==(const ExpressionValue &Other) const
ExpressionValue getAbsolute() const
bool isNegative() const
Returns true if value is signed and negative, false otherwise.
Expected< int64_t > getSignedValue() const
Expected< uint64_t > getUnsignedValue() const
Class representing an expression and its matching format.
ExpressionFormat getFormat() const
Expression(std::unique_ptr< ExpressionAST > AST, ExpressionFormat Format)
Generic constructor for an expression represented by the given AST and whose matching format is Forma...
ExpressionAST * getAST() const
Class holding the Pattern global state, shared by all patterns: tables holding values of variables an...
Error defineCmdlineVariables(ArrayRef< StringRef > CmdlineDefines, SourceMgr &SM)
Defines string and numeric variables from definitions given on the command line, passed as a vector o...
void createLineVariable()
Create @LINE pseudo variable.
Expected< StringRef > getPatternVarValue(StringRef VarName)
void clearLocalVars()
Undefines local variables (variables whose name does not start with a '$' sign), i....
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Expected< std::string > getResult() const override
NumericSubstitution(FileCheckPatternContext *Context, StringRef ExpressionStr, std::unique_ptr< Expression > ExpressionPointer, size_t InsertIdx)
Class representing the use of a numeric variable in the AST of an expression.
NumericVariableUse(StringRef Name, NumericVariable *Variable)
Expected< ExpressionValue > eval() const override
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Class representing a numeric variable and its associated current value.
void clearValue()
Clears value of this numeric variable, regardless of whether it is currently defined or not.
ExpressionFormat getImplicitFormat() const
StringRef getName() const
std::optional< StringRef > getStringValue() const
std::optional< ExpressionValue > getValue() const
NumericVariable(StringRef Name, ExpressionFormat ImplicitFormat, std::optional< size_t > DefLineNumber=std::nullopt)
Constructor for a variable Name with implicit format ImplicitFormat defined at line DefLineNumber or ...
void setValue(ExpressionValue NewValue, std::optional< StringRef > NewStrValue=std::nullopt)
Sets value of this numeric variable to NewValue, and sets the input buffer string from which it was p...
std::optional< size_t > getDefLineNumber() const
Class to represent an overflow error that might result when manipulating a value.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
static Expected< VariableProperties > parseVariable(StringRef &Str, const SourceMgr &SM)
Parses the string at the start of Str for a variable name.
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
void printFuzzyMatch(const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
void printSubstitutions(const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Prints the value of successful substitutions.
FileCheckPatternContext * getContext() const
static 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 LineNum...
Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, std::optional< size_t > Line=std::nullopt)
void printVariableDefs(const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
static bool isValidVarNameStart(char C)
Check::FileCheckType getCheckTy() const
bool parsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
Parses the pattern in PatternStr and initializes this Pattern instance accordingly.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
StringRef getMessage() const
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
Represents a range in source code.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringSubstitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
Expected< std::string > getResult() const override
Class representing a substitution to perform in the RegExStr string.
virtual ~Substitution()=default
Substitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
StringRef getFromString() const
FileCheckPatternContext * Context
Pointer to a class instance holding, among other things, the table with the values of live string var...
StringRef FromStr
The string that needs to be substituted for something else.
virtual Expected< std::string > getResult() const =0
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Class to represent an undefined variable error, which quotes that variable's name when printed.
UndefVarError(StringRef VarName)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
StringRef getVarName() const
void log(raw_ostream &OS) const override
Print name of variable associated with this error.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
APInt operator*(APInt a, uint64_t RHS)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
InstructionCost operator/(const InstructionCost &LHS, const InstructionCost &RHS)
APInt operator+(APInt a, const APInt &b)
MatchType
What type of match result does this diagnostic describe?
Contains info about various FileCheck options.
A check that we found in the input file.
bool CheckNext(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is a single line in the given Buffer.
Pattern Pat
The pattern to match.
bool CheckSame(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is no newline in the given Buffer.
size_t CheckDag(const SourceMgr &SM, StringRef Buffer, std::vector< const Pattern * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Matches "dag strings" and their mixed "not strings".
FileCheckString(const Pattern &P, StringRef S, SMLoc L)
SMLoc Loc
The location in the match file that the check string was specified.
StringRef Prefix
Which prefix name this check matched.
std::vector< Pattern > DagNotStrings
All of the strings that are disallowed from occurring between this match string and the previous one ...
bool CheckNot(const SourceMgr &SM, StringRef Buffer, const std::vector< const Pattern * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Verifies that none of the strings in NotStrings are found in the given Buffer.
MatchResult(Match M, Error E)
MatchResult(size_t MatchPos, size_t MatchLen, Error E)
std::optional< Match > TheMatch
Parsing information about a variable.