OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 '../common/backend_api.dart'; | 8 import '../common/backend_api.dart'; |
9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
10 import '../compile_time_constants.dart'; | 10 import '../compile_time_constants.dart'; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 141 } |
142 | 142 |
143 ConstructorEntity lookupConstructor(KClass cls, String name) { | 143 ConstructorEntity lookupConstructor(KClass cls, String name) { |
144 KClassEnv classEnv = _classEnvs[cls.classIndex]; | 144 KClassEnv classEnv = _classEnvs[cls.classIndex]; |
145 ir.Member member = classEnv.lookupConstructor(name); | 145 ir.Member member = classEnv.lookupConstructor(name); |
146 return member != null ? getConstructor(member) : null; | 146 return member != null ? getConstructor(member) : null; |
147 } | 147 } |
148 | 148 |
149 KClass _getClass(ir.Class node, [KClassEnv classEnv]) { | 149 KClass _getClass(ir.Class node, [KClassEnv classEnv]) { |
150 return _classMap.putIfAbsent(node, () { | 150 return _classMap.putIfAbsent(node, () { |
| 151 KLibrary library = _getLibrary(node.enclosingLibrary); |
151 if (classEnv == null) { | 152 if (classEnv == null) { |
152 KLibrary library = _getLibrary(node.enclosingLibrary); | |
153 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); | 153 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); |
154 } | 154 } |
155 _classEnvs.add(classEnv); | 155 _classEnvs.add(classEnv); |
156 return new KClass(_classMap.length, node.name); | 156 return new KClass(library, _classMap.length, node.name); |
157 }); | 157 }); |
158 } | 158 } |
159 | 159 |
160 KTypeVariable _getTypeVariable(ir.TypeParameter node) { | 160 KTypeVariable _getTypeVariable(ir.TypeParameter node) { |
161 return _typeVariableMap.putIfAbsent(node, () { | 161 return _typeVariableMap.putIfAbsent(node, () { |
162 if (node.parent is ir.Class) { | 162 if (node.parent is ir.Class) { |
163 ir.Class cls = node.parent; | 163 ir.Class cls = node.parent; |
164 int index = cls.typeParameters.indexOf(node); | 164 int index = cls.typeParameters.indexOf(node); |
165 return new KTypeVariable(_getClass(cls), node.name, index); | 165 return new KTypeVariable(_getClass(cls), node.name, index); |
166 } | 166 } |
(...skipping 16 matching lines...) Expand all Loading... |
183 } | 183 } |
184 } | 184 } |
185 throw new UnsupportedError('Unsupported type parameter type node $node.'); | 185 throw new UnsupportedError('Unsupported type parameter type node $node.'); |
186 }); | 186 }); |
187 } | 187 } |
188 | 188 |
189 KConstructor _getConstructor(ir.Member node) { | 189 KConstructor _getConstructor(ir.Member node) { |
190 return _constructorMap.putIfAbsent(node, () { | 190 return _constructorMap.putIfAbsent(node, () { |
191 int constructorIndex = _constructorList.length; | 191 int constructorIndex = _constructorList.length; |
192 KConstructor constructor; | 192 KConstructor constructor; |
| 193 KClass enclosingClass = _getClass(node.enclosingClass); |
| 194 Name name = getName(node.name); |
| 195 bool isExternal = node.isExternal; |
193 if (node is ir.Constructor) { | 196 if (node is ir.Constructor) { |
194 constructor = new KGenerativeConstructor(constructorIndex, | 197 constructor = new KGenerativeConstructor( |
195 _getClass(node.enclosingClass), getName(node.name)); | 198 constructorIndex, enclosingClass, name, |
| 199 isExternal: isExternal); |
196 } else { | 200 } else { |
197 constructor = new KFactoryConstructor(constructorIndex, | 201 constructor = new KFactoryConstructor( |
198 _getClass(node.enclosingClass), getName(node.name)); | 202 constructorIndex, enclosingClass, name, |
| 203 isExternal: isExternal); |
199 } | 204 } |
200 _constructorList.add(node); | 205 _constructorList.add(node); |
201 return constructor; | 206 return constructor; |
202 }); | 207 }); |
203 } | 208 } |
204 | 209 |
205 KFunction _getMethod(ir.Procedure node) { | 210 KFunction _getMethod(ir.Procedure node) { |
206 return _methodMap.putIfAbsent(node, () { | 211 return _methodMap.putIfAbsent(node, () { |
207 KClass enclosingClass = | 212 KLibrary library; |
208 node.enclosingClass != null ? _getClass(node.enclosingClass) : null; | 213 KClass enclosingClass; |
| 214 if (node.enclosingClass != null) { |
| 215 enclosingClass = _getClass(node.enclosingClass); |
| 216 library = enclosingClass.library; |
| 217 } else { |
| 218 library = _getLibrary(node.enclosingLibrary); |
| 219 } |
209 Name name = getName(node.name); | 220 Name name = getName(node.name); |
210 bool isStatic = node.isStatic; | 221 bool isStatic = node.isStatic; |
| 222 bool isExternal = node.isExternal; |
211 switch (node.kind) { | 223 switch (node.kind) { |
212 case ir.ProcedureKind.Factory: | 224 case ir.ProcedureKind.Factory: |
213 throw new UnsupportedError("Cannot create method from factory."); | 225 throw new UnsupportedError("Cannot create method from factory."); |
214 case ir.ProcedureKind.Getter: | 226 case ir.ProcedureKind.Getter: |
215 return new KGetter(enclosingClass, name, isStatic: isStatic); | 227 return new KGetter(library, enclosingClass, name, |
| 228 isStatic: isStatic, isExternal: isExternal); |
216 case ir.ProcedureKind.Method: | 229 case ir.ProcedureKind.Method: |
217 case ir.ProcedureKind.Operator: | 230 case ir.ProcedureKind.Operator: |
218 return new KMethod(enclosingClass, name, isStatic: isStatic); | 231 return new KMethod(library, enclosingClass, name, |
| 232 isStatic: isStatic, isExternal: isExternal); |
219 case ir.ProcedureKind.Setter: | 233 case ir.ProcedureKind.Setter: |
220 return new KSetter(enclosingClass, getName(node.name).setter, | 234 return new KSetter(library, enclosingClass, getName(node.name).setter, |
221 isStatic: isStatic); | 235 isStatic: isStatic, isExternal: isExternal); |
222 } | 236 } |
223 }); | 237 }); |
224 } | 238 } |
225 | 239 |
226 KField _getField(ir.Field node) { | 240 KField _getField(ir.Field node) { |
227 return _fieldMap.putIfAbsent(node, () { | 241 return _fieldMap.putIfAbsent(node, () { |
228 int fieldIndex = _fieldList.length; | 242 int fieldIndex = _fieldList.length; |
229 KClass enclosingClass = | 243 KLibrary library; |
230 node.enclosingClass != null ? _getClass(node.enclosingClass) : null; | 244 KClass enclosingClass; |
| 245 if (node.enclosingClass != null) { |
| 246 enclosingClass = _getClass(node.enclosingClass); |
| 247 library = enclosingClass.library; |
| 248 } else { |
| 249 library = _getLibrary(node.enclosingLibrary); |
| 250 } |
231 Name name = getName(node.name); | 251 Name name = getName(node.name); |
232 bool isStatic = node.isStatic; | 252 bool isStatic = node.isStatic; |
233 _fieldList.add(node); | 253 _fieldList.add(node); |
234 return new KField(fieldIndex, enclosingClass, name, | 254 return new KField(fieldIndex, library, enclosingClass, name, |
235 isStatic: isStatic, isAssignable: node.isMutable); | 255 isStatic: isStatic, isAssignable: node.isMutable); |
236 }); | 256 }); |
237 } | 257 } |
238 | 258 |
239 KLocalFunction _getLocal(ir.TreeNode node) { | 259 KLocalFunction _getLocal(ir.TreeNode node) { |
240 return _localFunctionMap.putIfAbsent(node, () { | 260 return _localFunctionMap.putIfAbsent(node, () { |
241 MemberEntity memberContext; | 261 MemberEntity memberContext; |
242 Entity executableContext; | 262 Entity executableContext; |
243 ir.TreeNode parent = node.parent; | 263 ir.TreeNode parent = node.parent; |
244 while (parent != null) { | 264 while (parent != null) { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 } | 853 } |
834 | 854 |
835 InterfaceType getMixinTypeForClass(KClass cls) { | 855 InterfaceType getMixinTypeForClass(KClass cls) { |
836 KClassEnv env = builder._classEnvs[cls.classIndex]; | 856 KClassEnv env = builder._classEnvs[cls.classIndex]; |
837 ir.Supertype mixedInType = env.cls.mixedInType; | 857 ir.Supertype mixedInType = env.cls.mixedInType; |
838 if (mixedInType == null) return null; | 858 if (mixedInType == null) return null; |
839 return builder.createInterfaceType( | 859 return builder.createInterfaceType( |
840 mixedInType.classNode, mixedInType.typeArguments); | 860 mixedInType.classNode, mixedInType.typeArguments); |
841 } | 861 } |
842 } | 862 } |
OLD | NEW |