blob: 1a922feb1e6221d9164f4e2111a3cf02765c3e70 [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
Zachary Turner4dc4f012017-04-13 21:11:00 +000023class ClassLayout;
24
Zachary Turner2d11c202015-02-27 09:15:59 +000025class LinePrinter {
26 friend class WithColor;
27
28public:
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000029 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
Zachary Turner2d11c202015-02-27 09:15:59 +000030
31 void Indent();
32 void Unindent();
Zachary Turner2d11c202015-02-27 09:15:59 +000033 void NewLine();
34
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000035 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000036 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000037 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000038
Zachary Turner4dc4f012017-04-13 21:11:00 +000039 bool IsClassExcluded(const ClassLayout &Class);
40 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000041 bool IsSymbolExcluded(llvm::StringRef SymbolName);
42 bool IsCompilandExcluded(llvm::StringRef CompilandName);
43
Zachary Turner2d11c202015-02-27 09:15:59 +000044private:
Zachary Turner7797c722015-03-02 04:39:56 +000045 template <typename Iter>
46 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
47 List.clear();
48 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000049 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000050 }
51
Zachary Turner2d11c202015-02-27 09:15:59 +000052 raw_ostream &OS;
53 int IndentSpaces;
54 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000055 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000056
Zachary Turner4dddcc62015-09-29 19:49:06 +000057 std::list<Regex> ExcludeCompilandFilters;
58 std::list<Regex> ExcludeTypeFilters;
59 std::list<Regex> ExcludeSymbolFilters;
60
61 std::list<Regex> IncludeCompilandFilters;
62 std::list<Regex> IncludeTypeFilters;
63 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000064};
65
66template <class T>
67inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
68 Printer.getStream() << Item;
69 return Printer.getStream();
70}
71
72enum class PDB_ColorItem {
73 None,
74 Address,
75 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +000076 Comment,
77 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +000078 Keyword,
79 Offset,
80 Identifier,
81 Path,
82 SectionHeader,
83 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +000084 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +000085};
86
87class WithColor {
88public:
89 WithColor(LinePrinter &P, PDB_ColorItem C);
90 ~WithColor();
91
92 raw_ostream &get() { return OS; }
93
94private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +000095 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +000096 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +000097 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +000098};
99}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000100}
Zachary Turner2d11c202015-02-27 09:15:59 +0000101
102#endif