1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[llvm-cov] Simplify the way expansion views are rendered (NFC)

If a sub-view has already been rendered, it's helpful to re-render the
expansion site before rendering the next expansion view. Make this fact
explicit in the rendering interface, instead of hiding it behind an
awkward Optional<LineRef> parameter.

llvm-svn: 273789
This commit is contained in:
Vedant Kumar 2016-06-26 02:45:13 +00:00
parent ba6158b462
commit 0bf7c0b1b7
4 changed files with 38 additions and 35 deletions

View File

@ -129,14 +129,22 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
for (; NextESV != EndESV && NextESV->getLine() == LI.line_number();
++NextESV) {
renderViewDivider(OS, ViewDepth + 1);
ExpansionColumn = renderExpansionView(
OS, *NextESV,
RenderedSubView ? Optional<LineRef>({*LI, LI.line_number()})
: Optional<LineRef>(),
WrappedSegment, LineSegments, ExpansionColumn, ViewDepth);
// Re-render the current line and highlight the expansion range for
// this subview.
if (RenderedSubView) {
ExpansionColumn = NextESV->getStartCol();
renderExpansionSite(
OS, *NextESV, {*LI, LI.line_number()}, WrappedSegment, LineSegments,
ExpansionColumn, ViewDepth);
renderViewDivider(OS, ViewDepth + 1);
}
renderExpansionView(OS, *NextESV, ViewDepth + 1);
RenderedSubView = true;
}
for (; NextISV != EndISV && NextISV->Line == LI.line_number(); ++NextISV) {
renderViewDivider(OS, ViewDepth + 1);
renderInstantiationView(OS, *NextISV, ViewDepth + 1);
RenderedSubView = true;
}

View File

@ -16,7 +16,6 @@
#include "CoverageViewOptions.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/MemoryBuffer.h"
#include <vector>
@ -163,16 +162,18 @@ protected:
CoverageSegmentArray Segments,
unsigned ViewDepth) = 0;
/// \brief Render an expansion view. If the expansion site must be re-rendered
/// for clarity, it is passed in via \p FirstLine.
virtual unsigned
renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
Optional<LineRef> FirstLine,
/// \brief Render the site of an expansion.
virtual void
renderExpansionSite(raw_ostream &OS, ExpansionView &ESV, LineRef L,
const coverage::CoverageSegment *WrappedSegment,
CoverageSegmentArray Segments, unsigned ExpansionCol,
unsigned ViewDepth) = 0;
/// \brief Render an instantiation view.
/// \brief Render an expansion view and any nested views.
virtual void renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
unsigned ViewDepth) = 0;
/// \brief Render an instantiation view and any nested views.
virtual void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV,
unsigned ViewDepth) = 0;

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "SourceCoverageViewText.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
@ -156,37 +157,29 @@ void SourceCoverageViewText::renderRegionMarkers(
<< formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n");
}
unsigned SourceCoverageViewText::renderExpansionView(
raw_ostream &OS, ExpansionView &ESV, Optional<LineRef> FirstLine,
void SourceCoverageViewText::renderExpansionSite(
raw_ostream &OS, ExpansionView &ESV, LineRef L,
const coverage::CoverageSegment *WrappedSegment,
CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) {
unsigned NextExpansionCol = ExpansionCol;
if (FirstLine.hasValue()) {
// Re-render the current line and highlight the expansion range for
// this subview.
NextExpansionCol = ESV.getStartCol();
renderLinePrefix(OS, ViewDepth);
OS.indent(getCombinedColumnWidth(getOptions()) + (ViewDepth == 0 ? 0 : 1));
renderLine(OS, *FirstLine, WrappedSegment, Segments, ExpansionCol,
ViewDepth);
renderViewDivider(OS, ViewDepth + 1);
}
renderLinePrefix(OS, ViewDepth);
OS.indent(getCombinedColumnWidth(getOptions()) + (ViewDepth == 0 ? 0 : 1));
renderLine(OS, L, WrappedSegment, Segments, ExpansionCol, ViewDepth);
}
void SourceCoverageViewText::renderExpansionView(raw_ostream &OS,
ExpansionView &ESV,
unsigned ViewDepth) {
// Render the child subview.
if (getOptions().Debug)
errs() << "Expansion at line " << ESV.getLine() << ", " << ESV.getStartCol()
<< " -> " << ESV.getEndCol() << '\n';
ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
ViewDepth + 1);
return NextExpansionCol;
}
void SourceCoverageViewText::renderInstantiationView(raw_ostream &OS,
InstantiationView &ISV,
unsigned ViewDepth) {
renderViewDivider(OS, ViewDepth);
renderLinePrefix(OS, ViewDepth);
OS << ' ';
ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true, ViewDepth);

View File

@ -31,12 +31,13 @@ class SourceCoverageViewText : public SourceCoverageView {
CoverageSegmentArray Segments, unsigned ExpansionCol,
unsigned ViewDepth) override;
unsigned renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
Optional<LineRef> FirstLine,
const coverage::CoverageSegment *WrappedSegment,
CoverageSegmentArray Segments,
unsigned ExpansionCol,
unsigned ViewDepth) override;
void renderExpansionSite(raw_ostream &OS, ExpansionView &ESV, LineRef L,
const coverage::CoverageSegment *WrappedSegment,
CoverageSegmentArray Segments, unsigned ExpansionCol,
unsigned ViewDepth) override;
void renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
unsigned ViewDepth) override;
void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV,
unsigned ViewDepth) override;