summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/SourceCoverageView.h
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-06-28 16:12:24 +0000
committerVedant Kumar <vsk@apple.com>2016-06-28 16:12:24 +0000
commit9cbad2c2b8ca3a5db8979f8233612a781b8eb7c5 (patch)
treed70144a8d080a512ed50f6c0e7fef8b0dc3a2171 /llvm/tools/llvm-cov/SourceCoverageView.h
parent64d8a029e9657538f7e89b932c0f20248ee0f23c (diff)
downloadbcm5719-llvm-9cbad2c2b8ca3a5db8979f8233612a781b8eb7c5.tar.gz
bcm5719-llvm-9cbad2c2b8ca3a5db8979f8233612a781b8eb7c5.zip
[llvm-cov] Create an index of reports in -output-dir mode
This index lists the reports available in the 'coverage' sub-directory. This will help navigate coverage output from large projects. This commit factors the file creation code out of SourceCoverageView and into CoveragePrinter. llvm-svn: 274029
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.h')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.h75
1 files changed, 49 insertions, 26 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index def5c6ad71d..3244dc8e8bb 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -97,11 +97,59 @@ struct LineCoverageStats {
}
};
+/// \brief A file manager that handles format-aware file creation.
+class CoveragePrinter {
+ const CoverageViewOptions &Opts;
+
+public:
+ struct StreamDestructor {
+ void operator()(raw_ostream *OS) const;
+ };
+
+ using OwnedStream = std::unique_ptr<raw_ostream, StreamDestructor>;
+
+protected:
+ CoveragePrinter(const CoverageViewOptions &Opts) : Opts(Opts) {}
+
+ /// \brief Return `OutputDir/ToplevelDir/Path.Extension`.
+ std::string getOutputPath(StringRef Path, StringRef Extension,
+ bool InToplevel);
+
+ /// \brief If directory output is enabled, create a file in that directory
+ /// at the path given by getOutputPath(). Otherwise, return stdout.
+ Expected<OwnedStream> createOutputStream(StringRef Path, StringRef Extension,
+ bool InToplevel);
+
+ /// \brief Return the sub-directory name for file coverage reports.
+ static StringRef getCoverageDir() { return "coverage"; }
+
+public:
+ static std::unique_ptr<CoveragePrinter>
+ create(const CoverageViewOptions &Opts);
+
+ virtual ~CoveragePrinter() {}
+
+ /// @name File Creation Interface
+ /// @{
+
+ /// \brief Create a file to print a coverage view into.
+ virtual Expected<OwnedStream> createViewFile(StringRef Path,
+ bool InToplevel) = 0;
+
+ /// \brief Close a file which has been used to print a coverage view.
+ virtual void closeViewFile(OwnedStream OS) = 0;
+
+ /// \brief Create an index which lists reports for the given source files.
+ virtual Error createIndexFile(ArrayRef<StringRef> SourceFiles) = 0;
+
+ /// @}
+};
+
/// \brief A code coverage view of a source file or function.
///
/// A source coverage view and its nested sub-views form a file-oriented
/// representation of code coverage data. This view can be printed out by a
-/// renderer which implements both the File Creation and Rendering interfaces.
+/// renderer which implements the Rendering Interface.
class SourceCoverageView {
/// A function or file name.
StringRef SourceName;
@@ -122,25 +170,6 @@ class SourceCoverageView {
/// on display.
std::vector<InstantiationView> InstantiationSubViews;
-public:
- struct StreamDestructor {
- void operator()(raw_ostream *OS) const;
- };
-
- using OwnedStream = std::unique_ptr<raw_ostream, StreamDestructor>;
-
- /// @name File Creation Interface
- /// @{
-
- /// \brief Create a file to print a coverage view into.
- virtual Expected<OwnedStream> createOutputFile(StringRef Path,
- bool InToplevel) = 0;
-
- /// \brief Close a file which has been used to print a coverage view.
- virtual void closeOutputFile(OwnedStream OS) = 0;
-
- /// @}
-
protected:
struct LineRef {
StringRef Line;
@@ -202,12 +231,6 @@ protected:
/// digits.
static std::string formatCount(uint64_t N);
- /// \brief If directory output is enabled, create a file with \p Path as the
- /// suffix. Otherwise, return stdout.
- static Expected<OwnedStream>
- createOutputStream(const CoverageViewOptions &Opts, StringRef Path,
- StringRef Extension, bool InToplevel);
-
SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
const CoverageViewOptions &Options,
coverage::CoverageData &&CoverageInfo)
OpenPOWER on IntegriCloud