summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/CoverageSummaryInfo.h
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-10-14 02:27:29 +0000
committerVedant Kumar <vsk@apple.com>2017-10-14 02:27:29 +0000
commit1963f51f14093fa036d1c6a06c4f10fc0a5e82c1 (patch)
tree43365a45a401bb4c70d3d31646c262e43afebda6 /llvm/tools/llvm-cov/CoverageSummaryInfo.h
parent0eb929b08bc4f41433a93d863a19c2b6788bb871 (diff)
downloadbcm5719-llvm-1963f51f14093fa036d1c6a06c4f10fc0a5e82c1.tar.gz
bcm5719-llvm-1963f51f14093fa036d1c6a06c4f10fc0a5e82c1.zip
[llvm-cov] Factor out logic to iterate over line coverage stats (NFC)
There were two copies of the logic needed to construct a line stats object for each line in a range: this patch brings it down to one. In the future, this will make it easier for IDE clients to display coverage in-line in source editors. To do that, we just need to move the new LineCoverageIterator class to libCoverage. llvm-svn: 315789
Diffstat (limited to 'llvm/tools/llvm-cov/CoverageSummaryInfo.h')
-rw-r--r--llvm/tools/llvm-cov/CoverageSummaryInfo.h81
1 files changed, 78 insertions, 3 deletions
diff --git a/llvm/tools/llvm-cov/CoverageSummaryInfo.h b/llvm/tools/llvm-cov/CoverageSummaryInfo.h
index 0548f491545..d3f43d19104 100644
--- a/llvm/tools/llvm-cov/CoverageSummaryInfo.h
+++ b/llvm/tools/llvm-cov/CoverageSummaryInfo.h
@@ -15,6 +15,8 @@
#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
#define LLVM_COV_COVERAGESUMMARYINFO_H
+#include "llvm/ADT/iterator.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/Support/raw_ostream.h"
@@ -137,19 +139,92 @@ public:
};
/// \brief Coverage statistics for a single line.
-struct LineCoverageStats {
+class LineCoverageStats {
uint64_t ExecutionCount;
bool HasMultipleRegions;
bool Mapped;
+ unsigned Line;
+ ArrayRef<const coverage::CoverageSegment *> LineSegments;
+ const coverage::CoverageSegment *WrappedSegment;
+ friend class LineCoverageIterator;
+ LineCoverageStats() = default;
+
+public:
LineCoverageStats(ArrayRef<const coverage::CoverageSegment *> LineSegments,
- const coverage::CoverageSegment *WrappedSegment);
+ const coverage::CoverageSegment *WrappedSegment,
+ unsigned Line);
- bool isMapped() const { return Mapped; }
+ uint64_t getExecutionCount() const { return ExecutionCount; }
bool hasMultipleRegions() const { return HasMultipleRegions; }
+
+ bool isMapped() const { return Mapped; }
+
+ unsigned getLine() const { return Line; }
+
+ ArrayRef<const coverage::CoverageSegment *> getLineSegments() const {
+ return LineSegments;
+ }
+
+ const coverage::CoverageSegment *getWrappedSegment() const {
+ return WrappedSegment;
+ }
};
+/// Iterates over LineCoverageStats for each line described by a CoverageData
+/// object.
+class LineCoverageIterator
+ : public iterator_facade_base<
+ LineCoverageIterator, std::forward_iterator_tag, LineCoverageStats> {
+public:
+ LineCoverageIterator(const coverage::CoverageData &CD)
+ : LineCoverageIterator(CD, CD.begin()->Line) {}
+
+ LineCoverageIterator(const coverage::CoverageData &CD, unsigned Line)
+ : CD(CD), WrappedSegment(nullptr), Next(CD.begin()), Ended(false),
+ Line(Line), Segments(), Stats() {
+ this->operator++();
+ }
+
+ LineCoverageIterator &operator=(const LineCoverageIterator &R) = default;
+
+ bool operator==(const LineCoverageIterator &R) const {
+ return &CD == &R.CD && Next == R.Next && Ended == R.Ended;
+ }
+
+ const LineCoverageStats &operator*() const { return Stats; }
+
+ LineCoverageStats &operator*() { return Stats; }
+
+ LineCoverageIterator &operator++();
+
+ LineCoverageIterator getEnd() const {
+ auto EndIt = *this;
+ EndIt.Next = CD.end();
+ EndIt.Ended = true;
+ return EndIt;
+ }
+
+private:
+ const coverage::CoverageData &CD;
+ const coverage::CoverageSegment *WrappedSegment;
+ std::vector<coverage::CoverageSegment>::const_iterator Next;
+ bool Ended;
+ unsigned Line;
+ SmallVector<const coverage::CoverageSegment *, 4> Segments;
+ LineCoverageStats Stats;
+};
+
+/// Get a range of LineCoverageStats for each line described by a CoverageData
+/// object.
+static inline iterator_range<LineCoverageIterator>
+getLineCoverageStats(const coverage::CoverageData &CD) {
+ auto Begin = LineCoverageIterator(CD);
+ auto End = Begin.getEnd();
+ return make_range(Begin, End);
+}
+
/// \brief A summary of function's code coverage.
struct FunctionCoverageSummary {
std::string Name;
OpenPOWER on IntegriCloud