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 '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 /// Serialize [ResolvedAst] that is defined in terms of an AST together with | 104 /// Serialize [ResolvedAst] that is defined in terms of an AST together with |
105 /// [TreeElements]. | 105 /// [TreeElements]. |
106 void serializeParsed() { | 106 void serializeParsed() { |
107 objectEncoder.setUri( | 107 objectEncoder.setUri( |
108 Key.URI, | 108 Key.URI, |
109 elements.analyzedElement.compilationUnit.script.resourceUri, | 109 elements.analyzedElement.compilationUnit.script.resourceUri, |
110 elements.analyzedElement.compilationUnit.script.resourceUri); | 110 elements.analyzedElement.compilationUnit.script.resourceUri); |
| 111 if (resolvedAst.body != null) { |
| 112 objectEncoder.setInt(Key.BODY, nodeIndices[resolvedAst.body]); |
| 113 } |
111 AstKind kind; | 114 AstKind kind; |
112 if (element.enclosingClass is EnumClassElement) { | 115 if (element.enclosingClass is EnumClassElement) { |
113 if (element.name == 'index') { | 116 if (element.name == 'index') { |
114 kind = AstKind.ENUM_INDEX_FIELD; | 117 kind = AstKind.ENUM_INDEX_FIELD; |
115 } else if (element.name == 'values') { | 118 } else if (element.name == 'values') { |
116 kind = AstKind.ENUM_VALUES_FIELD; | 119 kind = AstKind.ENUM_VALUES_FIELD; |
117 } else if (element.name == 'toString') { | 120 } else if (element.name == 'toString') { |
118 kind = AstKind.ENUM_TO_STRING; | 121 kind = AstKind.ENUM_TO_STRING; |
119 } else if (element.isConstructor) { | 122 } else if (element.isConstructor) { |
120 kind = AstKind.ENUM_CONSTRUCTOR; | 123 kind = AstKind.ENUM_CONSTRUCTOR; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 }); | 475 }); |
473 } | 476 } |
474 } | 477 } |
475 | 478 |
476 AstKind kind = objectDecoder.getEnum(Key.SUB_KIND, AstKind.values); | 479 AstKind kind = objectDecoder.getEnum(Key.SUB_KIND, AstKind.values); |
477 Node root = computeNode(kind); | 480 Node root = computeNode(kind); |
478 TreeElementMapping elements = new TreeElementMapping(element); | 481 TreeElementMapping elements = new TreeElementMapping(element); |
479 AstIndexComputer indexComputer = new AstIndexComputer(); | 482 AstIndexComputer indexComputer = new AstIndexComputer(); |
480 Map<Node, int> nodeIndices = indexComputer.nodeIndices; | 483 Map<Node, int> nodeIndices = indexComputer.nodeIndices; |
481 List<Node> nodeList = indexComputer.nodeList; | 484 List<Node> nodeList = indexComputer.nodeList; |
| 485 Node body; |
| 486 int bodyNodeIndex = objectDecoder.getInt(Key.BODY, isOptional: true); |
| 487 if (bodyNodeIndex != null) { |
| 488 body = nodeList[bodyNodeIndex]; |
| 489 } |
482 root.accept(indexComputer); | 490 root.accept(indexComputer); |
483 | 491 |
484 List<JumpTarget> jumpTargets = <JumpTarget>[]; | 492 List<JumpTarget> jumpTargets = <JumpTarget>[]; |
485 Map<JumpTarget, List<int>> jumpTargetLabels = <JumpTarget, List<int>>{}; | 493 Map<JumpTarget, List<int>> jumpTargetLabels = <JumpTarget, List<int>>{}; |
486 List<LabelDefinition> labelDefinitions = <LabelDefinition>[]; | 494 List<LabelDefinition> labelDefinitions = <LabelDefinition>[]; |
487 | 495 |
488 ListDecoder jumpTargetsDecoder = | 496 ListDecoder jumpTargetsDecoder = |
489 objectDecoder.getList(Key.JUMP_TARGETS, isOptional: true); | 497 objectDecoder.getList(Key.JUMP_TARGETS, isOptional: true); |
490 if (jumpTargetsDecoder != null) { | 498 if (jumpTargetsDecoder != null) { |
491 for (int i = 0; i < jumpTargetsDecoder.length; i++) { | 499 for (int i = 0; i < jumpTargetsDecoder.length; i++) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 if (labelDefinitionId != null) { | 595 if (labelDefinitionId != null) { |
588 elements.defineLabel(node, labelDefinitions[labelDefinitionId]); | 596 elements.defineLabel(node, labelDefinitions[labelDefinitionId]); |
589 } | 597 } |
590 int targetLabelId = | 598 int targetLabelId = |
591 objectDecoder.getInt(Key.TARGET_LABEL, isOptional: true); | 599 objectDecoder.getInt(Key.TARGET_LABEL, isOptional: true); |
592 if (targetLabelId != null) { | 600 if (targetLabelId != null) { |
593 elements.registerTargetLabel(node, labelDefinitions[targetLabelId]); | 601 elements.registerTargetLabel(node, labelDefinitions[targetLabelId]); |
594 } | 602 } |
595 } | 603 } |
596 } | 604 } |
597 return new ParsedResolvedAst(element, root, elements); | 605 return new ParsedResolvedAst(element, root, body, elements); |
598 } | 606 } |
599 } | 607 } |
OLD | NEW |