Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Support/WithColor.h
Line
Count
Source (jump to first uncovered line)
1
//===- WithColor.h ----------------------------------------------*- C++ -*-===//
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_SUPPORT_WITHCOLOR_H
10
#define LLVM_SUPPORT_WITHCOLOR_H
11
12
#include "llvm/ADT/StringRef.h"
13
#include "llvm/Support/CommandLine.h"
14
15
namespace llvm {
16
17
extern cl::OptionCategory ColorCategory;
18
19
class raw_ostream;
20
21
// Symbolic names for various syntax elements.
22
enum class HighlightColor {
23
  Address,
24
  String,
25
  Tag,
26
  Attribute,
27
  Enumerator,
28
  Macro,
29
  Error,
30
  Warning,
31
  Note,
32
  Remark
33
};
34
35
/// An RAII object that temporarily switches an output stream to a specific
36
/// color.
37
class WithColor {
38
  raw_ostream &OS;
39
  bool DisableColors;
40
41
public:
42
  /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
43
  /// @param OS The output stream
44
  /// @param S Symbolic name for syntax element to color
45
  /// @param DisableColors Whether to ignore color changes regardless of -color
46
  /// and support in OS
47
  WithColor(raw_ostream &OS, HighlightColor S, bool DisableColors = false);
48
  /// To be used like this: WithColor(OS, raw_ostream::Black) << "text";
49
  /// @param OS The output stream
50
  /// @param Color ANSI color to use, the special SAVEDCOLOR can be used to
51
  /// change only the bold attribute, and keep colors untouched
52
  /// @param Bold Bold/brighter text, default false
53
  /// @param BG If true, change the background, default: change foreground
54
  /// @param DisableColors Whether to ignore color changes regardless of -color
55
  /// and support in OS
56
  WithColor(raw_ostream &OS,
57
            raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
58
            bool Bold = false, bool BG = false, bool DisableColors = false)
59
279k
      : OS(OS), DisableColors(DisableColors) {
60
279k
    changeColor(Color, Bold, BG);
61
279k
  }
62
  ~WithColor();
63
64
156k
  raw_ostream &get() { return OS; }
65
0
  operator raw_ostream &() { return OS; }
66
1.20M
  template <typename T> WithColor &operator<<(T &O) {
67
1.20M
    OS << O;
68
1.20M
    return *this;
69
1.20M
  }
llvm::WithColor& llvm::WithColor::operator<<<char const*>(char const*&)
Line
Count
Source
66
220
  template <typename T> WithColor &operator<<(T &O) {
67
220
    OS << O;
68
220
    return *this;
69
220
  }
llvm::WithColor& llvm::WithColor::operator<<<char>(char&)
Line
Count
Source
66
1.20M
  template <typename T> WithColor &operator<<(T &O) {
67
1.20M
    OS << O;
68
1.20M
    return *this;
69
1.20M
  }
llvm::WithColor& llvm::WithColor::operator<<<llvm::StringRef>(llvm::StringRef&)
Line
Count
Source
66
4.56k
  template <typename T> WithColor &operator<<(T &O) {
67
4.56k
    OS << O;
68
4.56k
    return *this;
69
4.56k
  }
70
866k
  template <typename T> WithColor &operator<<(const T &O) {
71
866k
    OS << O;
72
866k
    return *this;
73
866k
  }
llvm::WithColor& llvm::WithColor::operator<<<char [3]>(char const (&) [3])
Line
Count
Source
70
93.1k
  template <typename T> WithColor &operator<<(const T &O) {
71
93.1k
    OS << O;
72
93.1k
    return *this;
73
93.1k
  }
Unexecuted instantiation: llvm::WithColor& llvm::WithColor::operator<<<char [8]>(char const (&) [8])
llvm::WithColor& llvm::WithColor::operator<<<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
70
186k
  template <typename T> WithColor &operator<<(const T &O) {
71
186k
    OS << O;
72
186k
    return *this;
73
186k
  }
llvm::WithColor& llvm::WithColor::operator<<<char>(char const&)
Line
Count
Source
70
371k
  template <typename T> WithColor &operator<<(const T &O) {
71
371k
    OS << O;
72
371k
    return *this;
73
371k
  }
llvm::WithColor& llvm::WithColor::operator<<<int>(int const&)
Line
Count
Source
70
185k
  template <typename T> WithColor &operator<<(const T &O) {
71
185k
    OS << O;
72
185k
    return *this;
73
185k
  }
llvm::WithColor& llvm::WithColor::operator<<<llvm::formatv_object<std::__1::tuple<llvm::detail::provider_format_adapter<llvm::dwarf::Attribute&> > > >(llvm::formatv_object<std::__1::tuple<llvm::detail::provider_format_adapter<llvm::dwarf::Attribute&> > > const&)
Line
Count
Source
70
29.6k
  template <typename T> WithColor &operator<<(const T &O) {
71
29.6k
    OS << O;
72
29.6k
    return *this;
73
29.6k
  }
74
75
  /// Convenience method for printing "error: " to stderr.
76
  static raw_ostream &error();
77
  /// Convenience method for printing "warning: " to stderr.
78
  static raw_ostream &warning();
79
  /// Convenience method for printing "note: " to stderr.
80
  static raw_ostream &note();
81
  /// Convenience method for printing "remark: " to stderr.
82
  static raw_ostream &remark();
83
84
  /// Convenience method for printing "error: " to the given stream.
85
  static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "",
86
                            bool DisableColors = false);
87
  /// Convenience method for printing "warning: " to the given stream.
88
  static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = "",
89
                              bool DisableColors = false);
90
  /// Convenience method for printing "note: " to the given stream.
91
  static raw_ostream &note(raw_ostream &OS, StringRef Prefix = "",
92
                           bool DisableColors = false);
93
  /// Convenience method for printing "remark: " to the given stream.
94
  static raw_ostream &remark(raw_ostream &OS, StringRef Prefix = "",
95
                             bool DisableColors = false);
96
97
  /// Determine whether colors are displayed.
98
  bool colorsEnabled();
99
100
  /// Change the color of text that will be output from this point forward.
101
  /// @param Color ANSI color to use, the special SAVEDCOLOR can be used to
102
  /// change only the bold attribute, and keep colors untouched
103
  /// @param Bold Bold/brighter text, default false
104
  /// @param BG If true, change the background, default: change foreground
105
  WithColor &changeColor(raw_ostream::Colors Color, bool Bold = false,
106
                         bool BG = false);
107
108
  /// Reset the colors to terminal defaults. Call this when you are done
109
  /// outputting colored text, or before program exit.
110
  WithColor &resetColor();
111
};
112
113
} // end namespace llvm
114
115
#endif // LLVM_LIB_DEBUGINFO_WITHCOLOR_H