blob: 87c51e34f444e67a44324fe2fc9b51dddde408b1 [file] [log] [blame]
Zachary Turner2d11c202015-02-27 09:15:59 +00001//===- 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
Zachary Turner98162462015-03-01 06:59:57 +000013#include "llvm/ADT/StringRef.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000014#include "llvm/ADT/Twine.h"
15#include "llvm/Support/raw_ostream.h"
Zachary Turnerf5abda22015-03-01 06:49:49 +000016#include "llvm/Support/Regex.h"
17
18#include <list>
Zachary Turner2d11c202015-02-27 09:15:59 +000019
20namespace llvm {
Zachary Turnerec28fc32016-05-04 20:32:13 +000021namespace pdb {
Zachary Turner2d11c202015-02-27 09:15:59 +000022
23class LinePrinter {
24 friend class WithColor;
25
26public:
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000027 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
Zachary Turner2d11c202015-02-27 09:15:59 +000028
29 void Indent();
30 void Unindent();
Zachary Turner2d11c202015-02-27 09:15:59 +000031 void NewLine();
32
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000033 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000034 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000035 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000036
Zachary Turnerf5abda22015-03-01 06:49:49 +000037 bool IsTypeExcluded(llvm::StringRef TypeName);
38 bool IsSymbolExcluded(llvm::StringRef SymbolName);
39 bool IsCompilandExcluded(llvm::StringRef CompilandName);
40
Zachary Turner2d11c202015-02-27 09:15:59 +000041private:
Zachary Turner7797c722015-03-02 04:39:56 +000042 template <typename Iter>
43 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
44 List.clear();
45 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000046 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000047 }
48
Zachary Turner2d11c202015-02-27 09:15:59 +000049 raw_ostream &OS;
50 int IndentSpaces;
51 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000052 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000053
Zachary Turner4dddcc62015-09-29 19:49:06 +000054 std::list<Regex> ExcludeCompilandFilters;
55 std::list<Regex> ExcludeTypeFilters;
56 std::list<Regex> ExcludeSymbolFilters;
57
58 std::list<Regex> IncludeCompilandFilters;
59 std::list<Regex> IncludeTypeFilters;
60 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000061};
62
63template <class T>
64inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
65 Printer.getStream() << Item;
66 return Printer.getStream();
67}
68
69enum class PDB_ColorItem {
70 None,
71 Address,
72 Type,
73 Keyword,
74 Offset,
75 Identifier,
76 Path,
77 SectionHeader,
78 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +000079 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +000080};
81
82class WithColor {
83public:
84 WithColor(LinePrinter &P, PDB_ColorItem C);
85 ~WithColor();
86
87 raw_ostream &get() { return OS; }
88
89private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +000090 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +000091 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +000092 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +000093};
94}
Zachary Turnerec28fc32016-05-04 20:32:13 +000095}
Zachary Turner2d11c202015-02-27 09:15:59 +000096
97#endif