Chromium Code Reviews| 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 '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 final DiagnosticReporter reporter; | 70 final DiagnosticReporter reporter; |
| 71 CommonElements _commonElements; | 71 CommonElements _commonElements; |
| 72 ElementEnvironment _elementEnvironment; | 72 ElementEnvironment _elementEnvironment; |
| 73 DartTypeConverter _typeConverter; | 73 DartTypeConverter _typeConverter; |
| 74 KernelConstantEnvironment _constantEnvironment; | 74 KernelConstantEnvironment _constantEnvironment; |
| 75 _KernelDartTypes _types; | 75 _KernelDartTypes _types; |
| 76 | 76 |
| 77 /// Library environment. Used for fast lookup. | 77 /// Library environment. Used for fast lookup. |
| 78 ProgramEnv _env = new ProgramEnv(); | 78 ProgramEnv _env = new ProgramEnv(); |
| 79 | 79 |
| 80 List<LibraryEntity> _libraryList = <LibraryEntity>[]; | 80 final EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv> _libraries = |
| 81 List<ClassEntity> _classList = <ClassEntity>[]; | 81 new EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv>(); |
| 82 List<MemberEntity> _memberList = <MemberEntity>[]; | 82 final EntityDataEnvMap<IndexedClass, ClassData, ClassEnv> _classes = |
| 83 List<TypeVariableEntity> _typeVariableList = <TypeVariableEntity>[]; | 83 new EntityDataEnvMap<IndexedClass, ClassData, ClassEnv>(); |
| 84 List<TypedefEntity> _typedefList = <TypedefEntity>[]; | 84 final EntityDataMap<IndexedMember, MemberData> _members = |
| 85 | 85 new EntityDataMap<IndexedMember, MemberData>(); |
| 86 /// List of library environments by `IndexedLibrary.libraryIndex`. This is | 86 final EntityMap<IndexedTypeVariable> _typeVariables = |
| 87 /// used for fast lookup into library classes and members. | 87 new EntityMap<IndexedTypeVariable>(); |
| 88 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[]; | 88 final EntityDataMap<IndexedTypedef, TypedefData> _typedefs = |
| 89 | 89 new EntityDataMap<IndexedTypedef, TypedefData>(); |
| 90 /// List of library data by `IndexedLibrary.libraryIndex`. This is used for | |
| 91 /// fast lookup into library properties. | |
| 92 List<LibraryData> _libraryData = <LibraryData>[]; | |
| 93 | |
| 94 /// List of class environments by `IndexedClass.classIndex`. This is used for | |
| 95 /// fast lookup into class members. | |
| 96 List<ClassEnv> _classEnvs = <ClassEnv>[]; | |
| 97 | |
| 98 /// List of class data by `IndexedClass.classIndex`. This is used for | |
| 99 /// fast lookup into class properties. | |
| 100 List<ClassData> _classData = <ClassData>[]; | |
| 101 | |
| 102 /// List of member data by `IndexedMember.memberIndex`. This is used for | |
| 103 /// fast lookup into member properties. | |
| 104 List<MemberData> _memberData = <MemberData>[]; | |
| 105 | |
| 106 /// List of typedef data by `IndexedTypedef.typedefIndex`. This is used for | |
| 107 /// fast lookup into typedef properties. | |
| 108 List<TypedefData> _typedefData = <TypedefData>[]; | |
| 109 | 90 |
| 110 KernelToElementMapBase(this.reporter, Environment environment) { | 91 KernelToElementMapBase(this.reporter, Environment environment) { |
| 111 _elementEnvironment = new KernelElementEnvironment(this); | 92 _elementEnvironment = new KernelElementEnvironment(this); |
| 112 _commonElements = new CommonElements(_elementEnvironment); | 93 _commonElements = new CommonElements(_elementEnvironment); |
| 113 _constantEnvironment = new KernelConstantEnvironment(this, environment); | 94 _constantEnvironment = new KernelConstantEnvironment(this, environment); |
| 114 _typeConverter = new DartTypeConverter(this); | 95 _typeConverter = new DartTypeConverter(this); |
| 115 _types = new _KernelDartTypes(this); | 96 _types = new _KernelDartTypes(this); |
| 116 } | 97 } |
| 117 | 98 |
| 118 bool checkFamily(Entity entity); | 99 bool checkFamily(Entity entity); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 131 FunctionEntity get _mainFunction { | 112 FunctionEntity get _mainFunction { |
| 132 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; | 113 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; |
| 133 } | 114 } |
| 134 | 115 |
| 135 LibraryEntity get _mainLibrary { | 116 LibraryEntity get _mainLibrary { |
| 136 return _env.mainMethod != null | 117 return _env.mainMethod != null |
| 137 ? _getLibrary(_env.mainMethod.enclosingLibrary) | 118 ? _getLibrary(_env.mainMethod.enclosingLibrary) |
| 138 : null; | 119 : null; |
| 139 } | 120 } |
| 140 | 121 |
| 141 Iterable<LibraryEntity> get _libraries; | 122 Iterable<LibraryEntity> get _libraryList; |
| 142 | 123 |
| 143 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) { | 124 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) { |
| 144 SourceSpan fromSpannable(Spannable spannable) { | 125 SourceSpan fromSpannable(Spannable spannable) { |
| 145 if (spannable is IndexedLibrary && | 126 if (spannable is IndexedLibrary && |
| 146 spannable.libraryIndex < _libraryEnvs.length) { | 127 spannable.libraryIndex < _libraries.length) { |
| 147 LibraryEnv env = _libraryEnvs[spannable.libraryIndex]; | 128 LibraryEnv env = _libraries.getEnv(spannable.libraryIndex); |
| 148 return computeSourceSpanFromTreeNode(env.library); | 129 return computeSourceSpanFromTreeNode(env.library); |
| 149 } else if (spannable is IndexedClass && | 130 } else if (spannable is IndexedClass && |
| 150 spannable.classIndex < _classEnvs.length) { | 131 spannable.classIndex < _classes.length) { |
| 151 ClassData data = _classData[spannable.classIndex]; | 132 ClassData data = _classes.getData(spannable.classIndex); |
| 152 return data.definition.location; | 133 return data.definition.location; |
| 153 } else if (spannable is IndexedMember && | 134 } else if (spannable is IndexedMember && |
| 154 spannable.memberIndex < _memberData.length) { | 135 spannable.memberIndex < _members.length) { |
| 155 MemberData data = _memberData[spannable.memberIndex]; | 136 MemberData data = _members.getData(spannable.memberIndex); |
| 156 return data.definition.location; | 137 return data.definition.location; |
| 157 } | 138 } |
| 158 return null; | 139 return null; |
| 159 } | 140 } |
| 160 | 141 |
| 161 SourceSpan sourceSpan = fromSpannable(spannable); | 142 SourceSpan sourceSpan = fromSpannable(spannable); |
| 162 sourceSpan ??= fromSpannable(currentElement); | 143 sourceSpan ??= fromSpannable(currentElement); |
| 163 return sourceSpan; | 144 return sourceSpan; |
| 164 } | 145 } |
| 165 | 146 |
| 166 LibraryEntity lookupLibrary(Uri uri) { | 147 LibraryEntity lookupLibrary(Uri uri) { |
| 167 LibraryEnv libraryEnv = _env.lookupLibrary(uri); | 148 LibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 168 if (libraryEnv == null) return null; | 149 if (libraryEnv == null) return null; |
| 169 return _getLibrary(libraryEnv.library, libraryEnv); | 150 return _getLibrary(libraryEnv.library, libraryEnv); |
| 170 } | 151 } |
| 171 | 152 |
| 172 String _getLibraryName(IndexedLibrary library) { | 153 String _getLibraryName(IndexedLibrary library) { |
| 173 assert(checkFamily(library)); | 154 assert(checkFamily(library)); |
| 174 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 155 LibraryEnv libraryEnv = _libraries.getEnv(library.libraryIndex); |
| 175 return libraryEnv.library.name ?? ''; | 156 return libraryEnv.library.name ?? ''; |
| 176 } | 157 } |
| 177 | 158 |
| 178 MemberEntity lookupLibraryMember(IndexedLibrary library, String name, | 159 MemberEntity lookupLibraryMember(IndexedLibrary library, String name, |
| 179 {bool setter: false}) { | 160 {bool setter: false}) { |
| 180 assert(checkFamily(library)); | 161 assert(checkFamily(library)); |
| 181 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 162 LibraryEnv libraryEnv = _libraries.getEnv(library.libraryIndex); |
| 182 ir.Member member = libraryEnv.lookupMember(name, setter: setter); | 163 ir.Member member = libraryEnv.lookupMember(name, setter: setter); |
| 183 return member != null ? getMember(member) : null; | 164 return member != null ? getMember(member) : null; |
| 184 } | 165 } |
| 185 | 166 |
| 186 void _forEachLibraryMember( | 167 void _forEachLibraryMember( |
| 187 IndexedLibrary library, void f(MemberEntity member)) { | 168 IndexedLibrary library, void f(MemberEntity member)) { |
| 188 assert(checkFamily(library)); | 169 assert(checkFamily(library)); |
| 189 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 170 LibraryEnv libraryEnv = _libraries.getEnv(library.libraryIndex); |
| 190 libraryEnv.forEachMember((ir.Member node) { | 171 libraryEnv.forEachMember((ir.Member node) { |
| 191 f(getMember(node)); | 172 f(getMember(node)); |
| 192 }); | 173 }); |
| 193 } | 174 } |
| 194 | 175 |
| 195 ClassEntity lookupClass(IndexedLibrary library, String name) { | 176 ClassEntity lookupClass(IndexedLibrary library, String name) { |
| 196 assert(checkFamily(library)); | 177 assert(checkFamily(library)); |
| 197 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 178 LibraryEnv libraryEnv = _libraries.getEnv(library.libraryIndex); |
| 198 ClassEnv classEnv = libraryEnv.lookupClass(name); | 179 ClassEnv classEnv = libraryEnv.lookupClass(name); |
| 199 if (classEnv != null) { | 180 if (classEnv != null) { |
| 200 return _getClass(classEnv.cls, classEnv); | 181 return _getClass(classEnv.cls, classEnv); |
| 201 } | 182 } |
| 202 return null; | 183 return null; |
| 203 } | 184 } |
| 204 | 185 |
| 205 void _forEachClass(IndexedLibrary library, void f(ClassEntity cls)) { | 186 void _forEachClass(IndexedLibrary library, void f(ClassEntity cls)) { |
| 206 assert(checkFamily(library)); | 187 assert(checkFamily(library)); |
| 207 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 188 LibraryEnv libraryEnv = _libraries.getEnv(library.libraryIndex); |
| 208 libraryEnv.forEachClass((ClassEnv classEnv) { | 189 libraryEnv.forEachClass((ClassEnv classEnv) { |
| 209 if (!classEnv.isUnnamedMixinApplication) { | 190 if (!classEnv.isUnnamedMixinApplication) { |
| 210 f(_getClass(classEnv.cls, classEnv)); | 191 f(_getClass(classEnv.cls, classEnv)); |
| 211 } | 192 } |
| 212 }); | 193 }); |
| 213 } | 194 } |
| 214 | 195 |
| 215 MemberEntity lookupClassMember(IndexedClass cls, String name, | 196 MemberEntity lookupClassMember(IndexedClass cls, String name, |
| 216 {bool setter: false}) { | 197 {bool setter: false}) { |
| 217 assert(checkFamily(cls)); | 198 assert(checkFamily(cls)); |
| 218 ClassEnv classEnv = _classEnvs[cls.classIndex]; | 199 ClassEnv classEnv = _classes.getEnv(cls.classIndex); |
| 219 return classEnv.lookupMember(this, name, setter: setter); | 200 return classEnv.lookupMember(this, name, setter: setter); |
| 220 } | 201 } |
| 221 | 202 |
| 222 ConstructorEntity lookupConstructor(IndexedClass cls, String name) { | 203 ConstructorEntity lookupConstructor(IndexedClass cls, String name) { |
| 223 assert(checkFamily(cls)); | 204 assert(checkFamily(cls)); |
| 224 ClassEnv classEnv = _classEnvs[cls.classIndex]; | 205 ClassEnv classEnv = _classes.getEnv(cls.classIndex); |
| 225 return classEnv.lookupConstructor(this, name); | 206 return classEnv.lookupConstructor(this, name); |
| 226 } | 207 } |
| 227 | 208 |
| 228 @override | 209 @override |
| 229 InterfaceType createInterfaceType( | 210 InterfaceType createInterfaceType( |
| 230 ir.Class cls, List<ir.DartType> typeArguments) { | 211 ir.Class cls, List<ir.DartType> typeArguments) { |
| 231 return new InterfaceType(getClass(cls), getDartTypes(typeArguments)); | 212 return new InterfaceType(getClass(cls), getDartTypes(typeArguments)); |
| 232 } | 213 } |
| 233 | 214 |
| 234 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node); | 215 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node); |
| 235 | 216 |
| 236 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]); | 217 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]); |
| 237 | 218 |
| 238 @override | 219 @override |
| 239 ClassEntity getClass(ir.Class node) => _getClass(node); | 220 ClassEntity getClass(ir.Class node) => _getClass(node); |
| 240 | 221 |
| 241 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]); | 222 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]); |
| 242 | 223 |
| 243 InterfaceType _getSuperType(IndexedClass cls) { | 224 InterfaceType _getSuperType(IndexedClass cls) { |
| 244 assert(checkFamily(cls)); | 225 assert(checkFamily(cls)); |
| 245 ClassData data = _classData[cls.classIndex]; | 226 ClassData data = _classes.getData(cls.classIndex); |
| 246 _ensureSupertypes(cls, data); | 227 _ensureSupertypes(cls, data); |
| 247 return data.supertype; | 228 return data.supertype; |
| 248 } | 229 } |
| 249 | 230 |
| 250 void _ensureThisAndRawType(ClassEntity cls, ClassData data) { | 231 void _ensureThisAndRawType(ClassEntity cls, ClassData data) { |
| 251 assert(checkFamily(cls)); | 232 assert(checkFamily(cls)); |
| 252 if (data.thisType == null) { | 233 if (data.thisType == null) { |
| 253 ir.Class node = data.cls; | 234 ir.Class node = data.cls; |
| 254 if (node.typeParameters.isEmpty) { | 235 if (node.typeParameters.isEmpty) { |
| 255 data.thisType = | 236 data.thisType = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 283 ir.Class node = data.cls; | 264 ir.Class node = data.cls; |
| 284 | 265 |
| 285 if (node.supertype == null) { | 266 if (node.supertype == null) { |
| 286 data.orderedTypeSet = new OrderedTypeSet.singleton(data.thisType); | 267 data.orderedTypeSet = new OrderedTypeSet.singleton(data.thisType); |
| 287 data.isMixinApplication = false; | 268 data.isMixinApplication = false; |
| 288 data.interfaces = const <InterfaceType>[]; | 269 data.interfaces = const <InterfaceType>[]; |
| 289 } else { | 270 } else { |
| 290 InterfaceType processSupertype(ir.Supertype node) { | 271 InterfaceType processSupertype(ir.Supertype node) { |
| 291 InterfaceType supertype = _typeConverter.visitSupertype(node); | 272 InterfaceType supertype = _typeConverter.visitSupertype(node); |
| 292 IndexedClass superclass = supertype.element; | 273 IndexedClass superclass = supertype.element; |
| 293 ClassData superdata = _classData[superclass.classIndex]; | 274 ClassData superdata = _classes.getData(superclass.classIndex); |
| 294 _ensureSupertypes(superclass, superdata); | 275 _ensureSupertypes(superclass, superdata); |
| 295 return supertype; | 276 return supertype; |
| 296 } | 277 } |
| 297 | 278 |
| 298 InterfaceType supertype = processSupertype(node.supertype); | 279 InterfaceType supertype = processSupertype(node.supertype); |
| 299 if (supertype == _commonElements.objectType) { | 280 if (supertype == _commonElements.objectType) { |
| 300 ClassEntity defaultSuperclass = | 281 ClassEntity defaultSuperclass = |
| 301 _commonElements.getDefaultSuperclass(cls, nativeBasicData); | 282 _commonElements.getDefaultSuperclass(cls, nativeBasicData); |
| 302 data.supertype = _elementEnvironment.getRawType(defaultSuperclass); | 283 data.supertype = _elementEnvironment.getRawType(defaultSuperclass); |
| 303 } else { | 284 } else { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 321 data.orderedTypeSet = setBuilder.createOrderedTypeSet( | 302 data.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 322 data.supertype, interfaces.reverse()); | 303 data.supertype, interfaces.reverse()); |
| 323 data.interfaces = new List<InterfaceType>.from(interfaces.toList()); | 304 data.interfaces = new List<InterfaceType>.from(interfaces.toList()); |
| 324 } | 305 } |
| 325 } | 306 } |
| 326 } | 307 } |
| 327 | 308 |
| 328 @override | 309 @override |
| 329 TypedefType getTypedefType(ir.Typedef node) { | 310 TypedefType getTypedefType(ir.Typedef node) { |
| 330 IndexedTypedef typedef = _getTypedef(node); | 311 IndexedTypedef typedef = _getTypedef(node); |
| 331 return _typedefData[typedef.typedefIndex].rawType; | 312 return _typedefs.getData(typedef.typedefIndex).rawType; |
| 332 } | 313 } |
| 333 | 314 |
| 334 TypedefEntity _getTypedef(ir.Typedef node); | 315 TypedefEntity _getTypedef(ir.Typedef node); |
| 335 | 316 |
| 336 @override | 317 @override |
| 337 MemberEntity getMember(ir.Member node) { | 318 MemberEntity getMember(ir.Member node) { |
| 338 if (node is ir.Field) { | 319 if (node is ir.Field) { |
| 339 return _getField(node); | 320 return _getField(node); |
| 340 } else if (node is ir.Constructor) { | 321 } else if (node is ir.Constructor) { |
| 341 return _getConstructor(node); | 322 return _getConstructor(node); |
| 342 } else if (node is ir.Procedure) { | 323 } else if (node is ir.Procedure) { |
| 343 if (node.kind == ir.ProcedureKind.Factory) { | 324 if (node.kind == ir.ProcedureKind.Factory) { |
| 344 return _getConstructor(node); | 325 return _getConstructor(node); |
| 345 } else { | 326 } else { |
| 346 return _getMethod(node); | 327 return _getMethod(node); |
| 347 } | 328 } |
| 348 } | 329 } |
| 349 throw new UnsupportedError("Unexpected member: $node"); | 330 throw new UnsupportedError("Unexpected member: $node"); |
| 350 } | 331 } |
| 351 | 332 |
| 352 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target, | 333 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target, |
| 353 {bool setter: false}) { | 334 {bool setter: false}) { |
| 354 if (target != null) { | 335 if (target != null) { |
| 355 return getMember(target); | 336 return getMember(target); |
| 356 } | 337 } |
| 357 ClassEntity cls = getMember(context).enclosingClass; | 338 ClassEntity cls = getMember(context).enclosingClass; |
| 358 IndexedClass superclass = _getSuperType(cls)?.element; | 339 IndexedClass superclass = _getSuperType(cls)?.element; |
| 359 while (superclass != null) { | 340 while (superclass != null) { |
| 360 ClassEnv env = _classEnvs[superclass.classIndex]; | 341 ClassEnv env = _classes.getEnv(superclass.classIndex); |
| 361 MemberEntity superMember = | 342 MemberEntity superMember = |
| 362 env.lookupMember(this, name.name, setter: setter); | 343 env.lookupMember(this, name.name, setter: setter); |
| 363 if (superMember != null) { | 344 if (superMember != null) { |
| 364 return superMember; | 345 return superMember; |
| 365 } | 346 } |
| 366 superclass = _getSuperType(superclass)?.element; | 347 superclass = _getSuperType(superclass)?.element; |
| 367 } | 348 } |
| 368 throw failedAt(cls, "No super method member found for ${name} in $cls."); | 349 throw failedAt(cls, "No super method member found for ${name} in $cls."); |
| 369 } | 350 } |
| 370 | 351 |
| 371 @override | 352 @override |
| 372 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); | 353 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); |
| 373 | 354 |
| 374 ConstructorEntity _getConstructor(ir.Member node); | 355 ConstructorEntity _getConstructor(ir.Member node); |
| 375 | 356 |
| 376 ConstructorEntity getSuperConstructor( | 357 ConstructorEntity getSuperConstructor( |
| 377 ir.Constructor sourceNode, ir.Member targetNode) { | 358 ir.Constructor sourceNode, ir.Member targetNode) { |
| 378 ConstructorEntity source = getConstructor(sourceNode); | 359 ConstructorEntity source = getConstructor(sourceNode); |
| 379 ClassEntity sourceClass = source.enclosingClass; | 360 ClassEntity sourceClass = source.enclosingClass; |
| 380 ConstructorEntity target = getConstructor(targetNode); | 361 ConstructorEntity target = getConstructor(targetNode); |
| 381 ClassEntity targetClass = target.enclosingClass; | 362 ClassEntity targetClass = target.enclosingClass; |
| 382 IndexedClass superClass = _getSuperType(sourceClass)?.element; | 363 IndexedClass superClass = _getSuperType(sourceClass)?.element; |
| 383 if (superClass == targetClass) { | 364 if (superClass == targetClass) { |
| 384 return target; | 365 return target; |
| 385 } | 366 } |
| 386 ClassEnv env = _classEnvs[superClass.classIndex]; | 367 ClassEnv env = _classes.getEnv(superClass.classIndex); |
| 387 ConstructorEntity constructor = env.lookupConstructor(this, target.name); | 368 ConstructorEntity constructor = env.lookupConstructor(this, target.name); |
| 388 if (constructor != null) { | 369 if (constructor != null) { |
| 389 return constructor; | 370 return constructor; |
| 390 } | 371 } |
| 391 throw failedAt(source, "Super constructor for $source not found."); | 372 throw failedAt(source, "Super constructor for $source not found."); |
| 392 } | 373 } |
| 393 | 374 |
| 394 @override | 375 @override |
| 395 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); | 376 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); |
| 396 | 377 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 } | 564 } |
| 584 | 565 |
| 585 /// Returns the type of the `call` method on 'type'. | 566 /// Returns the type of the `call` method on 'type'. |
| 586 /// | 567 /// |
| 587 /// If [type] doesn't have a `call` member `null` is returned. If [type] has | 568 /// If [type] doesn't have a `call` member `null` is returned. If [type] has |
| 588 /// an invalid `call` member (non-method or a synthesized method with both | 569 /// an invalid `call` member (non-method or a synthesized method with both |
| 589 /// optional and named parameters) a [DynamicType] is returned. | 570 /// optional and named parameters) a [DynamicType] is returned. |
| 590 DartType _getCallType(InterfaceType type) { | 571 DartType _getCallType(InterfaceType type) { |
| 591 IndexedClass cls = type.element; | 572 IndexedClass cls = type.element; |
| 592 assert(checkFamily(cls)); | 573 assert(checkFamily(cls)); |
| 593 ClassData data = _classData[cls.classIndex]; | 574 ClassData data = _classes.getData(cls.classIndex); |
| 594 _ensureCallType(cls, data); | 575 _ensureCallType(cls, data); |
| 595 if (data.callType != null) { | 576 if (data.callType != null) { |
| 596 return _substByContext(data.callType, type); | 577 return _substByContext(data.callType, type); |
| 597 } | 578 } |
| 598 return null; | 579 return null; |
| 599 } | 580 } |
| 600 | 581 |
| 601 InterfaceType _getThisType(IndexedClass cls) { | 582 InterfaceType _getThisType(IndexedClass cls) { |
| 602 assert(checkFamily(cls)); | 583 assert(checkFamily(cls)); |
| 603 ClassData data = _classData[cls.classIndex]; | 584 ClassData data = _classes.getData(cls.classIndex); |
| 604 _ensureThisAndRawType(cls, data); | 585 _ensureThisAndRawType(cls, data); |
| 605 return data.thisType; | 586 return data.thisType; |
| 606 } | 587 } |
| 607 | 588 |
| 608 InterfaceType _getRawType(IndexedClass cls) { | 589 InterfaceType _getRawType(IndexedClass cls) { |
| 609 assert(checkFamily(cls)); | 590 assert(checkFamily(cls)); |
| 610 ClassData data = _classData[cls.classIndex]; | 591 ClassData data = _classes.getData(cls.classIndex); |
| 611 _ensureThisAndRawType(cls, data); | 592 _ensureThisAndRawType(cls, data); |
| 612 return data.rawType; | 593 return data.rawType; |
| 613 } | 594 } |
| 614 | 595 |
| 615 FunctionType _getFunctionType(IndexedFunction function) { | 596 FunctionType _getFunctionType(IndexedFunction function) { |
| 616 assert(checkFamily(function)); | 597 assert(checkFamily(function)); |
| 617 FunctionData data = _memberData[function.memberIndex]; | 598 FunctionData data = _members.getData(function.memberIndex); |
| 618 return data.getFunctionType(this); | 599 return data.getFunctionType(this); |
| 619 } | 600 } |
| 620 | 601 |
| 621 DartType _getFieldType(IndexedField field) { | 602 DartType _getFieldType(IndexedField field) { |
| 622 assert(checkFamily(field)); | 603 assert(checkFamily(field)); |
| 623 FieldData data = _memberData[field.memberIndex]; | 604 FieldData data = _members.getData(field.memberIndex); |
| 624 return data.getFieldType(this); | 605 return data.getFieldType(this); |
| 625 } | 606 } |
| 626 | 607 |
| 627 ClassEntity _getAppliedMixin(IndexedClass cls) { | 608 ClassEntity _getAppliedMixin(IndexedClass cls) { |
| 628 assert(checkFamily(cls)); | 609 assert(checkFamily(cls)); |
| 629 ClassData data = _classData[cls.classIndex]; | 610 ClassData data = _classes.getData(cls.classIndex); |
| 630 _ensureSupertypes(cls, data); | 611 _ensureSupertypes(cls, data); |
| 631 return data.mixedInType?.element; | 612 return data.mixedInType?.element; |
| 632 } | 613 } |
| 633 | 614 |
| 634 bool _isMixinApplication(IndexedClass cls) { | 615 bool _isMixinApplication(IndexedClass cls) { |
| 635 assert(checkFamily(cls)); | 616 assert(checkFamily(cls)); |
| 636 ClassData data = _classData[cls.classIndex]; | 617 ClassData data = _classes.getData(cls.classIndex); |
| 637 _ensureSupertypes(cls, data); | 618 _ensureSupertypes(cls, data); |
| 638 return data.isMixinApplication; | 619 return data.isMixinApplication; |
| 639 } | 620 } |
| 640 | 621 |
| 641 bool _isUnnamedMixinApplication(IndexedClass cls) { | 622 bool _isUnnamedMixinApplication(IndexedClass cls) { |
| 642 assert(checkFamily(cls)); | 623 assert(checkFamily(cls)); |
| 643 ClassEnv env = _classEnvs[cls.classIndex]; | 624 ClassEnv env = _classes.getEnv(cls.classIndex); |
| 644 return env.isUnnamedMixinApplication; | 625 return env.isUnnamedMixinApplication; |
| 645 } | 626 } |
| 646 | 627 |
| 647 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) { | 628 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) { |
| 648 assert(checkFamily(cls)); | 629 assert(checkFamily(cls)); |
| 649 ClassData data = _classData[cls.classIndex]; | 630 ClassData data = _classes.getData(cls.classIndex); |
| 650 _ensureSupertypes(cls, data); | 631 _ensureSupertypes(cls, data); |
| 651 data.orderedTypeSet.supertypes.forEach(f); | 632 data.orderedTypeSet.supertypes.forEach(f); |
| 652 } | 633 } |
| 653 | 634 |
| 654 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) { | 635 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) { |
| 655 assert(checkFamily(cls)); | 636 assert(checkFamily(cls)); |
| 656 while (cls != null) { | 637 while (cls != null) { |
| 657 ClassData data = _classData[cls.classIndex]; | 638 ClassData data = _classes.getData(cls.classIndex); |
| 658 _ensureSupertypes(cls, data); | 639 _ensureSupertypes(cls, data); |
| 659 if (data.mixedInType != null) { | 640 if (data.mixedInType != null) { |
| 660 f(data.mixedInType.element); | 641 f(data.mixedInType.element); |
| 661 } | 642 } |
| 662 cls = data.supertype?.element; | 643 cls = data.supertype?.element; |
| 663 } | 644 } |
| 664 } | 645 } |
| 665 | 646 |
| 666 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { | 647 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { |
| 667 assert(checkFamily(cls)); | 648 assert(checkFamily(cls)); |
| 668 ClassEnv env = _classEnvs[cls.classIndex]; | 649 ClassEnv env = _classes.getEnv(cls.classIndex); |
| 669 env.forEachConstructor(this, f); | 650 env.forEachConstructor(this, f); |
| 670 } | 651 } |
| 671 | 652 |
| 672 void _forEachConstructorBody( | 653 void _forEachConstructorBody( |
| 673 IndexedClass cls, void f(ConstructorBodyEntity member)) { | 654 IndexedClass cls, void f(ConstructorBodyEntity member)) { |
| 674 throw new UnsupportedError( | 655 throw new UnsupportedError( |
| 675 'KernelToElementMapBase._forEachConstructorBody'); | 656 'KernelToElementMapBase._forEachConstructorBody'); |
| 676 } | 657 } |
| 677 | 658 |
| 678 void _forEachClassMember( | 659 void _forEachClassMember( |
| 679 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { | 660 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { |
| 680 assert(checkFamily(cls)); | 661 assert(checkFamily(cls)); |
| 681 ClassEnv env = _classEnvs[cls.classIndex]; | 662 ClassEnv env = _classes.getEnv(cls.classIndex); |
| 682 env.forEachMember(this, (MemberEntity member) { | 663 env.forEachMember(this, (MemberEntity member) { |
| 683 f(cls, member); | 664 f(cls, member); |
| 684 }); | 665 }); |
| 685 ClassData data = _classData[cls.classIndex]; | 666 ClassData data = _classes.getData(cls.classIndex); |
| 686 _ensureSupertypes(cls, data); | 667 _ensureSupertypes(cls, data); |
| 687 if (data.supertype != null) { | 668 if (data.supertype != null) { |
| 688 _forEachClassMember(data.supertype.element, f); | 669 _forEachClassMember(data.supertype.element, f); |
| 689 } | 670 } |
| 690 } | 671 } |
| 691 | 672 |
| 692 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { | 673 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { |
| 693 assert(checkFamily(constructor)); | 674 assert(checkFamily(constructor)); |
| 694 ConstructorData data = _memberData[constructor.memberIndex]; | 675 ConstructorData data = _members.getData(constructor.memberIndex); |
| 695 return data.getConstructorConstant(this, constructor); | 676 return data.getConstructorConstant(this, constructor); |
| 696 } | 677 } |
| 697 | 678 |
| 698 ConstantExpression _getFieldConstant(IndexedField field) { | 679 ConstantExpression _getFieldConstant(IndexedField field) { |
| 699 assert(checkFamily(field)); | 680 assert(checkFamily(field)); |
| 700 FieldData data = _memberData[field.memberIndex]; | 681 FieldData data = _members.getData(field.memberIndex); |
| 701 return data.getFieldConstant(this, field); | 682 return data.getFieldConstant(this, field); |
| 702 } | 683 } |
| 703 | 684 |
| 704 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { | 685 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { |
| 705 assert(checkFamily(cls)); | 686 assert(checkFamily(cls)); |
| 706 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); | 687 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); |
| 707 InterfaceType supertype = | 688 InterfaceType supertype = |
| 708 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); | 689 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); |
| 709 if (supertype != null) { | 690 if (supertype != null) { |
| 710 supertype = _substByContext(supertype, type); | 691 supertype = _substByContext(supertype, type); |
| 711 } | 692 } |
| 712 return supertype; | 693 return supertype; |
| 713 } | 694 } |
| 714 | 695 |
| 715 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) { | 696 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) { |
| 716 assert(checkFamily(cls)); | 697 assert(checkFamily(cls)); |
| 717 ClassData data = _classData[cls.classIndex]; | 698 ClassData data = _classes.getData(cls.classIndex); |
| 718 _ensureSupertypes(cls, data); | 699 _ensureSupertypes(cls, data); |
| 719 return data.orderedTypeSet; | 700 return data.orderedTypeSet; |
| 720 } | 701 } |
| 721 | 702 |
| 722 int _getHierarchyDepth(IndexedClass cls) { | 703 int _getHierarchyDepth(IndexedClass cls) { |
| 723 assert(checkFamily(cls)); | 704 assert(checkFamily(cls)); |
| 724 ClassData data = _classData[cls.classIndex]; | 705 ClassData data = _classes.getData(cls.classIndex); |
| 725 _ensureSupertypes(cls, data); | 706 _ensureSupertypes(cls, data); |
| 726 return data.orderedTypeSet.maxDepth; | 707 return data.orderedTypeSet.maxDepth; |
| 727 } | 708 } |
| 728 | 709 |
| 729 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { | 710 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { |
| 730 assert(checkFamily(cls)); | 711 assert(checkFamily(cls)); |
| 731 ClassData data = _classData[cls.classIndex]; | 712 ClassData data = _classes.getData(cls.classIndex); |
| 732 _ensureSupertypes(cls, data); | 713 _ensureSupertypes(cls, data); |
| 733 return data.interfaces; | 714 return data.interfaces; |
| 734 } | 715 } |
| 735 | 716 |
| 736 Spannable _getSpannable(MemberEntity member, ir.Node node) { | 717 Spannable _getSpannable(MemberEntity member, ir.Node node) { |
| 737 SourceSpan sourceSpan; | 718 SourceSpan sourceSpan; |
| 738 if (node is ir.TreeNode) { | 719 if (node is ir.TreeNode) { |
| 739 sourceSpan = computeSourceSpanFromTreeNode(node); | 720 sourceSpan = computeSourceSpanFromTreeNode(node); |
| 740 } | 721 } |
| 741 sourceSpan ??= getSourceSpan(member, null); | 722 sourceSpan ??= getSourceSpan(member, null); |
| 742 return sourceSpan; | 723 return sourceSpan; |
| 743 } | 724 } |
| 744 | 725 |
| 745 MemberDefinition _getMemberDefinition(covariant IndexedMember member) { | 726 MemberDefinition _getMemberDefinition(covariant IndexedMember member) { |
| 746 assert(checkFamily(member)); | 727 assert(checkFamily(member)); |
| 747 return _memberData[member.memberIndex].definition; | 728 return _members.getData(member.memberIndex).definition; |
| 748 } | 729 } |
| 749 | 730 |
| 750 ClassDefinition _getClassDefinition(covariant IndexedClass cls) { | 731 ClassDefinition _getClassDefinition(covariant IndexedClass cls) { |
| 751 assert(checkFamily(cls)); | 732 assert(checkFamily(cls)); |
| 752 return _classData[cls.classIndex].definition; | 733 return _classes.getData(cls.classIndex).definition; |
| 753 } | 734 } |
| 754 } | 735 } |
| 755 | 736 |
| 756 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. | 737 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. |
| 757 abstract class ElementCreatorMixin { | 738 abstract class ElementCreatorMixin { |
| 758 ProgramEnv get _env; | 739 ProgramEnv get _env; |
| 759 List<LibraryEntity> get _libraryList; | 740 EntityDataEnvMap<IndexedLibrary, LibraryData, LibraryEnv> get _libraries; |
| 760 List<LibraryEnv> get _libraryEnvs; | 741 EntityDataEnvMap<IndexedClass, ClassData, ClassEnv> get _classes; |
| 761 List<LibraryData> get _libraryData; | 742 EntityDataMap<IndexedMember, MemberData> get _members; |
| 762 List<ClassEntity> get _classList; | 743 EntityMap<IndexedTypeVariable> get _typeVariables; |
| 763 List<ClassEnv> get _classEnvs; | 744 EntityDataMap<IndexedTypedef, TypedefData> get _typedefs; |
| 764 List<ClassData> get _classData; | |
| 765 List<MemberEntity> get _memberList; | |
| 766 List<MemberData> get _memberData; | |
| 767 List<TypeVariableEntity> get _typeVariableList; | |
| 768 List<TypedefEntity> get _typedefList; | |
| 769 List<TypedefData> get _typedefData; | |
| 770 | 745 |
| 771 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; | 746 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; |
| 772 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; | 747 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; |
| 773 Map<ir.Typedef, IndexedTypedef> _typedefMap = <ir.Typedef, IndexedTypedef>{}; | 748 Map<ir.Typedef, IndexedTypedef> _typedefMap = <ir.Typedef, IndexedTypedef>{}; |
| 774 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = | 749 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = |
| 775 <ir.TypeParameter, IndexedTypeVariable>{}; | 750 <ir.TypeParameter, IndexedTypeVariable>{}; |
| 776 Map<ir.Member, IndexedConstructor> _constructorMap = | 751 Map<ir.Member, IndexedConstructor> _constructorMap = |
| 777 <ir.Member, IndexedConstructor>{}; | 752 <ir.Member, IndexedConstructor>{}; |
| 778 Map<ir.Procedure, IndexedFunction> _methodMap = | 753 Map<ir.Procedure, IndexedFunction> _methodMap = |
| 779 <ir.Procedure, IndexedFunction>{}; | 754 <ir.Procedure, IndexedFunction>{}; |
| 780 Map<ir.Field, IndexedField> _fieldMap = <ir.Field, IndexedField>{}; | 755 Map<ir.Field, IndexedField> _fieldMap = <ir.Field, IndexedField>{}; |
| 781 Map<ir.TreeNode, Local> _localFunctionMap = <ir.TreeNode, Local>{}; | 756 Map<ir.TreeNode, Local> _localFunctionMap = <ir.TreeNode, Local>{}; |
| 782 | 757 |
| 783 Name getName(ir.Name node); | 758 Name getName(ir.Name node); |
| 784 FunctionType getFunctionType(ir.FunctionNode node); | 759 FunctionType getFunctionType(ir.FunctionNode node); |
| 785 MemberEntity getMember(ir.Member node); | 760 MemberEntity getMember(ir.Member node); |
| 786 | 761 |
| 787 Iterable<LibraryEntity> get _libraries { | 762 Iterable<LibraryEntity> get _libraryList { |
| 788 if (_env.length != _libraryMap.length) { | 763 if (_env.length != _libraryMap.length) { |
| 789 // Create a [KLibrary] for each library. | 764 // Create a [KLibrary] for each library. |
| 790 _env.forEachLibrary((LibraryEnv env) { | 765 _env.forEachLibrary((LibraryEnv env) { |
| 791 _getLibrary(env.library, env); | 766 _getLibrary(env.library, env); |
| 792 }); | 767 }); |
| 793 } | 768 } |
| 794 return _libraryMap.values; | 769 return _libraryMap.values; |
| 795 } | 770 } |
| 796 | 771 |
| 797 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) { | 772 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) { |
| 798 return _libraryMap.putIfAbsent(node, () { | 773 return _libraryMap.putIfAbsent(node, () { |
| 799 Uri canonicalUri = node.importUri; | 774 Uri canonicalUri = node.importUri; |
| 800 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); | 775 return _libraries.register((int libraryIndex) { |
| 801 String name = node.name; | 776 String name = node.name; |
| 802 if (name == null) { | 777 if (name == null) { |
| 803 // Use the file name as script name. | 778 // Use the file name as script name. |
| 804 String path = canonicalUri.path; | 779 String path = canonicalUri.path; |
| 805 name = path.substring(path.lastIndexOf('/') + 1); | 780 name = path.substring(path.lastIndexOf('/') + 1); |
| 806 } | 781 } |
| 807 LibraryEntity library = | 782 return createLibrary(_libraryMap.length, name, canonicalUri); |
| 808 createLibrary(_libraryMap.length, name, canonicalUri); | 783 }, (IndexedLibrary library) { |
| 809 _libraryList.add(library); | 784 return new LibraryData(node); |
| 810 _libraryData.add(new LibraryData(node)); | 785 }, (IndexedLibrary library) { |
| 811 return library; | 786 return libraryEnv ?? _env.lookupLibrary(canonicalUri); |
| 787 }); | |
| 812 }); | 788 }); |
| 813 } | 789 } |
| 814 | 790 |
| 815 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { | 791 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { |
| 816 return _classMap.putIfAbsent(node, () { | 792 return _classMap.putIfAbsent(node, () { |
| 817 KLibrary library = _getLibrary(node.enclosingLibrary); | 793 return _classes.register((int classIndex) { |
| 818 if (classEnv == null) { | 794 KLibrary library = _getLibrary(node.enclosingLibrary); |
| 819 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); | 795 if (classEnv == null) { |
| 820 } | 796 classEnv = |
| 821 _classEnvs.add(classEnv); | 797 _libraries.getEnv(library.libraryIndex).lookupClass(node.name); |
| 822 ClassEntity cls = createClass(library, _classList.length, node.name, | 798 } |
| 823 isAbstract: node.isAbstract); | 799 return createClass(library, classIndex, node.name, |
| 824 _classData | 800 isAbstract: node.isAbstract); |
| 825 .add(new ClassData(node, new RegularClassDefinition(cls, node))); | 801 }, (IndexedClass cls) { |
| 826 _classList.add(cls); | 802 return new ClassData(node, new RegularClassDefinition(cls, node)); |
| 827 return cls; | 803 }, (IndexedClass cls) { |
| 804 return classEnv; | |
| 805 }); | |
| 828 }); | 806 }); |
| 829 } | 807 } |
| 830 | 808 |
| 831 TypedefEntity _getTypedef(ir.Typedef node) { | 809 TypedefEntity _getTypedef(ir.Typedef node) { |
| 832 return _typedefMap.putIfAbsent(node, () { | 810 return _typedefMap.putIfAbsent(node, () { |
| 833 IndexedLibrary library = _getLibrary(node.enclosingLibrary); | 811 return _typedefs.register((int typedefIndex) { |
| 834 TypedefEntity typedef = | 812 IndexedLibrary library = _getLibrary(node.enclosingLibrary); |
| 835 createTypedef(library, _typedefList.length, node.name); | 813 return createTypedef(library, typedefIndex, node.name); |
| 836 TypedefType typedefType = new TypedefType( | 814 }, (IndexedTypedef typedef) { |
| 837 typedef, | 815 TypedefType typedefType = new TypedefType( |
| 838 new List<DartType>.filled( | 816 typedef, |
| 839 node.typeParameters.length, const DynamicType())); | 817 new List<DartType>.filled( |
| 840 _typedefData.add(new TypedefData(node, typedef, typedefType)); | 818 node.typeParameters.length, const DynamicType())); |
| 841 _typedefList.add(typedef); | 819 return new TypedefData(node, typedef, typedefType); |
| 842 return typedef; | 820 }); |
| 843 }); | 821 }); |
| 844 } | 822 } |
| 845 | 823 |
| 846 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { | 824 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { |
| 847 return _typeVariableMap.putIfAbsent(node, () { | 825 return _typeVariableMap.putIfAbsent(node, () { |
| 848 if (node.parent is ir.Class) { | 826 if (node.parent is ir.Class) { |
| 849 int typeVariableIndex = _typeVariableList.length; | 827 return _typeVariables.register((int typeVariableIndex) { |
| 850 ir.Class cls = node.parent; | 828 ir.Class cls = node.parent; |
| 851 int index = cls.typeParameters.indexOf(node); | 829 int index = cls.typeParameters.indexOf(node); |
| 852 TypeVariableEntity typeVariable = createTypeVariable( | 830 return createTypeVariable( |
| 853 typeVariableIndex, _getClass(cls), node.name, index); | 831 typeVariableIndex, _getClass(cls), node.name, index); |
| 854 _typeVariableList.add(typeVariable); | 832 }); |
| 855 return typeVariable; | |
| 856 } | 833 } |
| 857 if (node.parent is ir.FunctionNode) { | 834 if (node.parent is ir.FunctionNode) { |
| 858 ir.FunctionNode func = node.parent; | 835 ir.FunctionNode func = node.parent; |
| 859 int index = func.typeParameters.indexOf(node); | 836 int index = func.typeParameters.indexOf(node); |
| 860 if (func.parent is ir.Constructor) { | 837 if (func.parent is ir.Constructor) { |
| 861 ir.Constructor constructor = func.parent; | 838 ir.Constructor constructor = func.parent; |
| 862 ir.Class cls = constructor.enclosingClass; | 839 ir.Class cls = constructor.enclosingClass; |
| 863 return _getTypeVariable(cls.typeParameters[index]); | 840 return _getTypeVariable(cls.typeParameters[index]); |
| 864 } | 841 } |
| 865 if (func.parent is ir.Procedure) { | 842 if (func.parent is ir.Procedure) { |
| 866 ir.Procedure procedure = func.parent; | 843 ir.Procedure procedure = func.parent; |
| 867 if (procedure.kind == ir.ProcedureKind.Factory) { | 844 if (procedure.kind == ir.ProcedureKind.Factory) { |
| 868 ir.Class cls = procedure.enclosingClass; | 845 ir.Class cls = procedure.enclosingClass; |
| 869 return _getTypeVariable(cls.typeParameters[index]); | 846 return _getTypeVariable(cls.typeParameters[index]); |
| 870 } else { | 847 } else { |
| 871 int typeVariableIndex = _typeVariableList.length; | 848 return _typeVariables.register((int typeVariableIndex) { |
| 872 TypeVariableEntity typeVariable = createTypeVariable( | 849 return createTypeVariable( |
| 873 typeVariableIndex, _getMethod(procedure), node.name, index); | 850 typeVariableIndex, _getMethod(procedure), node.name, index); |
| 874 _typeVariableList.add(typeVariable); | 851 }); |
| 875 return typeVariable; | |
| 876 } | 852 } |
| 877 } | 853 } |
| 878 } | 854 } |
| 879 throw new UnsupportedError('Unsupported type parameter type node $node.'); | 855 throw new UnsupportedError('Unsupported type parameter type node $node.'); |
| 880 }); | 856 }); |
| 881 } | 857 } |
| 882 | 858 |
| 883 ConstructorEntity _getConstructor(ir.Member node) { | 859 ConstructorEntity _getConstructor(ir.Member node) { |
| 884 return _constructorMap.putIfAbsent(node, () { | 860 return _constructorMap.putIfAbsent(node, () { |
| 885 int memberIndex = _memberData.length; | 861 MemberDefinition definition; |
| 886 ConstructorEntity constructor; | 862 ir.FunctionNode functionNode; |
| 887 ClassEntity enclosingClass = _getClass(node.enclosingClass); | 863 return _members.register<IndexedConstructor, ConstructorData>( |
| 888 Name name = getName(node.name); | 864 (int memberIndex) { |
| 889 bool isExternal = node.isExternal; | 865 ClassEntity enclosingClass = _getClass(node.enclosingClass); |
| 866 Name name = getName(node.name); | |
| 867 bool isExternal = node.isExternal; | |
| 890 | 868 |
| 891 ir.FunctionNode functionNode; | 869 IndexedConstructor constructor; |
| 892 MemberDefinition definition; | 870 if (node is ir.Constructor) { |
| 893 if (node is ir.Constructor) { | 871 functionNode = node.function; |
| 894 functionNode = node.function; | 872 constructor = createGenerativeConstructor(memberIndex, enclosingClass, |
| 895 constructor = createGenerativeConstructor(memberIndex, enclosingClass, | 873 name, _getParameterStructure(functionNode), |
| 896 name, _getParameterStructure(functionNode), | 874 isExternal: isExternal, isConst: node.isConst); |
| 897 isExternal: isExternal, isConst: node.isConst); | 875 definition = new SpecialMemberDefinition( |
| 898 definition = new SpecialMemberDefinition( | 876 constructor, node, MemberKind.constructor); |
| 899 constructor, node, MemberKind.constructor); | 877 } else if (node is ir.Procedure) { |
| 900 } else if (node is ir.Procedure) { | 878 functionNode = node.function; |
| 901 functionNode = node.function; | 879 bool isFromEnvironment = isExternal && |
| 902 bool isFromEnvironment = isExternal && | 880 name.text == 'fromEnvironment' && |
| 903 name.text == 'fromEnvironment' && | 881 const ['int', 'bool', 'String'].contains(enclosingClass.name); |
| 904 const ['int', 'bool', 'String'].contains(enclosingClass.name); | 882 constructor = createFactoryConstructor(memberIndex, enclosingClass, |
| 905 constructor = createFactoryConstructor(memberIndex, enclosingClass, | 883 name, _getParameterStructure(functionNode), |
| 906 name, _getParameterStructure(functionNode), | 884 isExternal: isExternal, |
| 907 isExternal: isExternal, | 885 isConst: node.isConst, |
| 908 isConst: node.isConst, | 886 isFromEnvironmentConstructor: isFromEnvironment); |
| 909 isFromEnvironmentConstructor: isFromEnvironment); | 887 definition = new RegularMemberDefinition(constructor, node); |
| 910 definition = new RegularMemberDefinition(constructor, node); | 888 } else { |
| 911 } else { | 889 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
| 912 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. | 890 throw failedAt( |
| 913 throw failedAt( | 891 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
| 914 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); | 892 } |
| 915 } | 893 return constructor; |
| 916 _memberData.add(new ConstructorDataImpl(node, functionNode, definition)); | 894 }, (IndexedConstructor constructor) { |
| 917 _memberList.add(constructor); | 895 return new ConstructorDataImpl(node, functionNode, definition); |
| 918 return constructor; | 896 }); |
| 919 }); | 897 }); |
| 920 } | 898 } |
| 921 | 899 |
| 922 AsyncMarker _getAsyncMarker(ir.FunctionNode node) { | 900 AsyncMarker _getAsyncMarker(ir.FunctionNode node) { |
| 923 switch (node.asyncMarker) { | 901 switch (node.asyncMarker) { |
| 924 case ir.AsyncMarker.Async: | 902 case ir.AsyncMarker.Async: |
| 925 return AsyncMarker.ASYNC; | 903 return AsyncMarker.ASYNC; |
| 926 case ir.AsyncMarker.AsyncStar: | 904 case ir.AsyncMarker.AsyncStar: |
| 927 return AsyncMarker.ASYNC_STAR; | 905 return AsyncMarker.ASYNC_STAR; |
| 928 case ir.AsyncMarker.Sync: | 906 case ir.AsyncMarker.Sync: |
| 929 return AsyncMarker.SYNC; | 907 return AsyncMarker.SYNC; |
| 930 case ir.AsyncMarker.SyncStar: | 908 case ir.AsyncMarker.SyncStar: |
| 931 return AsyncMarker.SYNC_STAR; | 909 return AsyncMarker.SYNC_STAR; |
| 932 case ir.AsyncMarker.SyncYielding: | 910 case ir.AsyncMarker.SyncYielding: |
| 933 default: | 911 default: |
| 934 throw new UnsupportedError( | 912 throw new UnsupportedError( |
| 935 "Async marker ${node.asyncMarker} is not supported."); | 913 "Async marker ${node.asyncMarker} is not supported."); |
| 936 } | 914 } |
| 937 } | 915 } |
| 938 | 916 |
| 939 FunctionEntity _getMethod(ir.Procedure node) { | 917 FunctionEntity _getMethod(ir.Procedure node) { |
| 940 return _methodMap.putIfAbsent(node, () { | 918 return _methodMap.putIfAbsent(node, () { |
| 941 int memberIndex = _memberData.length; | 919 return _members.register<IndexedFunction, FunctionData>( |
| 942 LibraryEntity library; | 920 (int memberIndex) { |
| 943 ClassEntity enclosingClass; | 921 LibraryEntity library; |
| 944 if (node.enclosingClass != null) { | 922 ClassEntity enclosingClass; |
| 945 enclosingClass = _getClass(node.enclosingClass); | 923 if (node.enclosingClass != null) { |
| 946 library = enclosingClass.library; | 924 enclosingClass = _getClass(node.enclosingClass); |
| 947 } else { | 925 library = enclosingClass.library; |
| 948 library = _getLibrary(node.enclosingLibrary); | 926 } else { |
| 949 } | 927 library = _getLibrary(node.enclosingLibrary); |
| 950 Name name = getName(node.name); | 928 } |
| 951 bool isStatic = node.isStatic; | 929 Name name = getName(node.name); |
| 952 bool isExternal = node.isExternal; | 930 bool isStatic = node.isStatic; |
| 953 bool isAbstract = node.isAbstract; | 931 bool isExternal = node.isExternal; |
| 954 IndexedFunction function; | 932 bool isAbstract = node.isAbstract; |
| 955 AsyncMarker asyncMarker = _getAsyncMarker(node.function); | 933 AsyncMarker asyncMarker = _getAsyncMarker(node.function); |
| 956 switch (node.kind) { | 934 switch (node.kind) { |
| 957 case ir.ProcedureKind.Factory: | 935 case ir.ProcedureKind.Factory: |
| 958 throw new UnsupportedError("Cannot create method from factory."); | 936 throw new UnsupportedError("Cannot create method from factory."); |
| 959 case ir.ProcedureKind.Getter: | 937 case ir.ProcedureKind.Getter: |
| 960 function = createGetter( | 938 return createGetter( |
| 961 memberIndex, library, enclosingClass, name, asyncMarker, | 939 memberIndex, library, enclosingClass, name, asyncMarker, |
| 962 isStatic: isStatic, | 940 isStatic: isStatic, |
| 963 isExternal: isExternal, | 941 isExternal: isExternal, |
| 964 isAbstract: isAbstract); | 942 isAbstract: isAbstract); |
| 965 break; | 943 case ir.ProcedureKind.Method: |
| 966 case ir.ProcedureKind.Method: | 944 case ir.ProcedureKind.Operator: |
| 967 case ir.ProcedureKind.Operator: | 945 return createMethod(memberIndex, library, enclosingClass, name, |
| 968 function = createMethod(memberIndex, library, enclosingClass, name, | 946 _getParameterStructure(node.function), asyncMarker, |
| 969 _getParameterStructure(node.function), asyncMarker, | 947 isStatic: isStatic, |
| 970 isStatic: isStatic, | 948 isExternal: isExternal, |
| 971 isExternal: isExternal, | 949 isAbstract: isAbstract); |
| 972 isAbstract: isAbstract); | 950 break; |
| 973 break; | 951 case ir.ProcedureKind.Setter: |
| 974 case ir.ProcedureKind.Setter: | 952 assert(asyncMarker == AsyncMarker.SYNC); |
| 975 assert(asyncMarker == AsyncMarker.SYNC); | 953 return createSetter( |
| 976 function = createSetter( | 954 memberIndex, library, enclosingClass, name.setter, |
| 977 memberIndex, library, enclosingClass, name.setter, | 955 isStatic: isStatic, |
| 978 isStatic: isStatic, | 956 isExternal: isExternal, |
| 979 isExternal: isExternal, | 957 isAbstract: isAbstract); |
| 980 isAbstract: isAbstract); | 958 break; |
| 981 break; | 959 } |
| 982 } | 960 }, (IndexedFunction function) { |
| 983 _memberData.add(new FunctionDataImpl( | 961 return new FunctionDataImpl( |
| 984 node, node.function, new RegularMemberDefinition(function, node))); | 962 node, node.function, new RegularMemberDefinition(function, node)); |
| 985 _memberList.add(function); | 963 }); |
| 986 return function; | |
| 987 }); | 964 }); |
| 988 } | 965 } |
| 989 | 966 |
| 990 FieldEntity _getField(ir.Field node) { | 967 FieldEntity _getField(ir.Field node) { |
| 991 return _fieldMap.putIfAbsent(node, () { | 968 return _fieldMap.putIfAbsent(node, () { |
| 992 int memberIndex = _memberData.length; | 969 return _members.register<IndexedField, FieldData>((int memberIndex) { |
| 993 LibraryEntity library; | 970 LibraryEntity library; |
| 994 ClassEntity enclosingClass; | 971 ClassEntity enclosingClass; |
| 995 if (node.enclosingClass != null) { | 972 if (node.enclosingClass != null) { |
| 996 enclosingClass = _getClass(node.enclosingClass); | 973 enclosingClass = _getClass(node.enclosingClass); |
| 997 library = enclosingClass.library; | 974 library = enclosingClass.library; |
| 998 } else { | 975 } else { |
| 999 library = _getLibrary(node.enclosingLibrary); | 976 library = _getLibrary(node.enclosingLibrary); |
| 1000 } | 977 } |
| 1001 Name name = getName(node.name); | 978 Name name = getName(node.name); |
| 1002 bool isStatic = node.isStatic; | 979 bool isStatic = node.isStatic; |
| 1003 FieldEntity field = createField( | 980 return createField(memberIndex, library, enclosingClass, name, |
| 1004 memberIndex, library, enclosingClass, name, | 981 isStatic: isStatic, |
| 1005 isStatic: isStatic, | 982 isAssignable: node.isMutable, |
| 1006 isAssignable: node.isMutable, | 983 isConst: node.isConst); |
| 1007 isConst: node.isConst); | 984 }, (FieldEntity field) { |
| 1008 _memberData.add( | 985 return new FieldDataImpl( |
| 1009 new FieldDataImpl(node, new RegularMemberDefinition(field, node))); | 986 node, new RegularMemberDefinition(field, node)); |
| 1010 _memberList.add(field); | 987 }); |
| 1011 return field; | |
| 1012 }); | 988 }); |
| 1013 } | 989 } |
| 1014 | 990 |
| 1015 ParameterStructure _getParameterStructure(ir.FunctionNode node) { | 991 ParameterStructure _getParameterStructure(ir.FunctionNode node) { |
| 1016 // TODO(johnniwinther): Cache the computed function type. | 992 // TODO(johnniwinther): Cache the computed function type. |
| 1017 int requiredParameters = node.requiredParameterCount; | 993 int requiredParameters = node.requiredParameterCount; |
| 1018 int positionalParameters = node.positionalParameters.length; | 994 int positionalParameters = node.positionalParameters.length; |
| 1019 List<String> namedParameters = | 995 List<String> namedParameters = |
| 1020 node.namedParameters.map((p) => p.name).toList()..sort(); | 996 node.namedParameters.map((p) => p.name).toList()..sort(); |
| 1021 return new ParameterStructure( | 997 return new ParameterStructure( |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 _env.addProgram(program); | 1172 _env.addProgram(program); |
| 1197 } | 1173 } |
| 1198 | 1174 |
| 1199 @override | 1175 @override |
| 1200 native.BehaviorBuilder get nativeBehaviorBuilder => | 1176 native.BehaviorBuilder get nativeBehaviorBuilder => |
| 1201 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(elementEnvironment, | 1177 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(elementEnvironment, |
| 1202 commonElements, nativeBasicData, reporter, _options); | 1178 commonElements, nativeBasicData, reporter, _options); |
| 1203 | 1179 |
| 1204 ResolutionImpact computeWorldImpact(KMember member) { | 1180 ResolutionImpact computeWorldImpact(KMember member) { |
| 1205 return buildKernelImpact( | 1181 return buildKernelImpact( |
| 1206 _memberData[member.memberIndex].definition.node, this); | 1182 _members.getData(member.memberIndex).definition.node, this); |
| 1207 } | 1183 } |
| 1208 | 1184 |
| 1209 ScopeModel computeScopeModel(KMember member) { | 1185 ScopeModel computeScopeModel(KMember member) { |
| 1210 ir.Member node = _memberData[member.memberIndex].definition.node; | 1186 ir.Member node = _members.getData(member.memberIndex).definition.node; |
| 1211 return KernelClosureAnalysis.computeScopeModel(member, node); | 1187 return KernelClosureAnalysis.computeScopeModel(member, node); |
| 1212 } | 1188 } |
| 1213 | 1189 |
| 1214 /// Returns the kernel [ir.Procedure] node for the [method]. | 1190 /// Returns the kernel [ir.Procedure] node for the [method]. |
| 1215 ir.Procedure _lookupProcedure(KFunction method) { | 1191 ir.Procedure _lookupProcedure(KFunction method) { |
| 1216 return _memberData[method.memberIndex].definition.node; | 1192 return _members.getData(method.memberIndex).definition.node; |
| 1217 } | 1193 } |
| 1218 | 1194 |
| 1219 @override | 1195 @override |
| 1220 Local getLocalFunction(ir.TreeNode node) { | 1196 Local getLocalFunction(ir.TreeNode node) { |
| 1221 assert( | 1197 assert( |
| 1222 node is ir.FunctionDeclaration || node is ir.FunctionExpression, | 1198 node is ir.FunctionDeclaration || node is ir.FunctionExpression, |
| 1223 failedAt( | 1199 failedAt( |
| 1224 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); | 1200 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); |
| 1225 return _localFunctionMap.putIfAbsent(node, () { | 1201 return _localFunctionMap.putIfAbsent(node, () { |
| 1226 MemberEntity memberContext; | 1202 MemberEntity memberContext; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1248 } else if (node is ir.FunctionExpression) { | 1224 } else if (node is ir.FunctionExpression) { |
| 1249 functionType = getFunctionType(node.function); | 1225 functionType = getFunctionType(node.function); |
| 1250 } | 1226 } |
| 1251 return new KLocalFunction( | 1227 return new KLocalFunction( |
| 1252 name, memberContext, executableContext, functionType); | 1228 name, memberContext, executableContext, functionType); |
| 1253 }); | 1229 }); |
| 1254 } | 1230 } |
| 1255 | 1231 |
| 1256 bool _implementsFunction(IndexedClass cls) { | 1232 bool _implementsFunction(IndexedClass cls) { |
| 1257 assert(checkFamily(cls)); | 1233 assert(checkFamily(cls)); |
| 1258 ClassData data = _classData[cls.classIndex]; | 1234 ClassData data = _classes.getData(cls.classIndex); |
| 1259 OrderedTypeSet orderedTypeSet = data.orderedTypeSet; | 1235 OrderedTypeSet orderedTypeSet = data.orderedTypeSet; |
| 1260 InterfaceType supertype = orderedTypeSet.asInstanceOf( | 1236 InterfaceType supertype = orderedTypeSet.asInstanceOf( |
| 1261 commonElements.functionClass, | 1237 commonElements.functionClass, |
| 1262 _getHierarchyDepth(commonElements.functionClass)); | 1238 _getHierarchyDepth(commonElements.functionClass)); |
| 1263 if (supertype != null) { | 1239 if (supertype != null) { |
| 1264 return true; | 1240 return true; |
| 1265 } | 1241 } |
| 1266 _ensureCallType(cls, data); | 1242 _ensureCallType(cls, data); |
| 1267 return data.callType is FunctionType; | 1243 return data.callType is FunctionType; |
| 1268 } | 1244 } |
| 1269 } | 1245 } |
| 1270 | 1246 |
| 1271 class KernelElementEnvironment implements ElementEnvironment { | 1247 class KernelElementEnvironment implements ElementEnvironment { |
| 1272 final KernelToElementMapBase elementMap; | 1248 final KernelToElementMapBase elementMap; |
| 1273 | 1249 |
| 1274 KernelElementEnvironment(this.elementMap); | 1250 KernelElementEnvironment(this.elementMap); |
| 1275 | 1251 |
| 1276 @override | 1252 @override |
| 1277 DartType get dynamicType => const DynamicType(); | 1253 DartType get dynamicType => const DynamicType(); |
| 1278 | 1254 |
| 1279 @override | 1255 @override |
| 1280 LibraryEntity get mainLibrary => elementMap._mainLibrary; | 1256 LibraryEntity get mainLibrary => elementMap._mainLibrary; |
| 1281 | 1257 |
| 1282 @override | 1258 @override |
| 1283 FunctionEntity get mainFunction => elementMap._mainFunction; | 1259 FunctionEntity get mainFunction => elementMap._mainFunction; |
| 1284 | 1260 |
| 1285 @override | 1261 @override |
| 1286 Iterable<LibraryEntity> get libraries => elementMap._libraries; | 1262 Iterable<LibraryEntity> get libraries => elementMap._libraryList; |
| 1287 | 1263 |
| 1288 @override | 1264 @override |
| 1289 String getLibraryName(LibraryEntity library) { | 1265 String getLibraryName(LibraryEntity library) { |
| 1290 return elementMap._getLibraryName(library); | 1266 return elementMap._getLibraryName(library); |
| 1291 } | 1267 } |
| 1292 | 1268 |
| 1293 @override | 1269 @override |
| 1294 InterfaceType getThisType(ClassEntity cls) { | 1270 InterfaceType getThisType(ClassEntity cls) { |
| 1295 return elementMap._getThisType(cls); | 1271 return elementMap._getThisType(cls); |
| 1296 } | 1272 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 } | 1440 } |
| 1465 | 1441 |
| 1466 @override | 1442 @override |
| 1467 bool isDeferredLoadLibraryGetter(MemberEntity member) { | 1443 bool isDeferredLoadLibraryGetter(MemberEntity member) { |
| 1468 // TODO(redemption): Support these. | 1444 // TODO(redemption): Support these. |
| 1469 return false; | 1445 return false; |
| 1470 } | 1446 } |
| 1471 | 1447 |
| 1472 @override | 1448 @override |
| 1473 Iterable<ConstantValue> getLibraryMetadata(covariant IndexedLibrary library) { | 1449 Iterable<ConstantValue> getLibraryMetadata(covariant IndexedLibrary library) { |
| 1474 LibraryData libraryData = elementMap._libraryData[library.libraryIndex]; | 1450 LibraryData libraryData = |
| 1451 elementMap._libraries.getData(library.libraryIndex); | |
| 1475 return libraryData.getMetadata(elementMap); | 1452 return libraryData.getMetadata(elementMap); |
| 1476 } | 1453 } |
| 1477 | 1454 |
| 1478 @override | 1455 @override |
| 1479 Iterable<ConstantValue> getClassMetadata(covariant IndexedClass cls) { | 1456 Iterable<ConstantValue> getClassMetadata(covariant IndexedClass cls) { |
| 1480 ClassData classData = elementMap._classData[cls.classIndex]; | 1457 ClassData classData = elementMap._classes.getData(cls.classIndex); |
| 1481 return classData.getMetadata(elementMap); | 1458 return classData.getMetadata(elementMap); |
| 1482 } | 1459 } |
| 1483 | 1460 |
| 1484 @override | 1461 @override |
| 1485 Iterable<ConstantValue> getTypedefMetadata(TypedefEntity typedef) { | 1462 Iterable<ConstantValue> getTypedefMetadata(TypedefEntity typedef) { |
| 1486 // TODO(redemption): Support this. | 1463 // TODO(redemption): Support this. |
| 1487 throw new UnsupportedError('ElementEnvironment.getTypedefMetadata'); | 1464 throw new UnsupportedError('ElementEnvironment.getTypedefMetadata'); |
| 1488 } | 1465 } |
| 1489 | 1466 |
| 1490 @override | 1467 @override |
| 1491 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member, | 1468 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member, |
| 1492 {bool includeParameterMetadata: false}) { | 1469 {bool includeParameterMetadata: false}) { |
| 1493 // TODO(redemption): Support includeParameterMetadata. | 1470 // TODO(redemption): Support includeParameterMetadata. |
| 1494 MemberData memberData = elementMap._memberData[member.memberIndex]; | 1471 MemberData memberData = elementMap._members.getData(member.memberIndex); |
| 1495 return memberData.getMetadata(elementMap); | 1472 return memberData.getMetadata(elementMap); |
| 1496 } | 1473 } |
| 1497 | 1474 |
| 1498 @override | 1475 @override |
| 1499 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { | 1476 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { |
| 1500 // TODO(redemption): Support this. | 1477 // TODO(redemption): Support this. |
| 1501 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); | 1478 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); |
| 1502 } | 1479 } |
| 1503 } | 1480 } |
| 1504 | 1481 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1849 } | 1826 } |
| 1850 } | 1827 } |
| 1851 | 1828 |
| 1852 // Interface for testing equivalence of Kernel-based entities. | 1829 // Interface for testing equivalence of Kernel-based entities. |
| 1853 class WorldDeconstructionForTesting { | 1830 class WorldDeconstructionForTesting { |
| 1854 final KernelToElementMapBase elementMap; | 1831 final KernelToElementMapBase elementMap; |
| 1855 | 1832 |
| 1856 WorldDeconstructionForTesting(this.elementMap); | 1833 WorldDeconstructionForTesting(this.elementMap); |
| 1857 | 1834 |
| 1858 IndexedClass getSuperclassForClass(IndexedClass cls) { | 1835 IndexedClass getSuperclassForClass(IndexedClass cls) { |
| 1859 ClassEnv env = elementMap._classEnvs[cls.classIndex]; | 1836 ClassEnv env = elementMap._classes.getEnv(cls.classIndex); |
| 1860 ir.Supertype supertype = env.cls.supertype; | 1837 ir.Supertype supertype = env.cls.supertype; |
| 1861 if (supertype == null) return null; | 1838 if (supertype == null) return null; |
| 1862 return elementMap.getClass(supertype.classNode); | 1839 return elementMap.getClass(supertype.classNode); |
| 1863 } | 1840 } |
| 1864 | 1841 |
| 1865 bool isUnnamedMixinApplication(IndexedClass cls) { | 1842 bool isUnnamedMixinApplication(IndexedClass cls) { |
| 1866 return elementMap._isUnnamedMixinApplication(cls); | 1843 return elementMap._isUnnamedMixinApplication(cls); |
| 1867 } | 1844 } |
| 1868 | 1845 |
| 1869 InterfaceType getMixinTypeForClass(IndexedClass cls) { | 1846 InterfaceType getMixinTypeForClass(IndexedClass cls) { |
| 1870 ClassEnv env = elementMap._classEnvs[cls.classIndex]; | 1847 ClassEnv env = elementMap._classes.getEnv(cls.classIndex); |
| 1871 ir.Supertype mixedInType = env.cls.mixedInType; | 1848 ir.Supertype mixedInType = env.cls.mixedInType; |
| 1872 if (mixedInType == null) return null; | 1849 if (mixedInType == null) return null; |
| 1873 return elementMap.createInterfaceType( | 1850 return elementMap.createInterfaceType( |
| 1874 mixedInType.classNode, mixedInType.typeArguments); | 1851 mixedInType.classNode, mixedInType.typeArguments); |
| 1875 } | 1852 } |
| 1876 } | 1853 } |
| 1877 | 1854 |
| 1878 class KernelNativeMemberResolver extends NativeMemberResolverBase { | 1855 class KernelNativeMemberResolver extends NativeMemberResolverBase { |
| 1879 final KernelToElementMapForImpactImpl elementMap; | 1856 final KernelToElementMapForImpactImpl elementMap; |
| 1880 final NativeBasicData nativeBasicData; | 1857 final NativeBasicData nativeBasicData; |
| 1881 final NativeDataBuilder nativeDataBuilder; | 1858 final NativeDataBuilder nativeDataBuilder; |
| 1882 | 1859 |
| 1883 KernelNativeMemberResolver( | 1860 KernelNativeMemberResolver( |
| 1884 this.elementMap, this.nativeBasicData, this.nativeDataBuilder); | 1861 this.elementMap, this.nativeBasicData, this.nativeDataBuilder); |
| 1885 | 1862 |
| 1886 @override | 1863 @override |
| 1887 ElementEnvironment get elementEnvironment => elementMap.elementEnvironment; | 1864 ElementEnvironment get elementEnvironment => elementMap.elementEnvironment; |
| 1888 | 1865 |
| 1889 @override | 1866 @override |
| 1890 CommonElements get commonElements => elementMap.commonElements; | 1867 CommonElements get commonElements => elementMap.commonElements; |
| 1891 | 1868 |
| 1892 @override | 1869 @override |
| 1893 native.NativeBehavior computeNativeFieldStoreBehavior( | 1870 native.NativeBehavior computeNativeFieldStoreBehavior( |
| 1894 covariant KField field) { | 1871 covariant KField field) { |
| 1895 ir.Field node = elementMap._memberData[field.memberIndex].definition.node; | 1872 ir.Field node = |
| 1873 elementMap._members.getData(field.memberIndex).definition.node; | |
| 1896 return elementMap.getNativeBehaviorForFieldStore(node); | 1874 return elementMap.getNativeBehaviorForFieldStore(node); |
| 1897 } | 1875 } |
| 1898 | 1876 |
| 1899 @override | 1877 @override |
| 1900 native.NativeBehavior computeNativeFieldLoadBehavior(covariant KField field, | 1878 native.NativeBehavior computeNativeFieldLoadBehavior(covariant KField field, |
| 1901 {bool isJsInterop}) { | 1879 {bool isJsInterop}) { |
| 1902 ir.Field node = elementMap._memberData[field.memberIndex].definition.node; | 1880 ir.Field node = |
| 1881 elementMap._members.getData(field.memberIndex).definition.node; | |
| 1903 return elementMap.getNativeBehaviorForFieldLoad(node, | 1882 return elementMap.getNativeBehaviorForFieldLoad(node, |
| 1904 isJsInterop: isJsInterop); | 1883 isJsInterop: isJsInterop); |
| 1905 } | 1884 } |
| 1906 | 1885 |
| 1907 @override | 1886 @override |
| 1908 native.NativeBehavior computeNativeMethodBehavior( | 1887 native.NativeBehavior computeNativeMethodBehavior( |
| 1909 covariant KFunction function, | 1888 covariant KFunction function, |
| 1910 {bool isJsInterop}) { | 1889 {bool isJsInterop}) { |
| 1911 ir.Member node = | 1890 ir.Member node = |
| 1912 elementMap._memberData[function.memberIndex].definition.node; | 1891 elementMap._members.getData(function.memberIndex).definition.node; |
| 1913 return elementMap.getNativeBehaviorForMethod(node, | 1892 return elementMap.getNativeBehaviorForMethod(node, |
| 1914 isJsInterop: isJsInterop); | 1893 isJsInterop: isJsInterop); |
| 1915 } | 1894 } |
| 1916 | 1895 |
| 1917 @override | 1896 @override |
| 1918 bool isNativeMethod(covariant KFunction function) { | 1897 bool isNativeMethod(covariant KFunction function) { |
| 1919 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; | 1898 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; |
| 1920 ir.Member node = | 1899 ir.Member node = |
| 1921 elementMap._memberData[function.memberIndex].definition.node; | 1900 elementMap._members.getData(function.memberIndex).definition.node; |
| 1922 return node.isExternal && | 1901 return node.isExternal && |
| 1923 !elementMap.isForeignLibrary(node.enclosingLibrary); | 1902 !elementMap.isForeignLibrary(node.enclosingLibrary); |
| 1924 } | 1903 } |
| 1925 | 1904 |
| 1926 @override | 1905 @override |
| 1927 bool isJsInteropMember(MemberEntity element) { | 1906 bool isJsInteropMember(MemberEntity element) { |
| 1928 return nativeBasicData.isJsInteropMember(element); | 1907 return nativeBasicData.isJsInteropMember(element); |
| 1929 } | 1908 } |
| 1930 } | 1909 } |
| 1931 | 1910 |
| 1932 class JsToFrontendMapImpl extends JsToFrontendMapBase | 1911 class JsToFrontendMapImpl extends JsToFrontendMapBase |
| 1933 implements JsToFrontendMap { | 1912 implements JsToFrontendMap { |
| 1934 final KernelToElementMapBase _backend; | 1913 final KernelToElementMapBase _backend; |
| 1935 | 1914 |
| 1936 JsToFrontendMapImpl(this._backend); | 1915 JsToFrontendMapImpl(this._backend); |
| 1937 | 1916 |
| 1938 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { | 1917 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { |
| 1939 return _backend._libraryList[library.libraryIndex]; | 1918 return _backend._libraries.getEntity(library.libraryIndex); |
| 1940 } | 1919 } |
| 1941 | 1920 |
| 1942 ClassEntity toBackendClass(covariant IndexedClass cls) { | 1921 ClassEntity toBackendClass(covariant IndexedClass cls) { |
| 1943 return _backend._classList[cls.classIndex]; | 1922 return _backend._classes.getEntity(cls.classIndex); |
| 1944 } | 1923 } |
| 1945 | 1924 |
| 1946 MemberEntity toBackendMember(covariant IndexedMember member) { | 1925 MemberEntity toBackendMember(covariant IndexedMember member) { |
| 1947 return _backend._memberList[member.memberIndex]; | 1926 return _backend._members.getEntity(member.memberIndex); |
| 1948 } | 1927 } |
| 1949 | 1928 |
| 1950 TypeVariableEntity toBackendTypeVariable( | 1929 TypeVariableEntity toBackendTypeVariable( |
| 1951 covariant IndexedTypeVariable typeVariable) { | 1930 covariant IndexedTypeVariable typeVariable) { |
| 1952 return _backend._typeVariableList[typeVariable.typeVariableIndex]; | 1931 return _backend._typeVariables.getEntity(typeVariable.typeVariableIndex); |
| 1953 } | 1932 } |
| 1954 } | 1933 } |
| 1955 | 1934 |
| 1956 class JsKernelToElementMap extends KernelToElementMapBase | 1935 class JsKernelToElementMap extends KernelToElementMapBase |
| 1957 with | 1936 with |
| 1958 KernelToElementMapForBuildingMixin, | 1937 KernelToElementMapForBuildingMixin, |
| 1959 JsElementCreatorMixin, | 1938 JsElementCreatorMixin, |
| 1960 // TODO(johnniwinther): Avoid mixing in [ElementCreatorMixin]. The | 1939 // TODO(johnniwinther): Avoid mixing in [ElementCreatorMixin]. The |
| 1961 // codegen world should be a strict subset of the resolution world and | 1940 // codegen world should be a strict subset of the resolution world and |
| 1962 // creating elements for IR nodes should therefore not be needed. | 1941 // creating elements for IR nodes should therefore not be needed. |
| 1963 // Currently some are created purely for testing (like | 1942 // Currently some are created purely for testing (like |
| 1964 // `element == commonElements.foo`, where 'foo' might not be live). | 1943 // `element == commonElements.foo`, where 'foo' might not be live). |
| 1965 // Others are created because we do a | 1944 // Others are created because we do a |
| 1966 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted | 1945 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted |
| 1967 // library. | 1946 // library. |
| 1968 ElementCreatorMixin | 1947 ElementCreatorMixin |
| 1969 implements | 1948 implements |
| 1970 KernelToWorldBuilder { | 1949 KernelToWorldBuilder { |
| 1971 NativeBasicData nativeBasicData; | 1950 NativeBasicData nativeBasicData; |
| 1972 | 1951 |
| 1973 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, | 1952 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, |
| 1974 KernelToElementMapForImpactImpl _elementMap) | 1953 KernelToElementMapForImpactImpl _elementMap) |
| 1975 : super(reporter, environment) { | 1954 : super(reporter, environment) { |
| 1976 _env = _elementMap._env; | 1955 _env = _elementMap._env; |
| 1977 for (int libraryIndex = 0; | 1956 for (int libraryIndex = 0; |
| 1978 libraryIndex < _elementMap._libraryEnvs.length; | 1957 libraryIndex < _elementMap._libraries.length; |
| 1979 libraryIndex++) { | 1958 libraryIndex++) { |
| 1980 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; | 1959 LibraryEnv env = _elementMap._libraries.getEnv(libraryIndex); |
| 1981 LibraryData data = _elementMap._libraryData[libraryIndex]; | 1960 LibraryData data = _elementMap._libraries.getData(libraryIndex); |
| 1982 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; | 1961 IndexedLibrary oldLibrary = |
| 1983 LibraryEntity newLibrary = convertLibrary(oldLibrary); | 1962 _elementMap._libraries.getEntity(libraryIndex); |
| 1984 _libraryMap[env.library] = newLibrary; | 1963 _libraryMap[env.library] = _libraries |
| 1985 _libraryList.add(newLibrary); | 1964 .register<IndexedLibrary, LibraryData, LibraryEnv>( |
| 1986 _libraryData.add(data.copy()); | 1965 (int libraryIndex) { |
| 1987 _libraryEnvs.add(env); | 1966 assert(libraryIndex == oldLibrary.libraryIndex); |
| 1967 return convertLibrary(oldLibrary); | |
| 1968 }, (LibraryEntity library) { | |
| 1969 return data.copy(); | |
| 1970 }, (LibraryEntity library) { | |
| 1971 return env; | |
| 1972 }); | |
| 1988 } | 1973 } |
| 1989 for (int classIndex = 0; | 1974 for (int classIndex = 0; |
| 1990 classIndex < _elementMap._classEnvs.length; | 1975 classIndex < _elementMap._classes.length; |
| 1991 classIndex++) { | 1976 classIndex++) { |
| 1992 ClassEnv env = _elementMap._classEnvs[classIndex]; | 1977 ClassEnv env = _elementMap._classes.getEnv(classIndex); |
| 1993 ClassData data = _elementMap._classData[classIndex]; | 1978 ClassData data = _elementMap._classes.getData(classIndex); |
| 1994 ClassEntity oldClass = _elementMap._classList[classIndex]; | 1979 IndexedClass oldClass = _elementMap._classes.getEntity(classIndex); |
| 1995 IndexedLibrary oldLibrary = oldClass.library; | 1980 IndexedLibrary oldLibrary = oldClass.library; |
| 1996 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; | 1981 _classMap[env.cls] = _classes.register((int classIndex) { |
| 1997 ClassEntity newClass = convertClass(newLibrary, oldClass); | 1982 assert(classIndex == oldClass.classIndex); |
| 1998 _classMap[env.cls] = newClass; | 1983 LibraryEntity newLibrary = |
| 1999 _classList.add(newClass); | 1984 _libraries.getEntity(oldLibrary.libraryIndex); |
| 2000 _classEnvs.add(env); | 1985 return convertClass(newLibrary, oldClass); |
| 2001 _classData.add(data.copy()); | 1986 }, (IndexedClass cls) { |
|
Siggi Cherem (dart-lang)
2017/08/22 19:12:22
I'd use => for these short closures here and elsew
| |
| 1987 return data.copy(); | |
| 1988 }, (IndexedClass cls) { | |
| 1989 return env; | |
| 1990 }); | |
| 2002 } | 1991 } |
| 2003 for (int memberIndex = 0; | 1992 for (int memberIndex = 0; |
| 2004 memberIndex < _elementMap._memberData.length; | 1993 memberIndex < _elementMap._members.length; |
| 2005 memberIndex++) { | 1994 memberIndex++) { |
| 2006 MemberDataImpl data = _elementMap._memberData[memberIndex]; | 1995 MemberDataImpl data = _elementMap._members.getData(memberIndex); |
| 2007 MemberEntity oldMember = _elementMap._memberList[memberIndex]; | 1996 IndexedMember oldMember = _elementMap._members.getEntity(memberIndex); |
| 2008 IndexedLibrary oldLibrary = oldMember.library; | 1997 IndexedLibrary oldLibrary = oldMember.library; |
| 2009 IndexedClass oldClass = oldMember.enclosingClass; | 1998 IndexedClass oldClass = oldMember.enclosingClass; |
| 2010 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; | 1999 IndexedMember newMember = _members.register((int memberIndex) { |
| 2011 ClassEntity newClass = | 2000 assert(memberIndex == oldMember.memberIndex); |
| 2012 oldClass != null ? _classList[oldClass.classIndex] : null; | 2001 LibraryEntity newLibrary = |
| 2013 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember); | 2002 _libraries.getEntity(oldLibrary.libraryIndex); |
| 2014 _memberList.add(newMember); | 2003 ClassEntity newClass = |
| 2015 _memberData.add(data.copy()); | 2004 oldClass != null ? _classes.getEntity(oldClass.classIndex) : null; |
| 2005 return convertMember(newLibrary, newClass, oldMember); | |
| 2006 }, (IndexedMember member) { | |
| 2007 return data.copy(); | |
| 2008 }); | |
| 2016 if (newMember.isField) { | 2009 if (newMember.isField) { |
| 2017 _fieldMap[data.node] = newMember; | 2010 _fieldMap[data.node] = newMember; |
| 2018 } else if (newMember.isConstructor) { | 2011 } else if (newMember.isConstructor) { |
| 2019 _constructorMap[data.node] = newMember; | 2012 _constructorMap[data.node] = newMember; |
| 2020 } else { | 2013 } else { |
| 2021 _methodMap[data.node] = newMember; | 2014 _methodMap[data.node] = newMember; |
| 2022 } | 2015 } |
| 2023 } | 2016 } |
| 2024 for (int typeVariableIndex = 0; | 2017 for (int typeVariableIndex = 0; |
| 2025 typeVariableIndex < _elementMap._typeVariableList.length; | 2018 typeVariableIndex < _elementMap._typeVariables.length; |
| 2026 typeVariableIndex++) { | 2019 typeVariableIndex++) { |
| 2027 TypeVariableEntity oldTypeVariable = | 2020 TypeVariableEntity oldTypeVariable = |
| 2028 _elementMap._typeVariableList[typeVariableIndex]; | 2021 _elementMap._typeVariables.getEntity(typeVariableIndex); |
| 2029 Entity newTypeDeclaration; | 2022 Entity newTypeDeclaration; |
| 2030 if (oldTypeVariable.typeDeclaration is ClassEntity) { | 2023 if (oldTypeVariable.typeDeclaration is ClassEntity) { |
| 2031 IndexedClass cls = oldTypeVariable.typeDeclaration; | 2024 IndexedClass cls = oldTypeVariable.typeDeclaration; |
| 2032 newTypeDeclaration = _classList[cls.classIndex]; | 2025 newTypeDeclaration = _classes.getEntity(cls.classIndex); |
| 2033 } else { | 2026 } else { |
| 2034 IndexedMember member = oldTypeVariable.typeDeclaration; | 2027 IndexedMember member = oldTypeVariable.typeDeclaration; |
| 2035 newTypeDeclaration = _memberList[member.memberIndex]; | 2028 newTypeDeclaration = _members.getEntity(member.memberIndex); |
| 2036 } | 2029 } |
| 2037 TypeVariableEntity newTypeVariable = createTypeVariable(typeVariableIndex, | 2030 _typeVariables.register<IndexedTypeVariable>((int typeVariablesIndex) { |
| 2038 newTypeDeclaration, oldTypeVariable.name, oldTypeVariable.index); | 2031 return createTypeVariable(typeVariableIndex, newTypeDeclaration, |
| 2039 _typeVariableList.add(newTypeVariable); | 2032 oldTypeVariable.name, oldTypeVariable.index); |
| 2033 }); | |
| 2040 } | 2034 } |
| 2041 } | 2035 } |
| 2042 | 2036 |
| 2043 @override | 2037 @override |
| 2044 bool checkFamily(Entity entity) { | 2038 bool checkFamily(Entity entity) { |
| 2045 assert( | 2039 assert( |
| 2046 '$entity'.startsWith(jsElementPrefix), | 2040 '$entity'.startsWith(jsElementPrefix), |
| 2047 failedAt(entity, | 2041 failedAt(entity, |
| 2048 "Unexpected entity $entity, expected family $jsElementPrefix.")); | 2042 "Unexpected entity $entity, expected family $jsElementPrefix.")); |
| 2049 return true; | 2043 return true; |
| 2050 } | 2044 } |
| 2051 | 2045 |
| 2052 @override | 2046 @override |
| 2053 Spannable getSpannable(MemberEntity member, ir.Node node) { | 2047 Spannable getSpannable(MemberEntity member, ir.Node node) { |
| 2054 return _getSpannable(member, node); | 2048 return _getSpannable(member, node); |
| 2055 } | 2049 } |
| 2056 | 2050 |
| 2057 Iterable<LibraryEntity> get _libraries { | 2051 Iterable<LibraryEntity> get _libraryList { |
| 2058 return _libraryMap.values; | 2052 return _libraryMap.values; |
| 2059 } | 2053 } |
| 2060 | 2054 |
| 2061 @override | 2055 @override |
| 2062 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv env]) { | 2056 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv env]) { |
| 2063 LibraryEntity library = _libraryMap[node]; | 2057 LibraryEntity library = _libraryMap[node]; |
| 2064 assert(library != null, "No library entity for $node"); | 2058 assert(library != null, "No library entity for $node"); |
| 2065 return library; | 2059 return library; |
| 2066 } | 2060 } |
| 2067 | 2061 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2095 return constructor; | 2089 return constructor; |
| 2096 } | 2090 } |
| 2097 | 2091 |
| 2098 FunctionEntity getConstructorBody(ir.Constructor node) { | 2092 FunctionEntity getConstructorBody(ir.Constructor node) { |
| 2099 ConstructorEntity constructor = getConstructor(node); | 2093 ConstructorEntity constructor = getConstructor(node); |
| 2100 return _getConstructorBody(node, constructor); | 2094 return _getConstructorBody(node, constructor); |
| 2101 } | 2095 } |
| 2102 | 2096 |
| 2103 FunctionEntity _getConstructorBody( | 2097 FunctionEntity _getConstructorBody( |
| 2104 ir.Constructor node, covariant IndexedConstructor constructor) { | 2098 ir.Constructor node, covariant IndexedConstructor constructor) { |
| 2105 ConstructorDataImpl data = _memberData[constructor.memberIndex]; | 2099 ConstructorDataImpl data = _members.getData(constructor.memberIndex); |
| 2106 if (data.constructorBody == null) { | 2100 if (data.constructorBody == null) { |
| 2107 ConstructorBodyEntity constructorBody = data.constructorBody = | 2101 JConstructorBody constructorBody = |
| 2108 createConstructorBody(_memberList.length, constructor); | 2102 _members.register<IndexedFunction, FunctionData>((int memberIndex) { |
| 2109 _memberList.add(constructorBody); | 2103 return createConstructorBody(memberIndex, constructor); |
| 2110 _memberData.add(new FunctionDataImpl( | 2104 }, (IndexedFunction constructorBody) { |
| 2111 node, | 2105 return new FunctionDataImpl( |
| 2112 node.function, | 2106 node, |
| 2113 new SpecialMemberDefinition( | 2107 node.function, |
| 2114 constructorBody, node, MemberKind.constructorBody))); | 2108 new SpecialMemberDefinition( |
| 2109 constructorBody, node, MemberKind.constructorBody)); | |
| 2110 }); | |
| 2115 IndexedClass cls = constructor.enclosingClass; | 2111 IndexedClass cls = constructor.enclosingClass; |
| 2116 ClassEnvImpl classEnv = _classEnvs[cls.classIndex]; | 2112 ClassEnvImpl classEnv = _classes.getEnv(cls.classIndex); |
| 2117 // TODO(johnniwinther): Avoid this by only including live members in the | 2113 // TODO(johnniwinther): Avoid this by only including live members in the |
| 2118 // js-model. | 2114 // js-model. |
| 2119 classEnv.addConstructorBody(constructorBody); | 2115 classEnv.addConstructorBody(constructorBody); |
| 2116 data.constructorBody = constructorBody; | |
| 2120 } | 2117 } |
| 2121 return data.constructorBody; | 2118 return data.constructorBody; |
| 2122 } | 2119 } |
| 2123 | 2120 |
| 2124 ConstructorBodyEntity createConstructorBody( | 2121 JConstructorBody createConstructorBody( |
| 2125 int memberIndex, ConstructorEntity constructor); | 2122 int memberIndex, ConstructorEntity constructor); |
| 2126 | 2123 |
| 2127 @override | 2124 @override |
| 2128 MemberDefinition getMemberDefinition(MemberEntity member) { | 2125 MemberDefinition getMemberDefinition(MemberEntity member) { |
| 2129 return _getMemberDefinition(member); | 2126 return _getMemberDefinition(member); |
| 2130 } | 2127 } |
| 2131 | 2128 |
| 2132 @override | 2129 @override |
| 2133 ClassDefinition getClassDefinition(ClassEntity cls) { | 2130 ClassDefinition getClassDefinition(ClassEntity cls) { |
| 2134 return _getClassDefinition(cls); | 2131 return _getClassDefinition(cls); |
| 2135 } | 2132 } |
| 2136 | 2133 |
| 2137 @override | 2134 @override |
| 2138 ConstantValue getFieldConstantValue(ir.Field field) { | 2135 ConstantValue getFieldConstantValue(ir.Field field) { |
| 2139 // TODO(johnniwinther): Cache the result in [FieldData]. | 2136 // TODO(johnniwinther): Cache the result in [FieldData]. |
| 2140 return getConstantValue(field.initializer, | 2137 return getConstantValue(field.initializer, |
| 2141 requireConstant: field.isConst, implicitNull: !field.isConst); | 2138 requireConstant: field.isConst, implicitNull: !field.isConst); |
| 2142 } | 2139 } |
| 2143 | 2140 |
| 2144 bool hasConstantFieldInitializer(covariant IndexedField field) { | 2141 bool hasConstantFieldInitializer(covariant IndexedField field) { |
| 2145 FieldData data = _memberData[field.memberIndex]; | 2142 FieldData data = _members.getData(field.memberIndex); |
| 2146 return getFieldConstantValue(data.definition.node) != null; | 2143 return getFieldConstantValue(data.definition.node) != null; |
| 2147 } | 2144 } |
| 2148 | 2145 |
| 2149 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { | 2146 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { |
| 2150 FieldData data = _memberData[field.memberIndex]; | 2147 FieldData data = _members.getData(field.memberIndex); |
| 2151 ConstantValue value = getFieldConstantValue(data.definition.node); | 2148 ConstantValue value = getFieldConstantValue(data.definition.node); |
| 2152 assert(value != null, | 2149 assert(value != null, |
| 2153 failedAt(field, "Field $field doesn't have a constant initial value.")); | 2150 failedAt(field, "Field $field doesn't have a constant initial value.")); |
| 2154 return value; | 2151 return value; |
| 2155 } | 2152 } |
| 2156 | 2153 |
| 2157 void forEachParameter(covariant IndexedFunction function, | 2154 void forEachParameter(covariant IndexedFunction function, |
| 2158 void f(DartType type, String name, ConstantValue defaultValue)) { | 2155 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 2159 FunctionData data = _memberData[function.memberIndex]; | 2156 FunctionData data = _members.getData(function.memberIndex); |
| 2160 data.forEachParameter(this, f); | 2157 data.forEachParameter(this, f); |
| 2161 } | 2158 } |
| 2162 | 2159 |
| 2163 void _forEachConstructorBody( | 2160 void _forEachConstructorBody( |
| 2164 IndexedClass cls, void f(ConstructorBodyEntity member)) { | 2161 IndexedClass cls, void f(ConstructorBodyEntity member)) { |
| 2165 ClassEnv env = _classEnvs[cls.classIndex]; | 2162 ClassEnv env = _classes.getEnv(cls.classIndex); |
| 2166 env.forEachConstructorBody(f); | 2163 env.forEachConstructorBody(f); |
| 2167 } | 2164 } |
| 2168 | 2165 |
| 2169 KernelClosureClass constructClosureClass( | 2166 KernelClosureClass constructClosureClass( |
| 2170 MemberEntity member, | 2167 MemberEntity member, |
| 2171 ir.FunctionNode node, | 2168 ir.FunctionNode node, |
| 2172 JLibrary enclosingLibrary, | 2169 JLibrary enclosingLibrary, |
| 2173 KernelScopeInfo info, | 2170 KernelScopeInfo info, |
| 2174 Map<Local, FieldEntity> boxedFields, | 2171 Map<Local, FieldEntity> boxedFields, |
| 2175 ir.Location location, | 2172 ir.Location location, |
| 2176 KernelToLocalsMap localsMap, | 2173 KernelToLocalsMap localsMap, |
| 2177 InterfaceType supertype) { | 2174 InterfaceType supertype) { |
| 2178 String name = _computeClosureName(node); | 2175 String name = _computeClosureName(node); |
| 2179 JClass classEntity = | 2176 SourceSpan location = computeSourceSpanFromTreeNode(node); |
| 2180 new JClosureClass(enclosingLibrary, _classEnvs.length, name); | |
| 2181 _classList.add(classEntity); | |
| 2182 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; | 2177 Map<String, MemberEntity> memberMap = <String, MemberEntity>{}; |
| 2183 _classEnvs.add(new ClosureClassEnv(memberMap)); | |
| 2184 | 2178 |
| 2185 // Create a classData and set up the interfaces and subclass | 2179 JClass classEntity = _classes.register((int classIndex) { |
| 2186 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing | 2180 return new JClosureClass(enclosingLibrary, classIndex, name); |
| 2187 var closureData = new ClassData( | 2181 }, (IndexedClass cls) { |
| 2188 null, | 2182 // Create a classData and set up the interfaces and subclass |
| 2189 new ClosureClassDefinition( | 2183 // relationships that _ensureSupertypes and _ensureThisAndRawType are doin g |
| 2190 classEntity, computeSourceSpanFromTreeNode(node))); | 2184 var closureData = |
| 2191 closureData | 2185 new ClassData(null, new ClosureClassDefinition(cls, location)); |
| 2192 ..isMixinApplication = false | 2186 closureData |
| 2193 ..thisType = closureData.rawType = | 2187 ..isMixinApplication = false |
| 2194 new InterfaceType(classEntity, const <DartType>[]) | 2188 ..thisType = |
| 2195 ..supertype = supertype | 2189 closureData.rawType = new InterfaceType(cls, const <DartType>[]) |
| 2196 ..interfaces = const <InterfaceType>[]; | 2190 ..supertype = supertype |
| 2191 ..interfaces = const <InterfaceType>[]; | |
| 2192 return closureData; | |
| 2193 }, (IndexedClass cls) { | |
| 2194 return new ClosureClassEnv(memberMap); | |
| 2195 }); | |
| 2196 var closureData = _classes.getData(classEntity.classIndex); | |
| 2197 var setBuilder = new _KernelOrderedTypeSetBuilder(this, classEntity); | 2197 var setBuilder = new _KernelOrderedTypeSetBuilder(this, classEntity); |
| 2198 _classData.add(closureData); | |
| 2199 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( | 2198 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 2200 closureData.supertype, const Link<InterfaceType>()); | 2199 closureData.supertype, const Link<InterfaceType>()); |
| 2201 | 2200 |
| 2202 KernelClosureClass cls = new KernelClosureClass.fromScopeInfo( | 2201 KernelClosureClass cls = new KernelClosureClass.fromScopeInfo( |
| 2203 classEntity, node, info, localsMap); | 2202 classEntity, node, info, localsMap); |
| 2204 | 2203 |
| 2205 int i = 0; | 2204 int i = 0; |
| 2206 Set<Local> boxes = new Set<Local>(); | 2205 Set<Local> boxes = new Set<Local>(); |
| 2207 for (ir.VariableDeclaration variable in info.freeVariables) { | 2206 for (ir.VariableDeclaration variable in info.freeVariables) { |
| 2208 // Make a corresponding field entity in this closure class for every | 2207 // Make a corresponding field entity in this closure class for every |
| 2209 // single freeVariable in the KernelScopeInfo.freeVariable. | 2208 // single freeVariable in the KernelScopeInfo.freeVariable. |
| 2210 | 2209 |
| 2211 void addClosureField(Local local) { | 2210 void addClosureField(Local local) { |
| 2212 FieldEntity closureField = new JClosureField( | 2211 IndexedField closureField = |
| 2213 _getClosureVariableName(local.name, i++), _memberData.length, cls); | 2212 _members.register<IndexedField, FieldData>((int memberIndex) { |
| 2214 cls.localToFieldMap[local] = closureField; | 2213 FieldEntity closureField = new JClosureField( |
| 2215 _memberList.add(closureField); | 2214 _getClosureVariableName(local.name, i++), memberIndex, cls); |
| 2216 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( | 2215 cls.localToFieldMap[local] = closureField; |
| 2217 closureField, | 2216 return closureField; |
| 2218 computeSourceSpanFromTreeNode(variable), | 2217 }, (IndexedField closureField) { |
| 2219 MemberKind.closureField, | 2218 return new ClosureFieldData(new ClosureMemberDefinition( |
| 2220 variable))); | 2219 closureField, |
| 2220 computeSourceSpanFromTreeNode(variable), | |
| 2221 MemberKind.closureField, | |
| 2222 variable)); | |
| 2223 }); | |
| 2221 memberMap[closureField.name] = closureField; | 2224 memberMap[closureField.name] = closureField; |
| 2222 } | 2225 } |
| 2223 | 2226 |
| 2224 Local capturedLocal = localsMap.getLocalVariable(variable); | 2227 Local capturedLocal = localsMap.getLocalVariable(variable); |
| 2225 JBoxedField boxedField = boxedFields[capturedLocal]; | 2228 JBoxedField boxedField = boxedFields[capturedLocal]; |
| 2226 if (boxedField != null) { | 2229 if (boxedField != null) { |
| 2227 /// [capturedLocal] is encoded as a boxed field. | 2230 /// [capturedLocal] is encoded as a boxed field. |
| 2228 if (boxes.add(boxedField.box)) { | 2231 if (boxes.add(boxedField.box)) { |
| 2229 /// Add a closure field for the box, if not already added. | 2232 /// Add a closure field for the box, if not already added. |
| 2230 addClosureField(boxedField.box); | 2233 addClosureField(boxedField.box); |
| 2231 } | 2234 } |
| 2232 | 2235 |
| 2233 /// Remember that [capturedLocal] should be accessed through the boxed | 2236 /// Remember that [capturedLocal] should be accessed through the boxed |
| 2234 /// field. | 2237 /// field. |
| 2235 cls.boxedVariables[capturedLocal] = boxedField; | 2238 cls.boxedVariables[capturedLocal] = boxedField; |
| 2236 } else { | 2239 } else { |
| 2237 /// [capturedLocal] is passed by value. Add a closure field for | 2240 /// [capturedLocal] is passed by value. Add a closure field for |
| 2238 /// the value. | 2241 /// the value. |
| 2239 addClosureField(capturedLocal); | 2242 addClosureField(capturedLocal); |
| 2240 } | 2243 } |
| 2241 } | 2244 } |
| 2242 | 2245 |
| 2243 FunctionEntity callMethod = cls.callMethod = new JClosureCallMethod( | 2246 cls.callMethod = |
| 2244 _memberData.length, | 2247 _members.register<IndexedFunction, FunctionData>((int memberIndex) { |
| 2245 cls, | 2248 return new JClosureCallMethod(memberIndex, cls, |
| 2246 _getParameterStructure(node), | 2249 _getParameterStructure(node), _getAsyncMarker(node)); |
| 2247 _getAsyncMarker(node)); | 2250 }, (IndexedFunction callMethod) { |
| 2248 _memberList.add(cls.callMethod); | 2251 return new ClosureFunctionData( |
| 2249 | 2252 new ClosureMemberDefinition( |
| 2250 _memberData.add(new ClosureFunctionData( | 2253 callMethod, location, MemberKind.closureCall, node.parent), |
| 2251 new ClosureMemberDefinition(callMethod, closureData.definition.location, | 2254 getFunctionType(node), |
| 2252 MemberKind.closureCall, node.parent), | 2255 node); |
| 2253 getFunctionType(node), | 2256 }); |
| 2254 node)); | |
| 2255 memberMap[cls.callMethod.name] = cls.callMethod; | 2257 memberMap[cls.callMethod.name] = cls.callMethod; |
| 2256 return cls; | 2258 return cls; |
| 2257 } | 2259 } |
| 2258 | 2260 |
| 2259 // Returns a non-unique name for the given closure element. | 2261 // Returns a non-unique name for the given closure element. |
| 2260 String _computeClosureName(ir.TreeNode treeNode) { | 2262 String _computeClosureName(ir.TreeNode treeNode) { |
| 2261 var parts = <String>[]; | 2263 var parts = <String>[]; |
| 2262 if (treeNode is ir.Field && treeNode.name.name != "") { | 2264 if (treeNode is ir.Field && treeNode.name.name != "") { |
| 2263 parts.add(treeNode.name.name); | 2265 parts.add(treeNode.name.name); |
| 2264 } else { | 2266 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2304 /// | 2306 /// |
| 2305 /// These names are not used in generated code, just as element name. | 2307 /// These names are not used in generated code, just as element name. |
| 2306 String _getClosureVariableName(String name, int id) { | 2308 String _getClosureVariableName(String name, int id) { |
| 2307 return "_captured_${name}_$id"; | 2309 return "_captured_${name}_$id"; |
| 2308 } | 2310 } |
| 2309 | 2311 |
| 2310 String getDeferredUri(ir.LibraryDependency node) { | 2312 String getDeferredUri(ir.LibraryDependency node) { |
| 2311 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2313 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 2312 } | 2314 } |
| 2313 } | 2315 } |
| OLD | NEW |