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.dart'; |
10 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 11 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
11 import '../common/tasks.dart'; | 12 import '../common/tasks.dart'; |
12 import '../compiler.dart'; | 13 import '../compiler.dart'; |
13 import '../elements/entities.dart'; | 14 import '../elements/entities.dart'; |
14 import '../elements/entity_utils.dart' as utils; | 15 import '../elements/entity_utils.dart' as utils; |
15 import '../enqueue.dart'; | 16 import '../enqueue.dart'; |
16 import '../io/source_information.dart'; | 17 import '../io/source_information.dart'; |
17 import '../js_backend/backend.dart'; | 18 import '../js_backend/backend.dart'; |
18 import '../js_emitter/sorter.dart'; | 19 import '../js_emitter/sorter.dart'; |
19 import '../js_model/js_strategy.dart'; | 20 import '../js_model/js_strategy.dart'; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 197 |
197 class KernelSorter implements Sorter { | 198 class KernelSorter implements Sorter { |
198 final KernelToElementMapForBuilding elementMap; | 199 final KernelToElementMapForBuilding elementMap; |
199 | 200 |
200 KernelSorter(this.elementMap); | 201 KernelSorter(this.elementMap); |
201 | 202 |
202 int _compareLibraries(LibraryEntity a, LibraryEntity b) { | 203 int _compareLibraries(LibraryEntity a, LibraryEntity b) { |
203 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); | 204 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); |
204 } | 205 } |
205 | 206 |
206 int _compareLocations(Entity entity1, ir.Location location1, Entity entity2, | 207 int _compareSourceSpans(Entity entity1, SourceSpan sourceSpan1, |
207 ir.Location location2) { | 208 Entity entity2, SourceSpan sourceSpan2) { |
208 int r = utils.compareSourceUris( | 209 int r = utils.compareSourceUris(sourceSpan1.uri, sourceSpan2.uri); |
209 Uri.parse(location1.file), Uri.parse(location2.file)); | |
210 if (r != 0) return r; | 210 if (r != 0) return r; |
211 return utils.compareEntities(entity1, location1.line, location1.column, | 211 return utils.compareEntities( |
212 entity2, location2.line, location2.column); | 212 entity1, sourceSpan1.begin, null, entity2, sourceSpan2.begin, null); |
213 } | 213 } |
214 | 214 |
215 @override | 215 @override |
216 Iterable<LibraryEntity> sortLibraries(Iterable<LibraryEntity> libraries) { | 216 Iterable<LibraryEntity> sortLibraries(Iterable<LibraryEntity> libraries) { |
217 return libraries.toList()..sort(_compareLibraries); | 217 return libraries.toList()..sort(_compareLibraries); |
218 } | 218 } |
219 | 219 |
220 @override | 220 @override |
221 Iterable<MemberEntity> sortMembers(Iterable<MemberEntity> members) { | 221 Iterable<MemberEntity> sortMembers(Iterable<MemberEntity> members) { |
222 return members.toList() | 222 return members.toList() |
223 ..sort((MemberEntity member1, MemberEntity member2) { | 223 ..sort((MemberEntity member1, MemberEntity member2) { |
224 int r = _compareLibraries(member1.library, member2.library); | 224 int r = _compareLibraries(member1.library, member2.library); |
225 if (r != 0) return r; | 225 if (r != 0) return r; |
226 MemberDefinition definition1 = elementMap.getMemberDefinition(member1); | 226 MemberDefinition definition1 = elementMap.getMemberDefinition(member1); |
227 MemberDefinition definition2 = elementMap.getMemberDefinition(member2); | 227 MemberDefinition definition2 = elementMap.getMemberDefinition(member2); |
228 return _compareLocations( | 228 return _compareSourceSpans( |
229 member1, definition1.location, member2, definition2.location); | 229 member1, definition1.location, member2, definition2.location); |
230 }); | 230 }); |
231 } | 231 } |
232 | 232 |
233 @override | 233 @override |
234 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 234 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
235 return classes.toList() | 235 return classes.toList() |
236 ..sort((ClassEntity cls1, ClassEntity cls2) { | 236 ..sort((ClassEntity cls1, ClassEntity cls2) { |
237 int r = _compareLibraries(cls1.library, cls2.library); | 237 int r = _compareLibraries(cls1.library, cls2.library); |
238 if (r != 0) return r; | 238 if (r != 0) return r; |
239 ClassDefinition definition1 = elementMap.getClassDefinition(cls1); | 239 ClassDefinition definition1 = elementMap.getClassDefinition(cls1); |
240 ClassDefinition definition2 = elementMap.getClassDefinition(cls2); | 240 ClassDefinition definition2 = elementMap.getClassDefinition(cls2); |
241 return _compareLocations( | 241 return _compareSourceSpans( |
242 cls1, definition1.location, cls2, definition2.location); | 242 cls1, definition1.location, cls2, definition2.location); |
243 }); | 243 }); |
244 } | 244 } |
245 | 245 |
246 @override | 246 @override |
247 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { | 247 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { |
248 // TODO(redemption): Support this. | 248 // TODO(redemption): Support this. |
249 assert(typedefs.isEmpty); | 249 assert(typedefs.isEmpty); |
250 return typedefs; | 250 return typedefs; |
251 } | 251 } |
252 } | 252 } |
OLD | NEW |