Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart

Issue 2125643002: Serialize parameter nodes for local functions. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/serialization/model_test_helper.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 for (JumpTarget jumpTarget in jumpTargetMap.keys) { 159 for (JumpTarget jumpTarget in jumpTargetMap.keys) {
160 serializeJumpTarget(jumpTarget, list.createObject()); 160 serializeJumpTarget(jumpTarget, list.createObject());
161 } 161 }
162 } 162 }
163 if (labelDefinitionMap.isNotEmpty) { 163 if (labelDefinitionMap.isNotEmpty) {
164 ListEncoder list = objectEncoder.createList(Key.LABEL_DEFINITIONS); 164 ListEncoder list = objectEncoder.createList(Key.LABEL_DEFINITIONS);
165 for (LabelDefinition labelDefinition in labelDefinitionMap.keys) { 165 for (LabelDefinition labelDefinition in labelDefinitionMap.keys) {
166 serializeLabelDefinition(labelDefinition, list.createObject()); 166 serializeLabelDefinition(labelDefinition, list.createObject());
167 } 167 }
168 } 168 }
169
169 if (element is FunctionElement) { 170 if (element is FunctionElement) {
170 FunctionElement function = element; 171 serializeParameterNodes(element);
171 function.functionSignature.forEachParameter((ParameterElement parameter) {
172 ParameterElement parameterImpl = parameter.implementation;
173 // TODO(johnniwinther): Should we support element->node mapping as well?
174 getNodeDataEncoder(parameterImpl.node)
175 .setElement(PARAMETER_NODE, parameter);
176 if (parameter.initializer != null) {
177 getNodeDataEncoder(parameterImpl.initializer)
178 .setElement(PARAMETER_INITIALIZER, parameter);
179 }
180 });
181 } 172 }
182 } 173 }
183 174
175 void serializeParameterNodes(FunctionElement function) {
176 function.functionSignature.forEachParameter((ParameterElement parameter) {
177 ParameterElement parameterImpl = parameter.implementation;
178 // TODO(johnniwinther): Should we support element->node mapping as well?
179 getNodeDataEncoder(parameterImpl.node)
180 .setElement(PARAMETER_NODE, parameter);
181 if (parameter.initializer != null) {
182 getNodeDataEncoder(parameterImpl.initializer)
183 .setElement(PARAMETER_INITIALIZER, parameter);
184 }
185 });
186 }
187
184 /// Serialize [target] into [encoder]. 188 /// Serialize [target] into [encoder].
185 void serializeJumpTarget(JumpTarget jumpTarget, ObjectEncoder encoder) { 189 void serializeJumpTarget(JumpTarget jumpTarget, ObjectEncoder encoder) {
186 encoder.setElement(Key.EXECUTABLE_CONTEXT, jumpTarget.executableContext); 190 encoder.setElement(Key.EXECUTABLE_CONTEXT, jumpTarget.executableContext);
187 encoder.setInt(Key.NODE, nodeIndices[jumpTarget.statement]); 191 encoder.setInt(Key.NODE, nodeIndices[jumpTarget.statement]);
188 encoder.setInt(Key.NESTING_LEVEL, jumpTarget.nestingLevel); 192 encoder.setInt(Key.NESTING_LEVEL, jumpTarget.nestingLevel);
189 encoder.setBool(Key.IS_BREAK_TARGET, jumpTarget.isBreakTarget); 193 encoder.setBool(Key.IS_BREAK_TARGET, jumpTarget.isBreakTarget);
190 encoder.setBool(Key.IS_CONTINUE_TARGET, jumpTarget.isContinueTarget); 194 encoder.setBool(Key.IS_CONTINUE_TARGET, jumpTarget.isContinueTarget);
191 if (jumpTarget.labels.isNotEmpty) { 195 if (jumpTarget.labels.isNotEmpty) {
192 List<int> labelIdList = <int>[]; 196 List<int> labelIdList = <int>[];
193 for (LabelDefinition label in jumpTarget.labels) { 197 for (LabelDefinition label in jumpTarget.labels) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 315 }
312 } 316 }
313 317
314 @override 318 @override
315 visitFunctionExpression(FunctionExpression node) { 319 visitFunctionExpression(FunctionExpression node) {
316 visitExpression(node); 320 visitExpression(node);
317 Element function = elements.getFunctionDefinition(node); 321 Element function = elements.getFunctionDefinition(node);
318 if (function != null && function.isFunction && function.isLocal) { 322 if (function != null && function.isFunction && function.isLocal) {
319 // Mark root nodes of local functions; these need their own ResolvedAst. 323 // Mark root nodes of local functions; these need their own ResolvedAst.
320 getNodeDataEncoder(node).setElement(Key.FUNCTION, function); 324 getNodeDataEncoder(node).setElement(Key.FUNCTION, function);
325 serializeParameterNodes(function);
321 } 326 }
322 } 327 }
323 } 328 }
324 329
325 class ResolvedAstDeserializer { 330 class ResolvedAstDeserializer {
326 /// Find the [Token] at [offset] searching through successors of [token]. 331 /// Find the [Token] at [offset] searching through successors of [token].
327 static Token findTokenInStream(Token token, int offset) { 332 static Token findTokenInStream(Token token, int offset) {
328 while (token.charOffset <= offset && token.next != token) { 333 while (token.charOffset <= offset && token.next != token) {
329 if (token.charOffset == offset) { 334 if (token.charOffset == offset) {
330 return token; 335 return token;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 688 }
684 } 689 }
685 } 690 }
686 element.resolvedAst = 691 element.resolvedAst =
687 new ParsedResolvedAst(element, root, body, elements, uri); 692 new ParsedResolvedAst(element, root, body, elements, uri);
688 } 693 }
689 } 694 }
690 695
691 const Key PARAMETER_NODE = const Key('parameter.node'); 696 const Key PARAMETER_NODE = const Key('parameter.node');
692 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer'); 697 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer');
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/serialization/model_test_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698