LLVM: lib/FileCheck/FileCheckImpl.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
16#define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
17
24#include
25#include
26#include
27#include
28
29namespace llvm {
30
31
32
33
34
35
36
37
40
41
43
45
47
49
51 };
52
53private:
55 unsigned Precision = 0;
56
57 bool AlternateForm = false;
58
59public:
60
62
63
64
67 Precision == Other.Precision && AlternateForm == Other.AlternateForm;
68 }
69
71 return !(*this == Other);
72 }
73
75
76 bool operator!=(Kind OtherValue) const { return !(*this == OtherValue); }
77
78
80
84 : Value(Value), Precision(Precision){};
86 : Value(Value), Precision(Precision), AlternateForm(AlternateForm){};
87
88
89
90
92
93
94
95
97
98
99
101};
102
103
104
106public:
108
110 return std::make_error_code(std::errc::value_too_large);
111 }
112
114};
115
116
117
118Expected exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
119Expected exprSub(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
120Expected exprMul(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
121Expected exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
122Expected exprMax(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
123Expected exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow);
124
125
127private:
129
130public:
132
134
136
137
138
140
141
142
143
144
148 }
149};
150
151
153private:
154
156
157public:
160
161
163};
164
165
166
168private:
170
171public:
173
175
177
180 }
181
182
184 OS << "undefined variable: " << VarName;
185 }
186};
187
188
190private:
191
192 std::unique_ptr AST;
193
194
196
197public:
198
199
201 : AST(std::move(AST)), Format(Format) {}
202
203
204
206
208};
209
210
212private:
213
215
216
217
219
220
221 std::optional Value;
222
223
224
225 std::optional StrValue;
226
227
228
229
230 std::optional<size_t> DefLineNumber;
231
232public:
233
234
235
237 std::optional<size_t> DefLineNumber = std::nullopt)
238 : Name(Name), ImplicitFormat(ImplicitFormat),
239 DefLineNumber(DefLineNumber) {}
240
241
243
244
246
247
249
250
251
252
253
254
255 std::optional getStringValue() const { return StrValue; }
256
257
258
259
261 std::optional NewStrValue = std::nullopt) {
262 Value = NewValue;
263 StrValue = NewStrValue;
264 }
265
266
267
269 Value = std::nullopt;
270 StrValue = std::nullopt;
271 }
272
273
274
276};
277
278
279
281private:
282
284
285public:
288
290
291
295 }
296};
297
298
300
301
303private:
304
305 std::unique_ptr LeftOperand;
306
307
308 std::unique_ptr RightOperand;
309
310
312
313public:
315 std::unique_ptr LeftOp,
316 std::unique_ptr RightOp)
317 : ExpressionAST(ExpressionStr), EvalBinop(EvalBinop) {
318 LeftOperand = std::move(LeftOp);
319 RightOperand = std::move(RightOp);
320 }
321
322
323
324
325
327
328
329
330
331
334};
335
336class FileCheckPatternContext;
337
338
340protected:
341
342
343
344
345
346
348
349
350
352
353
355
356public:
360
362
363
365
366
368
369
370
372};
373
375public:
379
380
381
383};
384
386private:
387
388
389 std::unique_ptr ExpressionPointer;
390
391public:
393 std::unique_ptr ExpressionPointer,
396 ExpressionPointer(std::move(ExpressionPointer)) {}
397
398
399
401};
402
403
404
405
406
407
408
409
412
413private:
414
415
416
417
419
420
421
422
424
425
426
427
428
430
431
432
434
435
436
437 std::vector<std::unique_ptr> NumericVariables;
438
439
440
441 std::vector<std::unique_ptr> Expressions;
442
443
444
445 std::vector<std::unique_ptr> Substitutions;
446
447public:
448
449
451
452
453
454
455
458
459
460
462
463
464
465
466
468
469private:
470
471
472 template <class... Types> NumericVariable *makeNumericVariable(Types... args);
473
474
475
477
478
479
481 std::unique_ptr Expression,
482 size_t InsertIdx);
483};
484
485
486
488private:
491
492public:
494
497
500 }
501
502
504
507
509 SMRange Range = std::nullopt) {
510 return make_error(
512 }
513
517 return get(SM, Start, ErrMsg, SMRange(Start, End));
518 }
519};
520
522public:
524
527 }
528
529
531 OS << "String not found in input";
532 }
533};
534
535
536
537
538
539
540
541
542
543
544
546public:
548
551 }
552
553
555 OS << "error previously reported";
556 }
557
559 if (HasErrorReported)
560 return make_error();
562 }
563};
564
566 SMLoc PatternLoc;
567
568
569
571
572
573
574 std::string RegExStr;
575
576
577
578
579
580
581
582 std::vector<Substitution *> Substitutions;
583
584
585
586
587
588
589
590
591
592
593
594
595 std::map<StringRef, unsigned> VariableDefs;
596
597
598
599
600
601 struct NumericVariableMatch {
602
603
605
606
607
608 unsigned CaptureParenGroup;
609 };
610
611
612
613
615
616
617
618
619
620
621
623
625
626
627
628
629 std::optional<size_t> LineNumber;
630
631
632 bool IgnoreCase = false;
633
634public:
636 std::optional<size_t> Line = std::nullopt)
637 : Context(Context), CheckTy(Ty), LineNumber(Line) {}
638
639
641
642
643
645
646
648
649
653 };
654
655
656
657
658
659
662
663
664
665
666
667
668
669
670
671
673 StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
674 bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
676
677
678
679
680
681
682
688 };
696 };
697
698
699
700
701
702
703
704
705
706
707
709
712 std::vector *Diags) const;
714 std::vector *Diags) const;
715
717 return !(Substitutions.empty() && VariableDefs.empty());
718 }
720 std::vector *Diags) const;
721
723
725
726private:
727 bool AddRegExToRegEx(StringRef RS, unsigned &CurParen, SourceMgr &SM);
728 void AddBackrefToRegEx(unsigned BackrefNum);
729
730
731
732 unsigned computeMatchDistance(StringRef Buffer) const;
733
734
735
736
737
738
740
741
742
743
744
745
748 std::optional<size_t> LineNumber, ExpressionFormat ImplicitFormat,
750
751
752
753
754
755
757 StringRef Name, bool IsPseudo, std::optional<size_t> LineNumber,
759 enum class AllowedOperand { LineVar, LegacyLiteral, Any };
760
761
762
763
764
765
766
767
768
769 static Expected<std::unique_ptr>
770 parseNumericOperand(StringRef &Expr, AllowedOperand AO, bool ConstraintParsed,
771 std::optional<size_t> LineNumber,
772 FileCheckPatternContext *Context, const SourceMgr &SM);
773
774
775
776
777
778
779
780
781
782 static Expected<std::unique_ptr>
783 parseBinop(StringRef Expr, StringRef &RemainingExpr,
784 std::unique_ptr LeftOp, bool IsLegacyLineExpr,
785 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
786 const SourceMgr &SM);
787
788
789
790
791
792
793
794 static Expected<std::unique_ptr>
795 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
796 FileCheckPatternContext *Context, const SourceMgr &SM);
797
798
799
800
801
802
803
804
805 static Expected<std::unique_ptr>
806 parseCallExpr(StringRef &Expr, StringRef FuncName,
807 std::optional<size_t> LineNumber,
808 FileCheckPatternContext *Context, const SourceMgr &SM);
809};
810
811
812
813
814
815
817
819
820
822
823
825
826
827
828
832
835 };
836
837
839
841 std::vector &&D)
843
844
845 size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode,
847 std::vector *Diags) const;
848
849
850
852
853
855
856
857
859 const std::vector<const DagNotPrefixInfo *> &NotStrings,
861 std::vector *Diags) const;
862
864 std::vector<const DagNotPrefixInfo *> &NotStrings,
866 std::vector *Diags) const;
867};
868
869}
870
871#endif
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")
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.
Type representing the format an expression value should be textualized into for matching.
APInt valueFromStringRepr(StringRef StrVal, const SourceMgr &SM) const
StringRef toString() const
bool operator!=(const ExpressionFormat &Other) const
bool operator==(Kind OtherValue) const
Expected< std::string > getMatchingString(APInt Value) const
Expected< std::string > getWildcardRegex() const
ExpressionFormat(Kind Value)
@ HexLower
Value should be printed as a lowercase hex number.
@ HexUpper
Value should be printed as an uppercase hex number.
@ Signed
Value is a signed integer and should be printed as a decimal number.
@ Unsigned
Value is an unsigned integer and should be printed as a decimal number.
@ NoFormat
Denote absence of format.
ExpressionFormat(Kind Value, unsigned Precision)
bool operator!=(Kind OtherValue) const
bool operator==(const ExpressionFormat &Other) const
Define format equality: formats are equal if neither is NoFormat and their kinds and precision are th...
ExpressionFormat(Kind Value, unsigned Precision, bool AlternateForm)
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.