LineIterator: Provide a variant that keeps blank lines

It isn't always useful to skip blank lines, as evidenced by the
somewhat awkward use of line_iterator in llvm-cov. This adds a knob to
control whether or not to skip blanks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner
2014-09-17 15:43:01 +00:00
parent 27608d8393
commit 0a277ea23d
6 changed files with 117 additions and 29 deletions

View File

@ -206,7 +206,7 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
size_t CurrentHighlightRange = 0;
size_t CurrentRegionMarker = 0;
line_iterator Lines(File);
line_iterator Lines(File, /*SkipBlanks=*/false);
// Advance the line iterator to the first line.
while (Lines.line_number() < LineOffset)
++Lines;
@ -228,8 +228,9 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
auto NextISV = InstantiationSubViews.begin();
auto EndISV = InstantiationSubViews.end();
for (size_t I = 0, E = LineStats.size(); I < E; ++I) {
unsigned LineNo = I + LineOffset;
for (size_t I = 0, E = LineStats.size(); I < E && !Lines.is_at_eof();
++I, ++Lines) {
unsigned LineNo = Lines.line_number();
renderIndent(OS, IndentLevel);
if (Options.ShowLineStats)
@ -252,11 +253,6 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
// Display the source code for the current line.
StringRef Line = *Lines;
// Check if the line is empty, as line_iterator skips blank lines.
if (LineNo < Lines.line_number())
Line = "";
else if (!Lines.is_at_eof())
++Lines;
renderLine(OS, Line, LineRanges);
// Show the region markers.