| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.serialization; | 5 library dart2js.serialization; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner/precedence.dart' show |
| 8 PrecedenceInfo; |
| 9 |
| 7 import '../common.dart'; | 10 import '../common.dart'; |
| 8 import '../common/resolution.dart'; | 11 import '../common/resolution.dart'; |
| 9 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
| 10 import '../elements/resolution_types.dart'; | 13 import '../elements/resolution_types.dart'; |
| 11 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 12 import '../library_loader.dart' show LibraryProvider; | 15 import '../library_loader.dart' show LibraryProvider; |
| 13 import '../util/enumset.dart'; | 16 import '../util/enumset.dart'; |
| 14 import 'constant_serialization.dart'; | 17 import 'constant_serialization.dart'; |
| 15 import 'element_serialization.dart'; | 18 import 'element_serialization.dart'; |
| 16 import 'json_serializer.dart'; | 19 import 'json_serializer.dart'; |
| 17 import 'keys.dart'; | 20 import 'keys.dart'; |
| 18 import 'type_serialization.dart'; | 21 import 'type_serialization.dart'; |
| 19 import 'values.dart'; | 22 import 'values.dart'; |
| 20 | 23 |
| 21 export 'task.dart' show LibraryDeserializer; | 24 export 'task.dart' show LibraryDeserializer; |
| 22 | 25 |
| 26 final Map<String, String> canonicalNames = computeCanonicalNames(); |
| 27 |
| 28 Map<String, String> computeCanonicalNames() { |
| 29 Map<String, String> result = <String, String>{}; |
| 30 for (PrecedenceInfo info in PrecedenceInfo.all) { |
| 31 result[info.value] = info.value; |
| 32 } |
| 33 return result; |
| 34 } |
| 35 |
| 23 /// An object that supports the encoding an [ObjectValue] for serialization. | 36 /// An object that supports the encoding an [ObjectValue] for serialization. |
| 24 /// | 37 /// |
| 25 /// The [ObjectEncoder] ensures that nominality and circularities of | 38 /// The [ObjectEncoder] ensures that nominality and circularities of |
| 26 /// non-primitive values like [Element], [ResolutionDartType] and | 39 /// non-primitive values like [Element], [ResolutionDartType] and |
| 27 /// [ConstantExpression] are handled. | 40 /// [ConstantExpression] are handled. |
| 28 class ObjectEncoder extends AbstractEncoder<Key> { | 41 class ObjectEncoder extends AbstractEncoder<Key> { |
| 29 /// Creates an [ObjectEncoder] in the scope of [serializer] that uses [map] | 42 /// Creates an [ObjectEncoder] in the scope of [serializer] that uses [map] |
| 30 /// as its internal storage. | 43 /// as its internal storage. |
| 31 ObjectEncoder(Serializer serializer, Map<dynamic, Value> map) | 44 ObjectEncoder(Serializer serializer, Map<dynamic, Value> map) |
| 32 : super(serializer, map); | 45 : super(serializer, map); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 /// If no value is associated with [key], then if [isOptional] is `true`, | 477 /// If no value is associated with [key], then if [isOptional] is `true`, |
| 465 /// [defaultValue] is returned, otherwise an exception is thrown. | 478 /// [defaultValue] is returned, otherwise an exception is thrown. |
| 466 String getString(K key, {bool isOptional: false, String defaultValue}) { | 479 String getString(K key, {bool isOptional: false, String defaultValue}) { |
| 467 String value = _map[_getKeyValue(key)]; | 480 String value = _map[_getKeyValue(key)]; |
| 468 if (value == null) { | 481 if (value == null) { |
| 469 if (isOptional || defaultValue != null) { | 482 if (isOptional || defaultValue != null) { |
| 470 return defaultValue; | 483 return defaultValue; |
| 471 } | 484 } |
| 472 throw new StateError("String value '$key' not found in $_map."); | 485 throw new StateError("String value '$key' not found in $_map."); |
| 473 } | 486 } |
| 474 return value; | 487 return canonicalNames[value] ?? value; |
| 475 } | 488 } |
| 476 | 489 |
| 477 /// Returns the list of [String] values associated with [key] in the decoded | 490 /// Returns the list of [String] values associated with [key] in the decoded |
| 478 /// object. | 491 /// object. |
| 479 /// | 492 /// |
| 480 /// If no value is associated with [key], then if [isOptional] is `true`, | 493 /// If no value is associated with [key], then if [isOptional] is `true`, |
| 481 /// and empty [List] is returned, otherwise an exception is thrown. | 494 /// and empty [List] is returned, otherwise an exception is thrown. |
| 482 List<String> getStrings(K key, {bool isOptional: false}) { | 495 List<String> getStrings(K key, {bool isOptional: false}) { |
| 483 List list = _map[_getKeyValue(key)]; | 496 List list = _map[_getKeyValue(key)]; |
| 484 if (list == null) { | 497 if (list == null) { |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 | 1152 |
| 1140 /// Returns the value used to store [key] as a property in the encoding an | 1153 /// Returns the value used to store [key] as a property in the encoding an |
| 1141 /// [ObjectValue]. | 1154 /// [ObjectValue]. |
| 1142 /// | 1155 /// |
| 1143 /// Different encodings have different restrictions and capabilities as how | 1156 /// Different encodings have different restrictions and capabilities as how |
| 1144 /// to store a [Key] value. For instance: A JSON encoding needs to convert | 1157 /// to store a [Key] value. For instance: A JSON encoding needs to convert |
| 1145 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can | 1158 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can |
| 1146 /// choose to store a [Key] as an [int] or as the [Key] itself. | 1159 /// choose to store a [Key] as an [int] or as the [Key] itself. |
| 1147 getObjectPropertyValue(Key key); | 1160 getObjectPropertyValue(Key key); |
| 1148 } | 1161 } |
| OLD | NEW |