| 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 for (int i = 1; i < linkedLibrary.units.length; i++) { | 999 for (int i = 1; i < linkedLibrary.units.length; i++) { |
| 1000 _UnitResynthesizer partResynthesizer = buildPart( | 1000 _UnitResynthesizer partResynthesizer = buildPart( |
| 1001 definingUnitResynthesizer, | 1001 definingUnitResynthesizer, |
| 1002 unlinkedDefiningUnit.publicNamespace.parts[i - 1], | 1002 unlinkedDefiningUnit.publicNamespace.parts[i - 1], |
| 1003 unlinkedDefiningUnit.parts[i - 1], | 1003 unlinkedDefiningUnit.parts[i - 1], |
| 1004 i); | 1004 i); |
| 1005 partResynthesizers.add(partResynthesizer); | 1005 partResynthesizers.add(partResynthesizer); |
| 1006 } | 1006 } |
| 1007 library.parts = partResynthesizers.map((r) => r.unit).toList(); | 1007 library.parts = partResynthesizers.map((r) => r.unit).toList(); |
| 1008 // Populate units. | 1008 // Populate units. |
| 1009 populateUnit(definingUnitResynthesizer); | 1009 rememberUriToUnit(definingUnitResynthesizer); |
| 1010 for (_UnitResynthesizer partResynthesizer in partResynthesizers) { | 1010 for (_UnitResynthesizer partResynthesizer in partResynthesizers) { |
| 1011 populateUnit(partResynthesizer); | 1011 rememberUriToUnit(partResynthesizer); |
| 1012 } | 1012 } |
| 1013 // Create the synthetic element for `loadLibrary`. | 1013 // Create the synthetic element for `loadLibrary`. |
| 1014 // Until the client received dart:core and dart:async, we cannot do this, | 1014 // Until the client received dart:core and dart:async, we cannot do this, |
| 1015 // because the TypeProvider is not fully initialized. So, it is up to the | 1015 // because the TypeProvider is not fully initialized. So, it is up to the |
| 1016 // Dart SDK client to initialize TypeProvider and finish the dart:core and | 1016 // Dart SDK client to initialize TypeProvider and finish the dart:core and |
| 1017 // dart:async libraries creation. | 1017 // dart:async libraries creation. |
| 1018 if (library.name != 'dart.core' && library.name != 'dart.async') { | 1018 if (library.name != 'dart.core' && library.name != 'dart.async') { |
| 1019 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider); | 1019 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider); |
| 1020 } | 1020 } |
| 1021 // Done. | 1021 // Done. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 Source partSource = | 1082 Source partSource = |
| 1083 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); | 1083 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); |
| 1084 partUri = partSource.uri.toString(); | 1084 partUri = partSource.uri.toString(); |
| 1085 } else { | 1085 } else { |
| 1086 partUri = referencedLibraryUri; | 1086 partUri = referencedLibraryUri; |
| 1087 } | 1087 } |
| 1088 return <String>[referencedLibraryUri, partUri, name]; | 1088 return <String>[referencedLibraryUri, partUri, name]; |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 /** | 1091 /** |
| 1092 * Populate a [CompilationUnitElement] by deserializing all the elements | 1092 * Remember the absolute URI to the corresponding unit mapping. |
| 1093 * contained in it. | |
| 1094 */ | 1093 */ |
| 1095 void populateUnit(_UnitResynthesizer unitResynthesized) { | 1094 void rememberUriToUnit(_UnitResynthesizer unitResynthesized) { |
| 1096 unitResynthesized.populateUnit(); | 1095 CompilationUnitElementImpl unit = unitResynthesized.unit; |
| 1097 String absoluteUri = unitResynthesized.unit.source.uri.toString(); | 1096 String absoluteUri = unit.source.uri.toString(); |
| 1098 resynthesizedUnits[absoluteUri] = unitResynthesized.unit; | 1097 resynthesizedUnits[absoluteUri] = unit; |
| 1099 } | 1098 } |
| 1100 } | 1099 } |
| 1101 | 1100 |
| 1102 /** | 1101 /** |
| 1103 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer]. | 1102 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer]. |
| 1104 */ | 1103 */ |
| 1105 class _LibraryResynthesizerContext implements LibraryResynthesizerContext { | 1104 class _LibraryResynthesizerContext implements LibraryResynthesizerContext { |
| 1106 final _LibraryResynthesizer resynthesizer; | 1105 final _LibraryResynthesizer resynthesizer; |
| 1107 | 1106 |
| 1108 _LibraryResynthesizerContext(this.resynthesizer); | 1107 _LibraryResynthesizerContext(this.resynthesizer); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 */ | 1415 */ |
| 1417 final LinkedUnit linkedUnit; | 1416 final LinkedUnit linkedUnit; |
| 1418 | 1417 |
| 1419 /** | 1418 /** |
| 1420 * The [CompilationUnitElementImpl] for the compilation unit currently being | 1419 * The [CompilationUnitElementImpl] for the compilation unit currently being |
| 1421 * resynthesized. | 1420 * resynthesized. |
| 1422 */ | 1421 */ |
| 1423 CompilationUnitElementImpl unit; | 1422 CompilationUnitElementImpl unit; |
| 1424 | 1423 |
| 1425 /** | 1424 /** |
| 1426 * [ElementHolder] into which resynthesized elements should be placed. This | |
| 1427 * object is recreated afresh for each unit in the library, and is used to | |
| 1428 * populate the [CompilationUnitElement]. | |
| 1429 */ | |
| 1430 final ElementHolder unitHolder = new ElementHolder(); | |
| 1431 | |
| 1432 /** | |
| 1433 * Map from slot id to the corresponding [EntityRef] object for linked types | 1425 * Map from slot id to the corresponding [EntityRef] object for linked types |
| 1434 * (i.e. propagated and inferred types). | 1426 * (i.e. propagated and inferred types). |
| 1435 */ | 1427 */ |
| 1436 final Map<int, EntityRef> linkedTypeMap = <int, EntityRef>{}; | 1428 final Map<int, EntityRef> linkedTypeMap = <int, EntityRef>{}; |
| 1437 | 1429 |
| 1438 /** | 1430 /** |
| 1439 * Set of slot ids corresponding to const constructors that are part of | 1431 * Set of slot ids corresponding to const constructors that are part of |
| 1440 * cycles. | 1432 * cycles. |
| 1441 */ | 1433 */ |
| 1442 Set<int> constCycles; | 1434 Set<int> constCycles; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 elementAnnotation.annotationAst = AstFactory.annotation2( | 1493 elementAnnotation.annotationAst = AstFactory.annotation2( |
| 1502 typeName, constructorName, constExpr.argumentList); | 1494 typeName, constructorName, constExpr.argumentList); |
| 1503 } else { | 1495 } else { |
| 1504 throw new StateError( | 1496 throw new StateError( |
| 1505 'Unexpected annotation type: ${constExpr.runtimeType}'); | 1497 'Unexpected annotation type: ${constExpr.runtimeType}'); |
| 1506 } | 1498 } |
| 1507 return elementAnnotation; | 1499 return elementAnnotation; |
| 1508 } | 1500 } |
| 1509 | 1501 |
| 1510 /** | 1502 /** |
| 1511 * Build the documentation for the given [element]. Does nothing if | |
| 1512 * [serializedDocumentationComment] is `null`. | |
| 1513 */ | |
| 1514 void buildDocumentation(ElementImpl element, | |
| 1515 UnlinkedDocumentationComment serializedDocumentationComment) { | |
| 1516 if (serializedDocumentationComment != null) { | |
| 1517 element.documentationComment = serializedDocumentationComment.text; | |
| 1518 element.setDocRange(serializedDocumentationComment.offset, | |
| 1519 serializedDocumentationComment.length); | |
| 1520 } | |
| 1521 } | |
| 1522 | |
| 1523 /** | |
| 1524 * Resynthesize the [ClassElement] corresponding to an enum, along with the | |
| 1525 * associated fields and implicit accessors. | |
| 1526 */ | |
| 1527 void buildEnum(UnlinkedEnum serializedEnum) { | |
| 1528 assert(!libraryResynthesizer.isCoreLibrary); | |
| 1529 EnumElementImpl classElement = | |
| 1530 new EnumElementImpl.forSerialized(serializedEnum, unit); | |
| 1531 unitHolder.addEnum(classElement); | |
| 1532 } | |
| 1533 | |
| 1534 /** | |
| 1535 * Build the implicit getter and setter associated with [element], and place | |
| 1536 * them in [holder]. | |
| 1537 */ | |
| 1538 void buildImplicitAccessors( | |
| 1539 PropertyInducingElementImpl element, ElementHolder holder) { | |
| 1540 PropertyAccessorElementImpl getter = buildImplicitGetter(element); | |
| 1541 holder?.addAccessor(getter); | |
| 1542 if (!(element.isConst || element.isFinal)) { | |
| 1543 PropertyAccessorElementImpl setter = buildImplicitSetter(element); | |
| 1544 holder?.addAccessor(setter); | |
| 1545 } | |
| 1546 } | |
| 1547 | |
| 1548 /** | |
| 1549 * Build an implicit getter for the given [property] and bind it to the | 1503 * Build an implicit getter for the given [property] and bind it to the |
| 1550 * [property] and to its enclosing element. | 1504 * [property] and to its enclosing element. |
| 1551 */ | 1505 */ |
| 1552 PropertyAccessorElementImpl buildImplicitGetter( | 1506 PropertyAccessorElementImpl buildImplicitGetter( |
| 1553 PropertyInducingElementImpl property) { | 1507 PropertyInducingElementImpl property) { |
| 1554 PropertyAccessorElementImpl_ImplicitGetter getter = | 1508 PropertyAccessorElementImpl_ImplicitGetter getter = |
| 1555 new PropertyAccessorElementImpl_ImplicitGetter(property); | 1509 new PropertyAccessorElementImpl_ImplicitGetter(property); |
| 1556 getter.enclosingElement = property.enclosingElement; | 1510 getter.enclosingElement = property.enclosingElement; |
| 1557 return getter; | 1511 return getter; |
| 1558 } | 1512 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 break; | 1760 break; |
| 1807 } | 1761 } |
| 1808 } | 1762 } |
| 1809 result = new _ReferenceInfo(libraryResynthesizer, enclosingInfo, name, | 1763 result = new _ReferenceInfo(libraryResynthesizer, enclosingInfo, name, |
| 1810 element, type, numTypeParameters); | 1764 element, type, numTypeParameters); |
| 1811 referenceInfos[index] = result; | 1765 referenceInfos[index] = result; |
| 1812 } | 1766 } |
| 1813 return result; | 1767 return result; |
| 1814 } | 1768 } |
| 1815 | 1769 |
| 1816 /** | |
| 1817 * Populate a [CompilationUnitElement] by deserializing all the elements | |
| 1818 * contained in it. | |
| 1819 */ | |
| 1820 void populateUnit() { | |
| 1821 unlinkedUnit.enums.forEach(buildEnum); | |
| 1822 unit.enums = unitHolder.enums; | |
| 1823 } | |
| 1824 | |
| 1825 Expression _buildConstExpression(ElementImpl context, UnlinkedConst uc) { | 1770 Expression _buildConstExpression(ElementImpl context, UnlinkedConst uc) { |
| 1826 return new _ConstExprBuilder(this, context, uc).build(); | 1771 return new _ConstExprBuilder(this, context, uc).build(); |
| 1827 } | 1772 } |
| 1828 | 1773 |
| 1829 /** | 1774 /** |
| 1830 * Return the defining type for a [ConstructorElement] by applying | 1775 * Return the defining type for a [ConstructorElement] by applying |
| 1831 * [typeArgumentRefs] to the given linked [info]. | 1776 * [typeArgumentRefs] to the given linked [info]. |
| 1832 */ | 1777 */ |
| 1833 DartType _createConstructorDefiningType( | 1778 DartType _createConstructorDefiningType( |
| 1834 TypeParameterizedElementMixin typeParameterContext, | 1779 TypeParameterizedElementMixin typeParameterContext, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 static String _getElementIdentifier(String name, ReferenceKind kind) { | 1836 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 1892 if (kind == ReferenceKind.topLevelPropertyAccessor || | 1837 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 1893 kind == ReferenceKind.propertyAccessor) { | 1838 kind == ReferenceKind.propertyAccessor) { |
| 1894 if (!name.endsWith('=')) { | 1839 if (!name.endsWith('=')) { |
| 1895 return name + '?'; | 1840 return name + '?'; |
| 1896 } | 1841 } |
| 1897 } | 1842 } |
| 1898 return name; | 1843 return name; |
| 1899 } | 1844 } |
| 1900 } | 1845 } |
| OLD | NEW |