| 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 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 String visitLetPrim(LetPrim node) { | 71 String visitLetPrim(LetPrim node) { |
| 72 String name = newValueName(node.primitive); | 72 String name = newValueName(node.primitive); |
| 73 String value = visit(node.primitive); | 73 String value = visit(node.primitive); |
| 74 String body = indentBlock(() => visit(node.body)); | 74 String body = indentBlock(() => visit(node.body)); |
| 75 return '$indentation(LetPrim ($name $value)\n$body)'; | 75 return '$indentation(LetPrim ($name $value)\n$body)'; |
| 76 } | 76 } |
| 77 | 77 |
| 78 String visitLetCont(LetCont node) { | 78 String visitLetCont(LetCont node) { |
| 79 String conts; | 79 String cont = newContinuationName(node.continuation); |
| 80 bool first = true; | 80 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and |
| 81 for (Continuation continuation in node.continuations) { | 81 // should recurse to [visit]. Currently we can't do that, because the |
| 82 String name = newContinuationName(continuation); | 82 // unstringifier_test produces [LetConts] with dummy arguments on them. |
| 83 if (continuation.isRecursive) name = 'rec $name'; | 83 String parameters = node.continuation.parameters |
| 84 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and | 84 .map((p) => '${decorator(p, newValueName(p))}') |
| 85 // should recurse to [visit]. Currently we can't do that, because the | 85 .join(' '); |
| 86 // unstringifier_test produces [LetConts] with dummy arguments on them. | 86 String contBody = |
| 87 String parameters = continuation.parameters | 87 indentBlock(() => indentBlock(() => visit(node.continuation.body))); |
| 88 .map((p) => '${decorator(p, newValueName(p))}') | |
| 89 .join(' '); | |
| 90 String body = | |
| 91 indentBlock(() => indentBlock(() => visit(continuation.body))); | |
| 92 if (first) { | |
| 93 first = false; | |
| 94 conts = '($name ($parameters)\n$body)'; | |
| 95 } else { | |
| 96 // Each subsequent line is indented additional spaces to align it | |
| 97 // with the previous continuation. | |
| 98 String indent = '$indentation${' ' * '(LetCont ('.length}'; | |
| 99 conts = '$conts\n$indent($name ($parameters)\n$body)'; | |
| 100 } | |
| 101 } | |
| 102 String body = indentBlock(() => visit(node.body)); | 88 String body = indentBlock(() => visit(node.body)); |
| 103 return '$indentation($LetCont ($conts)\n$body)'; | 89 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont'; |
| 90 return '$indentation($op ($cont ($parameters)\n' |
| 91 '$contBody)\n' |
| 92 '$body)'; |
| 104 } | 93 } |
| 105 | 94 |
| 106 String formatArguments(Invoke node) { | 95 String formatArguments(Invoke node) { |
| 107 int positionalArgumentCount = node.selector.positionalArgumentCount; | 96 int positionalArgumentCount = node.selector.positionalArgumentCount; |
| 108 List<String> args = new List<String>(); | 97 List<String> args = new List<String>(); |
| 109 args.addAll( | 98 args.addAll( |
| 110 node.arguments.getRange(0, positionalArgumentCount).map(access)); | 99 node.arguments.getRange(0, positionalArgumentCount).map(access)); |
| 111 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { | 100 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { |
| 112 String name = node.selector.namedArguments[i]; | 101 String name = node.selector.namedArguments[i]; |
| 113 String arg = access(node.arguments[positionalArgumentCount + i]); | 102 Definition arg = node.arguments[positionalArgumentCount + i].definition; |
| 114 args.add("($name: $arg)"); | 103 args.add("($name: $arg)"); |
| 115 } | 104 } |
| 116 return '(${args.join(' ')})'; | 105 return '(${args.join(' ')})'; |
| 117 } | 106 } |
| 118 | 107 |
| 119 String visitInvokeStatic(InvokeStatic node) { | 108 String visitInvokeStatic(InvokeStatic node) { |
| 120 String name = node.target.name; | 109 String name = node.target.name; |
| 121 String cont = access(node.continuation); | 110 String cont = access(node.continuation); |
| 122 String args = formatArguments(node); | 111 String args = formatArguments(node); |
| 123 return '$indentation(InvokeStatic $name $args $cont)'; | 112 return '$indentation(InvokeStatic $name $args $cont)'; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 void setReturnContinuation(Continuation node) { | 355 void setReturnContinuation(Continuation node) { |
| 367 assert(!_names.containsKey(node) || _names[node] == 'return'); | 356 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 368 _names[node] = 'return'; | 357 _names[node] = 'return'; |
| 369 } | 358 } |
| 370 | 359 |
| 371 String getName(Node node) { | 360 String getName(Node node) { |
| 372 assert(_names.containsKey(node)); | 361 assert(_names.containsKey(node)); |
| 373 return _names[node]; | 362 return _names[node]; |
| 374 } | 363 } |
| 375 } | 364 } |
| OLD | NEW |