Chromium Code Reviews| 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.dart'; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 if (r != 0) return r; | 226 if (r != 0) return r; |
| 227 MemberDefinition definition1 = elementMap.getMemberDefinition(member1); | 227 MemberDefinition definition1 = elementMap.getMemberDefinition(member1); |
| 228 MemberDefinition definition2 = elementMap.getMemberDefinition(member2); | 228 MemberDefinition definition2 = elementMap.getMemberDefinition(member2); |
| 229 return _compareSourceSpans( | 229 return _compareSourceSpans( |
| 230 member1, definition1.location, member2, definition2.location); | 230 member1, definition1.location, member2, definition2.location); |
| 231 }); | 231 }); |
| 232 } | 232 } |
| 233 | 233 |
| 234 @override | 234 @override |
| 235 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 235 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
| 236 return classes.toList() | 236 int compareClasses(ClassEntity cls1, ClassEntity cls2) { |
| 237 ..sort((ClassEntity cls1, ClassEntity cls2) { | 237 int r = _compareLibraries(cls1.library, cls2.library); |
| 238 int r = _compareLibraries(cls1.library, cls2.library); | 238 if (r != 0) return r; |
| 239 if (r != 0) return r; | 239 ClassDefinition definition1 = elementMap.getClassDefinition(cls1); |
| 240 ClassDefinition definition1 = elementMap.getClassDefinition(cls1); | 240 ClassDefinition definition2 = elementMap.getClassDefinition(cls2); |
| 241 ClassDefinition definition2 = elementMap.getClassDefinition(cls2); | 241 return _compareSourceSpans( |
| 242 return _compareSourceSpans( | 242 cls1, definition1.location, cls2, definition2.location); |
| 243 cls1, definition1.location, cls2, definition2.location); | 243 } |
| 244 | |
| 245 ClassEntity getMixin(ClassEntity cls) { | |
| 246 ClassEntity mixin; | |
| 247 elementMap.elementEnvironment.forEachMixin(cls, (ClassEntity c) { | |
|
Siggi Cherem (dart-lang)
2017/08/30 19:33:52
maybe it is worth having a method to just fetch th
| |
| 248 if (c != null) return; | |
|
Siggi Cherem (dart-lang)
2017/08/30 19:33:52
seems like c/mixin are swapped here and below:
| |
| 249 c = mixin; | |
| 244 }); | 250 }); |
| 251 return mixin; | |
| 252 } | |
| 253 | |
| 254 List<ClassEntity> regularClasses = <ClassEntity>[]; | |
| 255 List<ClassEntity> unnamedMixins = <ClassEntity>[]; | |
| 256 for (ClassEntity cls in classes) { | |
| 257 if (elementMap.elementEnvironment.isUnnamedMixinApplication(cls)) { | |
| 258 unnamedMixins.add(cls); | |
| 259 } else { | |
| 260 regularClasses.add(cls); | |
| 261 } | |
| 262 } | |
| 263 List<ClassEntity> sorted = <ClassEntity>[]; | |
| 264 regularClasses.sort(compareClasses); | |
| 265 sorted.addAll(regularClasses); | |
| 266 unnamedMixins.sort((a, b) { | |
| 267 int result = a.name.compareTo(b.name); | |
| 268 if (result != 0) return result; | |
| 269 return compareClasses(getMixin(a), getMixin(b)); | |
|
Siggi Cherem (dart-lang)
2017/08/30 19:33:52
should this be recursive instead?
e.g: compare A&
Johnni Winther
2017/09/01 15:17:45
Remove the need for this. If we sort first by libr
| |
| 270 }); | |
| 271 sorted.addAll(unnamedMixins); | |
| 272 return sorted; | |
| 245 } | 273 } |
| 246 | 274 |
| 247 @override | 275 @override |
| 248 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { | 276 Iterable<TypedefEntity> sortTypedefs(Iterable<TypedefEntity> typedefs) { |
| 249 // TODO(redemption): Support this. | 277 // TODO(redemption): Support this. |
| 250 assert(typedefs.isEmpty); | 278 assert(typedefs.isEmpty); |
| 251 return typedefs; | 279 return typedefs; |
| 252 } | 280 } |
| 253 } | 281 } |
| OLD | NEW |