OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Helper for debug Kernel nodes. |
| 6 |
| 7 library kernel.debug; |
| 8 |
| 9 import 'package:kernel/kernel.dart'; |
| 10 import 'package:kernel/visitor.dart'; |
| 11 |
| 12 import '../util/util.dart' show Indentation, Tagging; |
| 13 |
| 14 class DebugPrinter extends Visitor with Indentation, Tagging<Node> { |
| 15 StringBuffer sb = new StringBuffer(); |
| 16 |
| 17 void visitNodeWithChildren(Node node, String type, [Map params]) { |
| 18 openNode(node, type, params); |
| 19 node.visitChildren(this); |
| 20 closeNode(); |
| 21 } |
| 22 |
| 23 @override |
| 24 void defaultNode(Node node) { |
| 25 visitNodeWithChildren(node, '${node.runtimeType}'); |
| 26 } |
| 27 |
| 28 @override |
| 29 void visitName(Name node) { |
| 30 openAndCloseNode(node, '${node.runtimeType}', |
| 31 {'name': node.name, 'library': node.library?.name}); |
| 32 } |
| 33 |
| 34 @override |
| 35 void visitIntLiteral(IntLiteral node) { |
| 36 openAndCloseNode(node, '${node.runtimeType}', {'value': '${node.value}'}); |
| 37 } |
| 38 |
| 39 /// Pretty-prints given node tree into string. |
| 40 static String prettyPrint(Node node) { |
| 41 var p = new DebugPrinter(); |
| 42 node.accept(p); |
| 43 return p.sb.toString(); |
| 44 } |
| 45 } |
OLD | NEW |