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){};
112 return std::make_error_code(std::errc::value_too_large);
128Expected<APInt>
exprMax(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
129Expected<APInt>
exprMin(
const APInt &Lhs,
const APInt &Rhs,
bool &Overflow);
190 OS <<
"undefined variable: " << VarName;
198 std::unique_ptr<ExpressionAST> AST;
207 : AST(
std::
move(AST)), Format(Format) {}
227 std::optional<APInt>
Value;
231 std::optional<StringRef> StrValue;
236 std::optional<size_t> DefLineNumber;
243 std::optional<size_t> DefLineNumber = std::nullopt)
244 : Name(Name), ImplicitFormat(ImplicitFormat),
245 DefLineNumber(DefLineNumber) {}
267 std::optional<StringRef> NewStrValue = std::nullopt) {
269 StrValue = NewStrValue;
275 Value = std::nullopt;
276 StrValue = std::nullopt;
311 std::unique_ptr<ExpressionAST> LeftOperand;
314 std::unique_ptr<ExpressionAST> RightOperand;
321 std::unique_ptr<ExpressionAST> LeftOp,
322 std::unique_ptr<ExpressionAST> RightOp)
324 LeftOperand = std::move(LeftOp);
325 RightOperand = std::move(RightOp);
339 getImplicitFormat(
const SourceMgr &SM)
const override;
342class FileCheckPatternContext;
406 std::unique_ptr<Expression> ExpressionPointer;
410 std::unique_ptr<Expression> ExpressionPointer,
413 ExpressionPointer(
std::
move(ExpressionPointer)) {}
459 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
463 std::vector<std::unique_ptr<Expression>> Expressions;
467 std::vector<std::unique_ptr<Substitution>> Substitutions;
531 SMRange Range = std::nullopt) {
532 return make_error<ErrorDiagnostic>(
553 OS <<
"String not found in input";
577 OS <<
"error previously reported";
581 if (HasErrorReported)
582 return make_error<ErrorReported>();
596 std::string RegExStr;
604 std::vector<Substitution *> Substitutions;
617 std::map<StringRef, unsigned> VariableDefs;
623 struct NumericVariableMatch {
630 unsigned CaptureParenGroup;
651 std::optional<size_t> LineNumber;
654 bool IgnoreCase =
false;
658 std::optional<size_t> Line = std::nullopt)
696 StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
697 bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
737 std::vector<FileCheckDiag> *Diags)
const;
739 std::vector<FileCheckDiag> *Diags)
const;
742 return !(Substitutions.empty() && VariableDefs.empty());
746 std::vector<FileCheckDiag> *Diags)
const;
754 void AddBackrefToRegEx(
unsigned BackrefNum);
758 unsigned computeMatchDistance(
StringRef Buffer)
const;
783 StringRef Name,
bool IsPseudo, std::optional<size_t> LineNumber,
785 enum class AllowedOperand { LineVar, LegacyLiteral,
Any };
795 static Expected<std::unique_ptr<ExpressionAST>>
796 parseNumericOperand(StringRef &Expr, AllowedOperand AO,
bool ConstraintParsed,
797 std::optional<size_t> LineNumber,
798 FileCheckPatternContext *Context,
const SourceMgr &SM);
808 static Expected<std::unique_ptr<ExpressionAST>>
809 parseBinop(StringRef Expr, StringRef &RemainingExpr,
810 std::unique_ptr<ExpressionAST> LeftOp,
bool IsLegacyLineExpr,
811 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
812 const SourceMgr &SM);
820 static Expected<std::unique_ptr<ExpressionAST>>
821 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
822 FileCheckPatternContext *Context,
const SourceMgr &SM);
831 static Expected<std::unique_ptr<ExpressionAST>>
832 parseCallExpr(StringRef &Expr, StringRef FuncName,
833 std::optional<size_t> LineNumber,
834 FileCheckPatternContext *Context,
const SourceMgr &SM);
867 std::vector<DagNotPrefixInfo> &&
D)
873 std::vector<FileCheckDiag> *Diags)
const;
885 const std::vector<const DagNotPrefixInfo *> &NotStrings,
887 std::vector<FileCheckDiag> *Diags)
const;
890 std::vector<const DagNotPrefixInfo *> &NotStrings,
892 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< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI_FOR_TEST
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)
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.
static LLVM_ABI_FOR_TEST char ID
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...
LLVM_ABI_FOR_TEST Error defineCmdlineVariables(ArrayRef< StringRef > CmdlineDefines, SourceMgr &SM)
Defines string and numeric variables from definitions given on the command line, passed as a vector o...
LLVM_ABI_FOR_TEST void createLineVariable()
Create @LINE pseudo variable.
LLVM_ABI_FOR_TEST Expected< StringRef > getPatternVarValue(StringRef VarName)
LLVM_ABI_FOR_TEST 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.
static LLVM_ABI_FOR_TEST char ID
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< 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.
static LLVM_ABI_FOR_TEST char ID
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 LLVM_ABI_FOR_TEST Expected< VariableProperties > parseVariable(StringRef &Str, const SourceMgr &SM)
Parses the string at the start of Str for a variable name.
LLVM_ABI_FOR_TEST 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 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 LineNum...
Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, std::optional< size_t > Line=std::nullopt)
LLVM_ABI_FOR_TEST void printVariableDefs(const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
static LLVM_ABI_FOR_TEST bool isValidVarNameStart(char C)
Check::FileCheckType getCheckTy() 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.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
LLVM_ABI 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.
LLVM_ABI 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)
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...
virtual Expected< std::string > getResultRegex() const =0
virtual Expected< std::string > getResultForDiagnostics() const =0
StringRef FromStr
The string that needs to be substituted for something else.
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
static LLVM_ABI_FOR_TEST char ID
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.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI_FOR_TEST Expected< APInt > exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Performs operation and.
LLVM_ABI_FOR_TEST 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)
LLVM_ABI_FOR_TEST Expected< APInt > exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Expected< APInt > exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
LLVM_ABI_FOR_TEST 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.
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.
FileCheckString(Pattern &&P, StringRef S, SMLoc L, std::vector< DagNotPrefixInfo > &&D)
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.