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/ADT/STLExtras.h"
15 #include "llvm/Support/Regex.h"
20 bool IsItemExcluded(llvm::StringRef Item,
21 std::list<llvm::Regex> &IncludeFilters,
22 std::list<llvm::Regex> &ExcludeFilters) {
26 auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
28 // Include takes priority over exclude. If the user specified include
29 // filters, and none of them include this item, them item is gone.
30 if (!IncludeFilters.empty() && !any_of(IncludeFilters, match_pred))
33 if (any_of(ExcludeFilters, match_pred))
42 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
43 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
44 SetFilters(ExcludeTypeFilters, opts::ExcludeTypes.begin(),
45 opts::ExcludeTypes.end());
46 SetFilters(ExcludeSymbolFilters, opts::ExcludeSymbols.begin(),
47 opts::ExcludeSymbols.end());
48 SetFilters(ExcludeCompilandFilters, opts::ExcludeCompilands.begin(),
49 opts::ExcludeCompilands.end());
51 SetFilters(IncludeTypeFilters, opts::IncludeTypes.begin(),
52 opts::IncludeTypes.end());
53 SetFilters(IncludeSymbolFilters, opts::IncludeSymbols.begin(),
54 opts::IncludeSymbols.end());
55 SetFilters(IncludeCompilandFilters, opts::IncludeCompilands.begin(),
56 opts::IncludeCompilands.end());
59 void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
61 void LinePrinter::Unindent() {
62 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
65 void LinePrinter::NewLine() {
67 OS.indent(CurrentIndent);
70 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
71 return IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters);
74 bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
75 return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
78 bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
79 return IsItemExcluded(CompilandName, IncludeCompilandFilters,
80 ExcludeCompilandFilters);
83 WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
87 WithColor::~WithColor() { OS.resetColor(); }
89 void WithColor::applyColor(PDB_ColorItem C) {
91 case PDB_ColorItem::None:
94 case PDB_ColorItem::Address:
95 OS.changeColor(raw_ostream::YELLOW, /*bold=*/true);
97 case PDB_ColorItem::Keyword:
98 OS.changeColor(raw_ostream::MAGENTA, true);
100 case PDB_ColorItem::Register:
101 case PDB_ColorItem::Offset:
102 OS.changeColor(raw_ostream::YELLOW, false);
104 case PDB_ColorItem::Type:
105 OS.changeColor(raw_ostream::CYAN, true);
107 case PDB_ColorItem::Identifier:
108 OS.changeColor(raw_ostream::CYAN, false);
110 case PDB_ColorItem::Path:
111 OS.changeColor(raw_ostream::CYAN, false);
113 case PDB_ColorItem::SectionHeader:
114 OS.changeColor(raw_ostream::RED, true);
116 case PDB_ColorItem::LiteralValue:
117 OS.changeColor(raw_ostream::GREEN, true);