Skip to content

Commit

Permalink
[FileCheck] Annotate input dump (final tweaks)
Browse files Browse the repository at this point in the history
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

llvm-svn: 349425
  • Loading branch information
jdenny-ornl committed Dec 18, 2018
1 parent 96f0e84 commit e2afb61
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 39 deletions.
50 changes: 32 additions & 18 deletions llvm/include/llvm/Support/FileCheck.h
Expand Up @@ -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);
};
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Support/FileCheck.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions llvm/test/FileCheck/dump-input-annotations.txt
Expand Up @@ -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 \
Expand Down
32 changes: 16 additions & 16 deletions llvm/utils/FileCheck/FileCheck.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -310,8 +310,8 @@ static void BuildInputAnnotations(const std::vector<FileCheckDiag> &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.
Expand Down Expand Up @@ -351,7 +351,7 @@ static void BuildInputAnnotations(const std::vector<FileCheckDiag> &Diags,
B.Marker.Note = "";
} else
B.InputEndCol = DiagItr->InputEndCol;
B.FinalAndExpectedMatch = A.FinalAndExpectedMatch;
B.FoundAndExpectedMatch = A.FoundAndExpectedMatch;
Annotations.push_back(B);
}
}
Expand Down Expand Up @@ -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<InputAnnotation> 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<InputAnnotation> 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);
}
}

Expand All @@ -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;
Expand Down

0 comments on commit e2afb61

Please sign in to comment.