Make ListScope and DictScope re-use the same code.
llvm-svn: 268472
This commit is contained in:
parent
537c5b5b62
commit
e9bc5ce124
|
@ -302,33 +302,26 @@ ScopedPrinter::printHex<support::ulittle16_t>(StringRef Label,
|
||||||
startLine() << Label << ": " << hex(Value) << "\n";
|
startLine() << Label << ": " << hex(Value) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DictScope {
|
template<char Open, char Close>
|
||||||
DictScope(ScopedPrinter &W, StringRef N) : W(W) {
|
struct DelimitedScope {
|
||||||
W.startLine() << N << " {\n";
|
DelimitedScope(ScopedPrinter &W, StringRef N) : W(W) {
|
||||||
|
W.startLine() << N;
|
||||||
|
if (!N.empty())
|
||||||
|
W.getOStream() << ' ';
|
||||||
|
W.getOStream() << Open << '\n';
|
||||||
W.indent();
|
W.indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
~DictScope() {
|
~DelimitedScope() {
|
||||||
W.unindent();
|
W.unindent();
|
||||||
W.startLine() << "}\n";
|
W.startLine() << Close << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedPrinter &W;
|
ScopedPrinter &W;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ListScope {
|
using DictScope = DelimitedScope<'{', '}'>;
|
||||||
ListScope(ScopedPrinter &W, StringRef N) : W(W) {
|
using ListScope = DelimitedScope<'[', ']'>;
|
||||||
W.startLine() << N << " [\n";
|
|
||||||
W.indent();
|
|
||||||
}
|
|
||||||
|
|
||||||
~ListScope() {
|
|
||||||
W.unindent();
|
|
||||||
W.startLine() << "]\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedPrinter &W;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue