llvm-cov: Sink some reporting logic into CoverageMapping

This teaches CoverageMapping::getCoveredFunctions to filter to a
particular file and uses that to replace most of the logic found in
llvm-cov report.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221962 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner
2014-11-14 01:50:32 +00:00
parent 4a7bbf4c29
commit d24e90a5de
5 changed files with 66 additions and 43 deletions

View File

@@ -18,6 +18,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
@@ -240,6 +241,40 @@ struct FunctionRecord {
ExecutionCount(ExecutionCount) {}
};
/// \brief Iterator over Functions, optionally filtered to a single file.
class FunctionRecordIterator
: public iterator_facade_base<FunctionRecordIterator,
std::forward_iterator_tag, FunctionRecord> {
ArrayRef<FunctionRecord> Records;
ArrayRef<FunctionRecord>::iterator Current;
StringRef Filename;
/// \brief Skip records whose primary file is not \c Filename.
void skipOtherFiles();
public:
FunctionRecordIterator(ArrayRef<FunctionRecord> Records_,
StringRef Filename = "")
: Records(Records_), Current(Records.begin()), Filename(Filename) {
skipOtherFiles();
}
FunctionRecordIterator() : Current(Records.begin()) {}
bool operator==(const FunctionRecordIterator &RHS) const {
return Current == RHS.Current && Filename == RHS.Filename;
}
const FunctionRecord &operator*() const { return *Current; }
FunctionRecordIterator &operator++() {
assert(Current != Records.end() && "incremented past end");
++Current;
skipOtherFiles();
return *this;
}
};
/// \brief Coverage information for a macro expansion or #included file.
///
/// When covered code has pieces that can be expanded for more detail, such as a
@@ -342,7 +377,7 @@ public:
unsigned getMismatchedCount() { return MismatchedFunctionCount; }
/// \brief Returns the list of files that are covered.
std::vector<StringRef> getUniqueSourceFiles();
std::vector<StringRef> getUniqueSourceFiles() const;
/// \brief Get the coverage for a particular file.
///
@@ -352,8 +387,16 @@ public:
CoverageData getCoverageForFile(StringRef Filename);
/// \brief Gets all of the functions covered by this profile.
ArrayRef<FunctionRecord> getCoveredFunctions() {
return ArrayRef<FunctionRecord>(Functions.data(), Functions.size());
iterator_range<FunctionRecordIterator> getCoveredFunctions() const {
return make_range(FunctionRecordIterator(Functions),
FunctionRecordIterator());
}
/// \brief Gets all of the functions in a particular file.
iterator_range<FunctionRecordIterator>
getCoveredFunctions(StringRef Filename) const {
return make_range(FunctionRecordIterator(Functions, Filename),
FunctionRecordIterator());
}
/// \brief Get the list of function instantiations in the file.