Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2971673002: Split ClassEnv into env and data to avoid copying types/constants from the k-model (Closed)
Patch Set: Updated cf. comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_model/elements.dart ('k') | pkg/compiler/lib/src/kernel/env.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 List<MemberEntity> _memberList = <MemberEntity>[]; 77 List<MemberEntity> _memberList = <MemberEntity>[];
78 78
79 /// List of library environments by `IndexedLibrary.libraryIndex`. This is 79 /// List of library environments by `IndexedLibrary.libraryIndex`. This is
80 /// used for fast lookup into library classes and members. 80 /// used for fast lookup into library classes and members.
81 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[]; 81 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[];
82 82
83 /// List of class environments by `IndexedClass.classIndex`. This is used for 83 /// List of class environments by `IndexedClass.classIndex`. This is used for
84 /// fast lookup into class members. 84 /// fast lookup into class members.
85 List<ClassEnv> _classEnvs = <ClassEnv>[]; 85 List<ClassEnv> _classEnvs = <ClassEnv>[];
86 86
87 /// List of class data by `IndexedClass.classIndex`. This is used for
88 /// fast lookup into class properties.
89 List<ClassData> _classData = <ClassData>[];
90
87 /// List of member data by `IndexedMember.classIndex`. This is used for 91 /// List of member data by `IndexedMember.classIndex`. This is used for
88 /// fast lookup into member properties. 92 /// fast lookup into member properties.
89 List<MemberData> _memberData = <MemberData>[]; 93 List<MemberData> _memberData = <MemberData>[];
90 94
91 KernelToElementMapBase(this.reporter, Environment environment) { 95 KernelToElementMapBase(this.reporter, Environment environment) {
92 _elementEnvironment = new KernelElementEnvironment(this); 96 _elementEnvironment = new KernelElementEnvironment(this);
93 _commonElements = new CommonElements(_elementEnvironment); 97 _commonElements = new CommonElements(_elementEnvironment);
94 _constantEnvironment = new KernelConstantEnvironment(this, environment); 98 _constantEnvironment = new KernelConstantEnvironment(this, environment);
95 _typeConverter = new DartTypeConverter(this); 99 _typeConverter = new DartTypeConverter(this);
96 _types = new _KernelDartTypes(this); 100 _types = new _KernelDartTypes(this);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node); 186 LibraryEntity getLibrary(ir.Library node) => _getLibrary(node);
183 187
184 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]); 188 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]);
185 189
186 @override 190 @override
187 ClassEntity getClass(ir.Class node) => _getClass(node); 191 ClassEntity getClass(ir.Class node) => _getClass(node);
188 192
189 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]); 193 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]);
190 194
191 InterfaceType _getSuperType(IndexedClass cls) { 195 InterfaceType _getSuperType(IndexedClass cls) {
192 ClassEnv env = _classEnvs[cls.classIndex]; 196 ClassData data = _classData[cls.classIndex];
193 _ensureSupertypes(cls, env); 197 _ensureSupertypes(cls, data);
194 return env.supertype; 198 return data.supertype;
195 } 199 }
196 200
197 void _ensureThisAndRawType(ClassEntity cls, ClassEnv env) { 201 void _ensureThisAndRawType(ClassEntity cls, ClassData data) {
198 if (env.thisType == null) { 202 if (data.thisType == null) {
199 ir.Class node = env.cls; 203 ir.Class node = data.cls;
200 // TODO(johnniwinther): Add the type argument to the list literal when we 204 // TODO(johnniwinther): Add the type argument to the list literal when we
201 // no longer use resolution types. 205 // no longer use resolution types.
202 if (node.typeParameters.isEmpty) { 206 if (node.typeParameters.isEmpty) {
203 env.thisType = 207 data.thisType =
204 env.rawType = new InterfaceType(cls, const/*<DartType>*/ []); 208 data.rawType = new InterfaceType(cls, const/*<DartType>*/ []);
205 } else { 209 } else {
206 env.thisType = new InterfaceType( 210 data.thisType = new InterfaceType(
207 cls, 211 cls,
208 new List/*<DartType>*/ .generate(node.typeParameters.length, 212 new List/*<DartType>*/ .generate(node.typeParameters.length,
209 (int index) { 213 (int index) {
210 return new TypeVariableType( 214 return new TypeVariableType(
211 _getTypeVariable(node.typeParameters[index])); 215 _getTypeVariable(node.typeParameters[index]));
212 })); 216 }));
213 env.rawType = new InterfaceType( 217 data.rawType = new InterfaceType(
214 cls, 218 cls,
215 new List/*<DartType>*/ .filled( 219 new List/*<DartType>*/ .filled(
216 node.typeParameters.length, const DynamicType())); 220 node.typeParameters.length, const DynamicType()));
217 } 221 }
218 } 222 }
219 } 223 }
220 224
221 TypeVariableEntity getTypeVariable(ir.TypeParameter node) => 225 TypeVariableEntity getTypeVariable(ir.TypeParameter node) =>
222 _getTypeVariable(node); 226 _getTypeVariable(node);
223 227
224 TypeVariableEntity _getTypeVariable(ir.TypeParameter node); 228 TypeVariableEntity _getTypeVariable(ir.TypeParameter node);
225 229
226 void _ensureSupertypes(ClassEntity cls, ClassEnv env) { 230 void _ensureSupertypes(ClassEntity cls, ClassData data) {
227 if (env.orderedTypeSet == null) { 231 if (data.orderedTypeSet == null) {
228 _ensureThisAndRawType(cls, env); 232 _ensureThisAndRawType(cls, data);
229 233
230 ir.Class node = env.cls; 234 ir.Class node = data.cls;
231 235
232 if (node.supertype == null) { 236 if (node.supertype == null) {
233 env.orderedTypeSet = new OrderedTypeSet.singleton(env.thisType); 237 data.orderedTypeSet = new OrderedTypeSet.singleton(data.thisType);
234 env.isMixinApplication = false; 238 data.isMixinApplication = false;
235 env.interfaces = const <InterfaceType>[]; 239 data.interfaces = const <InterfaceType>[];
236 } else { 240 } else {
237 InterfaceType processSupertype(ir.Supertype node) { 241 InterfaceType processSupertype(ir.Supertype node) {
238 InterfaceType type = _typeConverter.visitSupertype(node); 242 InterfaceType supertype = _typeConverter.visitSupertype(node);
239 IndexedClass superclass = type.element; 243 IndexedClass superclass = supertype.element;
240 ClassEnv env = _classEnvs[superclass.classIndex]; 244 ClassData superdata = _classData[superclass.classIndex];
241 _ensureSupertypes(superclass, env); 245 _ensureSupertypes(superclass, superdata);
242 return type; 246 return supertype;
243 } 247 }
244 248
245 env.supertype = processSupertype(node.supertype); 249 data.supertype = processSupertype(node.supertype);
246 LinkBuilder<InterfaceType> linkBuilder = 250 LinkBuilder<InterfaceType> linkBuilder =
247 new LinkBuilder<InterfaceType>(); 251 new LinkBuilder<InterfaceType>();
248 if (node.mixedInType != null) { 252 if (node.mixedInType != null) {
249 env.isMixinApplication = true; 253 data.isMixinApplication = true;
250 linkBuilder 254 linkBuilder
251 .addLast(env.mixedInType = processSupertype(node.mixedInType)); 255 .addLast(data.mixedInType = processSupertype(node.mixedInType));
252 } else { 256 } else {
253 env.isMixinApplication = false; 257 data.isMixinApplication = false;
254 } 258 }
255 node.implementedTypes.forEach((ir.Supertype supertype) { 259 node.implementedTypes.forEach((ir.Supertype supertype) {
256 linkBuilder.addLast(processSupertype(supertype)); 260 linkBuilder.addLast(processSupertype(supertype));
257 }); 261 });
258 Link<InterfaceType> interfaces = linkBuilder.toLink(); 262 Link<InterfaceType> interfaces = linkBuilder.toLink();
259 OrderedTypeSetBuilder setBuilder = 263 OrderedTypeSetBuilder setBuilder =
260 new _KernelOrderedTypeSetBuilder(this, cls); 264 new _KernelOrderedTypeSetBuilder(this, cls);
261 env.orderedTypeSet = 265 data.orderedTypeSet =
262 setBuilder.createOrderedTypeSet(env.supertype, interfaces); 266 setBuilder.createOrderedTypeSet(data.supertype, interfaces);
263 env.interfaces = new List<InterfaceType>.from(interfaces.toList()); 267 data.interfaces = new List<InterfaceType>.from(interfaces.toList());
264 } 268 }
265 } 269 }
266 } 270 }
267 271
268 @override 272 @override
269 MemberEntity getMember(ir.Member node) { 273 MemberEntity getMember(ir.Member node) {
270 if (node is ir.Field) { 274 if (node is ir.Field) {
271 return _getField(node); 275 return _getField(node);
272 } else if (node is ir.Constructor) { 276 } else if (node is ir.Constructor) {
273 return _getConstructor(node); 277 return _getConstructor(node);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 {bool requireConstant: true}) { 389 {bool requireConstant: true}) {
386 return _constantEnvironment.getConstantValue(constant); 390 return _constantEnvironment.getConstantValue(constant);
387 } 391 }
388 392
389 DartType _substByContext(DartType type, InterfaceType context) { 393 DartType _substByContext(DartType type, InterfaceType context) {
390 return type.subst( 394 return type.subst(
391 context.typeArguments, _getThisType(context.element).typeArguments); 395 context.typeArguments, _getThisType(context.element).typeArguments);
392 } 396 }
393 397
394 InterfaceType _getThisType(IndexedClass cls) { 398 InterfaceType _getThisType(IndexedClass cls) {
395 ClassEnv env = _classEnvs[cls.classIndex]; 399 ClassData data = _classData[cls.classIndex];
396 _ensureThisAndRawType(cls, env); 400 _ensureThisAndRawType(cls, data);
397 return env.thisType; 401 return data.thisType;
398 } 402 }
399 403
400 InterfaceType _getRawType(IndexedClass cls) { 404 InterfaceType _getRawType(IndexedClass cls) {
401 ClassEnv env = _classEnvs[cls.classIndex]; 405 ClassData data = _classData[cls.classIndex];
402 _ensureThisAndRawType(cls, env); 406 _ensureThisAndRawType(cls, data);
403 return env.rawType; 407 return data.rawType;
404 } 408 }
405 409
406 FunctionType _getFunctionType(IndexedFunction function) { 410 FunctionType _getFunctionType(IndexedFunction function) {
407 FunctionData data = _memberData[function.memberIndex]; 411 FunctionData data = _memberData[function.memberIndex];
408 return data.getFunctionType(this); 412 return data.getFunctionType(this);
409 } 413 }
410 414
411 ClassEntity _getAppliedMixin(IndexedClass cls) { 415 ClassEntity _getAppliedMixin(IndexedClass cls) {
412 ClassEnv env = _classEnvs[cls.classIndex]; 416 ClassData data = _classData[cls.classIndex];
413 _ensureSupertypes(cls, env); 417 _ensureThisAndRawType(cls, data);
414 return env.mixedInType?.element; 418 return data.mixedInType?.element;
415 } 419 }
416 420
417 bool _isMixinApplication(IndexedClass cls) { 421 bool _isMixinApplication(IndexedClass cls) {
418 ClassEnv env = _classEnvs[cls.classIndex]; 422 ClassData data = _classData[cls.classIndex];
419 _ensureSupertypes(cls, env); 423 _ensureThisAndRawType(cls, data);
420 return env.isMixinApplication; 424 return data.isMixinApplication;
421 } 425 }
422 426
423 bool _isUnnamedMixinApplication(IndexedClass cls) { 427 bool _isUnnamedMixinApplication(IndexedClass cls) {
424 ClassEnv env = _classEnvs[cls.classIndex]; 428 ClassEnv env = _classEnvs[cls.classIndex];
425 _ensureSupertypes(cls, env);
426 return env.isUnnamedMixinApplication; 429 return env.isUnnamedMixinApplication;
427 } 430 }
428 431
429 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) { 432 void _forEachSupertype(IndexedClass cls, void f(InterfaceType supertype)) {
430 ClassEnv env = _classEnvs[cls.classIndex]; 433 ClassData data = _classData[cls.classIndex];
431 _ensureSupertypes(cls, env); 434 _ensureThisAndRawType(cls, data);
432 env.orderedTypeSet.supertypes.forEach(f); 435 data.orderedTypeSet.supertypes.forEach(f);
433 } 436 }
434 437
435 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) { 438 void _forEachMixin(IndexedClass cls, void f(ClassEntity mixin)) {
436 while (cls != null) { 439 while (cls != null) {
437 ClassEnv env = _classEnvs[cls.classIndex]; 440 ClassData data = _classData[cls.classIndex];
438 _ensureSupertypes(cls, env); 441 _ensureThisAndRawType(cls, data);
439 if (env.mixedInType != null) { 442 if (data.mixedInType != null) {
440 f(env.mixedInType.element); 443 f(data.mixedInType.element);
441 } 444 }
442 cls = env.supertype?.element; 445 cls = data.supertype?.element;
443 } 446 }
444 } 447 }
445 448
446 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { 449 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) {
447 ClassEnv env = _classEnvs[cls.classIndex]; 450 ClassEnv env = _classEnvs[cls.classIndex];
448 env.forEachConstructor((ir.Member member) { 451 env.forEachConstructor((ir.Member member) {
449 f(getConstructor(member)); 452 f(getConstructor(member));
450 }); 453 });
451 } 454 }
452 455
453 void _forEachClassMember( 456 void _forEachClassMember(
454 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { 457 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) {
455 ClassEnv env = _classEnvs[cls.classIndex]; 458 ClassEnv env = _classEnvs[cls.classIndex];
456 env.forEachMember((ir.Member member) { 459 env.forEachMember((ir.Member member) {
457 f(cls, getMember(member)); 460 f(cls, getMember(member));
458 }); 461 });
459 _ensureSupertypes(cls, env); 462 ClassData data = _classData[cls.classIndex];
460 if (env.supertype != null) { 463 _ensureSupertypes(cls, data);
461 _forEachClassMember(env.supertype.element, f); 464 if (data.supertype != null) {
465 _forEachClassMember(data.supertype.element, f);
462 } 466 }
463 } 467 }
464 468
465 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { 469 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) {
466 ConstructorData data = _memberData[constructor.memberIndex]; 470 ConstructorData data = _memberData[constructor.memberIndex];
467 return data.getConstructorConstant(this, constructor); 471 return data.getConstructorConstant(this, constructor);
468 } 472 }
469 473
470 ConstantExpression _getFieldConstant(IndexedField field) { 474 ConstantExpression _getFieldConstant(IndexedField field) {
471 FieldData data = _memberData[field.memberIndex]; 475 FieldData data = _memberData[field.memberIndex];
472 return data.getFieldConstant(this, field); 476 return data.getFieldConstant(this, field);
473 } 477 }
474 478
475 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { 479 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) {
476 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); 480 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element);
477 InterfaceType supertype = 481 InterfaceType supertype =
478 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); 482 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls));
479 if (supertype != null) { 483 if (supertype != null) {
480 supertype = _substByContext(supertype, type); 484 supertype = _substByContext(supertype, type);
481 } 485 }
482 return supertype; 486 return supertype;
483 } 487 }
484 488
485 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) { 489 OrderedTypeSet _getOrderedTypeSet(IndexedClass cls) {
486 ClassEnv env = _classEnvs[cls.classIndex]; 490 ClassData data = _classData[cls.classIndex];
487 _ensureSupertypes(cls, env); 491 _ensureThisAndRawType(cls, data);
488 return env.orderedTypeSet; 492 return data.orderedTypeSet;
489 } 493 }
490 494
491 int _getHierarchyDepth(IndexedClass cls) { 495 int _getHierarchyDepth(IndexedClass cls) {
492 ClassEnv env = _classEnvs[cls.classIndex]; 496 ClassData data = _classData[cls.classIndex];
493 _ensureSupertypes(cls, env); 497 _ensureThisAndRawType(cls, data);
494 return env.orderedTypeSet.maxDepth; 498 return data.orderedTypeSet.maxDepth;
495 } 499 }
496 500
497 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { 501 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) {
498 ClassEnv env = _classEnvs[cls.classIndex]; 502 ClassData data = _classData[cls.classIndex];
499 _ensureSupertypes(cls, env); 503 _ensureThisAndRawType(cls, data);
500 return env.interfaces; 504 return data.interfaces;
501 } 505 }
502 506
503 Spannable _getSpannable(MemberEntity member, ir.Node node) { 507 Spannable _getSpannable(MemberEntity member, ir.Node node) {
504 return member; 508 return member;
505 } 509 }
506 510
507 ir.Member _getMemberNode(covariant IndexedMember member) { 511 ir.Member _getMemberNode(covariant IndexedMember member) {
508 return _memberData[member.memberIndex].node; 512 return _memberData[member.memberIndex].node;
509 } 513 }
510 514
511 ir.Class _getClassNode(covariant IndexedClass cls) { 515 ir.Class _getClassNode(covariant IndexedClass cls) {
512 return _classEnvs[cls.classIndex].cls; 516 return _classEnvs[cls.classIndex].cls;
513 } 517 }
514 } 518 }
515 519
516 /// Mixin that implements the abstract methods in [KernelToElementMapBase] by 520 /// Mixin that implements the abstract methods in [KernelToElementMapBase] by
517 /// creating K-model elements. 521 /// creating K-model elements.
518 abstract class ElementCreatorMixin { 522 abstract class ElementCreatorMixin {
519 ProgramEnv get _env; 523 ProgramEnv get _env;
520 List<LibraryEntity> get _libraryList; 524 List<LibraryEntity> get _libraryList;
521 List<LibraryEnv> get _libraryEnvs; 525 List<LibraryEnv> get _libraryEnvs;
522 List<ClassEntity> get _classList; 526 List<ClassEntity> get _classList;
523 List<ClassEnv> get _classEnvs; 527 List<ClassEnv> get _classEnvs;
528 List<ClassData> get _classData;
524 List<MemberEntity> get _memberList; 529 List<MemberEntity> get _memberList;
525 List<MemberData> get _memberData; 530 List<MemberData> get _memberData;
526 531
527 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; 532 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{};
528 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; 533 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{};
529 Map<ir.TypeParameter, TypeVariableEntity> _typeVariableMap = 534 Map<ir.TypeParameter, TypeVariableEntity> _typeVariableMap =
530 <ir.TypeParameter, TypeVariableEntity>{}; 535 <ir.TypeParameter, TypeVariableEntity>{};
531 Map<ir.Member, IndexedConstructor> _constructorMap = 536 Map<ir.Member, IndexedConstructor> _constructorMap =
532 <ir.Member, IndexedConstructor>{}; 537 <ir.Member, IndexedConstructor>{};
533 Map<ir.Procedure, IndexedFunction> _methodMap = 538 Map<ir.Procedure, IndexedFunction> _methodMap =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 }); 571 });
567 } 572 }
568 573
569 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { 574 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) {
570 return _classMap.putIfAbsent(node, () { 575 return _classMap.putIfAbsent(node, () {
571 KLibrary library = _getLibrary(node.enclosingLibrary); 576 KLibrary library = _getLibrary(node.enclosingLibrary);
572 if (classEnv == null) { 577 if (classEnv == null) {
573 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); 578 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name);
574 } 579 }
575 _classEnvs.add(classEnv); 580 _classEnvs.add(classEnv);
581 _classData.add(new ClassData(node));
576 ClassEntity cls = createClass(library, _classMap.length, node.name, 582 ClassEntity cls = createClass(library, _classMap.length, node.name,
577 isAbstract: node.isAbstract); 583 isAbstract: node.isAbstract);
578 _classList.add(cls); 584 _classList.add(cls);
579 return cls; 585 return cls;
580 }); 586 });
581 } 587 }
582 588
583 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { 589 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
584 return _typeVariableMap.putIfAbsent(node, () { 590 return _typeVariableMap.putIfAbsent(node, () {
585 if (node.parent is ir.Class) { 591 if (node.parent is ir.Class) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ResolutionImpact computeWorldImpact(KMember member) { 947 ResolutionImpact computeWorldImpact(KMember member) {
942 return _memberData[member.memberIndex].getWorldImpact(this); 948 return _memberData[member.memberIndex].getWorldImpact(this);
943 } 949 }
944 950
945 /// Returns the kernel [ir.Procedure] node for the [method]. 951 /// Returns the kernel [ir.Procedure] node for the [method].
946 ir.Procedure _lookupProcedure(KFunction method) { 952 ir.Procedure _lookupProcedure(KFunction method) {
947 return _memberData[method.memberIndex].node; 953 return _memberData[method.memberIndex].node;
948 } 954 }
949 955
950 Iterable<ConstantValue> _getClassMetadata(KClass cls) { 956 Iterable<ConstantValue> _getClassMetadata(KClass cls) {
951 return _classEnvs[cls.classIndex].getMetadata(this); 957 return _classData[cls.classIndex].getMetadata(this);
952 } 958 }
953 } 959 }
954 960
955 /// Implementation of [KernelToElementMapForImpact] that only supports world 961 /// Implementation of [KernelToElementMapForImpact] that only supports world
956 /// impact computation. 962 /// impact computation.
957 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when 963 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when
958 // [JsStrategy] is the default. 964 // [JsStrategy] is the default.
959 class KernelToElementMapForImpactImpl2 extends KernelToElementMapBase 965 class KernelToElementMapForImpactImpl2 extends KernelToElementMapBase
960 with 966 with
961 KernelToElementMapForImpactMixin, 967 KernelToElementMapForImpactMixin,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 InterfaceType getRawType(ClassEntity cls) { 1080 InterfaceType getRawType(ClassEntity cls) {
1075 return elementMap._getRawType(cls); 1081 return elementMap._getRawType(cls);
1076 } 1082 }
1077 1083
1078 @override 1084 @override
1079 bool isGenericClass(ClassEntity cls) { 1085 bool isGenericClass(ClassEntity cls) {
1080 return getThisType(cls).typeArguments.isNotEmpty; 1086 return getThisType(cls).typeArguments.isNotEmpty;
1081 } 1087 }
1082 1088
1083 @override 1089 @override
1084 bool isMixinApplication(covariant KClass cls) { 1090 bool isMixinApplication(ClassEntity cls) {
1085 return elementMap._isMixinApplication(cls); 1091 return elementMap._isMixinApplication(cls);
1086 } 1092 }
1087 1093
1088 @override 1094 @override
1089 bool isUnnamedMixinApplication(covariant KClass cls) { 1095 bool isUnnamedMixinApplication(ClassEntity cls) {
1090 return elementMap._isUnnamedMixinApplication(cls); 1096 return elementMap._isUnnamedMixinApplication(cls);
1091 } 1097 }
1092 1098
1093 @override 1099 @override
1094 ClassEntity getEffectiveMixinClass(ClassEntity cls) { 1100 ClassEntity getEffectiveMixinClass(ClassEntity cls) {
1095 if (!isMixinApplication(cls)) return null; 1101 if (!isMixinApplication(cls)) return null;
1096 do { 1102 do {
1097 cls = elementMap._getAppliedMixin(cls); 1103 cls = elementMap._getAppliedMixin(cls);
1098 } while (isMixinApplication(cls)); 1104 } while (isMixinApplication(cls));
1099 return cls; 1105 return cls;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 {bool required: false}) { 1213 {bool required: false}) {
1208 ClassEntity cls = elementMap.lookupClass(library, name); 1214 ClassEntity cls = elementMap.lookupClass(library, name);
1209 if (cls == null && required) { 1215 if (cls == null && required) {
1210 throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE, 1216 throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE,
1211 "The class '$name' was not found in library '${library.name}'."); 1217 "The class '$name' was not found in library '${library.name}'.");
1212 } 1218 }
1213 return cls; 1219 return cls;
1214 } 1220 }
1215 1221
1216 @override 1222 @override
1217 void forEachClass(covariant KLibrary library, void f(ClassEntity cls)) { 1223 void forEachClass(LibraryEntity library, void f(ClassEntity cls)) {
1218 elementMap._forEachClass(library, f); 1224 elementMap._forEachClass(library, f);
1219 } 1225 }
1220 1226
1221 @override 1227 @override
1222 LibraryEntity lookupLibrary(Uri uri, {bool required: false}) { 1228 LibraryEntity lookupLibrary(Uri uri, {bool required: false}) {
1223 LibraryEntity library = elementMap.lookupLibrary(uri); 1229 LibraryEntity library = elementMap.lookupLibrary(uri);
1224 if (library == null && required) { 1230 if (library == null && required) {
1225 throw new SpannableAssertionFailure( 1231 throw new SpannableAssertionFailure(
1226 CURRENT_ELEMENT_SPANNABLE, "The library '$uri' was not found."); 1232 CURRENT_ELEMENT_SPANNABLE, "The library '$uri' was not found.");
1227 } 1233 }
1228 return library; 1234 return library;
1229 } 1235 }
1230 1236
1231 @override 1237 @override
1232 bool isDeferredLoadLibraryGetter(covariant KMember member) { 1238 bool isDeferredLoadLibraryGetter(MemberEntity member) {
1233 // TODO(redemption): Support these. 1239 // TODO(redemption): Support these.
1234 return false; 1240 return false;
1235 } 1241 }
1236 1242
1237 @override 1243 @override
1238 Iterable<ConstantValue> getMemberMetadata(covariant KMember member) { 1244 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member) {
1239 MemberData memberData = elementMap._memberData[member.memberIndex]; 1245 MemberData memberData = elementMap._memberData[member.memberIndex];
1240 return memberData.getMetadata(elementMap); 1246 return memberData.getMetadata(elementMap);
1241 } 1247 }
1242 } 1248 }
1243 1249
1244 /// Visitor that converts kernel dart types into [DartType]. 1250 /// Visitor that converts kernel dart types into [DartType].
1245 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { 1251 class DartTypeConverter extends ir.DartTypeVisitor<DartType> {
1246 final KernelToElementMapBase elementMap; 1252 final KernelToElementMapBase elementMap;
1247 bool topLevel = true; 1253 bool topLevel = true;
1248 1254
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; 1711 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex];
1706 LibraryEntity newLibrary = convertLibrary(oldLibrary); 1712 LibraryEntity newLibrary = convertLibrary(oldLibrary);
1707 _libraryMap[env.library] = newLibrary; 1713 _libraryMap[env.library] = newLibrary;
1708 _libraryList.add(newLibrary); 1714 _libraryList.add(newLibrary);
1709 _libraryEnvs.add(env); 1715 _libraryEnvs.add(env);
1710 } 1716 }
1711 for (int classIndex = 0; 1717 for (int classIndex = 0;
1712 classIndex < _elementMap._classEnvs.length; 1718 classIndex < _elementMap._classEnvs.length;
1713 classIndex++) { 1719 classIndex++) {
1714 ClassEnv env = _elementMap._classEnvs[classIndex]; 1720 ClassEnv env = _elementMap._classEnvs[classIndex];
1721 ClassData data = _elementMap._classData[classIndex];
1715 ClassEntity oldClass = _elementMap._classList[classIndex]; 1722 ClassEntity oldClass = _elementMap._classList[classIndex];
1716 IndexedLibrary oldLibrary = oldClass.library; 1723 IndexedLibrary oldLibrary = oldClass.library;
1717 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; 1724 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex];
1718 ClassEntity newClass = convertClass(newLibrary, oldClass); 1725 ClassEntity newClass = convertClass(newLibrary, oldClass);
1719 _classMap[env.cls] = newClass; 1726 _classMap[env.cls] = newClass;
1720 _classList.add(newClass); 1727 _classList.add(newClass);
1721 _classEnvs.add(env); 1728 _classEnvs.add(env);
1729 _classData.add(data.copy());
1722 } 1730 }
1723 for (int memberIndex = 0; 1731 for (int memberIndex = 0;
1724 memberIndex < _elementMap._memberData.length; 1732 memberIndex < _elementMap._memberData.length;
1725 memberIndex++) { 1733 memberIndex++) {
1726 MemberData data = _elementMap._memberData[memberIndex]; 1734 MemberData data = _elementMap._memberData[memberIndex];
1727 MemberEntity oldMember = _elementMap._memberList[memberIndex]; 1735 MemberEntity oldMember = _elementMap._memberList[memberIndex];
1728 IndexedLibrary oldLibrary = oldMember.library; 1736 IndexedLibrary oldLibrary = oldMember.library;
1729 IndexedClass oldClass = oldMember.enclosingClass; 1737 IndexedClass oldClass = oldMember.enclosingClass;
1730 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; 1738 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex];
1731 ClassEntity newClass = 1739 ClassEntity newClass =
1732 oldClass != null ? _classList[oldClass.classIndex] : null; 1740 oldClass != null ? _classList[oldClass.classIndex] : null;
1733 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember); 1741 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember);
1734 _memberList.add(newMember); 1742 _memberList.add(newMember);
1735 _memberData.add(data); 1743 _memberData.add(data.copy());
1736 if (newMember.isField) { 1744 if (newMember.isField) {
1737 _fieldMap[data.node] = newMember; 1745 _fieldMap[data.node] = newMember;
1738 } else if (newMember.isConstructor) { 1746 } else if (newMember.isConstructor) {
1739 _constructorMap[data.node] = newMember; 1747 _constructorMap[data.node] = newMember;
1740 } else { 1748 } else {
1741 _methodMap[data.node] = newMember; 1749 _methodMap[data.node] = newMember;
1742 } 1750 }
1743 } 1751 }
1744 } 1752 }
1745 1753
(...skipping 20 matching lines...) Expand all
1766 throw new UnsupportedError("JsKernelToElementMap.getLocalFunction"); 1774 throw new UnsupportedError("JsKernelToElementMap.getLocalFunction");
1767 } 1775 }
1768 1776
1769 @override 1777 @override
1770 ClassEntity _getClass(ir.Class node, [ClassEnv env]) { 1778 ClassEntity _getClass(ir.Class node, [ClassEnv env]) {
1771 ClassEntity cls = _classMap[node]; 1779 ClassEntity cls = _classMap[node];
1772 assert(cls != null, "No class entity for $node"); 1780 assert(cls != null, "No class entity for $node");
1773 return cls; 1781 return cls;
1774 } 1782 }
1775 1783
1776 @override
1777 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
1778 throw new UnsupportedError("JsKernelToElementMap._getTypeVariable");
1779 }
1780
1781 // TODO(johnniwinther): Reinsert these when [ElementCreatorMixin] is no longer 1784 // TODO(johnniwinther): Reinsert these when [ElementCreatorMixin] is no longer
1782 // mixed in. 1785 // mixed in.
1783 /*@override 1786 /*@override
1784 FieldEntity _getField(ir.Field node) { 1787 FieldEntity _getField(ir.Field node) {
1785 FieldEntity field = _fieldMap[node]; 1788 FieldEntity field = _fieldMap[node];
1786 assert(field != null, "No field entity for $node"); 1789 assert(field != null, "No field entity for $node");
1787 return field; 1790 return field;
1788 }*/ 1791 }*/
1789 1792
1790 /*@override 1793 /*@override
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 throw new UnsupportedError( 1830 throw new UnsupportedError(
1828 "JsKernelToElementMap.getConstantFieldInitializer"); 1831 "JsKernelToElementMap.getConstantFieldInitializer");
1829 } 1832 }
1830 1833
1831 @override 1834 @override
1832 bool hasConstantFieldInitializer(FieldEntity field) { 1835 bool hasConstantFieldInitializer(FieldEntity field) {
1833 throw new UnsupportedError( 1836 throw new UnsupportedError(
1834 "JsKernelToElementMap.hasConstantFieldInitializer"); 1837 "JsKernelToElementMap.hasConstantFieldInitializer");
1835 } 1838 }
1836 } 1839 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_model/elements.dart ('k') | pkg/compiler/lib/src/kernel/env.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698