| 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 import 'package:kernel/frontend/accessors.dart' | 6 import 'package:kernel/frontend/accessors.dart' |
| 7 show | 7 show |
| 8 Accessor, | 8 Accessor, |
| 9 IndexAccessor, | 9 IndexAccessor, |
| 10 NullAwarePropertyAccessor, | 10 NullAwarePropertyAccessor, |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 ir.InvocationExpression visitBoolFromEnvironmentConstructorInvoke( | 1217 ir.InvocationExpression visitBoolFromEnvironmentConstructorInvoke( |
| 1218 NewExpression node, BoolFromEnvironmentConstantExpression constant, _) { | 1218 NewExpression node, BoolFromEnvironmentConstantExpression constant, _) { |
| 1219 return buildConstructorInvoke(node, isConst: true); | 1219 return buildConstructorInvoke(node, isConst: true); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 ir.TypeLiteral buildTypeLiteral(TypeConstantExpression constant) { | 1222 ir.TypeLiteral buildTypeLiteral(TypeConstantExpression constant) { |
| 1223 return new ir.TypeLiteral(kernel.typeLiteralToIr(constant)); | 1223 return new ir.TypeLiteral(kernel.typeLiteralToIr(constant)); |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 @override | 1226 @override |
| 1227 ir.TypeLiteral visitClassTypeLiteralGet( | 1227 ir.Expression visitClassTypeLiteralGet( |
| 1228 Send node, ConstantExpression constant, _) { | 1228 Send node, ConstantExpression constant, _) { |
| 1229 return buildTypeLiteral(constant); | 1229 var loadedCheckFunc = |
| 1230 _createCheckLibraryLoadedFuncIfNeeded(_deferredLibrary); |
| 1231 _deferredLibrary = null; |
| 1232 return loadedCheckFunc(buildTypeLiteral(constant)); |
| 1230 } | 1233 } |
| 1231 | 1234 |
| 1232 @override | 1235 @override |
| 1233 ir.MethodInvocation visitClassTypeLiteralInvoke( | 1236 ir.MethodInvocation visitClassTypeLiteralInvoke( |
| 1234 Send node, | 1237 Send node, |
| 1235 ConstantExpression constant, | 1238 ConstantExpression constant, |
| 1236 NodeList arguments, | 1239 NodeList arguments, |
| 1237 CallStructure callStructure, | 1240 CallStructure callStructure, |
| 1238 _) { | 1241 _) { |
| 1239 return associateNode( | 1242 return associateNode( |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 } | 2010 } |
| 2008 | 2011 |
| 2009 @override | 2012 @override |
| 2010 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, | 2013 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, |
| 2011 FieldElement field, Node initializer, _) { | 2014 FieldElement field, Node initializer, _) { |
| 2012 // Shouldn't be called, handled by fieldToIr. | 2015 // Shouldn't be called, handled by fieldToIr. |
| 2013 return internalError(node, "StaticFieldDeclaration"); | 2016 return internalError(node, "StaticFieldDeclaration"); |
| 2014 } | 2017 } |
| 2015 | 2018 |
| 2016 ir.Expression buildStaticGet(Element element) { | 2019 ir.Expression buildStaticGet(Element element) { |
| 2017 var expression = buildStaticAccessor(element).buildSimpleRead(); | 2020 var loadedCheckFunc = |
| 2018 if (_deferredLibrary != null) { | 2021 _createCheckLibraryLoadedFuncIfNeeded(_deferredLibrary); |
| 2019 ir.Let let = new ir.Let( | 2022 _deferredLibrary = null; |
| 2020 makeOrReuseVariable(new ir.CheckLibraryIsLoaded(_deferredLibrary)), | 2023 return loadedCheckFunc(buildStaticAccessor(element).buildSimpleRead()); |
| 2021 expression); | |
| 2022 return let; | |
| 2023 } | |
| 2024 return expression; | |
| 2025 } | 2024 } |
| 2026 | 2025 |
| 2027 @override | 2026 @override |
| 2028 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { | 2027 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { |
| 2029 return associateNode(buildStaticGet(field), node); | 2028 return associateNode(buildStaticGet(field), node); |
| 2030 } | 2029 } |
| 2031 | 2030 |
| 2032 @override | 2031 @override |
| 2033 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, | 2032 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, |
| 2034 NodeList arguments, CallStructure callStructure, _) { | 2033 NodeList arguments, CallStructure callStructure, _) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 | 2225 |
| 2227 ir.StaticInvocation buildStaticInvoke( | 2226 ir.StaticInvocation buildStaticInvoke( |
| 2228 FunctionElement function, NodeList arguments, | 2227 FunctionElement function, NodeList arguments, |
| 2229 {bool isConst}) { | 2228 {bool isConst}) { |
| 2230 ir.Arguments argumentsNode = buildArguments(arguments); | 2229 ir.Arguments argumentsNode = buildArguments(arguments); |
| 2231 return new ir.StaticInvocation(kernel.functionToIr(function), argumentsNode, | 2230 return new ir.StaticInvocation(kernel.functionToIr(function), argumentsNode, |
| 2232 isConst: isConst); | 2231 isConst: isConst); |
| 2233 } | 2232 } |
| 2234 | 2233 |
| 2235 @override | 2234 @override |
| 2236 ir.StaticInvocation handleStaticFunctionInvoke( | 2235 ir.Expression handleStaticFunctionInvoke(Send node, MethodElement function, |
| 2237 Send node, | 2236 NodeList arguments, CallStructure callStructure, _) { |
| 2238 MethodElement function, | 2237 var loadedCheckFunc = |
| 2239 NodeList arguments, | 2238 _createCheckLibraryLoadedFuncIfNeeded(_deferredLibrary); |
| 2240 CallStructure callStructure, | 2239 _deferredLibrary = null; |
| 2241 _) { | 2240 return loadedCheckFunc(associateNode( |
| 2242 return associateNode( | 2241 buildStaticInvoke(function, arguments, isConst: false), node)); |
| 2243 buildStaticInvoke(function, arguments, isConst: false), node); | |
| 2244 } | 2242 } |
| 2245 | 2243 |
| 2246 @override | 2244 @override |
| 2247 ir.Expression handleStaticFunctionSet( | 2245 ir.Expression handleStaticFunctionSet( |
| 2248 Send node, MethodElement function, Node rhs, _) { | 2246 Send node, MethodElement function, Node rhs, _) { |
| 2249 return buildStaticAccessor(function) | 2247 return buildStaticAccessor(function) |
| 2250 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2248 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
| 2251 } | 2249 } |
| 2252 | 2250 |
| 2253 @override | 2251 @override |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2707 FunctionExpression node, MethodElement getter, Node body, _) { | 2705 FunctionExpression node, MethodElement getter, Node body, _) { |
| 2708 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); | 2706 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); |
| 2709 } | 2707 } |
| 2710 | 2708 |
| 2711 @override | 2709 @override |
| 2712 IrFunction visitTopLevelSetterDeclaration(FunctionExpression node, | 2710 IrFunction visitTopLevelSetterDeclaration(FunctionExpression node, |
| 2713 MethodElement setter, NodeList parameters, Node body, _) { | 2711 MethodElement setter, NodeList parameters, Node body, _) { |
| 2714 return buildIrFunction(ir.ProcedureKind.Setter, setter, body); | 2712 return buildIrFunction(ir.ProcedureKind.Setter, setter, body); |
| 2715 } | 2713 } |
| 2716 | 2714 |
| 2717 @override | 2715 /// Return a function that accepts an expression and returns an expression. If |
| 2718 ir.TypeLiteral visitTypeVariableTypeLiteralGet( | 2716 /// deferredImport is null, then the function returned is the identity |
| 2719 Send node, TypeVariableElement element, _) { | 2717 /// expression. Otherwise, it inserts a CheckLibraryIsLoaded call before |
| 2720 return buildTypeVariable(element); | 2718 /// evaluating the expression. |
| 2719 _createCheckLibraryLoadedFuncIfNeeded(ir.DeferredImport deferredImport) { |
| 2720 if (deferredImport != null) { |
| 2721 return (ir.Expression inputExpression) => new ir.Let( |
| 2722 makeOrReuseVariable(new ir.CheckLibraryIsLoaded(deferredImport)), |
| 2723 inputExpression); |
| 2724 } else { |
| 2725 return (ir.Expression expr) => expr; |
| 2726 } |
| 2721 } | 2727 } |
| 2722 | 2728 |
| 2723 @override | 2729 @override |
| 2730 ir.Expression visitTypeVariableTypeLiteralGet( |
| 2731 Send node, TypeVariableElement element, _) { |
| 2732 var loadedCheckFunc = |
| 2733 _createCheckLibraryLoadedFuncIfNeeded(_deferredLibrary); |
| 2734 _deferredLibrary = null; |
| 2735 return loadedCheckFunc(buildTypeVariable(element)); |
| 2736 } |
| 2737 |
| 2738 @override |
| 2724 ir.MethodInvocation visitTypeVariableTypeLiteralInvoke( | 2739 ir.MethodInvocation visitTypeVariableTypeLiteralInvoke( |
| 2725 Send node, | 2740 Send node, |
| 2726 TypeVariableElement element, | 2741 TypeVariableElement element, |
| 2727 NodeList arguments, | 2742 NodeList arguments, |
| 2728 CallStructure callStructure, | 2743 CallStructure callStructure, |
| 2729 _) { | 2744 _) { |
| 2730 return associateNode( | 2745 return associateNode( |
| 2731 buildCall(buildTypeVariable(element), callStructure, arguments), node); | 2746 buildCall(buildTypeVariable(element), callStructure, arguments), node); |
| 2732 } | 2747 } |
| 2733 | 2748 |
| 2734 @override | 2749 @override |
| 2735 ir.Expression visitTypeVariableTypeLiteralSet( | 2750 ir.Expression visitTypeVariableTypeLiteralSet( |
| 2736 SendSet node, TypeVariableElement element, Node rhs, _) { | 2751 SendSet node, TypeVariableElement element, Node rhs, _) { |
| 2737 return new ReadOnlyAccessor(buildTypeVariable(element)) | 2752 return new ReadOnlyAccessor(buildTypeVariable(element)) |
| 2738 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2753 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
| 2739 } | 2754 } |
| 2740 | 2755 |
| 2741 @override | 2756 @override |
| 2742 ir.Expression visitTypeVariableTypeLiteralSetIfNull( | 2757 ir.Expression visitTypeVariableTypeLiteralSetIfNull( |
| 2743 Send node, TypeVariableElement element, Node rhs, _) { | 2758 Send node, TypeVariableElement element, Node rhs, _) { |
| 2744 return _finishSetIfNull( | 2759 return _finishSetIfNull( |
| 2745 node, new ReadOnlyAccessor(buildTypeVariable(element)), rhs); | 2760 node, new ReadOnlyAccessor(buildTypeVariable(element)), rhs); |
| 2746 } | 2761 } |
| 2747 | 2762 |
| 2748 @override | 2763 @override |
| 2749 ir.TypeLiteral visitTypedefTypeLiteralGet( | 2764 ir.Expression visitTypedefTypeLiteralGet( |
| 2750 Send node, ConstantExpression constant, _) { | 2765 Send node, ConstantExpression constant, _) { |
| 2751 return buildTypeLiteral(constant); | 2766 var loadedCheckFunc = |
| 2767 _createCheckLibraryLoadedFuncIfNeeded(_deferredLibrary); |
| 2768 _deferredLibrary = null; |
| 2769 return loadedCheckFunc(buildTypeLiteral(constant)); |
| 2752 } | 2770 } |
| 2753 | 2771 |
| 2754 @override | 2772 @override |
| 2755 ir.MethodInvocation visitTypedefTypeLiteralInvoke( | 2773 ir.MethodInvocation visitTypedefTypeLiteralInvoke( |
| 2756 Send node, | 2774 Send node, |
| 2757 ConstantExpression constant, | 2775 ConstantExpression constant, |
| 2758 NodeList arguments, | 2776 NodeList arguments, |
| 2759 CallStructure callStructure, | 2777 CallStructure callStructure, |
| 2760 _) { | 2778 _) { |
| 2761 return associateNode( | 2779 return associateNode( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2906 : this(null, true, node, initializers); | 2924 : this(null, true, node, initializers); |
| 2907 | 2925 |
| 2908 accept(ir.Visitor v) => throw "unsupported"; | 2926 accept(ir.Visitor v) => throw "unsupported"; |
| 2909 | 2927 |
| 2910 visitChildren(ir.Visitor v) => throw "unsupported"; | 2928 visitChildren(ir.Visitor v) => throw "unsupported"; |
| 2911 | 2929 |
| 2912 String toString() { | 2930 String toString() { |
| 2913 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2931 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
| 2914 } | 2932 } |
| 2915 } | 2933 } |
| OLD | NEW |