| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 for (int i = 0; i < argumentNames.length; ++i) { | 118 for (int i = 0; i < argumentNames.length; ++i) { |
| 119 String name = argumentNames[i]; | 119 String name = argumentNames[i]; |
| 120 String arg = access(arguments[positionalArgumentCount + i]); | 120 String arg = access(arguments[positionalArgumentCount + i]); |
| 121 args.add("($name: $arg)"); | 121 args.add("($name: $arg)"); |
| 122 } | 122 } |
| 123 return '(${args.join(' ')})'; | 123 return '(${args.join(' ')})'; |
| 124 } | 124 } |
| 125 | 125 |
| 126 String visitInvokeStatic(InvokeStatic node) { | 126 String visitInvokeStatic(InvokeStatic node) { |
| 127 String name = node.target.name; | 127 String name = node.target.name; |
| 128 String cont = access(node.continuation); | |
| 129 String args = formatArguments(node.selector.callStructure, node.arguments); | 128 String args = formatArguments(node.selector.callStructure, node.arguments); |
| 130 return '$indentation(InvokeStatic $name $args $cont)'; | 129 return '(InvokeStatic $name $args)'; |
| 131 } | 130 } |
| 132 | 131 |
| 133 String visitInvokeMethod(InvokeMethod node) { | 132 String visitInvokeMethod(InvokeMethod node) { |
| 134 String name = node.selector.name; | 133 String name = node.selector.name; |
| 135 String rcv = access(node.receiver); | 134 String rcv = access(node.receiver); |
| 136 String cont = access(node.continuation); | |
| 137 String args = formatArguments(node.selector.callStructure, node.arguments, | 135 String args = formatArguments(node.selector.callStructure, node.arguments, |
| 138 isIntercepted: node.receiverIsIntercepted); | 136 isIntercepted: node.receiverIsIntercepted); |
| 139 return '$indentation(InvokeMethod $rcv $name $args $cont)'; | 137 return '(InvokeMethod $rcv $name $args)'; |
| 140 } | 138 } |
| 141 | 139 |
| 142 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { | 140 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 143 String receiver = access(node.receiver); | 141 String receiver = access(node.receiver); |
| 144 String name = node.selector.name; | 142 String name = node.selector.name; |
| 145 String cont = access(node.continuation); | |
| 146 String args = formatArguments(node.selector.callStructure, node.arguments); | 143 String args = formatArguments(node.selector.callStructure, node.arguments); |
| 147 return '$indentation(InvokeMethodDirectly $receiver $name $args $cont)'; | 144 return '(InvokeMethodDirectly $receiver $name $args)'; |
| 148 } | 145 } |
| 149 | 146 |
| 150 String visitInvokeConstructor(InvokeConstructor node) { | 147 String visitInvokeConstructor(InvokeConstructor node) { |
| 151 String className; | 148 String className; |
| 152 // TODO(karlklose): for illegal nodes constructed for tests or unresolved | 149 // TODO(karlklose): for illegal nodes constructed for tests or unresolved |
| 153 // constructor calls in the DartBackend, we get an element with no enclosing | 150 // constructor calls in the DartBackend, we get an element with no enclosing |
| 154 // class. Clean this up by introducing a name field to the node and | 151 // class. Clean this up by introducing a name field to the node and |
| 155 // removing [ErroneousElement]s from the IR. | 152 // removing [ErroneousElement]s from the IR. |
| 156 if (node.dartType != null) { | 153 if (node.dartType != null) { |
| 157 className = node.dartType.toString(); | 154 className = node.dartType.toString(); |
| 158 } else { | 155 } else { |
| 159 className = node.target.enclosingClass.name; | 156 className = node.target.enclosingClass.name; |
| 160 } | 157 } |
| 161 String callName; | 158 String callName; |
| 162 if (node.target.name.isEmpty) { | 159 if (node.target.name.isEmpty) { |
| 163 callName = '${className}'; | 160 callName = '${className}'; |
| 164 } else { | 161 } else { |
| 165 callName = '${className}.${node.target.name}'; | 162 callName = '${className}.${node.target.name}'; |
| 166 } | 163 } |
| 167 String cont = access(node.continuation); | |
| 168 String args = formatArguments(node.selector.callStructure, node.arguments); | 164 String args = formatArguments(node.selector.callStructure, node.arguments); |
| 169 return '$indentation(InvokeConstructor $callName $args $cont)'; | 165 return '(InvokeConstructor $callName $args)'; |
| 170 } | 166 } |
| 171 | 167 |
| 172 String visitInvokeContinuation(InvokeContinuation node) { | 168 String visitInvokeContinuation(InvokeContinuation node) { |
| 173 String name = access(node.continuation); | 169 String name = access(node.continuation); |
| 174 if (node.isRecursive) name = 'rec $name'; | 170 if (node.isRecursive) name = 'rec $name'; |
| 175 String args = node.arguments.map(access).join(' '); | 171 String args = node.arguments.map(access).join(' '); |
| 176 return '$indentation(InvokeContinuation $name ($args))'; | 172 return '$indentation(InvokeContinuation $name ($args))'; |
| 177 } | 173 } |
| 178 | 174 |
| 179 String visitThrow(Throw node) { | 175 String visitThrow(Throw node) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return '(GetMutable ${access(node.variable)})'; | 221 return '(GetMutable ${access(node.variable)})'; |
| 226 } | 222 } |
| 227 | 223 |
| 228 String visitSetMutable(SetMutable node) { | 224 String visitSetMutable(SetMutable node) { |
| 229 String value = access(node.value); | 225 String value = access(node.value); |
| 230 return '(SetMutable ${access(node.variable)} $value)'; | 226 return '(SetMutable ${access(node.variable)} $value)'; |
| 231 } | 227 } |
| 232 | 228 |
| 233 String visitTypeCast(TypeCast node) { | 229 String visitTypeCast(TypeCast node) { |
| 234 String value = access(node.value); | 230 String value = access(node.value); |
| 235 String cont = access(node.continuation); | |
| 236 String typeArguments = node.typeArguments.map(access).join(' '); | 231 String typeArguments = node.typeArguments.map(access).join(' '); |
| 237 return '$indentation(TypeCast $value ${node.dartType}' | 232 return '(TypeCast $value ${node.dartType} ($typeArguments))'; |
| 238 ' ($typeArguments) $cont)'; | |
| 239 } | 233 } |
| 240 | 234 |
| 241 String visitTypeTest(TypeTest node) { | 235 String visitTypeTest(TypeTest node) { |
| 242 String value = access(node.value); | 236 String value = access(node.value); |
| 243 String typeArguments = node.typeArguments.map(access).join(' '); | 237 String typeArguments = node.typeArguments.map(access).join(' '); |
| 244 String interceptor = node.interceptor == null | 238 String interceptor = node.interceptor == null |
| 245 ? '' | 239 ? '' |
| 246 : access(node.interceptor); | 240 : access(node.interceptor); |
| 247 return '(TypeTest $value ${node.dartType} ($typeArguments) ($interceptor))'; | 241 return '(TypeTest $value ${node.dartType} ($typeArguments) ($interceptor))'; |
| 248 } | 242 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 276 } |
| 283 | 277 |
| 284 String visitSetStatic(SetStatic node) { | 278 String visitSetStatic(SetStatic node) { |
| 285 String element = node.element.name; | 279 String element = node.element.name; |
| 286 String value = access(node.value); | 280 String value = access(node.value); |
| 287 return '(SetStatic $element $value)'; | 281 return '(SetStatic $element $value)'; |
| 288 } | 282 } |
| 289 | 283 |
| 290 String visitGetLazyStatic(GetLazyStatic node) { | 284 String visitGetLazyStatic(GetLazyStatic node) { |
| 291 String element = node.element.name; | 285 String element = node.element.name; |
| 292 String cont = access(node.continuation); | 286 return '(GetLazyStatic $element)'; |
| 293 return '$indentation(GetLazyStatic $element $cont)'; | |
| 294 } | 287 } |
| 295 | 288 |
| 296 String visitCreateBox(CreateBox node) { | 289 String visitCreateBox(CreateBox node) { |
| 297 return '(CreateBox)'; | 290 return '(CreateBox)'; |
| 298 } | 291 } |
| 299 | 292 |
| 300 String visitCreateInstance(CreateInstance node) { | 293 String visitCreateInstance(CreateInstance node) { |
| 301 String className = node.classElement.name; | 294 String className = node.classElement.name; |
| 302 String arguments = node.arguments.map(access).join(' '); | 295 String arguments = node.arguments.map(access).join(' '); |
| 303 String typeInformation = node.typeInformation.map(access).join(' '); | 296 String typeInformation = node.typeInformation.map(access).join(' '); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 328 |
| 336 String visitApplyBuiltinMethod(ApplyBuiltinMethod node) { | 329 String visitApplyBuiltinMethod(ApplyBuiltinMethod node) { |
| 337 String method = node.method.toString(); | 330 String method = node.method.toString(); |
| 338 String receiver = access(node.receiver); | 331 String receiver = access(node.receiver); |
| 339 String args = node.arguments.map(access).join(' '); | 332 String args = node.arguments.map(access).join(' '); |
| 340 return '(ApplyBuiltinMethod $method $receiver ($args))'; | 333 return '(ApplyBuiltinMethod $method $receiver ($args))'; |
| 341 } | 334 } |
| 342 | 335 |
| 343 String visitForeignCode(ForeignCode node) { | 336 String visitForeignCode(ForeignCode node) { |
| 344 String arguments = node.arguments.map(access).join(' '); | 337 String arguments = node.arguments.map(access).join(' '); |
| 345 String continuation = node.continuation == null ? '' | 338 return '(JS "${node.codeTemplate.source}" ($arguments))'; |
| 346 : ' ${access(node.continuation)}'; | |
| 347 return '$indentation(JS "${node.codeTemplate.source}"' | |
| 348 ' ($arguments)$continuation)'; | |
| 349 } | 339 } |
| 350 | 340 |
| 351 String visitGetLength(GetLength node) { | 341 String visitGetLength(GetLength node) { |
| 352 String object = access(node.object); | 342 String object = access(node.object); |
| 353 return '(GetLength $object)'; | 343 return '(GetLength $object)'; |
| 354 } | 344 } |
| 355 | 345 |
| 356 String visitGetIndex(GetIndex node) { | 346 String visitGetIndex(GetIndex node) { |
| 357 String object = access(node.object); | 347 String object = access(node.object); |
| 358 String index = access(node.index); | 348 String index = access(node.index); |
| 359 return '(GetIndex $object $index)'; | 349 return '(GetIndex $object $index)'; |
| 360 } | 350 } |
| 361 | 351 |
| 362 String visitSetIndex(SetIndex node) { | 352 String visitSetIndex(SetIndex node) { |
| 363 String object = access(node.object); | 353 String object = access(node.object); |
| 364 String index = access(node.index); | 354 String index = access(node.index); |
| 365 String value = access(node.value); | 355 String value = access(node.value); |
| 366 return '(SetIndex $object $index $value)'; | 356 return '(SetIndex $object $index $value)'; |
| 367 } | 357 } |
| 368 | 358 |
| 369 @override | 359 @override |
| 370 String visitAwait(Await node) { | 360 String visitAwait(Await node) { |
| 371 String value = access(node.input); | 361 String value = access(node.input); |
| 372 String continuation = access(node.continuation); | 362 return '(Await $value)'; |
| 373 return '(Await $value $continuation)'; | |
| 374 } | 363 } |
| 375 | 364 |
| 376 @override | 365 @override |
| 377 String visitYield(Yield node) { | 366 String visitYield(Yield node) { |
| 378 String value = access(node.input); | 367 String value = access(node.input); |
| 379 String continuation = access(node.continuation); | 368 return '(Yield $value)'; |
| 380 return '(Yield $value $continuation)'; | |
| 381 } | 369 } |
| 382 | 370 |
| 383 String visitRefinement(Refinement node) { | 371 String visitRefinement(Refinement node) { |
| 384 String value = access(node.value); | 372 String value = access(node.value); |
| 385 return '(Refinement $value ${node.type})'; | 373 return '(Refinement $value ${node.type})'; |
| 386 } | 374 } |
| 387 } | 375 } |
| 388 | 376 |
| 389 class ConstantStringifier extends ConstantValueVisitor<String, Null> { | 377 class ConstantStringifier extends ConstantValueVisitor<String, Null> { |
| 390 // Some of these methods are unimplemented because we haven't had a need | 378 // Some of these methods are unimplemented because we haven't had a need |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 void setReturnContinuation(Continuation node) { | 479 void setReturnContinuation(Continuation node) { |
| 492 assert(!_names.containsKey(node) || _names[node] == 'return'); | 480 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 493 _names[node] = 'return'; | 481 _names[node] = 'return'; |
| 494 } | 482 } |
| 495 | 483 |
| 496 String getName(Node node) { | 484 String getName(Node node) { |
| 497 if (!_names.containsKey(node)) return 'MISSING_NAME'; | 485 if (!_names.containsKey(node)) return 'MISSING_NAME'; |
| 498 return _names[node]; | 486 return _names[node]; |
| 499 } | 487 } |
| 500 } | 488 } |
| OLD | NEW |