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 22 class LinePrinter { 23 friend class WithColor; 24 25 public: 26 LinePrinter(int Indent, raw_ostream &Stream); 27 28 void Indent(); 29 void Unindent(); 30 void NewLine(); 31 getStream()32 raw_ostream &getStream() { return OS; } getIndentLevel()33 int getIndentLevel() const { return CurrentIndent; } 34 35 bool IsTypeExcluded(llvm::StringRef TypeName); 36 bool IsSymbolExcluded(llvm::StringRef SymbolName); 37 bool IsCompilandExcluded(llvm::StringRef CompilandName); 38 39 private: 40 template <typename Iter> SetFilters(std::list<Regex> & List,Iter Begin,Iter End)41 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) { 42 List.clear(); 43 for (; Begin != End; ++Begin) 44 List.push_back(StringRef(*Begin)); 45 } 46 47 raw_ostream &OS; 48 int IndentSpaces; 49 int CurrentIndent; 50 51 std::list<Regex> CompilandFilters; 52 std::list<Regex> TypeFilters; 53 std::list<Regex> SymbolFilters; 54 }; 55 56 template <class T> 57 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) { 58 Printer.getStream() << Item; 59 return Printer.getStream(); 60 } 61 62 enum class PDB_ColorItem { 63 None, 64 Address, 65 Type, 66 Keyword, 67 Offset, 68 Identifier, 69 Path, 70 SectionHeader, 71 LiteralValue, 72 Register, 73 }; 74 75 class WithColor { 76 public: 77 WithColor(LinePrinter &P, PDB_ColorItem C); 78 ~WithColor(); 79 get()80 raw_ostream &get() { return OS; } 81 82 private: 83 void translateColor(PDB_ColorItem C, raw_ostream::Colors &Color, 84 bool &Bold) const; 85 raw_ostream &OS; 86 }; 87 } 88 89 #endif 90