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 code_generator; | 5 library code_generator; |
6 | 6 |
7 import 'glue.dart'; | 7 import 'glue.dart'; |
8 | 8 |
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; | 10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 registry.registerStaticInvocation(target.declaration); | 227 registry.registerStaticInvocation(target.declaration); |
228 if (target == glue.getInterceptorMethod) { | 228 if (target == glue.getInterceptorMethod) { |
229 // This generates a call to the specialized interceptor function, which | 229 // This generates a call to the specialized interceptor function, which |
230 // does not have a specialized element yet, but is emitted as a stub from | 230 // does not have a specialized element yet, but is emitted as a stub from |
231 // the emitter in [InterceptorStubGenerator]. | 231 // the emitter in [InterceptorStubGenerator]. |
232 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] | 232 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] |
233 // instead of an [Element] and model the getInterceptor functions as | 233 // instead of an [Element] and model the getInterceptor functions as |
234 // [Entity]s or add a specialized Tree-IR node for interceptor calls. | 234 // [Entity]s or add a specialized Tree-IR node for interceptor calls. |
235 registry.registerUseInterceptor(); | 235 registry.registerUseInterceptor(); |
236 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); | 236 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); |
237 return js.propertyCall(interceptorLibrary, selector.name, arguments); | 237 return js.propertyCall(interceptorLibrary, js.string(selector.name), |
floitsch
2015/06/22 17:43:43
why is this just a string?
herhut
2015/06/23 13:26:30
Because it is a broken abstraction. Selectors can
asgerf
2015/06/23 13:34:54
Yeah that was broken. This CL should fix it:
http
| |
238 arguments); | |
238 } else { | 239 } else { |
239 js.Expression elementAccess = glue.staticFunctionAccess(target); | 240 js.Expression elementAccess = glue.staticFunctionAccess(target); |
240 return new js.Call(elementAccess, arguments, | 241 return new js.Call(elementAccess, arguments, |
241 sourceInformation: sourceInformation); | 242 sourceInformation: sourceInformation); |
242 } | 243 } |
243 } | 244 } |
244 | 245 |
245 @override | 246 @override |
246 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { | 247 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { |
247 if (node.constant != null) return giveup(node); | 248 if (node.constant != null) return giveup(node); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 // | 370 // |
370 // checkSubtype(value, $isT, typeArgs, $asT) | 371 // checkSubtype(value, $isT, typeArgs, $asT) |
371 // subtypeCast(value, $isT, typeArgs, $asT) | 372 // subtypeCast(value, $isT, typeArgs, $asT) |
372 // | 373 // |
373 // Any of the last two arguments may be null if there are no type | 374 // Any of the last two arguments may be null if there are no type |
374 // arguments, and/or if no substitution is required. | 375 // arguments, and/or if no substitution is required. |
375 Element function = node.isTypeTest | 376 Element function = node.isTypeTest |
376 ? glue.getCheckSubtype() | 377 ? glue.getCheckSubtype() |
377 : glue.getSubtypeCast(); | 378 : glue.getSubtypeCast(); |
378 | 379 |
379 js.Expression isT = js.string(glue.getTypeTestTag(type)); | 380 js.Expression isT = js.quoteName(glue.getTypeTestTag(type)); |
380 | 381 |
381 js.Expression typeArgumentArray = typeArguments.isNotEmpty | 382 js.Expression typeArgumentArray = typeArguments.isNotEmpty |
382 ? new js.ArrayInitializer(typeArguments) | 383 ? new js.ArrayInitializer(typeArguments) |
383 : new js.LiteralNull(); | 384 : new js.LiteralNull(); |
384 | 385 |
385 js.Expression asT = glue.hasStrictSubtype(clazz) | 386 js.Expression asT = glue.hasStrictSubtype(clazz) |
386 ? js.string(glue.getTypeSubstitutionTag(clazz)) | 387 ? js.quoteName(glue.getTypeSubstitutionTag(clazz)) |
387 : new js.LiteralNull(); | 388 : new js.LiteralNull(); |
388 | 389 |
389 return buildStaticHelperInvocation( | 390 return buildStaticHelperInvocation( |
390 function, | 391 function, |
391 <js.Expression>[value, isT, typeArgumentArray, asT]); | 392 <js.Expression>[value, isT, typeArgumentArray, asT]); |
392 } else if (type is TypeVariableType || type is FunctionType) { | 393 } else if (type is TypeVariableType || type is FunctionType) { |
393 glue.registerIsCheck(type, registry); | 394 glue.registerIsCheck(type, registry); |
394 | 395 |
395 Element function = node.isTypeTest | 396 Element function = node.isTypeTest |
396 ? glue.getCheckSubtypeOfRuntimeType() | 397 ? glue.getCheckSubtypeOfRuntimeType() |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 <js.Expression>[instance, typeArguments]); | 604 <js.Expression>[instance, typeArguments]); |
604 } else { | 605 } else { |
605 return instance; | 606 return instance; |
606 } | 607 } |
607 } | 608 } |
608 | 609 |
609 @override | 610 @override |
610 js.Expression visitCreateInvocationMirror( | 611 js.Expression visitCreateInvocationMirror( |
611 tree_ir.CreateInvocationMirror node) { | 612 tree_ir.CreateInvocationMirror node) { |
612 js.Expression name = js.string(node.selector.name); | 613 js.Expression name = js.string(node.selector.name); |
613 js.Expression internalName = js.string(glue.invocationName(node.selector)); | 614 js.Expression internalName = |
615 js.quoteName(glue.invocationName(node.selector)); | |
614 js.Expression kind = js.number(node.selector.invocationMirrorKind); | 616 js.Expression kind = js.number(node.selector.invocationMirrorKind); |
615 js.Expression arguments = new js.ArrayInitializer( | 617 js.Expression arguments = new js.ArrayInitializer( |
616 visitExpressionList(node.arguments)); | 618 visitExpressionList(node.arguments)); |
617 js.Expression argumentNames = new js.ArrayInitializer( | 619 js.Expression argumentNames = new js.ArrayInitializer( |
618 node.selector.namedArguments.map(js.string).toList(growable: false)); | 620 node.selector.namedArguments.map(js.string).toList(growable: false)); |
619 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, | 621 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, |
620 [name, internalName, kind, arguments, argumentNames]); | 622 [name, internalName, kind, arguments, argumentNames]); |
621 } | 623 } |
622 | 624 |
623 @override | 625 @override |
624 js.Expression visitGetField(tree_ir.GetField node) { | 626 js.Expression visitGetField(tree_ir.GetField node) { |
625 return new js.PropertyAccess.field( | 627 return new js.PropertyAccess( |
626 visitExpression(node.object), | 628 visitExpression(node.object), |
627 glue.instanceFieldPropertyName(node.field)); | 629 glue.instanceFieldPropertyName(node.field)); |
628 } | 630 } |
629 | 631 |
630 @override | 632 @override |
631 js.Assignment visitSetField(tree_ir.SetField node) { | 633 js.Assignment visitSetField(tree_ir.SetField node) { |
632 js.PropertyAccess field = | 634 js.PropertyAccess field = |
633 new js.PropertyAccess.field( | 635 new js.PropertyAccess( |
634 visitExpression(node.object), | 636 visitExpression(node.object), |
635 glue.instanceFieldPropertyName(node.field)); | 637 glue.instanceFieldPropertyName(node.field)); |
636 return new js.Assignment(field, visitExpression(node.value)); | 638 return new js.Assignment(field, visitExpression(node.value)); |
637 } | 639 } |
638 | 640 |
639 @override | 641 @override |
640 js.Expression visitGetStatic(tree_ir.GetStatic node) { | 642 js.Expression visitGetStatic(tree_ir.GetStatic node) { |
641 assert(node.element is FieldElement || node.element is FunctionElement); | 643 assert(node.element is FieldElement || node.element is FunctionElement); |
642 if (node.element is FunctionElement) { | 644 if (node.element is FunctionElement) { |
643 // Tear off a method. | 645 // Tear off a method. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 return js.js("typeof # === 'number' && Math.floor(#) === #", args); | 749 return js.js("typeof # === 'number' && Math.floor(#) === #", args); |
748 } | 750 } |
749 } | 751 } |
750 | 752 |
751 visitFunctionExpression(tree_ir.FunctionExpression node) { | 753 visitFunctionExpression(tree_ir.FunctionExpression node) { |
752 // FunctionExpressions are currently unused. | 754 // FunctionExpressions are currently unused. |
753 // We might need them if we want to emit raw JS nested functions. | 755 // We might need them if we want to emit raw JS nested functions. |
754 throw 'FunctionExpressions should not be used'; | 756 throw 'FunctionExpressions should not be used'; |
755 } | 757 } |
756 } | 758 } |
OLD | NEW |