From 302fa307d9fbd700209e07e29e62ff5e995f9507 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Tue, 18 Dec 2018 00:03:51 +0000 Subject: [PATCH] [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- 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 --- include/llvm/Support/FileCheck.h | 50 +++++++++++++++-------- lib/Support/FileCheck.cpp | 10 ++--- test/FileCheck/dump-input-annotations.txt | 7 ++++ utils/FileCheck/FileCheck.cpp | 32 +++++++-------- 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/include/llvm/Support/FileCheck.h b/include/llvm/Support/FileCheck.h index edc5424bd21..4061a26e22c 100644 --- a/include/llvm/Support/FileCheck.h +++ b/include/llvm/Support/FileCheck.h @@ -157,32 +157,46 @@ struct FileCheckDiag { Check::FileCheckType CheckTy; /// Where is the FileCheck directive for this diagnostic? unsigned CheckLine, CheckCol; - /// What kind of match result does this diagnostic describe? + /// What type of match result does this diagnostic describe? /// - /// There might be more than one of these for the same directive. For - /// example, there might be several discards before either a final or fail, - /// and there might be a fuzzy match after a fail. + /// A directive's supplied pattern is said to be either expected or excluded + /// depending on whether the pattern must have or must not have a match in + /// order for the directive to succeed. For example, a CHECK directive's + /// pattern is expected, and a CHECK-NOT directive's pattern is excluded. + /// All match result types whose names end with "Excluded" are for excluded + /// patterns, and all others are for expected patterns. + /// + /// There might be more than one match result for a single pattern. For + /// example, there might be several discarded matches + /// (MatchFoundButDiscarded) before either a good match + /// (MatchFoundAndExpected) or a failure to match (MatchNoneButExpected), + /// and there might be a fuzzy match (MatchFuzzy) after the latter. enum MatchType { - // TODO: More members will appear with later patches in this series. - /// Indicates the final match for an expected pattern. - MatchFinalAndExpected, - /// Indicates the final match for an excluded pattern. - MatchFinalButExcluded, - /// Indicates the final match for an expected pattern, but the match is on - /// the wrong line. - MatchFinalButWrongLine, + /// Indicates a good match for an expected pattern. + MatchFoundAndExpected, + /// Indicates a match for an excluded pattern. + MatchFoundButExcluded, + /// Indicates a match for an expected pattern, but the match is on the + /// wrong line. + MatchFoundButWrongLine, /// Indicates a discarded match for an expected pattern. - MatchDiscard, + MatchFoundButDiscarded, /// Indicates no match for an excluded pattern. MatchNoneAndExcluded, - /// Indicates no match for an expected pattern. + /// Indicates no match for an expected pattern, but this might follow good + /// matches when multiple matches are expected for the pattern, or it might + /// follow discarded matches for the pattern. MatchNoneButExpected, - /// Indicates a possible intended match because there's no perfect match. + /// Indicates a fuzzy match that serves as a suggestion for the next + /// intended match for an expected pattern with too few or no good matches. MatchFuzzy, } MatchTy; - /// The match range if MatchTy is not MatchNoneAndExcluded or - /// MatchNoneButExpected, or the search range otherwise. - unsigned InputStartLine, InputStartCol, InputEndLine, InputEndCol; + /// The search range if MatchTy is MatchNoneAndExcluded or + /// MatchNoneButExpected, or the match range otherwise. + unsigned InputStartLine; + unsigned InputStartCol; + unsigned InputEndLine; + unsigned InputEndCol; FileCheckDiag(const SourceMgr &SM, const Check::FileCheckType &CheckTy, SMLoc CheckLoc, MatchType MatchTy, SMRange InputRange); }; diff --git a/lib/Support/FileCheck.cpp b/lib/Support/FileCheck.cpp index cf377bd92e2..37986c96c08 100644 --- a/lib/Support/FileCheck.cpp +++ b/lib/Support/FileCheck.cpp @@ -908,8 +908,8 @@ static void PrintMatch(bool ExpectedMatch, const SourceMgr &SM, return; } SMRange MatchRange = ProcessMatchResult( - ExpectedMatch ? FileCheckDiag::MatchFinalAndExpected - : FileCheckDiag::MatchFinalButExcluded, + ExpectedMatch ? FileCheckDiag::MatchFoundAndExpected + : FileCheckDiag::MatchFoundButExcluded, SM, Loc, Pat.getCheckTy(), Buffer, MatchPos, MatchLen, Diags); std::string Message = formatv("{0}: {1} string found in input", Pat.getCheckTy().getDescription(Prefix), @@ -1062,7 +1062,7 @@ size_t FileCheckString::Check(const SourceMgr &SM, StringRef Buffer, // If this check is a "CHECK-NEXT", verify that the previous match was on // the previous line (i.e. that there is one newline between them). if (CheckNext(SM, SkippedRegion)) { - ProcessMatchResult(FileCheckDiag::MatchFinalButWrongLine, SM, Loc, + ProcessMatchResult(FileCheckDiag::MatchFoundButWrongLine, SM, Loc, Pat.getCheckTy(), MatchBuffer, MatchPos, MatchLen, Diags, Req.Verbose); return StringRef::npos; @@ -1071,7 +1071,7 @@ size_t FileCheckString::Check(const SourceMgr &SM, StringRef Buffer, // If this check is a "CHECK-SAME", verify that the previous match was on // the same line (i.e. that there is no newline between them). if (CheckSame(SM, SkippedRegion)) { - ProcessMatchResult(FileCheckDiag::MatchFinalButWrongLine, SM, Loc, + ProcessMatchResult(FileCheckDiag::MatchFoundButWrongLine, SM, Loc, Pat.getCheckTy(), MatchBuffer, MatchPos, MatchLen, Diags, Req.Verbose); return StringRef::npos; @@ -1283,7 +1283,7 @@ FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer, "match discarded, overlaps earlier DAG match here", {OldRange}); if (Diags) - Diags->rbegin()->MatchTy = FileCheckDiag::MatchDiscard; + Diags->rbegin()->MatchTy = FileCheckDiag::MatchFoundButDiscarded; } MatchPos = MI->End; } diff --git a/test/FileCheck/dump-input-annotations.txt b/test/FileCheck/dump-input-annotations.txt index 3dc7f908aa2..eaf1c941e67 100644 --- a/test/FileCheck/dump-input-annotations.txt +++ b/test/FileCheck/dump-input-annotations.txt @@ -322,6 +322,13 @@ ; RUN: echo 'CHECK-DAG: abc' >> %t.chk ; RUN: echo 'CHECK-DAG: def' >> %t.chk +; Prefixes used here: +; DAG = quiet, -v, or -vv +; DAG-Q = quiet +; DAG-V = -v or -vv (-vv implies -v) +; DAG-VQ = -v and not -vv +; DAG-VV = -vv + ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \ ; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-Q ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \ diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 6f4cf31ec83..fdfd3e7cb7c 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -144,13 +144,13 @@ struct MarkerStyle { static MarkerStyle GetMarker(FileCheckDiag::MatchType MatchTy) { switch (MatchTy) { - case FileCheckDiag::MatchFinalAndExpected: + case FileCheckDiag::MatchFoundAndExpected: return MarkerStyle('^', raw_ostream::GREEN); - case FileCheckDiag::MatchFinalButExcluded: + case FileCheckDiag::MatchFoundButExcluded: return MarkerStyle('!', raw_ostream::RED, "error: no match expected"); - case FileCheckDiag::MatchFinalButWrongLine: + case FileCheckDiag::MatchFoundButWrongLine: return MarkerStyle('!', raw_ostream::RED, "error: match on wrong line"); - case FileCheckDiag::MatchDiscard: + case FileCheckDiag::MatchFoundButDiscarded: return MarkerStyle('!', raw_ostream::CYAN, "discard: overlaps earlier match"); case FileCheckDiag::MatchNoneAndExcluded: @@ -241,8 +241,8 @@ struct InputAnnotation { unsigned InputStartCol, InputEndCol; /// The marker to use. MarkerStyle Marker; - /// Whether this annotation represents a final match for an expected pattern. - bool FinalAndExpectedMatch; + /// Whether this annotation represents a good match for an expected pattern. + bool FoundAndExpectedMatch; }; /// Get an abbreviation for the check type. @@ -310,8 +310,8 @@ static void BuildInputAnnotations(const std::vector &Diags, MarkerStyle Marker = GetMarker(DiagItr->MatchTy); A.Marker = Marker; - A.FinalAndExpectedMatch = - DiagItr->MatchTy == FileCheckDiag::MatchFinalAndExpected; + A.FoundAndExpectedMatch = + DiagItr->MatchTy == FileCheckDiag::MatchFoundAndExpected; // Compute the mark location, and break annotation into multiple // annotations if it spans multiple lines. @@ -351,7 +351,7 @@ static void BuildInputAnnotations(const std::vector &Diags, B.Marker.Note = ""; } else B.InputEndCol = DiagItr->InputEndCol; - B.FinalAndExpectedMatch = A.FinalAndExpectedMatch; + B.FoundAndExpectedMatch = A.FoundAndExpectedMatch; Annotations.push_back(B); } } @@ -424,15 +424,15 @@ static void DumpAnnotatedInput(raw_ostream &OS, const FileCheckRequest &Req, WithColor(OS, raw_ostream::BLACK, true) << format_decimal(Line, LabelWidth) << ": "; - // For case where -v and colors are enabled, find the annotations for final - // matches for expected patterns in order to highlight everything else in - // the line. There are no such annotations if -v is disabled. - std::vector FinalAndExpectedMatches; + // For the case where -v and colors are enabled, find the annotations for + // good matches for expected patterns in order to highlight everything + // else in the line. There are no such annotations if -v is disabled. + std::vector FoundAndExpectedMatches; if (Req.Verbose && WithColor(OS).colorsEnabled()) { for (auto I = AnnotationItr; I != AnnotationEnd && I->InputLine == Line; ++I) { - if (I->FinalAndExpectedMatch) - FinalAndExpectedMatches.push_back(*I); + if (I->FoundAndExpectedMatch) + FoundAndExpectedMatches.push_back(*I); } } @@ -447,7 +447,7 @@ static void DumpAnnotatedInput(raw_ostream &OS, const FileCheckRequest &Req, for (unsigned Col = 1; InputFilePtr != InputFileEnd && !Newline; ++Col) { bool WasInMatch = InMatch; InMatch = false; - for (auto M : FinalAndExpectedMatches) { + for (auto M : FoundAndExpectedMatches) { if (M.InputStartCol <= Col && Col < M.InputEndCol) { InMatch = true; break; -- 2.50.1