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 | 8 |
9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
10 import '../elements/elements.dart' | 10 import '../elements/elements.dart' show Element, Elements, FieldElement; |
11 show Element, | |
12 Elements, | |
13 FieldElement; | |
14 import '../tree/tree.dart' show DartString; | 11 import '../tree/tree.dart' show DartString; |
15 import '../js_backend/js_backend.dart' show SyntheticConstantKind; | 12 import '../js_backend/js_backend.dart' show SyntheticConstantKind; |
16 | 13 |
17 /// A canonical but arbrary ordering of constants. The ordering is 'stable' | 14 /// A canonical but arbrary ordering of constants. The ordering is 'stable' |
18 /// under perturbation of the source. | 15 /// under perturbation of the source. |
19 int deepCompareConstants(ConstantValue a, ConstantValue b) { | 16 int deepCompareConstants(ConstantValue a, ConstantValue b) { |
20 return _CompareVisitor.compareValues(a, b); | 17 return _CompareVisitor.compareValues(a, b); |
21 } | 18 } |
22 | 19 |
23 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { | 20 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 static int compareDartTypes(DartType a, DartType b) { | 54 static int compareDartTypes(DartType a, DartType b) { |
58 if (a == b) return 0; | 55 if (a == b) return 0; |
59 int r = a.kind.index.compareTo(b.kind.index); | 56 int r = a.kind.index.compareTo(b.kind.index); |
60 if (r != 0) return r; | 57 if (r != 0) return r; |
61 r = compareNullable(compareElements, a.element, b.element); | 58 r = compareNullable(compareElements, a.element, b.element); |
62 if (r != 0) return r; | 59 if (r != 0) return r; |
63 | 60 |
64 if (a is GenericType) { | 61 if (a is GenericType) { |
65 GenericType aGeneric = a; | 62 GenericType aGeneric = a; |
66 GenericType bGeneric = b; | 63 GenericType bGeneric = b; |
67 r = compareLists(compareDartTypes, | 64 r = compareLists( |
68 aGeneric.typeArguments, bGeneric.typeArguments); | 65 compareDartTypes, aGeneric.typeArguments, bGeneric.typeArguments); |
69 if (r != 0) return r; | 66 if (r != 0) return r; |
70 } | 67 } |
71 throw 'unexpected compareDartTypes $a $b'; | 68 throw 'unexpected compareDartTypes $a $b'; |
72 } | 69 } |
73 | 70 |
74 int visitFunction(FunctionConstantValue a, FunctionConstantValue b) { | 71 int visitFunction(FunctionConstantValue a, FunctionConstantValue b) { |
75 return compareElements(a.element, b.element); | 72 return compareElements(a.element, b.element); |
76 } | 73 } |
77 | 74 |
78 int visitNull(NullConstantValue a, NullConstantValue b) { | 75 int visitNull(NullConstantValue a, NullConstantValue b) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { | 115 int visitConstructed(ConstructedConstantValue a, ConstructedConstantValue b) { |
119 int r = compareDartTypes(a.type, b.type); | 116 int r = compareDartTypes(a.type, b.type); |
120 if (r != 0) return r; | 117 if (r != 0) return r; |
121 | 118 |
122 List<FieldElement> aFields = a.fields.keys.toList()..sort(compareElements); | 119 List<FieldElement> aFields = a.fields.keys.toList()..sort(compareElements); |
123 List<FieldElement> bFields = b.fields.keys.toList()..sort(compareElements); | 120 List<FieldElement> bFields = b.fields.keys.toList()..sort(compareElements); |
124 | 121 |
125 r = compareLists(compareElements, aFields, bFields); | 122 r = compareLists(compareElements, aFields, bFields); |
126 if (r != 0) return r; | 123 if (r != 0) return r; |
127 | 124 |
128 return compareLists(compareValues, | 125 return compareLists( |
| 126 compareValues, |
129 aFields.map((field) => a.fields[field]).toList(), | 127 aFields.map((field) => a.fields[field]).toList(), |
130 aFields.map((field) => b.fields[field]).toList()); | 128 aFields.map((field) => b.fields[field]).toList()); |
131 } | 129 } |
132 | 130 |
133 int visitType(TypeConstantValue a, TypeConstantValue b) { | 131 int visitType(TypeConstantValue a, TypeConstantValue b) { |
134 int r = compareDartTypes(a.representedType, b.representedType); | 132 int r = compareDartTypes(a.representedType, b.representedType); |
135 if (r != 0) return r; | 133 if (r != 0) return r; |
136 return compareDartTypes(a.type, b.type); | 134 return compareDartTypes(a.type, b.type); |
137 } | 135 } |
138 | 136 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 int visitBool(BoolConstantValue a, _) => BOOL; | 200 int visitBool(BoolConstantValue a, _) => BOOL; |
203 int visitString(StringConstantValue a, _) => STRING; | 201 int visitString(StringConstantValue a, _) => STRING; |
204 int visitList(ListConstantValue a, _) => LIST; | 202 int visitList(ListConstantValue a, _) => LIST; |
205 int visitMap(MapConstantValue a, _) => MAP; | 203 int visitMap(MapConstantValue a, _) => MAP; |
206 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; | 204 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; |
207 int visitType(TypeConstantValue a, _) => TYPE; | 205 int visitType(TypeConstantValue a, _) => TYPE; |
208 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; | 206 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; |
209 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; | 207 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; |
210 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; | 208 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; |
211 } | 209 } |
OLD | NEW |