Index: llvm/utils/FileCheck/FileCheck.cpp =================================================================== --- llvm/utils/FileCheck/FileCheck.cpp +++ llvm/utils/FileCheck/FileCheck.cpp @@ -130,6 +130,13 @@ clEnumValN(DumpInputFail, "fail", "Dump input on failure"), clEnumValN(DumpInputNever, "never", "Never dump input"))); +static cl::opt DumpInputContext( + "dump-input-context", cl::init(5), + cl::value_desc("N"), + cl::desc("In input dumps, print at most input lines before and \n" + "input lines after any annotation notes, such as error\n" + "diagnostics and fuzzy matches. Defaults to 5.\n")); + typedef cl::list::const_iterator prefix_iterator; @@ -223,6 +230,12 @@ WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "?"; OS << " marks fuzzy match when no match is found\n"; + // Elided lines. + OS << " - "; + WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "..."; + OS << " indicates elided input lines and annotations, as specified by\n" + << " -dump-input-context\n"; + // Colors. OS << " - colors "; WithColor(OS, raw_ostream::GREEN, true) << "success"; @@ -386,7 +399,7 @@ StringRef InputFileText, std::vector &Annotations, unsigned LabelWidth) { - OS << "Full input was:\n<<<<<<\n"; + OS << "Input was:\n<<<<<<\n"; // Sort annotations. std::sort(Annotations.begin(), Annotations.end(), @@ -457,11 +470,54 @@ // Print annotated input lines. auto AnnotationItr = Annotations.begin(), AnnotationEnd = Annotations.end(); + bool LastLineWasSkipped = false; + unsigned LastLineWithNote = 0; + unsigned NextLineWithNote = 0; for (unsigned Line = 1; InputFilePtr != InputFileEnd || AnnotationItr != AnnotationEnd; ++Line) { const unsigned char *InputFileLine = InputFilePtr; + // Don't print line if not within 10 lines of a note. + for (auto NoteItr = AnnotationItr; + NoteItr != AnnotationEnd && NoteItr->InputLine == Line; ++NoteItr) { + if (!NoteItr->Marker.Note.empty()) { + LastLineWithNote = Line; + break; + } + } + if (!NextLineWithNote || NextLineWithNote < Line) { + auto NoteItr = AnnotationItr; + for (; NoteItr != AnnotationEnd; ++NoteItr) { + if (!NoteItr->Marker.Note.empty()) { + NextLineWithNote = NoteItr->InputLine; + break; + } + } + if (NoteItr == AnnotationEnd) + NextLineWithNote = UINT_MAX; + } + unsigned Context = DumpInputContext.getValue(); + if ((!LastLineWithNote || LastLineWithNote + Context < Line) && + (!NextLineWithNote || Line + Context < NextLineWithNote)) { + while (InputFilePtr != InputFileEnd && *InputFilePtr != '\n') + ++InputFilePtr; + if (InputFilePtr != InputFileEnd) + ++InputFilePtr; + while (AnnotationItr != AnnotationEnd && AnnotationItr->InputLine == Line) + ++AnnotationItr; + if (!LastLineWasSkipped) { + for (int i = 0; i < 3; ++i) { + WithColor(OS, raw_ostream::BLACK, true) + << right_justify(".", LabelWidth); + OS << '\n'; + } + LastLineWasSkipped = true; + } + continue; + } + LastLineWasSkipped = false; + // Print right-aligned line number. WithColor(OS, raw_ostream::BLACK, true) << format_decimal(Line, LabelWidth) << ": "; @@ -685,6 +741,8 @@ << "Check file: " << CheckFilename << "\n" << "\n" << "-dump-input=help describes the format of the following dump.\n" + << "-dump-input-context=N increases the context of diagnostics.\n" + << "-v and -vv add more annotations.\n" << "\n"; std::vector Annotations; unsigned LabelWidth;