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 30 matching lines...) Expand all Loading... |
41 return namer.nameParameter(node); | 41 return namer.nameParameter(node); |
42 } | 42 } |
43 | 43 |
44 String visitMutableVariable(MutableVariable node) { | 44 String visitMutableVariable(MutableVariable node) { |
45 return namer.nameMutableVariable(node); | 45 return namer.nameMutableVariable(node); |
46 } | 46 } |
47 | 47 |
48 /// Main entry point for creating a [String] from a [Node]. All recursive | 48 /// Main entry point for creating a [String] from a [Node]. All recursive |
49 /// calls must go through this method. | 49 /// calls must go through this method. |
50 String visit(Node node) { | 50 String visit(Node node) { |
| 51 if (node == null) return '**** NULL ****'; |
51 String s = node.accept(this); | 52 String s = node.accept(this); |
52 return decorator(node, s); | 53 return decorator(node, s); |
53 } | 54 } |
54 | 55 |
55 String formatThisParameter(Parameter thisParameter) { | 56 String formatThisParameter(Parameter thisParameter) { |
56 return thisParameter == null ? '()' : '(${visit(thisParameter)})'; | 57 return thisParameter == null ? '()' : '(${visit(thisParameter)})'; |
57 } | 58 } |
58 | 59 |
59 String visitFunctionDefinition(FunctionDefinition node) { | 60 String visitFunctionDefinition(FunctionDefinition node) { |
60 String name = node.element.name; | 61 String name = node.element.name; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 106 } |
106 | 107 |
107 String visitLetMutable(LetMutable node) { | 108 String visitLetMutable(LetMutable node) { |
108 String name = visit(node.variable); | 109 String name = visit(node.variable); |
109 String value = access(node.value); | 110 String value = access(node.value); |
110 String body = indentBlock(() => visit(node.body)); | 111 String body = indentBlock(() => visit(node.body)); |
111 return '$indentation(LetMutable ($name $value)\n$body)'; | 112 return '$indentation(LetMutable ($name $value)\n$body)'; |
112 } | 113 } |
113 | 114 |
114 String formatArguments(CallStructure call, | 115 String formatArguments(CallStructure call, |
115 List<Reference<Primitive>> arguments, | 116 List<Reference<Primitive>> arguments, |
116 [CallingConvention callingConvention = CallingConvention.Normal]) { | 117 [CallingConvention callingConvention = CallingConvention.Normal]) { |
117 int positionalArgumentCount = call.positionalArgumentCount; | 118 int positionalArgumentCount = call.positionalArgumentCount; |
118 if (callingConvention == CallingConvention.Intercepted) { | 119 if (callingConvention == CallingConvention.Intercepted || |
| 120 callingConvention == CallingConvention.DummyIntercepted) { |
119 ++positionalArgumentCount; | 121 ++positionalArgumentCount; |
120 } | 122 } |
121 List<String> args = | 123 List<String> args = |
122 arguments.getRange(0, positionalArgumentCount).map(access).toList(); | 124 arguments.take(positionalArgumentCount).map(access).toList(); |
123 List<String> argumentNames = call.getOrderedNamedArguments(); | 125 List<String> argumentNames = call.getOrderedNamedArguments(); |
124 for (int i = 0; i < argumentNames.length; ++i) { | 126 for (int i = 0; i < argumentNames.length; ++i) { |
125 String name = argumentNames[i]; | 127 String name = argumentNames[i]; |
126 String arg = access(arguments[positionalArgumentCount + i]); | 128 String arg = access(arguments[positionalArgumentCount + i]); |
127 args.add("($name: $arg)"); | 129 args.add("($name: $arg)"); |
128 } | 130 } |
| 131 // Constructors can have type parameter after the named arguments. |
| 132 args.addAll( |
| 133 arguments.skip(positionalArgumentCount + argumentNames.length) |
| 134 .map(access)); |
129 return '(${args.join(' ')})'; | 135 return '(${args.join(' ')})'; |
130 } | 136 } |
131 | 137 |
132 String visitInvokeStatic(InvokeStatic node) { | 138 String visitInvokeStatic(InvokeStatic node) { |
133 String name = node.target.name; | 139 String name = node.target.name; |
134 String args = formatArguments(node.selector.callStructure, node.arguments); | 140 String args = formatArguments(node.selector.callStructure, node.arguments); |
135 return '(InvokeStatic $name $args)'; | 141 return '(InvokeStatic $name $args)'; |
136 } | 142 } |
137 | 143 |
138 String visitInvokeMethod(InvokeMethod node) { | 144 String visitInvokeMethod(InvokeMethod node) { |
(...skipping 24 matching lines...) Expand all Loading... |
163 name = '${name}.${node.target.name}'; | 169 name = '${name}.${node.target.name}'; |
164 } | 170 } |
165 String args = formatArguments(node.selector.callStructure, node.arguments); | 171 String args = formatArguments(node.selector.callStructure, node.arguments); |
166 return '(InvokeConstructor $name $args)'; | 172 return '(InvokeConstructor $name $args)'; |
167 } | 173 } |
168 | 174 |
169 String visitInvokeContinuation(InvokeContinuation node) { | 175 String visitInvokeContinuation(InvokeContinuation node) { |
170 String name = access(node.continuation); | 176 String name = access(node.continuation); |
171 if (node.isRecursive) name = 'rec $name'; | 177 if (node.isRecursive) name = 'rec $name'; |
172 String args = node.arguments.map(access).join(' '); | 178 String args = node.arguments.map(access).join(' '); |
173 return '$indentation(InvokeContinuation $name ($args))'; | 179 String escaping = node.isEscapingTry ? ' escape' : ''; |
| 180 return '$indentation(InvokeContinuation $name ($args)$escaping)'; |
174 } | 181 } |
175 | 182 |
176 String visitThrow(Throw node) { | 183 String visitThrow(Throw node) { |
177 String value = access(node.value); | 184 String value = access(node.value); |
178 return '$indentation(Throw $value)'; | 185 return '$indentation(Throw $value)'; |
179 } | 186 } |
180 | 187 |
181 String visitRethrow(Rethrow node) { | 188 String visitRethrow(Rethrow node) { |
182 return '$indentation(Rethrow)'; | 189 return '$indentation(Rethrow)'; |
183 } | 190 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 void setReturnContinuation(Continuation node) { | 491 void setReturnContinuation(Continuation node) { |
485 assert(!_names.containsKey(node) || _names[node] == 'return'); | 492 assert(!_names.containsKey(node) || _names[node] == 'return'); |
486 _names[node] = 'return'; | 493 _names[node] = 'return'; |
487 } | 494 } |
488 | 495 |
489 String getName(Node node) { | 496 String getName(Node node) { |
490 if (!_names.containsKey(node)) return 'MISSING_NAME'; | 497 if (!_names.containsKey(node)) return 'MISSING_NAME'; |
491 return _names[node]; | 498 return _names[node]; |
492 } | 499 } |
493 } | 500 } |
OLD | NEW |