Coverage Report

Created: 2018-01-17 21:32

/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
  /// \brief States that the JSON rendering machine can be in.
24
  enum JsonState { None, NonEmptyElement, EmptyElement };
25
26
  /// \brief Tracks state of the JSON output.
27
  std::stack<JsonState> State;
28
29
  /// \brief Emit a serialized scalar.
30
  void emitSerialized(const int64_t Value);
31
32
  /// \brief Emit a serialized string.
33
  void emitSerialized(const std::string &Value);
34
35
  /// \brief Emit a comma if there is a previous element to delimit.
36
  void emitComma();
37
38
  /// \brief Emit a starting dictionary/object character.
39
  void emitDictStart();
40
41
  /// \brief Emit a dictionary/object key but no value.
42
  void emitDictKey(const std::string &Key);
43
44
  /// \brief Emit a dictionary/object key/value pair.
45
  template <typename V>
46
546
  void emitDictElement(const std::string &Key, const V &Value) {
47
546
    emitComma();
48
546
    emitSerialized(Key);
49
546
    OS << ":";
50
546
    emitSerialized(Value);
51
546
  }
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
10
  void emitDictElement(const std::string &Key, const V &Value) {
47
10
    emitComma();
48
10
    emitSerialized(Key);
49
10
    OS << ":";
50
10
    emitSerialized(Value);
51
10
  }
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
10
  void emitDictElement(const std::string &Key, const V &Value) {
47
10
    emitComma();
48
10
    emitSerialized(Key);
49
10
    OS << ":";
50
10
    emitSerialized(Value);
51
10
  }
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
54
  void emitDictElement(const std::string &Key, const V &Value) {
47
54
    emitComma();
48
54
    emitSerialized(Key);
49
54
    OS << ":";
50
54
    emitSerialized(Value);
51
54
  }
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
30
  void emitDictElement(const std::string &Key, const V &Value) {
47
30
    emitComma();
48
30
    emitSerialized(Key);
49
30
    OS << ":";
50
30
    emitSerialized(Value);
51
30
  }
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
306
  void emitDictElement(const std::string &Key, const V &Value) {
47
306
    emitComma();
48
306
    emitSerialized(Key);
49
306
    OS << ":";
50
306
    emitSerialized(Value);
51
306
  }
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
136
  void emitDictElement(const std::string &Key, const V &Value) {
47
136
    emitComma();
48
136
    emitSerialized(Key);
49
136
    OS << ":";
50
136
    emitSerialized(Value);
51
136
  }
52
53
  /// \brief Emit a closing dictionary/object character.
54
  void emitDictEnd();
55
56
  /// \brief Emit a starting array character.
57
  void emitArrayStart();
58
59
  /// \brief Emit an array element.
60
2.41k
  template <typename V> void emitArrayElement(const V &Value) {
61
2.41k
    emitComma();
62
2.41k
    emitSerialized(Value);
63
2.41k
  }
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
37
  template <typename V> void emitArrayElement(const V &Value) {
61
37
    emitComma();
62
37
    emitSerialized(Value);
63
37
  }
void llvm::CoverageExporterJson::emitArrayElement<unsigned int>(unsigned int const&)
Line
Count
Source
60
1.44k
  template <typename V> void emitArrayElement(const V &Value) {
61
1.44k
    emitComma();
62
1.44k
    emitSerialized(Value);
63
1.44k
  }
void llvm::CoverageExporterJson::emitArrayElement<unsigned long long>(unsigned long long const&)
Line
Count
Source
60
368
  template <typename V> void emitArrayElement(const V &Value) {
61
368
    emitComma();
62
368
    emitSerialized(Value);
63
368
  }
void llvm::CoverageExporterJson::emitArrayElement<bool>(bool const&)
Line
Count
Source
60
380
  template <typename V> void emitArrayElement(const V &Value) {
61
380
    emitComma();
62
380
    emitSerialized(Value);
63
380
  }
void llvm::CoverageExporterJson::emitArrayElement<llvm::coverage::CounterMappingRegion::RegionKind>(llvm::coverage::CounterMappingRegion::RegionKind const&)
Line
Count
Source
60
178
  template <typename V> void emitArrayElement(const V &Value) {
61
178
    emitComma();
62
178
    emitSerialized(Value);
63
178
  }
64
65
  /// \brief emit a closing array character.
66
  void emitArrayEnd();
67
68
  /// \brief Render an array of all the given functions.
69
  void renderFunctions(
70
      const iterator_range<coverage::FunctionRecordIterator> &Functions);
71
72
  /// \brief 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
  /// \brief Render a single file.
77
  void renderFile(const std::string &Filename,
78
                  const FileCoverageSummary &FileReport);
79
80
  /// \brief Render summary for a single file.
81
  void renderFileCoverage(const coverage::CoverageData &FileCoverage,
82
                          const FileCoverageSummary &FileReport);
83
84
  /// \brief Render a CoverageSegment.
85
  void renderSegment(const coverage::CoverageSegment &Segment);
86
87
  /// \brief Render an ExpansionRecord.
88
  void renderExpansion(const coverage::ExpansionRecord &Expansion);
89
90
  /// \brief Render a list of CountedRegions.
91
  void renderRegions(ArrayRef<coverage::CountedRegion> Regions);
92
93
  /// \brief Render a single CountedRegion.
94
  void renderRegion(const coverage::CountedRegion &Region);
95
96
  /// \brief 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
  /// \brief Render the CoverageMapping object.
104
  void renderRoot() override;
105
106
  /// \brief 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