llvm.org GIT mirror llvm / ac7830e
[FileCheck] Clean up doxygen comments throughout. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289380 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 3 years ago
1 changed file(s) with 62 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
8888 CheckDAG,
8989 CheckLabel,
9090
91 /// MatchEOF - When set, this pattern only matches the end of file. This is
92 /// used for trailing CHECK-NOTs.
91 /// Indicates the pattern only matches the end of file. This is used for
92 /// trailing CHECK-NOTs.
9393 CheckEOF,
94 /// CheckBadNot - Found -NOT combined with another CHECK suffix.
94
95 /// Marks when parsing found a -NOT check combined with another CHECK suffix.
9596 CheckBadNot
9697 };
9798 }
99100 class Pattern {
100101 SMLoc PatternLoc;
101102
102 /// FixedStr - If non-empty, this pattern is a fixed string match with the
103 /// specified fixed string.
103 /// A fixed string to match as the pattern or empty if this pattern requires
104 /// a regex match.
104105 StringRef FixedStr;
105106
106 /// RegEx - If non-empty, this is a regex pattern.
107 /// A regex string to match as the pattern or empty if this pattern requires
108 /// a fixed string to match.
107109 std::string RegExStr;
108110
109 /// VariableUses - Entries in this vector map to uses of a variable in the
110 /// pattern, e.g. "foo[[bar]]baz". In this case, the RegExStr will contain
111 /// "foobaz" and we'll get an entry in this vector that tells us to insert the
112 /// value of bar at offset 3.
111 /// Entries in this vector map to uses of a variable in the pattern, e.g.
112 /// "foo[[bar]]baz". In this case, the RegExStr will contain "foobaz" and
113 /// we'll get an entry in this vector that tells us to insert the value of
114 /// bar at offset 3.
113115 std::vector> VariableUses;
114116
115 /// VariableDefs - Maps definitions of variables to their parenthesized
116 /// capture numbers.
117 /// E.g. for the pattern "foo[[bar:.*]]baz", VariableDefs will map "bar" to 1.
117 /// Maps definitions of variables to their parenthesized capture numbers.
118 ///
119 /// E.g. for the pattern "foo[[bar:.*]]baz", VariableDefs will map "bar" to
120 /// 1.
118121 std::map VariableDefs;
119122
120123 Check::CheckType CheckTy;
121124
122 /// \brief Contains the number of line this pattern is in.
125 /// Contains the number of line this pattern is in.
123126 unsigned LineNumber;
124127
125128 public:
126129 explicit Pattern(Check::CheckType Ty) : CheckTy(Ty) {}
127130
128 /// getLoc - Return the location in source code.
131 /// Returns the location in source code.
129132 SMLoc getLoc() const { return PatternLoc; }
130133
131 /// ParsePattern - Parse the given string into the Pattern. Prefix provides
132 /// which prefix is being matched, SM provides the SourceMgr used for error
133 /// reports, and LineNumber is the line number in the input file from which
134 /// the pattern string was read. Returns true in case of an error, false
135 /// otherwise.
136134 bool ParsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM,
137135 unsigned LineNumber);
138
139 /// Match - Match the pattern string against the input buffer Buffer. This
140 /// returns the position that is matched or npos if there is no match. If
141 /// there is a match, the size of the matched string is returned in MatchLen.
142 ///
143 /// The VariableTable StringMap provides the current values of filecheck
144 /// variables and is updated if this match defines new values.
145136 size_t Match(StringRef Buffer, size_t &MatchLen,
146137 StringMap &VariableTable) const;
147
148 /// PrintFailureInfo - Print additional information about a failure to match
149 /// involving this pattern.
150138 void PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
151139 const StringMap &VariableTable) const;
152140
159147 private:
160148 bool AddRegExToRegEx(StringRef RS, unsigned &CurParen, SourceMgr &SM);
161149 void AddBackrefToRegEx(unsigned BackrefNum);
162
163 /// ComputeMatchDistance - Compute an arbitrary estimate for the quality of
164 /// matching this pattern at the start of \arg Buffer; a distance of zero
165 /// should correspond to a perfect match.
166150 unsigned
167151 ComputeMatchDistance(StringRef Buffer,
168152 const StringMap &VariableTable) const;
169
170 /// \brief Evaluates expression and stores the result to \p Value.
171 /// \return true on success. false when the expression has invalid syntax.
172153 bool EvaluateExpression(StringRef Expr, std::string &Value) const;
173
174 /// \brief Finds the closing sequence of a regex variable usage or
175 /// definition. Str has to point in the beginning of the definition
176 /// (right after the opening sequence).
177 /// \return offset of the closing sequence within Str, or npos if it was not
178 /// found.
179154 size_t FindRegexVarEnd(StringRef Str, SourceMgr &SM);
180155 };
181156
157 /// Parses the given string into the Pattern.
158 ///
159 /// \p Prefix provides which prefix is being matched, \p SM provides the
160 /// SourceMgr used for error reports, and \p LineNumber is the line number in
161 /// the input file from which the pattern string was read. Returns true in
162 /// case of an error, false otherwise.
182163 bool Pattern::ParsePattern(StringRef PatternStr, StringRef Prefix,
183164 SourceMgr &SM, unsigned LineNumber) {
184165 bool MatchFullLinesHere = MatchFullLines && CheckTy != Check::CheckNot;
372353 RegExStr += Backref;
373354 }
374355
356 /// Evaluates expression and stores the result to \p Value.
357 ///
358 /// Returns true on success and false when the expression has invalid syntax.
375359 bool Pattern::EvaluateExpression(StringRef Expr, std::string &Value) const {
376360 // The only supported expression is @LINE([\+-]\d+)?
377361 if (!Expr.startswith("@LINE"))
390374 return true;
391375 }
392376
393 /// Match - Match the pattern string against the input buffer Buffer. This
394 /// returns the position that is matched or npos if there is no match. If
395 /// there is a match, the size of the matched string is returned in MatchLen.
377 /// Matches the pattern string against the input buffer \p Buffer
378 ///
379 /// This returns the position that is matched or npos if there is no match. If
380 /// there is a match, the size of the matched string is returned in \p
381 /// MatchLen.
382 ///
383 /// The \p VariableTable StringMap provides the current values of filecheck
384 /// variables and is updated if this match defines new values.
396385 size_t Pattern::Match(StringRef Buffer, size_t &MatchLen,
397386 StringMap &VariableTable) const {
398387 // If this is the EOF pattern, match it immediately.
462451 return FullMatch.data() - Buffer.data();
463452 }
464453
454
455 /// Computes an arbitrary estimate for the quality of matching this pattern at
456 /// the start of \p Buffer; a distance of zero should correspond to a perfect
457 /// match.
465458 unsigned
466459 Pattern::ComputeMatchDistance(StringRef Buffer,
467460 const StringMap &VariableTable) const {
481474 return BufferPrefix.edit_distance(ExampleString);
482475 }
483476
477 /// Prints additional information about a failure to match involving this
478 /// pattern.
484479 void Pattern::PrintFailureInfo(
485480 const SourceMgr &SM, StringRef Buffer,
486481 const StringMap &VariableTable) const {
561556 }
562557 }
563558
559 /// Finds the closing sequence of a regex variable usage or definition.
560 ///
561 /// \p Str has to point in the beginning of the definition (right after the
562 /// opening sequence). Returns the offset of the closing sequence within Str,
563 /// or npos if it was not found.
564564 size_t Pattern::FindRegexVarEnd(StringRef Str, SourceMgr &SM) {
565565 // Offset keeps track of the current offset within the input Str
566566 size_t Offset = 0;
603603 // Check Strings.
604604 //===----------------------------------------------------------------------===//
605605
606 /// CheckString - This is a check that we found in the input file.
606 /// A check that we found in the input file.
607607 struct CheckString {
608 /// Pat - The pattern to match.
608 /// The pattern to match.
609609 Pattern Pat;
610610
611 /// Prefix - Which prefix name this check matched.
611 /// Which prefix name this check matched.
612612 StringRef Prefix;
613613
614 /// Loc - The location in the match file that the check string was specified.
614 /// The location in the match file that the check string was specified.
615615 SMLoc Loc;
616616
617 /// CheckTy - Specify what kind of check this is. e.g. CHECK-NEXT: directive,
618 /// as opposed to a CHECK: directive.
619 // Check::CheckType CheckTy;
620
621 /// DagNotStrings - These are all of the strings that are disallowed from
622 /// occurring between this match string and the previous one (or start of
623 /// file).
617 /// All of the strings that are disallowed from occurring between this match
618 /// string and the previous one (or start of file).
624619 std::vector DagNotStrings;
625620
626621 CheckString(const Pattern &P, StringRef S, SMLoc L)
627622 : Pat(P), Prefix(S), Loc(L) {}
628623
629 /// Check - Match check string and its "not strings" and/or "dag strings".
630624 size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode,
631625 size_t &MatchLen, StringMap &VariableTable) const;
632626
633 /// CheckNext - Verify there is a single line in the given buffer.
634627 bool CheckNext(const SourceMgr &SM, StringRef Buffer) const;
635
636 /// CheckSame - Verify there is no newline in the given buffer.
637628 bool CheckSame(const SourceMgr &SM, StringRef Buffer) const;
638
639 /// CheckNot - Verify there's no "not strings" in the given buffer.
640629 bool CheckNot(const SourceMgr &SM, StringRef Buffer,
641630 const std::vector &NotStrings,
642631 StringMap &VariableTable) const;
643
644 /// CheckDag - Match "dag strings" and their mixed "not strings".
645632 size_t CheckDag(const SourceMgr &SM, StringRef Buffer,
646633 std::vector &NotStrings,
647634 StringMap &VariableTable) const;
849836 return StringRef();
850837 }
851838
852 /// ReadCheckFile - Read the check file, which specifies the sequence of
853 /// expected strings. The strings are added to the CheckStrings vector.
854 /// Returns true in case of an error, false otherwise.
839 /// Read the check file, which specifies the sequence of expected strings.
840 ///
841 /// The strings are added to the CheckStrings vector. Returns true in case of
842 /// an error, false otherwise.
855843 static bool ReadCheckFile(SourceMgr &SM, StringRef Buffer,
856844 std::vector &CheckStrings) {
857845 std::vector ImplicitNegativeChecks;
1003991 PrintCheckFailed(SM, CheckStr.Loc, CheckStr.Pat, Buffer, VariableTable);
1004992 }
1005993
1006 /// CountNumNewlinesBetween - Count the number of newlines in the specified
1007 /// range.
994 /// Count the number of newlines in the specified range.
1008995 static unsigned CountNumNewlinesBetween(StringRef Range,
1009996 const char *&FirstNewLine) {
1010997 unsigned NumNewLines = 0;
10271014 }
10281015 }
10291016
1017 /// Match check string and its "not strings" and/or "dag strings".
10301018 size_t CheckString::Check(const SourceMgr &SM, StringRef Buffer,
10311019 bool IsLabelScanMode, size_t &MatchLen,
10321020 StringMap &VariableTable) const {
10761064 return LastPos + MatchPos;
10771065 }
10781066
1067 /// Verify there is a single line in the given buffer.
10791068 bool CheckString::CheckNext(const SourceMgr &SM, StringRef Buffer) const {
10801069 if (Pat.getCheckTy() != Check::CheckNext)
10811070 return false;
11161105 return false;
11171106 }
11181107
1108 /// Verify there is no newline in the given buffer.
11191109 bool CheckString::CheckSame(const SourceMgr &SM, StringRef Buffer) const {
11201110 if (Pat.getCheckTy() != Check::CheckSame)
11211111 return false;
11441134 return false;
11451135 }
11461136
1137 /// Verify there's no "not strings" in the given buffer.
11471138 bool CheckString::CheckNot(const SourceMgr &SM, StringRef Buffer,
11481139 const std::vector &NotStrings,
11491140 StringMap &VariableTable) const {
11661157 return false;
11671158 }
11681159
1160 /// Match "dag strings" and their mixed "not strings".
11691161 size_t CheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
11701162 std::vector &NotStrings,
11711163 StringMap &VariableTable) const {