Index: pkg/compiler/lib/src/kernel/kernel_debug.dart |
diff --git a/pkg/compiler/lib/src/kernel/kernel_debug.dart b/pkg/compiler/lib/src/kernel/kernel_debug.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..72581617cb7d1ebbafd3e4ec7c523820bcea1e23 |
--- /dev/null |
+++ b/pkg/compiler/lib/src/kernel/kernel_debug.dart |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+/// Helper for debug Kernel nodes. |
+ |
+library kernel.debug; |
+ |
+import 'package:kernel/kernel.dart'; |
+import 'package:kernel/visitor.dart'; |
+ |
+import '../util/util.dart' show Indentation, Tagging; |
+ |
+class DebugPrinter extends Visitor with Indentation, Tagging<Node> { |
+ StringBuffer sb = new StringBuffer(); |
+ |
+ void visitNodeWithChildren(Node node, String type, [Map params]) { |
+ openNode(node, type, params); |
+ node.visitChildren(this); |
+ closeNode(); |
+ } |
+ |
+ @override |
+ void defaultNode(Node node) { |
+ visitNodeWithChildren(node, '${node.runtimeType}'); |
+ } |
+ |
+ @override |
+ void visitName(Name node) { |
+ openAndCloseNode(node, '${node.runtimeType}', |
+ {'name': node.name, 'library': node.library?.name}); |
+ } |
+ |
+ @override |
+ void visitIntLiteral(IntLiteral node) { |
+ openAndCloseNode(node, '${node.runtimeType}', {'value': '${node.value}'}); |
+ } |
+ |
+ /// Pretty-prints given node tree into string. |
+ static String prettyPrint(Node node) { |
+ var p = new DebugPrinter(); |
+ node.accept(p); |
+ return p.sb.toString(); |
+ } |
+} |