| 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 '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart' show Element, Elements, FieldElement; | 9 import '../elements/elements.dart' show Entity, Elements; |
| 10 import '../elements/entities.dart' show FieldEntity; |
| 10 import '../js_backend/js_backend.dart' show SyntheticConstantKind; | 11 import '../js_backend/js_backend.dart' show SyntheticConstantKind; |
| 11 import '../tree/dartstring.dart' show DartString; | 12 import '../tree/dartstring.dart' show DartString; |
| 12 | 13 |
| 13 /// A canonical but arbrary ordering of constants. The ordering is 'stable' | 14 /// A canonical but arbrary ordering of constants. The ordering is 'stable' |
| 14 /// under perturbation of the source. | 15 /// under perturbation of the source. |
| 15 int deepCompareConstants(ConstantValue a, ConstantValue b) { | 16 int deepCompareConstants(ConstantValue a, ConstantValue b) { |
| 16 return _CompareVisitor.compareValues(a, b); | 17 return _CompareVisitor.compareValues(a, b); |
| 17 } | 18 } |
| 18 | 19 |
| 19 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { | 20 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 static int compareLists(int compare(a, b), List a, List b) { | 38 static int compareLists(int compare(a, b), List a, List b) { |
| 38 int r = a.length.compareTo(b.length); | 39 int r = a.length.compareTo(b.length); |
| 39 if (r != 0) return r; | 40 if (r != 0) return r; |
| 40 for (int i = 0; i < a.length; i++) { | 41 for (int i = 0; i < a.length; i++) { |
| 41 r = compare(a[i], b[i]); | 42 r = compare(a[i], b[i]); |
| 42 if (r != 0) return r; | 43 if (r != 0) return r; |
| 43 } | 44 } |
| 44 return 0; | 45 return 0; |
| 45 } | 46 } |
| 46 | 47 |
| 47 static int compareElements(Element a, Element b) { | 48 static int compareElements(Entity a, Entity b) { |
| 48 int r = a.name.compareTo(b.name); | 49 int r = a.name.compareTo(b.name); |
| 49 if (r != 0) return r; | 50 if (r != 0) return r; |
| 50 return Elements.compareByPosition(a, b); | 51 return Elements.compareByPosition(a, b); |
| 51 } | 52 } |
| 52 | 53 |
| 53 static int compareDartTypes(DartType a, DartType b) { | 54 static int compareDartTypes(DartType a, DartType b) { |
| 54 if (a == b) return 0; | 55 if (a == b) return 0; |
| 55 int r = a.kind.index.compareTo(b.kind.index); | 56 int r = a.kind.index.compareTo(b.kind.index); |
| 56 if (r != 0) return r; | 57 if (r != 0) return r; |
| 57 r = compareNullable(compareElements, a.element, b.element); | 58 r = compareNullable(compareElements, a.element, b.element); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (r != 0) return r; | 113 if (r != 0) return r; |
| 113 r = compareLists(compareValues, a.values, b.values); | 114 r = compareLists(compareValues, a.values, b.values); |
| 114 if (r != 0) return r; | 115 if (r != 0) return r; |
| 115 return compareDartTypes(a.type, b.type); | 116 return compareDartTypes(a.type, b.type); |
| 116 } | 117 } |
| 117 | 118 |
| 118 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { | 119 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { |
| 119 int r = compareDartTypes(a.type, b.type); | 120 int r = compareDartTypes(a.type, b.type); |
| 120 if (r != 0) return r; | 121 if (r != 0) return r; |
| 121 | 122 |
| 122 List<FieldElement> aFields = a.fields.keys.toList()..sort(compareElements); | 123 List<FieldEntity> aFields = a.fields.keys.toList()..sort(compareElements); |
| 123 List<FieldElement> bFields = b.fields.keys.toList()..sort(compareElements); | 124 List<FieldEntity> bFields = b.fields.keys.toList()..sort(compareElements); |
| 124 | 125 |
| 125 r = compareLists(compareElements, aFields, bFields); | 126 r = compareLists(compareElements, aFields, bFields); |
| 126 if (r != 0) return r; | 127 if (r != 0) return r; |
| 127 | 128 |
| 128 return compareLists( | 129 return compareLists( |
| 129 compareValues, | 130 compareValues, |
| 130 aFields.map((field) => a.fields[field]).toList(), | 131 aFields.map((field) => a.fields[field]).toList(), |
| 131 aFields.map((field) => b.fields[field]).toList()); | 132 aFields.map((field) => b.fields[field]).toList()); |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 int visitBool(BoolConstantValue a, _) => BOOL; | 206 int visitBool(BoolConstantValue a, _) => BOOL; |
| 206 int visitString(StringConstantValue a, _) => STRING; | 207 int visitString(StringConstantValue a, _) => STRING; |
| 207 int visitList(ListConstantValue a, _) => LIST; | 208 int visitList(ListConstantValue a, _) => LIST; |
| 208 int visitMap(MapConstantValue a, _) => MAP; | 209 int visitMap(MapConstantValue a, _) => MAP; |
| 209 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; | 210 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; |
| 210 int visitType(TypeConstantValue a, _) => TYPE; | 211 int visitType(TypeConstantValue a, _) => TYPE; |
| 211 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; | 212 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; |
| 212 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; | 213 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; |
| 213 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; | 214 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; |
| 214 } | 215 } |
| OLD | NEW |