| 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 Elements; | 8 import '../elements/elements.dart' show Elements; |
| 9 import '../elements/entities.dart' show Entity, FieldEntity; | 9 import '../elements/entities.dart' show Entity, FieldEntity; |
| 10 import '../elements/resolution_types.dart'; | 10 import '../elements/resolution_types.dart'; |
| 11 import '../js_backend/js_backend.dart' show SyntheticConstantKind; | 11 import '../js_backend/js_backend.dart' show SyntheticConstantKind; |
| 12 import '../tree/dartstring.dart' show DartString; | |
| 13 | 12 |
| 14 /// A canonical but arbitrary ordering of constants. The ordering is 'stable' | 13 /// A canonical but arbitrary ordering of constants. The ordering is 'stable' |
| 15 /// under perturbation of the source. | 14 /// under perturbation of the source. |
| 16 int deepCompareConstants(ConstantValue a, ConstantValue b) { | 15 int deepCompareConstants(ConstantValue a, ConstantValue b) { |
| 17 return _CompareVisitor.compareValues(a, b); | 16 return _CompareVisitor.compareValues(a, b); |
| 18 } | 17 } |
| 19 | 18 |
| 20 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { | 19 class _CompareVisitor implements ConstantValueVisitor<int, ConstantValue> { |
| 21 const _CompareVisitor(); | 20 const _CompareVisitor(); |
| 22 | 21 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 return a.primitiveValue.compareTo(b.primitiveValue); | 87 return a.primitiveValue.compareTo(b.primitiveValue); |
| 89 } | 88 } |
| 90 | 89 |
| 91 int visitBool(BoolConstantValue a, BoolConstantValue b) { | 90 int visitBool(BoolConstantValue a, BoolConstantValue b) { |
| 92 int aInt = a.primitiveValue ? 1 : 0; | 91 int aInt = a.primitiveValue ? 1 : 0; |
| 93 int bInt = b.primitiveValue ? 1 : 0; | 92 int bInt = b.primitiveValue ? 1 : 0; |
| 94 return aInt.compareTo(bInt); | 93 return aInt.compareTo(bInt); |
| 95 } | 94 } |
| 96 | 95 |
| 97 int visitString(StringConstantValue a, StringConstantValue b) { | 96 int visitString(StringConstantValue a, StringConstantValue b) { |
| 98 DartString aString = a.primitiveValue; | 97 String aString = a.primitiveValue; |
| 99 DartString bString = b.primitiveValue; | 98 String bString = b.primitiveValue; |
| 100 int r = aString.length.compareTo(bString.length); | 99 return aString.compareTo(bString); |
| 101 if (r != 0) return r; | |
| 102 return aString.slowToString().compareTo(bString.slowToString()); | |
| 103 } | 100 } |
| 104 | 101 |
| 105 int visitList(ListConstantValue a, ListConstantValue b) { | 102 int visitList(ListConstantValue a, ListConstantValue b) { |
| 106 int r = compareLists(compareValues, a.entries, b.entries); | 103 int r = compareLists(compareValues, a.entries, b.entries); |
| 107 if (r != 0) return r; | 104 if (r != 0) return r; |
| 108 ResolutionInterfaceType type1 = a.type; | 105 ResolutionInterfaceType type1 = a.type; |
| 109 ResolutionInterfaceType type2 = b.type; | 106 ResolutionInterfaceType type2 = b.type; |
| 110 return compareDartTypes(type1, type2); | 107 return compareDartTypes(type1, type2); |
| 111 } | 108 } |
| 112 | 109 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 int visitBool(BoolConstantValue a, _) => BOOL; | 211 int visitBool(BoolConstantValue a, _) => BOOL; |
| 215 int visitString(StringConstantValue a, _) => STRING; | 212 int visitString(StringConstantValue a, _) => STRING; |
| 216 int visitList(ListConstantValue a, _) => LIST; | 213 int visitList(ListConstantValue a, _) => LIST; |
| 217 int visitMap(MapConstantValue a, _) => MAP; | 214 int visitMap(MapConstantValue a, _) => MAP; |
| 218 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; | 215 int visitConstructed(ConstructedConstantValue a, _) => CONSTRUCTED; |
| 219 int visitType(TypeConstantValue a, _) => TYPE; | 216 int visitType(TypeConstantValue a, _) => TYPE; |
| 220 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; | 217 int visitInterceptor(InterceptorConstantValue a, _) => INTERCEPTOR; |
| 221 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; | 218 int visitSynthetic(SyntheticConstantValue a, _) => SYNTHETIC; |
| 222 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; | 219 int visitDeferred(DeferredConstantValue a, _) => DEFERRED; |
| 223 } | 220 } |
| OLD | NEW |