Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 1 | //===- 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 Turner | f5abda2 | 2015-03-01 06:49:49 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Regex.h" |
| 13 | |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 14 | #include <algorithm> |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) |
Zachary Turner | 9411828 | 2015-02-27 09:53:55 +0000 | [diff] [blame] | 19 | : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {} |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 20 | |
| 21 | void LinePrinter::Indent() { CurrentIndent += IndentSpaces; } |
| 22 | |
| 23 | void LinePrinter::Unindent() { |
| 24 | CurrentIndent = std::max(0, CurrentIndent - IndentSpaces); |
| 25 | } |
| 26 | |
| 27 | void LinePrinter::NewLine() { |
| 28 | OS << "\n"; |
| 29 | OS.indent(CurrentIndent); |
| 30 | } |
| 31 | |
Zachary Turner | f5abda2 | 2015-03-01 06:49:49 +0000 | [diff] [blame] | 32 | bool 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 | |
| 43 | bool 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 | |
| 54 | bool 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 Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 65 | WithColor::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 | |
| 76 | WithColor::~WithColor() { OS.resetColor(); } |
| 77 | |
| 78 | void 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 | } |