| 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/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 _push( | 385 _push( |
| 386 AstFactory.conditionalExpression(condition, thenExpr, elseExpr)); | 386 AstFactory.conditionalExpression(condition, thenExpr, elseExpr)); |
| 387 break; | 387 break; |
| 388 // identical | 388 // identical |
| 389 case UnlinkedConstOperation.identical: | 389 case UnlinkedConstOperation.identical: |
| 390 Expression second = _pop(); | 390 Expression second = _pop(); |
| 391 Expression first = _pop(); | 391 Expression first = _pop(); |
| 392 _push(AstFactory.methodInvocation( | 392 _push(AstFactory.methodInvocation( |
| 393 null, 'identical', <Expression>[first, second])); | 393 null, 'identical', <Expression>[first, second])); |
| 394 break; | 394 break; |
| 395 // TODO(scheglov) complete implementation | 395 // TODO(scheglov) complete implementation |
| 396 case UnlinkedConstOperation.makeUntypedList: | 396 case UnlinkedConstOperation.makeUntypedList: |
| 397 case UnlinkedConstOperation.makeTypedList: | 397 case UnlinkedConstOperation.makeTypedList: |
| 398 case UnlinkedConstOperation.makeUntypedMap: | 398 case UnlinkedConstOperation.makeUntypedMap: |
| 399 case UnlinkedConstOperation.makeTypedMap: | 399 case UnlinkedConstOperation.makeTypedMap: |
| 400 case UnlinkedConstOperation.pushReference: | 400 case UnlinkedConstOperation.pushReference: |
| 401 case UnlinkedConstOperation.invokeConstructor: | 401 case UnlinkedConstOperation.invokeConstructor: |
| 402 case UnlinkedConstOperation.length: | 402 case UnlinkedConstOperation.length: |
| 403 return AstFactory.nullLiteral(); | 403 return AstFactory.nullLiteral(); |
| 404 // throw new StateError('Unsupported constant operation $operation'); | 404 // throw new StateError('Unsupported constant operation $operation'); |
| 405 } | 405 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 /** | 863 /** |
| 864 * Build an [ElementHandle] referring to the entity referred to by the given | 864 * Build an [ElementHandle] referring to the entity referred to by the given |
| 865 * [exportName]. | 865 * [exportName]. |
| 866 */ | 866 */ |
| 867 ElementHandle buildExportName(LinkedExportName exportName) { | 867 ElementHandle buildExportName(LinkedExportName exportName) { |
| 868 String name = exportName.name; | 868 String name = exportName.name; |
| 869 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor && | 869 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor && |
| 870 !name.endsWith('=')) { | 870 !name.endsWith('=')) { |
| 871 name += '?'; | 871 name += '?'; |
| 872 } | 872 } |
| 873 ElementLocationImpl location = getReferencedLocation( | 873 ElementLocationImpl location = new ElementLocationImpl.con3( |
| 874 linkedLibrary.dependencies[exportName.dependency], | 874 getReferencedLocationComponents( |
| 875 exportName.unit, | 875 exportName.dependency, exportName.unit, name)); |
| 876 name); | |
| 877 switch (exportName.kind) { | 876 switch (exportName.kind) { |
| 878 case ReferenceKind.classOrEnum: | 877 case ReferenceKind.classOrEnum: |
| 879 return new ClassElementHandle(summaryResynthesizer, location); | 878 return new ClassElementHandle(summaryResynthesizer, location); |
| 880 case ReferenceKind.typedef: | 879 case ReferenceKind.typedef: |
| 881 return new FunctionTypeAliasElementHandle( | 880 return new FunctionTypeAliasElementHandle( |
| 882 summaryResynthesizer, location); | 881 summaryResynthesizer, location); |
| 883 case ReferenceKind.topLevelFunction: | 882 case ReferenceKind.topLevelFunction: |
| 884 return new FunctionElementHandle(summaryResynthesizer, location); | 883 return new FunctionElementHandle(summaryResynthesizer, location); |
| 885 case ReferenceKind.topLevelPropertyAccessor: | 884 case ReferenceKind.topLevelPropertyAccessor: |
| 886 return new PropertyAccessorElementHandle( | 885 return new PropertyAccessorElementHandle( |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 * Finish creating a [TypeParameterElement] by deserializing its bound. | 1350 * Finish creating a [TypeParameterElement] by deserializing its bound. |
| 1352 */ | 1351 */ |
| 1353 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, | 1352 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, |
| 1354 TypeParameterElementImpl typeParameterElement) { | 1353 TypeParameterElementImpl typeParameterElement) { |
| 1355 if (serializedTypeParameter.bound != null) { | 1354 if (serializedTypeParameter.bound != null) { |
| 1356 typeParameterElement.bound = buildType(serializedTypeParameter.bound); | 1355 typeParameterElement.bound = buildType(serializedTypeParameter.bound); |
| 1357 } | 1356 } |
| 1358 } | 1357 } |
| 1359 | 1358 |
| 1360 /** | 1359 /** |
| 1361 * Build an [ElementLocationImpl] for the entity in the given [unit] of the | 1360 * Build the components of an [ElementLocationImpl] for the entity in the |
| 1362 * given [dependency], having the given [name]. | 1361 * given [unit] of the dependency located at [dependencyIndex], and having |
| 1362 * the given [name]. |
| 1363 */ | 1363 */ |
| 1364 ElementLocationImpl getReferencedLocation( | 1364 List<String> getReferencedLocationComponents( |
| 1365 LinkedDependency dependency, int unit, String name) { | 1365 int dependencyIndex, int unit, String name) { |
| 1366 if (dependencyIndex == 0) { |
| 1367 String referencedLibraryUri = librarySource.uri.toString(); |
| 1368 String partUri; |
| 1369 if (unit != 0) { |
| 1370 String uri = unlinkedUnits[0].publicNamespace.parts[unit - 1]; |
| 1371 Source partSource = |
| 1372 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); |
| 1373 partUri = partSource.uri.toString(); |
| 1374 } else { |
| 1375 partUri = referencedLibraryUri; |
| 1376 } |
| 1377 return <String>[referencedLibraryUri, partUri, name]; |
| 1378 } |
| 1379 LinkedDependency dependency = linkedLibrary.dependencies[dependencyIndex]; |
| 1366 Source referencedLibrarySource = summaryResynthesizer.sourceFactory | 1380 Source referencedLibrarySource = summaryResynthesizer.sourceFactory |
| 1367 .resolveUri(librarySource, dependency.uri); | 1381 .resolveUri(librarySource, dependency.uri); |
| 1368 String referencedLibraryUri = referencedLibrarySource.uri.toString(); | 1382 String referencedLibraryUri = referencedLibrarySource.uri.toString(); |
| 1369 // TODO(paulberry): consider changing Location format so that this is | 1383 // TODO(paulberry): consider changing Location format so that this is |
| 1370 // not necessary (2nd string in location should just be the unit | 1384 // not necessary (2nd string in location should just be the unit |
| 1371 // number). | 1385 // number). |
| 1372 String partUri; | 1386 String partUri; |
| 1373 if (unit != 0) { | 1387 if (unit != 0) { |
| 1374 UnlinkedUnit referencedLibraryDefiningUnit = | 1388 UnlinkedUnit referencedLibraryDefiningUnit = |
| 1375 summaryResynthesizer._getUnlinkedSummaryOrThrow(referencedLibraryUri); | 1389 summaryResynthesizer._getUnlinkedSummaryOrThrow(referencedLibraryUri); |
| 1376 String uri = | 1390 String uri = |
| 1377 referencedLibraryDefiningUnit.publicNamespace.parts[unit - 1]; | 1391 referencedLibraryDefiningUnit.publicNamespace.parts[unit - 1]; |
| 1378 Source partSource = summaryResynthesizer.sourceFactory | 1392 Source partSource = summaryResynthesizer.sourceFactory |
| 1379 .resolveUri(referencedLibrarySource, uri); | 1393 .resolveUri(referencedLibrarySource, uri); |
| 1380 partUri = partSource.uri.toString(); | 1394 partUri = partSource.uri.toString(); |
| 1381 } else { | 1395 } else { |
| 1382 partUri = referencedLibraryUri; | 1396 partUri = referencedLibraryUri; |
| 1383 } | 1397 } |
| 1384 return new ElementLocationImpl.con3( | 1398 return <String>[referencedLibraryUri, partUri, name]; |
| 1385 <String>[referencedLibraryUri, partUri, name]); | |
| 1386 } | 1399 } |
| 1387 | 1400 |
| 1388 /** | 1401 /** |
| 1389 * Populate [referenceInfos] with the correct information for the current | 1402 * Populate [referenceInfos] with the correct information for the current |
| 1390 * compilation unit. | 1403 * compilation unit. |
| 1391 */ | 1404 */ |
| 1392 void populateReferenceInfos() { | 1405 void populateReferenceInfos() { |
| 1393 int numLinkedReferences = linkedUnit.references.length; | 1406 int numLinkedReferences = linkedUnit.references.length; |
| 1394 int numUnlinkedReferences = unlinkedUnit.references.length; | 1407 int numUnlinkedReferences = unlinkedUnit.references.length; |
| 1395 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); | 1408 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); |
| 1396 for (int i = 0; i < numLinkedReferences; i++) { | 1409 for (int i = 0; i < numLinkedReferences; i++) { |
| 1397 LinkedReference linkedReference = linkedUnit.references[i]; | 1410 LinkedReference linkedReference = linkedUnit.references[i]; |
| 1398 String name; | 1411 String name; |
| 1399 if (i < numUnlinkedReferences) { | 1412 if (i < numUnlinkedReferences) { |
| 1400 name = unlinkedUnit.references[i].name; | 1413 name = unlinkedUnit.references[i].name; |
| 1401 } else { | 1414 } else { |
| 1402 name = linkedUnit.references[i].name; | 1415 name = linkedUnit.references[i].name; |
| 1403 } | 1416 } |
| 1404 ElementHandle element; | 1417 ElementHandle element; |
| 1405 DartType type; | 1418 DartType type; |
| 1406 if (linkedReference.kind == ReferenceKind.unresolved) { | 1419 if (linkedReference.kind == ReferenceKind.unresolved) { |
| 1407 type = summaryResynthesizer.typeProvider.undefinedType; | 1420 type = summaryResynthesizer.typeProvider.undefinedType; |
| 1408 } else if (name == 'dynamic') { | 1421 } else if (name == 'dynamic') { |
| 1409 type = summaryResynthesizer.typeProvider.dynamicType; | 1422 type = summaryResynthesizer.typeProvider.dynamicType; |
| 1410 } else if (name == 'void') { | 1423 } else if (name == 'void') { |
| 1411 type = VoidTypeImpl.instance; | 1424 type = VoidTypeImpl.instance; |
| 1412 } else { | 1425 } else { |
| 1413 ElementLocation location; | 1426 ElementLocation location = new ElementLocationImpl.con3( |
| 1414 if (linkedReference.dependency != 0) { | 1427 getReferencedLocationComponents( |
| 1415 location = getReferencedLocation( | 1428 linkedReference.dependency, linkedReference.unit, name)); |
| 1416 linkedLibrary.dependencies[linkedReference.dependency], | |
| 1417 linkedReference.unit, | |
| 1418 name); | |
| 1419 } else { | |
| 1420 String referencedLibraryUri = librarySource.uri.toString(); | |
| 1421 String partUri; | |
| 1422 if (linkedReference.unit != 0) { | |
| 1423 String uri = unlinkedUnits[0].publicNamespace.parts[ | |
| 1424 linkedReference.unit - 1]; | |
| 1425 Source partSource = summaryResynthesizer.sourceFactory | |
| 1426 .resolveUri(librarySource, uri); | |
| 1427 partUri = partSource.uri.toString(); | |
| 1428 } else { | |
| 1429 partUri = referencedLibraryUri; | |
| 1430 } | |
| 1431 location = new ElementLocationImpl.con3( | |
| 1432 <String>[referencedLibraryUri, partUri, name]); | |
| 1433 } | |
| 1434 switch (linkedReference.kind) { | 1429 switch (linkedReference.kind) { |
| 1435 case ReferenceKind.classOrEnum: | 1430 case ReferenceKind.classOrEnum: |
| 1436 element = new ClassElementHandle(summaryResynthesizer, location); | 1431 element = new ClassElementHandle(summaryResynthesizer, location); |
| 1437 break; | 1432 break; |
| 1438 case ReferenceKind.typedef: | 1433 case ReferenceKind.typedef: |
| 1439 element = new FunctionTypeAliasElementHandle( | 1434 element = new FunctionTypeAliasElementHandle( |
| 1440 summaryResynthesizer, location); | 1435 summaryResynthesizer, location); |
| 1441 break; | 1436 break; |
| 1442 default: | 1437 default: |
| 1443 // This is an element that doesn't (yet) need to be referred to | 1438 // This is an element that doesn't (yet) need to be referred to |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 return new InterfaceTypeImpl.elementWithNameAndArgs( | 1589 return new InterfaceTypeImpl.elementWithNameAndArgs( |
| 1595 element, name, typeArguments); | 1590 element, name, typeArguments); |
| 1596 } else if (element is FunctionTypeAliasElementHandle) { | 1591 } else if (element is FunctionTypeAliasElementHandle) { |
| 1597 return new FunctionTypeImpl.elementWithNameAndArgs( | 1592 return new FunctionTypeImpl.elementWithNameAndArgs( |
| 1598 element, name, typeArguments, typeArguments.isNotEmpty); | 1593 element, name, typeArguments, typeArguments.isNotEmpty); |
| 1599 } else { | 1594 } else { |
| 1600 return null; | 1595 return null; |
| 1601 } | 1596 } |
| 1602 } | 1597 } |
| 1603 } | 1598 } |
| OLD | NEW |