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

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

Issue 1970703002: Store ResolvedAst on AstElement (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 7 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 | « pkg/compiler/lib/src/serialization/modelz.dart ('k') | pkg/compiler/lib/src/ssa/builder.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';
11 import '../diagnostics/diagnostic_listener.dart'; 11 import '../diagnostics/diagnostic_listener.dart';
12 import '../elements/elements.dart'; 12 import '../elements/elements.dart';
13 import '../elements/modelx.dart'; 13 import '../elements/modelx.dart';
14 import '../parser/listener.dart' show ParserError; 14 import '../parser/listener.dart' show ParserError;
15 import '../parser/node_listener.dart' show NodeListener; 15 import '../parser/node_listener.dart' show NodeListener;
16 import '../parser/parser.dart' show Parser; 16 import '../parser/parser.dart' show Parser;
17 import '../resolution/enum_creator.dart'; 17 import '../resolution/enum_creator.dart';
18 import '../resolution/send_structure.dart'; 18 import '../resolution/send_structure.dart';
19 import '../resolution/tree_elements.dart'; 19 import '../resolution/tree_elements.dart';
20 import '../tokens/token.dart'; 20 import '../tokens/token.dart';
21 import '../tree/tree.dart'; 21 import '../tree/tree.dart';
22 import '../universe/selector.dart'; 22 import '../universe/selector.dart';
23 import '../util/util.dart'; 23 import '../util/util.dart';
24 import 'keys.dart'; 24 import 'keys.dart';
25 import 'modelz.dart'; 25 import 'modelz.dart';
26 import 'serialization.dart'; 26 import 'serialization.dart';
27 import 'serialization_util.dart'; 27 import 'serialization_util.dart';
28 import 'modelz.dart';
28 29
29 /// Visitor that computes a node-index mapping. 30 /// Visitor that computes a node-index mapping.
30 class AstIndexComputer extends Visitor { 31 class AstIndexComputer extends Visitor {
31 final Map<Node, int> nodeIndices = <Node, int>{}; 32 final Map<Node, int> nodeIndices = <Node, int>{};
32 final List<Node> nodeList = <Node>[]; 33 final List<Node> nodeList = <Node>[];
33 34
34 @override 35 @override
35 visitNode(Node node) { 36 visitNode(Node node) {
36 nodeIndices.putIfAbsent(node, () { 37 nodeIndices.putIfAbsent(node, () {
37 // Some nodes (like Modifier and empty NodeList) can be reused. 38 // Some nodes (like Modifier and empty NodeList) can be reused.
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 338
338 /// Deserializes the [ResolvedAst]s for [element] and its nested local 339 /// Deserializes the [ResolvedAst]s for [element] and its nested local
339 /// functions from [objectDecoder] and adds these to [resolvedAstMap]. 340 /// functions from [objectDecoder] and adds these to [resolvedAstMap].
340 /// [parsing] and [getBeginToken] are used for parsing the [Node] for 341 /// [parsing] and [getBeginToken] are used for parsing the [Node] for
341 /// [element] from its source code. 342 /// [element] from its source code.
342 static void deserialize( 343 static void deserialize(
343 Element element, 344 Element element,
344 ObjectDecoder objectDecoder, 345 ObjectDecoder objectDecoder,
345 ParsingContext parsing, 346 ParsingContext parsing,
346 Token getBeginToken(Uri uri, int charOffset), 347 Token getBeginToken(Uri uri, int charOffset),
347 DeserializerPlugin nativeDataDeserializer, 348 DeserializerPlugin nativeDataDeserializer) {
348 Map<Element, ResolvedAst> resolvedAstMap) {
349 ResolvedAstKind kind = 349 ResolvedAstKind kind =
350 objectDecoder.getEnum(Key.KIND, ResolvedAstKind.values); 350 objectDecoder.getEnum(Key.KIND, ResolvedAstKind.values);
351 switch (kind) { 351 switch (kind) {
352 case ResolvedAstKind.PARSED: 352 case ResolvedAstKind.PARSED:
353 deserializeParsed(element, objectDecoder, parsing, getBeginToken, 353 deserializeParsed(element, objectDecoder, parsing, getBeginToken,
354 nativeDataDeserializer, resolvedAstMap); 354 nativeDataDeserializer);
355 break; 355 break;
356 case ResolvedAstKind.DEFAULT_CONSTRUCTOR: 356 case ResolvedAstKind.DEFAULT_CONSTRUCTOR:
357 case ResolvedAstKind.FORWARDING_CONSTRUCTOR: 357 case ResolvedAstKind.FORWARDING_CONSTRUCTOR:
358 resolvedAstMap[element] = new SynthesizedResolvedAst(element, kind); 358 (element as AstElementMixinZ).resolvedAst =
359 new SynthesizedResolvedAst(element, kind);
359 break; 360 break;
360 } 361 }
361 } 362 }
362 363
363 /// Deserialize the [ResolvedAst]s for the member [element] (constructor, 364 /// Deserialize the [ResolvedAst]s for the member [element] (constructor,
364 /// method, or field) and its nested closures. The [ResolvedAst]s are added 365 /// method, or field) and its nested closures. The [ResolvedAst]s are added
365 /// to [resolvedAstMap]. 366 /// to [resolvedAstMap].
366 static void deserializeParsed( 367 static void deserializeParsed(
367 Element element, 368 AstElementMixinZ element,
368 ObjectDecoder objectDecoder, 369 ObjectDecoder objectDecoder,
369 ParsingContext parsing, 370 ParsingContext parsing,
370 Token getBeginToken(Uri uri, int charOffset), 371 Token getBeginToken(Uri uri, int charOffset),
371 DeserializerPlugin nativeDataDeserializer, 372 DeserializerPlugin nativeDataDeserializer) {
372 Map<Element, ResolvedAst> resolvedAstMap) {
373 CompilationUnitElement compilationUnit = element.compilationUnit; 373 CompilationUnitElement compilationUnit = element.compilationUnit;
374 DiagnosticReporter reporter = parsing.reporter; 374 DiagnosticReporter reporter = parsing.reporter;
375 Uri uri = objectDecoder.getUri(Key.URI); 375 Uri uri = objectDecoder.getUri(Key.URI);
376 376
377 /// Returns the first [Token] for parsing the [Node] for [element]. 377 /// Returns the first [Token] for parsing the [Node] for [element].
378 Token readBeginToken() { 378 Token readBeginToken() {
379 int charOffset = objectDecoder.getInt(Key.OFFSET); 379 int charOffset = objectDecoder.getInt(Key.OFFSET);
380 Token beginToken = getBeginToken(uri, charOffset); 380 Token beginToken = getBeginToken(uri, charOffset);
381 if (beginToken == null) { 381 if (beginToken == null) {
382 reporter.internalError( 382 reporter.internalError(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 VariableDefinitions indexDefinition = 473 VariableDefinitions indexDefinition =
474 builder.initializingFormal('index'); 474 builder.initializingFormal('index');
475 FunctionExpression constructorNode = builder.functionExpression( 475 FunctionExpression constructorNode = builder.functionExpression(
476 builder.modifiers(isConst: true), 476 builder.modifiers(isConst: true),
477 element.enclosingClass.name, 477 element.enclosingClass.name,
478 null, 478 null,
479 builder.argumentList([indexDefinition]), 479 builder.argumentList([indexDefinition]),
480 builder.emptyStatement()); 480 builder.emptyStatement());
481 return constructorNode; 481 return constructorNode;
482 case AstKind.ENUM_CONSTANT: 482 case AstKind.ENUM_CONSTANT:
483 EnumConstantElement enumConstant = element; 483 EnumConstantElementZ enumConstant = element;
484 EnumClassElement enumClass = element.enclosingClass; 484 EnumClassElement enumClass = element.enclosingClass;
485 int index = enumConstant.index; 485 int index = enumConstant.index;
486 AstBuilder builder = new AstBuilder(element.sourcePosition.begin); 486 AstBuilder builder = new AstBuilder(element.sourcePosition.begin);
487 Identifier name = builder.identifier(element.name); 487 Identifier name = builder.identifier(element.name);
488 488
489 Expression initializer = builder.newExpression( 489 Expression initializer = builder.newExpression(
490 enumClass.name, builder.argumentList([builder.literalInt(index)]), 490 enumClass.name, builder.argumentList([builder.literalInt(index)]),
491 isConst: true); 491 isConst: true);
492 SendSet definition = builder.createDefinition(name, initializer); 492 SendSet definition = builder.createDefinition(name, initializer);
493 493
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 elements.registerTargetLabel(node, labelDefinitions[targetLabelId]); 653 elements.registerTargetLabel(node, labelDefinitions[targetLabelId]);
654 } 654 }
655 ObjectDecoder nativeDataDecoder = 655 ObjectDecoder nativeDataDecoder =
656 objectDecoder.getObject(Key.NATIVE, isOptional: true); 656 objectDecoder.getObject(Key.NATIVE, isOptional: true);
657 if (nativeDataDecoder != null) { 657 if (nativeDataDecoder != null) {
658 var nativeData = nativeDataDeserializer.onData(nativeDataDecoder); 658 var nativeData = nativeDataDeserializer.onData(nativeDataDecoder);
659 if (nativeData != null) { 659 if (nativeData != null) {
660 elements.registerNativeData(node, nativeData); 660 elements.registerNativeData(node, nativeData);
661 } 661 }
662 } 662 }
663 FunctionElement function = 663 LocalFunctionElementZ function =
664 objectDecoder.getElement(Key.FUNCTION, isOptional: true); 664 objectDecoder.getElement(Key.FUNCTION, isOptional: true);
665 if (function != null) { 665 if (function != null) {
666 FunctionExpression functionExpression = node; 666 FunctionExpression functionExpression = node;
667 assert(invariant(function, !resolvedAstMap.containsKey(function), 667 function.resolvedAst = new ParsedResolvedAst(function,
668 message: "ResolvedAst has already been computed for $function."));
669 resolvedAstMap[function] = new ParsedResolvedAst(function,
670 functionExpression, functionExpression.body, elements, uri); 668 functionExpression, functionExpression.body, elements, uri);
671 } 669 }
672 // TODO(johnniwinther): Remove these when inference doesn't need `.node` 670 // TODO(johnniwinther): Remove these when inference doesn't need `.node`
673 // and `.initializer` of [ParameterElement]s. 671 // and `.initializer` of [ParameterElement]s.
674 ParameterElementZ parameter = 672 ParameterElementZ parameter =
675 objectDecoder.getElement(PARAMETER_NODE, isOptional: true); 673 objectDecoder.getElement(PARAMETER_NODE, isOptional: true);
676 if (parameter != null) { 674 if (parameter != null) {
677 parameter.node = node; 675 parameter.node = node;
678 } 676 }
679 parameter = 677 parameter =
680 objectDecoder.getElement(PARAMETER_INITIALIZER, isOptional: true); 678 objectDecoder.getElement(PARAMETER_INITIALIZER, isOptional: true);
681 if (parameter != null) { 679 if (parameter != null) {
682 parameter.initializer = node; 680 parameter.initializer = node;
683 } 681 }
684 } 682 }
685 } 683 }
686 assert(invariant(element, !resolvedAstMap.containsKey(element), 684 element.resolvedAst =
687 message: "ResolvedAst has already been computed for $element."));
688 resolvedAstMap[element] =
689 new ParsedResolvedAst(element, root, body, elements, uri); 685 new ParsedResolvedAst(element, root, body, elements, uri);
690 } 686 }
691 } 687 }
692 688
693 const Key PARAMETER_NODE = const Key('parameter.node'); 689 const Key PARAMETER_NODE = const Key('parameter.node');
694 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer'); 690 const Key PARAMETER_INITIALIZER = const Key('parameter.initializer');
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/modelz.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698