Ejemplo n.º 1
0
void
SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
                                             const LineCoverageInfo &Line) {
  if (!Line.isMapped()) {
    OS.indent(LineCoverageColumnWidth) << '|';
    return;
  }
  std::string C = formatCount(Line.ExecutionCount);
  OS.indent(LineCoverageColumnWidth - C.size());
  colored_ostream(OS, raw_ostream::MAGENTA,
                  Line.hasMultipleRegions() && Options.Colors)
      << C;
  OS << '|';
}
Ejemplo n.º 2
0
void
SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
                                             const LineCoverageInfo &Line) {
  if (!Line.isMapped()) {
    OS.indent(LineCoverageColumnWidth) << '|';
    return;
  }
  SmallString<32> Buffer;
  raw_svector_ostream BufferOS(Buffer);
  BufferOS << Line.ExecutionCount;
  auto Str = BufferOS.str();
  // Trim
  Str = Str.substr(0, std::min(Str.size(), (size_t)LineCoverageColumnWidth));
  // Align to the right
  OS.indent(LineCoverageColumnWidth - Str.size());
  colored_ostream(OS, raw_ostream::MAGENTA,
                  Line.hasMultipleRegions() && Options.Colors)
      << Str;
  OS << '|';
}
Ejemplo n.º 3
0
void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
                                unsigned IndentLevel) {
  // The width of the leading columns
  unsigned CombinedColumnWidth =
      (Options.ShowLineStats ? LineCoverageColumnWidth + 1 : 0) +
      (Options.ShowLineNumbers ? LineNumberColumnWidth + 1 : 0);
  // The width of the line that is used to divide between the view and the
  // subviews.
  unsigned DividerWidth = CombinedColumnWidth + 4;

  // We need the expansions and instantiations sorted so we can go through them
  // while we iterate lines.
  std::sort(ExpansionSubViews.begin(), ExpansionSubViews.end());
  std::sort(InstantiationSubViews.begin(), InstantiationSubViews.end());
  auto NextESV = ExpansionSubViews.begin();
  auto EndESV = ExpansionSubViews.end();
  auto NextISV = InstantiationSubViews.begin();
  auto EndISV = InstantiationSubViews.end();

  // Get the coverage information for the file.
  auto NextSegment = CoverageInfo.begin();
  auto EndSegment = CoverageInfo.end();

  unsigned FirstLine = NextSegment != EndSegment ? NextSegment->Line : 0;
  const coverage::CoverageSegment *WrappedSegment = nullptr;
  SmallVector<const coverage::CoverageSegment *, 8> LineSegments;
  for (line_iterator LI(File, /*SkipBlanks=*/false); !LI.is_at_eof(); ++LI) {
    // If we aren't rendering the whole file, we need to filter out the prologue
    // and epilogue.
    if (!WholeFile) {
      if (NextSegment == EndSegment)
        break;
      else if (LI.line_number() < FirstLine)
        continue;
    }

    // Collect the coverage information relevant to this line.
    if (LineSegments.size())
      WrappedSegment = LineSegments.back();
    LineSegments.clear();
    while (NextSegment != EndSegment && NextSegment->Line == LI.line_number())
      LineSegments.push_back(&*NextSegment++);

    // Calculate a count to be for the line as a whole.
    LineCoverageInfo LineCount;
    if (WrappedSegment && WrappedSegment->HasCount)
      LineCount.addRegionCount(WrappedSegment->Count);
    for (const auto *S : LineSegments)
      if (S->HasCount && S->IsRegionEntry)
          LineCount.addRegionStartCount(S->Count);

    // Render the line prefix.
    renderIndent(OS, IndentLevel);
    if (Options.ShowLineStats)
      renderLineCoverageColumn(OS, LineCount);
    if (Options.ShowLineNumbers)
      renderLineNumberColumn(OS, LI.line_number());

    // If there are expansion subviews, we want to highlight the first one.
    unsigned ExpansionColumn = 0;
    if (NextESV != EndESV && NextESV->getLine() == LI.line_number() &&
        Options.Colors)
      ExpansionColumn = NextESV->getStartCol();

    // Display the source code for the current line.
    renderLine(OS, *LI, LI.line_number(), WrappedSegment, LineSegments,
               ExpansionColumn);

    // Show the region markers.
    if (Options.ShowRegionMarkers && (!Options.ShowLineStatsOrRegionMarkers ||
                                      LineCount.hasMultipleRegions()) &&
        !LineSegments.empty()) {
      renderIndent(OS, IndentLevel);
      OS.indent(CombinedColumnWidth);
      renderRegionMarkers(OS, LineSegments);
    }

    // Show the expansions and instantiations for this line.
    unsigned NestedIndent = IndentLevel + 1;
    bool RenderedSubView = false;
    for (; NextESV != EndESV && NextESV->getLine() == LI.line_number();
         ++NextESV) {
      renderViewDivider(NestedIndent, DividerWidth, OS);
      OS << "\n";
      if (RenderedSubView) {
        // Re-render the current line and highlight the expansion range for
        // this subview.
        ExpansionColumn = NextESV->getStartCol();
        renderIndent(OS, IndentLevel);
        OS.indent(CombinedColumnWidth + (IndentLevel == 0 ? 0 : 1));
        renderLine(OS, *LI, LI.line_number(), WrappedSegment, LineSegments,
                   ExpansionColumn);
        renderViewDivider(NestedIndent, DividerWidth, OS);
        OS << "\n";
      }
      // Render the child subview
      if (Options.Debug)
        errs() << "Expansion at line " << NextESV->getLine() << ", "
               << NextESV->getStartCol() << " -> " << NextESV->getEndCol()
               << "\n";
      NextESV->View->render(OS, false, NestedIndent);
      RenderedSubView = true;
    }
    for (; NextISV != EndISV && NextISV->Line == LI.line_number(); ++NextISV) {
      renderViewDivider(NestedIndent, DividerWidth, OS);
      OS << "\n";
      renderIndent(OS, NestedIndent);
      OS << ' ';
      Options.colored_ostream(OS, raw_ostream::CYAN) << NextISV->FunctionName
                                                     << ":";
      OS << "\n";
      NextISV->View->render(OS, false, NestedIndent);
      RenderedSubView = true;
    }
    if (RenderedSubView) {
      renderViewDivider(NestedIndent, DividerWidth, OS);
      OS << "\n";
    }
  }
}