@@ -140,10 +140,12 @@ void SourceCoverageView::renderRegionMarkers(raw_ostream &OS,
140
140
141
141
// / \brief Insert a new highlighting range into the line's highlighting ranges
142
142
// / Return line's new highlighting ranges in result.
143
- static void insertHighlightRange (
143
+ static void insertExpansionHighlightRange (
144
144
ArrayRef<SourceCoverageView::HighlightRange> Ranges,
145
- SourceCoverageView::HighlightRange RangeToInsert ,
145
+ unsigned Line, unsigned StartCol, unsigned EndCol ,
146
146
SmallVectorImpl<SourceCoverageView::HighlightRange> &Result) {
147
+ auto RangeToInsert = SourceCoverageView::HighlightRange (
148
+ Line, StartCol, EndCol, SourceCoverageView::HighlightRange::Expanded);
147
149
Result.clear ();
148
150
size_t I = 0 ;
149
151
auto E = Ranges.size ();
@@ -189,22 +191,6 @@ static void insertHighlightRange(
189
191
Result.push_back (Ranges[I]);
190
192
}
191
193
192
- void SourceCoverageView::sortChildren () {
193
- for (auto &I : Children)
194
- I->sortChildren ();
195
- std::sort (Children.begin (), Children.end (),
196
- [](const std::unique_ptr<SourceCoverageView> &LHS,
197
- const std::unique_ptr<SourceCoverageView> &RHS) {
198
- return LHS->ExpansionRegion < RHS->ExpansionRegion ;
199
- });
200
- }
201
-
202
- SourceCoverageView::HighlightRange
203
- SourceCoverageView::getExpansionHighlightRange () const {
204
- return HighlightRange (ExpansionRegion.LineStart , ExpansionRegion.ColumnStart ,
205
- ExpansionRegion.ColumnEnd , HighlightRange::Expanded);
206
- }
207
-
208
194
template <typename T>
209
195
ArrayRef<T> gatherLineItems (size_t &CurrentIdx, const std::vector<T> &Items,
210
196
unsigned LineNo) {
@@ -215,24 +201,8 @@ ArrayRef<T> gatherLineItems(size_t &CurrentIdx, const std::vector<T> &Items,
215
201
return ArrayRef<T>(Items.data () + PrevIdx, CurrentIdx - PrevIdx);
216
202
}
217
203
218
- ArrayRef<std::unique_ptr<SourceCoverageView>>
219
- gatherLineSubViews (size_t &CurrentIdx,
220
- ArrayRef<std::unique_ptr<SourceCoverageView>> Items,
221
- unsigned LineNo) {
222
- auto PrevIdx = CurrentIdx;
223
- auto E = Items.size ();
224
- while (CurrentIdx < E &&
225
- Items[CurrentIdx]->getSubViewsExpansionLine () == LineNo)
226
- ++CurrentIdx;
227
- return Items.slice (PrevIdx, CurrentIdx - PrevIdx);
228
- }
229
-
230
204
void SourceCoverageView::render (raw_ostream &OS, unsigned IndentLevel) {
231
- // Make sure that the children are in sorted order.
232
- sortChildren ();
233
-
234
205
SmallVector<HighlightRange, 8 > AdjustedLineHighlightRanges;
235
- size_t CurrentChild = 0 ;
236
206
size_t CurrentHighlightRange = 0 ;
237
207
size_t CurrentRegionMarker = 0 ;
238
208
@@ -249,12 +219,18 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
249
219
// subviews.
250
220
unsigned DividerWidth = CombinedColumnWidth + 4 ;
251
221
222
+ // We need the expansions and instantiations sorted so we can go through them
223
+ // while we iterate lines.
224
+ std::sort (ExpansionSubViews.begin (), ExpansionSubViews.end ());
225
+ std::sort (InstantiationSubViews.begin (), InstantiationSubViews.end ());
226
+ auto NextESV = ExpansionSubViews.begin ();
227
+ auto EndESV = ExpansionSubViews.end ();
228
+ auto NextISV = InstantiationSubViews.begin ();
229
+ auto EndISV = InstantiationSubViews.end ();
230
+
252
231
for (size_t I = 0 , E = LineStats.size (); I < E; ++I) {
253
232
unsigned LineNo = I + LineOffset;
254
233
255
- // Gather the child subviews that are visible on this line.
256
- auto LineSubViews = gatherLineSubViews (CurrentChild, Children, LineNo);
257
-
258
234
renderIndent (OS, IndentLevel);
259
235
if (Options.ShowLineStats )
260
236
renderLineCoverageColumn (OS, LineStats[I]);
@@ -267,11 +243,10 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
267
243
auto LineRanges = LineHighlightRanges;
268
244
// Highlight the expansion range if there is an expansion subview on this
269
245
// line.
270
- if (!LineSubViews.empty () && LineSubViews.front ()->isExpansionSubView () &&
271
- Options.Colors ) {
272
- insertHighlightRange (LineHighlightRanges,
273
- LineSubViews.front ()->getExpansionHighlightRange (),
274
- AdjustedLineHighlightRanges);
246
+ if (NextESV != EndESV && NextESV->getLine () == LineNo && Options.Colors ) {
247
+ insertExpansionHighlightRange (
248
+ LineHighlightRanges, NextESV->getLine (), NextESV->getStartCol (),
249
+ NextESV->getEndCol (), AdjustedLineHighlightRanges);
275
250
LineRanges = AdjustedLineHighlightRanges;
276
251
}
277
252
@@ -294,40 +269,40 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned IndentLevel) {
294
269
renderRegionMarkers (OS, LineMarkers);
295
270
}
296
271
297
- // Show the line's expanded child subviews.
298
- bool FirstChildExpansion = true ;
299
- if (LineSubViews.empty ())
300
- continue ;
272
+ // Show the expansions and instantiations for this line.
301
273
unsigned NestedIndent = IndentLevel + 1 ;
302
- renderViewDivider (NestedIndent, DividerWidth, OS);
303
- OS << " \n " ;
304
- for (const auto &Child : LineSubViews) {
305
- // If this subview shows a function instantiation, render the function's
306
- // name.
307
- if (Child->isInstantiationSubView ()) {
308
- renderIndent (OS, NestedIndent);
309
- OS << ' ' ;
310
- Options.colored_ostream (OS, raw_ostream::CYAN) << Child->FunctionName
311
- << " :" ;
274
+ bool RenderedSubView = false ;
275
+ for (; NextESV != EndESV && NextESV->getLine () == LineNo; ++NextESV) {
276
+ renderViewDivider (NestedIndent, DividerWidth, OS);
277
+ OS << " \n " ;
278
+ if (RenderedSubView) {
279
+ // Re-render the current line and highlight the expansion range for
280
+ // this subview.
281
+ insertExpansionHighlightRange (
282
+ LineHighlightRanges, NextESV->getLine (), NextESV->getStartCol (),
283
+ NextESV->getEndCol (), AdjustedLineHighlightRanges);
284
+ renderIndent (OS, IndentLevel);
285
+ OS.indent (CombinedColumnWidth + (IndentLevel == 0 ? 0 : 1 ));
286
+ renderLine (OS, Line, AdjustedLineHighlightRanges);
287
+ renderViewDivider (NestedIndent, DividerWidth, OS);
312
288
OS << " \n " ;
313
- } else {
314
- if (!FirstChildExpansion) {
315
- // Re-render the current line and highlight the expansion range for
316
- // this
317
- // subview.
318
- insertHighlightRange (LineHighlightRanges,
319
- Child->getExpansionHighlightRange (),
320
- AdjustedLineHighlightRanges);
321
- renderIndent (OS, IndentLevel);
322
- OS.indent (CombinedColumnWidth + (IndentLevel == 0 ? 0 : 1 ));
323
- renderLine (OS, Line, AdjustedLineHighlightRanges);
324
- renderViewDivider (NestedIndent, DividerWidth, OS);
325
- OS << " \n " ;
326
- } else
327
- FirstChildExpansion = false ;
328
289
}
329
290
// Render the child subview
330
- Child->render (OS, NestedIndent);
291
+ NextESV->View ->render (OS, NestedIndent);
292
+ RenderedSubView = true ;
293
+ }
294
+ for (; NextISV != EndISV && NextISV->Line == LineNo; ++NextISV) {
295
+ renderViewDivider (NestedIndent, DividerWidth, OS);
296
+ OS << " \n " ;
297
+ renderIndent (OS, NestedIndent);
298
+ OS << ' ' ;
299
+ Options.colored_ostream (OS, raw_ostream::CYAN) << NextISV->FunctionName
300
+ << " :" ;
301
+ OS << " \n " ;
302
+ NextISV->View ->render (OS, NestedIndent);
303
+ RenderedSubView = true ;
304
+ }
305
+ if (RenderedSubView) {
331
306
renderViewDivider (NestedIndent, DividerWidth, OS);
332
307
OS << " \n " ;
333
308
}
0 commit comments