Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_emitter.constant_ordering; | 5 library dart2js.js_emitter.constant_ordering; |
| 6 | 6 |
| 7 import '../constants/values.dart'; | 7 import '../constants/values.dart'; |
| 8 import '../elements/elements.dart' show Entity, Elements; | 8 import '../elements/elements.dart' show Entity, Elements; |
| 9 import '../elements/entities.dart' show FieldEntity; | 9 import '../elements/entities.dart' show FieldEntity; |
| 10 import '../elements/resolution_types.dart'; | 10 import '../elements/resolution_types.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 } | 44 } |
| 45 return 0; | 45 return 0; |
| 46 } | 46 } |
| 47 | 47 |
| 48 static int compareElements(Entity a, Entity b) { | 48 static int compareElements(Entity a, Entity b) { |
| 49 int r = a.name.compareTo(b.name); | 49 int r = a.name.compareTo(b.name); |
| 50 if (r != 0) return r; | 50 if (r != 0) return r; |
| 51 return Elements.compareByPosition(a, b); | 51 return Elements.compareByPosition(a, b); |
| 52 } | 52 } |
| 53 | 53 |
| 54 static int compareDartTypes(ResolutionDartType a, ResolutionDartType b) { | 54 static int compareDartTypes(ResolutionDartType a, ResolutionDartType b) { |
|
Siggi Cherem (dart-lang)
2017/01/11 22:57:47
this looks like a nice candidate to do next :)
Johnni Winther
2017/01/12 11:17:45
Acknowledged.
| |
| 55 if (a == b) return 0; | 55 if (a == b) return 0; |
| 56 int r = a.kind.index.compareTo(b.kind.index); | 56 int r = a.kind.index.compareTo(b.kind.index); |
| 57 if (r != 0) return r; | 57 if (r != 0) return r; |
| 58 r = compareNullable(compareElements, a.element, b.element); | 58 r = compareNullable(compareElements, a.element, b.element); |
| 59 if (r != 0) return r; | 59 if (r != 0) return r; |
| 60 | 60 |
| 61 if (a is GenericType) { | 61 if (a is GenericType) { |
| 62 GenericType aGeneric = a; | 62 GenericType aGeneric = a; |
| 63 GenericType bGeneric = b; | 63 GenericType bGeneric = b; |
| 64 r = compareLists( | 64 r = compareLists( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 DartString aString = a.primitiveValue; | 98 DartString aString = a.primitiveValue; |
| 99 DartString bString = b.primitiveValue; | 99 DartString bString = b.primitiveValue; |
| 100 int r = aString.length.compareTo(bString.length); | 100 int r = aString.length.compareTo(bString.length); |
| 101 if (r != 0) return r; | 101 if (r != 0) return r; |
| 102 return aString.slowToString().compareTo(bString.slowToString()); | 102 return aString.slowToString().compareTo(bString.slowToString()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 int visitList(ListConstantValue a, ListConstantValue b) { | 105 int visitList(ListConstantValue a, ListConstantValue b) { |
| 106 int r = compareLists(compareValues, a.entries, b.entries); | 106 int r = compareLists(compareValues, a.entries, b.entries); |
| 107 if (r != 0) return r; | 107 if (r != 0) return r; |
| 108 return compareDartTypes(a.type, b.type); | 108 ResolutionInterfaceType type1 = a.type; |
| 109 ResolutionInterfaceType type2 = b.type; | |
| 110 return compareDartTypes(type1, type2); | |
| 109 } | 111 } |
| 110 | 112 |
| 111 int visitMap(MapConstantValue a, MapConstantValue b) { | 113 int visitMap(MapConstantValue a, MapConstantValue b) { |
| 112 int r = compareLists(compareValues, a.keys, b.keys); | 114 int r = compareLists(compareValues, a.keys, b.keys); |
| 113 if (r != 0) return r; | 115 if (r != 0) return r; |
| 114 r = compareLists(compareValues, a.values, b.values); | 116 r = compareLists(compareValues, a.values, b.values); |
| 115 if (r != 0) return r; | 117 if (r != 0) return r; |
| 116 return compareDartTypes(a.type, b.type); | 118 ResolutionInterfaceType type1 = a.type; |
| 119 ResolutionInterfaceType type2 = b.type; | |
| 120 return compareDartTypes(type1, type2); | |
| 117 } | 121 } |
| 118 | 122 |
| 119 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { | 123 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { |
| 120 int r = compareDartTypes(a.type, b.type); | 124 ResolutionInterfaceType type1 = a.type; |
| 125 ResolutionInterfaceType type2 = b.type; | |
| 126 int r = compareDartTypes(type1, type2); | |
| 121 if (r != 0) return r; | 127 if (r != 0) return r; |
| 122 | 128 |
| 123 List<FieldEntity> aFields = a.fields.keys.toList()..sort(compareElements); | 129 List<FieldEntity> aFields = a.fields.keys.toList()..sort(compareElements); |
| 124 List<FieldEntity> bFields = b.fields.keys.toList()..sort(compareElements); | 130 List<FieldEntity> bFields = b.fields.keys.toList()..sort(compareElements); |
| 125 | 131 |
| 126 r = compareLists(compareElements, aFields, bFields); | 132 r = compareLists(compareElements, aFields, bFields); |
| 127 if (r != 0) return r; | 133 if (r != 0) return r; |
| 128 | 134 |
| 129 return compareLists( | 135 return compareLists( |
| 130 compareValues, | 136 compareValues, |
| 131 aFields.map((field) => a.fields[field]).toList(), | 137 aFields.map((field) => a.fields[field]).toList(), |
| 132 aFields.map((field) => b.fields[field]).toList()); | 138 aFields.map((field) => b.fields[field]).toList()); |
| 133 } | 139 } |
| 134 | 140 |
| 135 int visitType(TypeConstantValue a, TypeConstantValue b) { | 141 int visitType(TypeConstantValue a, TypeConstantValue b) { |
| 136 int r = compareDartTypes(a.representedType, b.representedType); | 142 int r = compareDartTypes(a.representedType, b.representedType); |
| 137 if (r != 0) return r; | 143 if (r != 0) return r; |
| 138 return compareDartTypes(a.type, b.type); | 144 ResolutionInterfaceType type1 = a.type; |
| 145 ResolutionInterfaceType type2 = b.type; | |
| 146 return compareDartTypes(type1, type2); | |
| 139 } | 147 } |
| 140 | 148 |
| 141 int visitInterceptor(InterceptorConstantValue a, InterceptorConstantValue b) { | 149 int visitInterceptor(InterceptorConstantValue a, InterceptorConstantValue b) { |
| 142 return compareDartTypes(a.dispatchedType, b.dispatchedType); | 150 return compareElements(a.cls, b.cls); |
| 143 } | 151 } |
| 144 | 152 |
| 145 int visitSynthetic(SyntheticConstantValue a, SyntheticConstantValue b) { | 153 int visitSynthetic(SyntheticConstantValue a, SyntheticConstantValue b) { |
| 146 // [SyntheticConstantValue]s have abstract fields that are set only by | 154 // [SyntheticConstantValue]s have abstract fields that are set only by |
| 147 // convention. Lucky for us, they do not occur as top level constant, only | 155 // convention. Lucky for us, they do not occur as top level constant, only |
| 148 // as elements of a few constants. If this becomes a source of instability, | 156 // as elements of a few constants. If this becomes a source of instability, |
| 149 // we will need to add a total ordering on JavaScript ASTs including | 157 // we will need to add a total ordering on JavaScript ASTs including |
| 150 // deferred elements. | 158 // deferred elements. |
| 151 SyntheticConstantKind aKind = a.valueKind; | 159 SyntheticConstantKind aKind = a.valueKind; |
| 152 SyntheticConstantKind bKind = b.valueKind; | 160 SyntheticConstantKind bKind = b.valueKind; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 int visitBool(BoolConstantValue a, _) => BOOL; | 214 int visitBool(BoolConstantValue a, _) => BOOL; |
| 207 int visitString(StringConstantValue a, _) => STRING; | 215 int visitString(StringConstantValue a, _) => STRING; |
| 208 int visitList(ListConstantValue a, _) => LIST; | 216 int visitList(ListConstantValue a, _) => LIST; |
| 209 int visitMap(MapConstantValue a, _) => MAP; | 217 int visitMap(MapConstantValue a, _) => MAP; |
| 210 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; | 218 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; |
| 211 int visitType(TypeConstantValue a, _) => TYPE; | 219 int visitType(TypeConstantValue a, _) => TYPE; |
| 212 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; | 220 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; |
| 213 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; | 221 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; |
| 214 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; | 222 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; |
| 215 } | 223 } |
| OLD | NEW |