| 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/type.dart'; | 10 import 'package:analyzer/src/dart/element/type.dart'; |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 438 } |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. | 441 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. |
| 442 */ | 442 */ |
| 443 UnlinkedExecutableBuilder serializeExecutable( | 443 UnlinkedExecutableBuilder serializeExecutable( |
| 444 ExecutableElement executableElement) { | 444 ExecutableElement executableElement) { |
| 445 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); | 445 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); |
| 446 b.name = executableElement.name; | 446 b.name = executableElement.name; |
| 447 b.nameOffset = executableElement.nameOffset; | 447 b.nameOffset = executableElement.nameOffset; |
| 448 if (executableElement is! ConstructorElement && | 448 if (executableElement is! ConstructorElement) { |
| 449 !executableElement.type.returnType.isVoid) { | 449 if (executableElement.hasImplicitReturnType) { |
| 450 b.returnType = serializeTypeRef( | 450 // In strong mode, the variable's static type may have been overwritten |
| 451 executableElement.type.returnType, executableElement); | 451 // by an inferred type. In this part of the summary we want to store |
| 452 // the weak mode static type (which is `dynamic`), since the strong |
| 453 // mode static type is fully linked information. |
| 454 b.returnType = serializeTypeRef( |
| 455 librarySerializer.typeProvider.dynamicType, executableElement); |
| 456 } else if (!executableElement.type.returnType.isVoid) { |
| 457 b.returnType = serializeTypeRef( |
| 458 executableElement.type.returnType, executableElement); |
| 459 } |
| 452 } | 460 } |
| 453 b.typeParameters = | 461 b.typeParameters = |
| 454 executableElement.typeParameters.map(serializeTypeParam).toList(); | 462 executableElement.typeParameters.map(serializeTypeParam).toList(); |
| 455 b.parameters = | 463 b.parameters = |
| 456 executableElement.type.parameters.map(serializeParam).toList(); | 464 executableElement.type.parameters.map(serializeParam).toList(); |
| 457 if (executableElement is PropertyAccessorElement) { | 465 if (executableElement is PropertyAccessorElement) { |
| 458 if (executableElement.isGetter) { | 466 if (executableElement.isGetter) { |
| 459 b.kind = UnlinkedExecutableKind.getter; | 467 b.kind = UnlinkedExecutableKind.getter; |
| 460 } else { | 468 } else { |
| 461 b.kind = UnlinkedExecutableKind.setter; | 469 b.kind = UnlinkedExecutableKind.setter; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 return unresolvedReferenceIndex; | 700 return unresolvedReferenceIndex; |
| 693 } | 701 } |
| 694 | 702 |
| 695 /** | 703 /** |
| 696 * Serialize the given [variable], creating an [UnlinkedVariable]. | 704 * Serialize the given [variable], creating an [UnlinkedVariable]. |
| 697 */ | 705 */ |
| 698 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { | 706 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { |
| 699 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 707 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 700 b.name = variable.name; | 708 b.name = variable.name; |
| 701 b.nameOffset = variable.nameOffset; | 709 b.nameOffset = variable.nameOffset; |
| 702 b.type = serializeTypeRef(variable.type, variable); | 710 if (variable.hasImplicitType) { |
| 711 // In strong mode, the variable's static type may have been overwritten |
| 712 // by an inferred type. In this part of the summary we want to store the |
| 713 // weak mode static type (which is `dynamic`), since the strong mode |
| 714 // static type is fully linked information. |
| 715 b.type = serializeTypeRef( |
| 716 librarySerializer.typeProvider.dynamicType, variable); |
| 717 } else { |
| 718 b.type = serializeTypeRef(variable.type, variable); |
| 719 } |
| 703 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 720 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
| 704 b.isFinal = variable.isFinal; | 721 b.isFinal = variable.isFinal; |
| 705 b.isConst = variable.isConst; | 722 b.isConst = variable.isConst; |
| 706 b.hasImplicitType = variable.hasImplicitType; | 723 b.hasImplicitType = variable.hasImplicitType; |
| 707 b.documentationComment = serializeDocumentation(variable); | 724 b.documentationComment = serializeDocumentation(variable); |
| 708 if (variable.isConst && variable is ConstVariableElement) { | 725 if (variable.isConst && variable is ConstVariableElement) { |
| 709 ConstVariableElement constVariable = variable as ConstVariableElement; | 726 ConstVariableElement constVariable = variable as ConstVariableElement; |
| 710 Expression initializer = constVariable.constantInitializer; | 727 Expression initializer = constVariable.constantInitializer; |
| 711 if (initializer != null) { | 728 if (initializer != null) { |
| 712 b.constExpr = serializeConstExpr(initializer); | 729 b.constExpr = serializeConstExpr(initializer); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 exportNames.add(new LinkedExportNameBuilder( | 997 exportNames.add(new LinkedExportNameBuilder( |
| 981 name: name, | 998 name: name, |
| 982 dependency: serializeDependency(dependentLibrary), | 999 dependency: serializeDependency(dependentLibrary), |
| 983 unit: unit, | 1000 unit: unit, |
| 984 kind: kind)); | 1001 kind: kind)); |
| 985 } | 1002 } |
| 986 pb.exportNames = exportNames; | 1003 pb.exportNames = exportNames; |
| 987 return pb; | 1004 return pb; |
| 988 } | 1005 } |
| 989 } | 1006 } |
| OLD | NEW |