1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

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
This commit is contained in:
Justin Bogner 2014-09-15 03:41:04 +00:00
parent 4bb118ab83
commit 293ec338b0
3 changed files with 29 additions and 44 deletions

View File

@ -283,8 +283,7 @@ void CodeCoverageTool::createExpansionSubView(
if (!SourceBuffer) if (!SourceBuffer)
return; return;
auto SubView = llvm::make_unique<SourceCoverageView>( auto SubView = llvm::make_unique<SourceCoverageView>(
SourceBuffer.get(), Parent.getOptions(), ExpandedLines.first, SourceBuffer.get(), Parent.getOptions(), ExpandedRegion);
ExpandedLines.second, ExpandedRegion);
SourceCoverageDataManager RegionManager; SourceCoverageDataManager RegionManager;
for (const auto &CR : Function.CountedRegions) { for (const auto &CR : Function.CountedRegions) {
if (CR.FileID == ExpandedRegion.ExpandedFileID) if (CR.FileID == ExpandedRegion.ExpandedFileID)
@ -362,13 +361,9 @@ bool CodeCoverageTool::createSourceFileView(
for (const auto &InstantiationSet : InstantiationSetCollector) { for (const auto &InstantiationSet : InstantiationSetCollector) {
if (InstantiationSet.second.size() < 2) if (InstantiationSet.second.size() < 2)
continue; continue;
auto InterestingRange = findExpandedFileInterestingLineRange(
InstantiationSet.second.front()->CountedRegions.front().FileID,
*InstantiationSet.second.front());
for (auto Function : InstantiationSet.second) { for (auto Function : InstantiationSet.second) {
auto SubView = llvm::make_unique<SourceCoverageView>( auto SubView =
View, InterestingRange.first, InterestingRange.second, llvm::make_unique<SourceCoverageView>(View, Function->Name);
Function->Name);
createInstantiationSubView(SourceFile, *Function, *SubView); createInstantiationSubView(SourceFile, *Function, *SubView);
View.addChild(std::move(SubView)); View.addChild(std::move(SubView));
} }
@ -618,9 +613,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
auto SourceBuffer = getSourceFile(SourceFile); auto SourceBuffer = getSourceFile(SourceFile);
if (!SourceBuffer) if (!SourceBuffer)
return 1; return 1;
auto Range = findExpandedFileInterestingLineRange(MainFileID, Function); SourceCoverageView mainView(SourceBuffer.get(), ViewOpts);
SourceCoverageView mainView(SourceBuffer.get(), ViewOpts, Range.first,
Range.second);
createSourceFileView(SourceFile, mainView, Function, true); createSourceFileView(SourceFile, mainView, Function, true);
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) ViewOpts.colored_ostream(outs(), raw_ostream::CYAN)
<< Function.Name << " from " << SourceFile << ":"; << Function.Name << " from " << SourceFile << ":";

View File

@ -220,7 +220,7 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
line_iterator Lines(File); line_iterator Lines(File);
// Advance the line iterator to the first line. // Advance the line iterator to the first line.
while (Lines.line_number() < LineStart) while (Lines.line_number() < LineOffset)
++Lines; ++Lines;
// The width of the leading columns // The width of the leading columns
@ -231,8 +231,8 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
// subviews. // subviews.
unsigned DividerWidth = CombinedColumnWidth + 4; unsigned DividerWidth = CombinedColumnWidth + 4;
for (size_t I = 0; I < LineCount; ++I) { for (size_t I = 0, E = LineStats.size(); I < E; ++I) {
unsigned LineNo = I + LineStart; unsigned LineNo = I + LineOffset;
// Gather the child subviews that are visible on this line. // Gather the child subviews that are visible on this line.
auto LineSubViews = gatherLineSubViews(CurrentChild, Children, LineNo); auto LineSubViews = gatherLineSubViews(CurrentChild, Children, LineNo);
@ -318,18 +318,25 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
void void
SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) { SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) {
LineStats.resize(LineCount); auto CountedRegions = Data.getSourceRegions();
for (const auto &CR : 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) { if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion) {
// Reset the line stats for skipped regions. // Reset the line stats for skipped regions.
for (unsigned Line = CR.LineStart; Line <= CR.LineEnd; for (unsigned Line = CR.LineStart; Line <= CR.LineEnd;
++Line) ++Line)
LineStats[Line - LineStart] = LineCoverageInfo(); LineStats[Line - LineOffset] = LineCoverageInfo();
continue; 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) 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) { void SourceCoverageView::createRegionMarkers(SourceCoverageDataManager &Data) {
for (const auto &CR : Data.getSourceRegions()) { for (const auto &CR : Data.getSourceRegions())
if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion) if (CR.Kind != coverage::CounterMappingRegion::SkippedRegion)
continue;
if (CR.LineStart >= LineStart)
Markers.push_back( Markers.push_back(
RegionMarker(CR.LineStart, CR.ColumnStart, CR.ExecutionCount)); RegionMarker(CR.LineStart, CR.ColumnStart, CR.ExecutionCount));
}
if (Options.Debug) { if (Options.Debug) {
for (const auto &Marker : Markers) { for (const auto &Marker : Markers) {

View File

@ -110,7 +110,7 @@ public:
private: private:
const MemoryBuffer &File; const MemoryBuffer &File;
const CoverageViewOptions &Options; const CoverageViewOptions &Options;
unsigned LineStart, LineCount; unsigned LineOffset;
SubViewKind Kind; SubViewKind Kind;
coverage::CounterMappingRegion ExpansionRegion; coverage::CounterMappingRegion ExpansionRegion;
std::vector<std::unique_ptr<SourceCoverageView>> Children; std::vector<std::unique_ptr<SourceCoverageView>> Children;
@ -157,31 +157,19 @@ private:
public: public:
SourceCoverageView(const MemoryBuffer &File, SourceCoverageView(const MemoryBuffer &File,
const CoverageViewOptions &Options) const CoverageViewOptions &Options)
: File(File), Options(Options), LineStart(1), Kind(View), : File(File), Options(Options), LineOffset(0), 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),
ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0) {} ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0) {}
SourceCoverageView(SourceCoverageView &Parent, unsigned LineStart, SourceCoverageView(SourceCoverageView &Parent, StringRef FunctionName)
unsigned LineEnd, StringRef FunctionName) : File(Parent.File), Options(Parent.Options), LineOffset(0),
: File(Parent.File), Options(Parent.Options), LineStart(LineStart), Kind(InstantiationView),
LineCount(LineEnd - LineStart + 1), Kind(InstantiationView), ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 0),
ExpansionRegion(coverage::Counter(), 0, LineEnd, 0, LineEnd, 0),
FunctionName(FunctionName) {} FunctionName(FunctionName) {}
SourceCoverageView(const MemoryBuffer &File, SourceCoverageView(const MemoryBuffer &File,
const CoverageViewOptions &Options, unsigned LineStart, const CoverageViewOptions &Options,
unsigned LineEnd,
const coverage::CounterMappingRegion &ExpansionRegion) const coverage::CounterMappingRegion &ExpansionRegion)
: File(File), Options(Options), LineStart(LineStart), : File(File), Options(Options), LineOffset(0), Kind(ExpansionView),
LineCount(LineEnd - LineStart + 1), Kind(ExpansionView),
ExpansionRegion(ExpansionRegion) {} ExpansionRegion(ExpansionRegion) {}
const CoverageViewOptions &getOptions() const { return Options; } const CoverageViewOptions &getOptions() const { return Options; }