[llvm] r268472 - Make ListScope and DictScope re-use the same code.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Tue May 3 18:46:59 PDT 2016
Author: zturner
Date: Tue May 3 20:46:59 2016
New Revision: 268472
URL: http://llvm.org/viewvc/llvm-project?rev=268472&view=rev
Log:
Make ListScope and DictScope re-use the same code.
Modified:
llvm/trunk/include/llvm/Support/ScopedPrinter.h
Modified: llvm/trunk/include/llvm/Support/ScopedPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ScopedPrinter.h?rev=268472&r1=268471&r2=268472&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ScopedPrinter.h (original)
+++ llvm/trunk/include/llvm/Support/ScopedPrinter.h Tue May 3 20:46:59 2016
@@ -302,33 +302,26 @@ ScopedPrinter::printHex<support::ulittle
startLine() << Label << ": " << hex(Value) << "\n";
}
-struct DictScope {
- DictScope(ScopedPrinter &W, StringRef N) : W(W) {
- W.startLine() << N << " {\n";
+template<char Open, char Close>
+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
More information about the llvm-commits
mailing list