Path: blob/main/contrib/llvm-project/llvm/tools/llvm-cov/CoverageReport.h
35231 views
//===- CoverageReport.h - Code coverage report ----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This class implements rendering of a code coverage report.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_COV_COVERAGEREPORT_H13#define LLVM_COV_COVERAGEREPORT_H1415#include "CoverageFilters.h"16#include "CoverageSummaryInfo.h"17#include "CoverageViewOptions.h"18#include <map>1920namespace llvm {2122class ThreadPoolInterface;2324/// Displays the code coverage report.25class CoverageReport {26const CoverageViewOptions &Options;27const coverage::CoverageMapping &Coverage;2829void render(const FileCoverageSummary &File, raw_ostream &OS) const;30void render(const FunctionCoverageSummary &Function, const DemangleCache &DC,31raw_ostream &OS) const;3233public:34CoverageReport(const CoverageViewOptions &Options,35const coverage::CoverageMapping &Coverage)36: Options(Options), Coverage(Coverage) {}3738void renderFunctionReports(ArrayRef<std::string> Files,39const DemangleCache &DC, raw_ostream &OS);4041/// Prepare file reports for the files specified in \p Files.42static std::vector<FileCoverageSummary>43prepareFileReports(const coverage::CoverageMapping &Coverage,44FileCoverageSummary &Totals, ArrayRef<std::string> Files,45const CoverageViewOptions &Options,46const CoverageFilter &Filters = CoverageFiltersMatchAll());4748static void49prepareSingleFileReport(const StringRef Filename,50const coverage::CoverageMapping *Coverage,51const CoverageViewOptions &Options,52const unsigned LCP,53FileCoverageSummary *FileReport,54const CoverageFilter *Filters);5556/// Render file reports for every unique file in the coverage mapping.57void renderFileReports(raw_ostream &OS,58const CoverageFilters &IgnoreFilenameFilters) const;5960/// Render file reports for the files specified in \p Files.61void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files) const;6263/// Render file reports for the files specified in \p Files and the functions64/// in \p Filters.65void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files,66const CoverageFiltersMatchAll &Filters) const;6768/// Render file reports with given data.69void renderFileReports(raw_ostream &OS,70const std::vector<FileCoverageSummary> &FileReports,71const FileCoverageSummary &Totals,72bool ShowEmptyFiles) const;73};7475/// Prepare reports for every non-trivial directories (which have more than 176/// source files) of the source files. This class uses template method pattern.77class DirectoryCoverageReport {78public:79DirectoryCoverageReport(80const CoverageViewOptions &Options,81const coverage::CoverageMapping &Coverage,82const CoverageFiltersMatchAll &Filters = CoverageFiltersMatchAll())83: Options(Options), Coverage(Coverage), Filters(Filters) {}8485virtual ~DirectoryCoverageReport() = default;8687/// Prepare file reports for each directory in \p SourceFiles. The total88/// report for all files is returned and its Name is set to the LCP of all89/// files. The size of \p SourceFiles must be greater than 1 or else the90/// behavior is undefined, in which case you should use91/// CoverageReport::prepareSingleFileReport instead. If an error occurs,92/// the recursion will stop immediately.93Expected<FileCoverageSummary>94prepareDirectoryReports(ArrayRef<std::string> SourceFiles);9596protected:97// These member variables below are used for avoiding being passed98// repeatedly in recursion.99const CoverageViewOptions &Options;100const coverage::CoverageMapping &Coverage;101const CoverageFiltersMatchAll &Filters;102103/// For calling CoverageReport::prepareSingleFileReport asynchronously104/// in prepareSubDirectoryReports(). It's not intended to be modified by105/// generateSubDirectoryReport().106ThreadPoolInterface *TPool;107108/// One report level may correspond to multiple directory levels as we omit109/// directories which have only one subentry. So we use this Stack to track110/// each report level's corresponding drectory level.111/// Each value in the stack is the LCP prefix length length of that report112/// level. LCPStack.front() is the root LCP. Current LCP is LCPStack.back().113SmallVector<unsigned, 32> LCPStack;114115// Use std::map to sort table rows in order.116using SubFileReports = std::map<StringRef, FileCoverageSummary>;117using SubDirReports =118std::map<StringRef,119std::pair<FileCoverageSummary, SmallVector<StringRef, 0>>>;120121/// This method is called when a report level is prepared during the122/// recursion. \p SubFiles are the reports for those files directly in the123/// current directory. \p SubDirs are the reports for subdirectories in124/// current directory. \p SubTotals is the sum of all, and its name is the125/// current LCP. Note that this method won't be called for trivial126/// directories.127virtual Error generateSubDirectoryReport(SubFileReports &&SubFiles,128SubDirReports &&SubDirs,129FileCoverageSummary &&SubTotals) = 0;130131private:132Error prepareSubDirectoryReports(const ArrayRef<StringRef> &Files,133FileCoverageSummary *Totals);134};135136} // end namespace llvm137138#endif // LLVM_COV_COVERAGEREPORT_H139140141