Chromium Code Reviews| Index: pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart |
| diff --git a/pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart b/pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart |
| index bac31b1becdca220c2ea06de025557aa5856e2e1..8661bce452d7819cd9dedf408cef75c08cf324a2 100644 |
| --- a/pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart |
| +++ b/pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart |
| @@ -294,6 +294,16 @@ class ResolvedAstSerializer extends Visitor { |
| .setInt(Key.LABEL_DEFINITION, getLabelDefinitionId(labelDefinition)); |
| } |
| } |
| + |
| + @override |
| + visitFunctionExpression(FunctionExpression node) { |
| + visitExpression(node); |
| + Element function = elements.getFunctionDefinition(node); |
| + if (function != null && function.isFunction && function.isLocal) { |
| + // Mark root nodes of local functions; these need their own ResolvedAst. |
| + getNodeDataEncoder(node).setElement(Key.FUNCTION, function); |
| + } |
| + } |
| } |
| class ResolvedAstDeserializer { |
| @@ -308,35 +318,40 @@ class ResolvedAstDeserializer { |
| return null; |
| } |
| - /// Deserializes the [ResolvedAst] for [element] from [objectDecoder]. |
| + /// Deserializes the [ResolvedAst]s for [element] and its nested local |
| + /// functions from [objectDecoder] and adds these to [resolvedAstMap]. |
| /// [parsing] and [getBeginToken] are used for parsing the [Node] for |
| /// [element] from its source code. |
| - static ResolvedAst deserialize( |
| + static void deserialize( |
| Element element, |
| ObjectDecoder objectDecoder, |
| ParsingContext parsing, |
| Token getBeginToken(Uri uri, int charOffset), |
| - DeserializerPlugin nativeDataDeserializer) { |
| + DeserializerPlugin nativeDataDeserializer, |
| + Map<Element, ResolvedAst> resolvedAstMap) { |
| ResolvedAstKind kind = |
| objectDecoder.getEnum(Key.KIND, ResolvedAstKind.values); |
| switch (kind) { |
| case ResolvedAstKind.PARSED: |
| - return deserializeParsed(element, objectDecoder, parsing, getBeginToken, |
| - nativeDataDeserializer); |
| + deserializeParsed(element, objectDecoder, parsing, getBeginToken, |
| + nativeDataDeserializer, resolvedAstMap); |
| + break; |
| case ResolvedAstKind.DEFAULT_CONSTRUCTOR: |
| case ResolvedAstKind.FORWARDING_CONSTRUCTOR: |
| - return new SynthesizedResolvedAst(element, kind); |
| + resolvedAstMap[element] = new SynthesizedResolvedAst(element, kind); |
| + break; |
| } |
| } |
| /// Deserialize a [ResolvedAst] that is defined in terms of an AST together |
| /// with [TreeElements]. |
|
Siggi Cherem (dart-lang)
2016/05/02 16:21:43
let's update the comment to say that this deserial
Johnni Winther
2016/05/04 09:56:25
Done.
|
| - static ResolvedAst deserializeParsed( |
| + static void deserializeParsed( |
| Element element, |
| ObjectDecoder objectDecoder, |
| ParsingContext parsing, |
| Token getBeginToken(Uri uri, int charOffset), |
| - DeserializerPlugin nativeDataDeserializer) { |
| + DeserializerPlugin nativeDataDeserializer, |
| + Map<Element, ResolvedAst> resolvedAstMap) { |
| CompilationUnitElement compilationUnit = element.compilationUnit; |
| DiagnosticReporter reporter = parsing.reporter; |
| @@ -552,7 +567,7 @@ class ResolvedAstDeserializer { |
| jumpTarget.labels = linkBuilder.toLink(); |
| }); |
| - ListDecoder dataDecoder = objectDecoder.getList(Key.DATA); |
| + ListDecoder dataDecoder = objectDecoder.getList(Key.DATA, isOptional: true); |
| if (dataDecoder != null) { |
| for (int i = 0; i < dataDecoder.length; i++) { |
| ObjectDecoder objectDecoder = dataDecoder.getObject(i); |
| @@ -623,8 +638,16 @@ class ResolvedAstDeserializer { |
| elements.registerNativeData(node, nativeData); |
| } |
| } |
| + FunctionElement function = |
| + objectDecoder.getElement(Key.FUNCTION, isOptional: true); |
| + if (function != null) { |
| + FunctionExpression functionExpression = node; |
| + resolvedAstMap[function] = new ParsedResolvedAst( |
|
Siggi Cherem (dart-lang)
2016/05/02 16:21:43
do we need to assert that the key doesn't exist al
Johnni Winther
2016/05/04 09:56:25
Invariant test added!
|
| + function, functionExpression, functionExpression.body, elements); |
| + } |
| } |
| } |
| - return new ParsedResolvedAst(element, root, body, elements); |
| + resolvedAstMap[element] = |
| + new ParsedResolvedAst(element, root, body, elements); |
| } |
| } |