Coverage Report

Created: 2018-06-18 20:01

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/CoverageExporterJson.h
Line
Count
Source
1
//===- CoverageExporterJson.h - Code coverage JSON exporter ---------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This class implements a code coverage exporter for JSON format.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_COV_COVERAGEEXPORTERJSON_H
15
#define LLVM_COV_COVERAGEEXPORTERJSON_H
16
17
#include "CoverageExporter.h"
18
#include <stack>
19
20
namespace llvm {
21
22
class CoverageExporterJson : public CoverageExporter {
23
  /// States that the JSON rendering machine can be in.
24
  enum JsonState { None, NonEmptyElement, EmptyElement };
25
26
  /// Tracks state of the JSON output.
27
  std::stack<JsonState> State;
28
29
  /// Emit a serialized scalar.
30
  void emitSerialized(const int64_t Value);
31
32
  /// Emit a serialized string.
33
  void emitSerialized(const std::string &Value);
34
35
  /// Emit a comma if there is a previous element to delimit.
36
  void emitComma();
37
38
  /// Emit a starting dictionary/object character.
39
  void emitDictStart();
40
41
  /// Emit a dictionary/object key but no value.
42
  void emitDictKey(const std::string &Key);
43
44
  /// Emit a dictionary/object key/value pair.
45
  template <typename V>
46
651
  void emitDictElement(const std::string &Key, const V &Value) {
47
651
    emitComma();
48
651
    emitSerialized(Key);
49
651
    OS << ":";
50
651
    emitSerialized(Value);
51
651
  }
void llvm::CoverageExporterJson::emitDictElement<char [6]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [6])
Line
Count
Source
46
13
  void emitDictElement(const std::string &Key, const V &Value) {
47
13
    emitComma();
48
13
    emitSerialized(Key);
49
13
    OS << ":";
50
13
    emitSerialized(Value);
51
13
  }
void llvm::CoverageExporterJson::emitDictElement<char [26]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [26])
Line
Count
Source
46
13
  void emitDictElement(const std::string &Key, const V &Value) {
47
13
    emitComma();
48
13
    emitSerialized(Key);
49
13
    OS << ":";
50
13
    emitSerialized(Value);
51
13
  }
void llvm::CoverageExporterJson::emitDictElement<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
46
66
  void emitDictElement(const std::string &Key, const V &Value) {
47
66
    emitComma();
48
66
    emitSerialized(Key);
49
66
    OS << ":";
50
66
    emitSerialized(Value);
51
66
  }
void llvm::CoverageExporterJson::emitDictElement<unsigned long long>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long const&)
Line
Count
Source
46
39
  void emitDictElement(const std::string &Key, const V &Value) {
47
39
    emitComma();
48
39
    emitSerialized(Key);
49
39
    OS << ":";
50
39
    emitSerialized(Value);
51
39
  }
void llvm::CoverageExporterJson::emitDictElement<unsigned long>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long const&)
Line
Count
Source
46
360
  void emitDictElement(const std::string &Key, const V &Value) {
47
360
    emitComma();
48
360
    emitSerialized(Key);
49
360
    OS << ":";
50
360
    emitSerialized(Value);
51
360
  }
void llvm::CoverageExporterJson::emitDictElement<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double const&)
Line
Count
Source
46
160
  void emitDictElement(const std::string &Key, const V &Value) {
47
160
    emitComma();
48
160
    emitSerialized(Key);
49
160
    OS << ":";
50
160
    emitSerialized(Value);
51
160
  }
52
53
  /// Emit a closing dictionary/object character.
54
  void emitDictEnd();
55
56
  /// Emit a starting array character.
57
  void emitArrayStart();
58
59
  /// Emit an array element.
60
3.10k
  template <typename V> void emitArrayElement(const V &Value) {
61
3.10k
    emitComma();
62
3.10k
    emitSerialized(Value);
63
3.10k
  }
void llvm::CoverageExporterJson::emitArrayElement<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
60
46
  template <typename V> void emitArrayElement(const V &Value) {
61
46
    emitComma();
62
46
    emitSerialized(Value);
63
46
  }
void llvm::CoverageExporterJson::emitArrayElement<unsigned int>(unsigned int const&)
Line
Count
Source
60
1.84k
  template <typename V> void emitArrayElement(const V &Value) {
61
1.84k
    emitComma();
62
1.84k
    emitSerialized(Value);
63
1.84k
  }
void llvm::CoverageExporterJson::emitArrayElement<unsigned long long>(unsigned long long const&)
Line
Count
Source
60
478
  template <typename V> void emitArrayElement(const V &Value) {
61
478
    emitComma();
62
478
    emitSerialized(Value);
63
478
  }
void llvm::CoverageExporterJson::emitArrayElement<bool>(bool const&)
Line
Count
Source
60
512
  template <typename V> void emitArrayElement(const V &Value) {
61
512
    emitComma();
62
512
    emitSerialized(Value);
63
512
  }
void llvm::CoverageExporterJson::emitArrayElement<llvm::coverage::CounterMappingRegion::RegionKind>(llvm::coverage::CounterMappingRegion::RegionKind const&)
Line
Count
Source
60
222
  template <typename V> void emitArrayElement(const V &Value) {
61
222
    emitComma();
62
222
    emitSerialized(Value);
63
222
  }
64
65
  /// emit a closing array character.
66
  void emitArrayEnd();
67
68
  /// Render an array of all the given functions.
69
  void renderFunctions(
70
      const iterator_range<coverage::FunctionRecordIterator> &Functions);
71
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);
75
76
  /// Render a single file.
77
  void renderFile(const std::string &Filename,
78
                  const FileCoverageSummary &FileReport);
79
80
  /// Render summary for a single file.
81
  void renderFileCoverage(const coverage::CoverageData &FileCoverage,
82
                          const FileCoverageSummary &FileReport);
83
84
  /// Render a CoverageSegment.
85
  void renderSegment(const coverage::CoverageSegment &Segment);
86
87
  /// Render an ExpansionRecord.
88
  void renderExpansion(const coverage::ExpansionRecord &Expansion);
89
90
  /// Render a list of CountedRegions.
91
  void renderRegions(ArrayRef<coverage::CountedRegion> Regions);
92
93
  /// Render a single CountedRegion.
94
  void renderRegion(const coverage::CountedRegion &Region);
95
96
  /// Render a FileCoverageSummary.
97
  void renderSummary(const FileCoverageSummary &Summary);
98
99
public:
100
  CoverageExporterJson(const coverage::CoverageMapping &CoverageMapping,
101
                       const CoverageViewOptions &Options, raw_ostream &OS);
102
103
  /// Render the CoverageMapping object.
104
  void renderRoot(const CoverageFilters &IgnoreFilenameFilters) override;
105
106
  /// Render the CoverageMapping object for specified source files.
107
  void renderRoot(const std::vector<std::string> &SourceFiles) override;
108
};
109
110
} // end namespace llvm
111
112
#endif // LLVM_COV_COVERAGEEXPORTERJSON_H