| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.ir_nodes_sexpr; | 5 library dart2js.ir_nodes_sexpr; |
| 6 | 6 |
| 7 import '../constants/values.dart'; | 7 import '../constants/values.dart'; |
| 8 import '../util/util.dart'; | 8 import '../util/util.dart'; |
| 9 import 'cps_ir_nodes.dart'; | 9 import 'cps_ir_nodes.dart'; |
| 10 import '../universe/call_structure.dart' show | 10 import '../universe/call_structure.dart' show |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 String newValueName(Primitive node) => namer.nameValue(node); | 22 String newValueName(Primitive node) => namer.nameValue(node); |
| 23 String newContinuationName(Continuation node) => namer.nameContinuation(node); | 23 String newContinuationName(Continuation node) => namer.nameContinuation(node); |
| 24 Decorator decorator; | 24 Decorator decorator; |
| 25 | 25 |
| 26 SExpressionStringifier([this.decorator]) { | 26 SExpressionStringifier([this.decorator]) { |
| 27 if (this.decorator == null) { | 27 if (this.decorator == null) { |
| 28 this.decorator = (node, String s) => s; | 28 this.decorator = (node, String s) => s; |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 /// Create a stringifier with an extra layer of decoration. |
| 33 SExpressionStringifier withDecorator(Decorator subDecorator) { |
| 34 return new SExpressionStringifier((node, String s) { |
| 35 return subDecorator(node, decorator(node, s)); |
| 36 }); |
| 37 } |
| 38 |
| 39 /// Create a stringifier that displays type information. |
| 40 SExpressionStringifier withTypes() => withDecorator(typeDecorator); |
| 41 |
| 42 /// Creates a stringifier that adds annotations from a map; |
| 43 /// see [Node.debugString]. |
| 44 SExpressionStringifier withAnnotations(Map annotations) { |
| 45 return withDecorator(decoratorFromMap(annotations)); |
| 46 } |
| 47 |
| 48 static Decorator decoratorFromMap(Map annotations) { |
| 49 Map<Node, String> nodeMap = {}; |
| 50 for (var key in annotations.keys) { |
| 51 if (key is Node) { |
| 52 nodeMap[key] = '${annotations[key]}'; |
| 53 } else { |
| 54 String text = key; |
| 55 Node node = annotations[key]; |
| 56 if (nodeMap.containsKey(node)) { |
| 57 // In case two annotations belong to the same node, |
| 58 // put both annotations on that node. |
| 59 nodeMap[node] += ' $text'; |
| 60 } else { |
| 61 nodeMap[node] = text; |
| 62 } |
| 63 } |
| 64 } |
| 65 return (node, string) { |
| 66 String text = nodeMap[node]; |
| 67 if (text != null) return '***$string*** $text'; |
| 68 return string; |
| 69 }; |
| 70 } |
| 71 |
| 72 static String typeDecorator(node, String string) { |
| 73 return node is Variable ? '$string:${node.type}' : string; |
| 74 } |
| 75 |
| 32 String access(Reference<Definition> r) { | 76 String access(Reference<Definition> r) { |
| 33 if (r == null) return '**** NULL ****'; | 77 if (r == null) return '**** NULL ****'; |
| 34 return decorator(r, namer.getName(r.definition)); | 78 return decorator(r, namer.getName(r.definition)); |
| 35 } | 79 } |
| 36 | 80 |
| 37 String optionalAccess(Reference<Definition> reference) { | 81 String optionalAccess(Reference<Definition> reference) { |
| 38 return reference == null ? '()' : '(${access(reference)})'; | 82 return reference == null ? '()' : '(${access(reference)})'; |
| 39 } | 83 } |
| 40 | 84 |
| 41 String visitParameter(Parameter node) { | 85 String visitParameter(Parameter node) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 71 | 115 |
| 72 String visitLetPrim(LetPrim node) { | 116 String visitLetPrim(LetPrim node) { |
| 73 String name = newValueName(node.primitive); | 117 String name = newValueName(node.primitive); |
| 74 String value = visit(node.primitive); | 118 String value = visit(node.primitive); |
| 75 String bindings = '($name $value)'; | 119 String bindings = '($name $value)'; |
| 76 String skip = ' ' * '(LetPrim ('.length; | 120 String skip = ' ' * '(LetPrim ('.length; |
| 77 while (node.body is LetPrim) { | 121 while (node.body is LetPrim) { |
| 78 node = node.body; | 122 node = node.body; |
| 79 name = newValueName(node.primitive); | 123 name = newValueName(node.primitive); |
| 80 value = visit(node.primitive); | 124 value = visit(node.primitive); |
| 81 bindings += '\n${indentation}$skip($name $value)'; | 125 String binding = decorator(node, '($name $value)'); |
| 126 bindings += '\n${indentation}$skip$binding'; |
| 82 } | 127 } |
| 83 String body = indentBlock(() => visit(node.body)); | 128 String body = indentBlock(() => visit(node.body)); |
| 84 return '$indentation(LetPrim ($bindings)\n$body)'; | 129 return '$indentation(LetPrim ($bindings)\n$body)'; |
| 85 } | 130 } |
| 86 | 131 |
| 87 bool isBranchTarget(Continuation cont) { | 132 bool isBranchTarget(Continuation cont) { |
| 88 return cont.hasExactlyOneUse && cont.firstRef.parent is Branch; | 133 return cont.hasExactlyOneUse && cont.firstRef.parent is Branch; |
| 89 } | 134 } |
| 90 | 135 |
| 91 String visitLetCont(LetCont node) { | 136 String visitLetCont(LetCont node) { |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 void setReturnContinuation(Continuation node) { | 560 void setReturnContinuation(Continuation node) { |
| 516 assert(!_names.containsKey(node) || _names[node] == 'return'); | 561 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 517 _names[node] = 'return'; | 562 _names[node] = 'return'; |
| 518 } | 563 } |
| 519 | 564 |
| 520 String getName(Node node) { | 565 String getName(Node node) { |
| 521 if (!_names.containsKey(node)) return 'MISSING_NAME'; | 566 if (!_names.containsKey(node)) return 'MISSING_NAME'; |
| 522 return _names[node]; | 567 return _names[node]; |
| 523 } | 568 } |
| 524 } | 569 } |
| OLD | NEW |