1 //===- LinePrinter.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "LinePrinter.h"
12 #include "llvm-pdbdump.h"
14 #include "llvm/Support/Regex.h"
20 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
21 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
22 SetFilters(TypeFilters, opts::ExcludeTypes.begin(), opts::ExcludeTypes.end());
23 SetFilters(SymbolFilters, opts::ExcludeSymbols.begin(),
24 opts::ExcludeSymbols.end());
25 SetFilters(CompilandFilters, opts::ExcludeCompilands.begin(),
26 opts::ExcludeCompilands.end());
29 void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
31 void LinePrinter::Unindent() {
32 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
35 void LinePrinter::NewLine() {
37 OS.indent(CurrentIndent);
40 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
44 for (auto &Expr : TypeFilters) {
45 if (Expr.match(TypeName))
51 bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
52 if (SymbolName.empty())
55 for (auto &Expr : SymbolFilters) {
56 if (Expr.match(SymbolName))
62 bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
63 if (CompilandName.empty())
66 for (auto &Expr : CompilandFilters) {
67 if (Expr.match(CompilandName))
73 WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
74 if (C == PDB_ColorItem::None)
77 raw_ostream::Colors Color;
79 translateColor(C, Color, Bold);
80 OS.changeColor(Color, Bold);
84 WithColor::~WithColor() { OS.resetColor(); }
86 void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
89 case PDB_ColorItem::Address:
90 Color = raw_ostream::YELLOW;
93 case PDB_ColorItem::Keyword:
94 Color = raw_ostream::MAGENTA;
97 case PDB_ColorItem::Register:
98 case PDB_ColorItem::Offset:
99 Color = raw_ostream::YELLOW;
102 case PDB_ColorItem::Type:
103 Color = raw_ostream::CYAN;
106 case PDB_ColorItem::Identifier:
107 Color = raw_ostream::CYAN;
110 case PDB_ColorItem::Path:
111 Color = raw_ostream::CYAN;
114 case PDB_ColorItem::SectionHeader:
115 Color = raw_ostream::RED;
118 case PDB_ColorItem::LiteralValue:
119 Color = raw_ostream::GREEN;