| OLD | NEW |
| 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'; |
| 11 import 'package:analyzer/src/dart/element/type.dart'; | 11 import 'package:analyzer/src/dart/element/type.dart'; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/resolver.dart'; | 13 import 'package:analyzer/src/generated/resolver.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:analyzer/src/generated/utilities_dart.dart'; | 15 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 15 import 'package:analyzer/src/summary/format.dart'; | 16 import 'package:analyzer/src/summary/format.dart'; |
| 16 import 'package:analyzer/src/summary/idl.dart'; | 17 import 'package:analyzer/src/summary/idl.dart'; |
| 17 import 'package:analyzer/src/summary/name_filter.dart'; | 18 import 'package:analyzer/src/summary/name_filter.dart'; |
| 18 import 'package:analyzer/src/summary/summarize_const_expr.dart'; | 19 import 'package:analyzer/src/summary/summarize_const_expr.dart'; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * Serialize all the elements in [lib] to a summary using [ctx] as the context | 22 * Serialize all the elements in [lib] to a summary using [ctx] as the context |
| 22 * for building the summary, and using [typeProvider] to find built-in types. | 23 * for building the summary, and using [typeProvider] to find built-in types. |
| 23 */ | 24 */ |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 } | 580 } |
| 580 } else { | 581 } else { |
| 581 b.kind = UnlinkedExecutableKind.functionOrMethod; | 582 b.kind = UnlinkedExecutableKind.functionOrMethod; |
| 582 } | 583 } |
| 583 b.isAbstract = executableElement.isAbstract; | 584 b.isAbstract = executableElement.isAbstract; |
| 584 b.isStatic = executableElement.isStatic && | 585 b.isStatic = executableElement.isStatic && |
| 585 executableElement.enclosingElement is ClassElement; | 586 executableElement.enclosingElement is ClassElement; |
| 586 b.isExternal = executableElement.isExternal; | 587 b.isExternal = executableElement.isExternal; |
| 587 b.documentationComment = serializeDocumentation(executableElement); | 588 b.documentationComment = serializeDocumentation(executableElement); |
| 588 b.annotations = serializeAnnotations(executableElement); | 589 b.annotations = serializeAnnotations(executableElement); |
| 590 if (executableElement is FunctionElement) { |
| 591 SourceRange visibleRange = executableElement.visibleRange; |
| 592 if (visibleRange != null) { |
| 593 b.visibleOffset = visibleRange.offset; |
| 594 b.visibleLength = visibleRange.length; |
| 595 } |
| 596 } |
| 597 b.localFunctions = |
| 598 executableElement.functions.map(serializeExecutable).toList(); |
| 599 b.localVariables = |
| 600 executableElement.localVariables.map(serializeVariable).toList(); |
| 589 return b; | 601 return b; |
| 590 } | 602 } |
| 591 | 603 |
| 592 /** | 604 /** |
| 593 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. | 605 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. |
| 594 */ | 606 */ |
| 595 UnlinkedExportNonPublicBuilder serializeExportNonPublic( | 607 UnlinkedExportNonPublicBuilder serializeExportNonPublic( |
| 596 ExportElement exportElement) { | 608 ExportElement exportElement) { |
| 597 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(); | 609 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(); |
| 598 b.offset = exportElement.nameOffset; | 610 b.offset = exportElement.nameOffset; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 if (unresolvedReferenceIndex == null) { | 858 if (unresolvedReferenceIndex == null) { |
| 847 return serializeUnlinkedReference( | 859 return serializeUnlinkedReference( |
| 848 '*unresolved*', ReferenceKind.unresolved); | 860 '*unresolved*', ReferenceKind.unresolved); |
| 849 } | 861 } |
| 850 return unresolvedReferenceIndex; | 862 return unresolvedReferenceIndex; |
| 851 } | 863 } |
| 852 | 864 |
| 853 /** | 865 /** |
| 854 * Serialize the given [variable], creating an [UnlinkedVariable]. | 866 * Serialize the given [variable], creating an [UnlinkedVariable]. |
| 855 */ | 867 */ |
| 856 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { | 868 UnlinkedVariableBuilder serializeVariable(VariableElement variable) { |
| 857 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 869 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 858 b.name = variable.name; | 870 b.name = variable.name; |
| 859 b.nameOffset = variable.nameOffset; | 871 b.nameOffset = variable.nameOffset; |
| 860 if (!variable.hasImplicitType) { | 872 if (!variable.hasImplicitType) { |
| 861 b.type = serializeTypeRef(variable.type, variable); | 873 b.type = serializeTypeRef(variable.type, variable); |
| 862 } | 874 } |
| 863 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 875 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
| 864 b.isFinal = variable.isFinal; | 876 b.isFinal = variable.isFinal; |
| 865 b.isConst = variable.isConst; | 877 b.isConst = variable.isConst; |
| 866 b.documentationComment = serializeDocumentation(variable); | 878 b.documentationComment = serializeDocumentation(variable); |
| 867 b.annotations = serializeAnnotations(variable); | 879 b.annotations = serializeAnnotations(variable); |
| 868 if (variable is ConstVariableElement) { | 880 if (variable is ConstVariableElement) { |
| 869 ConstVariableElement constVariable = variable as ConstVariableElement; | 881 ConstVariableElement constVariable = variable as ConstVariableElement; |
| 870 Expression initializer = constVariable.constantInitializer; | 882 Expression initializer = constVariable.constantInitializer; |
| 871 if (initializer != null) { | 883 if (initializer != null) { |
| 872 b.constExpr = serializeConstExpr(initializer); | 884 b.constExpr = serializeConstExpr(initializer); |
| 873 } | 885 } |
| 874 } | 886 } |
| 875 if (b.isFinal || b.isConst) { | 887 if (variable is PropertyInducingElement) { |
| 876 b.propagatedTypeSlot = storeLinkedType(variable.propagatedType, variable); | 888 if (b.isFinal || b.isConst) { |
| 877 } else { | 889 b.propagatedTypeSlot = |
| 878 // Variable is not propagable. | 890 storeLinkedType(variable.propagatedType, variable); |
| 879 assert(variable.propagatedType == null); | 891 } else { |
| 892 // Variable is not propagable. |
| 893 assert(variable.propagatedType == null); |
| 894 } |
| 880 } | 895 } |
| 881 if (variable.hasImplicitType && | 896 if (variable.hasImplicitType && |
| 882 (variable.initializer != null || !variable.isStatic)) { | 897 (variable.initializer != null || !variable.isStatic)) { |
| 883 b.inferredTypeSlot = storeInferredType(variable.type, variable); | 898 b.inferredTypeSlot = storeInferredType(variable.type, variable); |
| 884 } | 899 } |
| 900 if (variable is LocalVariableElement) { |
| 901 SourceRange visibleRange = variable.visibleRange; |
| 902 if (visibleRange != null) { |
| 903 b.visibleOffset = visibleRange.offset; |
| 904 b.visibleLength = visibleRange.length; |
| 905 } |
| 906 } |
| 885 return b; | 907 return b; |
| 886 } | 908 } |
| 887 | 909 |
| 888 /** | 910 /** |
| 889 * Create a slot id for the given [type] (which is an inferred type). If | 911 * Create a slot id for the given [type] (which is an inferred type). If |
| 890 * strong mode is enabled and [type] is not `dynamic`, it is stored in | 912 * strong mode is enabled and [type] is not `dynamic`, it is stored in |
| 891 * [linkedTypes] so that once the compilation unit has been fully visited, it | 913 * [linkedTypes] so that once the compilation unit has been fully visited, it |
| 892 * will be serialized into [LinkedUnit.types]. | 914 * will be serialized into [LinkedUnit.types]. |
| 893 * | 915 * |
| 894 * [context] is the element within which the slot id will appear; this is | 916 * [context] is the element within which the slot id will appear; this is |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 exportNames.add(new LinkedExportNameBuilder( | 1303 exportNames.add(new LinkedExportNameBuilder( |
| 1282 name: name, | 1304 name: name, |
| 1283 dependency: serializeDependency(dependentLibrary), | 1305 dependency: serializeDependency(dependentLibrary), |
| 1284 unit: unit, | 1306 unit: unit, |
| 1285 kind: kind)); | 1307 kind: kind)); |
| 1286 } | 1308 } |
| 1287 pb.exportNames = exportNames; | 1309 pb.exportNames = exportNames; |
| 1288 return pb; | 1310 return pb; |
| 1289 } | 1311 } |
| 1290 } | 1312 } |
| OLD | NEW |