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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 registry.registerStaticInvocation(target.declaration); | 200 registry.registerStaticInvocation(target.declaration); |
201 if (target == glue.getInterceptorMethod) { | 201 if (target == glue.getInterceptorMethod) { |
202 // This generates a call to the specialized interceptor function, which | 202 // This generates a call to the specialized interceptor function, which |
203 // does not have a specialized element yet, but is emitted as a stub from | 203 // does not have a specialized element yet, but is emitted as a stub from |
204 // the emitter in [InterceptorStubGenerator]. | 204 // the emitter in [InterceptorStubGenerator]. |
205 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] | 205 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] |
206 // instead of an [Element] and model the getInterceptor functions as | 206 // instead of an [Element] and model the getInterceptor functions as |
207 // [Entity]s or add a specialized Tree-IR node for interceptor calls. | 207 // [Entity]s or add a specialized Tree-IR node for interceptor calls. |
208 registry.registerUseInterceptor(); | 208 registry.registerUseInterceptor(); |
209 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); | 209 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); |
210 return js.propertyCall(interceptorLibrary, selector.name, arguments); | 210 return js.propertyCall(interceptorLibrary, js.string(selector.name), |
211 arguments); | |
asgerf
2015/06/24 15:59:55
Don't worry about this code, I forgot to remove it
| |
211 } else { | 212 } else { |
212 js.Expression elementAccess = glue.staticFunctionAccess(target); | 213 js.Expression elementAccess = glue.staticFunctionAccess(target); |
213 return new js.Call(elementAccess, arguments, | 214 return new js.Call(elementAccess, arguments, |
214 sourceInformation: sourceInformation); | 215 sourceInformation: sourceInformation); |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 @override | 219 @override |
219 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { | 220 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { |
220 if (node.constant != null) return giveup(node); | 221 if (node.constant != null) return giveup(node); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // | 342 // |
342 // checkSubtype(value, $isT, typeArgs, $asT) | 343 // checkSubtype(value, $isT, typeArgs, $asT) |
343 // subtypeCast(value, $isT, typeArgs, $asT) | 344 // subtypeCast(value, $isT, typeArgs, $asT) |
344 // | 345 // |
345 // Any of the last two arguments may be null if there are no type | 346 // Any of the last two arguments may be null if there are no type |
346 // arguments, and/or if no substitution is required. | 347 // arguments, and/or if no substitution is required. |
347 Element function = node.isTypeTest | 348 Element function = node.isTypeTest |
348 ? glue.getCheckSubtype() | 349 ? glue.getCheckSubtype() |
349 : glue.getSubtypeCast(); | 350 : glue.getSubtypeCast(); |
350 | 351 |
351 js.Expression isT = js.string(glue.getTypeTestTag(type)); | 352 js.Expression isT = js.quoteName(glue.getTypeTestTag(type)); |
352 | 353 |
353 js.Expression typeArgumentArray = typeArguments.isNotEmpty | 354 js.Expression typeArgumentArray = typeArguments.isNotEmpty |
354 ? new js.ArrayInitializer(typeArguments) | 355 ? new js.ArrayInitializer(typeArguments) |
355 : new js.LiteralNull(); | 356 : new js.LiteralNull(); |
356 | 357 |
357 js.Expression asT = glue.hasStrictSubtype(clazz) | 358 js.Expression asT = glue.hasStrictSubtype(clazz) |
358 ? js.string(glue.getTypeSubstitutionTag(clazz)) | 359 ? js.quoteName(glue.getTypeSubstitutionTag(clazz)) |
359 : new js.LiteralNull(); | 360 : new js.LiteralNull(); |
360 | 361 |
361 return buildStaticHelperInvocation( | 362 return buildStaticHelperInvocation( |
362 function, | 363 function, |
363 <js.Expression>[value, isT, typeArgumentArray, asT]); | 364 <js.Expression>[value, isT, typeArgumentArray, asT]); |
364 } else if (type is TypeVariableType || type is FunctionType) { | 365 } else if (type is TypeVariableType || type is FunctionType) { |
365 glue.registerIsCheck(type, registry); | 366 glue.registerIsCheck(type, registry); |
366 | 367 |
367 Element function = node.isTypeTest | 368 Element function = node.isTypeTest |
368 ? glue.getCheckSubtypeOfRuntimeType() | 369 ? glue.getCheckSubtypeOfRuntimeType() |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 <js.Expression>[instance, typeArguments]); | 576 <js.Expression>[instance, typeArguments]); |
576 } else { | 577 } else { |
577 return instance; | 578 return instance; |
578 } | 579 } |
579 } | 580 } |
580 | 581 |
581 @override | 582 @override |
582 js.Expression visitCreateInvocationMirror( | 583 js.Expression visitCreateInvocationMirror( |
583 tree_ir.CreateInvocationMirror node) { | 584 tree_ir.CreateInvocationMirror node) { |
584 js.Expression name = js.string(node.selector.name); | 585 js.Expression name = js.string(node.selector.name); |
585 js.Expression internalName = js.string(glue.invocationName(node.selector)); | 586 js.Expression internalName = |
587 js.quoteName(glue.invocationName(node.selector)); | |
586 js.Expression kind = js.number(node.selector.invocationMirrorKind); | 588 js.Expression kind = js.number(node.selector.invocationMirrorKind); |
587 js.Expression arguments = new js.ArrayInitializer( | 589 js.Expression arguments = new js.ArrayInitializer( |
588 visitExpressionList(node.arguments)); | 590 visitExpressionList(node.arguments)); |
589 js.Expression argumentNames = new js.ArrayInitializer( | 591 js.Expression argumentNames = new js.ArrayInitializer( |
590 node.selector.namedArguments.map(js.string).toList(growable: false)); | 592 node.selector.namedArguments.map(js.string).toList(growable: false)); |
591 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, | 593 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, |
592 <js.Expression>[name, internalName, kind, arguments, argumentNames]); | 594 <js.Expression>[name, internalName, kind, arguments, argumentNames]); |
593 } | 595 } |
594 | 596 |
595 @override | 597 @override |
596 js.Expression visitInterceptor(tree_ir.Interceptor node) { | 598 js.Expression visitInterceptor(tree_ir.Interceptor node) { |
597 glue.registerUseInterceptorInCodegen(); | 599 glue.registerUseInterceptorInCodegen(); |
598 registry.registerSpecializedGetInterceptor(node.interceptedClasses); | 600 registry.registerSpecializedGetInterceptor(node.interceptedClasses); |
599 String helperName = glue.getInterceptorName(node.interceptedClasses); | 601 js.Name helperName = glue.getInterceptorName(node.interceptedClasses); |
600 js.Expression globalHolder = glue.getInterceptorLibrary(); | 602 js.Expression globalHolder = glue.getInterceptorLibrary(); |
601 return js.js('#.#(#)', | 603 return js.js('#.#(#)', |
602 [globalHolder, helperName, visitExpression(node.input)]); | 604 [globalHolder, helperName, visitExpression(node.input)]); |
603 } | 605 } |
604 | 606 |
605 @override | 607 @override |
606 js.Expression visitGetField(tree_ir.GetField node) { | 608 js.Expression visitGetField(tree_ir.GetField node) { |
607 return new js.PropertyAccess.field( | 609 return new js.PropertyAccess( |
608 visitExpression(node.object), | 610 visitExpression(node.object), |
609 glue.instanceFieldPropertyName(node.field)); | 611 glue.instanceFieldPropertyName(node.field)); |
610 } | 612 } |
611 | 613 |
612 @override | 614 @override |
613 js.Assignment visitSetField(tree_ir.SetField node) { | 615 js.Assignment visitSetField(tree_ir.SetField node) { |
614 js.PropertyAccess field = | 616 js.PropertyAccess field = |
615 new js.PropertyAccess.field( | 617 new js.PropertyAccess( |
616 visitExpression(node.object), | 618 visitExpression(node.object), |
617 glue.instanceFieldPropertyName(node.field)); | 619 glue.instanceFieldPropertyName(node.field)); |
618 return new js.Assignment(field, visitExpression(node.value)); | 620 return new js.Assignment(field, visitExpression(node.value)); |
619 } | 621 } |
620 | 622 |
621 @override | 623 @override |
622 js.Expression visitGetStatic(tree_ir.GetStatic node) { | 624 js.Expression visitGetStatic(tree_ir.GetStatic node) { |
623 assert(node.element is FieldElement || node.element is FunctionElement); | 625 assert(node.element is FieldElement || node.element is FunctionElement); |
624 if (node.element is FunctionElement) { | 626 if (node.element is FunctionElement) { |
625 // Tear off a method. | 627 // Tear off a method. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 return js.js("typeof # === 'number' && Math.floor(#) === #", args); | 752 return js.js("typeof # === 'number' && Math.floor(#) === #", args); |
751 } | 753 } |
752 } | 754 } |
753 | 755 |
754 visitFunctionExpression(tree_ir.FunctionExpression node) { | 756 visitFunctionExpression(tree_ir.FunctionExpression node) { |
755 // FunctionExpressions are currently unused. | 757 // FunctionExpressions are currently unused. |
756 // We might need them if we want to emit raw JS nested functions. | 758 // We might need them if we want to emit raw JS nested functions. |
757 throw 'FunctionExpressions should not be used'; | 759 throw 'FunctionExpressions should not be used'; |
758 } | 760 } |
759 } | 761 } |
OLD | NEW |