1 //===- SourceCoverageDataManager.cpp - Manager for source file coverage
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This class separates and merges mapping regions for a specific source file.
13 //===----------------------------------------------------------------------===//
15 #include "SourceCoverageDataManager.h"
18 using namespace coverage;
20 void SourceCoverageDataManager::insert(const MappingRegion &Region) {
21 SourceRange Range(Region.LineStart, Region.ColumnStart, Region.LineEnd,
23 if (Region.Kind == CounterMappingRegion::SkippedRegion) {
24 SkippedRegions.push_back(Range);
27 Regions.push_back(std::make_pair(Range, Region.ExecutionCount));
30 ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>
31 SourceCoverageDataManager::getSourceRegions() {
32 if (Uniqued || Regions.size() <= 1)
36 std::sort(Regions.begin(), Regions.end(),
37 [](const std::pair<SourceRange, uint64_t> &LHS,
38 const std::pair<SourceRange, uint64_t> &RHS) {
39 return LHS.first < RHS.first;
42 // Merge duplicate source ranges and sum their execution counts.
43 auto Prev = Regions.begin();
44 for (auto I = Prev + 1, E = Regions.end(); I != E; ++I) {
45 if (I->first == Prev->first) {
46 Prev->second += I->second;
53 Regions.erase(Prev, Regions.end());