Index: include/llvm/Support/ScopedPrinter.h =================================================================== --- include/llvm/Support/ScopedPrinter.h +++ include/llvm/Support/ScopedPrinter.h @@ -304,33 +304,26 @@ startLine() << Label << ": " << hex(Value) << "\n"; } -struct DictScope { - DictScope(ScopedPrinter &W, StringRef N) : W(W) { - W.startLine() << N << " {\n"; +template +struct DelimitedScope { + DelimitedScope(ScopedPrinter &W, StringRef N) : W(W) { + W.startLine() << N; + if (!N.empty()) + W.getOStream() << ' '; + W.getOStream() << Open << '\n'; W.indent(); } - ~DictScope() { + ~DelimitedScope() { W.unindent(); - W.startLine() << "}\n"; + W.startLine() << Close << '\n'; } ScopedPrinter &W; }; -struct ListScope { - ListScope(ScopedPrinter &W, StringRef N) : W(W) { - W.startLine() << N << " [\n"; - W.indent(); - } - - ~ListScope() { - W.unindent(); - W.startLine() << "]\n"; - } - - ScopedPrinter &W; -}; +using DictScope = DelimitedScope<'{', '}'>; +using ListScope = DelimitedScope<'[', ']'>; } // namespace llvm