-}
-
-/// \brief Insert a new highlighting range into the line's highlighting ranges
-/// Return line's new highlighting ranges in result.
-static void insertHighlightRange(
- ArrayRef<SourceCoverageView::HighlightRange> Ranges,
- SourceCoverageView::HighlightRange RangeToInsert,
- SmallVectorImpl<SourceCoverageView::HighlightRange> &Result) {
- Result.clear();
- size_t I = 0;
- auto E = Ranges.size();
- for (; I < E; ++I) {
- if (RangeToInsert.ColumnStart < Ranges[I].ColumnEnd) {
- const auto &Range = Ranges[I];
- bool NextRangeContainsInserted = false;
- // If the next range starts before the inserted range, move the end of the
- // next range to the start of the inserted range.
- if (Range.ColumnStart < RangeToInsert.ColumnStart) {
- if (RangeToInsert.ColumnStart != Range.ColumnStart)
- Result.push_back(SourceCoverageView::HighlightRange(
- Range.Line, Range.ColumnStart, RangeToInsert.ColumnStart,
- Range.Kind));
- // If the next range also ends after the inserted range, keep this range
- // and create a new range that starts at the inserted range and ends
- // at the next range later.
- if (Range.ColumnEnd > RangeToInsert.ColumnEnd)
- NextRangeContainsInserted = true;
- }
- if (!NextRangeContainsInserted) {
- ++I;
- // Ignore ranges that are contained in inserted range
- while (I < E && RangeToInsert.contains(Ranges[I]))
- ++I;
- }
- break;
- }
- Result.push_back(Ranges[I]);
- }
- Result.push_back(RangeToInsert);
- // If the next range starts before the inserted range end, move the start
- // of the next range to the end of the inserted range.
- if (I < E && Ranges[I].ColumnStart < RangeToInsert.ColumnEnd) {
- const auto &Range = Ranges[I];
- if (RangeToInsert.ColumnEnd != Range.ColumnEnd)
- Result.push_back(SourceCoverageView::HighlightRange(
- Range.Line, RangeToInsert.ColumnEnd, Range.ColumnEnd, Range.Kind));
- ++I;
- }
- // Add the remaining ranges that are located after the inserted range
- for (; I < E; ++I)
- Result.push_back(Ranges[I]);
-}
-
-void SourceCoverageView::sortChildren() {
- for (auto &I : Children)
- I->sortChildren();
- std::sort(Children.begin(), Children.end(),
- [](const std::unique_ptr<SourceCoverageView> &LHS,
- const std::unique_ptr<SourceCoverageView> &RHS) {
- return LHS->ExpansionRegion < RHS->ExpansionRegion;
- });
-}