[llvm-pdbdump] Colorize output.
[oota-llvm.git] / tools / llvm-pdbdump / LinePrinter.h
1 //===- LinePrinter.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_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
11 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
12
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/Support/raw_ostream.h"
15
16 namespace llvm {
17
18 class LinePrinter {
19   friend class WithColor;
20
21 public:
22   LinePrinter(int Indent, raw_ostream &Stream);
23
24   void Indent();
25   void Unindent();
26
27   void NewLine();
28
29   raw_ostream &getStream() { return OS; }
30
31 private:
32   raw_ostream &OS;
33   int IndentSpaces;
34   int CurrentIndent;
35 };
36
37 template <class T>
38 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
39   Printer.getStream() << Item;
40   return Printer.getStream();
41 }
42
43 enum class PDB_ColorItem {
44   None,
45   Address,
46   Type,
47   Keyword,
48   Offset,
49   Identifier,
50   Path,
51   SectionHeader,
52   LiteralValue,
53 };
54
55 class WithColor {
56 public:
57   WithColor(LinePrinter &P, PDB_ColorItem C);
58   ~WithColor();
59
60   raw_ostream &get() { return OS; }
61
62 private:
63   void translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
64                       bool &Bold) const;
65   raw_ostream &OS;
66 };
67 }
68
69 #endif