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 '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 LibraryEntity toBackendLibrary(LibraryEntity library) { | 52 LibraryEntity toBackendLibrary(LibraryEntity library) { |
53 return _toBackendLibrary.putIfAbsent(library, () { | 53 return _toBackendLibrary.putIfAbsent(library, () { |
54 JLibrary newLibrary = new JLibrary( | 54 JLibrary newLibrary = new JLibrary( |
55 _toBackendLibrary.length, library.name, library.canonicalUri); | 55 _toBackendLibrary.length, library.name, library.canonicalUri); |
56 _frontendLibraryList.add(library); | 56 _frontendLibraryList.add(library); |
57 return newLibrary; | 57 return newLibrary; |
58 }); | 58 }); |
59 } | 59 } |
60 | 60 |
61 LibraryEntity toFrontendLibrary(JLibrary library) => | 61 LibraryEntity toFrontendLibrary(covariant JLibrary library) => |
62 _frontendLibraryList[library.libraryIndex]; | 62 _frontendLibraryList[library.libraryIndex]; |
63 | 63 |
64 final Map<ClassEntity, ClassEntity> _toBackendClass = | 64 final Map<ClassEntity, ClassEntity> _toBackendClass = |
65 <ClassEntity, ClassEntity>{}; | 65 <ClassEntity, ClassEntity>{}; |
66 final List<ClassEntity> _frontendClassList = <ClassEntity>[]; | 66 final List<ClassEntity> _frontendClassList = <ClassEntity>[]; |
67 | 67 |
68 ClassEntity toBackendClass(ClassEntity cls) { | 68 ClassEntity toBackendClass(ClassEntity cls) { |
69 return _toBackendClass.putIfAbsent(cls, () { | 69 return _toBackendClass.putIfAbsent(cls, () { |
70 LibraryEntity library = toBackendLibrary(cls.library); | 70 LibraryEntity library = toBackendLibrary(cls.library); |
71 JClass newClass = new JClass(library, _toBackendClass.length, cls.name, | 71 JClass newClass = new JClass(library, _toBackendClass.length, cls.name, |
72 isAbstract: cls.isAbstract); | 72 isAbstract: cls.isAbstract); |
73 _frontendClassList.add(cls); | 73 _frontendClassList.add(cls); |
74 return newClass; | 74 return newClass; |
75 }); | 75 }); |
76 } | 76 } |
77 | 77 |
78 ClassEntity toFrontendClass(JClass cls) => _frontendClassList[cls.classIndex]; | 78 ClassEntity toFrontendClass(covariant JClass cls) => |
| 79 _frontendClassList[cls.classIndex]; |
79 | 80 |
80 final Map<MemberEntity, MemberEntity> _toBackendMember = | 81 final Map<MemberEntity, MemberEntity> _toBackendMember = |
81 <MemberEntity, MemberEntity>{}; | 82 <MemberEntity, MemberEntity>{}; |
82 final List<MemberEntity> _frontendMemberList = <MemberEntity>[]; | 83 final List<MemberEntity> _frontendMemberList = <MemberEntity>[]; |
83 | 84 |
84 MemberEntity toBackendMember(MemberEntity member) { | 85 MemberEntity toBackendMember(MemberEntity member) { |
85 return _toBackendMember.putIfAbsent(member, () { | 86 return _toBackendMember.putIfAbsent(member, () { |
86 LibraryEntity library = toBackendLibrary(member.library); | 87 LibraryEntity library = toBackendLibrary(member.library); |
87 ClassEntity cls; | 88 ClassEntity cls; |
88 if (member.enclosingClass != null) { | 89 if (member.enclosingClass != null) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 memberName, function.parameterStructure, function.asyncMarker, | 135 memberName, function.parameterStructure, function.asyncMarker, |
135 isStatic: function.isStatic, | 136 isStatic: function.isStatic, |
136 isExternal: function.isExternal, | 137 isExternal: function.isExternal, |
137 isAbstract: function.isAbstract); | 138 isAbstract: function.isAbstract); |
138 } | 139 } |
139 _frontendMemberList.add(member); | 140 _frontendMemberList.add(member); |
140 return newMember; | 141 return newMember; |
141 }); | 142 }); |
142 } | 143 } |
143 | 144 |
144 MemberEntity toFrontendMember(JMember member) => | 145 MemberEntity toFrontendMember(covariant JMember member) => |
145 _frontendMemberList[member.memberIndex]; | 146 _frontendMemberList[member.memberIndex]; |
146 | 147 |
147 DartType toBackendType(DartType type) => | 148 DartType toBackendType(DartType type) => |
148 const TypeConverter().visit(type, _toBackendEntity); | 149 const TypeConverter().visit(type, _toBackendEntity); |
149 DartType toFrontendType(DartType type) => | 150 DartType toFrontendType(DartType type) => |
150 const TypeConverter().visit(type, _toFrontendEntity); | 151 const TypeConverter().visit(type, _toFrontendEntity); |
151 | 152 |
152 Entity _toBackendEntity(Entity entity) { | 153 Entity _toBackendEntity(Entity entity) { |
153 if (entity is ClassEntity) return toBackendClass(entity); | 154 if (entity is ClassEntity) return toBackendClass(entity); |
154 assert(entity is TypeVariableEntity); | 155 assert(entity is TypeVariableEntity); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 .isFunctionUsedByBackend(_map.toFrontendMember(element)); | 683 .isFunctionUsedByBackend(_map.toFrontendMember(element)); |
683 } | 684 } |
684 | 685 |
685 @override | 686 @override |
686 bool isFieldUsedByBackend(FieldEntity element) { | 687 bool isFieldUsedByBackend(FieldEntity element) { |
687 return _backendUsage.isFieldUsedByBackend(_map.toFrontendMember(element)); | 688 return _backendUsage.isFieldUsedByBackend(_map.toFrontendMember(element)); |
688 } | 689 } |
689 | 690 |
690 @override | 691 @override |
691 Iterable<FunctionEntity> get globalFunctionDependencies { | 692 Iterable<FunctionEntity> get globalFunctionDependencies { |
692 return _backendUsage.globalFunctionDependencies | 693 FunctionEntity f(FunctionEntity e) => _map.toBackendMember(e); |
693 .map((FunctionEntity e) => _map.toBackendMember(e)); | 694 return _backendUsage.globalFunctionDependencies.map(f); |
694 } | 695 } |
695 | 696 |
696 @override | 697 @override |
697 Iterable<ClassEntity> get globalClassDependencies { | 698 Iterable<ClassEntity> get globalClassDependencies { |
698 return _backendUsage.globalClassDependencies.map(_map.toBackendClass); | 699 return _backendUsage.globalClassDependencies.map(_map.toBackendClass); |
699 } | 700 } |
700 | 701 |
701 @override | 702 @override |
702 bool get requiresPreamble => _backendUsage.requiresPreamble; | 703 bool get requiresPreamble => _backendUsage.requiresPreamble; |
703 | 704 |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 @override | 1856 @override |
1856 ClassEntity get numClass => _map.toBackendClass(_commonElements.numClass); | 1857 ClassEntity get numClass => _map.toBackendClass(_commonElements.numClass); |
1857 | 1858 |
1858 @override | 1859 @override |
1859 ClassEntity get boolClass => _map.toBackendClass(_commonElements.boolClass); | 1860 ClassEntity get boolClass => _map.toBackendClass(_commonElements.boolClass); |
1860 | 1861 |
1861 @override | 1862 @override |
1862 FunctionEntity get throwUnsupportedError => | 1863 FunctionEntity get throwUnsupportedError => |
1863 _map.toBackendMember(_commonElements.throwUnsupportedError); | 1864 _map.toBackendMember(_commonElements.throwUnsupportedError); |
1864 } | 1865 } |
OLD | NEW |