annotate tools/llvm-pdbutil/DiffPrinter.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 #include "DiffPrinter.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 #include "llvm/Support/FormatAdapters.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 using namespace llvm::pdb;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 namespace {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 struct Colorize {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 Colorize(raw_ostream &OS, DiffResult Result) : OS(OS) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 if (!OS.has_colors())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 switch (Result) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 case DiffResult::IDENTICAL:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 OS.changeColor(raw_ostream::Colors::GREEN, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 case DiffResult::EQUIVALENT:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 OS.changeColor(raw_ostream::Colors::YELLOW, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 default:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 OS.changeColor(raw_ostream::Colors::RED, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 ~Colorize() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 if (OS.has_colors())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 OS.resetColor();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 raw_ostream &OS;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 DiffPrinter::DiffPrinter(uint32_t Indent, StringRef Header,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 uint32_t PropertyWidth, uint32_t FieldWidth,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 bool Result, bool Fields, raw_ostream &Stream)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 : PrintResult(Result), PrintValues(Fields), Indent(Indent),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 PropertyWidth(PropertyWidth), FieldWidth(FieldWidth), OS(Stream) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 printHeaderRow();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 printFullRow(Header);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 DiffPrinter::~DiffPrinter() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 uint32_t DiffPrinter::tableWidth() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 // `|`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 uint32_t W = 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 // `<width>|`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 W += PropertyWidth + 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 if (PrintResult) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 // ` I |`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 W += 4;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 if (PrintValues) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 // `<width>|<width>|`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 W += 2 * (FieldWidth + 1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 return W;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 void DiffPrinter::printFullRow(StringRef Text) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 newLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 printValue(Text, DiffResult::UNSPECIFIED, AlignStyle::Center,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 tableWidth() - 2, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 printSeparatorRow();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 void DiffPrinter::printSeparatorRow() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 newLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 OS << formatv("{0}", fmt_repeat('-', PropertyWidth));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 if (PrintResult) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 OS << '+';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 OS << formatv("{0}", fmt_repeat('-', 3));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 if (PrintValues) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 OS << '+';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 OS << formatv("{0}", fmt_repeat('-', FieldWidth));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 OS << '+';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 OS << formatv("{0}", fmt_repeat('-', FieldWidth));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 OS << '|';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 void DiffPrinter::printHeaderRow() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 newLine('-');
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 OS << formatv("{0}", fmt_repeat('-', tableWidth() - 1));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 void DiffPrinter::newLine(char InitialChar) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 OS << "\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 OS.indent(Indent) << InitialChar;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 void DiffPrinter::printExplicit(StringRef Property, DiffResult C,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 StringRef Left, StringRef Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 newLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 printValue(Property, DiffResult::UNSPECIFIED, AlignStyle::Right,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 PropertyWidth, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 printResult(C);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 printValue(Left, C, AlignStyle::Center, FieldWidth, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 printValue(Right, C, AlignStyle::Center, FieldWidth, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 printSeparatorRow();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 void DiffPrinter::printResult(DiffResult Result) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 if (!PrintResult)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 switch (Result) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 case DiffResult::DIFFERENT:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 printValue("D", Result, AlignStyle::Center, 3, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 case DiffResult::EQUIVALENT:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 printValue("E", Result, AlignStyle::Center, 3, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 case DiffResult::IDENTICAL:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 printValue("I", Result, AlignStyle::Center, 3, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 case DiffResult::UNSPECIFIED:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 printValue(" ", Result, AlignStyle::Center, 3, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 break;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 void DiffPrinter::printValue(StringRef Value, DiffResult C, AlignStyle Style,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 uint32_t Width, bool Force) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 if (!Force && !PrintValues)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 if (Style == AlignStyle::Right)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 --Width;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 std::string FormattedItem =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 formatv("{0}", fmt_align(Value, Style, Width)).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 if (C != DiffResult::UNSPECIFIED) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 Colorize Color(OS, C);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 OS << FormattedItem;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 } else
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 OS << FormattedItem;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 if (Style == AlignStyle::Right)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 OS << ' ';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 OS << '|';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 }