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.backend_strategy; | 5 library dart2js.kernel.backend_strategy; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../backend_strategy.dart'; | 9 import '../backend_strategy.dart'; |
10 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 10 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 KernelSsaBuilder( | 88 KernelSsaBuilder( |
89 this.task, this._compiler, this._elementMap, this._globalLocalsMap); | 89 this.task, this._compiler, this._elementMap, this._globalLocalsMap); |
90 | 90 |
91 @override | 91 @override |
92 HGraph build(CodegenWorkItem work, ClosedWorld closedWorld) { | 92 HGraph build(CodegenWorkItem work, ClosedWorld closedWorld) { |
93 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(work.element); | 93 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(work.element); |
94 KernelSsaGraphBuilder builder = new KernelSsaGraphBuilder( | 94 KernelSsaGraphBuilder builder = new KernelSsaGraphBuilder( |
95 work.element, | 95 work.element, |
96 work.element.enclosingClass, | 96 work.element.enclosingClass, |
97 _elementMap.getMemberNode(work.element), | |
98 _compiler, | 97 _compiler, |
99 _elementMap, | 98 _elementMap, |
100 new KernelToTypeInferenceMapImpl(closedWorld), | 99 new KernelToTypeInferenceMapImpl(closedWorld), |
101 localsMap, | 100 localsMap, |
102 closedWorld, | 101 closedWorld, |
103 _compiler.codegenWorldBuilder, | 102 _compiler.codegenWorldBuilder, |
104 work.registry, | 103 work.registry, |
105 _compiler.backendStrategy.closureDataLookup, | 104 _compiler.backendStrategy.closureDataLookup, |
106 // TODO(redemption): Support these: | 105 // TODO(redemption): Support these: |
107 const SourceInformationBuilder(), | 106 const SourceInformationBuilder(), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 196 |
198 class KernelSorter implements Sorter { | 197 class KernelSorter implements Sorter { |
199 final KernelToElementMapForBuilding elementMap; | 198 final KernelToElementMapForBuilding elementMap; |
200 | 199 |
201 KernelSorter(this.elementMap); | 200 KernelSorter(this.elementMap); |
202 | 201 |
203 int _compareLibraries(LibraryEntity a, LibraryEntity b) { | 202 int _compareLibraries(LibraryEntity a, LibraryEntity b) { |
204 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); | 203 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); |
205 } | 204 } |
206 | 205 |
207 int _compareNodes( | 206 int _compareLocations(Entity entity1, ir.Location location1, Entity entity2, |
208 Entity entity1, ir.TreeNode node1, Entity entity2, ir.TreeNode node2) { | 207 ir.Location location2) { |
209 ir.Location location1 = node1.location; | |
210 ir.Location location2 = node2.location; | |
211 int r = utils.compareSourceUris( | 208 int r = utils.compareSourceUris( |
212 Uri.parse(location1.file), Uri.parse(location2.file)); | 209 Uri.parse(location1.file), Uri.parse(location2.file)); |
213 if (r != 0) return r; | 210 if (r != 0) return r; |
214 return utils.compareEntities(entity1, location1.line, location1.column, | 211 return utils.compareEntities(entity1, location1.line, location1.column, |
215 entity2, location2.line, location2.column); | 212 entity2, location2.line, location2.column); |
216 } | 213 } |
217 | 214 |
218 @override | 215 @override |
219 Iterable<LibraryEntity> sortLibraries(Iterable<LibraryEntity> libraries) { | 216 Iterable<LibraryEntity> sortLibraries(Iterable<LibraryEntity> libraries) { |
220 return libraries.toList()..sort(_compareLibraries); | 217 return libraries.toList()..sort(_compareLibraries); |
221 } | 218 } |
222 | 219 |
223 @override | 220 @override |
224 Iterable<MemberEntity> sortMembers(Iterable<MemberEntity> members) { | 221 Iterable<MemberEntity> sortMembers(Iterable<MemberEntity> members) { |
225 return members.toList() | 222 return members.toList() |
226 ..sort((MemberEntity a, MemberEntity b) { | 223 ..sort((MemberEntity member1, MemberEntity member2) { |
227 int r = _compareLibraries(a.library, b.library); | 224 int r = _compareLibraries(member1.library, member2.library); |
228 if (r != 0) return r; | 225 if (r != 0) return r; |
229 return _compareNodes( | 226 MemberDefinition definition1 = elementMap.getMemberDefinition(member1); |
230 a, elementMap.getMemberNode(a), b, elementMap.getMemberNode(b)); | 227 MemberDefinition definition2 = elementMap.getMemberDefinition(member2); |
| 228 return _compareLocations( |
| 229 member1, definition1.location, member2, definition2.location); |
231 }); | 230 }); |
232 } | 231 } |
233 | 232 |
234 @override | 233 @override |
235 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 234 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
236 return classes.toList() | 235 return classes.toList() |
237 ..sort((ClassEntity a, ClassEntity b) { | 236 ..sort((ClassEntity cls1, ClassEntity cls2) { |
238 int r = _compareLibraries(a.library, b.library); | 237 int r = _compareLibraries(cls1.library, cls2.library); |
239 if (r != 0) return r; | 238 if (r != 0) return r; |
240 return _compareNodes( | 239 ClassDefinition definition1 = elementMap.getClassDefinition(cls1); |
241 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); | 240 ClassDefinition definition2 = elementMap.getClassDefinition(cls2); |
| 241 return _compareLocations( |
| 242 cls1, definition1.location, cls2, definition2.location); |
242 }); | 243 }); |
243 } | 244 } |
244 | 245 |
245 @override | 246 @override |
246 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { | 247 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { |
247 // TODO(redemption): Support this. | 248 // TODO(redemption): Support this. |
248 assert(typedefs.isEmpty); | 249 assert(typedefs.isEmpty); |
249 return typedefs; | 250 return typedefs; |
250 } | 251 } |
251 } | 252 } |
OLD | NEW |