1 //===- LinePrinter.h ------------------------------------------ *- 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 #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H 11 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H 12 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/ADT/Twine.h" 15 #include "llvm/Support/raw_ostream.h" 16 #include "llvm/Support/Regex.h" 17 18 #include <list> 19 20 namespace llvm { 21 namespace pdb { 22 23 class LinePrinter { 24 friend class WithColor; 25 26 public: 27 LinePrinter(int Indent, raw_ostream &Stream); 28 29 void Indent(); 30 void Unindent(); 31 void NewLine(); 32 getStream()33 raw_ostream &getStream() { return OS; } getIndentLevel()34 int getIndentLevel() const { return CurrentIndent; } 35 36 bool IsTypeExcluded(llvm::StringRef TypeName); 37 bool IsSymbolExcluded(llvm::StringRef SymbolName); 38 bool IsCompilandExcluded(llvm::StringRef CompilandName); 39 40 private: 41 template <typename Iter> SetFilters(std::list<Regex> & List,Iter Begin,Iter End)42 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) { 43 List.clear(); 44 for (; Begin != End; ++Begin) 45 List.emplace_back(StringRef(*Begin)); 46 } 47 48 raw_ostream &OS; 49 int IndentSpaces; 50 int CurrentIndent; 51 52 std::list<Regex> ExcludeCompilandFilters; 53 std::list<Regex> ExcludeTypeFilters; 54 std::list<Regex> ExcludeSymbolFilters; 55 56 std::list<Regex> IncludeCompilandFilters; 57 std::list<Regex> IncludeTypeFilters; 58 std::list<Regex> IncludeSymbolFilters; 59 }; 60 61 template <class T> 62 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) { 63 Printer.getStream() << Item; 64 return Printer.getStream(); 65 } 66 67 enum class PDB_ColorItem { 68 None, 69 Address, 70 Type, 71 Keyword, 72 Offset, 73 Identifier, 74 Path, 75 SectionHeader, 76 LiteralValue, 77 Register, 78 }; 79 80 class WithColor { 81 public: 82 WithColor(LinePrinter &P, PDB_ColorItem C); 83 ~WithColor(); 84 get()85 raw_ostream &get() { return OS; } 86 87 private: 88 void applyColor(PDB_ColorItem C); 89 raw_ostream &OS; 90 }; 91 } 92 } 93 94 #endif 95