1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[llvm-cov] Clean up the summary class, delete dead code (NFC)

llvm-svn: 280764
This commit is contained in:
Vedant Kumar 2016-09-06 22:45:57 +00:00
parent 76f373ba04
commit 5f0da89d4a
3 changed files with 59 additions and 59 deletions

View File

@ -730,7 +730,7 @@ int CodeCoverageTool::report(int argc, const char **argv,
if (!Coverage)
return 1;
CoverageReport Report(ViewOpts, std::move(Coverage));
CoverageReport Report(ViewOpts, *Coverage.get());
if (SourceFiles.empty())
Report.renderFileReports(llvm::outs());
else

View File

@ -15,12 +15,15 @@
#include "RenderingSupport.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include <numeric>
using namespace llvm;
namespace {
/// \brief Helper struct which prints trimmed and aligned columns.
struct Column {
enum TrimKind { NoTrim, WidthTrim, LeftTrim, RightTrim };
enum TrimKind { NoTrim, WidthTrim, RightTrim };
enum AlignmentKind { LeftAlignment, RightAlignment };
@ -42,87 +45,81 @@ struct Column {
return *this;
}
void render(raw_ostream &OS) const;
void render(raw_ostream &OS) const {
if (Str.size() <= Width) {
if (Alignment == RightAlignment) {
OS.indent(Width - Str.size());
OS << Str;
return;
}
OS << Str;
OS.indent(Width - Str.size());
return;
}
switch (Trim) {
case NoTrim:
OS << Str;
break;
case WidthTrim:
OS << Str.substr(0, Width);
break;
case RightTrim:
OS << Str.substr(0, Width - 3) << "...";
break;
}
}
};
raw_ostream &operator<<(raw_ostream &OS, const Column &Value) {
Value.render(OS);
return OS;
}
}
void Column::render(raw_ostream &OS) const {
if (Str.size() <= Width) {
if (Alignment == RightAlignment) {
OS.indent(Width - Str.size());
OS << Str;
return;
}
OS << Str;
OS.indent(Width - Str.size());
return;
}
switch (Trim) {
case NoTrim:
OS << Str;
break;
case WidthTrim:
OS << Str.substr(0, Width);
break;
case LeftTrim:
OS << "..." << Str.substr(Str.size() - Width + 3);
break;
case RightTrim:
OS << Str.substr(0, Width - 3) << "...";
break;
}
}
static Column column(StringRef Str, unsigned Width) {
return Column(Str, Width);
}
Column column(StringRef Str, unsigned Width) { return Column(Str, Width); }
template <typename T>
static Column column(StringRef Str, unsigned Width, const T &Value) {
Column column(StringRef Str, unsigned Width, const T &Value) {
return Column(Str, Width).set(Value);
}
// Specify the default column widths.
static size_t FileReportColumns[] = {25, 12, 18, 10, 12, 18, 10, 12, 18, 10};
static size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
size_t FileReportColumns[] = {25, 12, 18, 10, 12, 18, 10, 12, 18, 10};
size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
/// \brief Adjust column widths to fit long file paths and function names.
static void adjustColumnWidths(coverage::CoverageMapping *CM) {
for (StringRef Filename : CM->getUniqueSourceFiles()) {
/// \brief Adjust column widths to fit long file paths and function names.
void adjustColumnWidths(const coverage::CoverageMapping &CM) {
for (StringRef Filename : CM.getUniqueSourceFiles()) {
FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size());
for (const auto &F : CM->getCoveredFunctions(Filename)) {
for (const auto &F : CM.getCoveredFunctions(Filename)) {
FunctionReportColumns[0] =
std::max(FunctionReportColumns[0], F.Name.size());
}
}
}
/// \brief Prints a horizontal divider which spans across the given columns.
template <typename T, size_t N>
static void renderDivider(T (&Columns)[N], raw_ostream &OS) {
unsigned Length = 0;
for (unsigned I = 0; I < N; ++I)
Length += Columns[I];
for (unsigned I = 0; I < Length; ++I)
/// \brief Prints a horizontal divider long enough to cover the given column
/// widths.
void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS) {
size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
for (size_t I = 0; I < Length; ++I)
OS << '-';
}
/// \brief Return the color which correponds to the coverage
/// percentage of a certain metric.
template <typename T>
static raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
if (Info.isFullyCovered())
return raw_ostream::GREEN;
return Info.getPercentCovered() >= 80.0 ? raw_ostream::YELLOW
: raw_ostream::RED;
}
} // end anonymous namespace
namespace llvm {
void CoverageReport::render(const FileCoverageSummary &File, raw_ostream &OS) {
OS << column(File.Name, FileReportColumns[0], Column::NoTrim)
<< format("%*u", FileReportColumns[1],
@ -188,7 +185,7 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
raw_ostream &OS) {
adjustColumnWidths(Coverage.get());
adjustColumnWidths(Coverage);
bool isFirst = true;
for (StringRef Filename : Files) {
if (isFirst)
@ -207,7 +204,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
renderDivider(FunctionReportColumns, OS);
OS << "\n";
FunctionCoverageSummary Totals("TOTAL");
for (const auto &F : Coverage->getCoveredFunctions(Filename)) {
for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
++Totals.ExecutionCount;
Totals.RegionCoverage += Function.RegionCoverage;
@ -223,7 +220,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
}
void CoverageReport::renderFileReports(raw_ostream &OS) {
adjustColumnWidths(Coverage.get());
adjustColumnWidths(Coverage);
OS << column("Filename", FileReportColumns[0])
<< column("Regions", FileReportColumns[1], Column::RightAlignment)
<< column("Missed Regions", FileReportColumns[2], Column::RightAlignment)
@ -240,9 +237,9 @@ void CoverageReport::renderFileReports(raw_ostream &OS) {
OS << "\n";
FileCoverageSummary Totals("TOTAL");
for (StringRef Filename : Coverage->getUniqueSourceFiles()) {
for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
FileCoverageSummary Summary(Filename);
for (const auto &F : Coverage->getCoveredFunctions(Filename)) {
for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
Summary.addFunction(Function);
Totals.addFunction(Function);
@ -253,3 +250,5 @@ void CoverageReport::renderFileReports(raw_ostream &OS) {
OS << "\n";
render(Totals, OS);
}
} // end namespace llvm

View File

@ -22,20 +22,21 @@ namespace llvm {
/// \brief Displays the code coverage report.
class CoverageReport {
const CoverageViewOptions &Options;
std::unique_ptr<coverage::CoverageMapping> Coverage;
const coverage::CoverageMapping &Coverage;
void render(const FileCoverageSummary &File, raw_ostream &OS);
void render(const FunctionCoverageSummary &Function, raw_ostream &OS);
public:
CoverageReport(const CoverageViewOptions &Options,
std::unique_ptr<coverage::CoverageMapping> Coverage)
: Options(Options), Coverage(std::move(Coverage)) {}
const coverage::CoverageMapping &Coverage)
: Options(Options), Coverage(Coverage) {}
void renderFunctionReports(ArrayRef<StringRef> Files, raw_ostream &OS);
void renderFileReports(raw_ostream &OS);
};
}
} // end namespace llvm
#endif // LLVM_COV_COVERAGEREPORT_H