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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1707073002: Serialize and resynthesize variable initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 serialization.elements; 5 library serialization.elements;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/dart/element/element.dart'; 9 import 'package:analyzer/src/dart/element/element.dart';
10 import 'package:analyzer/src/dart/element/member.dart'; 10 import 'package:analyzer/src/dart/element/member.dart';
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 ReferenceKind _getReferenceKind(Element element) { 33 ReferenceKind _getReferenceKind(Element element) {
34 if (element == null || 34 if (element == null ||
35 element is ClassElement || 35 element is ClassElement ||
36 element is DynamicElementImpl) { 36 element is DynamicElementImpl) {
37 return ReferenceKind.classOrEnum; 37 return ReferenceKind.classOrEnum;
38 } else if (element is ConstructorElement) { 38 } else if (element is ConstructorElement) {
39 return ReferenceKind.constructor; 39 return ReferenceKind.constructor;
40 } else if (element is FunctionElement) { 40 } else if (element is FunctionElement) {
41 return ReferenceKind.topLevelFunction; 41 if (element.enclosingElement is CompilationUnitElement) {
42 return ReferenceKind.topLevelFunction;
43 }
44 return ReferenceKind.function;
42 } else if (element is FunctionTypeAliasElement) { 45 } else if (element is FunctionTypeAliasElement) {
43 return ReferenceKind.typedef; 46 return ReferenceKind.typedef;
44 } else if (element is PropertyAccessorElement) { 47 } else if (element is PropertyAccessorElement) {
45 if (element.enclosingElement is ClassElement) { 48 if (element.enclosingElement is ClassElement) {
46 return ReferenceKind.propertyAccessor; 49 return ReferenceKind.propertyAccessor;
47 } 50 }
48 return ReferenceKind.topLevelPropertyAccessor; 51 return ReferenceKind.topLevelPropertyAccessor;
49 } else if (element is MethodElement) { 52 } else if (element is MethodElement) {
50 return ReferenceKind.method; 53 return ReferenceKind.method;
51 } else { 54 } else {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 515 }
513 516
514 /** 517 /**
515 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. 518 * Serialize the given [executableElement], creating an [UnlinkedExecutable].
516 */ 519 */
517 UnlinkedExecutableBuilder serializeExecutable( 520 UnlinkedExecutableBuilder serializeExecutable(
518 ExecutableElement executableElement) { 521 ExecutableElement executableElement) {
519 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); 522 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder();
520 b.name = executableElement.name; 523 b.name = executableElement.name;
521 b.nameOffset = executableElement.nameOffset; 524 b.nameOffset = executableElement.nameOffset;
522 if (executableElement is! ConstructorElement) { 525 if (executableElement.enclosingElement is VariableElement) {
526 // TODO(scheglov) remove this check and serialize initializer types
527 // Note that for code like `var v = null` w need to support Bottom.
528 } else if (executableElement is! ConstructorElement) {
523 if (!executableElement.hasImplicitReturnType) { 529 if (!executableElement.hasImplicitReturnType) {
524 b.returnType = serializeTypeRef( 530 b.returnType = serializeTypeRef(
525 executableElement.type.returnType, executableElement); 531 executableElement.type.returnType, executableElement);
526 } else if (!executableElement.isStatic) { 532 } else if (!executableElement.isStatic) {
527 b.inferredReturnTypeSlot = 533 b.inferredReturnTypeSlot =
528 storeInferredType(executableElement.returnType, executableElement); 534 storeInferredType(executableElement.returnType, executableElement);
529 } 535 }
530 } 536 }
531 b.typeParameters = 537 b.typeParameters =
532 executableElement.typeParameters.map(serializeTypeParam).toList(); 538 executableElement.typeParameters.map(serializeTypeParam).toList();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 b.type = serializeTypeRef(type, context); 699 b.type = serializeTypeRef(type, context);
694 } 700 }
695 } 701 }
696 if (parameter is ConstVariableElement) { 702 if (parameter is ConstVariableElement) {
697 ConstVariableElement constParameter = parameter as ConstVariableElement; 703 ConstVariableElement constParameter = parameter as ConstVariableElement;
698 Expression initializer = constParameter.constantInitializer; 704 Expression initializer = constParameter.constantInitializer;
699 if (initializer != null) { 705 if (initializer != null) {
700 b.defaultValue = serializeConstExpr(initializer); 706 b.defaultValue = serializeConstExpr(initializer);
701 } 707 }
702 } 708 }
709 // TODO(scheglov) VariableMember.initializer is not implemented
710 if (parameter is! VariableMember && parameter.initializer != null) {
711 b.initializer = serializeExecutable(parameter.initializer);
712 }
703 { 713 {
704 SourceRange visibleRange = parameter.visibleRange; 714 SourceRange visibleRange = parameter.visibleRange;
705 if (visibleRange != null) { 715 if (visibleRange != null) {
706 b.visibleOffset = visibleRange.offset; 716 b.visibleOffset = visibleRange.offset;
707 b.visibleLength = visibleRange.length; 717 b.visibleLength = visibleRange.length;
708 } 718 }
709 } 719 }
710 return b; 720 return b;
711 } 721 }
712 722
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 (variable.initializer != null || !variable.isStatic)) { 916 (variable.initializer != null || !variable.isStatic)) {
907 b.inferredTypeSlot = storeInferredType(variable.type, variable); 917 b.inferredTypeSlot = storeInferredType(variable.type, variable);
908 } 918 }
909 if (variable is LocalVariableElement) { 919 if (variable is LocalVariableElement) {
910 SourceRange visibleRange = variable.visibleRange; 920 SourceRange visibleRange = variable.visibleRange;
911 if (visibleRange != null) { 921 if (visibleRange != null) {
912 b.visibleOffset = visibleRange.offset; 922 b.visibleOffset = visibleRange.offset;
913 b.visibleLength = visibleRange.length; 923 b.visibleLength = visibleRange.length;
914 } 924 }
915 } 925 }
926 // TODO(scheglov) VariableMember.initializer is not implemented
927 if (variable is! VariableMember && variable.initializer != null) {
928 b.initializer = serializeExecutable(variable.initializer);
929 }
916 return b; 930 return b;
917 } 931 }
918 932
919 /** 933 /**
920 * Create a slot id for the given [type] (which is an inferred type). If 934 * Create a slot id for the given [type] (which is an inferred type). If
921 * strong mode is enabled and [type] is not `dynamic`, it is stored in 935 * strong mode is enabled and [type] is not `dynamic`, it is stored in
922 * [linkedTypes] so that once the compilation unit has been fully visited, it 936 * [linkedTypes] so that once the compilation unit has been fully visited, it
923 * will be serialized into [LinkedUnit.types]. 937 * will be serialized into [LinkedUnit.types].
924 * 938 *
925 * [context] is the element within which the slot id will appear; this is 939 * [context] is the element within which the slot id will appear; this is
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 exportNames.add(new LinkedExportNameBuilder( 1363 exportNames.add(new LinkedExportNameBuilder(
1350 name: name, 1364 name: name,
1351 dependency: serializeDependency(dependentLibrary), 1365 dependency: serializeDependency(dependentLibrary),
1352 unit: unit, 1366 unit: unit,
1353 kind: kind)); 1367 kind: kind));
1354 } 1368 }
1355 pb.exportNames = exportNames; 1369 pb.exportNames = exportNames;
1356 return pb; 1370 return pb;
1357 } 1371 }
1358 } 1372 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_ast.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698