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 '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 final ResolvedAst _resolvedAst; | 27 final ResolvedAst _resolvedAst; |
28 final Map<ir.Node, ast.Node> _nodeToAst; | 28 final Map<ir.Node, ast.Node> _nodeToAst; |
29 final Map<ir.Node, Element> _nodeToElement; | 29 final Map<ir.Node, Element> _nodeToElement; |
30 DartTypeConverter _typeConverter; | 30 DartTypeConverter _typeConverter; |
31 | 31 |
32 KernelAstAdapter( | 32 KernelAstAdapter( |
33 this._backend, | 33 this._backend, |
34 this._resolvedAst, | 34 this._resolvedAst, |
35 this._nodeToAst, | 35 this._nodeToAst, |
36 this._nodeToElement, | 36 this._nodeToElement, |
| 37 Map<FieldElement, ir.Field> fields, |
37 Map<FunctionElement, ir.Member> functions, | 38 Map<FunctionElement, ir.Member> functions, |
38 Map<ClassElement, ir.Class> classes, | 39 Map<ClassElement, ir.Class> classes, |
39 Map<LibraryElement, ir.Library> libraries) { | 40 Map<LibraryElement, ir.Library> libraries) { |
| 41 // TODO(het): Maybe just use all of the kernel maps directly? |
| 42 for (FieldElement fieldElement in fields.keys) { |
| 43 _nodeToElement[fields[fieldElement]] = fieldElement; |
| 44 } |
40 for (FunctionElement functionElement in functions.keys) { | 45 for (FunctionElement functionElement in functions.keys) { |
41 _nodeToElement[functions[functionElement]] = functionElement; | 46 _nodeToElement[functions[functionElement]] = functionElement; |
42 } | 47 } |
43 for (ClassElement classElement in classes.keys) { | 48 for (ClassElement classElement in classes.keys) { |
44 _nodeToElement[classes[classElement]] = classElement; | 49 _nodeToElement[classes[classElement]] = classElement; |
45 } | 50 } |
46 for (LibraryElement libraryElement in libraries.keys) { | 51 for (LibraryElement libraryElement in libraries.keys) { |
47 _nodeToElement[libraries[libraryElement]] = libraryElement; | 52 _nodeToElement[libraries[libraryElement]] = libraryElement; |
48 } | 53 } |
49 _typeConverter = new DartTypeConverter(this); | 54 _typeConverter = new DartTypeConverter(this); |
(...skipping 16 matching lines...) Expand all Loading... |
66 assert(result != null); | 71 assert(result != null); |
67 return result; | 72 return result; |
68 } | 73 } |
69 | 74 |
70 ast.Node getNode(ir.Node node) { | 75 ast.Node getNode(ir.Node node) { |
71 ast.Node result = _nodeToAst[node]; | 76 ast.Node result = _nodeToAst[node]; |
72 assert(result != null); | 77 assert(result != null); |
73 return result; | 78 return result; |
74 } | 79 } |
75 | 80 |
76 bool getCanThrow(ir.Procedure procedure) { | 81 bool getCanThrow(ir.Node procedure) { |
77 FunctionElement function = getElement(procedure); | 82 return !_compiler.world.getCannotThrow(getElement(procedure)); |
78 return !_compiler.world.getCannotThrow(function); | |
79 } | 83 } |
80 | 84 |
81 TypeMask returnTypeOf(ir.Procedure node) { | 85 TypeMask returnTypeOf(ir.Member node) { |
82 return TypeMaskFactory.inferredReturnTypeForElement( | 86 return TypeMaskFactory.inferredReturnTypeForElement( |
83 getElement(node), _compiler); | 87 getElement(node), _compiler); |
84 } | 88 } |
85 | 89 |
86 SideEffects getSideEffects(ir.Node node) { | 90 SideEffects getSideEffects(ir.Node node) { |
87 return _compiler.world.getSideEffectsOfElement(getElement(node)); | 91 return _compiler.world.getSideEffectsOfElement(getElement(node)); |
88 } | 92 } |
89 | 93 |
90 CallStructure getCallStructure(ir.Arguments arguments) { | 94 CallStructure getCallStructure(ir.Arguments arguments) { |
91 int argumentCount = arguments.positional.length + arguments.named.length; | 95 int argumentCount = arguments.positional.length + arguments.named.length; |
92 List<String> namedArguments = arguments.named.map((e) => e.name).toList(); | 96 List<String> namedArguments = arguments.named.map((e) => e.name).toList(); |
93 return new CallStructure(argumentCount, namedArguments); | 97 return new CallStructure(argumentCount, namedArguments); |
94 } | 98 } |
95 | 99 |
96 // TODO(het): Create the selector directly from the invocation | 100 // TODO(het): Create the selector directly from the invocation |
97 Selector getSelector(ir.MethodInvocation invocation) { | 101 Selector getSelector(ir.InvocationExpression invocation) { |
98 SelectorKind kind = Elements.isOperatorName(invocation.name.name) | 102 SelectorKind kind = Elements.isOperatorName(invocation.name.name) |
99 ? SelectorKind.OPERATOR | 103 ? SelectorKind.OPERATOR |
100 : SelectorKind.CALL; | 104 : SelectorKind.CALL; |
| 105 if (invocation.name.name == '[]' || invocation.name.name == '[]=') { |
| 106 kind = SelectorKind.INDEX; |
| 107 } |
101 | 108 |
102 ir.Name irName = invocation.name; | 109 ir.Name irName = invocation.name; |
103 Name name = new Name( | 110 Name name = new Name( |
104 irName.name, irName.isPrivate ? getElement(irName.library) : null); | 111 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
105 CallStructure callStructure = getCallStructure(invocation.arguments); | 112 CallStructure callStructure = getCallStructure(invocation.arguments); |
106 | 113 |
107 return new Selector(kind, name, callStructure); | 114 return new Selector(kind, name, callStructure); |
108 } | 115 } |
109 | 116 |
| 117 Selector getGetterSelector(ir.PropertyGet getter) { |
| 118 ir.Name irName = getter.name; |
| 119 Name name = new Name( |
| 120 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
| 121 return new Selector.getter(name); |
| 122 } |
| 123 |
110 TypeMask typeOfInvocation(ir.MethodInvocation invocation) { | 124 TypeMask typeOfInvocation(ir.MethodInvocation invocation) { |
111 return _compiler.globalInference.results | 125 return _compiler.globalInference.results |
112 .typeOfSend(getNode(invocation), _elements); | 126 .typeOfSend(getNode(invocation), _elements); |
113 } | 127 } |
114 | 128 |
| 129 TypeMask typeOfGet(ir.PropertyGet getter) { |
| 130 return _compiler.globalInference.results |
| 131 .typeOfSend(getNode(getter), _elements); |
| 132 } |
| 133 |
| 134 TypeMask inferredTypeOf(ir.Member node) { |
| 135 return TypeMaskFactory.inferredTypeForElement(getElement(node), _compiler); |
| 136 } |
| 137 |
115 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { | 138 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { |
116 return TypeMaskFactory.inferredTypeForSelector( | 139 return TypeMaskFactory.inferredTypeForSelector( |
117 getSelector(invocation), typeOfInvocation(invocation), _compiler); | 140 getSelector(invocation), typeOfInvocation(invocation), _compiler); |
118 } | 141 } |
119 | 142 |
120 bool isIntercepted(ir.MethodInvocation invocation) { | 143 TypeMask selectorGetterTypeOf(ir.PropertyGet getter) { |
121 return _backend.isInterceptedSelector(getSelector(invocation)); | 144 return TypeMaskFactory.inferredTypeForSelector( |
| 145 getGetterSelector(getter), typeOfGet(getter), _compiler); |
| 146 } |
| 147 |
| 148 bool isIntercepted(ir.Node node) { |
| 149 Selector selector; |
| 150 if (node is ir.PropertyGet) { |
| 151 selector = getGetterSelector(node); |
| 152 } else { |
| 153 selector = getSelector(node); |
| 154 } |
| 155 return _backend.isInterceptedSelector(selector); |
122 } | 156 } |
123 | 157 |
124 DartType getDartType(ir.DartType type) { | 158 DartType getDartType(ir.DartType type) { |
125 return type.accept(_typeConverter); | 159 return type.accept(_typeConverter); |
126 } | 160 } |
127 } | 161 } |
128 | 162 |
129 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { | 163 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { |
130 final KernelAstAdapter astAdapter; | 164 final KernelAstAdapter astAdapter; |
131 | 165 |
(...skipping 28 matching lines...) Expand all Loading... |
160 @override | 194 @override |
161 DartType visitDynamicType(ir.DynamicType node) { | 195 DartType visitDynamicType(ir.DynamicType node) { |
162 return const DynamicType(); | 196 return const DynamicType(); |
163 } | 197 } |
164 | 198 |
165 @override | 199 @override |
166 DartType visitInvalidType(ir.InvalidType node) { | 200 DartType visitInvalidType(ir.InvalidType node) { |
167 throw new UnimplementedError("Invalid types not currently supported"); | 201 throw new UnimplementedError("Invalid types not currently supported"); |
168 } | 202 } |
169 } | 203 } |
OLD | NEW |