| 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:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
| 6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
| 7 | 7 |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
| 11 import '../constants/expressions.dart'; | 11 import '../constants/expressions.dart'; |
| 12 import '../constants/values.dart'; | 12 import '../constants/values.dart'; |
| 13 import '../elements/resolution_types.dart'; | 13 import '../elements/resolution_types.dart'; |
| 14 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 15 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
| 16 import '../elements/modelx.dart'; | 16 import '../elements/modelx.dart'; |
| 17 import '../elements/types.dart'; | 17 import '../elements/types.dart'; |
| 18 import '../js/js.dart' as js; | 18 import '../js/js.dart' as js; |
| 19 import '../js_backend/backend_helpers.dart'; | 19 import '../js_backend/backend_helpers.dart'; |
| 20 import '../js_backend/js_backend.dart'; | 20 import '../js_backend/js_backend.dart'; |
| 21 import '../kernel/element_adapter.dart'; |
| 21 import '../kernel/kernel.dart'; | 22 import '../kernel/kernel.dart'; |
| 22 import '../kernel/kernel_debug.dart'; | 23 import '../kernel/kernel_debug.dart'; |
| 23 import '../native/native.dart' as native; | 24 import '../native/native.dart' as native; |
| 24 import '../resolution/tree_elements.dart'; | 25 import '../resolution/tree_elements.dart'; |
| 25 import '../tree/tree.dart' as ast; | 26 import '../tree/tree.dart' as ast; |
| 26 import '../types/masks.dart'; | 27 import '../types/masks.dart'; |
| 27 import '../types/types.dart'; | 28 import '../types/types.dart'; |
| 28 import '../universe/call_structure.dart'; | 29 import '../universe/call_structure.dart'; |
| 29 import '../universe/selector.dart'; | 30 import '../universe/selector.dart'; |
| 30 import '../universe/side_effects.dart'; | 31 import '../universe/side_effects.dart'; |
| 31 import '../world.dart'; | 32 import '../world.dart'; |
| 32 import 'graph_builder.dart'; | 33 import 'graph_builder.dart'; |
| 33 import 'jump_handler.dart' show SwitchCaseJumpHandler; | 34 import 'jump_handler.dart' show SwitchCaseJumpHandler; |
| 34 import 'locals_handler.dart'; | 35 import 'locals_handler.dart'; |
| 35 import 'types.dart'; | 36 import 'types.dart'; |
| 36 | 37 |
| 37 /// Interface that translates between Kernel IR nodes and entities. | |
| 38 abstract class KernelWorldBuilder { | |
| 39 /// Returns the [DartType] corresponding to [type]. | |
| 40 DartType getDartType(ir.DartType type); | |
| 41 | |
| 42 /// Returns the list of [DartType]s corresponding to [types]. | |
| 43 List<DartType> getDartTypes(List<ir.DartType> types); | |
| 44 | |
| 45 /// Returns the [InterfaceType] corresponding to [type]. | |
| 46 InterfaceType getInterfaceType(ir.InterfaceType type); | |
| 47 | |
| 48 /// Return the [InterfaceType] corresponding to the [cls] with the given | |
| 49 /// [typeArguments]. | |
| 50 InterfaceType createInterfaceType( | |
| 51 ir.Class cls, List<ir.DartType> typeArguments); | |
| 52 | |
| 53 /// Returns the [CallStructure] corresponding to the [arguments]. | |
| 54 CallStructure getCallStructure(ir.Arguments arguments); | |
| 55 | |
| 56 /// Returns the [Selector] corresponding to the invocation or getter/setter | |
| 57 /// access of [node]. | |
| 58 Selector getSelector(ir.Expression node); | |
| 59 | |
| 60 /// Returns the [FunctionEntity] corresponding to the generative or factory | |
| 61 /// constructor [node]. | |
| 62 FunctionEntity getConstructor(ir.Member node); | |
| 63 | |
| 64 /// Returns the [MemberEntity] corresponding to the member [node]. | |
| 65 MemberEntity getMember(ir.Member node); | |
| 66 | |
| 67 /// Returns the [FunctionEntity] corresponding to the procedure [node]. | |
| 68 FunctionEntity getMethod(ir.Procedure node); | |
| 69 | |
| 70 /// Returns the [FieldEntity] corresponding to the field [node]. | |
| 71 FieldEntity getField(ir.Field node); | |
| 72 | |
| 73 /// Returns the [ClassEntity] corresponding to the class [node]. | |
| 74 ClassEntity getClass(ir.Class node); | |
| 75 | |
| 76 /// Returns the [Local] corresponding to the [node]. The node must be either | |
| 77 /// a [ir.FunctionDeclaration] or [ir.FunctionExpression]. | |
| 78 Local getLocalFunction(ir.Node node); | |
| 79 | |
| 80 /// Returns the [Name] corresponding to [name]. | |
| 81 Name getName(ir.Name name); | |
| 82 | |
| 83 /// Returns `true` is [node] has a `@Native(...)` annotation. | |
| 84 bool isNativeClass(ir.Class node); | |
| 85 | |
| 86 /// Return `true` if [node] is the `dart:_foreign_helper` library. | |
| 87 bool isForeignLibrary(ir.Library node); | |
| 88 | |
| 89 /// Computes the native behavior for reading the native [field]. | |
| 90 native.NativeBehavior getNativeBehaviorForFieldLoad(ir.Field field); | |
| 91 | |
| 92 /// Computes the native behavior for writing to the native [field]. | |
| 93 native.NativeBehavior getNativeBehaviorForFieldStore(ir.Field field); | |
| 94 | |
| 95 /// Computes the native behavior for calling [procedure]. | |
| 96 native.NativeBehavior getNativeBehaviorForMethod(ir.Procedure procedure); | |
| 97 | |
| 98 /// Computes the [native.NativeBehavior] for a call to the [JS] function. | |
| 99 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node); | |
| 100 | |
| 101 /// Computes the [native.NativeBehavior] for a call to the [JS_BUILTIN] | |
| 102 /// function. | |
| 103 native.NativeBehavior getNativeBehaviorForJsBuiltinCall( | |
| 104 ir.StaticInvocation node); | |
| 105 | |
| 106 /// Computes the [native.NativeBehavior] for a call to the | |
| 107 /// [JS_EMBEDDED_GLOBAL] function. | |
| 108 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( | |
| 109 ir.StaticInvocation node); | |
| 110 | |
| 111 /// Compute the kind of foreign helper function called by [node], if any. | |
| 112 ForeignKind getForeignKind(ir.StaticInvocation node); | |
| 113 | |
| 114 /// Computes the [InterfaceType] referenced by a call to the | |
| 115 /// [JS_INTERCEPTOR_CONSTANT] function, if any. | |
| 116 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node); | |
| 117 } | |
| 118 | |
| 119 /// A helper class that abstracts all accesses of the AST from Kernel nodes. | 38 /// A helper class that abstracts all accesses of the AST from Kernel nodes. |
| 120 /// | 39 /// |
| 121 /// The goal is to remove all need for the AST from the Kernel SSA builder. | 40 /// The goal is to remove all need for the AST from the Kernel SSA builder. |
| 122 class KernelAstAdapter implements KernelWorldBuilder { | 41 class KernelAstAdapter implements KernelElementAdapter { |
| 123 final Kernel kernel; | 42 final Kernel kernel; |
| 124 final JavaScriptBackend _backend; | 43 final JavaScriptBackend _backend; |
| 125 final Map<ir.Node, ast.Node> _nodeToAst; | 44 final Map<ir.Node, ast.Node> _nodeToAst; |
| 126 final Map<ir.Node, Element> _nodeToElement; | 45 final Map<ir.Node, Element> _nodeToElement; |
| 127 final Map<ir.VariableDeclaration, SyntheticLocal> _syntheticLocals = | 46 final Map<ir.VariableDeclaration, SyntheticLocal> _syntheticLocals = |
| 128 <ir.VariableDeclaration, SyntheticLocal>{}; | 47 <ir.VariableDeclaration, SyntheticLocal>{}; |
| 129 // TODO(efortuna): In an ideal world the TreeNodes should be some common | 48 // TODO(efortuna): In an ideal world the TreeNodes should be some common |
| 130 // interface we create for both ir.Statements and ir.SwitchCase (the | 49 // interface we create for both ir.Statements and ir.SwitchCase (the |
| 131 // ContinueSwitchStatement's target is a SwitchCase) rather than general | 50 // ContinueSwitchStatement's target is a SwitchCase) rather than general |
| 132 // TreeNode. Talking to Asger about this. | 51 // TreeNode. Talking to Asger about this. |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 837 |
| 919 MemberEntity getConstructorBodyEntity(ir.Constructor constructor) { | 838 MemberEntity getConstructorBodyEntity(ir.Constructor constructor) { |
| 920 AstElement element = getElement(constructor); | 839 AstElement element = getElement(constructor); |
| 921 MemberEntity constructorBody = | 840 MemberEntity constructorBody = |
| 922 ConstructorBodyElementX.createFromResolvedAst(element.resolvedAst); | 841 ConstructorBodyElementX.createFromResolvedAst(element.resolvedAst); |
| 923 assert(constructorBody != null); | 842 assert(constructorBody != null); |
| 924 return constructorBody; | 843 return constructorBody; |
| 925 } | 844 } |
| 926 } | 845 } |
| 927 | 846 |
| 928 /// Kinds of foreign functions. | |
| 929 enum ForeignKind { | |
| 930 JS, | |
| 931 JS_BUILTIN, | |
| 932 JS_EMBEDDED_GLOBAL, | |
| 933 JS_INTERCEPTOR_CONSTANT, | |
| 934 NONE, | |
| 935 } | |
| 936 | |
| 937 /// Visitor that converts kernel dart types into [ResolutionDartType]. | 847 /// Visitor that converts kernel dart types into [ResolutionDartType]. |
| 938 class DartTypeConverter extends ir.DartTypeVisitor<ResolutionDartType> { | 848 class DartTypeConverter extends ir.DartTypeVisitor<ResolutionDartType> { |
| 939 final KernelAstAdapter astAdapter; | 849 final KernelAstAdapter astAdapter; |
| 940 bool topLevel = true; | 850 bool topLevel = true; |
| 941 | 851 |
| 942 DartTypeConverter(this.astAdapter); | 852 DartTypeConverter(this.astAdapter); |
| 943 | 853 |
| 944 ResolutionDartType convert(ir.DartType type) { | 854 ResolutionDartType convert(ir.DartType type) { |
| 945 topLevel = true; | 855 topLevel = true; |
| 946 return type.accept(this); | 856 return type.accept(this); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 JumpTarget continueTarget = | 1109 JumpTarget continueTarget = |
| 1200 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); | 1110 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); |
| 1201 assert(continueTarget is KernelJumpTarget); | 1111 assert(continueTarget is KernelJumpTarget); |
| 1202 targetIndexMap[continueTarget] = switchIndex; | 1112 targetIndexMap[continueTarget] = switchIndex; |
| 1203 assert(builder.jumpTargets[continueTarget] == null); | 1113 assert(builder.jumpTargets[continueTarget] == null); |
| 1204 builder.jumpTargets[continueTarget] = this; | 1114 builder.jumpTargets[continueTarget] = this; |
| 1205 switchIndex++; | 1115 switchIndex++; |
| 1206 } | 1116 } |
| 1207 } | 1117 } |
| 1208 } | 1118 } |
| OLD | NEW |