]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Support/WithColor.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / 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 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/CommandLine.h"
15
16 namespace llvm {
17
18 extern cl::OptionCategory ColorCategory;
19
20 class raw_ostream;
21
22 // Symbolic names for various syntax elements.
23 enum class HighlightColor {
24   Address,
25   String,
26   Tag,
27   Attribute,
28   Enumerator,
29   Macro,
30   Error,
31   Warning,
32   Note
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   /// Determine whether colors should be displayed.
40   bool colorsEnabled(raw_ostream &OS);
41
42 public:
43   /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
44   WithColor(raw_ostream &OS, HighlightColor S);
45   ~WithColor();
46
47   raw_ostream &get() { return OS; }
48   operator raw_ostream &() { return OS; }
49
50   /// Convenience method for printing "error: " to stderr.
51   static raw_ostream &error();
52   /// Convenience method for printing "warning: " to stderr.
53   static raw_ostream &warning();
54   /// Convenience method for printing "note: " to stderr.
55   static raw_ostream &note();
56
57   /// Convenience method for printing "error: " to the given stream.
58   static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "");
59   /// Convenience method for printing "warning: " to the given stream.
60   static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = "");
61   /// Convenience method for printing "note: " to the given stream.
62   static raw_ostream &note(raw_ostream &OS, StringRef Prefix = "");
63 };
64
65 } // end namespace llvm
66
67 #endif // LLVM_LIB_DEBUGINFO_WITHCOLOR_H