blob: 7aa93599a20b75be1d0f86b9c868421af969cadb [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
Zachary Turnerf5abda22015-03-01 06:49:49 +000012#include "llvm/Support/Regex.h"
13
Zachary Turner2d11c202015-02-27 09:15:59 +000014#include <algorithm>
15
16using namespace llvm;
17
18LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
Zachary Turner94118282015-02-27 09:53:55 +000019 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {}
Zachary Turner2d11c202015-02-27 09:15:59 +000020
21void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
22
23void LinePrinter::Unindent() {
24 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
25}
26
27void LinePrinter::NewLine() {
28 OS << "\n";
29 OS.indent(CurrentIndent);
30}
31
Zachary Turnerf5abda22015-03-01 06:49:49 +000032bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
33 if (TypeName.empty())
34 return false;
35
36 for (auto &Expr : TypeFilters) {
37 if (Expr.match(TypeName))
38 return true;
39 }
40 return false;
41}
42
43bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
44 if (SymbolName.empty())
45 return false;
46
47 for (auto &Expr : SymbolFilters) {
48 if (Expr.match(SymbolName))
49 return true;
50 }
51 return false;
52}
53
54bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
55 if (CompilandName.empty())
56 return false;
57
58 for (auto &Expr : CompilandFilters) {
59 if (Expr.match(CompilandName))
60 return true;
61 }
62 return false;
63}
64
Zachary Turner2d11c202015-02-27 09:15:59 +000065WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
66 if (C == PDB_ColorItem::None)
67 OS.resetColor();
68 else {
69 raw_ostream::Colors Color;
70 bool Bold;
71 translateColor(C, Color, Bold);
72 OS.changeColor(Color, Bold);
73 }
74}
75
76WithColor::~WithColor() { OS.resetColor(); }
77
78void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
79 bool &Bold) const {
80 switch (C) {
81 case PDB_ColorItem::Address:
82 Color = raw_ostream::YELLOW;
83 Bold = true;
84 return;
85 case PDB_ColorItem::Keyword:
86 Color = raw_ostream::MAGENTA;
87 Bold = true;
88 return;
89 case PDB_ColorItem::Offset:
90 Color = raw_ostream::YELLOW;
91 Bold = false;
92 return;
93 case PDB_ColorItem::Type:
94 Color = raw_ostream::CYAN;
95 Bold = true;
96 return;
97 case PDB_ColorItem::Identifier:
98 Color = raw_ostream::CYAN;
99 Bold = false;
100 return;
101 case PDB_ColorItem::Path:
102 Color = raw_ostream::CYAN;
103 Bold = false;
104 return;
105 case PDB_ColorItem::SectionHeader:
106 Color = raw_ostream::RED;
107 Bold = true;
108 return;
109 case PDB_ColorItem::LiteralValue:
110 Color = raw_ostream::GREEN;
111 Bold = true;
112 default:
113 return;
114 }
115}