summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-09-15 03:41:04 +0000
committerJustin Bogner <mail@justinbogner.com>2014-09-15 03:41:04 +0000
commit7dad93bec2657b444d02d027c7e41efd6c540c74 (patch)
treeed87f428e48b8427058a92630708694338f50eba /llvm/tools/llvm-cov
parentaee36f94396f1b7eb301a1ff01230fa7fa33cd2f (diff)
downloadbcm5719-llvm-7dad93bec2657b444d02d027c7e41efd6c540c74.tar.gz
bcm5719-llvm-7dad93bec2657b444d02d027c7e41efd6c540c74.zip
llvm-cov: Clean up some redundancy in the view API (NFC)
This removes the need to pass a starting and ending line when creating a SourceCoverageView, since these are easy to determine. llvm-svn: 217746
Diffstat (limited to 'llvm/tools/llvm-cov')
-rw-r--r--llvm/tools/llvm-cov/CodeCoverage.cpp15
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp30
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.h28
3 files changed, 29 insertions, 44 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 3945b17bc3d..79a596d702a 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -283,8 +283,7 @@ void CodeCoverageTool::createExpansionSubView(
if (!SourceBuffer)
return;
auto SubView = llvm::make_unique<SourceCoverageView>(
- SourceBuffer.get(), Parent.getOptions(), ExpandedLines.first,
- ExpandedLines.second, ExpandedRegion);
+ SourceBuffer.get(), Parent.getOptions(), ExpandedRegion);
SourceCoverageDataManager RegionManager;
for (const auto &CR : Function.CountedRegions) {
if (CR.FileID == ExpandedRegion.ExpandedFileID)
@@ -362,13 +361,9 @@ bool CodeCoverageTool::createSourceFileView(
for (const auto &InstantiationSet : InstantiationSetCollector) {
if (InstantiationSet.second.size() < 2)
continue;
- auto InterestingRange = findExpandedFileInterestingLineRange(
- InstantiationSet.second.front()->CountedRegions.front().FileID,
- *InstantiationSet.second.front());
for (auto Function : InstantiationSet.second) {
- auto SubView = llvm::make_unique<SourceCoverageView>(
- View, InterestingRange.first, InterestingRange.second,
- Function->Name);
+ auto SubView =
+ llvm::make_unique<SourceCoverageView>(View, Function->Name);
createInstantiationSubView(SourceFile, *Function, *SubView);
View.addChild(std::move(SubView));
}
@@ -618,9 +613,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
auto SourceBuffer = getSourceFile(SourceFile);
if (!SourceBuffer)
return 1;
- auto Range = findExpandedFileInterestingLineRange(MainFileID, Function);
- SourceCoverageView mainView(SourceBuffer.get(), ViewOpts, Range.first,
- Range.second);
+ SourceCoverageView mainView(SourceBuffer.get(), ViewOpts);
createSourceFileView(SourceFile, mainView, Function, true);
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN)
<< Function.Name << " from " << SourceFile << ":";
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 159d74adf38..87a68e0db03 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -220,7 +220,7 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
line_iterator Lines(File);
// Advance the line iterator to the first line.
- while (Lines.line_number() < LineStart)
+ while (Lines.line_number() < LineOffset)
++Lines;
// The width of the leading columns
@@ -231,8 +231,8 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
// subviews.
unsigned DividerWidth = CombinedColumnWidth + 4;
- for (size_t I = 0; I < LineCount; ++I) {
- unsigned LineNo = I + LineStart;
+ for (size_t I = 0, E = LineStats.size(); I < E; ++I) {
+ unsigned LineNo = I + LineOffset;
// Gather the child subviews that are visible on this line.
auto LineSubViews = gatherLineSubViews(CurrentChild, Children, LineNo);
@@ -318,18 +318,25 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
void
SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) {
- LineStats.resize(LineCount);
- for (const auto &CR : Data.getSourceRegions()) {
+ auto CountedRegions = Data.getSourceRegions();
+ if (!CountedRegions.size())
+ return;
+
+ LineOffset = CountedRegions.front().LineStart;
+ LineStats.resize(CountedRegions.front().LineEnd - LineOffset + 1);
+ for (const auto &CR : CountedRegions) {
+ if (CR.LineEnd > LineStats.size())
+ LineStats.resize(CR.LineEnd - LineOffset + 1);
if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion) {
// Reset the line stats for skipped regions.
for (unsigned Line = CR.LineStart; Line <= CR.LineEnd;
++Line)
- LineStats[Line - LineStart] = LineCoverageInfo();
+ LineStats[Line - LineOffset] = LineCoverageInfo();
continue;
}
- LineStats[CR.LineStart - LineStart].addRegionStartCount(CR.ExecutionCount);
+ LineStats[CR.LineStart - LineOffset].addRegionStartCount(CR.ExecutionCount);
for (unsigned Line = CR.LineStart + 1; Line <= CR.LineEnd; ++Line)
- LineStats[Line - LineStart].addRegionCount(CR.ExecutionCount);
+ LineStats[Line - LineOffset].addRegionCount(CR.ExecutionCount);
}
}
@@ -384,13 +391,10 @@ SourceCoverageView::createHighlightRanges(SourceCoverageDataManager &Data) {
}
void SourceCoverageView::createRegionMarkers(SourceCoverageDataManager &Data) {
- for (const auto &CR : Data.getSourceRegions()) {
- if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion)
- continue;
- if (CR.LineStart >= LineStart)
+ for (const auto &CR : Data.getSourceRegions())
+ if (CR.Kind != coverage::CounterMappingRegion::SkippedRegion)
Markers.push_back(
RegionMarker(CR.LineStart, CR.ColumnStart, CR.ExecutionCount));
- }
if (Options.Debug) {
for (const auto &Marker : Markers) {
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index ddfc690c482..37d4027a568 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -110,7 +110,7 @@ public:
private:
const MemoryBuffer &File;
const CoverageViewOptions &Options;
- unsigned LineStart, LineCount;
+ unsigned LineOffset;
SubViewKind Kind;
coverage::CounterMappingRegion ExpansionRegion;
std::vector<std::unique_ptr<SourceCoverageView>> Children;
@@ -157,31 +157,19 @@ private:
public:
SourceCoverageView(const MemoryBuffer &File,
const CoverageViewOptions &Options)
- : File(File), Options(Options), LineStart(1), Kind(View),
- ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0) {
- LineCount = File.getBuffer().count('\n') + 1;
- }
-
- SourceCoverageView(const MemoryBuffer &File,
- const CoverageViewOptions &Options, unsigned LineStart,
- unsigned LineEnd)
- : File(File), Options(Options), LineStart(LineStart),
- LineCount(LineEnd - LineStart + 1), Kind(View),
+ : File(File), Options(Options), LineOffset(0), Kind(View),
ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0) {}
- SourceCoverageView(SourceCoverageView &Parent, unsigned LineStart,
- unsigned LineEnd, StringRef FunctionName)
- : File(Parent.File), Options(Parent.Options), LineStart(LineStart),
- LineCount(LineEnd - LineStart + 1), Kind(InstantiationView),
- ExpansionRegion(coverage::Counter(), 0, LineEnd, 0, LineEnd, 0),
+ SourceCoverageView(SourceCoverageView &Parent, StringRef FunctionName)
+ : File(Parent.File), Options(Parent.Options), LineOffset(0),
+ Kind(InstantiationView),
+ ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0),
FunctionName(FunctionName) {}
SourceCoverageView(const MemoryBuffer &File,
- const CoverageViewOptions &Options, unsigned LineStart,
- unsigned LineEnd,
+ const CoverageViewOptions &Options,
const coverage::CounterMappingRegion &ExpansionRegion)
- : File(File), Options(Options), LineStart(LineStart),
- LineCount(LineEnd - LineStart + 1), Kind(ExpansionView),
+ : File(File), Options(Options), LineOffset(0), Kind(ExpansionView),
ExpansionRegion(ExpansionRegion) {}
const CoverageViewOptions &getOptions() const { return Options; }
OpenPOWER on IntegriCloud