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"
19 template <class T, class Pred> bool any_of_range(T &&R, Pred P) {
20 return std::any_of(R.begin(), R.end(), P);
23 bool IsItemExcluded(llvm::StringRef Item,
24 std::list<llvm::Regex> &IncludeFilters,
25 std::list<llvm::Regex> &ExcludeFilters) {
29 auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
31 // Include takes priority over exclude. If the user specified include
32 // filters, and none of them include this item, them item is gone.
33 if (!IncludeFilters.empty() && !any_of_range(IncludeFilters, match_pred))
36 if (any_of_range(ExcludeFilters, match_pred))
45 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
46 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
47 SetFilters(ExcludeTypeFilters, opts::ExcludeTypes.begin(),
48 opts::ExcludeTypes.end());
49 SetFilters(ExcludeSymbolFilters, opts::ExcludeSymbols.begin(),
50 opts::ExcludeSymbols.end());
51 SetFilters(ExcludeCompilandFilters, opts::ExcludeCompilands.begin(),
52 opts::ExcludeCompilands.end());
54 SetFilters(IncludeTypeFilters, opts::IncludeTypes.begin(),
55 opts::IncludeTypes.end());
56 SetFilters(IncludeSymbolFilters, opts::IncludeSymbols.begin(),
57 opts::IncludeSymbols.end());
58 SetFilters(IncludeCompilandFilters, opts::IncludeCompilands.begin(),
59 opts::IncludeCompilands.end());
62 void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
64 void LinePrinter::Unindent() {
65 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
68 void LinePrinter::NewLine() {
70 OS.indent(CurrentIndent);
73 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
74 return IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters);
77 bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
78 return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
81 bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
82 return IsItemExcluded(CompilandName, IncludeCompilandFilters,
83 ExcludeCompilandFilters);
86 WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
87 if (C == PDB_ColorItem::None)
90 raw_ostream::Colors Color;
92 translateColor(C, Color, Bold);
93 OS.changeColor(Color, Bold);
97 WithColor::~WithColor() { OS.resetColor(); }
99 void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
102 case PDB_ColorItem::Address:
103 Color = raw_ostream::YELLOW;
106 case PDB_ColorItem::Keyword:
107 Color = raw_ostream::MAGENTA;
110 case PDB_ColorItem::Register:
111 case PDB_ColorItem::Offset:
112 Color = raw_ostream::YELLOW;
115 case PDB_ColorItem::Type:
116 Color = raw_ostream::CYAN;
119 case PDB_ColorItem::Identifier:
120 Color = raw_ostream::CYAN;
123 case PDB_ColorItem::Path:
124 Color = raw_ostream::CYAN;
127 case PDB_ColorItem::SectionHeader:
128 Color = raw_ostream::RED;
131 case PDB_ColorItem::LiteralValue:
132 Color = raw_ostream::GREEN;