| 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 library dart2js.kernel.element_map; | 5 library dart2js.kernel.element_map; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 | 8 |
| 9 import '../closure.dart' show BoxLocal, ThisLocal; | 9 import '../closure.dart' show BoxLocal, ThisLocal; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import '../ordered_typeset.dart'; | 39 import '../ordered_typeset.dart'; |
| 40 import '../options.dart'; | 40 import '../options.dart'; |
| 41 import '../ssa/kernel_impact.dart'; | 41 import '../ssa/kernel_impact.dart'; |
| 42 import '../universe/class_set.dart'; | 42 import '../universe/class_set.dart'; |
| 43 import '../universe/selector.dart'; | 43 import '../universe/selector.dart'; |
| 44 import '../universe/world_builder.dart'; | 44 import '../universe/world_builder.dart'; |
| 45 import '../world.dart'; | 45 import '../world.dart'; |
| 46 import '../util/util.dart' show Link, LinkBuilder; | 46 import '../util/util.dart' show Link, LinkBuilder; |
| 47 import 'element_map.dart'; | 47 import 'element_map.dart'; |
| 48 import 'element_map_mixins.dart'; | 48 import 'element_map_mixins.dart'; |
| 49 import 'elements.dart'; | |
| 50 import 'env.dart'; | 49 import 'env.dart'; |
| 50 import 'indexed.dart'; |
| 51 import 'kelements.dart'; | 51 import 'kelements.dart'; |
| 52 | 52 |
| 53 part 'native_basic_data.dart'; | 53 part 'native_basic_data.dart'; |
| 54 part 'no_such_method_resolver.dart'; | 54 part 'no_such_method_resolver.dart'; |
| 55 part 'types.dart'; | 55 part 'types.dart'; |
| 56 | 56 |
| 57 /// Interface for kernel queries needed to implement the [CodegenWorldBuilder]. | 57 /// Interface for kernel queries needed to implement the [CodegenWorldBuilder]. |
| 58 abstract class KernelToWorldBuilder implements KernelToElementMapForBuilding { | 58 abstract class KernelToWorldBuilder implements KernelToElementMapForBuilding { |
| 59 /// Returns `true` if [field] has a constant initializer. | 59 /// Returns `true` if [field] has a constant initializer. |
| 60 bool hasConstantFieldInitializer(FieldEntity field); | 60 bool hasConstantFieldInitializer(FieldEntity field); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 final DiagnosticReporter reporter; | 72 final DiagnosticReporter reporter; |
| 73 CommonElements _commonElements; | 73 CommonElements _commonElements; |
| 74 ElementEnvironment _elementEnvironment; | 74 ElementEnvironment _elementEnvironment; |
| 75 DartTypeConverter _typeConverter; | 75 DartTypeConverter _typeConverter; |
| 76 KernelConstantEnvironment _constantEnvironment; | 76 KernelConstantEnvironment _constantEnvironment; |
| 77 _KernelDartTypes _types; | 77 _KernelDartTypes _types; |
| 78 | 78 |
| 79 /// Library environment. Used for fast lookup. | 79 /// Library environment. Used for fast lookup. |
| 80 ProgramEnv _env = new ProgramEnv(); | 80 ProgramEnv _env = new ProgramEnv(); |
| 81 | 81 |
| 82 List<LibraryEntity> _libraryList = <LibraryEntity>[]; | 82 final EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv> _libraries = |
| 83 List<ClassEntity> _classList = <ClassEntity>[]; | 83 new EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv>(); |
| 84 List<MemberEntity> _memberList = <MemberEntity>[]; | 84 final EntityDataEnvMap<IndexedClass, ClassData, ClassEnv> _classes = |
| 85 List<TypeVariableEntity> _typeVariableList = <TypeVariableEntity>[]; | 85 new EntityDataEnvMap<IndexedClass, ClassData, ClassEnv>(); |
| 86 List<TypedefEntity> _typedefList = <TypedefEntity>[]; | 86 final EntityDataMap<IndexedMember, MemberData> _members = |
| 87 | 87 new EntityDataMap<IndexedMember, MemberData>(); |
| 88 /// List of library environments by `IndexedLibrary.libraryIndex`. This is | 88 final EntityMap<IndexedTypeVariable> _typeVariables = |
| 89 /// used for fast lookup into library classes and members. | 89 new EntityMap<IndexedTypeVariable>(); |
| 90 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[]; | 90 final EntityDataMap<IndexedTypedef, TypedefData> _typedefs = |
| 91 | 91 new EntityDataMap<IndexedTypedef, TypedefData>(); |
| 92 /// List of library data by `IndexedLibrary.libraryIndex`. This is used for | |
| 93 /// fast lookup into library properties. | |
| 94 List<LibraryData> _libraryData = <LibraryData>[]; | |
| 95 | |
| 96 /// List of class environments by `IndexedClass.classIndex`. This is used for | |
| 97 /// fast lookup into class members. | |
| 98 List<ClassEnv> _classEnvs = <ClassEnv>[]; | |
| 99 | |
| 100 /// List of class data by `IndexedClass.classIndex`. This is used for | |
| 101 /// fast lookup into class properties. | |
| 102 List<ClassData> _classData = <ClassData>[]; | |
| 103 | |
| 104 /// List of member data by `IndexedMember.memberIndex`. This is used for | |
| 105 /// fast lookup into member properties. | |
| 106 List<MemberData> _memberData = <MemberData>[]; | |
| 107 | |
| 108 /// List of typedef data by `IndexedTypedef.typedefIndex`. This is used for | |
| 109 /// fast lookup into typedef properties. | |
| 110 List<TypedefData> _typedefData = <TypedefData>[]; | |
| 111 | 92 |
| 112 KernelToElementMapBase(this.reporter, Environment environment) { | 93 KernelToElementMapBase(this.reporter, Environment environment) { |
| 113 _elementEnvironment = new KernelElementEnvironment(this); | 94 _elementEnvironment = new KernelElementEnvironment(this); |
| 114 _commonElements = new CommonElements(_elementEnvironment); | 95 _commonElements = new CommonElements(_elementEnvironment); |
| 115 _constantEnvironment = new KernelConstantEnvironment(this, environment); | 96 _constantEnvironment = new KernelConstantEnvironment(this, environment); |
| 116 _typeConverter = new DartTypeConverter(this); | 97 _typeConverter = new DartTypeConverter(this); |
| 117 _types = new _KernelDartTypes(this); | 98 _types = new _KernelDartTypes(this); |
| 118 } | 99 } |
| 119 | 100 |
| 120 bool checkFamily(Entity entity); | 101 bool checkFamily(Entity entity); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 FunctionEntity get _mainFunction { | 114 FunctionEntity get _mainFunction { |
| 134 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; | 115 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; |
| 135 } | 116 } |
| 136 | 117 |
| 137 LibraryEntity get _mainLibrary { | 118 LibraryEntity get _mainLibrary { |
| 138 return _env.mainMethod != null | 119 return _env.mainMethod != null |
| 139 ? _getLibrary(_env.mainMethod.enclosingLibrary) | 120 ? _getLibrary(_env.mainMethod.enclosingLibrary) |
| 140 : null; | 121 : null; |
| 141 } | 122 } |
| 142 | 123 |
| 143 Iterable<LibraryEntity> get _libraries; | 124 Iterable<LibraryEntity> get _libraryList; |
| 144 | 125 |
| 145 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) { | 126 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) { |
| 146 SourceSpan fromSpannable(Spannable spannable) { | 127 SourceSpan fromSpannable(Spannable spannable) { |
| 147 if (spannable is IndexedLibrary && | 128 if (spannable is IndexedLibrary && |
| 148 spannable.libraryIndex < _libraryEnvs.length) { | 129 spannable.libraryIndex < _libraries.length) { |
| 149 LibraryEnv env = _libraryEnvs[spannable.libraryIndex]; | 130 LibraryEnv env = _libraries.getEnv(spannable); |
| 150 return computeSourceSpanFromTreeNode(env.library); | 131 return computeSourceSpanFromTreeNode(env.library); |
| 151 } else if (spannable is IndexedClass && | 132 } else if (spannable is IndexedClass && |
| 152 spannable.classIndex < _classEnvs.length) { | 133 spannable.classIndex < _classes.length) { |
| 153 ClassData data = _classData[spannable.classIndex]; | 134 ClassData data = _classes.getData(spannable); |
| 154 return data.definition.location; | 135 return data.definition.location; |
| 155 } else if (spannable is IndexedMember && | 136 } else if (spannable is IndexedMember && |
| 156 spannable.memberIndex < _memberData.length) { | 137 spannable.memberIndex < _members.length) { |
| 157 MemberData data = _memberData[spannable.memberIndex]; | 138 MemberData data = _members.getData(spannable); |
| 158 return data.definition.location; | 139 return data.definition.location; |
| 159 } | 140 } |
| 160 return null; | 141 return null; |
| 161 } | 142 } |
| 162 | 143 |
| 163 SourceSpan sourceSpan = fromSpannable(spannable); | 144 SourceSpan sourceSpan = fromSpannable(spannable); |
| 164 sourceSpan ??= fromSpannable(currentElement); | 145 sourceSpan ??= fromSpannable(currentElement); |
| 165 return sourceSpan; | 146 return sourceSpan; |
| 166 } | 147 } |
| 167 | 148 |
| 168 LibraryEntity lookupLibrary(Uri uri) { | 149 LibraryEntity lookupLibrary(Uri uri) { |
| 169 LibraryEnv libraryEnv = _env.lookupLibrary(uri); | 150 LibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 170 if (libraryEnv == null) return null; | 151 if (libraryEnv == null) return null; |
| 171 return _getLibrary(libraryEnv.library, libraryEnv); | 152 return _getLibrary(libraryEnv.library, libraryEnv); |
| 172 } | 153 } |
| 173 | 154 |
| 174 String _getLibraryName(IndexedLibrary library) { | 155 String _getLibraryName(IndexedLibrary library) { |
| 175 assert(checkFamily(library)); | 156 assert(checkFamily(library)); |
| 176 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 157 LibraryEnv libraryEnv = _libraries.getEnv(library); |
| 177 return libraryEnv.library.name ?? ''; | 158 return libraryEnv.library.name ?? ''; |
| 178 } | 159 } |
| 179 | 160 |
| 180 MemberEntity lookupLibraryMember(IndexedLibrary library, String name, | 161 MemberEntity lookupLibraryMember(IndexedLibrary library, String name, |
| 181 {bool setter: false}) { | 162 {bool setter: false}) { |
| 182 assert(checkFamily(library)); | 163 assert(checkFamily(library)); |
| 183 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 164 LibraryEnv libraryEnv = _libraries.getEnv(library); |
| 184 ir.Member member = libraryEnv.lookupMember(name, setter: setter); | 165 ir.Member member = libraryEnv.lookupMember(name, setter: setter); |
| 185 return member != null ? getMember(member) : null; | 166 return member != null ? getMember(member) : null; |
| 186 } | 167 } |
| 187 | 168 |
| 188 void _forEachLibraryMember( | 169 void _forEachLibraryMember( |
| 189 IndexedLibrary library, void f(MemberEntity member)) { | 170 IndexedLibrary library, void f(MemberEntity member)) { |
| 190 assert(checkFamily(library)); | 171 assert(checkFamily(library)); |
| 191 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 172 LibraryEnv libraryEnv = _libraries.getEnv(library); |
| 192 libraryEnv.forEachMember((ir.Member node) { | 173 libraryEnv.forEachMember((ir.Member node) { |
| 193 f(getMember(node)); | 174 f(getMember(node)); |
| 194 }); | 175 }); |
| 195 } | 176 } |
| 196 | 177 |
| 197 ClassEntity lookupClass(IndexedLibrary library, String name) { | 178 ClassEntity lookupClass(IndexedLibrary library, String name) { |
| 198 assert(checkFamily(library)); | 179 assert(checkFamily(library)); |
| 199 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 180 LibraryEnv libraryEnv = _libraries.getEnv(library); |
| 200 ClassEnv classEnv = libraryEnv.lookupClass(name); | 181 ClassEnv classEnv = libraryEnv.lookupClass(name); |
| 201 if (classEnv != null) { | 182 if (classEnv != null) { |
| 202 return _getClass(classEnv.cls, classEnv); | 183 return _getClass(classEnv.cls, classEnv); |
| 203 } | 184 } |
| 204 return null; | 185 return null; |
| 205 } | 186 } |
| 206 | 187 |
| 207 void _forEachClass(IndexedLibrary library, void f(ClassEntity cls)) { | 188 void _forEachClass(IndexedLibrary library, void f(ClassEntity cls)) { |
| 208 assert(checkFamily(library)); | 189 assert(checkFamily(library)); |
| 209 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 190 LibraryEnv libraryEnv = _libraries.getEnv(library); |
| 210 libraryEnv.forEachClass((ClassEnv classEnv) { | 191 libraryEnv.forEachClass((ClassEnv classEnv) { |
| 211 if (!classEnv.isUnnamedMixinApplication) { | 192 if (!classEnv.isUnnamedMixinApplication) { |
| 212 f(_getClass(classEnv.cls, classEnv)); | 193 f(_getClass(classEnv.cls, classEnv)); |
| 213 } | 194 } |
| 214 }); | 195 }); |
| 215 } | 196 } |
| 216 | 197 |
| 217 MemberEntity lookupClassMember(IndexedClass cls, String name, | 198 MemberEntity lookupClassMember(IndexedClass cls, String name, |
| 218 {bool setter: false}) { | 199 {bool setter: false}) { |
| 219 assert(checkFamily(cls)); | 200 assert(checkFamily(cls)); |
| 220 ClassEnv classEnv = _classEnvs[cls.classIndex]; | 201 ClassEnv classEnv = _classes.getEnv(cls); |
| 221 return classEnv.lookupMember(this, name, setter: setter); | 202 return classEnv.lookupMember(this, name, setter: setter); |
| 222 } | 203 } |
| 223 | 204 |
| 224 ConstructorEntity lookupConstructor(IndexedClass cls, String name) { | 205 ConstructorEntity lookupConstructor(IndexedClass cls, String name) { |
| 225 assert(checkFamily(cls)); | 206 assert(checkFamily(cls)); |
| 226 ClassEnv classEnv = _classEnvs[cls.classIndex]; | 207 ClassEnv classEnv = _classes.getEnv(cls); |
| 227 return classEnv.lookupConstructor(this, name); | 208 return classEnv.lookupConstructor(this, name); |
| 228 } | 209 } |
| 229 | 210 |
| 230 @override | 211 @override |
| 231 InterfaceType createInterfaceType( | 212 InterfaceType createInterfaceType( |
| 232 ir.Class cls, List<ir.DartType> typeArguments) { | 213 ir.Class cls, List<ir.DartType> typeArguments) { |
| 233 return new InterfaceType(getClass(cls), getDartTypes(typeArguments)); | 214 return new InterfaceType(getClass(cls), getDartTypes(typeArguments)); |
| 234 } | 215 } |
| 235 | 216 |
| 236 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node); | 217 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node); |
| 237 | 218 |
| 238 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]); | 219 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]); |
| 239 | 220 |
| 240 @override | 221 @override |
| 241 ClassEntity getClass(ir.Class node) => _getClass(node); | 222 ClassEntity getClass(ir.Class node) => _getClass(node); |
| 242 | 223 |
| 243 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]); | 224 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]); |
| 244 | 225 |
| 245 InterfaceType _getSuperType(IndexedClass cls) { | 226 InterfaceType _getSuperType(IndexedClass cls) { |
| 246 assert(checkFamily(cls)); | 227 assert(checkFamily(cls)); |
| 247 ClassData data = _classData[cls.classIndex]; | 228 ClassData data = _classes.getData(cls); |
| 248 _ensureSupertypes(cls, data); | 229 _ensureSupertypes(cls, data); |
| 249 return data.supertype; | 230 return data.supertype; |
| 250 } | 231 } |
| 251 | 232 |
| 252 void _ensureThisAndRawType(ClassEntity cls, ClassData data) { | 233 void _ensureThisAndRawType(ClassEntity cls, ClassData data) { |
| 253 assert(checkFamily(cls)); | 234 assert(checkFamily(cls)); |
| 254 if (data.thisType == null) { | 235 if (data.thisType == null) { |
| 255 ir.Class node = data.cls; | 236 ir.Class node = data.cls; |
| 256 if (node.typeParameters.isEmpty) { | 237 if (node.typeParameters.isEmpty) { |
| 257 data.thisType = | 238 data.thisType = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 285 ir.Class node = data.cls; | 266 ir.Class node = data.cls; |
| 286 | 267 |
| 287 if (node.supertype == null) { | 268 if (node.supertype == null) { |
| 288 data.orderedTypeSet = new OrderedTypeSet.singleton(data.thisType); | 269 data.orderedTypeSet = new OrderedTypeSet.singleton(data.thisType); |
| 289 data.isMixinApplication = false; | 270 data.isMixinApplication = false; |
| 290 data.interfaces = const <InterfaceType>[]; | 271 data.interfaces = const <InterfaceType>[]; |
| 291 } else { | 272 } else { |
| 292 InterfaceType processSupertype(ir.Supertype node) { | 273 InterfaceType processSupertype(ir.Supertype node) { |
| 293 InterfaceType supertype = _typeConverter.visitSupertype(node); | 274 InterfaceType supertype = _typeConverter.visitSupertype(node); |
| 294 IndexedClass superclass = supertype.element; | 275 IndexedClass superclass = supertype.element; |
| 295 ClassData superdata = _classData[superclass.classIndex]; | 276 ClassData superdata = _classes.getData(superclass); |
| 296 _ensureSupertypes(superclass, superdata); | 277 _ensureSupertypes(superclass, superdata); |
| 297 return supertype; | 278 return supertype; |
| 298 } | 279 } |
| 299 | 280 |
| 300 InterfaceType supertype = processSupertype(node.supertype); | 281 InterfaceType supertype = processSupertype(node.supertype); |
| 301 if (supertype == _commonElements.objectType) { | 282 if (supertype == _commonElements.objectType) { |
| 302 ClassEntity defaultSuperclass = | 283 ClassEntity defaultSuperclass = |
| 303 _commonElements.getDefaultSuperclass(cls, nativeBasicData); | 284 _commonElements.getDefaultSuperclass(cls, nativeBasicData); |
| 304 data.supertype = _elementEnvironment.getRawType(defaultSuperclass); | 285 data.supertype = _elementEnvironment.getRawType(defaultSuperclass); |
| 305 } else { | 286 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 323 data.orderedTypeSet = setBuilder.createOrderedTypeSet( | 304 data.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 324 data.supertype, interfaces.reverse()); | 305 data.supertype, interfaces.reverse()); |
| 325 data.interfaces = new List<InterfaceType>.from(interfaces.toList()); | 306 data.interfaces = new List<InterfaceType>.from(interfaces.toList()); |
| 326 } | 307 } |
| 327 } | 308 } |
| 328 } | 309 } |
| 329 | 310 |
| 330 @override | 311 @override |
| 331 TypedefType getTypedefType(ir.Typedef node) { | 312 TypedefType getTypedefType(ir.Typedef node) { |
| 332 IndexedTypedef typedef = _getTypedef(node); | 313 IndexedTypedef typedef = _getTypedef(node); |
| 333 return _typedefData[typedef.typedefIndex].rawType; | 314 return _typedefs.getData(typedef).rawType; |
| 334 } | 315 } |
| 335 | 316 |
| 336 TypedefEntity _getTypedef(ir.Typedef node); | 317 TypedefEntity _getTypedef(ir.Typedef node); |
| 337 | 318 |
| 338 @override | 319 @override |
| 339 MemberEntity getMember(ir.Member node) { | 320 MemberEntity getMember(ir.Member node) { |
| 340 if (node is ir.Field) { | 321 if (node is ir.Field) { |
| 341 return _getField(node); | 322 return _getField(node); |
| 342 } else if (node is ir.Constructor) { | 323 } else if (node is ir.Constructor) { |
| 343 return _getConstructor(node); | 324 return _getConstructor(node); |
| 344 } else if (node is ir.Procedure) { | 325 } else if (node is ir.Procedure) { |
| 345 if (node.kind == ir.ProcedureKind.Factory) { | 326 if (node.kind == ir.ProcedureKind.Factory) { |
| 346 return _getConstructor(node); | 327 return _getConstructor(node); |
| 347 } else { | 328 } else { |
| 348 return _getMethod(node); | 329 return _getMethod(node); |
| 349 } | 330 } |
| 350 } | 331 } |
| 351 throw new UnsupportedError("Unexpected member: $node"); | 332 throw new UnsupportedError("Unexpected member: $node"); |
| 352 } | 333 } |
| 353 | 334 |
| 354 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target, | 335 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target, |
| 355 {bool setter: false}) { | 336 {bool setter: false}) { |
| 356 if (target != null) { | 337 if (target != null) { |
| 357 return getMember(target); | 338 return getMember(target); |
| 358 } | 339 } |
| 359 ClassEntity cls = getMember(context).enclosingClass; | 340 ClassEntity cls = getMember(context).enclosingClass; |
| 360 IndexedClass superclass = _getSuperType(cls)?.element; | 341 IndexedClass superclass = _getSuperType(cls)?.element; |
| 361 while (superclass != null) { | 342 while (superclass != null) { |
| 362 ClassEnv env = _classEnvs[superclass.classIndex]; | 343 ClassEnv env = _classes.getEnv(superclass); |
| 363 MemberEntity superMember = | 344 MemberEntity superMember = |
| 364 env.lookupMember(this, name.name, setter: setter); | 345 env.lookupMember(this, name.name, setter: setter); |
| 365 if (superMember != null) { | 346 if (superMember != null) { |
| 366 return superMember; | 347 return superMember; |
| 367 } | 348 } |
| 368 superclass = _getSuperType(superclass)?.element; | 349 superclass = _getSuperType(superclass)?.element; |
| 369 } | 350 } |
| 370 return null; | 351 return null; |
| 371 } | 352 } |
| 372 | 353 |
| 373 @override | 354 @override |
| 374 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); | 355 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); |
| 375 | 356 |
| 376 ConstructorEntity _getConstructor(ir.Member node); | 357 ConstructorEntity _getConstructor(ir.Member node); |
| 377 | 358 |
| 378 ConstructorEntity getSuperConstructor( | 359 ConstructorEntity getSuperConstructor( |
| 379 ir.Constructor sourceNode, ir.Member targetNode) { | 360 ir.Constructor sourceNode, ir.Member targetNode) { |
| 380 ConstructorEntity source = getConstructor(sourceNode); | 361 ConstructorEntity source = getConstructor(sourceNode); |
| 381 ClassEntity sourceClass = source.enclosingClass; | 362 ClassEntity sourceClass = source.enclosingClass; |
| 382 ConstructorEntity target = getConstructor(targetNode); | 363 ConstructorEntity target = getConstructor(targetNode); |
| 383 ClassEntity targetClass = target.enclosingClass; | 364 ClassEntity targetClass = target.enclosingClass; |
| 384 IndexedClass superClass = _getSuperType(sourceClass)?.element; | 365 IndexedClass superClass = _getSuperType(sourceClass)?.element; |
| 385 if (superClass == targetClass) { | 366 if (superClass == targetClass) { |
| 386 return target; | 367 return target; |
| 387 } | 368 } |
| 388 ClassEnv env = _classEnvs[superClass.classIndex]; | 369 ClassEnv env = _classes.getEnv(superClass); |
| 389 ConstructorEntity constructor = env.lookupConstructor(this, target.name); | 370 ConstructorEntity constructor = env.lookupConstructor(this, target.name); |
| 390 if (constructor != null) { | 371 if (constructor != null) { |
| 391 return constructor; | 372 return constructor; |
| 392 } | 373 } |
| 393 throw failedAt(source, "Super constructor for $source not found."); | 374 throw failedAt(source, "Super constructor for $source not found."); |
| 394 } | 375 } |
| 395 | 376 |
| 396 @override | 377 @override |
| 397 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); | 378 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); |
| 398 | 379 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 566 } |
| 586 | 567 |
| 587 /// Returns the type of the `call` method on 'type'. | 568 /// Returns the type of the `call` method on 'type'. |
| 588 /// | 569 /// |
| 589 /// If [type] doesn't have a `call` member `null` is returned. If [type] has | 570 /// If [type] doesn't have a `call` member `null` is returned. If [type] has |
| 590 /// an invalid `call` member (non-method or a synthesized method with both | 571 /// an invalid `call` member (non-method or a synthesized method with both |
| 591 /// optional and named parameters) a [DynamicType] is returned. | 572 /// optional and named parameters) a [DynamicType] is returned. |
| 592 DartType _getCallType(InterfaceType type) { | 573 DartType _getCallType(InterfaceType type) { |
| 593 IndexedClass cls = type.element; | 574 IndexedClass cls = type.element; |
| 594 assert(checkFamily(cls)); | 575 assert(checkFamily(cls)); |
| 595 ClassData data = _classData[cls.classIndex]; | 576 ClassData data = _classes.getData(cls); |
| 596 _ensureCallType(cls, data); | 577 _ensureCallType(cls, data); |
| 597 if (data.callType != null) { | 578 if (data.callType != null) { |
| 598 return _substByContext(data.callType, type); | 579 return _substByContext(data.callType, type); |
| 599 } | 580 } |
| 600 return null; | 581 return null; |
| 601 } | 582 } |
| 602 | 583 |
| 603 InterfaceType _getThisType(IndexedClass cls) { | 584 InterfaceType _getThisType(IndexedClass cls) { |
| 604 assert(checkFamily(cls)); | 585 assert(checkFamily(cls)); |
| 605 ClassData data = _classData[cls.classIndex]; | 586 ClassData data = _classes.getData(cls); |
| 606 _ensureThisAndRawType(cls, data); | 587 _ensureThisAndRawType(cls, data); |
| 607 return data.thisType; | 588 return data.thisType; |
| 608 } | 589 } |
| 609 | 590 |
| 610 InterfaceType _getRawType(IndexedClass cls) { | 591 InterfaceType _getRawType(IndexedClass cls) { |
| 611 assert(checkFamily(cls)); | 592 assert(checkFamily(cls)); |
| 612 ClassData data = _classData[cls.classIndex]; | 593 ClassData data = _classes.getData(cls); |
| 613 _ensureThisAndRawType(cls, data); | 594 _ensureThisAndRawType(cls, data); |
| 614 return data.rawType; | 595 return data.rawType; |
| 615 } | 596 } |
| 616 | 597 |
| 617 FunctionType _getFunctionType(IndexedFunction function) { | 598 FunctionType _getFunctionType(IndexedFunction function) { |
| 618 assert(checkFamily(function)); | 599 assert(checkFamily(function)); |
| 619 FunctionData data = _memberData[function.memberIndex]; | 600 FunctionData data = _members.getData(function); |
| 620 return data.getFunctionType(this); | 601 return data.getFunctionType(this); |
| 621 } | 602 } |
| 622 | 603 |
| 623 DartType _getFieldType(IndexedField field) { | 604 DartType _getFieldType(IndexedField field) { |
| 624 assert(checkFamily(field)); | 605 assert(checkFamily(field)); |
| 625 FieldData data = _memberData[field.memberIndex]; | 606 FieldData data = _members.getData(field); |
| 626 return data.getFieldType(this); | 607 return data.getFieldType(this); |
| 627 } | 608 } |
| 628 | 609 |
| 629 ClassEntity _getAppliedMixin(IndexedClass cls) { | 610 ClassEntity _getAppliedMixin(IndexedClass cls) { |
| 630 assert(checkFamily(cls)); | 611 assert(checkFamily(cls)); |
| 631 ClassData data = _classData[cls.classIndex]; | 612 ClassData data = _classes.getData(cls); |
| 632 _ensureSupertypes(cls, data); | 613 _ensureSupertypes(cls, data); |
| 633 return data.mixedInType?.element; | 614 return data.mixedInType?.element; |
| 634 } | 615 } |
| 635 | 616 |
| 636 bool _isMixinApplication(IndexedClass cls) { | 617 bool _isMixinApplication(IndexedClass cls) { |
| 637 assert(checkFamily(cls)); | 618 assert(checkFamily(cls)); |
| 638 ClassData data = _classData[cls.classIndex]; | 619 ClassData data = _classes.getData(cls); |
| 639 _ensureSupertypes(cls, data); | 620 _ensureSupertypes(cls, data); |
| 640 return data.isMixinApplication; | 621 return data.isMixinApplication; |
| 641 } | 622 } |
| 642 | 623 |
| 643 bool _isUnnamedMixinApplication(IndexedClass cls) { | 624 bool _isUnnamedMixinApplication(IndexedClass cls) { |
| 644 assert(checkFamily(cls)); | 625 assert(checkFamily(cls)); |
| 645 ClassEnv env = _classEnvs[cls.classIndex]; | 626 ClassEnv env = _classes.getEnv(cls); |
| 646 return env.isUnnamedMixinApplication; | 627 return env.isUnnamedMixinApplication; |
| 647 } | 628 } |
| 648 | 629 |
| 649 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) { | 630 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) { |
| 650 assert(checkFamily(cls)); | 631 assert(checkFamily(cls)); |
| 651 ClassData data = _classData[cls.classIndex]; | 632 ClassData data = _classes.getData(cls); |
| 652 _ensureSupertypes(cls, data); | 633 _ensureSupertypes(cls, data); |
| 653 data.orderedTypeSet.supertypes.forEach(f); | 634 data.orderedTypeSet.supertypes.forEach(f); |
| 654 } | 635 } |
| 655 | 636 |
| 656 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) { | 637 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) { |
| 657 assert(checkFamily(cls)); | 638 assert(checkFamily(cls)); |
| 658 while (cls != null) { | 639 while (cls != null) { |
| 659 ClassData data = _classData[cls.classIndex]; | 640 ClassData data = _classes.getData(cls); |
| 660 _ensureSupertypes(cls, data); | 641 _ensureSupertypes(cls, data); |
| 661 if (data.mixedInType != null) { | 642 if (data.mixedInType != null) { |
| 662 f(data.mixedInType.element); | 643 f(data.mixedInType.element); |
| 663 } | 644 } |
| 664 cls = data.supertype?.element; | 645 cls = data.supertype?.element; |
| 665 } | 646 } |
| 666 } | 647 } |
| 667 | 648 |
| 668 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { | 649 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { |
| 669 assert(checkFamily(cls)); | 650 assert(checkFamily(cls)); |
| 670 ClassEnv env = _classEnvs[cls.classIndex]; | 651 ClassEnv env = _classes.getEnv(cls); |
| 671 env.forEachConstructor(this, f); | 652 env.forEachConstructor(this, f); |
| 672 } | 653 } |
| 673 | 654 |
| 674 void _forEachConstructorBody( | 655 void _forEachConstructorBody( |
| 675 IndexedClass cls, void f(ConstructorBodyEntity member)) { | 656 IndexedClass cls, void f(ConstructorBodyEntity member)) { |
| 676 throw new UnsupportedError( | 657 throw new UnsupportedError( |
| 677 'KernelToElementMapBase._forEachConstructorBody'); | 658 'KernelToElementMapBase._forEachConstructorBody'); |
| 678 } | 659 } |
| 679 | 660 |
| 680 void _forEachClassMember( | 661 void _forEachClassMember( |
| 681 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { | 662 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { |
| 682 assert(checkFamily(cls)); | 663 assert(checkFamily(cls)); |
| 683 ClassEnv env = _classEnvs[cls.classIndex]; | 664 ClassEnv env = _classes.getEnv(cls); |
| 684 env.forEachMember(this, (MemberEntity member) { | 665 env.forEachMember(this, (MemberEntity member) { |
| 685 f(cls, member); | 666 f(cls, member); |
| 686 }); | 667 }); |
| 687 ClassData data = _classData[cls.classIndex]; | 668 ClassData data = _classes.getData(cls); |
| 688 _ensureSupertypes(cls, data); | 669 _ensureSupertypes(cls, data); |
| 689 if (data.supertype != null) { | 670 if (data.supertype != null) { |
| 690 _forEachClassMember(data.supertype.element, f); | 671 _forEachClassMember(data.supertype.element, f); |
| 691 } | 672 } |
| 692 } | 673 } |
| 693 | 674 |
| 694 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { | 675 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { |
| 695 assert(checkFamily(constructor)); | 676 assert(checkFamily(constructor)); |
| 696 ConstructorData data = _memberData[constructor.memberIndex]; | 677 ConstructorData data = _members.getData(constructor); |
| 697 return data.getConstructorConstant(this, constructor); | 678 return data.getConstructorConstant(this, constructor); |
| 698 } | 679 } |
| 699 | 680 |
| 700 ConstantExpression _getFieldConstantExpression(IndexedField field) { | 681 ConstantExpression _getFieldConstantExpression(IndexedField field) { |
| 701 assert(checkFamily(field)); | 682 assert(checkFamily(field)); |
| 702 FieldData data = _memberData[field.memberIndex]; | 683 FieldData data = _members.getData(field); |
| 703 return data.getFieldConstantExpression(this); | 684 return data.getFieldConstantExpression(this); |
| 704 } | 685 } |
| 705 | 686 |
| 706 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { | 687 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { |
| 707 assert(checkFamily(cls)); | 688 assert(checkFamily(cls)); |
| 708 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); | 689 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); |
| 709 InterfaceType supertype = | 690 InterfaceType supertype = |
| 710 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); | 691 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); |
| 711 if (supertype != null) { | 692 if (supertype != null) { |
| 712 supertype = _substByContext(supertype, type); | 693 supertype = _substByContext(supertype, type); |
| 713 } | 694 } |
| 714 return supertype; | 695 return supertype; |
| 715 } | 696 } |
| 716 | 697 |
| 717 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) { | 698 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) { |
| 718 assert(checkFamily(cls)); | 699 assert(checkFamily(cls)); |
| 719 ClassData data = _classData[cls.classIndex]; | 700 ClassData data = _classes.getData(cls); |
| 720 _ensureSupertypes(cls, data); | 701 _ensureSupertypes(cls, data); |
| 721 return data.orderedTypeSet; | 702 return data.orderedTypeSet; |
| 722 } | 703 } |
| 723 | 704 |
| 724 int _getHierarchyDepth(IndexedClass cls) { | 705 int _getHierarchyDepth(IndexedClass cls) { |
| 725 assert(checkFamily(cls)); | 706 assert(checkFamily(cls)); |
| 726 ClassData data = _classData[cls.classIndex]; | 707 ClassData data = _classes.getData(cls); |
| 727 _ensureSupertypes(cls, data); | 708 _ensureSupertypes(cls, data); |
| 728 return data.orderedTypeSet.maxDepth; | 709 return data.orderedTypeSet.maxDepth; |
| 729 } | 710 } |
| 730 | 711 |
| 731 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { | 712 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { |
| 732 assert(checkFamily(cls)); | 713 assert(checkFamily(cls)); |
| 733 ClassData data = _classData[cls.classIndex]; | 714 ClassData data = _classes.getData(cls); |
| 734 _ensureSupertypes(cls, data); | 715 _ensureSupertypes(cls, data); |
| 735 return data.interfaces; | 716 return data.interfaces; |
| 736 } | 717 } |
| 737 | 718 |
| 738 Spannable _getSpannable(MemberEntity member, ir.Node node) { | 719 Spannable _getSpannable(MemberEntity member, ir.Node node) { |
| 739 SourceSpan sourceSpan; | 720 SourceSpan sourceSpan; |
| 740 if (node is ir.TreeNode) { | 721 if (node is ir.TreeNode) { |
| 741 sourceSpan = computeSourceSpanFromTreeNode(node); | 722 sourceSpan = computeSourceSpanFromTreeNode(node); |
| 742 } | 723 } |
| 743 sourceSpan ??= getSourceSpan(member, null); | 724 sourceSpan ??= getSourceSpan(member, null); |
| 744 return sourceSpan; | 725 return sourceSpan; |
| 745 } | 726 } |
| 746 | 727 |
| 747 MemberDefinition _getMemberDefinition(covariant IndexedMember member) { | 728 MemberDefinition _getMemberDefinition(covariant IndexedMember member) { |
| 748 assert(checkFamily(member)); | 729 assert(checkFamily(member)); |
| 749 return _memberData[member.memberIndex].definition; | 730 return _members.getData(member).definition; |
| 750 } | 731 } |
| 751 | 732 |
| 752 ClassDefinition _getClassDefinition(covariant IndexedClass cls) { | 733 ClassDefinition _getClassDefinition(covariant IndexedClass cls) { |
| 753 assert(checkFamily(cls)); | 734 assert(checkFamily(cls)); |
| 754 return _classData[cls.classIndex].definition; | 735 return _classes.getData(cls).definition; |
| 755 } | 736 } |
| 756 } | 737 } |
| 757 | 738 |
| 758 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. | 739 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. |
| 759 abstract class ElementCreatorMixin { | 740 abstract class ElementCreatorMixin { |
| 760 ProgramEnv get _env; | 741 ProgramEnv get _env; |
| 761 List<LibraryEntity> get _libraryList; | 742 EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv> get _libraries; |
| 762 List<LibraryEnv> get _libraryEnvs; | 743 EntityDataEnvMap<IndexedClass, ClassData, ClassEnv> get _classes; |
| 763 List<LibraryData> get _libraryData; | 744 EntityDataMap<IndexedMember, MemberData> get _members; |
| 764 List<ClassEntity> get _classList; | 745 EntityMap<IndexedTypeVariable> get _typeVariables; |
| 765 List<ClassEnv> get _classEnvs; | 746 EntityDataMap<IndexedTypedef, TypedefData> get _typedefs; |
| 766 List<ClassData> get _classData; | |
| 767 List<MemberEntity> get _memberList; | |
| 768 List<MemberData> get _memberData; | |
| 769 List<TypeVariableEntity> get _typeVariableList; | |
| 770 List<TypedefEntity> get _typedefList; | |
| 771 List<TypedefData> get _typedefData; | |
| 772 | 747 |
| 773 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; | 748 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; |
| 774 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; | 749 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; |
| 775 Map<ir.Typedef, IndexedTypedef> _typedefMap = <ir.Typedef, IndexedTypedef>{}; | 750 Map<ir.Typedef, IndexedTypedef> _typedefMap = <ir.Typedef, IndexedTypedef>{}; |
| 776 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = | 751 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = |
| 777 <ir.TypeParameter, IndexedTypeVariable>{}; | 752 <ir.TypeParameter, IndexedTypeVariable>{}; |
| 778 Map<ir.Member, IndexedConstructor> _constructorMap = | 753 Map<ir.Member, IndexedConstructor> _constructorMap = |
| 779 <ir.Member, IndexedConstructor>{}; | 754 <ir.Member, IndexedConstructor>{}; |
| 780 Map<ir.Procedure, IndexedFunction> _methodMap = | 755 Map<ir.Procedure, IndexedFunction> _methodMap = |
| 781 <ir.Procedure, IndexedFunction>{}; | 756 <ir.Procedure, IndexedFunction>{}; |
| 782 Map<ir.Field, IndexedField> _fieldMap = <ir.Field, IndexedField>{}; | 757 Map<ir.Field, IndexedField> _fieldMap = <ir.Field, IndexedField>{}; |
| 783 Map<ir.TreeNode, Local> _localFunctionMap = <ir.TreeNode, Local>{}; | 758 Map<ir.TreeNode, Local> _localFunctionMap = <ir.TreeNode, Local>{}; |
| 784 | 759 |
| 785 Name getName(ir.Name node); | 760 Name getName(ir.Name node); |
| 786 FunctionType getFunctionType(ir.FunctionNode node); | 761 FunctionType getFunctionType(ir.FunctionNode node); |
| 787 MemberEntity getMember(ir.Member node); | 762 MemberEntity getMember(ir.Member node); |
| 788 | 763 |
| 789 Iterable<LibraryEntity> get _libraries { | 764 Iterable<LibraryEntity> get _libraryList { |
| 790 if (_env.length != _libraryMap.length) { | 765 if (_env.length != _libraryMap.length) { |
| 791 // Create a [KLibrary] for each library. | 766 // Create a [KLibrary] for each library. |
| 792 _env.forEachLibrary((LibraryEnv env) { | 767 _env.forEachLibrary((LibraryEnv env) { |
| 793 _getLibrary(env.library, env); | 768 _getLibrary(env.library, env); |
| 794 }); | 769 }); |
| 795 } | 770 } |
| 796 return _libraryMap.values; | 771 return _libraryMap.values; |
| 797 } | 772 } |
| 798 | 773 |
| 799 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) { | 774 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) { |
| 800 return _libraryMap.putIfAbsent(node, () { | 775 return _libraryMap.putIfAbsent(node, () { |
| 801 Uri canonicalUri = node.importUri; | 776 Uri canonicalUri = node.importUri; |
| 802 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); | |
| 803 String name = node.name; | 777 String name = node.name; |
| 804 if (name == null) { | 778 if (name == null) { |
| 805 // Use the file name as script name. | 779 // Use the file name as script name. |
| 806 String path = canonicalUri.path; | 780 String path = canonicalUri.path; |
| 807 name = path.substring(path.lastIndexOf('/') + 1); | 781 name = path.substring(path.lastIndexOf('/') + 1); |
| 808 } | 782 } |
| 809 LibraryEntity library = | 783 IndexedLibrary library = createLibrary(name, canonicalUri); |
| 810 createLibrary(_libraryMap.length, name, canonicalUri); | 784 return _libraries.register(library, new LibraryData(node), |
| 811 _libraryList.add(library); | 785 libraryEnv ?? _env.lookupLibrary(canonicalUri)); |
| 812 _libraryData.add(new LibraryData(node)); | |
| 813 return library; | |
| 814 }); | 786 }); |
| 815 } | 787 } |
| 816 | 788 |
| 817 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { | 789 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { |
| 818 return _classMap.putIfAbsent(node, () { | 790 return _classMap.putIfAbsent(node, () { |
| 819 KLibrary library = _getLibrary(node.enclosingLibrary); | 791 KLibrary library = _getLibrary(node.enclosingLibrary); |
| 820 if (classEnv == null) { | 792 if (classEnv == null) { |
| 821 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); | 793 classEnv = _libraries.getEnv(library).lookupClass(node.name); |
| 822 } | 794 } |
| 823 _classEnvs.add(classEnv); | 795 IndexedClass cls = |
| 824 ClassEntity cls = createClass(library, _classList.length, node.name, | 796 createClass(library, node.name, isAbstract: node.isAbstract); |
| 825 isAbstract: node.isAbstract); | 797 return _classes.register(cls, |
| 826 _classData | 798 new ClassData(node, new RegularClassDefinition(cls, node)), classEnv); |
| 827 .add(new ClassData(node, new RegularClassDefinition(cls, node))); | |
| 828 _classList.add(cls); | |
| 829 return cls; | |
| 830 }); | 799 }); |
| 831 } | 800 } |
| 832 | 801 |
| 833 TypedefEntity _getTypedef(ir.Typedef node) { | 802 TypedefEntity _getTypedef(ir.Typedef node) { |
| 834 return _typedefMap.putIfAbsent(node, () { | 803 return _typedefMap.putIfAbsent(node, () { |
| 835 IndexedLibrary library = _getLibrary(node.enclosingLibrary); | 804 IndexedLibrary library = _getLibrary(node.enclosingLibrary); |
| 836 TypedefEntity typedef = | 805 IndexedTypedef typedef = createTypedef(library, node.name); |
| 837 createTypedef(library, _typedefList.length, node.name); | |
| 838 TypedefType typedefType = new TypedefType( | 806 TypedefType typedefType = new TypedefType( |
| 839 typedef, | 807 typedef, |
| 840 new List<DartType>.filled( | 808 new List<DartType>.filled( |
| 841 node.typeParameters.length, const DynamicType())); | 809 node.typeParameters.length, const DynamicType())); |
| 842 _typedefData.add(new TypedefData(node, typedef, typedefType)); | 810 return _typedefs.register( |
| 843 _typedefList.add(typedef); | 811 typedef, new TypedefData(node, typedef, typedefType)); |
| 844 return typedef; | |
| 845 }); | 812 }); |
| 846 } | 813 } |
| 847 | 814 |
| 848 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { | 815 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { |
| 849 return _typeVariableMap.putIfAbsent(node, () { | 816 return _typeVariableMap.putIfAbsent(node, () { |
| 850 if (node.parent is ir.Class) { | 817 if (node.parent is ir.Class) { |
| 851 int typeVariableIndex = _typeVariableList.length; | |
| 852 ir.Class cls = node.parent; | 818 ir.Class cls = node.parent; |
| 853 int index = cls.typeParameters.indexOf(node); | 819 int index = cls.typeParameters.indexOf(node); |
| 854 TypeVariableEntity typeVariable = createTypeVariable( | 820 return _typeVariables |
| 855 typeVariableIndex, _getClass(cls), node.name, index); | 821 .register(createTypeVariable(_getClass(cls), node.name, index)); |
| 856 _typeVariableList.add(typeVariable); | |
| 857 return typeVariable; | |
| 858 } | 822 } |
| 859 if (node.parent is ir.FunctionNode) { | 823 if (node.parent is ir.FunctionNode) { |
| 860 ir.FunctionNode func = node.parent; | 824 ir.FunctionNode func = node.parent; |
| 861 int index = func.typeParameters.indexOf(node); | 825 int index = func.typeParameters.indexOf(node); |
| 862 if (func.parent is ir.Constructor) { | 826 if (func.parent is ir.Constructor) { |
| 863 ir.Constructor constructor = func.parent; | 827 ir.Constructor constructor = func.parent; |
| 864 ir.Class cls = constructor.enclosingClass; | 828 ir.Class cls = constructor.enclosingClass; |
| 865 return _getTypeVariable(cls.typeParameters[index]); | 829 return _getTypeVariable(cls.typeParameters[index]); |
| 866 } | 830 } |
| 867 if (func.parent is ir.Procedure) { | 831 if (func.parent is ir.Procedure) { |
| 868 ir.Procedure procedure = func.parent; | 832 ir.Procedure procedure = func.parent; |
| 869 if (procedure.kind == ir.ProcedureKind.Factory) { | 833 if (procedure.kind == ir.ProcedureKind.Factory) { |
| 870 ir.Class cls = procedure.enclosingClass; | 834 ir.Class cls = procedure.enclosingClass; |
| 871 return _getTypeVariable(cls.typeParameters[index]); | 835 return _getTypeVariable(cls.typeParameters[index]); |
| 872 } else { | 836 } else { |
| 873 int typeVariableIndex = _typeVariableList.length; | 837 return _typeVariables.register( |
| 874 TypeVariableEntity typeVariable = createTypeVariable( | 838 createTypeVariable(_getMethod(procedure), node.name, index)); |
| 875 typeVariableIndex, _getMethod(procedure), node.name, index); | |
| 876 _typeVariableList.add(typeVariable); | |
| 877 return typeVariable; | |
| 878 } | 839 } |
| 879 } | 840 } |
| 880 } | 841 } |
| 881 throw new UnsupportedError('Unsupported type parameter type node $node.'); | 842 throw new UnsupportedError('Unsupported type parameter type node $node.'); |
| 882 }); | 843 }); |
| 883 } | 844 } |
| 884 | 845 |
| 885 ConstructorEntity _getConstructor(ir.Member node) { | 846 ConstructorEntity _getConstructor(ir.Member node) { |
| 886 return _constructorMap.putIfAbsent(node, () { | 847 return _constructorMap.putIfAbsent(node, () { |
| 887 int memberIndex = _memberData.length; | 848 MemberDefinition definition; |
| 888 ConstructorEntity constructor; | 849 ir.FunctionNode functionNode; |
| 889 ClassEntity enclosingClass = _getClass(node.enclosingClass); | 850 ClassEntity enclosingClass = _getClass(node.enclosingClass); |
| 890 Name name = getName(node.name); | 851 Name name = getName(node.name); |
| 891 bool isExternal = node.isExternal; | 852 bool isExternal = node.isExternal; |
| 892 | 853 |
| 893 ir.FunctionNode functionNode; | 854 IndexedConstructor constructor; |
| 894 MemberDefinition definition; | |
| 895 if (node is ir.Constructor) { | 855 if (node is ir.Constructor) { |
| 896 functionNode = node.function; | 856 functionNode = node.function; |
| 897 constructor = createGenerativeConstructor(memberIndex, enclosingClass, | 857 constructor = createGenerativeConstructor( |
| 898 name, _getParameterStructure(functionNode), | 858 enclosingClass, name, _getParameterStructure(functionNode), |
| 899 isExternal: isExternal, isConst: node.isConst); | 859 isExternal: isExternal, isConst: node.isConst); |
| 900 definition = new SpecialMemberDefinition( | 860 definition = new SpecialMemberDefinition( |
| 901 constructor, node, MemberKind.constructor); | 861 constructor, node, MemberKind.constructor); |
| 902 } else if (node is ir.Procedure) { | 862 } else if (node is ir.Procedure) { |
| 903 functionNode = node.function; | 863 functionNode = node.function; |
| 904 bool isFromEnvironment = isExternal && | 864 bool isFromEnvironment = isExternal && |
| 905 name.text == 'fromEnvironment' && | 865 name.text == 'fromEnvironment' && |
| 906 const ['int', 'bool', 'String'].contains(enclosingClass.name); | 866 const ['int', 'bool', 'String'].contains(enclosingClass.name); |
| 907 constructor = createFactoryConstructor(memberIndex, enclosingClass, | 867 constructor = createFactoryConstructor( |
| 908 name, _getParameterStructure(functionNode), | 868 enclosingClass, name, _getParameterStructure(functionNode), |
| 909 isExternal: isExternal, | 869 isExternal: isExternal, |
| 910 isConst: node.isConst, | 870 isConst: node.isConst, |
| 911 isFromEnvironmentConstructor: isFromEnvironment); | 871 isFromEnvironmentConstructor: isFromEnvironment); |
| 912 definition = new RegularMemberDefinition(constructor, node); | 872 definition = new RegularMemberDefinition(constructor, node); |
| 913 } else { | 873 } else { |
| 914 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. | 874 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
| 915 throw failedAt( | 875 throw failedAt( |
| 916 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); | 876 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
| 917 } | 877 } |
| 918 _memberData.add(new ConstructorDataImpl(node, functionNode, definition)); | 878 return _members.register<IndexedConstructor, ConstructorData>( |
| 919 _memberList.add(constructor); | 879 constructor, new ConstructorDataImpl(node, functionNode, definition)); |
| 920 return constructor; | |
| 921 }); | 880 }); |
| 922 } | 881 } |
| 923 | 882 |
| 924 AsyncMarker _getAsyncMarker(ir.FunctionNode node) { | 883 AsyncMarker _getAsyncMarker(ir.FunctionNode node) { |
| 925 switch (node.asyncMarker) { | 884 switch (node.asyncMarker) { |
| 926 case ir.AsyncMarker.Async: | 885 case ir.AsyncMarker.Async: |
| 927 return AsyncMarker.ASYNC; | 886 return AsyncMarker.ASYNC; |
| 928 case ir.AsyncMarker.AsyncStar: | 887 case ir.AsyncMarker.AsyncStar: |
| 929 return AsyncMarker.ASYNC_STAR; | 888 return AsyncMarker.ASYNC_STAR; |
| 930 case ir.AsyncMarker.Sync: | 889 case ir.AsyncMarker.Sync: |
| 931 return AsyncMarker.SYNC; | 890 return AsyncMarker.SYNC; |
| 932 case ir.AsyncMarker.SyncStar: | 891 case ir.AsyncMarker.SyncStar: |
| 933 return AsyncMarker.SYNC_STAR; | 892 return AsyncMarker.SYNC_STAR; |
| 934 case ir.AsyncMarker.SyncYielding: | 893 case ir.AsyncMarker.SyncYielding: |
| 935 default: | 894 default: |
| 936 throw new UnsupportedError( | 895 throw new UnsupportedError( |
| 937 "Async marker ${node.asyncMarker} is not supported."); | 896 "Async marker ${node.asyncMarker} is not supported."); |
| 938 } | 897 } |
| 939 } | 898 } |
| 940 | 899 |
| 941 FunctionEntity _getMethod(ir.Procedure node) { | 900 FunctionEntity _getMethod(ir.Procedure node) { |
| 942 return _methodMap.putIfAbsent(node, () { | 901 return _methodMap.putIfAbsent(node, () { |
| 943 int memberIndex = _memberData.length; | |
| 944 LibraryEntity library; | 902 LibraryEntity library; |
| 945 ClassEntity enclosingClass; | 903 ClassEntity enclosingClass; |
| 946 if (node.enclosingClass != null) { | 904 if (node.enclosingClass != null) { |
| 947 enclosingClass = _getClass(node.enclosingClass); | 905 enclosingClass = _getClass(node.enclosingClass); |
| 948 library = enclosingClass.library; | 906 library = enclosingClass.library; |
| 949 } else { | 907 } else { |
| 950 library = _getLibrary(node.enclosingLibrary); | 908 library = _getLibrary(node.enclosingLibrary); |
| 951 } | 909 } |
| 952 Name name = getName(node.name); | 910 Name name = getName(node.name); |
| 953 bool isStatic = node.isStatic; | 911 bool isStatic = node.isStatic; |
| 954 bool isExternal = node.isExternal; | 912 bool isExternal = node.isExternal; |
| 955 bool isAbstract = node.isAbstract; | 913 bool isAbstract = node.isAbstract; |
| 914 AsyncMarker asyncMarker = _getAsyncMarker(node.function); |
| 956 IndexedFunction function; | 915 IndexedFunction function; |
| 957 AsyncMarker asyncMarker = _getAsyncMarker(node.function); | |
| 958 switch (node.kind) { | 916 switch (node.kind) { |
| 959 case ir.ProcedureKind.Factory: | 917 case ir.ProcedureKind.Factory: |
| 960 throw new UnsupportedError("Cannot create method from factory."); | 918 throw new UnsupportedError("Cannot create method from factory."); |
| 961 case ir.ProcedureKind.Getter: | 919 case ir.ProcedureKind.Getter: |
| 962 function = createGetter( | 920 function = createGetter(library, enclosingClass, name, asyncMarker, |
| 963 memberIndex, library, enclosingClass, name, asyncMarker, | |
| 964 isStatic: isStatic, | 921 isStatic: isStatic, |
| 965 isExternal: isExternal, | 922 isExternal: isExternal, |
| 966 isAbstract: isAbstract); | 923 isAbstract: isAbstract); |
| 967 break; | 924 break; |
| 968 case ir.ProcedureKind.Method: | 925 case ir.ProcedureKind.Method: |
| 969 case ir.ProcedureKind.Operator: | 926 case ir.ProcedureKind.Operator: |
| 970 function = createMethod(memberIndex, library, enclosingClass, name, | 927 function = createMethod(library, enclosingClass, name, |
| 971 _getParameterStructure(node.function), asyncMarker, | 928 _getParameterStructure(node.function), asyncMarker, |
| 972 isStatic: isStatic, | 929 isStatic: isStatic, |
| 973 isExternal: isExternal, | 930 isExternal: isExternal, |
| 974 isAbstract: isAbstract); | 931 isAbstract: isAbstract); |
| 975 break; | 932 break; |
| 976 case ir.ProcedureKind.Setter: | 933 case ir.ProcedureKind.Setter: |
| 977 assert(asyncMarker == AsyncMarker.SYNC); | 934 assert(asyncMarker == AsyncMarker.SYNC); |
| 978 function = createSetter( | 935 function = createSetter(library, enclosingClass, name.setter, |
| 979 memberIndex, library, enclosingClass, name.setter, | |
| 980 isStatic: isStatic, | 936 isStatic: isStatic, |
| 981 isExternal: isExternal, | 937 isExternal: isExternal, |
| 982 isAbstract: isAbstract); | 938 isAbstract: isAbstract); |
| 983 break; | 939 break; |
| 984 } | 940 } |
| 985 _memberData.add(new FunctionDataImpl( | 941 return _members.register<IndexedFunction, FunctionData>( |
| 986 node, node.function, new RegularMemberDefinition(function, node))); | 942 function, |
| 987 _memberList.add(function); | 943 new FunctionDataImpl(node, node.function, |
| 988 return function; | 944 new RegularMemberDefinition(function, node))); |
| 989 }); | 945 }); |
| 990 } | 946 } |
| 991 | 947 |
| 992 FieldEntity _getField(ir.Field node) { | 948 FieldEntity _getField(ir.Field node) { |
| 993 return _fieldMap.putIfAbsent(node, () { | 949 return _fieldMap.putIfAbsent(node, () { |
| 994 int memberIndex = _memberData.length; | |
| 995 LibraryEntity library; | 950 LibraryEntity library; |
| 996 ClassEntity enclosingClass; | 951 ClassEntity enclosingClass; |
| 997 if (node.enclosingClass != null) { | 952 if (node.enclosingClass != null) { |
| 998 enclosingClass = _getClass(node.enclosingClass); | 953 enclosingClass = _getClass(node.enclosingClass); |
| 999 library = enclosingClass.library; | 954 library = enclosingClass.library; |
| 1000 } else { | 955 } else { |
| 1001 library = _getLibrary(node.enclosingLibrary); | 956 library = _getLibrary(node.enclosingLibrary); |
| 1002 } | 957 } |
| 1003 Name name = getName(node.name); | 958 Name name = getName(node.name); |
| 1004 bool isStatic = node.isStatic; | 959 bool isStatic = node.isStatic; |
| 1005 FieldEntity field = createField( | 960 IndexedField field = createField(library, enclosingClass, name, |
| 1006 memberIndex, library, enclosingClass, name, | |
| 1007 isStatic: isStatic, | 961 isStatic: isStatic, |
| 1008 isAssignable: node.isMutable, | 962 isAssignable: node.isMutable, |
| 1009 isConst: node.isConst); | 963 isConst: node.isConst); |
| 1010 _memberData.add( | 964 return _members.register<IndexedField, FieldData>(field, |
| 1011 new FieldDataImpl(node, new RegularMemberDefinition(field, node))); | 965 new FieldDataImpl(node, new RegularMemberDefinition(field, node))); |
| 1012 _memberList.add(field); | |
| 1013 return field; | |
| 1014 }); | 966 }); |
| 1015 } | 967 } |
| 1016 | 968 |
| 1017 ParameterStructure _getParameterStructure(ir.FunctionNode node) { | 969 ParameterStructure _getParameterStructure(ir.FunctionNode node) { |
| 1018 // TODO(johnniwinther): Cache the computed function type. | 970 // TODO(johnniwinther): Cache the computed function type. |
| 1019 int requiredParameters = node.requiredParameterCount; | 971 int requiredParameters = node.requiredParameterCount; |
| 1020 int positionalParameters = node.positionalParameters.length; | 972 int positionalParameters = node.positionalParameters.length; |
| 1021 List<String> namedParameters = | 973 List<String> namedParameters = |
| 1022 node.namedParameters.map((p) => p.name).toList()..sort(); | 974 node.namedParameters.map((p) => p.name).toList()..sort(); |
| 1023 return new ParameterStructure( | 975 return new ParameterStructure( |
| 1024 requiredParameters, positionalParameters, namedParameters); | 976 requiredParameters, positionalParameters, namedParameters); |
| 1025 } | 977 } |
| 1026 | 978 |
| 1027 IndexedLibrary createLibrary(int libraryIndex, String name, Uri canonicalUri); | 979 IndexedLibrary createLibrary(String name, Uri canonicalUri); |
| 1028 | 980 |
| 1029 IndexedClass createClass(LibraryEntity library, int classIndex, String name, | 981 IndexedClass createClass(LibraryEntity library, String name, |
| 1030 {bool isAbstract}); | 982 {bool isAbstract}); |
| 1031 | 983 |
| 1032 IndexedTypedef createTypedef( | 984 IndexedTypedef createTypedef(LibraryEntity library, String name); |
| 1033 LibraryEntity library, int typedefIndex, String name); | |
| 1034 | 985 |
| 1035 TypeVariableEntity createTypeVariable( | 986 TypeVariableEntity createTypeVariable( |
| 1036 int typeVariableIndex, Entity typeDeclaration, String name, int index); | 987 Entity typeDeclaration, String name, int index); |
| 1037 | 988 |
| 1038 IndexedConstructor createGenerativeConstructor( | 989 IndexedConstructor createGenerativeConstructor(ClassEntity enclosingClass, |
| 1039 int memberIndex, | 990 Name name, ParameterStructure parameterStructure, |
| 1040 ClassEntity enclosingClass, | 991 {bool isExternal, bool isConst}); |
| 1041 Name name, | |
| 1042 ParameterStructure parameterStructure, | |
| 1043 {bool isExternal, | |
| 1044 bool isConst}); | |
| 1045 | 992 |
| 1046 IndexedConstructor createFactoryConstructor( | 993 IndexedConstructor createFactoryConstructor(ClassEntity enclosingClass, |
| 1047 int memberIndex, | 994 Name name, ParameterStructure parameterStructure, |
| 1048 ClassEntity enclosingClass, | 995 {bool isExternal, bool isConst, bool isFromEnvironmentConstructor}); |
| 1049 Name name, | |
| 1050 ParameterStructure parameterStructure, | |
| 1051 {bool isExternal, | |
| 1052 bool isConst, | |
| 1053 bool isFromEnvironmentConstructor}); | |
| 1054 | 996 |
| 1055 IndexedFunction createGetter(int memberIndex, LibraryEntity library, | 997 IndexedFunction createGetter(LibraryEntity library, |
| 1056 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, | 998 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, |
| 1057 {bool isStatic, bool isExternal, bool isAbstract}); | 999 {bool isStatic, bool isExternal, bool isAbstract}); |
| 1058 | 1000 |
| 1059 IndexedFunction createMethod( | 1001 IndexedFunction createMethod( |
| 1060 int memberIndex, | |
| 1061 LibraryEntity library, | 1002 LibraryEntity library, |
| 1062 ClassEntity enclosingClass, | 1003 ClassEntity enclosingClass, |
| 1063 Name name, | 1004 Name name, |
| 1064 ParameterStructure parameterStructure, | 1005 ParameterStructure parameterStructure, |
| 1065 AsyncMarker asyncMarker, | 1006 AsyncMarker asyncMarker, |
| 1066 {bool isStatic, | 1007 {bool isStatic, |
| 1067 bool isExternal, | 1008 bool isExternal, |
| 1068 bool isAbstract}); | 1009 bool isAbstract}); |
| 1069 | 1010 |
| 1070 IndexedFunction createSetter(int memberIndex, LibraryEntity library, | 1011 IndexedFunction createSetter( |
| 1071 ClassEntity enclosingClass, Name name, | 1012 LibraryEntity library, ClassEntity enclosingClass, Name name, |
| 1072 {bool isStatic, bool isExternal, bool isAbstract}); | 1013 {bool isStatic, bool isExternal, bool isAbstract}); |
| 1073 | 1014 |
| 1074 IndexedField createField(int memberIndex, LibraryEntity library, | 1015 IndexedField createField( |
| 1075 ClassEntity enclosingClass, Name name, | 1016 LibraryEntity library, ClassEntity enclosingClass, Name name, |
| 1076 {bool isStatic, bool isAssignable, bool isConst}); | 1017 {bool isStatic, bool isAssignable, bool isConst}); |
| 1077 } | 1018 } |
| 1078 | 1019 |
| 1079 /// Completes the [ElementCreatorMixin] by creating K-model elements. | 1020 /// Completes the [ElementCreatorMixin] by creating K-model elements. |
| 1080 abstract class KElementCreatorMixin implements ElementCreatorMixin { | 1021 abstract class KElementCreatorMixin implements ElementCreatorMixin { |
| 1081 IndexedLibrary createLibrary( | 1022 IndexedLibrary createLibrary(String name, Uri canonicalUri) { |
| 1082 int libraryIndex, String name, Uri canonicalUri) { | 1023 return new KLibrary(name, canonicalUri); |
| 1083 return new KLibrary(libraryIndex, name, canonicalUri); | |
| 1084 } | 1024 } |
| 1085 | 1025 |
| 1086 IndexedClass createClass(LibraryEntity library, int classIndex, String name, | 1026 IndexedClass createClass(LibraryEntity library, String name, |
| 1087 {bool isAbstract}) { | 1027 {bool isAbstract}) { |
| 1088 return new KClass(library, classIndex, name, isAbstract: isAbstract); | 1028 return new KClass(library, name, isAbstract: isAbstract); |
| 1089 } | 1029 } |
| 1090 | 1030 |
| 1091 @override | 1031 @override |
| 1092 IndexedTypedef createTypedef( | 1032 IndexedTypedef createTypedef(LibraryEntity library, String name) { |
| 1093 LibraryEntity library, int typedefIndex, String name) { | |
| 1094 throw new UnsupportedError('KElementCreatorMixin.createTypedef'); | 1033 throw new UnsupportedError('KElementCreatorMixin.createTypedef'); |
| 1095 } | 1034 } |
| 1096 | 1035 |
| 1097 TypeVariableEntity createTypeVariable( | 1036 TypeVariableEntity createTypeVariable( |
| 1098 int typeVariableIndex, Entity typeDeclaration, String name, int index) { | 1037 Entity typeDeclaration, String name, int index) { |
| 1099 return new KTypeVariable(typeVariableIndex, typeDeclaration, name, index); | 1038 return new KTypeVariable(typeDeclaration, name, index); |
| 1100 } | 1039 } |
| 1101 | 1040 |
| 1102 IndexedConstructor createGenerativeConstructor( | 1041 IndexedConstructor createGenerativeConstructor(ClassEntity enclosingClass, |
| 1103 int memberIndex, | 1042 Name name, ParameterStructure parameterStructure, |
| 1104 ClassEntity enclosingClass, | 1043 {bool isExternal, bool isConst}) { |
| 1105 Name name, | 1044 return new KGenerativeConstructor(enclosingClass, name, parameterStructure, |
| 1106 ParameterStructure parameterStructure, | |
| 1107 {bool isExternal, | |
| 1108 bool isConst}) { | |
| 1109 return new KGenerativeConstructor( | |
| 1110 memberIndex, enclosingClass, name, parameterStructure, | |
| 1111 isExternal: isExternal, isConst: isConst); | 1045 isExternal: isExternal, isConst: isConst); |
| 1112 } | 1046 } |
| 1113 | 1047 |
| 1114 IndexedConstructor createFactoryConstructor( | 1048 IndexedConstructor createFactoryConstructor(ClassEntity enclosingClass, |
| 1115 int memberIndex, | 1049 Name name, ParameterStructure parameterStructure, |
| 1116 ClassEntity enclosingClass, | 1050 {bool isExternal, bool isConst, bool isFromEnvironmentConstructor}) { |
| 1117 Name name, | 1051 return new KFactoryConstructor(enclosingClass, name, parameterStructure, |
| 1118 ParameterStructure parameterStructure, | |
| 1119 {bool isExternal, | |
| 1120 bool isConst, | |
| 1121 bool isFromEnvironmentConstructor}) { | |
| 1122 return new KFactoryConstructor( | |
| 1123 memberIndex, enclosingClass, name, parameterStructure, | |
| 1124 isExternal: isExternal, | 1052 isExternal: isExternal, |
| 1125 isConst: isConst, | 1053 isConst: isConst, |
| 1126 isFromEnvironmentConstructor: isFromEnvironmentConstructor); | 1054 isFromEnvironmentConstructor: isFromEnvironmentConstructor); |
| 1127 } | 1055 } |
| 1128 | 1056 |
| 1129 IndexedFunction createGetter(int memberIndex, LibraryEntity library, | 1057 IndexedFunction createGetter(LibraryEntity library, |
| 1130 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, | 1058 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, |
| 1131 {bool isStatic, bool isExternal, bool isAbstract}) { | 1059 {bool isStatic, bool isExternal, bool isAbstract}) { |
| 1132 return new KGetter(memberIndex, library, enclosingClass, name, asyncMarker, | 1060 return new KGetter(library, enclosingClass, name, asyncMarker, |
| 1133 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); | 1061 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); |
| 1134 } | 1062 } |
| 1135 | 1063 |
| 1136 IndexedFunction createMethod( | 1064 IndexedFunction createMethod( |
| 1137 int memberIndex, | |
| 1138 LibraryEntity library, | 1065 LibraryEntity library, |
| 1139 ClassEntity enclosingClass, | 1066 ClassEntity enclosingClass, |
| 1140 Name name, | 1067 Name name, |
| 1141 ParameterStructure parameterStructure, | 1068 ParameterStructure parameterStructure, |
| 1142 AsyncMarker asyncMarker, | 1069 AsyncMarker asyncMarker, |
| 1143 {bool isStatic, | 1070 {bool isStatic, |
| 1144 bool isExternal, | 1071 bool isExternal, |
| 1145 bool isAbstract}) { | 1072 bool isAbstract}) { |
| 1146 return new KMethod(memberIndex, library, enclosingClass, name, | 1073 return new KMethod( |
| 1147 parameterStructure, asyncMarker, | 1074 library, enclosingClass, name, parameterStructure, asyncMarker, |
| 1148 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); | 1075 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); |
| 1149 } | 1076 } |
| 1150 | 1077 |
| 1151 IndexedFunction createSetter(int memberIndex, LibraryEntity library, | 1078 IndexedFunction createSetter( |
| 1152 ClassEntity enclosingClass, Name name, | 1079 LibraryEntity library, ClassEntity enclosingClass, Name name, |
| 1153 {bool isStatic, bool isExternal, bool isAbstract}) { | 1080 {bool isStatic, bool isExternal, bool isAbstract}) { |
| 1154 return new KSetter(memberIndex, library, enclosingClass, name, | 1081 return new KSetter(library, enclosingClass, name, |
| 1155 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); | 1082 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); |
| 1156 } | 1083 } |
| 1157 | 1084 |
| 1158 IndexedField createField(int memberIndex, LibraryEntity library, | 1085 IndexedField createField( |
| 1159 ClassEntity enclosingClass, Name name, | 1086 LibraryEntity library, ClassEntity enclosingClass, Name name, |
| 1160 {bool isStatic, bool isAssignable, bool isConst}) { | 1087 {bool isStatic, bool isAssignable, bool isConst}) { |
| 1161 return new KField(memberIndex, library, enclosingClass, name, | 1088 return new KField(library, enclosingClass, name, |
| 1162 isStatic: isStatic, isAssignable: isAssignable, isConst: isConst); | 1089 isStatic: isStatic, isAssignable: isAssignable, isConst: isConst); |
| 1163 } | 1090 } |
| 1164 } | 1091 } |
| 1165 | 1092 |
| 1166 /// Implementation of [KernelToElementMapForImpact] that only supports world | 1093 /// Implementation of [KernelToElementMapForImpact] that only supports world |
| 1167 /// impact computation. | 1094 /// impact computation. |
| 1168 class KernelToElementMapForImpactImpl extends KernelToElementMapBase | 1095 class KernelToElementMapForImpactImpl extends KernelToElementMapBase |
| 1169 with | 1096 with |
| 1170 KernelToElementMapForImpactMixin, | 1097 KernelToElementMapForImpactMixin, |
| 1171 ElementCreatorMixin, | 1098 ElementCreatorMixin, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1197 void addProgram(ir.Program program) { | 1124 void addProgram(ir.Program program) { |
| 1198 _env.addProgram(program); | 1125 _env.addProgram(program); |
| 1199 } | 1126 } |
| 1200 | 1127 |
| 1201 @override | 1128 @override |
| 1202 native.BehaviorBuilder get nativeBehaviorBuilder => | 1129 native.BehaviorBuilder get nativeBehaviorBuilder => |
| 1203 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(elementEnvironment, | 1130 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(elementEnvironment, |
| 1204 commonElements, nativeBasicData, reporter, _options); | 1131 commonElements, nativeBasicData, reporter, _options); |
| 1205 | 1132 |
| 1206 ResolutionImpact computeWorldImpact(KMember member) { | 1133 ResolutionImpact computeWorldImpact(KMember member) { |
| 1207 return buildKernelImpact( | 1134 return buildKernelImpact(_members.getData(member).definition.node, this); |
| 1208 _memberData[member.memberIndex].definition.node, this); | |
| 1209 } | 1135 } |
| 1210 | 1136 |
| 1211 ScopeModel computeScopeModel(KMember member) { | 1137 ScopeModel computeScopeModel(KMember member) { |
| 1212 ir.Member node = _memberData[member.memberIndex].definition.node; | 1138 ir.Member node = _members.getData(member).definition.node; |
| 1213 return KernelClosureAnalysis.computeScopeModel(member, node); | 1139 return KernelClosureAnalysis.computeScopeModel(member, node); |
| 1214 } | 1140 } |
| 1215 | 1141 |
| 1216 /// Returns the kernel [ir.Procedure] node for the [method]. | 1142 /// Returns the kernel [ir.Procedure] node for the [method]. |
| 1217 ir.Procedure _lookupProcedure(KFunction method) { | 1143 ir.Procedure _lookupProcedure(KFunction method) { |
| 1218 return _memberData[method.memberIndex].definition.node; | 1144 return _members.getData(method).definition.node; |
| 1219 } | 1145 } |
| 1220 | 1146 |
| 1221 @override | 1147 @override |
| 1222 Local getLocalFunction(ir.TreeNode node) { | 1148 Local getLocalFunction(ir.TreeNode node) { |
| 1223 assert( | 1149 assert( |
| 1224 node is ir.FunctionDeclaration || node is ir.FunctionExpression, | 1150 node is ir.FunctionDeclaration || node is ir.FunctionExpression, |
| 1225 failedAt( | 1151 failedAt( |
| 1226 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); | 1152 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); |
| 1227 return _localFunctionMap.putIfAbsent(node, () { | 1153 return _localFunctionMap.putIfAbsent(node, () { |
| 1228 MemberEntity memberContext; | 1154 MemberEntity memberContext; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1250 } else if (node is ir.FunctionExpression) { | 1176 } else if (node is ir.FunctionExpression) { |
| 1251 functionType = getFunctionType(node.function); | 1177 functionType = getFunctionType(node.function); |
| 1252 } | 1178 } |
| 1253 return new KLocalFunction( | 1179 return new KLocalFunction( |
| 1254 name, memberContext, executableContext, functionType); | 1180 name, memberContext, executableContext, functionType); |
| 1255 }); | 1181 }); |
| 1256 } | 1182 } |
| 1257 | 1183 |
| 1258 bool _implementsFunction(IndexedClass cls) { | 1184 bool _implementsFunction(IndexedClass cls) { |
| 1259 assert(checkFamily(cls)); | 1185 assert(checkFamily(cls)); |
| 1260 ClassData data = _classData[cls.classIndex]; | 1186 ClassData data = _classes.getData(cls); |
| 1261 OrderedTypeSet orderedTypeSet = data.orderedTypeSet; | 1187 OrderedTypeSet orderedTypeSet = data.orderedTypeSet; |
| 1262 InterfaceType supertype = orderedTypeSet.asInstanceOf( | 1188 InterfaceType supertype = orderedTypeSet.asInstanceOf( |
| 1263 commonElements.functionClass, | 1189 commonElements.functionClass, |
| 1264 _getHierarchyDepth(commonElements.functionClass)); | 1190 _getHierarchyDepth(commonElements.functionClass)); |
| 1265 if (supertype != null) { | 1191 if (supertype != null) { |
| 1266 return true; | 1192 return true; |
| 1267 } | 1193 } |
| 1268 _ensureCallType(cls, data); | 1194 _ensureCallType(cls, data); |
| 1269 return data.callType is FunctionType; | 1195 return data.callType is FunctionType; |
| 1270 } | 1196 } |
| 1271 } | 1197 } |
| 1272 | 1198 |
| 1273 class KernelElementEnvironment implements ElementEnvironment { | 1199 class KernelElementEnvironment implements ElementEnvironment { |
| 1274 final KernelToElementMapBase elementMap; | 1200 final KernelToElementMapBase elementMap; |
| 1275 | 1201 |
| 1276 KernelElementEnvironment(this.elementMap); | 1202 KernelElementEnvironment(this.elementMap); |
| 1277 | 1203 |
| 1278 @override | 1204 @override |
| 1279 DartType get dynamicType => const DynamicType(); | 1205 DartType get dynamicType => const DynamicType(); |
| 1280 | 1206 |
| 1281 @override | 1207 @override |
| 1282 LibraryEntity get mainLibrary => elementMap._mainLibrary; | 1208 LibraryEntity get mainLibrary => elementMap._mainLibrary; |
| 1283 | 1209 |
| 1284 @override | 1210 @override |
| 1285 FunctionEntity get mainFunction => elementMap._mainFunction; | 1211 FunctionEntity get mainFunction => elementMap._mainFunction; |
| 1286 | 1212 |
| 1287 @override | 1213 @override |
| 1288 Iterable<LibraryEntity> get libraries => elementMap._libraries; | 1214 Iterable<LibraryEntity> get libraries => elementMap._libraryList; |
| 1289 | 1215 |
| 1290 @override | 1216 @override |
| 1291 String getLibraryName(LibraryEntity library) { | 1217 String getLibraryName(LibraryEntity library) { |
| 1292 return elementMap._getLibraryName(library); | 1218 return elementMap._getLibraryName(library); |
| 1293 } | 1219 } |
| 1294 | 1220 |
| 1295 @override | 1221 @override |
| 1296 InterfaceType getThisType(ClassEntity cls) { | 1222 InterfaceType getThisType(ClassEntity cls) { |
| 1297 return elementMap._getThisType(cls); | 1223 return elementMap._getThisType(cls); |
| 1298 } | 1224 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 } | 1405 } |
| 1480 | 1406 |
| 1481 @override | 1407 @override |
| 1482 bool isDeferredLoadLibraryGetter(MemberEntity member) { | 1408 bool isDeferredLoadLibraryGetter(MemberEntity member) { |
| 1483 // TODO(redemption): Support these. | 1409 // TODO(redemption): Support these. |
| 1484 return false; | 1410 return false; |
| 1485 } | 1411 } |
| 1486 | 1412 |
| 1487 @override | 1413 @override |
| 1488 Iterable<ConstantValue> getLibraryMetadata(covariant IndexedLibrary library) { | 1414 Iterable<ConstantValue> getLibraryMetadata(covariant IndexedLibrary library) { |
| 1489 LibraryData libraryData = elementMap._libraryData[library.libraryIndex]; | 1415 LibraryData libraryData = elementMap._libraries.getData(library); |
| 1490 return libraryData.getMetadata(elementMap); | 1416 return libraryData.getMetadata(elementMap); |
| 1491 } | 1417 } |
| 1492 | 1418 |
| 1493 @override | 1419 @override |
| 1494 Iterable<ConstantValue> getClassMetadata(covariant IndexedClass cls) { | 1420 Iterable<ConstantValue> getClassMetadata(covariant IndexedClass cls) { |
| 1495 ClassData classData = elementMap._classData[cls.classIndex]; | 1421 ClassData classData = elementMap._classes.getData(cls); |
| 1496 return classData.getMetadata(elementMap); | 1422 return classData.getMetadata(elementMap); |
| 1497 } | 1423 } |
| 1498 | 1424 |
| 1499 @override | 1425 @override |
| 1500 Iterable<ConstantValue> getTypedefMetadata(TypedefEntity typedef) { | 1426 Iterable<ConstantValue> getTypedefMetadata(TypedefEntity typedef) { |
| 1501 // TODO(redemption): Support this. | 1427 // TODO(redemption): Support this. |
| 1502 throw new UnsupportedError('ElementEnvironment.getTypedefMetadata'); | 1428 throw new UnsupportedError('ElementEnvironment.getTypedefMetadata'); |
| 1503 } | 1429 } |
| 1504 | 1430 |
| 1505 @override | 1431 @override |
| 1506 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member, | 1432 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member, |
| 1507 {bool includeParameterMetadata: false}) { | 1433 {bool includeParameterMetadata: false}) { |
| 1508 // TODO(redemption): Support includeParameterMetadata. | 1434 // TODO(redemption): Support includeParameterMetadata. |
| 1509 MemberData memberData = elementMap._memberData[member.memberIndex]; | 1435 MemberData memberData = elementMap._members.getData(member); |
| 1510 return memberData.getMetadata(elementMap); | 1436 return memberData.getMetadata(elementMap); |
| 1511 } | 1437 } |
| 1512 | 1438 |
| 1513 @override | 1439 @override |
| 1514 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { | 1440 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { |
| 1515 // TODO(redemption): Support this. | 1441 // TODO(redemption): Support this. |
| 1516 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); | 1442 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); |
| 1517 } | 1443 } |
| 1518 } | 1444 } |
| 1519 | 1445 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 } | 1792 } |
| 1867 } | 1793 } |
| 1868 | 1794 |
| 1869 // Interface for testing equivalence of Kernel-based entities. | 1795 // Interface for testing equivalence of Kernel-based entities. |
| 1870 class WorldDeconstructionForTesting { | 1796 class WorldDeconstructionForTesting { |
| 1871 final KernelToElementMapBase elementMap; | 1797 final KernelToElementMapBase elementMap; |
| 1872 | 1798 |
| 1873 WorldDeconstructionForTesting(this.elementMap); | 1799 WorldDeconstructionForTesting(this.elementMap); |
| 1874 | 1800 |
| 1875 IndexedClass getSuperclassForClass(IndexedClass cls) { | 1801 IndexedClass getSuperclassForClass(IndexedClass cls) { |
| 1876 ClassEnv env = elementMap._classEnvs[cls.classIndex]; | 1802 ClassEnv env = elementMap._classes.getEnv(cls); |
| 1877 ir.Supertype supertype = env.cls.supertype; | 1803 ir.Supertype supertype = env.cls.supertype; |
| 1878 if (supertype == null) return null; | 1804 if (supertype == null) return null; |
| 1879 return elementMap.getClass(supertype.classNode); | 1805 return elementMap.getClass(supertype.classNode); |
| 1880 } | 1806 } |
| 1881 | 1807 |
| 1882 bool isUnnamedMixinApplication(IndexedClass cls) { | 1808 bool isUnnamedMixinApplication(IndexedClass cls) { |
| 1883 return elementMap._isUnnamedMixinApplication(cls); | 1809 return elementMap._isUnnamedMixinApplication(cls); |
| 1884 } | 1810 } |
| 1885 | 1811 |
| 1886 InterfaceType getMixinTypeForClass(IndexedClass cls) { | 1812 InterfaceType getMixinTypeForClass(IndexedClass cls) { |
| 1887 ClassEnv env = elementMap._classEnvs[cls.classIndex]; | 1813 ClassEnv env = elementMap._classes.getEnv(cls); |
| 1888 ir.Supertype mixedInType = env.cls.mixedInType; | 1814 ir.Supertype mixedInType = env.cls.mixedInType; |
| 1889 if (mixedInType == null) return null; | 1815 if (mixedInType == null) return null; |
| 1890 return elementMap.createInterfaceType( | 1816 return elementMap.createInterfaceType( |
| 1891 mixedInType.classNode, mixedInType.typeArguments); | 1817 mixedInType.classNode, mixedInType.typeArguments); |
| 1892 } | 1818 } |
| 1893 } | 1819 } |
| 1894 | 1820 |
| 1895 class KernelNativeMemberResolver extends NativeMemberResolverBase { | 1821 class KernelNativeMemberResolver extends NativeMemberResolverBase { |
| 1896 final KernelToElementMapForImpactImpl elementMap; | 1822 final KernelToElementMapForImpactImpl elementMap; |
| 1897 final NativeBasicData nativeBasicData; | 1823 final NativeBasicData nativeBasicData; |
| 1898 final NativeDataBuilder nativeDataBuilder; | 1824 final NativeDataBuilder nativeDataBuilder; |
| 1899 | 1825 |
| 1900 KernelNativeMemberResolver( | 1826 KernelNativeMemberResolver( |
| 1901 this.elementMap, this.nativeBasicData, this.nativeDataBuilder); | 1827 this.elementMap, this.nativeBasicData, this.nativeDataBuilder); |
| 1902 | 1828 |
| 1903 @override | 1829 @override |
| 1904 ElementEnvironment get elementEnvironment => elementMap.elementEnvironment; | 1830 ElementEnvironment get elementEnvironment => elementMap.elementEnvironment; |
| 1905 | 1831 |
| 1906 @override | 1832 @override |
| 1907 CommonElements get commonElements => elementMap.commonElements; | 1833 CommonElements get commonElements => elementMap.commonElements; |
| 1908 | 1834 |
| 1909 @override | 1835 @override |
| 1910 native.NativeBehavior computeNativeFieldStoreBehavior( | 1836 native.NativeBehavior computeNativeFieldStoreBehavior( |
| 1911 covariant KField field) { | 1837 covariant KField field) { |
| 1912 ir.Field node = elementMap._memberData[field.memberIndex].definition.node; | 1838 ir.Field node = elementMap._members.getData(field).definition.node; |
| 1913 return elementMap.getNativeBehaviorForFieldStore(node); | 1839 return elementMap.getNativeBehaviorForFieldStore(node); |
| 1914 } | 1840 } |
| 1915 | 1841 |
| 1916 @override | 1842 @override |
| 1917 native.NativeBehavior computeNativeFieldLoadBehavior(covariant KField field, | 1843 native.NativeBehavior computeNativeFieldLoadBehavior(covariant KField field, |
| 1918 {bool isJsInterop}) { | 1844 {bool isJsInterop}) { |
| 1919 ir.Field node = elementMap._memberData[field.memberIndex].definition.node; | 1845 ir.Field node = elementMap._members.getData(field).definition.node; |
| 1920 return elementMap.getNativeBehaviorForFieldLoad(node, | 1846 return elementMap.getNativeBehaviorForFieldLoad(node, |
| 1921 isJsInterop: isJsInterop); | 1847 isJsInterop: isJsInterop); |
| 1922 } | 1848 } |
| 1923 | 1849 |
| 1924 @override | 1850 @override |
| 1925 native.NativeBehavior computeNativeMethodBehavior( | 1851 native.NativeBehavior computeNativeMethodBehavior( |
| 1926 covariant KFunction function, | 1852 covariant KFunction function, |
| 1927 {bool isJsInterop}) { | 1853 {bool isJsInterop}) { |
| 1928 ir.Member node = | 1854 ir.Member node = elementMap._members.getData(function).definition.node; |
| 1929 elementMap._memberData[function.memberIndex].definition.node; | |
| 1930 return elementMap.getNativeBehaviorForMethod(node, | 1855 return elementMap.getNativeBehaviorForMethod(node, |
| 1931 isJsInterop: isJsInterop); | 1856 isJsInterop: isJsInterop); |
| 1932 } | 1857 } |
| 1933 | 1858 |
| 1934 @override | 1859 @override |
| 1935 bool isNativeMethod(covariant KFunction function) { | 1860 bool isNativeMethod(covariant KFunction function) { |
| 1936 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; | 1861 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; |
| 1937 ir.Member node = | 1862 ir.Member node = elementMap._members.getData(function).definition.node; |
| 1938 elementMap._memberData[function.memberIndex].definition.node; | |
| 1939 return node.isExternal && | 1863 return node.isExternal && |
| 1940 !elementMap.isForeignLibrary(node.enclosingLibrary); | 1864 !elementMap.isForeignLibrary(node.enclosingLibrary); |
| 1941 } | 1865 } |
| 1942 | 1866 |
| 1943 @override | 1867 @override |
| 1944 bool isJsInteropMember(MemberEntity element) { | 1868 bool isJsInteropMember(MemberEntity element) { |
| 1945 return nativeBasicData.isJsInteropMember(element); | 1869 return nativeBasicData.isJsInteropMember(element); |
| 1946 } | 1870 } |
| 1947 } | 1871 } |
| 1948 | 1872 |
| 1949 class JsToFrontendMapImpl extends JsToFrontendMapBase | 1873 class JsToFrontendMapImpl extends JsToFrontendMapBase |
| 1950 implements JsToFrontendMap { | 1874 implements JsToFrontendMap { |
| 1951 final KernelToElementMapBase _backend; | 1875 final KernelToElementMapBase _backend; |
| 1952 | 1876 |
| 1953 JsToFrontendMapImpl(this._backend); | 1877 JsToFrontendMapImpl(this._backend); |
| 1954 | 1878 |
| 1955 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { | 1879 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { |
| 1956 return _backend._libraryList[library.libraryIndex]; | 1880 return _backend._libraries.getEntity(library.libraryIndex); |
| 1957 } | 1881 } |
| 1958 | 1882 |
| 1959 ClassEntity toBackendClass(covariant IndexedClass cls) { | 1883 ClassEntity toBackendClass(covariant IndexedClass cls) { |
| 1960 return _backend._classList[cls.classIndex]; | 1884 return _backend._classes.getEntity(cls.classIndex); |
| 1961 } | 1885 } |
| 1962 | 1886 |
| 1963 MemberEntity toBackendMember(covariant IndexedMember member) { | 1887 MemberEntity toBackendMember(covariant IndexedMember member) { |
| 1964 return _backend._memberList[member.memberIndex]; | 1888 return _backend._members.getEntity(member.memberIndex); |
| 1965 } | 1889 } |
| 1966 | 1890 |
| 1967 TypeVariableEntity toBackendTypeVariable( | 1891 TypeVariableEntity toBackendTypeVariable( |
| 1968 covariant IndexedTypeVariable typeVariable) { | 1892 covariant IndexedTypeVariable typeVariable) { |
| 1969 return _backend._typeVariableList[typeVariable.typeVariableIndex]; | 1893 return _backend._typeVariables.getEntity(typeVariable.typeVariableIndex); |
| 1970 } | 1894 } |
| 1971 } | 1895 } |
| 1972 | 1896 |
| 1973 class JsKernelToElementMap extends KernelToElementMapBase | 1897 class JsKernelToElementMap extends KernelToElementMapBase |
| 1974 with | 1898 with |
| 1975 KernelToElementMapForBuildingMixin, | 1899 KernelToElementMapForBuildingMixin, |
| 1976 JsElementCreatorMixin, | 1900 JsElementCreatorMixin, |
| 1977 // TODO(johnniwinther): Avoid mixing in [ElementCreatorMixin]. The | 1901 // TODO(johnniwinther): Avoid mixing in [ElementCreatorMixin]. The |
| 1978 // codegen world should be a strict subset of the resolution world and | 1902 // codegen world should be a strict subset of the resolution world and |
| 1979 // creating elements for IR nodes should therefore not be needed. | 1903 // creating elements for IR nodes should therefore not be needed. |
| 1980 // Currently some are created purely for testing (like | 1904 // Currently some are created purely for testing (like |
| 1981 // `element == commonElements.foo`, where 'foo' might not be live). | 1905 // `element == commonElements.foo`, where 'foo' might not be live). |
| 1982 // Others are created because we do a | 1906 // Others are created because we do a |
| 1983 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted | 1907 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted |
| 1984 // library. | 1908 // library. |
| 1985 ElementCreatorMixin | 1909 ElementCreatorMixin |
| 1986 implements | 1910 implements |
| 1987 KernelToWorldBuilder { | 1911 KernelToWorldBuilder { |
| 1988 NativeBasicData nativeBasicData; | 1912 NativeBasicData nativeBasicData; |
| 1989 | 1913 |
| 1990 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, | 1914 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, |
| 1991 KernelToElementMapForImpactImpl _elementMap) | 1915 KernelToElementMapForImpactImpl _elementMap) |
| 1992 : super(reporter, environment) { | 1916 : super(reporter, environment) { |
| 1993 _env = _elementMap._env; | 1917 _env = _elementMap._env; |
| 1994 for (int libraryIndex = 0; | 1918 for (int libraryIndex = 0; |
| 1995 libraryIndex < _elementMap._libraryEnvs.length; | 1919 libraryIndex < _elementMap._libraries.length; |
| 1996 libraryIndex++) { | 1920 libraryIndex++) { |
| 1997 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; | 1921 IndexedLibrary oldLibrary = |
| 1998 LibraryData data = _elementMap._libraryData[libraryIndex]; | 1922 _elementMap._libraries.getEntity(libraryIndex); |
| 1999 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; | 1923 LibraryEnv env = _elementMap._libraries.getEnv(oldLibrary); |
| 2000 LibraryEntity newLibrary = convertLibrary(oldLibrary); | 1924 LibraryData data = _elementMap._libraries.getData(oldLibrary); |
| 2001 _libraryMap[env.library] = newLibrary; | 1925 IndexedLibrary newLibrary = convertLibrary(oldLibrary); |
| 2002 _libraryList.add(newLibrary); | 1926 _libraryMap[env.library] = |
| 2003 _libraryData.add(data.copy()); | 1927 _libraries.register<IndexedLibrary, LibraryData, LibraryEnv>( |
| 2004 _libraryEnvs.add(env); | 1928 newLibrary, data.copy(), env); |
| 1929 assert(newLibrary.libraryIndex == oldLibrary.libraryIndex); |
| 2005 } | 1930 } |
| 2006 for (int classIndex = 0; | 1931 for (int classIndex = 0; |
| 2007 classIndex < _elementMap._classEnvs.length; | 1932 classIndex < _elementMap._classes.length; |
| 2008 classIndex++) { | 1933 classIndex++) { |
| 2009 ClassEnv env = _elementMap._classEnvs[classIndex]; | 1934 IndexedClass oldClass = _elementMap._classes.getEntity(classIndex); |
| 2010 ClassData data = _elementMap._classData[classIndex]; | 1935 ClassEnv env = _elementMap._classes.getEnv(oldClass); |
| 2011 ClassEntity oldClass = _elementMap._classList[classIndex]; | 1936 ClassData data = _elementMap._classes.getData(oldClass); |
| 2012 IndexedLibrary oldLibrary = oldClass.library; | 1937 IndexedLibrary oldLibrary = oldClass.library; |
| 2013 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; | 1938 LibraryEntity newLibrary = _libraries.getEntity(oldLibrary.libraryIndex); |
| 2014 ClassEntity newClass = convertClass(newLibrary, oldClass); | 1939 IndexedClass newClass = convertClass(newLibrary, oldClass); |
| 2015 _classMap[env.cls] = newClass; | 1940 _classMap[env.cls] = _classes.register(newClass, data.copy(), env); |
| 2016 _classList.add(newClass); | 1941 assert(newClass.classIndex == oldClass.classIndex); |
| 2017 _classEnvs.add(env); | |
| 2018 _classData.add(data.copy()); | |
| 2019 } | 1942 } |
| 2020 for (int memberIndex = 0; | 1943 for (int memberIndex = 0; |
| 2021 memberIndex < _elementMap._memberData.length; | 1944 memberIndex < _elementMap._members.length; |
| 2022 memberIndex++) { | 1945 memberIndex++) { |
| 2023 MemberDataImpl data = _elementMap._memberData[memberIndex]; | 1946 IndexedMember oldMember = _elementMap._members.getEntity(memberIndex); |
| 2024 MemberEntity oldMember = _elementMap._memberList[memberIndex]; | 1947 MemberDataImpl data = _elementMap._members.getData(oldMember); |
| 2025 IndexedLibrary oldLibrary = oldMember.library; | 1948 IndexedLibrary oldLibrary = oldMember.library; |
| 2026 IndexedClass oldClass = oldMember.enclosingClass; | 1949 IndexedClass oldClass = oldMember.enclosingClass; |
| 2027 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; | 1950 LibraryEntity newLibrary = _libraries.getEntity(oldLibrary.libraryIndex); |
| 2028 ClassEntity newClass = | 1951 ClassEntity newClass = |
| 2029 oldClass != null ? _classList[oldClass.classIndex] : null; | 1952 oldClass != null ? _classes.getEntity(oldClass.classIndex) : null; |
| 2030 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember); | 1953 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember); |
| 2031 _memberList.add(newMember); | 1954 _members.register(newMember, data.copy()); |
| 2032 _memberData.add(data.copy()); | 1955 assert(newMember.memberIndex == oldMember.memberIndex); |
| 2033 if (newMember.isField) { | 1956 if (newMember.isField) { |
| 2034 _fieldMap[data.node] = newMember; | 1957 _fieldMap[data.node] = newMember; |
| 2035 } else if (newMember.isConstructor) { | 1958 } else if (newMember.isConstructor) { |
| 2036 _constructorMap[data.node] = newMember; | 1959 _constructorMap[data.node] = newMember; |
| 2037 } else { | 1960 } else { |
| 2038 _methodMap[data.node] = newMember; | 1961 _methodMap[data.node] = newMember; |
| 2039 } | 1962 } |
| 2040 } | 1963 } |
| 2041 for (int typeVariableIndex = 0; | 1964 for (int typeVariableIndex = 0; |
| 2042 typeVariableIndex < _elementMap._typeVariableList.length; | 1965 typeVariableIndex < _elementMap._typeVariables.length; |
| 2043 typeVariableIndex++) { | 1966 typeVariableIndex++) { |
| 2044 TypeVariableEntity oldTypeVariable = | 1967 IndexedTypeVariable oldTypeVariable = |
| 2045 _elementMap._typeVariableList[typeVariableIndex]; | 1968 _elementMap._typeVariables.getEntity(typeVariableIndex); |
| 2046 Entity newTypeDeclaration; | 1969 Entity newTypeDeclaration; |
| 2047 if (oldTypeVariable.typeDeclaration is ClassEntity) { | 1970 if (oldTypeVariable.typeDeclaration is ClassEntity) { |
| 2048 IndexedClass cls = oldTypeVariable.typeDeclaration; | 1971 IndexedClass cls = oldTypeVariable.typeDeclaration; |
| 2049 newTypeDeclaration = _classList[cls.classIndex]; | 1972 newTypeDeclaration = _classes.getEntity(cls.classIndex); |
| 2050 } else { | 1973 } else { |
| 2051 IndexedMember member = oldTypeVariable.typeDeclaration; | 1974 IndexedMember member = oldTypeVariable.typeDeclaration; |
| 2052 newTypeDeclaration = _memberList[member.memberIndex]; | 1975 newTypeDeclaration = _members.getEntity(member.memberIndex); |
| 2053 } | 1976 } |
| 2054 TypeVariableEntity newTypeVariable = createTypeVariable(typeVariableIndex, | 1977 IndexedTypeVariable newTypeVariable = createTypeVariable( |
| 2055 newTypeDeclaration, oldTypeVariable.name, oldTypeVariable.index); | 1978 newTypeDeclaration, oldTypeVariable.name, oldTypeVariable.index); |
| 2056 _typeVariableList.add(newTypeVariable); | 1979 _typeVariables.register<IndexedTypeVariable>(newTypeVariable); |
| 1980 assert(newTypeVariable.typeVariableIndex == |
| 1981 oldTypeVariable.typeVariableIndex); |
| 2057 } | 1982 } |
| 2058 } | 1983 } |
| 2059 | 1984 |
| 2060 @override | 1985 @override |
| 2061 bool checkFamily(Entity entity) { | 1986 bool checkFamily(Entity entity) { |
| 2062 assert( | 1987 assert( |
| 2063 '$entity'.startsWith(jsElementPrefix), | 1988 '$entity'.startsWith(jsElementPrefix), |
| 2064 failedAt(entity, | 1989 failedAt(entity, |
| 2065 "Unexpected entity $entity, expected family $jsElementPrefix.")); | 1990 "Unexpected entity $entity, expected family $jsElementPrefix.")); |
| 2066 return true; | 1991 return true; |
| 2067 } | 1992 } |
| 2068 | 1993 |
| 2069 @override | 1994 @override |
| 2070 Spannable getSpannable(MemberEntity member, ir.Node node) { | 1995 Spannable getSpannable(MemberEntity member, ir.Node node) { |
| 2071 return _getSpannable(member, node); | 1996 return _getSpannable(member, node); |
| 2072 } | 1997 } |
| 2073 | 1998 |
| 2074 Iterable<LibraryEntity> get _libraries { | 1999 Iterable<LibraryEntity> get _libraryList { |
| 2075 return _libraryMap.values; | 2000 return _libraryMap.values; |
| 2076 } | 2001 } |
| 2077 | 2002 |
| 2078 @override | 2003 @override |
| 2079 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv env]) { | 2004 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv env]) { |
| 2080 LibraryEntity library = _libraryMap[node]; | 2005 LibraryEntity library = _libraryMap[node]; |
| 2081 assert(library != null, "No library entity for $node"); | 2006 assert(library != null, "No library entity for $node"); |
| 2082 return library; | 2007 return library; |
| 2083 } | 2008 } |
| 2084 | 2009 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2112 return constructor; | 2037 return constructor; |
| 2113 } | 2038 } |
| 2114 | 2039 |
| 2115 FunctionEntity getConstructorBody(ir.Constructor node) { | 2040 FunctionEntity getConstructorBody(ir.Constructor node) { |
| 2116 ConstructorEntity constructor = getConstructor(node); | 2041 ConstructorEntity constructor = getConstructor(node); |
| 2117 return _getConstructorBody(node, constructor); | 2042 return _getConstructorBody(node, constructor); |
| 2118 } | 2043 } |
| 2119 | 2044 |
| 2120 FunctionEntity _getConstructorBody( | 2045 FunctionEntity _getConstructorBody( |
| 2121 ir.Constructor node, covariant IndexedConstructor constructor) { | 2046 ir.Constructor node, covariant IndexedConstructor constructor) { |
| 2122 ConstructorDataImpl data = _memberData[constructor.memberIndex]; | 2047 ConstructorDataImpl data = _members.getData(constructor); |
| 2123 if (data.constructorBody == null) { | 2048 if (data.constructorBody == null) { |
| 2124 ConstructorBodyEntity constructorBody = data.constructorBody = | 2049 JConstructorBody constructorBody = createConstructorBody(constructor); |
| 2125 createConstructorBody(_memberList.length, constructor); | 2050 _members.register<IndexedFunction, FunctionData>( |
| 2126 _memberList.add(constructorBody); | 2051 constructorBody, |
| 2127 _memberData.add(new FunctionDataImpl( | 2052 new FunctionDataImpl( |
| 2128 node, | 2053 node, |
| 2129 node.function, | 2054 node.function, |
| 2130 new SpecialMemberDefinition( | 2055 new SpecialMemberDefinition( |
| 2131 constructorBody, node, MemberKind.constructorBody))); | 2056 constructorBody, node, MemberKind.constructorBody))); |
| 2132 IndexedClass cls = constructor.enclosingClass; | 2057 IndexedClass cls = constructor.enclosingClass; |
| 2133 ClassEnvImpl classEnv = _classEnvs[cls.classIndex]; | 2058 ClassEnvImpl classEnv = _classes.getEnv(cls); |
| 2134 // TODO(johnniwinther): Avoid this by only including live members in the | 2059 // TODO(johnniwinther): Avoid this by only including live members in the |
| 2135 // js-model. | 2060 // js-model. |
| 2136 classEnv.addConstructorBody(constructorBody); | 2061 classEnv.addConstructorBody(constructorBody); |
| 2062 data.constructorBody = constructorBody; |
| 2137 } | 2063 } |
| 2138 return data.constructorBody; | 2064 return data.constructorBody; |
| 2139 } | 2065 } |
| 2140 | 2066 |
| 2141 ConstructorBodyEntity createConstructorBody( | 2067 JConstructorBody createConstructorBody(ConstructorEntity constructor); |
| 2142 int memberIndex, ConstructorEntity constructor); | |
| 2143 | 2068 |
| 2144 @override | 2069 @override |
| 2145 MemberDefinition getMemberDefinition(MemberEntity member) { | 2070 MemberDefinition getMemberDefinition(MemberEntity member) { |
| 2146 return _getMemberDefinition(member); | 2071 return _getMemberDefinition(member); |
| 2147 } | 2072 } |
| 2148 | 2073 |
| 2149 @override | 2074 @override |
| 2150 ClassDefinition getClassDefinition(ClassEntity cls) { | 2075 ClassDefinition getClassDefinition(ClassEntity cls) { |
| 2151 return _getClassDefinition(cls); | 2076 return _getClassDefinition(cls); |
| 2152 } | 2077 } |
| 2153 | 2078 |
| 2154 @override | 2079 @override |
| 2155 ConstantValue getFieldConstantValue(covariant IndexedField field) { | 2080 ConstantValue getFieldConstantValue(covariant IndexedField field) { |
| 2156 assert(checkFamily(field)); | 2081 assert(checkFamily(field)); |
| 2157 FieldData data = _memberData[field.memberIndex]; | 2082 FieldData data = _members.getData(field); |
| 2158 return data.getFieldConstantValue(this); | 2083 return data.getFieldConstantValue(this); |
| 2159 } | 2084 } |
| 2160 | 2085 |
| 2161 bool hasConstantFieldInitializer(covariant IndexedField field) { | 2086 bool hasConstantFieldInitializer(covariant IndexedField field) { |
| 2162 assert(checkFamily(field)); | 2087 FieldData data = _members.getData(field); |
| 2163 FieldData data = _memberData[field.memberIndex]; | |
| 2164 return data.hasConstantFieldInitializer(this); | 2088 return data.hasConstantFieldInitializer(this); |
| 2165 } | 2089 } |
| 2166 | 2090 |
| 2167 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { | 2091 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { |
| 2168 assert(checkFamily(field)); | 2092 FieldData data = _members.getData(field); |
| 2169 FieldData data = _memberData[field.memberIndex]; | |
| 2170 return data.getConstantFieldInitializer(this); | 2093 return data.getConstantFieldInitializer(this); |
| 2171 } | 2094 } |
| 2172 | 2095 |
| 2173 void forEachParameter(covariant IndexedFunction function, | 2096 void forEachParameter(covariant IndexedFunction function, |
| 2174 void f(DartType type, String name, ConstantValue defaultValue)) { | 2097 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 2175 FunctionData data = _memberData[function.memberIndex]; | 2098 FunctionData data = _members.getData(function); |
| 2176 data.forEachParameter(this, f); | 2099 data.forEachParameter(this, f); |
| 2177 } | 2100 } |
| 2178 | 2101 |
| 2179 void _forEachConstructorBody( | 2102 void _forEachConstructorBody( |
| 2180 IndexedClass cls, void f(ConstructorBodyEntity member)) { | 2103 IndexedClass cls, void f(ConstructorBodyEntity member)) { |
| 2181 ClassEnv env = _classEnvs[cls.classIndex]; | 2104 ClassEnv env = _classes.getEnv(cls); |
| 2182 env.forEachConstructorBody(f); | 2105 env.forEachConstructorBody(f); |
| 2183 } | 2106 } |
| 2184 | 2107 |
| 2185 JRecordField _constructBoxedField( | 2108 JRecordField _constructBoxedField( |
| 2186 ir.VariableDeclaration variable, | 2109 ir.VariableDeclaration variable, |
| 2187 BoxLocal boxLocal, | 2110 BoxLocal boxLocal, |
| 2188 JClass container, | 2111 JClass container, |
| 2189 Map<String, MemberEntity> memberMap, | 2112 Map<String, MemberEntity> memberMap, |
| 2190 KernelToLocalsMap localsMap) { | 2113 KernelToLocalsMap localsMap) { |
| 2191 Local local = localsMap.getLocalVariable(variable); | 2114 Local local = localsMap.getLocalVariable(variable); |
| 2192 var boxedField = new JRecordField( | 2115 JRecordField boxedField = |
| 2193 local.name, _memberData.length, boxLocal, container, variable.isConst); | 2116 new JRecordField(local.name, boxLocal, container, variable.isConst); |
| 2194 _memberList.add(boxedField); | 2117 _members.register( |
| 2195 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( | |
| 2196 boxedField, | 2118 boxedField, |
| 2197 computeSourceSpanFromTreeNode(variable), | 2119 new ClosureFieldData(new ClosureMemberDefinition( |
| 2198 MemberKind.closureField, | 2120 boxedField, |
| 2199 variable))); | 2121 computeSourceSpanFromTreeNode(variable), |
| 2122 MemberKind.closureField, |
| 2123 variable))); |
| 2200 memberMap[boxedField.name] = boxedField; | 2124 memberMap[boxedField.name] = boxedField; |
| 2201 | 2125 |
| 2202 return boxedField; | 2126 return boxedField; |
| 2203 } | 2127 } |
| 2204 | 2128 |
| 2205 /// Make a container controlling access to records, that is, variables that | 2129 /// Make a container controlling access to records, that is, variables that |
| 2206 /// are accessed in different scopes. This function creates the container | 2130 /// are accessed in different scopes. This function creates the container |
| 2207 /// and returns a map of locals to the corresponding records created. | 2131 /// and returns a map of locals to the corresponding records created. |
| 2208 Map<Local, JRecordField> makeRecordContainer( | 2132 Map<Local, JRecordField> makeRecordContainer( |
| 2209 KernelScopeInfo info, MemberEntity member, KernelToLocalsMap localsMap) { | 2133 KernelScopeInfo info, MemberEntity member, KernelToLocalsMap localsMap) { |
| 2210 Map<Local, JRecordField> boxedFields = {}; | 2134 Map<Local, JRecordField> boxedFields = {}; |
| 2211 if (info.boxedVariables.isNotEmpty) { | 2135 if (info.boxedVariables.isNotEmpty) { |
| 2212 NodeBox box = info.capturedVariablesAccessor; | 2136 NodeBox box = info.capturedVariablesAccessor; |
| 2213 | 2137 |
| 2214 var container = new JRecord(member.library, _classEnvs.length, box.name); | |
| 2215 _classList.add(container); | |
| 2216 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; | 2138 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; |
| 2217 _classEnvs.add(new RecordEnv(memberMap)); | 2139 JRecord container = new JRecord(member.library, box.name); |
| 2218 | |
| 2219 var containerData = new ClassData( | 2140 var containerData = new ClassData( |
| 2220 null, | 2141 null, |
| 2221 new ClosureClassDefinition(container, | 2142 new ClosureClassDefinition(container, |
| 2222 computeSourceSpanFromTreeNode(getMemberDefinition(member).node))); | 2143 computeSourceSpanFromTreeNode(getMemberDefinition(member).node))); |
| 2223 containerData | 2144 containerData |
| 2224 ..isMixinApplication = false | 2145 ..isMixinApplication = false |
| 2225 ..thisType = new InterfaceType(container, const <DartType>[]) | 2146 ..thisType = new InterfaceType(container, const <DartType>[]) |
| 2226 ..supertype = commonElements.objectType | 2147 ..supertype = commonElements.objectType |
| 2227 ..interfaces = const <InterfaceType>[]; | 2148 ..interfaces = const <InterfaceType>[]; |
| 2149 _classes.register(container, containerData, new RecordEnv(memberMap)); |
| 2150 |
| 2228 var setBuilder = new _KernelOrderedTypeSetBuilder(this, container); | 2151 var setBuilder = new _KernelOrderedTypeSetBuilder(this, container); |
| 2229 _classData.add(containerData); | |
| 2230 containerData.orderedTypeSet = setBuilder.createOrderedTypeSet( | 2152 containerData.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 2231 containerData.supertype, const Link<InterfaceType>()); | 2153 containerData.supertype, const Link<InterfaceType>()); |
| 2232 | 2154 |
| 2233 BoxLocal boxLocal = new BoxLocal(box.name, member); | 2155 BoxLocal boxLocal = new BoxLocal(box.name, member); |
| 2234 for (ir.VariableDeclaration variable in info.boxedVariables) { | 2156 for (ir.VariableDeclaration variable in info.boxedVariables) { |
| 2235 boxedFields[localsMap.getLocalVariable(variable)] = | 2157 boxedFields[localsMap.getLocalVariable(variable)] = |
| 2236 _constructBoxedField( | 2158 _constructBoxedField( |
| 2237 variable, boxLocal, container, memberMap, localsMap); | 2159 variable, boxLocal, container, memberMap, localsMap); |
| 2238 } | 2160 } |
| 2239 } | 2161 } |
| 2240 return boxedFields; | 2162 return boxedFields; |
| 2241 } | 2163 } |
| 2242 | 2164 |
| 2243 KernelClosureClass constructClosureClass( | 2165 KernelClosureClass constructClosureClass( |
| 2244 MemberEntity member, | 2166 MemberEntity member, |
| 2245 ir.FunctionNode node, | 2167 ir.FunctionNode node, |
| 2246 JLibrary enclosingLibrary, | 2168 JLibrary enclosingLibrary, |
| 2247 Map<Local, JRecordField> boxedCapturedVariables, | 2169 Map<Local, JRecordField> boxedCapturedVariables, |
| 2248 KernelScopeInfo info, | 2170 KernelScopeInfo info, |
| 2249 ir.Location location, | 2171 ir.Location location, |
| 2250 KernelToLocalsMap localsMap, | 2172 KernelToLocalsMap localsMap, |
| 2251 InterfaceType supertype) { | 2173 InterfaceType supertype) { |
| 2252 String name = _computeClosureName(node); | 2174 String name = _computeClosureName(node); |
| 2253 JClass classEntity = | 2175 SourceSpan location = computeSourceSpanFromTreeNode(node); |
| 2254 new JClosureClass(enclosingLibrary, _classEnvs.length, name); | |
| 2255 _classList.add(classEntity); | |
| 2256 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; | 2176 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; |
| 2257 _classEnvs.add(new ClosureClassEnv(memberMap)); | |
| 2258 | 2177 |
| 2178 JClass classEntity = new JClosureClass(enclosingLibrary, name); |
| 2259 // Create a classData and set up the interfaces and subclass | 2179 // Create a classData and set up the interfaces and subclass |
| 2260 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing | 2180 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing |
| 2261 var closureData = new ClassData( | 2181 var closureData = |
| 2262 null, | 2182 new ClassData(null, new ClosureClassDefinition(classEntity, location)); |
| 2263 new ClosureClassDefinition( | |
| 2264 classEntity, computeSourceSpanFromTreeNode(node))); | |
| 2265 closureData | 2183 closureData |
| 2266 ..isMixinApplication = false | 2184 ..isMixinApplication = false |
| 2267 ..thisType = closureData.rawType = | 2185 ..thisType = closureData.rawType = |
| 2268 new InterfaceType(classEntity, const <DartType>[]) | 2186 new InterfaceType(classEntity, const <DartType>[]) |
| 2269 ..supertype = supertype | 2187 ..supertype = supertype |
| 2270 ..interfaces = const <InterfaceType>[]; | 2188 ..interfaces = const <InterfaceType>[]; |
| 2189 _classes.register(classEntity, closureData, new ClosureClassEnv(memberMap)); |
| 2271 var setBuilder = new _KernelOrderedTypeSetBuilder(this, classEntity); | 2190 var setBuilder = new _KernelOrderedTypeSetBuilder(this, classEntity); |
| 2272 _classData.add(closureData); | |
| 2273 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( | 2191 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 2274 closureData.supertype, const Link<InterfaceType>()); | 2192 closureData.supertype, const Link<InterfaceType>()); |
| 2275 | 2193 |
| 2276 Local closureEntity; | 2194 Local closureEntity; |
| 2277 if (node.parent is ir.FunctionDeclaration) { | 2195 if (node.parent is ir.FunctionDeclaration) { |
| 2278 ir.FunctionDeclaration parent = node.parent; | 2196 ir.FunctionDeclaration parent = node.parent; |
| 2279 closureEntity = localsMap.getLocalVariable(parent.variable); | 2197 closureEntity = localsMap.getLocalVariable(parent.variable); |
| 2280 } else if (node.parent is ir.FunctionExpression) { | 2198 } else if (node.parent is ir.FunctionExpression) { |
| 2281 closureEntity = new JLocal('', localsMap.currentMember); | 2199 closureEntity = new JLocal('', localsMap.currentMember); |
| 2282 } | 2200 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2300 cls, | 2218 cls, |
| 2301 memberMap, | 2219 memberMap, |
| 2302 variable, | 2220 variable, |
| 2303 boxedCapturedVariables, | 2221 boxedCapturedVariables, |
| 2304 fieldNumber, | 2222 fieldNumber, |
| 2305 info.capturedVariablesAccessor, | 2223 info.capturedVariablesAccessor, |
| 2306 localsMap); | 2224 localsMap); |
| 2307 fieldNumber++; | 2225 fieldNumber++; |
| 2308 } | 2226 } |
| 2309 | 2227 |
| 2310 FunctionEntity callMethod = cls.callMethod = new JClosureCallMethod( | 2228 FunctionEntity callMethod = new JClosureCallMethod( |
| 2311 _memberData.length, | 2229 cls, _getParameterStructure(node), _getAsyncMarker(node)); |
| 2312 cls, | 2230 _members.register<IndexedFunction, FunctionData>( |
| 2313 _getParameterStructure(node), | 2231 callMethod, |
| 2314 _getAsyncMarker(node)); | 2232 new ClosureFunctionData( |
| 2315 _memberList.add(cls.callMethod); | 2233 new ClosureMemberDefinition( |
| 2316 | 2234 callMethod, location, MemberKind.closureCall, node.parent), |
| 2317 _memberData.add(new ClosureFunctionData( | 2235 getFunctionType(node), |
| 2318 new ClosureMemberDefinition(callMethod, closureData.definition.location, | 2236 node)); |
| 2319 MemberKind.closureCall, node.parent), | 2237 memberMap[callMethod.name] = cls.callMethod = callMethod; |
| 2320 getFunctionType(node), | |
| 2321 node)); | |
| 2322 memberMap[cls.callMethod.name] = cls.callMethod; | |
| 2323 return cls; | 2238 return cls; |
| 2324 } | 2239 } |
| 2325 | 2240 |
| 2326 _constructClosureField( | 2241 _constructClosureField( |
| 2327 MemberEntity member, | 2242 MemberEntity member, |
| 2328 KernelClosureClass cls, | 2243 KernelClosureClass cls, |
| 2329 Map<String, MemberEntity> memberMap, | 2244 Map<String, MemberEntity> memberMap, |
| 2330 ir.VariableDeclaration variable, | 2245 ir.VariableDeclaration variable, |
| 2331 Map<Local, JRecordField> boxedCapturedVariables, | 2246 Map<Local, JRecordField> boxedCapturedVariables, |
| 2332 int fieldNumber, | 2247 int fieldNumber, |
| 2333 NodeBox box, | 2248 NodeBox box, |
| 2334 KernelToLocalsMap localsMap) { | 2249 KernelToLocalsMap localsMap) { |
| 2335 // NOTE: This construction order may be slightly different than the | 2250 // NOTE: This construction order may be slightly different than the |
| 2336 // old Element version. The old version did all the boxed items and then | 2251 // old Element version. The old version did all the boxed items and then |
| 2337 // all the others. | 2252 // all the others. |
| 2338 Local capturedLocal = localsMap.getLocalVariable(variable); | 2253 Local capturedLocal = localsMap.getLocalVariable(variable); |
| 2339 JRecordField field = boxedCapturedVariables[capturedLocal]; | 2254 JRecordField field = boxedCapturedVariables[capturedLocal]; |
| 2340 FieldEntity closureField = new JClosureField( | 2255 FieldEntity closureField = new JClosureField( |
| 2341 _getClosureVariableName(capturedLocal.name, fieldNumber), | 2256 _getClosureVariableName(capturedLocal.name, fieldNumber), |
| 2342 _memberData.length, | |
| 2343 cls, | 2257 cls, |
| 2344 variable.isConst, | 2258 variable.isConst, |
| 2345 variable.isFinal || variable.isConst); | 2259 variable.isFinal || variable.isConst); |
| 2346 _memberList.add(closureField); | 2260 |
| 2347 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( | 2261 _members.register<IndexedField, FieldData>( |
| 2348 cls.localToFieldMap[capturedLocal], | 2262 closureField, |
| 2349 computeSourceSpanFromTreeNode(variable), | 2263 new ClosureFieldData(new ClosureMemberDefinition( |
| 2350 MemberKind.closureField, | 2264 cls.localToFieldMap[capturedLocal], |
| 2351 variable))); | 2265 computeSourceSpanFromTreeNode(variable), |
| 2266 MemberKind.closureField, |
| 2267 variable))); |
| 2352 memberMap[closureField.name] = closureField; | 2268 memberMap[closureField.name] = closureField; |
| 2353 if (boxedCapturedVariables.containsKey(capturedLocal)) { | 2269 if (boxedCapturedVariables.containsKey(capturedLocal)) { |
| 2354 cls.localToFieldMap[field.box] = closureField; | 2270 cls.localToFieldMap[field.box] = closureField; |
| 2355 cls.boxedVariables[capturedLocal] = field; | 2271 cls.boxedVariables[capturedLocal] = field; |
| 2356 } else { | 2272 } else { |
| 2357 cls.localToFieldMap[capturedLocal] = closureField; | 2273 cls.localToFieldMap[capturedLocal] = closureField; |
| 2358 } | 2274 } |
| 2359 } | 2275 } |
| 2360 | 2276 |
| 2361 // Returns a non-unique name for the given closure element. | 2277 // Returns a non-unique name for the given closure element. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2406 /// | 2322 /// |
| 2407 /// These names are not used in generated code, just as element name. | 2323 /// These names are not used in generated code, just as element name. |
| 2408 String _getClosureVariableName(String name, int id) { | 2324 String _getClosureVariableName(String name, int id) { |
| 2409 return "_captured_${name}_$id"; | 2325 return "_captured_${name}_$id"; |
| 2410 } | 2326 } |
| 2411 | 2327 |
| 2412 String getDeferredUri(ir.LibraryDependency node) { | 2328 String getDeferredUri(ir.LibraryDependency node) { |
| 2413 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2329 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 2414 } | 2330 } |
| 2415 } | 2331 } |
| OLD | NEW |