blob: 09ba329ad0a7172e0c3d9130866348dc0c0a909f [file] [log] [blame]
Zachary Turner2d11c202015-02-27 09:15:59 +00001//===- LinePrinter.cpp ------------------------------------------*- 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#include "LinePrinter.h"
11
12#include <algorithm>
13
14using namespace llvm;
15
16LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
Zachary Turner94118282015-02-27 09:53:55 +000017 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {}
Zachary Turner2d11c202015-02-27 09:15:59 +000018
19void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
20
21void LinePrinter::Unindent() {
22 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
23}
24
25void LinePrinter::NewLine() {
26 OS << "\n";
27 OS.indent(CurrentIndent);
28}
29
30WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
31 if (C == PDB_ColorItem::None)
32 OS.resetColor();
33 else {
34 raw_ostream::Colors Color;
35 bool Bold;
36 translateColor(C, Color, Bold);
37 OS.changeColor(Color, Bold);
38 }
39}
40
41WithColor::~WithColor() { OS.resetColor(); }
42
43void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
44 bool &Bold) const {
45 switch (C) {
46 case PDB_ColorItem::Address:
47 Color = raw_ostream::YELLOW;
48 Bold = true;
49 return;
50 case PDB_ColorItem::Keyword:
51 Color = raw_ostream::MAGENTA;
52 Bold = true;
53 return;
54 case PDB_ColorItem::Offset:
55 Color = raw_ostream::YELLOW;
56 Bold = false;
57 return;
58 case PDB_ColorItem::Type:
59 Color = raw_ostream::CYAN;
60 Bold = true;
61 return;
62 case PDB_ColorItem::Identifier:
63 Color = raw_ostream::CYAN;
64 Bold = false;
65 return;
66 case PDB_ColorItem::Path:
67 Color = raw_ostream::CYAN;
68 Bold = false;
69 return;
70 case PDB_ColorItem::SectionHeader:
71 Color = raw_ostream::RED;
72 Bold = true;
73 return;
74 case PDB_ColorItem::LiteralValue:
75 Color = raw_ostream::GREEN;
76 Bold = true;
77 default:
78 return;
79 }
80}