comparison tools/llvm-cov/SourceCoverageView.h @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents 1172e4bd9c6f
children 3a76565eade5
comparison
equal deleted inserted replaced
120:1172e4bd9c6f 121:803732b1fca8
13 13
14 #ifndef LLVM_COV_SOURCECOVERAGEVIEW_H 14 #ifndef LLVM_COV_SOURCECOVERAGEVIEW_H
15 #define LLVM_COV_SOURCECOVERAGEVIEW_H 15 #define LLVM_COV_SOURCECOVERAGEVIEW_H
16 16
17 #include "CoverageViewOptions.h" 17 #include "CoverageViewOptions.h"
18 #include "CoverageSummaryInfo.h"
18 #include "llvm/ProfileData/Coverage/CoverageMapping.h" 19 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
19 #include "llvm/Support/MemoryBuffer.h" 20 #include "llvm/Support/MemoryBuffer.h"
20 #include <vector> 21 #include <vector>
21 22
22 namespace llvm { 23 namespace llvm {
23 24
25 using namespace coverage;
26
27 class CoverageFiltersMatchAll;
24 class SourceCoverageView; 28 class SourceCoverageView;
25 29
26 /// \brief A view that represents a macro or include expansion. 30 /// \brief A view that represents a macro or include expansion.
27 struct ExpansionView { 31 struct ExpansionView {
28 coverage::CounterMappingRegion Region; 32 CounterMappingRegion Region;
29 std::unique_ptr<SourceCoverageView> View; 33 std::unique_ptr<SourceCoverageView> View;
30 34
31 ExpansionView(const coverage::CounterMappingRegion &Region, 35 ExpansionView(const CounterMappingRegion &Region,
32 std::unique_ptr<SourceCoverageView> View) 36 std::unique_ptr<SourceCoverageView> View)
33 : Region(Region), View(std::move(View)) {} 37 : Region(Region), View(std::move(View)) {}
34 ExpansionView(ExpansionView &&RHS) 38 ExpansionView(ExpansionView &&RHS)
35 : Region(std::move(RHS.Region)), View(std::move(RHS.View)) {} 39 : Region(std::move(RHS.Region)), View(std::move(RHS.View)) {}
36 ExpansionView &operator=(ExpansionView &&RHS) { 40 ExpansionView &operator=(ExpansionView &&RHS) {
62 const InstantiationView &RHS) { 66 const InstantiationView &RHS) {
63 return LHS.Line < RHS.Line; 67 return LHS.Line < RHS.Line;
64 } 68 }
65 }; 69 };
66 70
67 /// \brief Coverage statistics for a single line.
68 struct LineCoverageStats {
69 uint64_t ExecutionCount;
70 unsigned RegionCount;
71 bool Mapped;
72
73 LineCoverageStats() : ExecutionCount(0), RegionCount(0), Mapped(false) {}
74
75 bool isMapped() const { return Mapped; }
76
77 bool hasMultipleRegions() const { return RegionCount > 1; }
78
79 void addRegionStartCount(uint64_t Count) {
80 // The max of all region starts is the most interesting value.
81 addRegionCount(RegionCount ? std::max(ExecutionCount, Count) : Count);
82 ++RegionCount;
83 }
84
85 void addRegionCount(uint64_t Count) {
86 Mapped = true;
87 ExecutionCount = Count;
88 }
89 };
90
91 /// \brief A file manager that handles format-aware file creation. 71 /// \brief A file manager that handles format-aware file creation.
92 class CoveragePrinter { 72 class CoveragePrinter {
93 public: 73 public:
94 struct StreamDestructor { 74 struct StreamDestructor {
95 void operator()(raw_ostream *OS) const; 75 void operator()(raw_ostream *OS) const;
132 /// \brief Close a file which has been used to print a coverage view. 112 /// \brief Close a file which has been used to print a coverage view.
133 virtual void closeViewFile(OwnedStream OS) = 0; 113 virtual void closeViewFile(OwnedStream OS) = 0;
134 114
135 /// \brief Create an index which lists reports for the given source files. 115 /// \brief Create an index which lists reports for the given source files.
136 virtual Error createIndexFile(ArrayRef<std::string> SourceFiles, 116 virtual Error createIndexFile(ArrayRef<std::string> SourceFiles,
137 const coverage::CoverageMapping &Coverage) = 0; 117 const CoverageMapping &Coverage,
118 const CoverageFiltersMatchAll &Filters) = 0;
138 119
139 /// @} 120 /// @}
140 }; 121 };
141 122
142 /// \brief A code coverage view of a source file or function. 123 /// \brief A code coverage view of a source file or function.
153 134
154 /// Various options to guide the coverage renderer. 135 /// Various options to guide the coverage renderer.
155 const CoverageViewOptions &Options; 136 const CoverageViewOptions &Options;
156 137
157 /// Complete coverage information about the source on display. 138 /// Complete coverage information about the source on display.
158 coverage::CoverageData CoverageInfo; 139 CoverageData CoverageInfo;
159 140
160 /// A container for all expansions (e.g macros) in the source on display. 141 /// A container for all expansions (e.g macros) in the source on display.
161 std::vector<ExpansionView> ExpansionSubViews; 142 std::vector<ExpansionView> ExpansionSubViews;
162 143
163 /// A container for all instantiations (e.g template functions) in the source 144 /// A container for all instantiations (e.g template functions) in the source
173 int64_t LineNo; 154 int64_t LineNo;
174 155
175 LineRef(StringRef Line, int64_t LineNo) : Line(Line), LineNo(LineNo) {} 156 LineRef(StringRef Line, int64_t LineNo) : Line(Line), LineNo(LineNo) {}
176 }; 157 };
177 158
178 using CoverageSegmentArray = ArrayRef<const coverage::CoverageSegment *>; 159 using CoverageSegmentArray = ArrayRef<const CoverageSegment *>;
179 160
180 /// @name Rendering Interface 161 /// @name Rendering Interface
181 /// @{ 162 /// @{
182 163
183 /// \brief Render a header for the view. 164 /// \brief Render a header for the view.
198 /// \brief Render a view divider at the given \p ViewDepth. 179 /// \brief Render a view divider at the given \p ViewDepth.
199 virtual void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) = 0; 180 virtual void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) = 0;
200 181
201 /// \brief Render a source line with highlighting. 182 /// \brief Render a source line with highlighting.
202 virtual void renderLine(raw_ostream &OS, LineRef L, 183 virtual void renderLine(raw_ostream &OS, LineRef L,
203 const coverage::CoverageSegment *WrappedSegment, 184 const LineCoverageStats &LCS, unsigned ExpansionCol,
204 CoverageSegmentArray Segments, unsigned ExpansionCol,
205 unsigned ViewDepth) = 0; 185 unsigned ViewDepth) = 0;
206 186
207 /// \brief Render the line's execution count column. 187 /// \brief Render the line's execution count column.
208 virtual void renderLineCoverageColumn(raw_ostream &OS, 188 virtual void renderLineCoverageColumn(raw_ostream &OS,
209 const LineCoverageStats &Line) = 0; 189 const LineCoverageStats &Line) = 0;
211 /// \brief Render the line number column. 191 /// \brief Render the line number column.
212 virtual void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) = 0; 192 virtual void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) = 0;
213 193
214 /// \brief Render all the region's execution counts on a line. 194 /// \brief Render all the region's execution counts on a line.
215 virtual void renderRegionMarkers(raw_ostream &OS, 195 virtual void renderRegionMarkers(raw_ostream &OS,
216 CoverageSegmentArray Segments, 196 const LineCoverageStats &Line,
217 unsigned ViewDepth) = 0; 197 unsigned ViewDepth) = 0;
218 198
219 /// \brief Render the site of an expansion. 199 /// \brief Render the site of an expansion.
220 virtual void 200 virtual void renderExpansionSite(raw_ostream &OS, LineRef L,
221 renderExpansionSite(raw_ostream &OS, LineRef L, 201 const LineCoverageStats &LCS,
222 const coverage::CoverageSegment *WrappedSegment, 202 unsigned ExpansionCol,
223 CoverageSegmentArray Segments, unsigned ExpansionCol, 203 unsigned ViewDepth) = 0;
224 unsigned ViewDepth) = 0;
225 204
226 /// \brief Render an expansion view and any nested views. 205 /// \brief Render an expansion view and any nested views.
227 virtual void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, 206 virtual void renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
228 unsigned ViewDepth) = 0; 207 unsigned ViewDepth) = 0;
229 208
244 /// \brief Format a count using engineering notation with 3 significant 223 /// \brief Format a count using engineering notation with 3 significant
245 /// digits. 224 /// digits.
246 static std::string formatCount(uint64_t N); 225 static std::string formatCount(uint64_t N);
247 226
248 /// \brief Check if region marker output is expected for a line. 227 /// \brief Check if region marker output is expected for a line.
249 bool shouldRenderRegionMarkers(bool LineHasMultipleRegions) const; 228 bool shouldRenderRegionMarkers(CoverageSegmentArray Segments) const;
250 229
251 /// \brief Check if there are any sub-views attached to this view. 230 /// \brief Check if there are any sub-views attached to this view.
252 bool hasSubViews() const; 231 bool hasSubViews() const;
253 232
254 SourceCoverageView(StringRef SourceName, const MemoryBuffer &File, 233 SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
255 const CoverageViewOptions &Options, 234 const CoverageViewOptions &Options,
256 coverage::CoverageData &&CoverageInfo) 235 CoverageData &&CoverageInfo)
257 : SourceName(SourceName), File(File), Options(Options), 236 : SourceName(SourceName), File(File), Options(Options),
258 CoverageInfo(std::move(CoverageInfo)) {} 237 CoverageInfo(std::move(CoverageInfo)) {}
259 238
260 public: 239 public:
261 static std::unique_ptr<SourceCoverageView> 240 static std::unique_ptr<SourceCoverageView>
262 create(StringRef SourceName, const MemoryBuffer &File, 241 create(StringRef SourceName, const MemoryBuffer &File,
263 const CoverageViewOptions &Options, 242 const CoverageViewOptions &Options, CoverageData &&CoverageInfo);
264 coverage::CoverageData &&CoverageInfo);
265 243
266 virtual ~SourceCoverageView() {} 244 virtual ~SourceCoverageView() {}
267 245
268 /// \brief Return the source name formatted for the host OS. 246 /// \brief Return the source name formatted for the host OS.
269 std::string getSourceName() const; 247 std::string getSourceName() const;
270 248
271 const CoverageViewOptions &getOptions() const { return Options; } 249 const CoverageViewOptions &getOptions() const { return Options; }
272 250
273 /// \brief Add an expansion subview to this view. 251 /// \brief Add an expansion subview to this view.
274 void addExpansion(const coverage::CounterMappingRegion &Region, 252 void addExpansion(const CounterMappingRegion &Region,
275 std::unique_ptr<SourceCoverageView> View); 253 std::unique_ptr<SourceCoverageView> View);
276 254
277 /// \brief Add a function instantiation subview to this view. 255 /// \brief Add a function instantiation subview to this view.
278 void addInstantiation(StringRef FunctionName, unsigned Line, 256 void addInstantiation(StringRef FunctionName, unsigned Line,
279 std::unique_ptr<SourceCoverageView> View); 257 std::unique_ptr<SourceCoverageView> View);
280 258
281 /// \brief Print the code coverage information for a specific portion of a 259 /// \brief Print the code coverage information for a specific portion of a
282 /// source file to the output stream. 260 /// source file to the output stream.
283 void print(raw_ostream &OS, bool WholeFile, bool ShowSourceName, 261 void print(raw_ostream &OS, bool WholeFile, bool ShowSourceName,
284 unsigned ViewDepth = 0); 262 bool ShowTitle, unsigned ViewDepth = 0);
285 }; 263 };
286 264
287 } // namespace llvm 265 } // namespace llvm
288 266
289 #endif // LLVM_COV_SOURCECOVERAGEVIEW_H 267 #endif // LLVM_COV_SOURCECOVERAGEVIEW_H