| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/codegen.dart' show CodegenRegistry; | 9 import '../common/codegen.dart' show CodegenRegistry; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 close(new HGoto()).addSuccessor(block); | 712 close(new HGoto()).addSuccessor(block); |
| 713 | 713 |
| 714 open(block); | 714 open(block); |
| 715 } | 715 } |
| 716 | 716 |
| 717 void closeFunction() { | 717 void closeFunction() { |
| 718 if (!isAborted()) closeAndGotoExit(new HGoto()); | 718 if (!isAborted()) closeAndGotoExit(new HGoto()); |
| 719 graph.finalize(); | 719 graph.finalize(); |
| 720 } | 720 } |
| 721 | 721 |
| 722 /// Pushes a boolean checking [expression] against null. | |
| 723 pushCheckNull(HInstruction expression) { | |
| 724 push(new HIdentity(expression, graph.addConstantNull(closedWorld), null, | |
| 725 commonMasks.boolType)); | |
| 726 } | |
| 727 | |
| 728 @override | 722 @override |
| 729 void defaultExpression(ir.Expression expression) { | 723 void defaultExpression(ir.Expression expression) { |
| 730 // TODO(het): This is only to get tests working. | 724 // TODO(het): This is only to get tests working. |
| 731 _trap('Unhandled ir.${expression.runtimeType} $expression'); | 725 _trap('Unhandled ir.${expression.runtimeType} $expression'); |
| 732 } | 726 } |
| 733 | 727 |
| 734 @override | 728 @override |
| 735 void defaultStatement(ir.Statement statement) { | 729 void defaultStatement(ir.Statement statement) { |
| 736 _trap('Unhandled ir.${statement.runtimeType} $statement'); | 730 _trap('Unhandled ir.${statement.runtimeType} $statement'); |
| 737 pop(); | 731 pop(); |
| (...skipping 2143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 } | 2875 } |
| 2882 | 2876 |
| 2883 @override | 2877 @override |
| 2884 void visitFunctionExpression(ir.FunctionExpression funcExpression) { | 2878 void visitFunctionExpression(ir.FunctionExpression funcExpression) { |
| 2885 funcExpression.function.accept(this); | 2879 funcExpression.function.accept(this); |
| 2886 } | 2880 } |
| 2887 | 2881 |
| 2888 // TODO(het): Decide when to inline | 2882 // TODO(het): Decide when to inline |
| 2889 @override | 2883 @override |
| 2890 void visitMethodInvocation(ir.MethodInvocation invocation) { | 2884 void visitMethodInvocation(ir.MethodInvocation invocation) { |
| 2891 // Handle `x == null` specially. When these come from null-aware operators, | |
| 2892 // there is no mapping in the astAdapter. | |
| 2893 if (_handleEqualsNull(invocation)) return; | |
| 2894 invocation.receiver.accept(this); | 2885 invocation.receiver.accept(this); |
| 2895 HInstruction receiver = pop(); | 2886 HInstruction receiver = pop(); |
| 2896 Selector selector = _elementMap.getSelector(invocation); | 2887 Selector selector = _elementMap.getSelector(invocation); |
| 2897 _pushDynamicInvocation( | 2888 _pushDynamicInvocation( |
| 2898 invocation, | 2889 invocation, |
| 2899 _typeInferenceMap.typeOfInvocation(invocation, closedWorld), | 2890 _typeInferenceMap.typeOfInvocation(invocation, closedWorld), |
| 2900 <HInstruction>[receiver]..addAll( | 2891 <HInstruction>[receiver]..addAll( |
| 2901 _visitArgumentsForDynamicTarget(selector, invocation.arguments))); | 2892 _visitArgumentsForDynamicTarget(selector, invocation.arguments))); |
| 2902 } | 2893 } |
| 2903 | 2894 |
| 2904 bool _handleEqualsNull(ir.MethodInvocation invocation) { | |
| 2905 if (invocation.name.name == '==') { | |
| 2906 ir.Arguments arguments = invocation.arguments; | |
| 2907 if (arguments.types.isEmpty && | |
| 2908 arguments.positional.length == 1 && | |
| 2909 arguments.named.isEmpty) { | |
| 2910 bool finish(ir.Expression comparand) { | |
| 2911 comparand.accept(this); | |
| 2912 pushCheckNull(pop()); | |
| 2913 return true; | |
| 2914 } | |
| 2915 | |
| 2916 ir.Expression receiver = invocation.receiver; | |
| 2917 ir.Expression argument = arguments.positional.first; | |
| 2918 if (argument is ir.NullLiteral) return finish(receiver); | |
| 2919 if (receiver is ir.NullLiteral) return finish(argument); | |
| 2920 } | |
| 2921 } | |
| 2922 return false; | |
| 2923 } | |
| 2924 | |
| 2925 HInterceptor _interceptorFor(HInstruction intercepted) { | 2895 HInterceptor _interceptorFor(HInstruction intercepted) { |
| 2926 HInterceptor interceptor = | 2896 HInterceptor interceptor = |
| 2927 new HInterceptor(intercepted, commonMasks.nonNullType); | 2897 new HInterceptor(intercepted, commonMasks.nonNullType); |
| 2928 add(interceptor); | 2898 add(interceptor); |
| 2929 return interceptor; | 2899 return interceptor; |
| 2930 } | 2900 } |
| 2931 | 2901 |
| 2932 static ir.Class _containingClass(ir.TreeNode node) { | 2902 static ir.Class _containingClass(ir.TreeNode node) { |
| 2933 while (node != null) { | 2903 while (node != null) { |
| 2934 if (node is ir.Class) return node; | 2904 if (node is ir.Class) return node; |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3498 enterBlock.setBlockFlow( | 3468 enterBlock.setBlockFlow( |
| 3499 new HTryBlockInformation( | 3469 new HTryBlockInformation( |
| 3500 kernelBuilder.wrapStatementGraph(bodyGraph), | 3470 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3501 exception, | 3471 exception, |
| 3502 kernelBuilder.wrapStatementGraph(catchGraph), | 3472 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3503 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3473 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3504 exitBlock); | 3474 exitBlock); |
| 3505 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3475 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3506 } | 3476 } |
| 3507 } | 3477 } |
| OLD | NEW |