mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00: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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217746 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
baca001683
commit
b1287f54cf
@ -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 << ":";
|
||||
|
@ -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) {
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user