15#ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
16#define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
55 unsigned Precision = 0;
57 bool AlternateForm =
false;
67 Precision ==
Other.Precision && AlternateForm ==
Other.AlternateForm;
71 return !(*
this ==
Other);
86 :
Value(
Value), Precision(Precision), AlternateForm(AlternateForm){};
110 return std::make_error_code(std::errc::value_too_large);
118Expected<APInt>
exprAdd(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
119Expected<APInt>
exprSub(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
120Expected<APInt>
exprMul(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
121Expected<APInt>
exprDiv(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
122Expected<APInt>
exprMax(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
123Expected<APInt>
exprMin(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
184 OS <<
"undefined variable: " << VarName;
192 std::unique_ptr<ExpressionAST> AST;
201 : AST(
std::
move(AST)), Format(Format) {}
221 std::optional<APInt>
Value;
225 std::optional<StringRef> StrValue;
230 std::optional<size_t> DefLineNumber;
237 std::optional<size_t> DefLineNumber = std::nullopt)
238 : Name(Name), ImplicitFormat(ImplicitFormat),
239 DefLineNumber(DefLineNumber) {}
261 std::optional<StringRef> NewStrValue = std::nullopt) {
263 StrValue = NewStrValue;
269 Value = std::nullopt;
270 StrValue = std::nullopt;
305 std::unique_ptr<ExpressionAST> LeftOperand;
308 std::unique_ptr<ExpressionAST> RightOperand;
315 std::unique_ptr<ExpressionAST> LeftOp,
316 std::unique_ptr<ExpressionAST> RightOp)
318 LeftOperand = std::move(LeftOp);
319 RightOperand = std::move(RightOp);
336class FileCheckPatternContext;
389 std::unique_ptr<Expression> ExpressionPointer;
393 std::unique_ptr<Expression> ExpressionPointer,
396 ExpressionPointer(
std::
move(ExpressionPointer)) {}
437 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
441 std::vector<std::unique_ptr<Expression>> Expressions;
445 std::vector<std::unique_ptr<Substitution>> Substitutions;
509 SMRange Range = std::nullopt) {
510 return make_error<ErrorDiagnostic>(
531 OS <<
"String not found in input";
555 OS <<
"error previously reported";
559 if (HasErrorReported)
560 return make_error<ErrorReported>();
574 std::string RegExStr;
582 std::vector<Substitution *> Substitutions;
595 std::map<StringRef, unsigned> VariableDefs;
601 struct NumericVariableMatch {
608 unsigned CaptureParenGroup;
629 std::optional<size_t> LineNumber;
632 bool IgnoreCase =
false;
636 std::optional<size_t> Line = std::nullopt)
637 : Context(Context), CheckTy(Ty), LineNumber(Line) {}
673 StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
674 bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
712 std::vector<FileCheckDiag> *Diags)
const;
714 std::vector<FileCheckDiag> *Diags)
const;
717 return !(Substitutions.empty() && VariableDefs.empty());
720 std::vector<FileCheckDiag> *Diags)
const;
728 void AddBackrefToRegEx(
unsigned BackrefNum);
732 unsigned computeMatchDistance(
StringRef Buffer)
const;
757 StringRef Name,
bool IsPseudo, std::optional<size_t> LineNumber,
759 enum class AllowedOperand { LineVar, LegacyLiteral,
Any };
769 static Expected<std::unique_ptr<ExpressionAST>>
770 parseNumericOperand(StringRef &Expr, AllowedOperand AO,
bool ConstraintParsed,
771 std::optional<size_t> LineNumber,
772 FileCheckPatternContext *Context,
const SourceMgr &SM);
782 static Expected<std::unique_ptr<ExpressionAST>>
783 parseBinop(StringRef Expr, StringRef &RemainingExpr,
784 std::unique_ptr<ExpressionAST> LeftOp,
bool IsLegacyLineExpr,
785 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
786 const SourceMgr &SM);
794 static Expected<std::unique_ptr<ExpressionAST>>
795 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
796 FileCheckPatternContext *Context,
const SourceMgr &SM);
805 static Expected<std::unique_ptr<ExpressionAST>>
806 parseCallExpr(StringRef &Expr, StringRef FuncName,
807 std::optional<size_t> LineNumber,
808 FileCheckPatternContext *Context,
const SourceMgr &SM);
846 std::vector<FileCheckDiag> *Diags)
const;
858 const std::vector<const DagNotPrefixInfo *> &NotStrings,
860 std::vector<FileCheckDiag> *Diags)
const;
863 std::vector<const DagNotPrefixInfo *> &NotStrings,
865 std::vector<FileCheckDiag> *Diags)
const;
This file defines the StringMap class.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Class for arbitrary precision integers.
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< APInt > 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.
ExpressionAST(StringRef ExpressionStr)
virtual Expected< APInt > eval() const =0
Evaluates and.
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, APInt Val)
Expected< APInt > eval() const override
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< APInt > 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.
void setValue(APInt 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...
ExpressionFormat getImplicitFormat() const
StringRef getName() const
std::optional< StringRef > getStringValue() const
std::optional< APInt > 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 ...
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...
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
StringRef getMessage() 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.
constexpr 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.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Expected< APInt > exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Performs operation and.
Expected< APInt > exprMul(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Expected< APInt > exprMax(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprSub(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Implement std::hash so that hash_code can be used in STL containers.
MatchType
What type of match result does this diagnostic describe?
Contains info about various FileCheck options.
Hold the information about the DAG/NOT strings in the program, which are not explicitly stored otherw...
DagNotPrefixInfo(const Pattern &P, StringRef S)
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.
FileCheckString(const Pattern &P, StringRef S, SMLoc L)
std::vector< DagNotPrefixInfo > DagNotStrings
Hold the DAG/NOT strings occurring in the input file.
SMLoc Loc
The location in the match file that the check string was specified.
StringRef Prefix
Which prefix name this check matched.
size_t CheckDag(const SourceMgr &SM, StringRef Buffer, std::vector< const DagNotPrefixInfo * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Matches "dag strings" and their mixed "not strings".
bool CheckNot(const SourceMgr &SM, StringRef Buffer, const std::vector< const DagNotPrefixInfo * > &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.