| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 void _pushBinary(TokenType operator) { | 516 void _pushBinary(TokenType operator) { |
| 517 Expression right = _pop(); | 517 Expression right = _pop(); |
| 518 Expression left = _pop(); | 518 Expression left = _pop(); |
| 519 _push(AstFactory.binaryExpression(left, operator, right)); | 519 _push(AstFactory.binaryExpression(left, operator, right)); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void _pushInstanceCreation() { | 522 void _pushInstanceCreation() { |
| 523 EntityRef ref = uc.references[refPtr++]; | 523 EntityRef ref = uc.references[refPtr++]; |
| 524 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference]; | 524 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference]; |
| 525 // prepare ConstructorElement | 525 // prepare ConstructorElement |
| 526 TypeName typeNode; |
| 526 String constructorName; | 527 String constructorName; |
| 527 if (info.element is ConstructorElement) { | 528 ConstructorElement constructorElement; |
| 528 constructorName = info.name; | 529 if (info.element != null) { |
| 529 } else if (info.element is ClassElement) { | 530 if (info.element is ConstructorElement) { |
| 530 constructorName = null; | 531 constructorName = info.name; |
| 532 } else if (info.element is ClassElement) { |
| 533 constructorName = null; |
| 534 } else { |
| 535 throw new StateError('Unsupported element for invokeConstructor ' |
| 536 '${info.element?.runtimeType}'); |
| 537 } |
| 538 InterfaceType definingType = |
| 539 resynthesizer._createConstructorDefiningType(info, ref.typeArguments); |
| 540 constructorElement = |
| 541 resynthesizer._createConstructorElement(definingType, info); |
| 542 typeNode = _buildTypeAst(definingType); |
| 531 } else { | 543 } else { |
| 532 throw new StateError('Unsupported element for invokeConstructor ' | 544 if (info.enclosing != null) { |
| 533 '${info.element?.runtimeType}'); | 545 if (info.enclosing.enclosing != null) { |
| 546 PrefixedIdentifier typeName = AstFactory.identifier5( |
| 547 info.enclosing.enclosing.name, info.enclosing.name); |
| 548 typeName.prefix.staticElement = info.enclosing.enclosing.element; |
| 549 typeName.identifier.staticElement = info.enclosing.element; |
| 550 typeName.identifier.staticType = info.enclosing.type; |
| 551 typeNode = AstFactory.typeName3(typeName); |
| 552 typeNode.type = info.enclosing.type; |
| 553 constructorName = info.name; |
| 554 } else if (info.enclosing.element != null) { |
| 555 SimpleIdentifier typeName = |
| 556 AstFactory.identifier3(info.enclosing.name); |
| 557 typeName.staticElement = info.enclosing.element; |
| 558 typeName.staticType = info.enclosing.type; |
| 559 typeNode = AstFactory.typeName3(typeName); |
| 560 typeNode.type = info.enclosing.type; |
| 561 constructorName = info.name; |
| 562 } else { |
| 563 typeNode = AstFactory.typeName3( |
| 564 AstFactory.identifier5(info.enclosing.name, info.name)); |
| 565 constructorName = null; |
| 566 } |
| 567 } else { |
| 568 typeNode = AstFactory.typeName4(info.name); |
| 569 } |
| 534 } | 570 } |
| 535 InterfaceType definingType = | |
| 536 resynthesizer._createConstructorDefiningType(info, ref.typeArguments); | |
| 537 ConstructorElement constructorElement = | |
| 538 resynthesizer._createConstructorElement(definingType, info); | |
| 539 // prepare arguments | 571 // prepare arguments |
| 540 List<Expression> arguments; | 572 List<Expression> arguments; |
| 541 { | 573 { |
| 542 int numNamedArgs = uc.ints[intPtr++]; | 574 int numNamedArgs = uc.ints[intPtr++]; |
| 543 int numPositionalArgs = uc.ints[intPtr++]; | 575 int numPositionalArgs = uc.ints[intPtr++]; |
| 544 int numArgs = numNamedArgs + numPositionalArgs; | 576 int numArgs = numNamedArgs + numPositionalArgs; |
| 545 arguments = _removeTopItems(numArgs); | 577 arguments = _removeTopItems(numArgs); |
| 546 // add names to the named arguments | 578 // add names to the named arguments |
| 547 for (int i = 0; i < numNamedArgs; i++) { | 579 for (int i = 0; i < numNamedArgs; i++) { |
| 548 String name = uc.strings[stringPtr++]; | 580 String name = uc.strings[stringPtr++]; |
| 549 int index = numPositionalArgs + i; | 581 int index = numPositionalArgs + i; |
| 550 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); | 582 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); |
| 551 } | 583 } |
| 552 } | 584 } |
| 553 // create TypeName | |
| 554 TypeName typeNode = _buildTypeAst(definingType); | |
| 555 // create ConstructorName | 585 // create ConstructorName |
| 556 ConstructorName constructorNode; | 586 ConstructorName constructorNode; |
| 557 if (constructorName != null) { | 587 if (constructorName != null) { |
| 558 constructorNode = AstFactory.constructorName(typeNode, constructorName); | 588 constructorNode = AstFactory.constructorName(typeNode, constructorName); |
| 559 constructorNode.name.staticElement = constructorElement; | 589 constructorNode.name.staticElement = constructorElement; |
| 560 } else { | 590 } else { |
| 561 constructorNode = AstFactory.constructorName(typeNode, null); | 591 constructorNode = AstFactory.constructorName(typeNode, null); |
| 562 } | 592 } |
| 563 constructorNode.staticElement = constructorElement; | 593 constructorNode.staticElement = constructorElement; |
| 564 // create InstanceCreationExpression | 594 // create InstanceCreationExpression |
| (...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 /** | 1848 /** |
| 1819 * Populate [referenceInfos] with the correct information for the current | 1849 * Populate [referenceInfos] with the correct information for the current |
| 1820 * compilation unit. | 1850 * compilation unit. |
| 1821 */ | 1851 */ |
| 1822 void populateReferenceInfos() { | 1852 void populateReferenceInfos() { |
| 1823 int numLinkedReferences = linkedUnit.references.length; | 1853 int numLinkedReferences = linkedUnit.references.length; |
| 1824 int numUnlinkedReferences = unlinkedUnit.references.length; | 1854 int numUnlinkedReferences = unlinkedUnit.references.length; |
| 1825 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); | 1855 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); |
| 1826 for (int i = 0; i < numLinkedReferences; i++) { | 1856 for (int i = 0; i < numLinkedReferences; i++) { |
| 1827 LinkedReference linkedReference = linkedUnit.references[i]; | 1857 LinkedReference linkedReference = linkedUnit.references[i]; |
| 1828 _ReferenceInfo enclosingInfo = null; | |
| 1829 String name; | 1858 String name; |
| 1830 int containingReference; | 1859 int containingReference; |
| 1831 if (i < numUnlinkedReferences) { | 1860 if (i < numUnlinkedReferences) { |
| 1832 name = unlinkedUnit.references[i].name; | 1861 name = unlinkedUnit.references[i].name; |
| 1833 containingReference = unlinkedUnit.references[i].prefixReference; | 1862 containingReference = unlinkedUnit.references[i].prefixReference; |
| 1834 } else { | 1863 } else { |
| 1835 name = linkedUnit.references[i].name; | 1864 name = linkedUnit.references[i].name; |
| 1836 containingReference = linkedUnit.references[i].containingReference; | 1865 containingReference = linkedUnit.references[i].containingReference; |
| 1837 } | 1866 } |
| 1867 _ReferenceInfo enclosingInfo = |
| 1868 containingReference != 0 ? referenceInfos[containingReference] : null; |
| 1838 Element element; | 1869 Element element; |
| 1839 DartType type; | 1870 DartType type; |
| 1840 int numTypeParameters = linkedReference.numTypeParameters; | 1871 int numTypeParameters = linkedReference.numTypeParameters; |
| 1841 if (linkedReference.kind == ReferenceKind.unresolved) { | 1872 if (linkedReference.kind == ReferenceKind.unresolved) { |
| 1842 type = summaryResynthesizer.typeProvider.undefinedType; | 1873 type = summaryResynthesizer.typeProvider.undefinedType; |
| 1843 element = null; | 1874 element = null; |
| 1844 } else if (name == 'dynamic') { | 1875 } else if (name == 'dynamic') { |
| 1845 type = summaryResynthesizer.typeProvider.dynamicType; | 1876 type = summaryResynthesizer.typeProvider.dynamicType; |
| 1846 element = type.element; | 1877 element = type.element; |
| 1847 } else if (name == 'void') { | 1878 } else if (name == 'void') { |
| 1848 type = VoidTypeImpl.instance; | 1879 type = VoidTypeImpl.instance; |
| 1849 element = type.element; | 1880 element = type.element; |
| 1850 } else { | 1881 } else { |
| 1851 List<String> locationComponents; | 1882 List<String> locationComponents; |
| 1852 if (containingReference != 0 && | 1883 if (enclosingInfo != null && enclosingInfo.element is ClassElement) { |
| 1853 referenceInfos[containingReference].element is ClassElement) { | |
| 1854 String identifier = _getElementIdentifier(name, linkedReference.kind); | 1884 String identifier = _getElementIdentifier(name, linkedReference.kind); |
| 1855 enclosingInfo = referenceInfos[containingReference]; | |
| 1856 locationComponents = | 1885 locationComponents = |
| 1857 enclosingInfo.element.location.components.toList(); | 1886 enclosingInfo.element.location.components.toList(); |
| 1858 locationComponents.add(identifier); | 1887 locationComponents.add(identifier); |
| 1859 } else { | 1888 } else { |
| 1860 String identifier = _getElementIdentifier(name, linkedReference.kind); | 1889 String identifier = _getElementIdentifier(name, linkedReference.kind); |
| 1861 locationComponents = getReferencedLocationComponents( | 1890 locationComponents = getReferencedLocationComponents( |
| 1862 linkedReference.dependency, linkedReference.unit, identifier); | 1891 linkedReference.dependency, linkedReference.unit, identifier); |
| 1863 } | 1892 } |
| 1864 ElementLocation location = | 1893 ElementLocation location = |
| 1865 new ElementLocationImpl.con3(locationComponents); | 1894 new ElementLocationImpl.con3(locationComponents); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 } | 2207 } |
| 2179 : () => this.element; | 2208 : () => this.element; |
| 2180 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2209 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2181 // isInstantiated? | 2210 // isInstantiated? |
| 2182 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2211 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2183 } else { | 2212 } else { |
| 2184 return null; | 2213 return null; |
| 2185 } | 2214 } |
| 2186 } | 2215 } |
| 2187 } | 2216 } |
| OLD | NEW |