Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
FileCheckImpl.h
Go to the documentation of this file.
1//===-- FileCheckImpl.h - Private FileCheck Interface ------------*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the private interfaces of FileCheck. Its purpose is to
10// allow unit testing of FileCheck and to separate the interface from the
11// implementation. It is only meant to be used by FileCheck.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
16#define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
17
18#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/FileCheck/FileCheck.h"
22#include "llvm/Support/Error.h"
23#include "llvm/Support/SourceMgr.h"
24#include <map>
25#include <optional>
26#include <string>
27#include <vector>
28
29namespacellvm {
30
31//===----------------------------------------------------------------------===//
32// Numeric substitution handling code.
33//===----------------------------------------------------------------------===//
34
35/// Type representing the format an expression value should be textualized into
36/// for matching. Used to represent both explicit format specifiers as well as
37/// implicit format from using numeric variables.
38structExpressionFormat {
39enum classKind {
40 /// Denote absence of format. Used for implicit format of literals and
41 /// empty expressions.
42NoFormat,
43 /// Value is an unsigned integer and should be printed as a decimal number.
44Unsigned,
45 /// Value is a signed integer and should be printed as a decimal number.
46Signed,
47 /// Value should be printed as an uppercase hex number.
48HexUpper,
49 /// Value should be printed as a lowercase hex number.
50HexLower
51 };
52
53private:
54KindValue;
55unsigned Precision = 0;
56 /// printf-like "alternate form" selected.
57bool AlternateForm =false;
58
59public:
60 /// Evaluates a format to true if it can be used in a match.
61explicitoperatorbool() const{returnValue !=Kind::NoFormat; }
62
63 /// Define format equality: formats are equal if neither is NoFormat and
64 /// their kinds and precision are the same.
65booloperator==(constExpressionFormat &Other) const{
66returnValue !=Kind::NoFormat &&Value ==Other.Value &&
67 Precision ==Other.Precision && AlternateForm ==Other.AlternateForm;
68 }
69
70booloperator!=(constExpressionFormat &Other) const{
71return !(*this ==Other);
72 }
73
74booloperator==(Kind OtherValue) const{returnValue == OtherValue; }
75
76booloperator!=(Kind OtherValue) const{return !(*this == OtherValue); }
77
78 /// \returns the format specifier corresponding to this format as a string.
79StringReftoString()const;
80
81ExpressionFormat() :Value(Kind::NoFormat){};
82explicitExpressionFormat(KindValue) :Value(Value), Precision(0){};
83explicitExpressionFormat(KindValue,unsigned Precision)
84 :Value(Value), Precision(Precision){};
85explicitExpressionFormat(KindValue,unsigned Precision,bool AlternateForm)
86 :Value(Value), Precision(Precision), AlternateForm(AlternateForm){};
87
88 /// \returns a wildcard regular expression string that matches any value in
89 /// the format represented by this instance and no other value, or an error
90 /// if the format is NoFormat.
91Expected<std::string>getWildcardRegex()const;
92
93 /// \returns the string representation of \p Value in the format represented
94 /// by this instance, or an error if conversion to this format failed or the
95 /// format is NoFormat.
96Expected<std::string>getMatchingString(APIntValue)const;
97
98 /// \returns the value corresponding to string representation \p StrVal
99 /// according to the matching format represented by this instance.
100APIntvalueFromStringRepr(StringRef StrVal,constSourceMgr &SM)const;
101};
102
103/// Class to represent an overflow error that might result when manipulating a
104/// value.
105classOverflowError :publicErrorInfo<OverflowError> {
106public:
107staticcharID;
108
109 std::error_codeconvertToErrorCode() const override{
110return std::make_error_code(std::errc::value_too_large);
111 }
112
113voidlog(raw_ostream &OS) const override{OS <<"overflow error"; }
114};
115
116/// Performs operation and \returns its result or an error in case of failure,
117/// such as if an overflow occurs.
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);
124
125/// Base class representing the AST of a given expression.
126classExpressionAST {
127private:
128StringRef ExpressionStr;
129
130public:
131ExpressionAST(StringRef ExpressionStr) : ExpressionStr(ExpressionStr) {}
132
133virtual~ExpressionAST() =default;
134
135StringRefgetExpressionStr() const{return ExpressionStr; }
136
137 /// Evaluates and \returns the value of the expression represented by this
138 /// AST or an error if evaluation fails.
139virtualExpected<APInt>eval()const = 0;
140
141 /// \returns either the implicit format of this AST, a diagnostic against
142 /// \p SM if implicit formats of the AST's components conflict, or NoFormat
143 /// if the AST has no implicit format (e.g. AST is made up of a single
144 /// literal).
145virtualExpected<ExpressionFormat>
146getImplicitFormat(constSourceMgr &SM) const{
147returnExpressionFormat();
148 }
149};
150
151/// Class representing an unsigned literal in the AST of an expression.
152classExpressionLiteral :publicExpressionAST {
153private:
154 /// Actual value of the literal.
155APIntValue;
156
157public:
158explicitExpressionLiteral(StringRef ExpressionStr,APInt Val)
159 :ExpressionAST(ExpressionStr),Value(Val) {}
160
161 /// \returns the literal's value.
162Expected<APInt>eval() const override{returnValue; }
163};
164
165/// Class to represent an undefined variable error, which quotes that
166/// variable's name when printed.
167classUndefVarError :publicErrorInfo<UndefVarError> {
168private:
169StringRef VarName;
170
171public:
172staticcharID;
173
174UndefVarError(StringRef VarName) : VarName(VarName) {}
175
176StringRefgetVarName() const{return VarName; }
177
178 std::error_codeconvertToErrorCode() const override{
179returninconvertibleErrorCode();
180 }
181
182 /// Print name of variable associated with this error.
183voidlog(raw_ostream &OS) const override{
184OS <<"undefined variable: " << VarName;
185 }
186};
187
188/// Class representing an expression and its matching format.
189classExpression {
190private:
191 /// Pointer to AST of the expression.
192 std::unique_ptr<ExpressionAST> AST;
193
194 /// Format to use (e.g. hex upper case letters) when matching the value.
195ExpressionFormat Format;
196
197public:
198 /// Generic constructor for an expression represented by the given \p AST and
199 /// whose matching format is \p Format.
200Expression(std::unique_ptr<ExpressionAST> AST,ExpressionFormat Format)
201 : AST(std::move(AST)), Format(Format) {}
202
203 /// \returns pointer to AST of the expression. Pointer is guaranteed to be
204 /// valid as long as this object is.
205ExpressionAST *getAST() const{return AST.get(); }
206
207ExpressionFormatgetFormat() const{return Format; }
208};
209
210/// Class representing a numeric variable and its associated current value.
211classNumericVariable {
212private:
213 /// Name of the numeric variable.
214StringRef Name;
215
216 /// Format to use for expressions using this variable without an explicit
217 /// format.
218ExpressionFormat ImplicitFormat;
219
220 /// Value of numeric variable, if defined, or std::nullopt otherwise.
221 std::optional<APInt>Value;
222
223 /// The input buffer's string from which Value was parsed, or std::nullopt.
224 /// See comments on getStringValue for a discussion of the std::nullopt case.
225 std::optional<StringRef> StrValue;
226
227 /// Line number where this variable is defined, or std::nullopt if defined
228 /// before input is parsed. Used to determine whether a variable is defined on
229 /// the same line as a given use.
230 std::optional<size_t> DefLineNumber;
231
232public:
233 /// Constructor for a variable \p Name with implicit format \p ImplicitFormat
234 /// defined at line \p DefLineNumber or defined before input is parsed if
235 /// \p DefLineNumber is std::nullopt.
236explicitNumericVariable(StringRef Name,ExpressionFormat ImplicitFormat,
237 std::optional<size_t> DefLineNumber = std::nullopt)
238 : Name(Name), ImplicitFormat(ImplicitFormat),
239 DefLineNumber(DefLineNumber) {}
240
241 /// \returns name of this numeric variable.
242StringRefgetName() const{return Name; }
243
244 /// \returns implicit format of this numeric variable.
245ExpressionFormatgetImplicitFormat() const{return ImplicitFormat; }
246
247 /// \returns this variable's value.
248 std::optional<APInt>getValue() const{returnValue; }
249
250 /// \returns the input buffer's string from which this variable's value was
251 /// parsed, or std::nullopt if the value is not yet defined or was not parsed
252 /// from the input buffer. For example, the value of @LINE is not parsed from
253 /// the input buffer, and some numeric variables are parsed from the command
254 /// line instead.
255 std::optional<StringRef>getStringValue() const{return StrValue; }
256
257 /// Sets value of this numeric variable to \p NewValue, and sets the input
258 /// buffer string from which it was parsed to \p NewStrValue. See comments on
259 /// getStringValue for a discussion of when the latter can be std::nullopt.
260voidsetValue(APInt NewValue,
261 std::optional<StringRef> NewStrValue = std::nullopt) {
262Value = NewValue;
263 StrValue = NewStrValue;
264 }
265
266 /// Clears value of this numeric variable, regardless of whether it is
267 /// currently defined or not.
268voidclearValue() {
269Value = std::nullopt;
270 StrValue = std::nullopt;
271 }
272
273 /// \returns the line number where this variable is defined, if any, or
274 /// std::nullopt if defined before input is parsed.
275 std::optional<size_t>getDefLineNumber() const{return DefLineNumber; }
276};
277
278/// Class representing the use of a numeric variable in the AST of an
279/// expression.
280classNumericVariableUse :publicExpressionAST {
281private:
282 /// Pointer to the class instance for the variable this use is about.
283NumericVariable *Variable;
284
285public:
286NumericVariableUse(StringRefName,NumericVariable *Variable)
287 :ExpressionAST(Name), Variable(Variable) {}
288 /// \returns the value of the variable referenced by this instance.
289Expected<APInt>eval()const override;
290
291 /// \returns implicit format of this numeric variable.
292Expected<ExpressionFormat>
293getImplicitFormat(constSourceMgr &SM) const override{
294return Variable->getImplicitFormat();
295 }
296};
297
298/// Type of functions evaluating a given binary operation.
299usingbinop_eval_t =Expected<APInt> (*)(constAPInt &,constAPInt &,bool &);
300
301/// Class representing a single binary operation in the AST of an expression.
302classBinaryOperation :publicExpressionAST {
303private:
304 /// Left operand.
305 std::unique_ptr<ExpressionAST> LeftOperand;
306
307 /// Right operand.
308 std::unique_ptr<ExpressionAST> RightOperand;
309
310 /// Pointer to function that can evaluate this binary operation.
311binop_eval_t EvalBinop;
312
313public:
314BinaryOperation(StringRef ExpressionStr,binop_eval_t EvalBinop,
315 std::unique_ptr<ExpressionAST> LeftOp,
316 std::unique_ptr<ExpressionAST> RightOp)
317 :ExpressionAST(ExpressionStr), EvalBinop(EvalBinop) {
318 LeftOperand = std::move(LeftOp);
319 RightOperand = std::move(RightOp);
320 }
321
322 /// Evaluates the value of the binary operation represented by this AST,
323 /// using EvalBinop on the result of recursively evaluating the operands.
324 /// \returns the expression value or an error if an undefined numeric
325 /// variable is used in one of the operands.
326Expected<APInt>eval()const override;
327
328 /// \returns the implicit format of this AST, if any, a diagnostic against
329 /// \p SM if the implicit formats of the AST's components conflict, or no
330 /// format if the AST has no implicit format (e.g. AST is made of a single
331 /// literal).
332Expected<ExpressionFormat>
333getImplicitFormat(constSourceMgr &SM)const override;
334};
335
336classFileCheckPatternContext;
337
338/// Class representing a substitution to perform in the RegExStr string.
339classSubstitution {
340protected:
341 /// Pointer to a class instance holding, among other things, the table with
342 /// the values of live string variables at the start of any given CHECK line.
343 /// Used for substituting string variables with the text they were defined
344 /// as. Expressions are linked to the numeric variables they use at
345 /// parse time and directly access the value of the numeric variable to
346 /// evaluate their value.
347FileCheckPatternContext *Context;
348
349 /// The string that needs to be substituted for something else. For a
350 /// string variable this is its name, otherwise this is the whole expression.
351StringRefFromStr;
352
353// Index in RegExStr of where to do the substitution.
354size_tInsertIdx;
355
356public:
357Substitution(FileCheckPatternContext *Context,StringRef VarName,
358size_tInsertIdx)
359 :Context(Context),FromStr(VarName),InsertIdx(InsertIdx) {}
360
361virtual~Substitution() =default;
362
363 /// \returns the string to be substituted for something else.
364StringRefgetFromString() const{returnFromStr; }
365
366 /// \returns the index where the substitution is to be performed in RegExStr.
367size_tgetIndex() const{returnInsertIdx; }
368
369 /// \returns a string containing the result of the substitution represented
370 /// by this class instance or an error if substitution failed.
371virtualExpected<std::string>getResult()const = 0;
372};
373
374classStringSubstitution :publicSubstitution {
375public:
376StringSubstitution(FileCheckPatternContext *Context,StringRef VarName,
377size_tInsertIdx)
378 :Substitution(Context, VarName,InsertIdx) {}
379
380 /// \returns the text that the string variable in this substitution matched
381 /// when defined, or an error if the variable is undefined.
382Expected<std::string>getResult()const override;
383};
384
385classNumericSubstitution :publicSubstitution {
386private:
387 /// Pointer to the class representing the expression whose value is to be
388 /// substituted.
389 std::unique_ptr<Expression> ExpressionPointer;
390
391public:
392NumericSubstitution(FileCheckPatternContext *Context,StringRef ExpressionStr,
393 std::unique_ptr<Expression> ExpressionPointer,
394size_tInsertIdx)
395 :Substitution(Context, ExpressionStr,InsertIdx),
396 ExpressionPointer(std::move(ExpressionPointer)) {}
397
398 /// \returns a string containing the result of evaluating the expression in
399 /// this substitution, or an error if evaluation failed.
400Expected<std::string>getResult()const override;
401};
402
403//===----------------------------------------------------------------------===//
404// Pattern handling code.
405//===----------------------------------------------------------------------===//
406
407/// Class holding the Pattern global state, shared by all patterns: tables
408/// holding values of variables and whether they are defined or not at any
409/// given time in the matching process.
410classFileCheckPatternContext {
411friendclassPattern;
412
413private:
414 /// When matching a given pattern, this holds the value of all the string
415 /// variables defined in previous patterns. In a pattern, only the last
416 /// definition for a given variable is recorded in this table.
417 /// Back-references are used for uses after any the other definition.
418StringMap<StringRef> GlobalVariableTable;
419
420 /// Map of all string variables defined so far. Used at parse time to detect
421 /// a name conflict between a numeric variable and a string variable when
422 /// the former is defined on a later line than the latter.
423StringMap<bool> DefinedVariableTable;
424
425 /// When matching a given pattern, this holds the pointers to the classes
426 /// representing the numeric variables defined in previous patterns. When
427 /// matching a pattern all definitions for that pattern are recorded in the
428 /// NumericVariableDefs table in the Pattern instance of that pattern.
429StringMap<NumericVariable *> GlobalNumericVariableTable;
430
431 /// Pointer to the class instance representing the @LINE pseudo variable for
432 /// easily updating its value.
433NumericVariable *LineVariable =nullptr;
434
435 /// Vector holding pointers to all parsed numeric variables. Used to
436 /// automatically free them once they are guaranteed to no longer be used.
437 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
438
439 /// Vector holding pointers to all parsed expressions. Used to automatically
440 /// free the expressions once they are guaranteed to no longer be used.
441 std::vector<std::unique_ptr<Expression>> Expressions;
442
443 /// Vector holding pointers to all substitutions. Used to automatically free
444 /// them once they are guaranteed to no longer be used.
445 std::vector<std::unique_ptr<Substitution>> Substitutions;
446
447public:
448 /// \returns the value of string variable \p VarName or an error if no such
449 /// variable has been defined.
450Expected<StringRef>getPatternVarValue(StringRef VarName);
451
452 /// Defines string and numeric variables from definitions given on the
453 /// command line, passed as a vector of [#]VAR=VAL strings in
454 /// \p CmdlineDefines. \returns an error list containing diagnostics against
455 /// \p SM for all definition parsing failures, if any, or Success otherwise.
456ErrordefineCmdlineVariables(ArrayRef<StringRef> CmdlineDefines,
457SourceMgr &SM);
458
459 /// Create @LINE pseudo variable. Value is set when pattern are being
460 /// matched.
461voidcreateLineVariable();
462
463 /// Undefines local variables (variables whose name does not start with a '$'
464 /// sign), i.e. removes them from GlobalVariableTable and from
465 /// GlobalNumericVariableTable and also clears the value of numeric
466 /// variables.
467voidclearLocalVars();
468
469private:
470 /// Makes a new numeric variable and registers it for destruction when the
471 /// context is destroyed.
472template <class... Types>NumericVariable *makeNumericVariable(Types...args);
473
474 /// Makes a new string substitution and registers it for destruction when the
475 /// context is destroyed.
476Substitution *makeStringSubstitution(StringRef VarName,size_t InsertIdx);
477
478 /// Makes a new numeric substitution and registers it for destruction when
479 /// the context is destroyed.
480Substitution *makeNumericSubstitution(StringRef ExpressionStr,
481 std::unique_ptr<Expression>Expression,
482size_t InsertIdx);
483};
484
485/// Class to represent an error holding a diagnostic with location information
486/// used when printing it.
487classErrorDiagnostic :publicErrorInfo<ErrorDiagnostic> {
488private:
489SMDiagnostic Diagnostic;
490SMRange Range;
491
492public:
493staticcharID;
494
495ErrorDiagnostic(SMDiagnostic &&Diag,SMRange Range)
496 : Diagnostic(Diag),Range(Range) {}
497
498 std::error_codeconvertToErrorCode() const override{
499returninconvertibleErrorCode();
500 }
501
502 /// Print diagnostic associated with this error when printing the error.
503voidlog(raw_ostream &OS) const override{ Diagnostic.print(nullptr,OS); }
504
505StringRefgetMessage() const{return Diagnostic.getMessage(); }
506SMRangegetRange() const{returnRange; }
507
508staticErrorget(constSourceMgr &SM,SMLoc Loc,constTwine &ErrMsg,
509SMRange Range = std::nullopt) {
510return make_error<ErrorDiagnostic>(
511 SM.GetMessage(Loc,SourceMgr::DK_Error, ErrMsg),Range);
512 }
513
514staticErrorget(constSourceMgr &SM,StringRef Buffer,constTwine &ErrMsg) {
515SMLoc Start =SMLoc::getFromPointer(Buffer.data());
516SMLocEnd =SMLoc::getFromPointer(Buffer.data() + Buffer.size());
517returnget(SM, Start, ErrMsg,SMRange(Start,End));
518 }
519};
520
521classNotFoundError :publicErrorInfo<NotFoundError> {
522public:
523staticcharID;
524
525 std::error_codeconvertToErrorCode() const override{
526returninconvertibleErrorCode();
527 }
528
529 /// Print diagnostic associated with this error when printing the error.
530voidlog(raw_ostream &OS) const override{
531OS <<"String not found in input";
532 }
533};
534
535/// An error that has already been reported.
536///
537/// This class is designed to support a function whose callers may need to know
538/// whether the function encountered and reported an error but never need to
539/// know the nature of that error. For example, the function has a return type
540/// of \c Error and always returns either \c ErrorReported or \c ErrorSuccess.
541/// That interface is similar to that of a function returning bool to indicate
542/// an error except, in the former case, (1) there is no confusion over polarity
543/// and (2) the caller must either check the result or explicitly ignore it with
544/// a call like \c consumeError.
545classErrorReported final :publicErrorInfo<ErrorReported> {
546public:
547staticcharID;
548
549 std::error_codeconvertToErrorCode() const override{
550returninconvertibleErrorCode();
551 }
552
553 /// Print diagnostic associated with this error when printing the error.
554voidlog(raw_ostream &OS) const override{
555OS <<"error previously reported";
556 }
557
558staticinlineErrorreportedOrSuccess(bool HasErrorReported) {
559if (HasErrorReported)
560return make_error<ErrorReported>();
561returnError::success();
562 }
563};
564
565classPattern {
566SMLoc PatternLoc;
567
568 /// A fixed string to match as the pattern or empty if this pattern requires
569 /// a regex match.
570StringRef FixedStr;
571
572 /// A regex string to match as the pattern or empty if this pattern requires
573 /// a fixed string to match.
574 std::string RegExStr;
575
576 /// Entries in this vector represent a substitution of a string variable or
577 /// an expression in the RegExStr regex at match time. For example, in the
578 /// case of a CHECK directive with the pattern "foo[[bar]]baz[[#N+1]]",
579 /// RegExStr will contain "foobaz" and we'll get two entries in this vector
580 /// that tells us to insert the value of string variable "bar" at offset 3
581 /// and the value of expression "N+1" at offset 6.
582 std::vector<Substitution *> Substitutions;
583
584 /// Maps names of string variables defined in a pattern to the number of
585 /// their parenthesis group in RegExStr capturing their last definition.
586 ///
587 /// E.g. for the pattern "foo[[bar:.*]]baz([[bar]][[QUUX]][[bar:.*]])",
588 /// RegExStr will be "foo(.*)baz(\1<quux value>(.*))" where <quux value> is
589 /// the value captured for QUUX on the earlier line where it was defined, and
590 /// VariableDefs will map "bar" to the third parenthesis group which captures
591 /// the second definition of "bar".
592 ///
593 /// Note: uses std::map rather than StringMap to be able to get the key when
594 /// iterating over values.
595 std::map<StringRef, unsigned> VariableDefs;
596
597 /// Structure representing the definition of a numeric variable in a pattern.
598 /// It holds the pointer to the class instance holding the value and matching
599 /// format of the numeric variable whose value is being defined and the
600 /// number of the parenthesis group in RegExStr to capture that value.
601structNumericVariableMatch {
602 /// Pointer to class instance holding the value and matching format of the
603 /// numeric variable being defined.
604NumericVariable *DefinedNumericVariable;
605
606 /// Number of the parenthesis group in RegExStr that captures the value of
607 /// this numeric variable definition.
608unsigned CaptureParenGroup;
609 };
610
611 /// Holds the number of the parenthesis group in RegExStr and pointer to the
612 /// corresponding NumericVariable class instance of all numeric variable
613 /// definitions. Used to set the matched value of all those variables.
614StringMap<NumericVariableMatch> NumericVariableDefs;
615
616 /// Pointer to a class instance holding the global state shared by all
617 /// patterns:
618 /// - separate tables with the values of live string and numeric variables
619 /// respectively at the start of any given CHECK line;
620 /// - table holding whether a string variable has been defined at any given
621 /// point during the parsing phase.
622FileCheckPatternContext *Context;
623
624Check::FileCheckType CheckTy;
625
626 /// Line number for this CHECK pattern or std::nullopt if it is an implicit
627 /// pattern. Used to determine whether a variable definition is made on an
628 /// earlier line to the one with this CHECK.
629 std::optional<size_t> LineNumber;
630
631 /// Ignore case while matching if set to true.
632bool IgnoreCase =false;
633
634public:
635Pattern(Check::FileCheckType Ty,FileCheckPatternContext *Context,
636 std::optional<size_t> Line = std::nullopt)
637 : Context(Context), CheckTy(Ty), LineNumber(Line) {}
638
639 /// \returns the location in source code.
640SMLocgetLoc() const{return PatternLoc; }
641
642 /// \returns the pointer to the global state for all patterns in this
643 /// FileCheck instance.
644FileCheckPatternContext *getContext() const{return Context; }
645
646 /// \returns whether \p C is a valid first character for a variable name.
647staticboolisValidVarNameStart(charC);
648
649 /// Parsing information about a variable.
650structVariableProperties {
651StringRefName;
652boolIsPseudo;
653 };
654
655 /// Parses the string at the start of \p Str for a variable name. \returns
656 /// a VariableProperties structure holding the variable name and whether it
657 /// is the name of a pseudo variable, or an error holding a diagnostic
658 /// against \p SM if parsing fail. If parsing was successful, also strips
659 /// \p Str from the variable name.
660staticExpected<VariableProperties>parseVariable(StringRef &Str,
661constSourceMgr &SM);
662 /// Parses \p Expr for a numeric substitution block at line \p LineNumber,
663 /// or before input is parsed if \p LineNumber is None. Parameter
664 /// \p IsLegacyLineExpr indicates whether \p Expr should be a legacy @LINE
665 /// expression and \p Context points to the class instance holding the live
666 /// string and numeric variables. \returns a pointer to the class instance
667 /// representing the expression whose value must be substitued, or an error
668 /// holding a diagnostic against \p SM if parsing fails. If substitution was
669 /// successful, sets \p DefinedNumericVariable to point to the class
670 /// representing the numeric variable defined in this numeric substitution
671 /// block, or std::nullopt if this block does not define any variable.
672staticExpected<std::unique_ptr<Expression>>parseNumericSubstitutionBlock(
673StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
674bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
675FileCheckPatternContext *Context,constSourceMgr &SM);
676 /// Parses the pattern in \p PatternStr and initializes this Pattern instance
677 /// accordingly.
678 ///
679 /// \p Prefix provides which prefix is being matched, \p Req describes the
680 /// global options that influence the parsing such as whitespace
681 /// canonicalization, \p SM provides the SourceMgr used for error reports.
682 /// \returns true in case of an error, false otherwise.
683boolparsePattern(StringRef PatternStr,StringRef Prefix,SourceMgr &SM,
684constFileCheckRequest &Req);
685structMatch {
686size_tPos;
687size_tLen;
688 };
689structMatchResult {
690 std::optional<Match>TheMatch;
691ErrorTheError;
692MatchResult(size_t MatchPos,size_t MatchLen,ErrorE)
693 :TheMatch(Match{MatchPos, MatchLen}),TheError(std::move(E)) {}
694MatchResult(Match M,ErrorE) :TheMatch(M),TheError(std::move(E)) {}
695MatchResult(ErrorE) :TheError(std::move(E)) {}
696 };
697 /// Matches the pattern string against the input buffer \p Buffer.
698 ///
699 /// \returns either (1) an error resulting in no match or (2) a match possibly
700 /// with an error encountered while processing the match.
701 ///
702 /// The GlobalVariableTable StringMap in the FileCheckPatternContext class
703 /// instance provides the current values of FileCheck string variables and is
704 /// updated if this match defines new values. Likewise, the
705 /// GlobalNumericVariableTable StringMap in the same class provides the
706 /// current values of FileCheck numeric variables and is updated if this
707 /// match defines new numeric values.
708 MatchResultmatch(StringRef Buffer,constSourceMgr &SM)const;
709 /// Prints the value of successful substitutions.
710voidprintSubstitutions(constSourceMgr &SM,StringRef Buffer,
711SMRange MatchRange,FileCheckDiag::MatchType MatchTy,
712 std::vector<FileCheckDiag> *Diags)const;
713voidprintFuzzyMatch(constSourceMgr &SM,StringRef Buffer,
714 std::vector<FileCheckDiag> *Diags)const;
715
716boolhasVariable() const{
717return !(Substitutions.empty() && VariableDefs.empty());
718 }
719voidprintVariableDefs(constSourceMgr &SM,FileCheckDiag::MatchType MatchTy,
720 std::vector<FileCheckDiag> *Diags)const;
721
722Check::FileCheckTypegetCheckTy() const{return CheckTy; }
723
724intgetCount() const{return CheckTy.getCount(); }
725
726private:
727bool AddRegExToRegEx(StringRef RS,unsigned &CurParen,SourceMgr &SM);
728void AddBackrefToRegEx(unsigned BackrefNum);
729 /// Computes an arbitrary estimate for the quality of matching this pattern
730 /// at the start of \p Buffer; a distance of zero should correspond to a
731 /// perfect match.
732unsigned computeMatchDistance(StringRef Buffer)const;
733 /// Finds the closing sequence of a regex variable usage or definition.
734 ///
735 /// \p Str has to point in the beginning of the definition (right after the
736 /// opening sequence). \p SM holds the SourceMgr used for error reporting.
737 /// \returns the offset of the closing sequence within Str, or npos if it
738 /// was not found.
739staticsize_t FindRegexVarEnd(StringRef Str,SourceMgr &SM);
740
741 /// Parses \p Expr for the name of a numeric variable to be defined at line
742 /// \p LineNumber, or before input is parsed if \p LineNumber is None.
743 /// \returns a pointer to the class instance representing that variable,
744 /// creating it if needed, or an error holding a diagnostic against \p SM
745 /// should defining such a variable be invalid.
746staticExpected<NumericVariable *> parseNumericVariableDefinition(
747StringRef &Expr,FileCheckPatternContext *Context,
748 std::optional<size_t> LineNumber,ExpressionFormat ImplicitFormat,
749constSourceMgr &SM);
750 /// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use
751 /// at line \p LineNumber, or before input is parsed if \p LineNumber is
752 /// None. Parameter \p Context points to the class instance holding the live
753 /// string and numeric variables. \returns the pointer to the class instance
754 /// representing that variable if successful, or an error holding a
755 /// diagnostic against \p SM otherwise.
756staticExpected<std::unique_ptr<NumericVariableUse>> parseNumericVariableUse(
757StringRefName,bool IsPseudo, std::optional<size_t> LineNumber,
758FileCheckPatternContext *Context,constSourceMgr &SM);
759enum class AllowedOperand { LineVar, LegacyLiteral,Any };
760 /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or
761 /// before input is parsed if \p LineNumber is None. Accepts literal values,
762 /// numeric variables and function calls, depending on the value of \p AO.
763 /// \p MaybeInvalidConstraint indicates whether the text being parsed could
764 /// be an invalid constraint. \p Context points to the class instance holding
765 /// the live string and numeric variables. \returns the class representing
766 /// that operand in the AST of the expression or an error holding a
767 /// diagnostic against \p SM otherwise. If \p Expr starts with a "(" this
768 /// function will attempt to parse a parenthesized expression.
769static 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);
773 /// Parses and updates \p RemainingExpr for a binary operation at line
774 /// \p LineNumber, or before input is parsed if \p LineNumber is None. The
775 /// left operand of this binary operation is given in \p LeftOp and \p Expr
776 /// holds the string for the full expression, including the left operand.
777 /// Parameter \p IsLegacyLineExpr indicates whether we are parsing a legacy
778 /// @LINE expression. Parameter \p Context points to the class instance
779 /// holding the live string and numeric variables. \returns the class
780 /// representing the binary operation in the AST of the expression, or an
781 /// error holding a diagnostic against \p SM otherwise.
782static 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,
786const SourceMgr &SM);
787
788 /// Parses a parenthesized expression inside \p Expr at line \p LineNumber, or
789 /// before input is parsed if \p LineNumber is None. \p Expr must start with
790 /// a '('. Accepts both literal values and numeric variables. Parameter \p
791 /// Context points to the class instance holding the live string and numeric
792 /// variables. \returns the class representing that operand in the AST of the
793 /// expression or an error holding a diagnostic against \p SM otherwise.
794static Expected<std::unique_ptr<ExpressionAST>>
795 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
796 FileCheckPatternContext *Context,const SourceMgr &SM);
797
798 /// Parses \p Expr for an argument list belonging to a call to function \p
799 /// FuncName at line \p LineNumber, or before input is parsed if \p LineNumber
800 /// is None. Parameter \p FuncLoc is the source location used for diagnostics.
801 /// Parameter \p Context points to the class instance holding the live string
802 /// and numeric variables. \returns the class representing that call in the
803 /// AST of the expression or an error holding a diagnostic against \p SM
804 /// otherwise.
805static Expected<std::unique_ptr<ExpressionAST>>
806 parseCallExpr(StringRef &Expr, StringRef FuncName,
807 std::optional<size_t> LineNumber,
808 FileCheckPatternContext *Context,const SourceMgr &SM);
809};
810
811//===----------------------------------------------------------------------===//
812// Check Strings.
813//===----------------------------------------------------------------------===//
814
815/// A check that we found in the input file.
816structFileCheckString {
817 /// The pattern to match.
818PatternPat;
819
820 /// Which prefix name this check matched.
821StringRefPrefix;
822
823 /// The location in the match file that the check string was specified.
824SMLocLoc;
825
826 /// Hold the information about the DAG/NOT strings in the program, which are
827 /// not explicitly stored otherwise. This allows for better and more accurate
828 /// diagnostic messages.
829structDagNotPrefixInfo {
830PatternDagNotPat;
831StringRefDagNotPrefix;
832
833DagNotPrefixInfo(constPattern &P,StringRef S)
834 :DagNotPat(P),DagNotPrefix(S) {}
835 };
836
837 /// Hold the DAG/NOT strings occurring in the input file.
838 std::vector<DagNotPrefixInfo>DagNotStrings;
839
840FileCheckString(Pattern &&P,StringRef S,SMLoc L,
841 std::vector<DagNotPrefixInfo> &&D)
842 :Pat(std::move(P)),Prefix(S),Loc(L),DagNotStrings(std::move(D)) {}
843
844 /// Matches check string and its "not strings" and/or "dag strings".
845size_t Check(constSourceMgr &SM,StringRef Buffer,bool IsLabelScanMode,
846size_t &MatchLen,FileCheckRequest &Req,
847 std::vector<FileCheckDiag> *Diags)const;
848
849 /// Verifies that there is a single line in the given \p Buffer. Errors are
850 /// reported against \p SM.
851boolCheckNext(constSourceMgr &SM,StringRef Buffer)const;
852 /// Verifies that there is no newline in the given \p Buffer. Errors are
853 /// reported against \p SM.
854boolCheckSame(constSourceMgr &SM,StringRef Buffer)const;
855 /// Verifies that none of the strings in \p NotStrings are found in the given
856 /// \p Buffer. Errors are reported against \p SM and diagnostics recorded in
857 /// \p Diags according to the verbosity level set in \p Req.
858boolCheckNot(constSourceMgr &SM,StringRef Buffer,
859const std::vector<const DagNotPrefixInfo *> &NotStrings,
860constFileCheckRequest &Req,
861 std::vector<FileCheckDiag> *Diags)const;
862 /// Matches "dag strings" and their mixed "not strings".
863size_tCheckDag(constSourceMgr &SM,StringRef Buffer,
864 std::vector<const DagNotPrefixInfo *> &NotStrings,
865constFileCheckRequest &Req,
866 std::vector<FileCheckDiag> *Diags)const;
867};
868
869}// namespace llvm
870
871#endif
StringMap.h
This file defines the StringMap class.
APInt.h
This file implements a class to represent arbitrary precision integral constant values and operations...
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Name
std::string Name
Definition:ELFObjHandler.cpp:77
End
bool End
Definition:ELF_riscv.cpp:480
FileCheck.h
args
nvptx lower args
Definition:NVPTXLowerArgs.cpp:199
Range
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
P
#define P(N)
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
StringRef.h
SourceMgr.h
bool
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::Any
Definition:Any.h:28
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::BinaryOperation
Class representing a single binary operation in the AST of an expression.
Definition:FileCheckImpl.h:302
llvm::BinaryOperation::BinaryOperation
BinaryOperation(StringRef ExpressionStr, binop_eval_t EvalBinop, std::unique_ptr< ExpressionAST > LeftOp, std::unique_ptr< ExpressionAST > RightOp)
Definition:FileCheckImpl.h:314
llvm::BinaryOperation::getImplicitFormat
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Definition:FileCheck.cpp:242
llvm::BinaryOperation::eval
Expected< APInt > eval() const override
Evaluates the value of the binary operation represented by this AST, using EvalBinop on the result of...
Definition:FileCheck.cpp:203
llvm::Check::FileCheckType
Definition:FileCheck.h:80
llvm::Check::FileCheckType::getCount
int getCount() const
Definition:FileCheck.h:93
llvm::ErrorDiagnostic
Class to represent an error holding a diagnostic with location information used when printing it.
Definition:FileCheckImpl.h:487
llvm::ErrorDiagnostic::getMessage
StringRef getMessage() const
Definition:FileCheckImpl.h:505
llvm::ErrorDiagnostic::ErrorDiagnostic
ErrorDiagnostic(SMDiagnostic &&Diag, SMRange Range)
Definition:FileCheckImpl.h:495
llvm::ErrorDiagnostic::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:FileCheckImpl.h:498
llvm::ErrorDiagnostic::ID
static char ID
Definition:FileCheckImpl.h:493
llvm::ErrorDiagnostic::log
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Definition:FileCheckImpl.h:503
llvm::ErrorDiagnostic::getRange
SMRange getRange() const
Definition:FileCheckImpl.h:506
llvm::ErrorDiagnostic::get
static Error get(const SourceMgr &SM, StringRef Buffer, const Twine &ErrMsg)
Definition:FileCheckImpl.h:514
llvm::ErrorDiagnostic::get
static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg, SMRange Range=std::nullopt)
Definition:FileCheckImpl.h:508
llvm::ErrorInfo
Base class for user error types.
Definition:Error.h:355
llvm::ErrorReported
An error that has already been reported.
Definition:FileCheckImpl.h:545
llvm::ErrorReported::reportedOrSuccess
static Error reportedOrSuccess(bool HasErrorReported)
Definition:FileCheckImpl.h:558
llvm::ErrorReported::ID
static char ID
Definition:FileCheckImpl.h:547
llvm::ErrorReported::log
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Definition:FileCheckImpl.h:554
llvm::ErrorReported::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:FileCheckImpl.h:549
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::ExpressionAST
Base class representing the AST of a given expression.
Definition:FileCheckImpl.h:126
llvm::ExpressionAST::ExpressionAST
ExpressionAST(StringRef ExpressionStr)
Definition:FileCheckImpl.h:131
llvm::ExpressionAST::eval
virtual Expected< APInt > eval() const =0
Evaluates and.
llvm::ExpressionAST::getExpressionStr
StringRef getExpressionStr() const
Definition:FileCheckImpl.h:135
llvm::ExpressionAST::~ExpressionAST
virtual ~ExpressionAST()=default
llvm::ExpressionAST::getImplicitFormat
virtual Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const
Definition:FileCheckImpl.h:146
llvm::ExpressionLiteral
Class representing an unsigned literal in the AST of an expression.
Definition:FileCheckImpl.h:152
llvm::ExpressionLiteral::ExpressionLiteral
ExpressionLiteral(StringRef ExpressionStr, APInt Val)
Definition:FileCheckImpl.h:158
llvm::ExpressionLiteral::eval
Expected< APInt > eval() const override
Definition:FileCheckImpl.h:162
llvm::Expression
Class representing an expression and its matching format.
Definition:FileCheckImpl.h:189
llvm::Expression::getFormat
ExpressionFormat getFormat() const
Definition:FileCheckImpl.h:207
llvm::Expression::Expression
Expression(std::unique_ptr< ExpressionAST > AST, ExpressionFormat Format)
Generic constructor for an expression represented by the given AST and whose matching format is Forma...
Definition:FileCheckImpl.h:200
llvm::Expression::getAST
ExpressionAST * getAST() const
Definition:FileCheckImpl.h:205
llvm::FileCheckPatternContext
Class holding the Pattern global state, shared by all patterns: tables holding values of variables an...
Definition:FileCheckImpl.h:410
llvm::FileCheckPatternContext::defineCmdlineVariables
Error defineCmdlineVariables(ArrayRef< StringRef > CmdlineDefines, SourceMgr &SM)
Defines string and numeric variables from definitions given on the command line, passed as a vector o...
Definition:FileCheck.cpp:2512
llvm::FileCheckPatternContext::createLineVariable
void createLineVariable()
Create @LINE pseudo variable.
Definition:FileCheck.cpp:1760
llvm::FileCheckPatternContext::getPatternVarValue
Expected< StringRef > getPatternVarValue(StringRef VarName)
Definition:FileCheck.cpp:1360
llvm::FileCheckPatternContext::clearLocalVars
void clearLocalVars()
Undefines local variables (variables whose name does not start with a '$' sign), i....
Definition:FileCheck.cpp:2650
llvm::NotFoundError
Definition:FileCheckImpl.h:521
llvm::NotFoundError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:FileCheckImpl.h:525
llvm::NotFoundError::log
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Definition:FileCheckImpl.h:530
llvm::NotFoundError::ID
static char ID
Definition:FileCheckImpl.h:523
llvm::NumericSubstitution
Definition:FileCheckImpl.h:385
llvm::NumericSubstitution::getResult
Expected< std::string > getResult() const override
Definition:FileCheck.cpp:268
llvm::NumericSubstitution::NumericSubstitution
NumericSubstitution(FileCheckPatternContext *Context, StringRef ExpressionStr, std::unique_ptr< Expression > ExpressionPointer, size_t InsertIdx)
Definition:FileCheckImpl.h:392
llvm::NumericVariableUse
Class representing the use of a numeric variable in the AST of an expression.
Definition:FileCheckImpl.h:280
llvm::NumericVariableUse::NumericVariableUse
NumericVariableUse(StringRef Name, NumericVariable *Variable)
Definition:FileCheckImpl.h:286
llvm::NumericVariableUse::eval
Expected< APInt > eval() const override
Definition:FileCheck.cpp:195
llvm::NumericVariableUse::getImplicitFormat
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Definition:FileCheckImpl.h:293
llvm::NumericVariable
Class representing a numeric variable and its associated current value.
Definition:FileCheckImpl.h:211
llvm::NumericVariable::clearValue
void clearValue()
Clears value of this numeric variable, regardless of whether it is currently defined or not.
Definition:FileCheckImpl.h:268
llvm::NumericVariable::setValue
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...
Definition:FileCheckImpl.h:260
llvm::NumericVariable::getImplicitFormat
ExpressionFormat getImplicitFormat() const
Definition:FileCheckImpl.h:245
llvm::NumericVariable::getName
StringRef getName() const
Definition:FileCheckImpl.h:242
llvm::NumericVariable::getStringValue
std::optional< StringRef > getStringValue() const
Definition:FileCheckImpl.h:255
llvm::NumericVariable::getValue
std::optional< APInt > getValue() const
Definition:FileCheckImpl.h:248
llvm::NumericVariable::NumericVariable
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 ...
Definition:FileCheckImpl.h:236
llvm::NumericVariable::getDefLineNumber
std::optional< size_t > getDefLineNumber() const
Definition:FileCheckImpl.h:275
llvm::OverflowError
Class to represent an overflow error that might result when manipulating a value.
Definition:FileCheckImpl.h:105
llvm::OverflowError::ID
static char ID
Definition:FileCheckImpl.h:107
llvm::OverflowError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:FileCheckImpl.h:113
llvm::OverflowError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:FileCheckImpl.h:109
llvm::Pattern
Definition:FileCheckImpl.h:565
llvm::Pattern::parseVariable
static Expected< VariableProperties > parseVariable(StringRef &Str, const SourceMgr &SM)
Parses the string at the start of Str for a variable name.
Definition:FileCheck.cpp:289
llvm::Pattern::match
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
Definition:FileCheck.cpp:1077
llvm::Pattern::printFuzzyMatch
void printFuzzyMatch(const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
Definition:FileCheck.cpp:1313
llvm::Pattern::printSubstitutions
void printSubstitutions(const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Prints the value of successful substitutions.
Definition:FileCheck.cpp:1205
llvm::Pattern::hasVariable
bool hasVariable() const
Definition:FileCheckImpl.h:716
llvm::Pattern::getLoc
SMLoc getLoc() const
Definition:FileCheckImpl.h:640
llvm::Pattern::getContext
FileCheckPatternContext * getContext() const
Definition:FileCheckImpl.h:644
llvm::Pattern::parseNumericSubstitutionBlock
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...
Definition:FileCheck.cpp:617
llvm::Pattern::Pattern
Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, std::optional< size_t > Line=std::nullopt)
Definition:FileCheckImpl.h:635
llvm::Pattern::printVariableDefs
void printVariableDefs(const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Definition:FileCheck.cpp:1239
llvm::Pattern::isValidVarNameStart
static bool isValidVarNameStart(char C)
Definition:FileCheck.cpp:286
llvm::Pattern::getCount
int getCount() const
Definition:FileCheckImpl.h:724
llvm::Pattern::getCheckTy
Check::FileCheckType getCheckTy() const
Definition:FileCheckImpl.h:722
llvm::Pattern::parsePattern
bool parsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
Parses the pattern in PatternStr and initializes this Pattern instance accordingly.
Definition:FileCheck.cpp:764
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition:SourceMgr.h:281
llvm::SMDiagnostic::print
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
Definition:SourceMgr.cpp:484
llvm::SMDiagnostic::getMessage
StringRef getMessage() const
Definition:SourceMgr.h:311
llvm::SMLoc
Represents a location in source code.
Definition:SMLoc.h:23
llvm::SMLoc::getFromPointer
static SMLoc getFromPointer(const char *Ptr)
Definition:SMLoc.h:36
llvm::SMRange
Represents a range in source code.
Definition:SMLoc.h:48
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition:SourceMgr.h:31
llvm::SourceMgr::DK_Error
@ DK_Error
Definition:SourceMgr.h:34
llvm::SourceMgr::GetMessage
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.
Definition:SourceMgr.cpp:274
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition:StringMap.h:128
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::StringRef::data
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition:StringRef.h:144
llvm::StringSubstitution
Definition:FileCheckImpl.h:374
llvm::StringSubstitution::StringSubstitution
StringSubstitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
Definition:FileCheckImpl.h:376
llvm::StringSubstitution::getResult
Expected< std::string > getResult() const override
Definition:FileCheck.cpp:278
llvm::Substitution
Class representing a substitution to perform in the RegExStr string.
Definition:FileCheckImpl.h:339
llvm::Substitution::~Substitution
virtual ~Substitution()=default
llvm::Substitution::Substitution
Substitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
Definition:FileCheckImpl.h:357
llvm::Substitution::getFromString
StringRef getFromString() const
Definition:FileCheckImpl.h:364
llvm::Substitution::InsertIdx
size_t InsertIdx
Definition:FileCheckImpl.h:354
llvm::Substitution::getIndex
size_t getIndex() const
Definition:FileCheckImpl.h:367
llvm::Substitution::Context
FileCheckPatternContext * Context
Pointer to a class instance holding, among other things, the table with the values of live string var...
Definition:FileCheckImpl.h:347
llvm::Substitution::FromStr
StringRef FromStr
The string that needs to be substituted for something else.
Definition:FileCheckImpl.h:351
llvm::Substitution::getResult
virtual Expected< std::string > getResult() const =0
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::UndefVarError
Class to represent an undefined variable error, which quotes that variable's name when printed.
Definition:FileCheckImpl.h:167
llvm::UndefVarError::UndefVarError
UndefVarError(StringRef VarName)
Definition:FileCheckImpl.h:174
llvm::UndefVarError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:FileCheckImpl.h:178
llvm::UndefVarError::getVarName
StringRef getVarName() const
Definition:FileCheckImpl.h:176
llvm::UndefVarError::ID
static char ID
Definition:FileCheckImpl.h:172
llvm::UndefVarError::log
void log(raw_ostream &OS) const override
Print name of variable associated with this error.
Definition:FileCheckImpl.h:183
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
Error.h
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition:Error.cpp:98
llvm::exprAdd
Expected< APInt > exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Performs operation and.
Definition:FileCheck.cpp:156
llvm::exprMul
Expected< APInt > exprMul(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Definition:FileCheck.cpp:166
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1873
llvm::exprMax
Expected< APInt > exprMax(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Definition:FileCheck.cpp:180
llvm::exprDiv
Expected< APInt > exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Definition:FileCheck.cpp:171
llvm::exprMin
Expected< APInt > exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Definition:FileCheck.cpp:186
llvm::exprSub
Expected< APInt > exprSub(const APInt &Lhs, const APInt &Rhs, bool &Overflow)
Definition:FileCheck.cpp:161
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
llvm::ExpressionFormat
Type representing the format an expression value should be textualized into for matching.
Definition:FileCheckImpl.h:38
llvm::ExpressionFormat::valueFromStringRepr
APInt valueFromStringRepr(StringRef StrVal, const SourceMgr &SM) const
Definition:FileCheck.cpp:137
llvm::ExpressionFormat::toString
StringRef toString() const
Definition:FileCheck.cpp:32
llvm::ExpressionFormat::operator!=
bool operator!=(const ExpressionFormat &Other) const
Definition:FileCheckImpl.h:70
llvm::ExpressionFormat::operator==
bool operator==(Kind OtherValue) const
Definition:FileCheckImpl.h:74
llvm::ExpressionFormat::getMatchingString
Expected< std::string > getMatchingString(APInt Value) const
Definition:FileCheck.cpp:81
llvm::ExpressionFormat::getWildcardRegex
Expected< std::string > getWildcardRegex() const
Definition:FileCheck.cpp:48
llvm::ExpressionFormat::ExpressionFormat
ExpressionFormat(Kind Value)
Definition:FileCheckImpl.h:82
llvm::ExpressionFormat::Kind
Kind
Definition:FileCheckImpl.h:39
llvm::ExpressionFormat::Kind::HexLower
@ HexLower
Value should be printed as a lowercase hex number.
llvm::ExpressionFormat::Kind::HexUpper
@ HexUpper
Value should be printed as an uppercase hex number.
llvm::ExpressionFormat::Kind::Signed
@ Signed
Value is a signed integer and should be printed as a decimal number.
llvm::ExpressionFormat::Kind::Unsigned
@ Unsigned
Value is an unsigned integer and should be printed as a decimal number.
llvm::ExpressionFormat::Kind::NoFormat
@ NoFormat
Denote absence of format.
llvm::ExpressionFormat::ExpressionFormat
ExpressionFormat(Kind Value, unsigned Precision)
Definition:FileCheckImpl.h:83
llvm::ExpressionFormat::operator!=
bool operator!=(Kind OtherValue) const
Definition:FileCheckImpl.h:76
llvm::ExpressionFormat::operator==
bool operator==(const ExpressionFormat &Other) const
Define format equality: formats are equal if neither is NoFormat and their kinds and precision are th...
Definition:FileCheckImpl.h:65
llvm::ExpressionFormat::ExpressionFormat
ExpressionFormat(Kind Value, unsigned Precision, bool AlternateForm)
Definition:FileCheckImpl.h:85
llvm::ExpressionFormat::ExpressionFormat
ExpressionFormat()
Definition:FileCheckImpl.h:81
llvm::FileCheckDiag::MatchType
MatchType
What type of match result does this diagnostic describe?
Definition:FileCheck.h:130
llvm::FileCheckRequest
Contains info about various FileCheck options.
Definition:FileCheck.h:30
llvm::FileCheckString::DagNotPrefixInfo
Hold the information about the DAG/NOT strings in the program, which are not explicitly stored otherw...
Definition:FileCheckImpl.h:829
llvm::FileCheckString::DagNotPrefixInfo::DagNotPat
Pattern DagNotPat
Definition:FileCheckImpl.h:830
llvm::FileCheckString::DagNotPrefixInfo::DagNotPrefix
StringRef DagNotPrefix
Definition:FileCheckImpl.h:831
llvm::FileCheckString::DagNotPrefixInfo::DagNotPrefixInfo
DagNotPrefixInfo(const Pattern &P, StringRef S)
Definition:FileCheckImpl.h:833
llvm::FileCheckString
A check that we found in the input file.
Definition:FileCheckImpl.h:816
llvm::FileCheckString::CheckNext
bool CheckNext(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is a single line in the given Buffer.
Definition:FileCheck.cpp:2246
llvm::FileCheckString::Pat
Pattern Pat
The pattern to match.
Definition:FileCheckImpl.h:818
llvm::FileCheckString::CheckSame
bool CheckSame(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is no newline in the given Buffer.
Definition:FileCheck.cpp:2285
llvm::FileCheckString::DagNotStrings
std::vector< DagNotPrefixInfo > DagNotStrings
Hold the DAG/NOT strings occurring in the input file.
Definition:FileCheckImpl.h:838
llvm::FileCheckString::Loc
SMLoc Loc
The location in the match file that the check string was specified.
Definition:FileCheckImpl.h:824
llvm::FileCheckString::Prefix
StringRef Prefix
Which prefix name this check matched.
Definition:FileCheckImpl.h:821
llvm::FileCheckString::FileCheckString
FileCheckString(Pattern &&P, StringRef S, SMLoc L, std::vector< DagNotPrefixInfo > &&D)
Definition:FileCheckImpl.h:840
llvm::FileCheckString::CheckDag
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".
Definition:FileCheck.cpp:2329
llvm::FileCheckString::CheckNot
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.
Definition:FileCheck.cpp:2307
llvm::Pattern::MatchResult
Definition:FileCheckImpl.h:689
llvm::Pattern::MatchResult::TheError
Error TheError
Definition:FileCheckImpl.h:691
llvm::Pattern::MatchResult::MatchResult
MatchResult(Match M, Error E)
Definition:FileCheckImpl.h:694
llvm::Pattern::MatchResult::MatchResult
MatchResult(size_t MatchPos, size_t MatchLen, Error E)
Definition:FileCheckImpl.h:692
llvm::Pattern::MatchResult::TheMatch
std::optional< Match > TheMatch
Definition:FileCheckImpl.h:690
llvm::Pattern::MatchResult::MatchResult
MatchResult(Error E)
Definition:FileCheckImpl.h:695
llvm::Pattern::Match
Definition:FileCheckImpl.h:685
llvm::Pattern::Match::Len
size_t Len
Definition:FileCheckImpl.h:687
llvm::Pattern::Match::Pos
size_t Pos
Definition:FileCheckImpl.h:686
llvm::Pattern::VariableProperties
Parsing information about a variable.
Definition:FileCheckImpl.h:650
llvm::Pattern::VariableProperties::IsPseudo
bool IsPseudo
Definition:FileCheckImpl.h:652
llvm::Pattern::VariableProperties::Name
StringRef Name
Definition:FileCheckImpl.h:651

Generated on Thu Jul 17 2025 12:20:40 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp