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