Merging r259236:
[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   void Indent();
29   void Unindent();
30   void NewLine();
31
32   raw_ostream &getStream() { return OS; }
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>
41   void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
42     List.clear();
43     for (; Begin != End; ++Begin)
44       List.emplace_back(StringRef(*Begin));
45   }
46
47   raw_ostream &OS;
48   int IndentSpaces;
49   int CurrentIndent;
50
51   std::list<Regex> ExcludeCompilandFilters;
52   std::list<Regex> ExcludeTypeFilters;
53   std::list<Regex> ExcludeSymbolFilters;
54
55   std::list<Regex> IncludeCompilandFilters;
56   std::list<Regex> IncludeTypeFilters;
57   std::list<Regex> IncludeSymbolFilters;
58 };
59
60 template <class T>
61 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
62   Printer.getStream() << Item;
63   return Printer.getStream();
64 }
65
66 enum class PDB_ColorItem {
67   None,
68   Address,
69   Type,
70   Keyword,
71   Offset,
72   Identifier,
73   Path,
74   SectionHeader,
75   LiteralValue,
76   Register,
77 };
78
79 class WithColor {
80 public:
81   WithColor(LinePrinter &P, PDB_ColorItem C);
82   ~WithColor();
83
84   raw_ostream &get() { return OS; }
85
86 private:
87   void applyColor(PDB_ColorItem C);
88   raw_ostream &OS;
89 };
90 }
91
92 #endif