]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_report_decorator.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_report_decorator.h
1 //===-- sanitizer_report_decorator.h ----------------------------*- C++ -*-===//
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 // Tags to decorate the sanitizer reports.
11 // Currently supported tags:
12 //   * None.
13 //   * ANSI color sequences.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef SANITIZER_REPORT_DECORATOR_H
18 #define SANITIZER_REPORT_DECORATOR_H
19
20 #include "sanitizer_common.h"
21
22 namespace __sanitizer {
23 class SanitizerCommonDecorator {
24   // FIXME: This is not portable. It assumes the special strings are printed to
25   // stdout, which is not the case on Windows (see SetConsoleTextAttribute()).
26  public:
27   SanitizerCommonDecorator() : ansi_(ColorizeReports()) {}
28   const char *Bold() const { return ansi_ ? "\033[1m" : ""; }
29   const char *Default() const { return ansi_ ? "\033[1m\033[0m"  : ""; }
30   const char *Warning() const { return Red(); }
31   const char *Error() const { return Red(); }
32   const char *MemoryByte() const { return Magenta(); }
33
34  protected:
35   const char *Black()   const { return ansi_ ? "\033[1m\033[30m" : ""; }
36   const char *Red()     const { return ansi_ ? "\033[1m\033[31m" : ""; }
37   const char *Green()   const { return ansi_ ? "\033[1m\033[32m" : ""; }
38   const char *Yellow()  const { return ansi_ ? "\033[1m\033[33m" : ""; }
39   const char *Blue()    const { return ansi_ ? "\033[1m\033[34m" : ""; }
40   const char *Magenta() const { return ansi_ ? "\033[1m\033[35m" : ""; }
41   const char *Cyan()    const { return ansi_ ? "\033[1m\033[36m" : ""; }
42   const char *White()   const { return ansi_ ? "\033[1m\033[37m" : ""; }
43  private:
44   bool ansi_;
45 };
46
47 }  // namespace __sanitizer
48
49 #endif  // SANITIZER_REPORT_DECORATOR_H