aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/tools/llvm-cov/CoverageReport.cpp52
-rw-r--r--llvm/tools/llvm-cov/CoverageReport.h15
2 files changed, 47 insertions, 20 deletions
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 648ddf8..695e50f 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -133,7 +133,8 @@ unsigned getLongestCommonPrefixLen(ArrayRef<StringRef> Strings) {
namespace llvm {
-void CoverageReport::render(const FileCoverageSummary &File, raw_ostream &OS) {
+void CoverageReport::render(const FileCoverageSummary &File,
+ raw_ostream &OS) const {
auto FileCoverageColor =
determineCoveragePercentageColor(File.RegionCoverage);
auto FuncCoverageColor =
@@ -169,7 +170,7 @@ void CoverageReport::render(const FileCoverageSummary &File, raw_ostream &OS) {
}
void CoverageReport::render(const FunctionCoverageSummary &Function,
- raw_ostream &OS) {
+ raw_ostream &OS) const {
auto FuncCoverageColor =
determineCoveragePercentageColor(Function.RegionCoverage);
auto LineCoverageColor =
@@ -234,7 +235,34 @@ void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
}
}
-void CoverageReport::renderFileReports(raw_ostream &OS) {
+std::vector<FileCoverageSummary>
+CoverageReport::prepareFileReports(FileCoverageSummary &Totals,
+ ArrayRef<StringRef> Files) const {
+ std::vector<FileCoverageSummary> FileReports;
+ unsigned LCP = 0;
+ if (Files.size() > 1)
+ LCP = getLongestCommonPrefixLen(Files);
+
+ for (StringRef Filename : Files) {
+ FileCoverageSummary Summary(Filename.drop_front(LCP));
+ for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
+ FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
+ Summary.addFunction(Function);
+ Totals.addFunction(Function);
+ }
+ FileReports.push_back(Summary);
+ }
+
+ return FileReports;
+}
+
+void CoverageReport::renderFileReports(raw_ostream &OS) const {
+ std::vector<StringRef> UniqueSourceFiles = Coverage.getUniqueSourceFiles();
+ renderFileReports(OS, UniqueSourceFiles);
+}
+
+void CoverageReport::renderFileReports(raw_ostream &OS,
+ ArrayRef<StringRef> Files) const {
adjustColumnWidths(Coverage);
OS << column("Filename", FileReportColumns[0])
<< column("Regions", FileReportColumns[1], Column::RightAlignment)
@@ -249,21 +277,11 @@ void CoverageReport::renderFileReports(raw_ostream &OS) {
renderDivider(FileReportColumns, OS);
OS << "\n";
- std::vector<StringRef> UniqueSourceFiles = Coverage.getUniqueSourceFiles();
- unsigned LCP = 0;
- if (UniqueSourceFiles.size() > 1)
- LCP = getLongestCommonPrefixLen(UniqueSourceFiles);
-
FileCoverageSummary Totals("TOTAL");
- for (StringRef Filename : UniqueSourceFiles) {
- FileCoverageSummary Summary(Filename.drop_front(LCP));
- for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
- FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
- Summary.addFunction(Function);
- Totals.addFunction(Function);
- }
- render(Summary, OS);
- }
+ auto FileReports = prepareFileReports(Totals, Files);
+ for (const FileCoverageSummary &FCS : FileReports)
+ render(FCS, OS);
+
renderDivider(FileReportColumns, OS);
OS << "\n";
render(Totals, OS);
diff --git a/llvm/tools/llvm-cov/CoverageReport.h b/llvm/tools/llvm-cov/CoverageReport.h
index 8d6a20e..7a06954 100644
--- a/llvm/tools/llvm-cov/CoverageReport.h
+++ b/llvm/tools/llvm-cov/CoverageReport.h
@@ -24,8 +24,8 @@ class CoverageReport {
const CoverageViewOptions &Options;
const coverage::CoverageMapping &Coverage;
- void render(const FileCoverageSummary &File, raw_ostream &OS);
- void render(const FunctionCoverageSummary &Function, raw_ostream &OS);
+ void render(const FileCoverageSummary &File, raw_ostream &OS) const;
+ void render(const FunctionCoverageSummary &Function, raw_ostream &OS) const;
public:
CoverageReport(const CoverageViewOptions &Options,
@@ -34,7 +34,16 @@ public:
void renderFunctionReports(ArrayRef<StringRef> Files, raw_ostream &OS);
- void renderFileReports(raw_ostream &OS);
+ /// Prepare file reports for the files specified in \p Files.
+ std::vector<FileCoverageSummary>
+ prepareFileReports(FileCoverageSummary &Totals,
+ ArrayRef<StringRef> Files) const;
+
+ /// Render file reports for every unique file in the coverage mapping.
+ void renderFileReports(raw_ostream &OS) const;
+
+ /// Render file reports for the files specified in \p Files.
+ void renderFileReports(raw_ostream &OS, ArrayRef<StringRef> Files) const;
};
} // end namespace llvm