Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/RenderingSupport.h
Line
Count
Source (jump to first uncovered line)
1
//===- RenderingSupport.h - output stream rendering support functions  ----===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_COV_RENDERINGSUPPORT_H
10
#define LLVM_COV_RENDERINGSUPPORT_H
11
12
#include "llvm/Support/raw_ostream.h"
13
#include <utility>
14
15
namespace llvm {
16
17
/// A helper class that resets the output stream's color if needed
18
/// when destroyed.
19
class ColoredRawOstream {
20
  ColoredRawOstream(const ColoredRawOstream &OS) = delete;
21
22
public:
23
  raw_ostream &OS;
24
  bool IsColorUsed;
25
26
  ColoredRawOstream(raw_ostream &OS, bool IsColorUsed)
27
4.82k
      : OS(OS), IsColorUsed(IsColorUsed) {}
28
29
  ColoredRawOstream(ColoredRawOstream &&Other)
30
0
      : OS(Other.OS), IsColorUsed(Other.IsColorUsed) {
31
0
    // Reset the other IsColorUsed so that the other object won't reset the
32
0
    // color when destroyed.
33
0
    Other.IsColorUsed = false;
34
0
  }
35
36
4.82k
  ~ColoredRawOstream() {
37
4.82k
    if (IsColorUsed)
38
8
      OS.resetColor();
39
4.82k
  }
40
};
41
42
template <typename T>
43
4.82k
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
4.82k
  return OS.OS << std::forward<T>(Value);
45
4.82k
}
llvm::raw_ostream& llvm::operator<<<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(llvm::ColoredRawOstream const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
43
129
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
129
  return OS.OS << std::forward<T>(Value);
45
129
}
llvm::raw_ostream& llvm::operator<<<llvm::format_object<unsigned long, unsigned int> >(llvm::ColoredRawOstream const&, llvm::format_object<unsigned long, unsigned int>&&)
Line
Count
Source
43
256
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
256
  return OS.OS << std::forward<T>(Value);
45
256
}
llvm::raw_ostream& llvm::operator<<<llvm::format_object<unsigned long, double> >(llvm::ColoredRawOstream const&, llvm::format_object<unsigned long, double>&&)
Line
Count
Source
43
366
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
366
  return OS.OS << std::forward<T>(Value);
45
366
}
llvm::raw_ostream& llvm::operator<<<char const (&) [2]>(llvm::ColoredRawOstream const&, char const (&&&) [2])
Line
Count
Source
43
13
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
13
  return OS.OS << std::forward<T>(Value);
45
13
}
llvm::raw_ostream& llvm::operator<<<llvm::StringRef>(llvm::ColoredRawOstream const&, llvm::StringRef&&)
Line
Count
Source
43
3.05k
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
3.05k
  return OS.OS << std::forward<T>(Value);
45
3.05k
}
llvm::raw_ostream& llvm::operator<<<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&>(llvm::ColoredRawOstream const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&&)
Line
Count
Source
43
950
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
950
  return OS.OS << std::forward<T>(Value);
45
950
}
llvm::raw_ostream& llvm::operator<<<char const (&) [27]>(llvm::ColoredRawOstream const&, char const (&&&) [27])
Line
Count
Source
43
6
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
6
  return OS.OS << std::forward<T>(Value);
45
6
}
llvm::raw_ostream& llvm::operator<<<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(llvm::ColoredRawOstream const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&)
Line
Count
Source
43
25
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
25
  return OS.OS << std::forward<T>(Value);
45
25
}
llvm::raw_ostream& llvm::operator<<<llvm::StringRef&>(llvm::ColoredRawOstream const&, llvm::StringRef&&&)
Line
Count
Source
43
25
inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
44
25
  return OS.OS << std::forward<T>(Value);
45
25
}
46
47
/// Change the color of the output stream if the `IsColorUsed` flag
48
/// is true. Returns an object that resets the color when destroyed.
49
inline ColoredRawOstream colored_ostream(raw_ostream &OS,
50
                                         raw_ostream::Colors Color,
51
                                         bool IsColorUsed = true,
52
4.82k
                                         bool Bold = false, bool BG = false) {
53
4.82k
  if (IsColorUsed)
54
8
    OS.changeColor(Color, Bold, BG);
55
4.82k
  return ColoredRawOstream(OS, IsColorUsed);
56
4.82k
}
57
58
} // namespace llvm
59
60
#endif // LLVM_COV_RENDERINGSUPPORT_H