llvm.org GIT mirror llvm / 302fa30
[FileCheck] Annotate input dump (final tweaks) Apply final suggestions from probinson for this patch series plus a few more tweaks: * Improve various docs, for MatchType in particular. * Rename some members of MatchType. The main problem was that the term "final match" became a misnomer when CHECK-COUNT-<N> was created. * Split InputStartLine, etc. declarations into multiple lines. Differential Revision: https://reviews.llvm.org/D55738 Reviewed By: probinson git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349425 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 1 year, 3 months ago
4 changed file(s) with 61 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
156156 Check::FileCheckType CheckTy;
157157 /// Where is the FileCheck directive for this diagnostic?
158158 unsigned CheckLine, CheckCol;
159 /// What kind of match result does this diagnostic describe?
160 ///
161 /// There might be more than one of these for the same directive. For
162 /// example, there might be several discards before either a final or fail,
163 /// and there might be a fuzzy match after a fail.
159 /// What type of match result does this diagnostic describe?
160 ///
161 /// A directive's supplied pattern is said to be either expected or excluded
162 /// depending on whether the pattern must have or must not have a match in
163 /// order for the directive to succeed. For example, a CHECK directive's
164 /// pattern is expected, and a CHECK-NOT directive's pattern is excluded.
165 /// All match result types whose names end with "Excluded" are for excluded
166 /// patterns, and all others are for expected patterns.
167 ///
168 /// There might be more than one match result for a single pattern. For
169 /// example, there might be several discarded matches
170 /// (MatchFoundButDiscarded) before either a good match
171 /// (MatchFoundAndExpected) or a failure to match (MatchNoneButExpected),
172 /// and there might be a fuzzy match (MatchFuzzy) after the latter.
164173 enum MatchType {
165 // TODO: More members will appear with later patches in this series.
166 /// Indicates the final match for an expected pattern.
167 MatchFinalAndExpected,
168 /// Indicates the final match for an excluded pattern.
169 MatchFinalButExcluded,
170 /// Indicates the final match for an expected pattern, but the match is on
171 /// the wrong line.
172 MatchFinalButWrongLine,
174 /// Indicates a good match for an expected pattern.
175 MatchFoundAndExpected,
176 /// Indicates a match for an excluded pattern.
177 MatchFoundButExcluded,
178 /// Indicates a match for an expected pattern, but the match is on the
179 /// wrong line.
180 MatchFoundButWrongLine,
173181 /// Indicates a discarded match for an expected pattern.
174 MatchDiscard,
182 MatchFoundButDiscarded,
175183 /// Indicates no match for an excluded pattern.
176184 MatchNoneAndExcluded,
177 /// Indicates no match for an expected pattern.
185 /// Indicates no match for an expected pattern, but this might follow good
186 /// matches when multiple matches are expected for the pattern, or it might
187 /// follow discarded matches for the pattern.
178188 MatchNoneButExpected,
179 /// Indicates a possible intended match because there's no perfect match.
189 /// Indicates a fuzzy match that serves as a suggestion for the next
190 /// intended match for an expected pattern with too few or no good matches.
180191 MatchFuzzy,
181192 } MatchTy;
182 /// The match range if MatchTy is not MatchNoneAndExcluded or
183 /// MatchNoneButExpected, or the search range otherwise.
184 unsigned InputStartLine, InputStartCol, InputEndLine, InputEndCol;
193 /// The search range if MatchTy is MatchNoneAndExcluded or
194 /// MatchNoneButExpected, or the match range otherwise.
195 unsigned InputStartLine;
196 unsigned InputStartCol;
197 unsigned InputEndLine;
198 unsigned InputEndCol;
185199 FileCheckDiag(const SourceMgr &SM, const Check::FileCheckType &CheckTy,
186200 SMLoc CheckLoc, MatchType MatchTy, SMRange InputRange);
187201 };
907907 return;
908908 }
909909 SMRange MatchRange = ProcessMatchResult(
910 ExpectedMatch ? FileCheckDiag::MatchFinalAndExpected
911 : FileCheckDiag::MatchFinalButExcluded,
910 ExpectedMatch ? FileCheckDiag::MatchFoundAndExpected
911 : FileCheckDiag::MatchFoundButExcluded,
912912 SM, Loc, Pat.getCheckTy(), Buffer, MatchPos, MatchLen, Diags);
913913 std::string Message = formatv("{0}: {1} string found in input",
914914 Pat.getCheckTy().getDescription(Prefix),
10611061 // If this check is a "CHECK-NEXT", verify that the previous match was on
10621062 // the previous line (i.e. that there is one newline between them).
10631063 if (CheckNext(SM, SkippedRegion)) {
1064 ProcessMatchResult(FileCheckDiag::MatchFinalButWrongLine, SM, Loc,
1064 ProcessMatchResult(FileCheckDiag::MatchFoundButWrongLine, SM, Loc,
10651065 Pat.getCheckTy(), MatchBuffer, MatchPos, MatchLen,
10661066 Diags, Req.Verbose);
10671067 return StringRef::npos;
10701070 // If this check is a "CHECK-SAME", verify that the previous match was on
10711071 // the same line (i.e. that there is no newline between them).
10721072 if (CheckSame(SM, SkippedRegion)) {
1073 ProcessMatchResult(FileCheckDiag::MatchFinalButWrongLine, SM, Loc,
1073 ProcessMatchResult(FileCheckDiag::MatchFoundButWrongLine, SM, Loc,
10741074 Pat.getCheckTy(), MatchBuffer, MatchPos, MatchLen,
10751075 Diags, Req.Verbose);
10761076 return StringRef::npos;
12821282 "match discarded, overlaps earlier DAG match here",
12831283 {OldRange});
12841284 if (Diags)
1285 Diags->rbegin()->MatchTy = FileCheckDiag::MatchDiscard;
1285 Diags->rbegin()->MatchTy = FileCheckDiag::MatchFoundButDiscarded;
12861286 }
12871287 MatchPos = MI->End;
12881288 }
320320 ; RUN: echo 'CHECK-DAG: abc' >> %t.chk
321321 ; RUN: echo 'CHECK-DAG: abc' >> %t.chk
322322 ; RUN: echo 'CHECK-DAG: def' >> %t.chk
323
324 ; Prefixes used here:
325 ; DAG = quiet, -v, or -vv
326 ; DAG-Q = quiet
327 ; DAG-V = -v or -vv (-vv implies -v)
328 ; DAG-VQ = -v and not -vv
329 ; DAG-VV = -vv
323330
324331 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
325332 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-Q
143143
144144 static MarkerStyle GetMarker(FileCheckDiag::MatchType MatchTy) {
145145 switch (MatchTy) {
146 case FileCheckDiag::MatchFinalAndExpected:
146 case FileCheckDiag::MatchFoundAndExpected:
147147 return MarkerStyle('^', raw_ostream::GREEN);
148 case FileCheckDiag::MatchFinalButExcluded:
148 case FileCheckDiag::MatchFoundButExcluded:
149149 return MarkerStyle('!', raw_ostream::RED, "error: no match expected");
150 case FileCheckDiag::MatchFinalButWrongLine:
150 case FileCheckDiag::MatchFoundButWrongLine:
151151 return MarkerStyle('!', raw_ostream::RED, "error: match on wrong line");
152 case FileCheckDiag::MatchDiscard:
152 case FileCheckDiag::MatchFoundButDiscarded:
153153 return MarkerStyle('!', raw_ostream::CYAN,
154154 "discard: overlaps earlier match");
155155 case FileCheckDiag::MatchNoneAndExcluded:
240240 unsigned InputStartCol, InputEndCol;
241241 /// The marker to use.
242242 MarkerStyle Marker;
243 /// Whether this annotation represents a final match for an expected pattern.
244 bool FinalAndExpectedMatch;
243 /// Whether this annotation represents a good match for an expected pattern.
244 bool FoundAndExpectedMatch;
245245 };
246246
247247 /// Get an abbreviation for the check type.
309309
310310 MarkerStyle Marker = GetMarker(DiagItr->MatchTy);
311311 A.Marker = Marker;
312 A.FinalAndExpectedMatch =
313 DiagItr->MatchTy == FileCheckDiag::MatchFinalAndExpected;
312 A.FoundAndExpectedMatch =
313 DiagItr->MatchTy == FileCheckDiag::MatchFoundAndExpected;
314314
315315 // Compute the mark location, and break annotation into multiple
316316 // annotations if it spans multiple lines.
350350 B.Marker.Note = "";
351351 } else
352352 B.InputEndCol = DiagItr->InputEndCol;
353 B.FinalAndExpectedMatch = A.FinalAndExpectedMatch;
353 B.FoundAndExpectedMatch = A.FoundAndExpectedMatch;
354354 Annotations.push_back(B);
355355 }
356356 }
423423 WithColor(OS, raw_ostream::BLACK, true)
424424 << format_decimal(Line, LabelWidth) << ": ";
425425
426 // For case where -v and colors are enabled, find the annotations for final
427 // matches for expected patterns in order to highlight everything else in
428 // the line. There are no such annotations if -v is disabled.
429 std::vector FinalAndExpectedMatches;
426 // For the case where -v and colors are enabled, find the annotations for
427 // good matches for expected patterns in order to highlight everything
428 // else in the line. There are no such annotations if -v is disabled.
429 std::vector FoundAndExpectedMatches;
430430 if (Req.Verbose && WithColor(OS).colorsEnabled()) {
431431 for (auto I = AnnotationItr; I != AnnotationEnd && I->InputLine == Line;
432432 ++I) {
433 if (I->FinalAndExpectedMatch)
434 FinalAndExpectedMatches.push_back(*I);
433 if (I->FoundAndExpectedMatch)
434 FoundAndExpectedMatches.push_back(*I);
435435 }
436436 }
437437
446446 for (unsigned Col = 1; InputFilePtr != InputFileEnd && !Newline; ++Col) {
447447 bool WasInMatch = InMatch;
448448 InMatch = false;
449 for (auto M : FinalAndExpectedMatches) {
449 for (auto M : FoundAndExpectedMatches) {
450450 if (M.InputStartCol <= Col && Col < M.InputEndCol) {
451451 InMatch = true;
452452 break;