1 //===- CoverageExporterJson.h - Code coverage JSON exporter ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements a code coverage exporter for JSON format.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_COV_COVERAGEEXPORTERJSON_H
15 #define LLVM_COV_COVERAGEEXPORTERJSON_H
17 #include "CoverageExporter.h"
22 class CoverageExporterJson : public CoverageExporter {
23 /// States that the JSON rendering machine can be in.
24 enum JsonState { None, NonEmptyElement, EmptyElement };
26 /// Tracks state of the JSON output.
27 std::stack<JsonState> State;
29 /// Emit a serialized scalar.
30 void emitSerialized(const int64_t Value);
32 /// Emit a serialized string.
33 void emitSerialized(const std::string &Value);
35 /// Emit a comma if there is a previous element to delimit.
38 /// Emit a starting dictionary/object character.
41 /// Emit a dictionary/object key but no value.
42 void emitDictKey(const std::string &Key);
44 /// Emit a dictionary/object key/value pair.
46 void emitDictElement(const std::string &Key, const V &Value) {
50 emitSerialized(Value);
53 /// Emit a closing dictionary/object character.
56 /// Emit a starting array character.
57 void emitArrayStart();
59 /// Emit an array element.
60 template <typename V> void emitArrayElement(const V &Value) {
62 emitSerialized(Value);
65 /// emit a closing array character.
68 /// Render an array of all the given functions.
70 const iterator_range<coverage::FunctionRecordIterator> &Functions);
72 /// Render an array of all the source files, also pass back a Summary.
73 void renderFiles(ArrayRef<std::string> SourceFiles,
74 ArrayRef<FileCoverageSummary> FileReports);
76 /// Render a single file.
77 void renderFile(const std::string &Filename,
78 const FileCoverageSummary &FileReport);
80 /// Render summary for a single file.
81 void renderFileCoverage(const coverage::CoverageData &FileCoverage,
82 const FileCoverageSummary &FileReport);
84 /// Render a CoverageSegment.
85 void renderSegment(const coverage::CoverageSegment &Segment);
87 /// Render an ExpansionRecord.
88 void renderExpansion(const coverage::ExpansionRecord &Expansion);
90 /// Render a list of CountedRegions.
91 void renderRegions(ArrayRef<coverage::CountedRegion> Regions);
93 /// Render a single CountedRegion.
94 void renderRegion(const coverage::CountedRegion &Region);
96 /// Render a FileCoverageSummary.
97 void renderSummary(const FileCoverageSummary &Summary);
100 CoverageExporterJson(const coverage::CoverageMapping &CoverageMapping,
101 const CoverageViewOptions &Options, raw_ostream &OS);
103 /// Render the CoverageMapping object.
104 void renderRoot(const CoverageFilters &IgnoreFilenameFilters) override;
106 /// Render the CoverageMapping object for specified source files.
107 void renderRoot(const std::vector<std::string> &SourceFiles) override;
110 } // end namespace llvm
112 #endif // LLVM_COV_COVERAGEEXPORTERJSON_H