[llvm] r217746 - llvm-cov: Clean up some redundancy in the view API (NFC)
Justin Bogner
mail at justinbogner.com
Sun Sep 14 20:41:04 PDT 2014
Author: bogner
Date: Sun Sep 14 22:41:04 2014
New Revision: 217746
URL: http://llvm.org/viewvc/llvm-project?rev=217746&view=rev
Log:
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.
Modified:
llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
llvm/trunk/tools/llvm-cov/SourceCoverageView.h
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=217746&r1=217745&r2=217746&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Sun Sep 14 22:41:04 2014
@@ -283,8 +283,7 @@ void CodeCoverageTool::createExpansionSu
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::createSourceFileV
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, con
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 << ":";
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=217746&r1=217745&r2=217746&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Sun Sep 14 22:41:04 2014
@@ -220,7 +220,7 @@ void SourceCoverageView::render(raw_ostr
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_ostr
// 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_ostr
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::createHighlightRange
}
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) {
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=217746&r1=217745&r2=217746&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Sun Sep 14 22:41:04 2014
@@ -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; }
More information about the llvm-commits
mailing list