summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/SourceCoverageView.h
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-09-17 05:33:20 +0000
committerJustin Bogner <mail@justinbogner.com>2014-09-17 05:33:20 +0000
commit5e1400a81c45418879776924518f1ff4843f8dd4 (patch)
tree575cfea3ebd159c6c088f7664fb3fa51d68c30f4 /llvm/tools/llvm-cov/SourceCoverageView.h
parentb435a4214e5920e56dd2e9fb5fb29bb2d4e98fab (diff)
downloadbcm5719-llvm-5e1400a81c45418879776924518f1ff4843f8dd4.tar.gz
bcm5719-llvm-5e1400a81c45418879776924518f1ff4843f8dd4.zip
llvm-cov: Distinguish expansion/instantiation from SourceCoverageView
SourceCoverageView currently has "Kind" and a list of child views, all of which must have either an expansion or an instantiation Kind. In addition to being an error-prone design, this makes it awkward to differentiate between the two child types and adds a number of optionally used members to the type. Split the subview types into their own separate objects, and maintain lists of each rather than one combined "Children" list. llvm-svn: 217940
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.h')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.h82
1 files changed, 47 insertions, 35 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index 0777c23a855..af44085cffc 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -22,12 +22,46 @@
namespace llvm {
+class SourceCoverageView;
+
+/// \brief A view that represents a macro or include expansion
+struct ExpansionView {
+ coverage::CounterMappingRegion Region;
+ std::unique_ptr<SourceCoverageView> View;
+
+ ExpansionView(const coverage::CounterMappingRegion &Region,
+ std::unique_ptr<SourceCoverageView> View)
+ : Region(Region), View(std::move(View)) {}
+
+ unsigned getLine() const { return Region.LineStart; }
+ unsigned getStartCol() const { return Region.ColumnStart; }
+ unsigned getEndCol() const { return Region.ColumnEnd; }
+
+ friend bool operator<(const ExpansionView &LHS, const ExpansionView &RHS) {
+ return LHS.Region.startLoc() < RHS.Region.startLoc();
+ }
+};
+
+/// \brief A view that represents a function instantiation
+struct InstantiationView {
+ StringRef FunctionName;
+ unsigned Line;
+ std::unique_ptr<SourceCoverageView> View;
+
+ InstantiationView(StringRef FunctionName, unsigned Line,
+ std::unique_ptr<SourceCoverageView> View)
+ : FunctionName(FunctionName), Line(Line), View(std::move(View)) {}
+
+ friend bool operator<(const InstantiationView &LHS,
+ const InstantiationView &RHS) {
+ return LHS.Line < RHS.Line;
+ }
+};
+
/// \brief A code coverage view of a specific source file.
/// It can have embedded coverage views.
class SourceCoverageView {
public:
- enum SubViewKind { View, ExpansionView, InstantiationView };
-
/// \brief Coverage information for a single line.
struct LineCoverageInfo {
uint64_t ExecutionCount;
@@ -111,13 +145,11 @@ private:
const MemoryBuffer &File;
const CoverageViewOptions &Options;
unsigned LineOffset;
- SubViewKind Kind;
- coverage::CounterMappingRegion ExpansionRegion;
- std::vector<std::unique_ptr<SourceCoverageView>> Children;
+ std::vector<ExpansionView> ExpansionSubViews;
+ std::vector<InstantiationView> InstantiationSubViews;
std::vector<LineCoverageInfo> LineStats;
std::vector<HighlightRange> HighlightRanges;
std::vector<RegionMarker> Markers;
- StringRef FunctionName;
/// \brief Initialize the visible source range for this view.
void setUpVisibleRange(SourceCoverageDataManager &Data);
@@ -131,12 +163,6 @@ private:
/// \brief Create the region markers using the coverage data.
void createRegionMarkers(SourceCoverageDataManager &Data);
- /// \brief Sort children by the starting location.
- void sortChildren();
-
- /// \brief Return a highlight range for the expansion region of this view.
- HighlightRange getExpansionHighlightRange() const;
-
/// \brief Render a source line with highlighting.
void renderLine(raw_ostream &OS, StringRef Line,
ArrayRef<HighlightRange> Ranges);
@@ -160,34 +186,20 @@ private:
public:
SourceCoverageView(const MemoryBuffer &File,
const CoverageViewOptions &Options)
- : File(File), Options(Options), LineOffset(0), Kind(View),
- ExpansionRegion(coverage::Counter(), 0, 0, 0, 0, 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,
- const coverage::CounterMappingRegion &ExpansionRegion)
- : File(File), Options(Options), LineOffset(0), Kind(ExpansionView),
- ExpansionRegion(ExpansionRegion) {}
+ : File(File), Options(Options), LineOffset(0) {}
const CoverageViewOptions &getOptions() const { return Options; }
- bool isExpansionSubView() const { return Kind == ExpansionView; }
-
- bool isInstantiationSubView() const { return Kind == InstantiationView; }
-
- /// \brief Return the line number after which the subview expansion is shown.
- unsigned getSubViewsExpansionLine() const {
- return ExpansionRegion.LineStart;
+ /// \brief Add an expansion subview to this view.
+ void addExpansion(const coverage::CounterMappingRegion &Region,
+ std::unique_ptr<SourceCoverageView> View) {
+ ExpansionSubViews.emplace_back(Region, std::move(View));
}
- void addChild(std::unique_ptr<SourceCoverageView> View) {
- Children.push_back(std::move(View));
+ /// \brief Add a function instantiation subview to this view.
+ void addInstantiation(StringRef FunctionName, unsigned Line,
+ std::unique_ptr<SourceCoverageView> View) {
+ InstantiationSubViews.emplace_back(FunctionName, Line, std::move(View));
}
/// \brief Print the code coverage information for a specific
OpenPOWER on IntegriCloud