| 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 /// Converters and codecs for converting between JSON and [Info] classes. | 5 /// Converters and codecs for converting between JSON and [Info] classes. |
| 6 part of dart2js_info.info; | 6 part of dart2js_info.info; |
| 7 | 7 |
| 8 // TODO(sigmund): add unit tests. | 8 // TODO(sigmund): add unit tests. |
| 9 class JsonToAllInfoConverter extends Converter<Map<String, dynamic>, AllInfo> { | 9 class JsonToAllInfoConverter extends Converter<Map<String, dynamic>, AllInfo> { |
| 10 Map<String, Info> registry; | 10 Map<String, Info> registry; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 ..code = json['code'] | 124 ..code = json['code'] |
| 125 ..isConst = json['const'] ?? false | 125 ..isConst = json['const'] ?? false |
| 126 ..initializer = parseId(json['initializer']) | 126 ..initializer = parseId(json['initializer']) |
| 127 ..closures = (json['children'] as List).map(parseId).toList(); | 127 ..closures = (json['children'] as List).map(parseId).toList(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 ConstantInfo parseConstant(Map json) { | 130 ConstantInfo parseConstant(Map json) { |
| 131 ConstantInfo result = parseId(json['id']); | 131 ConstantInfo result = parseId(json['id']); |
| 132 return result | 132 return result |
| 133 ..code = json['code'] | 133 ..code = json['code'] |
| 134 ..size = json['size']; | 134 ..size = json['size'] |
| 135 ..outputUnit = parseId(json['outputUnit']); |
| 135 } | 136 } |
| 136 | 137 |
| 137 TypedefInfo parseTypedef(Map json) { | 138 TypedefInfo parseTypedef(Map json) { |
| 138 TypedefInfo result = parseId(json['id']); | 139 TypedefInfo result = parseId(json['id']); |
| 139 return result | 140 return result |
| 140 ..name = json['name'] | 141 ..name = json['name'] |
| 141 ..parent = parseId(json['parent']) | 142 ..parent = parseId(json['parent']) |
| 142 ..type = json['type'] | 143 ..type = json['type'] |
| 143 ..size = 0; | 144 ..size = 0; |
| 144 } | 145 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 Map _visitDependencyInfo(DependencyInfo info) => | 254 Map _visitDependencyInfo(DependencyInfo info) => |
| 254 {'id': info.target.serializedId, 'mask': info.mask}; | 255 {'id': info.target.serializedId, 'mask': info.mask}; |
| 255 | 256 |
| 256 Map _visitAllInfoHolding(AllInfo allInfo) { | 257 Map _visitAllInfoHolding(AllInfo allInfo) { |
| 257 var map = <String, List>{}; | 258 var map = <String, List>{}; |
| 258 void helper(CodeInfo info) { | 259 void helper(CodeInfo info) { |
| 259 if (info.uses.isEmpty) return; | 260 if (info.uses.isEmpty) return; |
| 260 map[info.serializedId] = | 261 map[info.serializedId] = |
| 261 info.uses.map((u) => _visitDependencyInfo(u)).toList(); | 262 info.uses.map((u) => _visitDependencyInfo(u)).toList(); |
| 262 } | 263 } |
| 264 |
| 263 allInfo.functions.forEach(helper); | 265 allInfo.functions.forEach(helper); |
| 264 allInfo.fields.forEach(helper); | 266 allInfo.fields.forEach(helper); |
| 265 return map; | 267 return map; |
| 266 } | 268 } |
| 267 | 269 |
| 268 Map _visitAllInfoDependencies(AllInfo allInfo) { | 270 Map _visitAllInfoDependencies(AllInfo allInfo) { |
| 269 var map = <String, List>{}; | 271 var map = <String, List>{}; |
| 270 allInfo.dependencies.forEach((k, v) { | 272 allInfo.dependencies.forEach((k, v) { |
| 271 map[k.serializedId] = v.map((i) => i.serializedId).toList(); | 273 map[k.serializedId] = v.map((i) => i.serializedId).toList(); |
| 272 }); | 274 }); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 visitTypedef(TypedefInfo info) => _visitBasicInfo(info)..['type'] = info.type; | 428 visitTypedef(TypedefInfo info) => _visitBasicInfo(info)..['type'] = info.type; |
| 427 | 429 |
| 428 visitOutput(OutputUnitInfo info) => | 430 visitOutput(OutputUnitInfo info) => |
| 429 _visitBasicInfo(info)..['imports'] = info.imports; | 431 _visitBasicInfo(info)..['imports'] = info.imports; |
| 430 } | 432 } |
| 431 | 433 |
| 432 class AllInfoJsonCodec extends Codec<AllInfo, Map> { | 434 class AllInfoJsonCodec extends Codec<AllInfo, Map> { |
| 433 final Converter<AllInfo, Map> encoder = new AllInfoToJsonConverter(); | 435 final Converter<AllInfo, Map> encoder = new AllInfoToJsonConverter(); |
| 434 final Converter<Map, AllInfo> decoder = new JsonToAllInfoConverter(); | 436 final Converter<Map, AllInfo> decoder = new JsonToAllInfoConverter(); |
| 435 } | 437 } |
| OLD | NEW |