Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1678053002: Fix super noSuchMethod handling. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 closure; 7 import '../closure.dart' as closure;
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/names.dart' show 9 import '../common/names.dart' show
10 Identifiers,
10 Names, 11 Names,
11 Selectors; 12 Selectors;
12 import '../common/tasks.dart' show 13 import '../common/tasks.dart' show
13 CompilerTask; 14 CompilerTask;
14 import '../compiler.dart' show 15 import '../compiler.dart' show
15 Compiler; 16 Compiler;
16 import '../constants/expressions.dart'; 17 import '../constants/expressions.dart';
17 import '../dart_types.dart'; 18 import '../dart_types.dart';
18 import '../elements/elements.dart'; 19 import '../elements/elements.dart';
19 import '../elements/modelx.dart' show 20 import '../elements/modelx.dart' show
(...skipping 1867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 ast.Send node, 1888 ast.Send node,
1888 MethodElement method, 1889 MethodElement method,
1889 _) { 1890 _) {
1890 return irBuilder.buildSuperMethodGet(method); 1891 return irBuilder.buildSuperMethodGet(method);
1891 } 1892 }
1892 1893
1893 @override 1894 @override
1894 ir.Primitive visitUnresolvedSuperGet( 1895 ir.Primitive visitUnresolvedSuperGet(
1895 ast.Send node, 1896 ast.Send node,
1896 Element element, _) { 1897 Element element, _) {
1897 return buildInstanceNoSuchMethod( 1898 return buildSuperNoSuchMethod(
1898 elements.getSelector(node), elements.getTypeMask(node), []); 1899 elements.getSelector(node), elements.getTypeMask(node), []);
1899 } 1900 }
1900 1901
1901 @override 1902 @override
1903 ir.Primitive visitUnresolvedSuperSet(
1904 ast.Send node,
1905 Element element,
1906 ast.Node rhs, _) {
1907 return buildSuperNoSuchMethod(
1908 elements.getSelector(node), elements.getTypeMask(node), [visit(rhs)]);
1909 }
1910
1911 @override
1902 ir.Primitive visitThisGet(ast.Identifier node, _) { 1912 ir.Primitive visitThisGet(ast.Identifier node, _) {
1903 if (irBuilder.state.thisParameter == null) { 1913 if (irBuilder.state.thisParameter == null) {
1904 // TODO(asgerf,johnniwinther): Should be in a visitInvalidThis method. 1914 // TODO(asgerf,johnniwinther): Should be in a visitInvalidThis method.
1905 // 'this' in static context. Just translate to null. 1915 // 'this' in static context. Just translate to null.
1906 assert(compiler.compilationFailed); 1916 assert(compiler.compilationFailed);
1907 return irBuilder.buildNullConstant(); 1917 return irBuilder.buildNullConstant();
1908 } 1918 }
1909 return irBuilder.buildThis(); 1919 return irBuilder.buildThis();
1910 } 1920 }
1911 1921
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 2431
2422 @override 2432 @override
2423 ir.Primitive visitSuperMethodIncompatibleInvoke( 2433 ir.Primitive visitSuperMethodIncompatibleInvoke(
2424 ast.Send node, 2434 ast.Send node,
2425 MethodElement method, 2435 MethodElement method,
2426 ast.NodeList arguments, 2436 ast.NodeList arguments,
2427 CallStructure callStructure, _) { 2437 CallStructure callStructure, _) {
2428 List<ir.Primitive> normalizedArguments = <ir.Primitive>[]; 2438 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
2429 CallStructure normalizedCallStructure = 2439 CallStructure normalizedCallStructure =
2430 translateDynamicArguments(arguments, callStructure, normalizedArguments); 2440 translateDynamicArguments(arguments, callStructure, normalizedArguments);
2431 return buildInstanceNoSuchMethod( 2441 return buildSuperNoSuchMethod(
2432 new Selector.call(method.memberName, normalizedCallStructure), 2442 new Selector.call(method.memberName, normalizedCallStructure),
2433 elements.getTypeMask(node), 2443 elements.getTypeMask(node),
2434 normalizedArguments); 2444 normalizedArguments);
2435 } 2445 }
2436 2446
2437 @override 2447 @override
2438 ir.Primitive visitUnresolvedSuperInvoke( 2448 ir.Primitive visitUnresolvedSuperInvoke(
2439 ast.Send node, 2449 ast.Send node,
2440 Element element, 2450 Element element,
2441 ast.NodeList argumentsNode, 2451 ast.NodeList argumentsNode,
2442 Selector selector, _) { 2452 Selector selector, _) {
2443 List<ir.Primitive> arguments = <ir.Primitive>[]; 2453 List<ir.Primitive> arguments = <ir.Primitive>[];
2444 CallStructure callStructure = translateDynamicArguments( 2454 CallStructure callStructure = translateDynamicArguments(
2445 argumentsNode, selector.callStructure, arguments); 2455 argumentsNode, selector.callStructure, arguments);
2446 // TODO(johnniwinther): Supply a member name to the visit function instead 2456 // TODO(johnniwinther): Supply a member name to the visit function instead
2447 // of looking it up in elements. 2457 // of looking it up in elements.
2448 return buildInstanceNoSuchMethod( 2458 return buildSuperNoSuchMethod(
2449 new Selector.call(elements.getSelector(node).memberName, callStructure), 2459 new Selector.call(elements.getSelector(node).memberName, callStructure),
2450 elements.getTypeMask(node), 2460 elements.getTypeMask(node),
2451 arguments); 2461 arguments);
2452 } 2462 }
2453 2463
2454 @override 2464 @override
2455 ir.Primitive visitThisInvoke( 2465 ir.Primitive visitThisInvoke(
2456 ast.Send node, 2466 ast.Send node,
2457 ast.NodeList arguments, 2467 ast.NodeList arguments,
2458 CallStructure callStructure, 2468 CallStructure callStructure,
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2849 case CompoundSetter.INVALID: 2859 case CompoundSetter.INVALID:
2850 irBuilder.buildStaticNoSuchMethod( 2860 irBuilder.buildStaticNoSuchMethod(
2851 new Selector.setter(new Name(setter.name, setter.library)), 2861 new Selector.setter(new Name(setter.name, setter.library)),
2852 <ir.Primitive>[result]); 2862 <ir.Primitive>[result]);
2853 return; 2863 return;
2854 } 2864 }
2855 }); 2865 });
2856 } 2866 }
2857 2867
2858 ir.Primitive buildSuperNoSuchGetter(Element element, TypeMask mask) { 2868 ir.Primitive buildSuperNoSuchGetter(Element element, TypeMask mask) {
2859 return buildInstanceNoSuchMethod( 2869 return buildSuperNoSuchMethod(
2860 new Selector.getter(new Name(element.name, element.library)), 2870 new Selector.getter(new Name(element.name, element.library)),
2861 mask, 2871 mask,
2862 const <ir.Primitive>[]); 2872 const <ir.Primitive>[]);
2863 } 2873 }
2864 2874
2865 ir.Primitive buildSuperNoSuchSetter(Element element, 2875 ir.Primitive buildSuperNoSuchSetter(Element element,
2866 TypeMask mask, 2876 TypeMask mask,
2867 ir.Primitive value) { 2877 ir.Primitive value) {
2868 return buildInstanceNoSuchMethod( 2878 return buildSuperNoSuchMethod(
2869 new Selector.setter(new Name(element.name, element.library)), 2879 new Selector.setter(new Name(element.name, element.library)),
2870 mask, 2880 mask,
2871 <ir.Primitive>[value]); 2881 <ir.Primitive>[value]);
2872 } 2882 }
2873 2883
2874 @override 2884 @override
2875 ir.Primitive handleSuperCompounds( 2885 ir.Primitive handleSuperCompounds(
2876 ast.SendSet node, 2886 ast.SendSet node,
2877 Element getter, 2887 Element getter,
2878 CompoundGetter getterKind, 2888 CompoundGetter getterKind,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 Element indexSetFunction, 3021 Element indexSetFunction,
3012 ast.Node index, 3022 ast.Node index,
3013 CompoundRhs rhs, 3023 CompoundRhs rhs,
3014 arg, 3024 arg,
3015 {bool isGetterValid, 3025 {bool isGetterValid,
3016 bool isSetterValid}) { 3026 bool isSetterValid}) {
3017 ir.Primitive indexValue = visit(index); 3027 ir.Primitive indexValue = visit(index);
3018 return translateCompounds(node, () { 3028 return translateCompounds(node, () {
3019 return isGetterValid 3029 return isGetterValid
3020 ? irBuilder.buildSuperIndex(indexFunction, indexValue) 3030 ? irBuilder.buildSuperIndex(indexFunction, indexValue)
3021 : buildInstanceNoSuchMethod( 3031 : buildSuperNoSuchMethod(
3022 new Selector.index(), 3032 new Selector.index(),
3023 elements.getGetterTypeMaskInComplexSendSet(node), 3033 elements.getGetterTypeMaskInComplexSendSet(node),
3024 <ir.Primitive>[indexValue]); 3034 <ir.Primitive>[indexValue]);
3025 }, rhs, (ir.Primitive result) { 3035 }, rhs, (ir.Primitive result) {
3026 if (isSetterValid) { 3036 if (isSetterValid) {
3027 irBuilder.buildSuperIndexSet(indexSetFunction, indexValue, result); 3037 irBuilder.buildSuperIndexSet(indexSetFunction, indexValue, result);
3028 } else { 3038 } else {
3029 buildInstanceNoSuchMethod( 3039 buildSuperNoSuchMethod(
3030 new Selector.indexSet(), 3040 new Selector.indexSet(),
3031 elements.getTypeMask(node), 3041 elements.getTypeMask(node),
3032 <ir.Primitive>[indexValue, result]); 3042 <ir.Primitive>[indexValue, result]);
3033 } 3043 }
3034 }); 3044 });
3035 } 3045 }
3036 3046
3037 /// Build code to handle foreign code, that is, native JavaScript code, or 3047 /// Build code to handle foreign code, that is, native JavaScript code, or
3038 /// builtin values and operations of the backend. 3048 /// builtin values and operations of the backend.
3039 ir.Primitive handleForeignCode(ast.Send node, 3049 ir.Primitive handleForeignCode(ast.Send node,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 sourceInformation: sourceInformationBuilder.buildGet(node)); 3330 sourceInformation: sourceInformationBuilder.buildGet(node));
3321 } 3331 }
3322 3332
3323 ir.Primitive visitThrow(ast.Throw node) { 3333 ir.Primitive visitThrow(ast.Throw node) {
3324 assert(irBuilder.isOpen); 3334 assert(irBuilder.isOpen);
3325 // This function is not called for throw expressions occurring as 3335 // This function is not called for throw expressions occurring as
3326 // statements. 3336 // statements.
3327 return irBuilder.buildNonTailThrow(visit(node.expression)); 3337 return irBuilder.buildNonTailThrow(visit(node.expression));
3328 } 3338 }
3329 3339
3330 ir.Primitive buildInstanceNoSuchMethod(Selector selector, 3340 ir.Primitive buildSuperNoSuchMethod(Selector selector,
3331 TypeMask mask, 3341 TypeMask mask,
3332 List<ir.Primitive> arguments) { 3342 List<ir.Primitive> arguments) {
3333 return irBuilder.buildDynamicInvocation( 3343 ClassElement cls = elements.analyzedElement.enclosingClass;
3334 irBuilder.buildThis(), 3344 MethodElement element = cls.lookupSuperMember(Identifiers.noSuchMethod_);
3335 Selectors.noSuchMethod_, 3345 if (!Selectors.noSuchMethod_.signatureApplies(element)) {
3336 mask, 3346 element = compiler.coreClasses.objectClass.lookupMember(
3347 Identifiers.noSuchMethod_);
3348 }
3349 return irBuilder.buildSuperMethodInvocation(
3350 element,
3351 Selectors.noSuchMethod_.callStructure,
3337 [irBuilder.buildInvocationMirror(selector, arguments)]); 3352 [irBuilder.buildInvocationMirror(selector, arguments)]);
3338 } 3353 }
3339 3354
3340 @override 3355 @override
3341 ir.Primitive visitUnresolvedCompound( 3356 ir.Primitive visitUnresolvedCompound(
3342 ast.Send node, 3357 ast.Send node,
3343 Element element, 3358 Element element,
3344 op.AssignmentOperator operator, 3359 op.AssignmentOperator operator,
3345 ast.Node rhs, _) { 3360 ast.Node rhs, _) {
3346 // TODO(asgerf): What is unresolved? The getter and/or the setter? 3361 // TODO(asgerf): What is unresolved? The getter and/or the setter?
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3435 return irBuilder.buildStaticNoSuchMethod(elements.getSelector(node), 3450 return irBuilder.buildStaticNoSuchMethod(elements.getSelector(node),
3436 [visit(rhs)]); 3451 [visit(rhs)]);
3437 } 3452 }
3438 3453
3439 @override 3454 @override
3440 ir.Primitive visitUnresolvedSuperIndex( 3455 ir.Primitive visitUnresolvedSuperIndex(
3441 ast.Send node, 3456 ast.Send node,
3442 Element function, 3457 Element function,
3443 ast.Node index, _) { 3458 ast.Node index, _) {
3444 // Assume the index getter is missing. 3459 // Assume the index getter is missing.
3445 return buildInstanceNoSuchMethod( 3460 return buildSuperNoSuchMethod(
3446 new Selector.index(), elements.getTypeMask(node), [visit(index)]); 3461 new Selector.index(), elements.getTypeMask(node), [visit(index)]);
3447 } 3462 }
3448 3463
3449 @override 3464 @override
3450 ir.Primitive visitUnresolvedSuperBinary( 3465 ir.Primitive visitUnresolvedSuperBinary(
3451 ast.Send node, 3466 ast.Send node,
3452 Element element, 3467 Element element,
3453 op.BinaryOperator operator, 3468 op.BinaryOperator operator,
3454 ast.Node argument, _) { 3469 ast.Node argument, _) {
3455 return buildInstanceNoSuchMethod( 3470 return buildSuperNoSuchMethod(
3456 elements.getSelector(node), 3471 elements.getSelector(node),
3457 elements.getTypeMask(node), 3472 elements.getTypeMask(node),
3458 [visit(argument)]); 3473 [visit(argument)]);
3459 } 3474 }
3460 3475
3461 @override 3476 @override
3462 ir.Primitive visitUnresolvedSuperUnary( 3477 ir.Primitive visitUnresolvedSuperUnary(
3463 ast.Send node, 3478 ast.Send node,
3464 op.UnaryOperator operator, 3479 op.UnaryOperator operator,
3465 Element element, _) { 3480 Element element, _) {
3466 return buildInstanceNoSuchMethod( 3481 return buildSuperNoSuchMethod(
3467 elements.getSelector(node), elements.getTypeMask(node), []); 3482 elements.getSelector(node), elements.getTypeMask(node), []);
3468 } 3483 }
3469 3484
3470 @override 3485 @override
3471 ir.Primitive bulkHandleNode(ast.Node node, String message, _) { 3486 ir.Primitive bulkHandleNode(ast.Node node, String message, _) {
3472 return giveup(node, "Unhandled node: ${message.replaceAll('#', '$node')}"); 3487 return giveup(node, "Unhandled node: ${message.replaceAll('#', '$node')}");
3473 } 3488 }
3474 3489
3475 @override 3490 @override
3476 ir.Primitive bulkHandleError(ast.Node node, ErroneousElement error, _) { 3491 ir.Primitive bulkHandleError(ast.Node node, ErroneousElement error, _) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3543 return irBuilder.buildStaticNoSuchMethod( 3558 return irBuilder.buildStaticNoSuchMethod(
3544 new Selector.setter(field.memberName), 3559 new Selector.setter(field.memberName),
3545 [visit(rhs)]); 3560 [visit(rhs)]);
3546 } 3561 }
3547 3562
3548 @override 3563 @override
3549 ir.Primitive visitFinalSuperFieldSet( 3564 ir.Primitive visitFinalSuperFieldSet(
3550 ast.SendSet node, 3565 ast.SendSet node,
3551 FieldElement field, 3566 FieldElement field,
3552 ast.Node rhs, _) { 3567 ast.Node rhs, _) {
3553 return buildInstanceNoSuchMethod( 3568 return buildSuperNoSuchMethod(
3554 new Selector.setter(field.memberName), 3569 new Selector.setter(field.memberName),
3555 elements.getTypeMask(node), 3570 elements.getTypeMask(node),
3556 [visit(rhs)]); 3571 [visit(rhs)]);
3557 } 3572 }
3558 3573
3559 @override 3574 @override
3560 ir.Primitive handleImmutableLocalSet( 3575 ir.Primitive handleImmutableLocalSet(
3561 ast.SendSet node, 3576 ast.SendSet node,
3562 LocalElement local, 3577 LocalElement local,
3563 ast.Node rhs, _) { 3578 ast.Node rhs, _) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 new Selector.call(setter.memberName, callStructure), 3625 new Selector.call(setter.memberName, callStructure),
3611 arguments); 3626 arguments);
3612 } 3627 }
3613 3628
3614 @override 3629 @override
3615 ir.Primitive visitSuperGetterSet( 3630 ir.Primitive visitSuperGetterSet(
3616 ast.SendSet node, 3631 ast.SendSet node,
3617 GetterElement getter, 3632 GetterElement getter,
3618 ast.Node rhs, 3633 ast.Node rhs,
3619 _) { 3634 _) {
3620 return buildInstanceNoSuchMethod( 3635 return buildSuperNoSuchMethod(
3621 new Selector.setter(getter.memberName), 3636 new Selector.setter(getter.memberName),
3622 elements.getTypeMask(node), 3637 elements.getTypeMask(node),
3623 [visit(rhs)]); 3638 [visit(rhs)]);
3624 } 3639 }
3625 3640
3626 @override 3641 @override
3627 ir.Primitive visitSuperMethodSet( 3642 ir.Primitive visitSuperMethodSet(
3628 ast.Send node, 3643 ast.Send node,
3629 MethodElement method, 3644 MethodElement method,
3630 ast.Node rhs, 3645 ast.Node rhs,
3631 _) { 3646 _) {
3632 return buildInstanceNoSuchMethod( 3647 return buildSuperNoSuchMethod(
3633 new Selector.setter(method.memberName), 3648 new Selector.setter(method.memberName),
3634 elements.getTypeMask(node), 3649 elements.getTypeMask(node),
3635 [visit(rhs)]); 3650 [visit(rhs)]);
3636 } 3651 }
3637 3652
3638 @override 3653 @override
3639 ir.Primitive visitSuperSetterGet( 3654 ir.Primitive visitSuperSetterGet(
3640 ast.Send node, 3655 ast.Send node,
3641 SetterElement setter, _) { 3656 SetterElement setter, _) {
3642 return buildInstanceNoSuchMethod( 3657 return buildSuperNoSuchMethod(
3643 new Selector.setter(setter.memberName), 3658 new Selector.setter(setter.memberName),
3644 elements.getTypeMask(node), 3659 elements.getTypeMask(node),
3645 []); 3660 []);
3646 } 3661 }
3647 3662
3648 @override 3663 @override
3649 ir.Primitive visitSuperSetterInvoke( 3664 ir.Primitive visitSuperSetterInvoke(
3650 ast.Send node, 3665 ast.Send node,
3651 SetterElement setter, 3666 SetterElement setter,
3652 ast.NodeList argumentsNode, 3667 ast.NodeList argumentsNode,
3653 CallStructure callStructure, _) { 3668 CallStructure callStructure, _) {
3654 List<ir.Primitive> arguments = <ir.Primitive>[]; 3669 List<ir.Primitive> arguments = <ir.Primitive>[];
3655 callStructure = 3670 callStructure =
3656 translateDynamicArguments(argumentsNode, callStructure, arguments); 3671 translateDynamicArguments(argumentsNode, callStructure, arguments);
3657 return buildInstanceNoSuchMethod( 3672 return buildSuperNoSuchMethod(
3658 new Selector.call(setter.memberName, callStructure), 3673 new Selector.call(setter.memberName, callStructure),
3659 elements.getTypeMask(node), 3674 elements.getTypeMask(node),
3660 arguments); 3675 arguments);
3661 } 3676 }
3662 3677
3663 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { 3678 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) {
3664 try { 3679 try {
3665 return action(); 3680 return action();
3666 } catch(e) { 3681 } catch(e) {
3667 if (e == ABORT_IRNODE_BUILDER) { 3682 if (e == ABORT_IRNODE_BUILDER) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3900 } 3915 }
3901 3916
3902 Element get closureConverter { 3917 Element get closureConverter {
3903 return _backend.helpers.closureConverter; 3918 return _backend.helpers.closureConverter;
3904 } 3919 }
3905 3920
3906 void addNativeMethod(FunctionElement function) { 3921 void addNativeMethod(FunctionElement function) {
3907 _backend.emitter.nativeEmitter.nativeMethods.add(function); 3922 _backend.emitter.nativeEmitter.nativeMethods.add(function);
3908 } 3923 }
3909 } 3924 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698