| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_builder_task; | 5 library dart2js.ir_builder_task; |
| 6 | 6 |
| 7 import '../closure.dart' as closurelib; | 7 import '../closure.dart' as closurelib; |
| 8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show | 10 import '../common/names.dart' show |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 // in production mode. | 699 // in production mode. |
| 700 // Assertions can only occur in expression statements, so no value needs | 700 // Assertions can only occur in expression statements, so no value needs |
| 701 // to be returned. | 701 // to be returned. |
| 702 return null; | 702 return null; |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 | 705 |
| 706 // ## Sends ## | 706 // ## Sends ## |
| 707 @override | 707 @override |
| 708 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) { | 708 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) { |
| 709 giveup(node, 'deferred access is not implemented'); | 709 buildCheckDeferredIsLoaded(prefix, node, |
| 710 sourceInformationBuilder.buildCall(node, node.selector)); |
| 711 } |
| 712 |
| 713 ir.Primitive buildCheckDeferredIsLoaded(PrefixElement prefix, Spannable node, |
| 714 SourceInformation sourceInformation) { |
| 715 if (prefix == null) return null; |
| 716 JavaScriptBackend backend = compiler.backend; |
| 717 return irBuilder.buildStaticFunctionInvocation( |
| 718 backend.helpers.checkDeferredIsLoaded, |
| 719 CallStructure.TWO_ARGS, <ir.Primitive>[ |
| 720 irBuilder.buildStringConstant( |
| 721 compiler.deferredLoadTask.getImportDeferName(node, prefix)), |
| 722 irBuilder.buildStringConstant('${prefix.deferredImport.uri}'), |
| 723 ], sourceInformation: sourceInformation); |
| 710 } | 724 } |
| 711 | 725 |
| 712 ir.Primitive visitNamedArgument(ast.NamedArgument node) { | 726 ir.Primitive visitNamedArgument(ast.NamedArgument node) { |
| 713 assert(irBuilder.isOpen); | 727 assert(irBuilder.isOpen); |
| 714 return visit(node.expression); | 728 return visit(node.expression); |
| 715 } | 729 } |
| 716 | 730 |
| 717 @override | 731 @override |
| 718 ir.Primitive visitExpressionInvoke(ast.Send node, | 732 ir.Primitive visitExpressionInvoke(ast.Send node, |
| 719 ast.Node expression, | 733 ast.Node expression, |
| (...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2574 | 2588 |
| 2575 FunctionElement get stringifyFunction { | 2589 FunctionElement get stringifyFunction { |
| 2576 return _backend.helpers.stringInterpolationHelper; | 2590 return _backend.helpers.stringInterpolationHelper; |
| 2577 } | 2591 } |
| 2578 | 2592 |
| 2579 FunctionElement get throwTypeErrorHelper => _backend.helpers.throwTypeError; | 2593 FunctionElement get throwTypeErrorHelper => _backend.helpers.throwTypeError; |
| 2580 Element get throwNoSuchMethod => _backend.helpers.throwNoSuchMethod; | 2594 Element get throwNoSuchMethod => _backend.helpers.throwNoSuchMethod; |
| 2581 | 2595 |
| 2582 ClassElement get nullClass => _compiler.coreClasses.nullClass; | 2596 ClassElement get nullClass => _compiler.coreClasses.nullClass; |
| 2583 | 2597 |
| 2598 Element get loadLibraryFunction => _compiler.loadLibraryFunction; |
| 2599 String getImportDeferName(PrefixElement prefix) { |
| 2600 return _compiler.deferredLoadTask.getImportDeferName(null, prefix); |
| 2601 } |
| 2602 |
| 2584 DartType unaliasType(DartType type) => type.unaliased; | 2603 DartType unaliasType(DartType type) => type.unaliased; |
| 2585 | 2604 |
| 2586 TypeMask getTypeMaskForForeign(NativeBehavior behavior) { | 2605 TypeMask getTypeMaskForForeign(NativeBehavior behavior) { |
| 2587 if (behavior == null) { | 2606 if (behavior == null) { |
| 2588 return _backend.dynamicType; | 2607 return _backend.dynamicType; |
| 2589 } | 2608 } |
| 2590 return TypeMaskFactory.fromNativeBehavior(behavior, _compiler); | 2609 return TypeMaskFactory.fromNativeBehavior(behavior, _compiler); |
| 2591 } | 2610 } |
| 2592 | 2611 |
| 2593 FieldElement locateSingleField(Selector selector, TypeMask type) { | 2612 FieldElement locateSingleField(Selector selector, TypeMask type) { |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3337 } | 3356 } |
| 3338 | 3357 |
| 3339 @override | 3358 @override |
| 3340 ir.Primitive handleConstructorInvoke( | 3359 ir.Primitive handleConstructorInvoke( |
| 3341 ast.NewExpression node, | 3360 ast.NewExpression node, |
| 3342 ConstructorElement constructor, | 3361 ConstructorElement constructor, |
| 3343 DartType type, | 3362 DartType type, |
| 3344 ast.NodeList argumentsNode, | 3363 ast.NodeList argumentsNode, |
| 3345 CallStructure callStructure, | 3364 CallStructure callStructure, |
| 3346 _) { | 3365 _) { |
| 3366 |
| 3367 ast.Send send = node.send; |
| 3368 // If an allocation refers to a type using a deferred import prefix (e.g. |
| 3369 // `new lib.A()`), we must ensure that the deferred import has already been |
| 3370 // loaded. |
| 3371 var prefix = compiler.deferredLoadTask.deferredPrefixElement( |
| 3372 send, elements); |
| 3373 if (prefix != null) { |
| 3374 buildCheckDeferredIsLoaded(prefix, send, |
| 3375 sourceInformationBuilder.buildCall(send, send.selector)); |
| 3376 } |
| 3377 |
| 3347 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit); | 3378 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit); |
| 3348 // Use default values from the effective target, not the immediate target. | 3379 // Use default values from the effective target, not the immediate target. |
| 3349 ConstructorElement target = constructor.effectiveTarget; | 3380 ConstructorElement target = constructor.effectiveTarget; |
| 3350 callStructure = | 3381 |
| 3351 normalizeStaticArguments(callStructure, target, arguments); | 3382 // We also emit deferred import checks when using redirecting factories that |
| 3383 // refer to deferred prefixes. |
| 3384 if (constructor.isRedirectingFactory && !constructor.isCyclicRedirection) { |
| 3385 ConstructorElement current = constructor; |
| 3386 while (current.isRedirectingFactory) { |
| 3387 var prefix = current.redirectionDeferredPrefix; |
| 3388 if (prefix != null) { |
| 3389 buildCheckDeferredIsLoaded(prefix, send, |
| 3390 sourceInformationBuilder.buildCall(send, send.selector)); |
| 3391 } |
| 3392 current = current.immediateRedirectionTarget; |
| 3393 } |
| 3394 } |
| 3395 |
| 3396 callStructure = normalizeStaticArguments(callStructure, target, arguments); |
| 3352 TypeMask allocationSiteType; | 3397 TypeMask allocationSiteType; |
| 3353 ast.Node send = node.send; | 3398 |
| 3354 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || | 3399 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || |
| 3355 Elements.isGrowableListConstructorCall(constructor, send, compiler) || | 3400 Elements.isGrowableListConstructorCall(constructor, send, compiler) || |
| 3356 Elements.isFilledListConstructorCall(constructor, send, compiler) || | 3401 Elements.isFilledListConstructorCall(constructor, send, compiler) || |
| 3357 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { | 3402 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { |
| 3358 allocationSiteType = getAllocationSiteType(send); | 3403 allocationSiteType = getAllocationSiteType(send); |
| 3359 } | 3404 } |
| 3360 return irBuilder.buildConstructorInvocation( | 3405 return irBuilder.buildConstructorInvocation( |
| 3361 target, | 3406 target, |
| 3362 callStructure, | 3407 callStructure, |
| 3363 constructor.computeEffectiveTargetType(type), | 3408 constructor.computeEffectiveTargetType(type), |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3664 callStructure = translateStaticArguments(argumentsNode, function, | 3709 callStructure = translateStaticArguments(argumentsNode, function, |
| 3665 callStructure, arguments); | 3710 callStructure, arguments); |
| 3666 return irBuilder.buildStaticFunctionInvocation(function, | 3711 return irBuilder.buildStaticFunctionInvocation(function, |
| 3667 callStructure, | 3712 callStructure, |
| 3668 arguments, | 3713 arguments, |
| 3669 sourceInformation: | 3714 sourceInformation: |
| 3670 sourceInformationBuilder.buildCall(node, node.selector)); | 3715 sourceInformationBuilder.buildCall(node, node.selector)); |
| 3671 } | 3716 } |
| 3672 } | 3717 } |
| 3673 } | 3718 } |
| OLD | NEW |