llvm-cov: Rename MappingRegion to coverage::CountedRegion (NFC)

This name was too similar to CoverageMappingRegion, and the type
really belongs in the coverage library anyway.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner 2014-09-09 05:32:14 +00:00
parent 086832979b
commit 74a60259a5
6 changed files with 57 additions and 58 deletions

View File

@ -173,6 +173,14 @@ struct CounterMappingRegion {
}
};
/// \brief Associates a source range with an execution count.
struct CountedRegion : public CounterMappingRegion {
uint64_t ExecutionCount;
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
: CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
};
/// \brief A Counter mapping context is used to connect the counters,
/// expressions and the obtained counter values.
class CounterMappingContext {

View File

@ -53,14 +53,14 @@ class FunctionInstantiationSetCollector {
typedef std::vector<const FunctionCoverageMapping *> SetType;
std::unordered_map<uint64_t, SetType> InstantiatedFunctions;
static KeyType getKey(const MappingRegion &R) {
static KeyType getKey(const CountedRegion &R) {
return uint64_t(R.LineStart) | uint64_t(R.ColumnStart) << 32;
}
public:
void insert(const FunctionCoverageMapping &Function, unsigned FileID) {
KeyType Key = 0;
for (const auto &R : Function.MappingRegions) {
for (const auto &R : Function.CountedRegions) {
if (R.FileID == FileID) {
Key = getKey(R);
break;
@ -119,7 +119,7 @@ public:
/// \brief Create a source view which shows coverage for an expansion
/// of a file.
void createExpansionSubView(const MappingRegion &ExpandedRegion,
void createExpansionSubView(const CountedRegion &ExpandedRegion,
const FunctionCoverageMapping &Function,
SourceCoverageView &Parent);
@ -197,11 +197,11 @@ findExpandedFileInterestingLineRange(unsigned FileID,
const FunctionCoverageMapping &Function) {
unsigned LineStart = std::numeric_limits<unsigned>::max();
unsigned LineEnd = 0;
for (const auto &Region : Function.MappingRegions) {
if (Region.FileID != FileID)
for (const auto &CR : Function.CountedRegions) {
if (CR.FileID != FileID)
continue;
LineStart = std::min(Region.LineStart, LineStart);
LineEnd = std::max(Region.LineEnd, LineEnd);
LineStart = std::min(CR.LineStart, LineStart);
LineEnd = std::max(CR.LineEnd, LineEnd);
}
return std::make_pair(LineStart, LineEnd);
}
@ -236,10 +236,10 @@ CodeCoverageTool::findMainViewFileID(StringRef SourceFile,
if (equivalentFiles(SourceFile, Function.Filenames[I]))
FilenameEquivalence[I] = true;
}
for (const auto &Region : Function.MappingRegions) {
if (Region.Kind == MappingRegion::ExpansionRegion &&
FilenameEquivalence[Region.FileID])
IsExpandedFile[Region.ExpandedFileID] = true;
for (const auto &CR : Function.CountedRegions) {
if (CR.Kind == CounterMappingRegion::ExpansionRegion &&
FilenameEquivalence[CR.FileID])
IsExpandedFile[CR.ExpandedFileID] = true;
}
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
if (!FilenameEquivalence[I] || IsExpandedFile[I])
@ -254,9 +254,9 @@ bool
CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
unsigned &MainViewFileID) {
llvm::SmallVector<bool, 8> IsExpandedFile(Function.Filenames.size(), false);
for (const auto &Region : Function.MappingRegions) {
if (Region.Kind == MappingRegion::ExpansionRegion)
IsExpandedFile[Region.ExpandedFileID] = true;
for (const auto &CR : Function.CountedRegions) {
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
IsExpandedFile[CR.ExpandedFileID] = true;
}
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
if (IsExpandedFile[I])
@ -268,7 +268,7 @@ CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
}
void CodeCoverageTool::createExpansionSubView(
const MappingRegion &ExpandedRegion,
const CountedRegion &ExpandedRegion,
const FunctionCoverageMapping &Function, SourceCoverageView &Parent) {
auto ExpandedLines = findExpandedFileInterestingLineRange(
ExpandedRegion.ExpandedFileID, Function);
@ -286,9 +286,9 @@ void CodeCoverageTool::createExpansionSubView(
SourceBuffer.get(), Parent.getOptions(), ExpandedLines.first,
ExpandedLines.second, ExpandedRegion);
SourceCoverageDataManager RegionManager;
for (const auto &Region : Function.MappingRegions) {
if (Region.FileID == ExpandedRegion.ExpandedFileID)
RegionManager.insert(Region);
for (const auto &CR : Function.CountedRegions) {
if (CR.FileID == ExpandedRegion.ExpandedFileID)
RegionManager.insert(CR);
}
SubView->load(RegionManager);
createExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
@ -300,12 +300,12 @@ void CodeCoverageTool::createExpansionSubViews(
const FunctionCoverageMapping &Function) {
if (!ViewOpts.ShowExpandedRegions)
return;
for (const auto &Region : Function.MappingRegions) {
if (Region.Kind != CounterMappingRegion::ExpansionRegion)
for (const auto &CR : Function.CountedRegions) {
if (CR.Kind != CounterMappingRegion::ExpansionRegion)
continue;
if (Region.FileID != ViewFileID)
if (CR.FileID != ViewFileID)
continue;
createExpansionSubView(Region, Function, View);
createExpansionSubView(CR, Function, View);
}
}
@ -317,9 +317,9 @@ void CodeCoverageTool::createInstantiationSubView(
if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
return;
// Get the interesting regions
for (const auto &Region : Function.MappingRegions) {
if (InterestingFileIDs.count(Region.FileID))
RegionManager.insert(Region);
for (const auto &CR : Function.CountedRegions) {
if (InterestingFileIDs.count(CR.FileID))
RegionManager.insert(CR);
}
View.load(RegionManager);
unsigned MainFileID;
@ -346,9 +346,9 @@ bool CodeCoverageTool::createSourceFileView(
InterestingFileIDs))
continue;
// Get the interesting regions
for (const auto &Region : Function.MappingRegions) {
if (InterestingFileIDs.count(Region.FileID))
RegionManager.insert(Region);
for (const auto &CR : Function.CountedRegions) {
if (InterestingFileIDs.count(CR.FileID))
RegionManager.insert(CR);
}
InstantiationSetCollector.insert(Function, MainFileID);
createExpansionSubViews(View, MainFileID, Function);
@ -363,7 +363,7 @@ bool CodeCoverageTool::createSourceFileView(
if (InstantiationSet.second.size() < 2)
continue;
auto InterestingRange = findExpandedFileInterestingLineRange(
InstantiationSet.second.front()->MappingRegions.front().FileID,
InstantiationSet.second.front()->CountedRegions.front().FileID,
*InstantiationSet.second.front());
for (auto Function : InstantiationSet.second) {
auto SubView = llvm::make_unique<SourceCoverageView>(
@ -413,7 +413,7 @@ bool CodeCoverageTool::load() {
}
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(R.Count);
if (ExecutionCount) {
Function.MappingRegions.push_back(MappingRegion(R, *ExecutionCount));
Function.CountedRegions.push_back(CountedRegion(R, *ExecutionCount));
} else if (!RegionError) {
colored_ostream(errs(), raw_ostream::RED)
<< "error: Regions and counters don't match in a function '"

View File

@ -21,11 +21,11 @@ FunctionCoverageSummary
FunctionCoverageSummary::get(const FunctionCoverageMapping &Function) {
// Compute the region coverage
size_t NumCodeRegions = 0, CoveredRegions = 0;
for (auto &Region : Function.MappingRegions) {
if (Region.Kind != CounterMappingRegion::CodeRegion)
for (auto &CR : Function.CountedRegions) {
if (CR.Kind != CounterMappingRegion::CodeRegion)
continue;
++NumCodeRegions;
if (Region.ExecutionCount != 0)
if (CR.ExecutionCount != 0)
++CoveredRegions;
}
@ -37,27 +37,27 @@ FunctionCoverageSummary::get(const FunctionCoverageMapping &Function) {
// in that particular file
unsigned LineStart = std::numeric_limits<unsigned>::max();
unsigned LineEnd = 0;
for (auto &Region : Function.MappingRegions) {
if (Region.FileID != FileID)
for (auto &CR : Function.CountedRegions) {
if (CR.FileID != FileID)
continue;
LineStart = std::min(LineStart, Region.LineStart);
LineEnd = std::max(LineEnd, Region.LineEnd);
LineStart = std::min(LineStart, CR.LineStart);
LineEnd = std::max(LineEnd, CR.LineEnd);
}
unsigned LineCount = LineEnd - LineStart + 1;
// Get counters
llvm::SmallVector<uint64_t, 16> ExecutionCounts;
ExecutionCounts.resize(LineCount, 0);
for (auto &Region : Function.MappingRegions) {
if (Region.FileID != FileID)
for (auto &CR : Function.CountedRegions) {
if (CR.FileID != FileID)
continue;
// Ignore the lines that were skipped by the preprocessor.
auto ExecutionCount = Region.ExecutionCount;
if (Region.Kind == MappingRegion::SkippedRegion) {
LineCount -= Region.LineEnd - Region.LineStart + 1;
auto ExecutionCount = CR.ExecutionCount;
if (CR.Kind == CounterMappingRegion::SkippedRegion) {
LineCount -= CR.LineEnd - CR.LineStart + 1;
ExecutionCount = 1;
}
for (unsigned I = Region.LineStart; I <= Region.LineEnd; ++I)
for (unsigned I = CR.LineStart; I <= CR.LineEnd; ++I)
ExecutionCounts[I - LineStart] = ExecutionCount;
}
CoveredLines += LineCount - std::count(ExecutionCounts.begin(),

View File

@ -22,21 +22,13 @@
namespace llvm {
/// \brief Associates a source range with an execution count.
struct MappingRegion : public coverage::CounterMappingRegion {
uint64_t ExecutionCount;
MappingRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
: CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
};
/// \brief Stores all the required information
/// about code coverage for a single function.
struct FunctionCoverageMapping {
/// \brief Raw function name.
std::string Name;
std::vector<std::string> Filenames;
std::vector<MappingRegion> MappingRegions;
std::vector<coverage::CountedRegion> CountedRegions;
FunctionCoverageMapping(StringRef Name, ArrayRef<StringRef> Filenames)
: Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}

View File

@ -17,14 +17,13 @@
using namespace llvm;
using namespace coverage;
void SourceCoverageDataManager::insert(const MappingRegion &Region) {
SourceRange Range(Region.LineStart, Region.ColumnStart, Region.LineEnd,
Region.ColumnEnd);
if (Region.Kind == CounterMappingRegion::SkippedRegion) {
void SourceCoverageDataManager::insert(const CountedRegion &CR) {
SourceRange Range(CR.LineStart, CR.ColumnStart, CR.LineEnd, CR.ColumnEnd);
if (CR.Kind == CounterMappingRegion::SkippedRegion) {
SkippedRegions.push_back(Range);
return;
}
Regions.push_back(std::make_pair(Range, Region.ExecutionCount));
Regions.push_back(std::make_pair(Range, CR.ExecutionCount));
}
ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>

View File

@ -64,7 +64,7 @@ protected:
public:
SourceCoverageDataManager() : Uniqued(false) {}
void insert(const MappingRegion &Region);
void insert(const coverage::CountedRegion &CR);
/// \brief Return the source ranges and execution counts
/// obtained from the non-skipped mapping regions.