| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.resolved_ast; | 5 library dart2js.serialization.resolved_ast; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart'; | 8 import '../common/resolution.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../elements/resolution_types.dart'; | 10 import '../elements/resolution_types.dart'; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 kind = AstKind.ENUM_INDEX_FIELD; | 114 kind = AstKind.ENUM_INDEX_FIELD; |
| 115 } else if (element.name == '_name') { | 115 } else if (element.name == '_name') { |
| 116 kind = AstKind.ENUM_NAME_FIELD; | 116 kind = AstKind.ENUM_NAME_FIELD; |
| 117 } else if (element.name == 'values') { | 117 } else if (element.name == 'values') { |
| 118 kind = AstKind.ENUM_VALUES_FIELD; | 118 kind = AstKind.ENUM_VALUES_FIELD; |
| 119 } else if (element.name == 'toString') { | 119 } else if (element.name == 'toString') { |
| 120 kind = AstKind.ENUM_TO_STRING; | 120 kind = AstKind.ENUM_TO_STRING; |
| 121 } else if (element.isConstructor) { | 121 } else if (element.isConstructor) { |
| 122 kind = AstKind.ENUM_CONSTRUCTOR; | 122 kind = AstKind.ENUM_CONSTRUCTOR; |
| 123 } else { | 123 } else { |
| 124 assert(invariant(element, element.isConst, | 124 assert(element.isConst, |
| 125 message: "Unexpected enum member: $element")); | 125 failedAt(element, "Unexpected enum member: $element")); |
| 126 kind = AstKind.ENUM_CONSTANT; | 126 kind = AstKind.ENUM_CONSTANT; |
| 127 } | 127 } |
| 128 } else { | 128 } else { |
| 129 // [element] has a body that we'll need to re-parse. We store where to | 129 // [element] has a body that we'll need to re-parse. We store where to |
| 130 // start parsing from. | 130 // start parsing from. |
| 131 objectEncoder.setInt(Key.OFFSET, root.getBeginToken().charOffset); | 131 objectEncoder.setInt(Key.OFFSET, root.getBeginToken().charOffset); |
| 132 if (element.isFactoryConstructor) { | 132 if (element.isFactoryConstructor) { |
| 133 kind = AstKind.FACTORY; | 133 kind = AstKind.FACTORY; |
| 134 } else if (element.isField) { | 134 } else if (element.isField) { |
| 135 kind = AstKind.FIELD; | 135 kind = AstKind.FIELD; |
| 136 } else { | 136 } else { |
| 137 kind = AstKind.FUNCTION; | 137 kind = AstKind.FUNCTION; |
| 138 FunctionExpression functionExpression = root.asFunctionExpression(); | 138 FunctionExpression functionExpression = root.asFunctionExpression(); |
| 139 if (functionExpression.getOrSet != null) { | 139 if (functionExpression.getOrSet != null) { |
| 140 // Getters/setters need the get/set token to be parsed. | 140 // Getters/setters need the get/set token to be parsed. |
| 141 objectEncoder.setInt( | 141 objectEncoder.setInt( |
| 142 Key.GET_OR_SET, functionExpression.getOrSet.charOffset); | 142 Key.GET_OR_SET, functionExpression.getOrSet.charOffset); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 objectEncoder.setEnum(Key.SUB_KIND, kind); | 146 objectEncoder.setEnum(Key.SUB_KIND, kind); |
| 147 root.accept(indexComputer); | 147 root.accept(indexComputer); |
| 148 objectEncoder.setBool(Key.CONTAINS_TRY, elements.containsTryStatement); | 148 objectEncoder.setBool(Key.CONTAINS_TRY, elements.containsTryStatement); |
| 149 if (resolvedAst.body != null) { | 149 if (resolvedAst.body != null) { |
| 150 int index = nodeIndices[resolvedAst.body]; | 150 int index = nodeIndices[resolvedAst.body]; |
| 151 assert(invariant(element, index != null, | 151 assert( |
| 152 message: "No index for body of $element: " | 152 index != null, |
| 153 failedAt( |
| 154 element, |
| 155 "No index for body of $element: " |
| 153 "${resolvedAst.body} ($nodeIndices).")); | 156 "${resolvedAst.body} ($nodeIndices).")); |
| 154 objectEncoder.setInt(Key.BODY, index); | 157 objectEncoder.setInt(Key.BODY, index); |
| 155 } | 158 } |
| 156 root.accept(this); | 159 root.accept(this); |
| 157 if (jumpTargetMap.isNotEmpty) { | 160 if (jumpTargetMap.isNotEmpty) { |
| 158 ListEncoder list = objectEncoder.createList(Key.JUMP_TARGETS); | 161 ListEncoder list = objectEncoder.createList(Key.JUMP_TARGETS); |
| 159 for (JumpTarget jumpTarget in jumpTargetMap.keys) { | 162 for (JumpTarget jumpTarget in jumpTargetMap.keys) { |
| 160 serializeJumpTarget(jumpTarget, list.createObject()); | 163 serializeJumpTarget(jumpTarget, list.createObject()); |
| 161 } | 164 } |
| 162 } | 165 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 /// Computes the [ListEncoder] for serializing data for nodes. | 217 /// Computes the [ListEncoder] for serializing data for nodes. |
| 215 ListEncoder get nodeDataEncoder { | 218 ListEncoder get nodeDataEncoder { |
| 216 if (_nodeDataEncoder == null) { | 219 if (_nodeDataEncoder == null) { |
| 217 _nodeDataEncoder = objectEncoder.createList(Key.DATA); | 220 _nodeDataEncoder = objectEncoder.createList(Key.DATA); |
| 218 } | 221 } |
| 219 return _nodeDataEncoder; | 222 return _nodeDataEncoder; |
| 220 } | 223 } |
| 221 | 224 |
| 222 /// Computes the [ObjectEncoder] for serializing data for [node]. | 225 /// Computes the [ObjectEncoder] for serializing data for [node]. |
| 223 ObjectEncoder getNodeDataEncoder(Node node) { | 226 ObjectEncoder getNodeDataEncoder(Node node) { |
| 224 assert(invariant(element, node != null, message: "Node must be non-null.")); | 227 assert(node != null, failedAt(element, "Node must be non-null.")); |
| 225 int id = nodeIndices[node]; | 228 int id = nodeIndices[node]; |
| 226 assert(invariant(element, id != null, message: "Node without id: $node")); | 229 assert(id != null, failedAt(element, "Node without id: $node")); |
| 227 return nodeData.putIfAbsent(id, () { | 230 return nodeData.putIfAbsent(id, () { |
| 228 ObjectEncoder objectEncoder = nodeDataEncoder.createObject(); | 231 ObjectEncoder objectEncoder = nodeDataEncoder.createObject(); |
| 229 objectEncoder.setInt(Key.ID, id); | 232 objectEncoder.setInt(Key.ID, id); |
| 230 return objectEncoder; | 233 return objectEncoder; |
| 231 }); | 234 }); |
| 232 } | 235 } |
| 233 | 236 |
| 234 @override | 237 @override |
| 235 visitNode(Node node) { | 238 visitNode(Node node) { |
| 236 Element nodeElement = elements[node]; | 239 Element nodeElement = elements[node]; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 Node root = computeNode(kind); | 548 Node root = computeNode(kind); |
| 546 TreeElementMapping elements = new TreeElementMapping(element); | 549 TreeElementMapping elements = new TreeElementMapping(element); |
| 547 AstIndexComputer indexComputer = new AstIndexComputer(); | 550 AstIndexComputer indexComputer = new AstIndexComputer(); |
| 548 List<Node> nodeList = indexComputer.nodeList; | 551 List<Node> nodeList = indexComputer.nodeList; |
| 549 root.accept(indexComputer); | 552 root.accept(indexComputer); |
| 550 elements.containsTryStatement = objectDecoder.getBool(Key.CONTAINS_TRY); | 553 elements.containsTryStatement = objectDecoder.getBool(Key.CONTAINS_TRY); |
| 551 | 554 |
| 552 Node body; | 555 Node body; |
| 553 int bodyNodeIndex = objectDecoder.getInt(Key.BODY, isOptional: true); | 556 int bodyNodeIndex = objectDecoder.getInt(Key.BODY, isOptional: true); |
| 554 if (bodyNodeIndex != null) { | 557 if (bodyNodeIndex != null) { |
| 555 assert(invariant(element, bodyNodeIndex < nodeList.length, | 558 assert( |
| 556 message: "Body node index ${bodyNodeIndex} out of range. " | 559 bodyNodeIndex < nodeList.length, |
| 560 failedAt( |
| 561 element, |
| 562 "Body node index ${bodyNodeIndex} out of range. " |
| 557 "Node count: ${nodeList.length}")); | 563 "Node count: ${nodeList.length}")); |
| 558 body = nodeList[bodyNodeIndex]; | 564 body = nodeList[bodyNodeIndex]; |
| 559 } | 565 } |
| 560 | 566 |
| 561 List<JumpTarget> jumpTargets = <JumpTarget>[]; | 567 List<JumpTarget> jumpTargets = <JumpTarget>[]; |
| 562 Map<JumpTarget, List<int>> jumpTargetLabels = <JumpTarget, List<int>>{}; | 568 Map<JumpTarget, List<int>> jumpTargetLabels = <JumpTarget, List<int>>{}; |
| 563 List<LabelDefinition> labelDefinitions = <LabelDefinition>[]; | 569 List<LabelDefinition> labelDefinitions = <LabelDefinition>[]; |
| 564 | 570 |
| 565 ListDecoder jumpTargetsDecoder = | 571 ListDecoder jumpTargetsDecoder = |
| 566 objectDecoder.getList(Key.JUMP_TARGETS, isOptional: true); | 572 objectDecoder.getList(Key.JUMP_TARGETS, isOptional: true); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 705 } |
| 700 } | 706 } |
| 701 } | 707 } |
| 702 element.resolvedAst = | 708 element.resolvedAst = |
| 703 new ParsedResolvedAst(element, root, body, elements, uri); | 709 new ParsedResolvedAst(element, root, body, elements, uri); |
| 704 } | 710 } |
| 705 } | 711 } |
| 706 | 712 |
| 707 const Key PARAMETER_NODE = const Key('parameter.node'); | 713 const Key PARAMETER_NODE = const Key('parameter.node'); |
| 708 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer'); | 714 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer'); |
| OLD | NEW |