1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//===- DiffPrinter.h ------------------------------------------ *- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVMPDBDUMP_DIFFPRINTER_H
#define LLVM_TOOLS_LLVMPDBDUMP_DIFFPRINTER_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include <list>
#include <unordered_set>
namespace std {
template <> struct hash<llvm::pdb::PdbRaw_FeatureSig> {
typedef llvm::pdb::PdbRaw_FeatureSig argument_type;
typedef std::size_t result_type;
result_type operator()(argument_type Item) const {
return std::hash<uint32_t>{}(uint32_t(Item));
}
};
} // namespace std
namespace llvm {
namespace pdb {
class PDBFile;
enum class DiffResult { UNSPECIFIED, IDENTICAL, EQUIVALENT, DIFFERENT };
struct IdenticalDiffProvider {
template <typename T, typename U>
DiffResult compare(const T &Left, const U &Right) {
return (Left == Right) ? DiffResult::IDENTICAL : DiffResult::DIFFERENT;
}
template <typename T> std::string format(const T &Item, bool Right) {
return formatv("{0}", Item).str();
}
};
struct EquivalentDiffProvider {
template <typename T, typename U>
DiffResult compare(const T &Left, const U &Right) {
return (Left == Right) ? DiffResult::IDENTICAL : DiffResult::EQUIVALENT;
}
template <typename T> std::string format(const T &Item, bool Right) {
return formatv("{0}", Item).str();
}
};
class DiffPrinter {
public:
DiffPrinter(uint32_t Indent, StringRef Header, uint32_t PropertyWidth,
uint32_t FieldWidth, bool Result, bool Values,
raw_ostream &Stream);
~DiffPrinter();
template <typename T, typename U> struct Identical {};
template <typename Provider = IdenticalDiffProvider, typename T, typename U>
void print(StringRef Property, const T &Left, const U &Right,
Provider P = Provider()) {
std::string L = P.format(Left, false);
std::string R = P.format(Right, true);
DiffResult Result = P.compare(Left, Right);
printExplicit(Property, Result, L, R);
}
void printExplicit(StringRef Property, DiffResult C, StringRef Left,
StringRef Right);
template <typename T, typename U>
void printExplicit(StringRef Property, DiffResult C, const T &Left,
const U &Right) {
std::string L = formatv("{0}", Left).str();
std::string R = formatv("{0}", Right).str();
printExplicit(Property, C, StringRef(L), StringRef(R));
}
template <typename T, typename U>
void diffUnorderedArray(StringRef Property, ArrayRef<T> Left,
ArrayRef<U> Right) {
std::unordered_set<T> LS(Left.begin(), Left.end());
std::unordered_set<U> RS(Right.begin(), Right.end());
std::string Count1 = formatv("{0} element(s)", Left.size());
std::string Count2 = formatv("{0} element(s)", Right.size());
print(std::string(Property) + "s (set)", Count1, Count2);
for (const auto &L : LS) {
auto Iter = RS.find(L);
std::string Text = formatv("{0}", L).str();
if (Iter == RS.end()) {
print(Property, Text, "(not present)");
continue;
}
print(Property, Text, Text);
RS.erase(Iter);
}
for (const auto &R : RS) {
auto Iter = LS.find(R);
std::string Text = formatv("{0}", R).str();
if (Iter == LS.end()) {
print(Property, "(not present)", Text);
continue;
}
print(Property, Text, Text);
}
}
template <typename ValueProvider = IdenticalDiffProvider, typename T,
typename U>
void diffUnorderedMap(StringRef Property, const StringMap<T> &Left,
const StringMap<U> &Right,
ValueProvider P = ValueProvider()) {
StringMap<U> RightCopy(Right);
std::string Count1 = formatv("{0} element(s)", Left.size());
std::string Count2 = formatv("{0} element(s)", Right.size());
print(std::string(Property) + "s (map)", Count1, Count2);
for (const auto &L : Left) {
auto Iter = RightCopy.find(L.getKey());
if (Iter == RightCopy.end()) {
printExplicit(L.getKey(), DiffResult::DIFFERENT, L.getValue(),
"(not present)");
continue;
}
print(L.getKey(), L.getValue(), Iter->getValue(), P);
RightCopy.erase(Iter);
}
for (const auto &R : RightCopy) {
printExplicit(R.getKey(), DiffResult::DIFFERENT, "(not present)",
R.getValue());
}
}
void printFullRow(StringRef Text);
private:
uint32_t tableWidth() const;
void printHeaderRow();
void printSeparatorRow();
void newLine(char InitialChar = '|');
void printValue(StringRef Value, DiffResult C, AlignStyle Style,
uint32_t Width, bool Force);
void printResult(DiffResult Result);
bool PrintResult;
bool PrintValues;
uint32_t Indent;
uint32_t PropertyWidth;
uint32_t FieldWidth;
raw_ostream &OS;
};
} // namespace pdb
} // namespace llvm
#endif
|