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.js_model.elements; | 5 library dart2js.js_model.elements; |
6 | 6 |
7 import '../common_elements.dart'; | 7 import '../common_elements.dart'; |
8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 Entity _toFrontendEntity(Entity entity) { | 56 Entity _toFrontendEntity(Entity entity) { |
57 if (entity is ClassEntity) return toFrontendClass(entity); | 57 if (entity is ClassEntity) return toFrontendClass(entity); |
58 assert(entity is TypeVariableEntity); | 58 assert(entity is TypeVariableEntity); |
59 TypeVariableEntity typeVariable = toFrontendTypeVariable(entity); | 59 TypeVariableEntity typeVariable = toFrontendTypeVariable(entity); |
60 assert(typeVariable != null, "No front end type variable for $entity"); | 60 assert(typeVariable != null, "No front end type variable for $entity"); |
61 return typeVariable; | 61 return typeVariable; |
62 } | 62 } |
63 | 63 |
64 final Map<TypeVariableEntity, TypeVariableEntity> _toBackendTypeVariableMap = | 64 TypeVariableEntity toBackendTypeVariable(TypeVariableEntity typeVariable); |
65 <TypeVariableEntity, TypeVariableEntity>{}; | 65 TypeVariableEntity toFrontendTypeVariable(TypeVariableEntity typeVariable); |
66 | |
67 final Map<TypeVariableEntity, TypeVariableEntity> _toFrontendTypeVariableMap = | |
68 <TypeVariableEntity, TypeVariableEntity>{}; | |
69 | |
70 TypeVariableEntity toBackendTypeVariable(TypeVariableEntity typeVariable) { | |
71 return _toBackendTypeVariableMap.putIfAbsent(typeVariable, () { | |
72 Entity typeDeclaration; | |
73 if (typeVariable.typeDeclaration is ClassEntity) { | |
74 typeDeclaration = toBackendClass(typeVariable.typeDeclaration); | |
75 } else { | |
76 typeDeclaration = toBackendMember(typeVariable.typeDeclaration); | |
77 } | |
78 TypeVariableEntity newTypeVariable = | |
79 createTypeVariable(typeDeclaration, typeVariable); | |
80 _toFrontendTypeVariableMap[newTypeVariable] = typeVariable; | |
81 return newTypeVariable; | |
82 }); | |
83 } | |
84 | |
85 TypeVariableEntity toFrontendTypeVariable(TypeVariableEntity typeVariable) { | |
86 return _toFrontendTypeVariableMap[typeVariable]; | |
87 } | |
88 | |
89 TypeVariableEntity createTypeVariable( | |
90 Entity typeDeclaration, TypeVariableEntity typeVariable) { | |
91 return new JTypeVariable( | |
92 typeDeclaration, typeVariable.name, typeVariable.index); | |
93 } | |
94 } | 66 } |
95 | 67 |
96 class JsElementCreatorMixin { | 68 class JsElementCreatorMixin { |
97 IndexedLibrary createLibrary( | 69 IndexedLibrary createLibrary( |
98 int libraryIndex, String name, Uri canonicalUri) { | 70 int libraryIndex, String name, Uri canonicalUri) { |
99 return new JLibrary(libraryIndex, name, canonicalUri); | 71 return new JLibrary(libraryIndex, name, canonicalUri); |
100 } | 72 } |
101 | 73 |
102 IndexedClass createClass(LibraryEntity library, int classIndex, String name, | 74 IndexedClass createClass(LibraryEntity library, int classIndex, String name, |
103 {bool isAbstract}) { | 75 {bool isAbstract}) { |
104 return new JClass(library, classIndex, name, isAbstract: isAbstract); | 76 return new JClass(library, classIndex, name, isAbstract: isAbstract); |
105 } | 77 } |
106 | 78 |
107 TypeVariableEntity createTypeVariable( | 79 TypeVariableEntity createTypeVariable( |
108 Entity typeDeclaration, String name, int index) { | 80 int typeVariableIndex, Entity typeDeclaration, String name, int index) { |
109 return new JTypeVariable(typeDeclaration, name, index); | 81 return new JTypeVariable(typeVariableIndex, typeDeclaration, name, index); |
110 } | 82 } |
111 | 83 |
112 IndexedConstructor createGenerativeConstructor( | 84 IndexedConstructor createGenerativeConstructor( |
113 int memberIndex, | 85 int memberIndex, |
114 ClassEntity enclosingClass, | 86 ClassEntity enclosingClass, |
115 Name name, | 87 Name name, |
116 ParameterStructure parameterStructure, | 88 ParameterStructure parameterStructure, |
117 {bool isExternal, | 89 {bool isExternal, |
118 bool isConst}) { | 90 bool isConst}) { |
119 return new JGenerativeConstructor( | 91 return new JGenerativeConstructor( |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 {bool isStatic, this.isAssignable, this.isConst}) | 472 {bool isStatic, this.isAssignable, this.isConst}) |
501 : super(memberIndex, library, enclosingClass, name, isStatic: isStatic); | 473 : super(memberIndex, library, enclosingClass, name, isStatic: isStatic); |
502 | 474 |
503 @override | 475 @override |
504 bool get isField => true; | 476 bool get isField => true; |
505 | 477 |
506 String get _kind => 'field'; | 478 String get _kind => 'field'; |
507 } | 479 } |
508 | 480 |
509 class JTypeVariable implements TypeVariableEntity, IndexedTypeVariable { | 481 class JTypeVariable implements TypeVariableEntity, IndexedTypeVariable { |
| 482 final int typeVariableIndex; |
510 final Entity typeDeclaration; | 483 final Entity typeDeclaration; |
511 final String name; | 484 final String name; |
512 final int index; | 485 final int index; |
513 | 486 |
514 JTypeVariable(this.typeDeclaration, this.name, this.index); | 487 JTypeVariable( |
| 488 this.typeVariableIndex, this.typeDeclaration, this.name, this.index); |
515 | 489 |
516 String toString() => | 490 String toString() => |
517 '${jsElementPrefix}type_variable(${typeDeclaration.name}.$name)'; | 491 '${jsElementPrefix}type_variable(${typeDeclaration.name}.$name)'; |
518 } | 492 } |
519 | 493 |
520 class JsClosedWorld extends ClosedWorldBase with KernelClosedWorldMixin { | 494 class JsClosedWorld extends ClosedWorldBase with KernelClosedWorldMixin { |
521 final JsKernelToElementMap elementMap; | 495 final JsKernelToElementMap elementMap; |
522 | 496 |
523 JsClosedWorld(this.elementMap, | 497 JsClosedWorld(this.elementMap, |
524 {ElementEnvironment elementEnvironment, | 498 {ElementEnvironment elementEnvironment, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 694 |
721 @override | 695 @override |
722 bool get isFunctionApplyUsed => _backendUsage.isFunctionApplyUsed; | 696 bool get isFunctionApplyUsed => _backendUsage.isFunctionApplyUsed; |
723 | 697 |
724 @override | 698 @override |
725 bool get isMirrorsUsed => _backendUsage.isMirrorsUsed; | 699 bool get isMirrorsUsed => _backendUsage.isMirrorsUsed; |
726 | 700 |
727 @override | 701 @override |
728 bool get isNoSuchMethodUsed => _backendUsage.isNoSuchMethodUsed; | 702 bool get isNoSuchMethodUsed => _backendUsage.isNoSuchMethodUsed; |
729 } | 703 } |
OLD | NEW |