From 69fe4e98fa00cce06d64c8bf81882dfea0851302 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Wed, 17 Sep 2014 15:43:01 +0000 Subject: 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. llvm-svn: 217960 --- llvm/tools/llvm-cov/SourceCoverageView.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'llvm/tools/llvm-cov/SourceCoverageView.cpp') diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp index f18f0f680d1..a83bd54e15e 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -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. -- cgit v1.2.3