OSDN Git Service

[Support] Add convenience functions to WithColor. NFC.
[android-x86/external-llvm.git] / include / llvm / Support / WithColor.h
1 //===- WithColor.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 #ifndef LLVM_SUPPORT_WITHCOLOR_H
11 #define LLVM_SUPPORT_WITHCOLOR_H
12
13 namespace llvm {
14
15 class raw_ostream;
16
17 // Symbolic names for various syntax elements.
18 enum class HighlightColor {
19   Address,
20   String,
21   Tag,
22   Attribute,
23   Enumerator,
24   Macro,
25   Error,
26   Warning,
27   Note
28 };
29
30 /// An RAII object that temporarily switches an output stream to a specific
31 /// color.
32 class WithColor {
33   raw_ostream &OS;
34   /// Determine whether colors should be displayed.
35   bool colorsEnabled(raw_ostream &OS);
36
37 public:
38   /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
39   WithColor(raw_ostream &OS, HighlightColor S);
40   ~WithColor();
41
42   raw_ostream &get() { return OS; }
43   operator raw_ostream &() { return OS; }
44
45   /// Convenience method for printing "error: " to stderr.
46   static raw_ostream &error();
47
48   /// Convenience method for printing "warning: " to stderr.
49   static raw_ostream &warning();
50
51   /// Convenience method for printing "note: " to stderr.
52   static raw_ostream &note();
53 };
54
55 } // end namespace llvm
56
57 #endif // LLVM_LIB_DEBUGINFO_WITHCOLOR_H