Chromium Code Reviews| 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 if (info.element == null) { | |
|
Paul Berry
2016/02/16 20:44:10
Remove this case (it's unreachable since we alread
scheglov
2016/02/16 21:48:44
Done.
| |
| 535 constructorName = null; | |
| 536 } else { | |
| 537 throw new StateError('Unsupported element for invokeConstructor ' | |
| 538 '${info.element?.runtimeType}'); | |
| 539 } | |
| 540 InterfaceType definingType = | |
| 541 resynthesizer._createConstructorDefiningType(info, ref.typeArguments); | |
| 542 constructorElement = | |
| 543 resynthesizer._createConstructorElement(definingType, info); | |
| 544 typeNode = _buildTypeAst(definingType); | |
| 531 } else { | 545 } else { |
| 532 throw new StateError('Unsupported element for invokeConstructor ' | 546 if (info.enclosing != null) { |
| 533 '${info.element?.runtimeType}'); | 547 if (info.enclosing.element != null) { |
| 548 SimpleIdentifier typeName = | |
| 549 AstFactory.identifier3(info.enclosing.name); | |
| 550 typeName.staticElement = info.enclosing.element; | |
| 551 typeName.staticType = info.enclosing.type; | |
| 552 typeNode = AstFactory.typeName3(typeName); | |
| 553 typeNode.type = info.enclosing.type; | |
| 554 constructorName = info.name; | |
| 555 } else { | |
| 556 typeNode = AstFactory.typeName3( | |
| 557 AstFactory.identifier5(info.enclosing.name, info.name)); | |
| 558 constructorName = null; | |
| 559 } | |
| 560 } else { | |
| 561 typeNode = AstFactory.typeName4(info.name); | |
| 562 } | |
| 534 } | 563 } |
| 535 InterfaceType definingType = | |
| 536 resynthesizer._createConstructorDefiningType(info, ref.typeArguments); | |
| 537 ConstructorElement constructorElement = | |
| 538 resynthesizer._createConstructorElement(definingType, info); | |
| 539 // prepare arguments | 564 // prepare arguments |
| 540 List<Expression> arguments; | 565 List<Expression> arguments; |
| 541 { | 566 { |
| 542 int numNamedArgs = uc.ints[intPtr++]; | 567 int numNamedArgs = uc.ints[intPtr++]; |
| 543 int numPositionalArgs = uc.ints[intPtr++]; | 568 int numPositionalArgs = uc.ints[intPtr++]; |
| 544 int numArgs = numNamedArgs + numPositionalArgs; | 569 int numArgs = numNamedArgs + numPositionalArgs; |
| 545 arguments = _removeTopItems(numArgs); | 570 arguments = _removeTopItems(numArgs); |
| 546 // add names to the named arguments | 571 // add names to the named arguments |
| 547 for (int i = 0; i < numNamedArgs; i++) { | 572 for (int i = 0; i < numNamedArgs; i++) { |
| 548 String name = uc.strings[stringPtr++]; | 573 String name = uc.strings[stringPtr++]; |
| 549 int index = numPositionalArgs + i; | 574 int index = numPositionalArgs + i; |
| 550 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); | 575 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); |
| 551 } | 576 } |
| 552 } | 577 } |
| 553 // create TypeName | |
| 554 TypeName typeNode = _buildTypeAst(definingType); | |
| 555 // create ConstructorName | 578 // create ConstructorName |
| 556 ConstructorName constructorNode; | 579 ConstructorName constructorNode; |
| 557 if (constructorName != null) { | 580 if (constructorName != null) { |
| 558 constructorNode = AstFactory.constructorName(typeNode, constructorName); | 581 constructorNode = AstFactory.constructorName(typeNode, constructorName); |
| 559 constructorNode.name.staticElement = constructorElement; | 582 constructorNode.name.staticElement = constructorElement; |
| 560 } else { | 583 } else { |
| 561 constructorNode = AstFactory.constructorName(typeNode, null); | 584 constructorNode = AstFactory.constructorName(typeNode, null); |
| 562 } | 585 } |
| 563 constructorNode.staticElement = constructorElement; | 586 constructorNode.staticElement = constructorElement; |
| 564 // create InstanceCreationExpression | 587 // create InstanceCreationExpression |
| (...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1818 /** | 1841 /** |
| 1819 * Populate [referenceInfos] with the correct information for the current | 1842 * Populate [referenceInfos] with the correct information for the current |
| 1820 * compilation unit. | 1843 * compilation unit. |
| 1821 */ | 1844 */ |
| 1822 void populateReferenceInfos() { | 1845 void populateReferenceInfos() { |
| 1823 int numLinkedReferences = linkedUnit.references.length; | 1846 int numLinkedReferences = linkedUnit.references.length; |
| 1824 int numUnlinkedReferences = unlinkedUnit.references.length; | 1847 int numUnlinkedReferences = unlinkedUnit.references.length; |
| 1825 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); | 1848 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); |
| 1826 for (int i = 0; i < numLinkedReferences; i++) { | 1849 for (int i = 0; i < numLinkedReferences; i++) { |
| 1827 LinkedReference linkedReference = linkedUnit.references[i]; | 1850 LinkedReference linkedReference = linkedUnit.references[i]; |
| 1828 _ReferenceInfo enclosingInfo = null; | |
| 1829 String name; | 1851 String name; |
| 1830 int containingReference; | 1852 int containingReference; |
| 1831 if (i < numUnlinkedReferences) { | 1853 if (i < numUnlinkedReferences) { |
| 1832 name = unlinkedUnit.references[i].name; | 1854 name = unlinkedUnit.references[i].name; |
| 1833 containingReference = unlinkedUnit.references[i].prefixReference; | 1855 containingReference = unlinkedUnit.references[i].prefixReference; |
| 1834 } else { | 1856 } else { |
| 1835 name = linkedUnit.references[i].name; | 1857 name = linkedUnit.references[i].name; |
| 1836 containingReference = linkedUnit.references[i].containingReference; | 1858 containingReference = linkedUnit.references[i].containingReference; |
| 1837 } | 1859 } |
| 1860 _ReferenceInfo enclosingInfo = | |
| 1861 containingReference != 0 ? referenceInfos[containingReference] : null; | |
| 1838 Element element; | 1862 Element element; |
| 1839 DartType type; | 1863 DartType type; |
| 1840 int numTypeParameters = linkedReference.numTypeParameters; | 1864 int numTypeParameters = linkedReference.numTypeParameters; |
| 1841 if (linkedReference.kind == ReferenceKind.unresolved) { | 1865 if (linkedReference.kind == ReferenceKind.unresolved) { |
| 1842 type = summaryResynthesizer.typeProvider.undefinedType; | 1866 type = summaryResynthesizer.typeProvider.undefinedType; |
| 1843 element = null; | 1867 element = null; |
| 1844 } else if (name == 'dynamic') { | 1868 } else if (name == 'dynamic') { |
| 1845 type = summaryResynthesizer.typeProvider.dynamicType; | 1869 type = summaryResynthesizer.typeProvider.dynamicType; |
| 1846 element = type.element; | 1870 element = type.element; |
| 1847 } else if (name == 'void') { | 1871 } else if (name == 'void') { |
| 1848 type = VoidTypeImpl.instance; | 1872 type = VoidTypeImpl.instance; |
| 1849 element = type.element; | 1873 element = type.element; |
| 1850 } else { | 1874 } else { |
| 1851 List<String> locationComponents; | 1875 List<String> locationComponents; |
| 1852 if (containingReference != 0 && | 1876 if (enclosingInfo != null && enclosingInfo.element is ClassElement) { |
| 1853 referenceInfos[containingReference].element is ClassElement) { | |
| 1854 String identifier = _getElementIdentifier(name, linkedReference.kind); | 1877 String identifier = _getElementIdentifier(name, linkedReference.kind); |
| 1855 enclosingInfo = referenceInfos[containingReference]; | |
| 1856 locationComponents = | 1878 locationComponents = |
| 1857 enclosingInfo.element.location.components.toList(); | 1879 enclosingInfo.element.location.components.toList(); |
| 1858 locationComponents.add(identifier); | 1880 locationComponents.add(identifier); |
| 1859 } else { | 1881 } else { |
| 1860 String identifier = _getElementIdentifier(name, linkedReference.kind); | 1882 String identifier = _getElementIdentifier(name, linkedReference.kind); |
| 1861 locationComponents = getReferencedLocationComponents( | 1883 locationComponents = getReferencedLocationComponents( |
| 1862 linkedReference.dependency, linkedReference.unit, identifier); | 1884 linkedReference.dependency, linkedReference.unit, identifier); |
| 1863 } | 1885 } |
| 1864 ElementLocation location = | 1886 ElementLocation location = |
| 1865 new ElementLocationImpl.con3(locationComponents); | 1887 new ElementLocationImpl.con3(locationComponents); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2178 } | 2200 } |
| 2179 : () => this.element; | 2201 : () => this.element; |
| 2180 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2202 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2181 // isInstantiated? | 2203 // isInstantiated? |
| 2182 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2204 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2183 } else { | 2205 } else { |
| 2184 return null; | 2206 return null; |
| 2185 } | 2207 } |
| 2186 } | 2208 } |
| 2187 } | 2209 } |
| OLD | NEW |