Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1652183002: Resynthesize top-level and class static property access references. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 _pushMap(null); 406 _pushMap(null);
407 break; 407 break;
408 case UnlinkedConstOperation.makeTypedMap: 408 case UnlinkedConstOperation.makeTypedMap:
409 TypeName keyType = _newTypeName(); 409 TypeName keyType = _newTypeName();
410 TypeName valueType = _newTypeName(); 410 TypeName valueType = _newTypeName();
411 _pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType])); 411 _pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType]));
412 break; 412 break;
413 case UnlinkedConstOperation.pushReference: 413 case UnlinkedConstOperation.pushReference:
414 EntityRef ref = uc.references[refPtr++]; 414 EntityRef ref = uc.references[refPtr++];
415 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference]; 415 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference];
416 if (info.type != null) { 416 if (info.element != null) {
417 Identifier node = _buildTypeIdentifierAst(info.type); 417 Identifier node = _buildElementAst(info.name, info.element);
418 _push(node);
419 } else if (info.type != null) {
420 Identifier node = _buildElementAst(info.name, info.type.element);
Paul Berry 2016/02/01 19:27:16 I bet this case (info.element == null but info.typ
scheglov 2016/02/01 19:42:18 I will try to simplify this in the next CL.
418 _push(node); 421 _push(node);
419 } else { 422 } else {
420 throw new StateError( 423 throw new StateError('Unsupported reference ${ref.toMap()}');
421 'Unsupported reference ${info.element?.runtimeType}');
422 } 424 }
423 break; 425 break;
424 case UnlinkedConstOperation.invokeConstructor: 426 case UnlinkedConstOperation.invokeConstructor:
425 case UnlinkedConstOperation.length: 427 case UnlinkedConstOperation.length:
426 return AstFactory.nullLiteral(); 428 return AstFactory.nullLiteral();
427 // throw new StateError('Unsupported constant operation $operation'); 429 // throw new StateError('Unsupported constant operation $operation');
428 } 430 }
429 } 431 }
430 return stack.single; 432 return stack.single;
431 } 433 }
432 434
435 Identifier _buildElementAst(String name, Element element) {
436 SimpleIdentifier node = AstFactory.identifier3(name);
437 node.staticElement = element;
438 return node;
439 }
440
433 TypeName _buildTypeAst(DartType type) { 441 TypeName _buildTypeAst(DartType type) {
434 if (type is DynamicTypeImpl) { 442 if (type is DynamicTypeImpl) {
435 TypeName node = AstFactory.typeName4('dynamic'); 443 TypeName node = AstFactory.typeName4('dynamic');
436 node.type = type; 444 node.type = type;
437 (node.name as SimpleIdentifier).staticElement = type.element; 445 (node.name as SimpleIdentifier).staticElement = type.element;
438 return node; 446 return node;
439 } else if (type is InterfaceType) { 447 } else if (type is InterfaceType) {
440 List<TypeName> argumentNodes = 448 List<TypeName> argumentNodes =
441 type.typeArguments.map(_buildTypeAst).toList(); 449 type.typeArguments.map(_buildTypeAst).toList();
442 TypeName node = AstFactory.typeName4(type.name, argumentNodes); 450 TypeName node = AstFactory.typeName4(type.name, argumentNodes);
443 node.type = type; 451 node.type = type;
444 (node.name as SimpleIdentifier).staticElement = type.element; 452 (node.name as SimpleIdentifier).staticElement = type.element;
445 return node; 453 return node;
446 } 454 }
447 throw new StateError('Unsupported type $type'); 455 throw new StateError('Unsupported type $type');
448 } 456 }
449 457
450 Identifier _buildTypeIdentifierAst(DartType type) {
451 String name = type.name;
452 SimpleIdentifier node = AstFactory.identifier3(name);
453 node.staticElement = type.element;
454 return node;
455 }
456
457 InterpolationElement _newInterpolationElement(Expression expr) { 458 InterpolationElement _newInterpolationElement(Expression expr) {
458 if (expr is SimpleStringLiteral) { 459 if (expr is SimpleStringLiteral) {
459 return new InterpolationString(expr.literal, expr.value); 460 return new InterpolationString(expr.literal, expr.value);
460 } else { 461 } else {
461 return new InterpolationExpression( 462 return new InterpolationExpression(
462 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), 463 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION),
463 expr, 464 expr,
464 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 465 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
465 } 466 }
466 } 467 }
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 if (linkedReference.kind == ReferenceKind.unresolved) { 1473 if (linkedReference.kind == ReferenceKind.unresolved) {
1473 type = summaryResynthesizer.typeProvider.undefinedType; 1474 type = summaryResynthesizer.typeProvider.undefinedType;
1474 } else if (name == 'dynamic') { 1475 } else if (name == 'dynamic') {
1475 type = summaryResynthesizer.typeProvider.dynamicType; 1476 type = summaryResynthesizer.typeProvider.dynamicType;
1476 } else if (name == 'void') { 1477 } else if (name == 'void') {
1477 type = VoidTypeImpl.instance; 1478 type = VoidTypeImpl.instance;
1478 } else { 1479 } else {
1479 List<String> locationComponents; 1480 List<String> locationComponents;
1480 if (containingReference != 0 && 1481 if (containingReference != 0 &&
1481 referenceInfos[containingReference].element is ClassElement) { 1482 referenceInfos[containingReference].element is ClassElement) {
1483 String identifier = _getElementIdentifier(name, linkedReference.kind);
1482 locationComponents = referenceInfos[containingReference] 1484 locationComponents = referenceInfos[containingReference]
1483 .element 1485 .element
1484 .location 1486 .location
1485 .components 1487 .components
1486 .toList(); 1488 .toList();
1487 locationComponents.add(name); 1489 locationComponents.add(identifier);
1488 } else { 1490 } else {
1491 String identifier = _getElementIdentifier(name, linkedReference.kind);
1489 locationComponents = getReferencedLocationComponents( 1492 locationComponents = getReferencedLocationComponents(
1490 linkedReference.dependency, linkedReference.unit, name); 1493 linkedReference.dependency, linkedReference.unit, identifier);
1491 } 1494 }
1492 ElementLocation location = 1495 ElementLocation location =
1493 new ElementLocationImpl.con3(locationComponents); 1496 new ElementLocationImpl.con3(locationComponents);
1494 switch (linkedReference.kind) { 1497 switch (linkedReference.kind) {
1495 case ReferenceKind.classOrEnum: 1498 case ReferenceKind.classOrEnum:
1496 element = new ClassElementHandle(summaryResynthesizer, location); 1499 element = new ClassElementHandle(summaryResynthesizer, location);
1497 break; 1500 break;
1498 case ReferenceKind.typedef: 1501 case ReferenceKind.typedef:
1499 element = new FunctionTypeAliasElementHandle( 1502 element = new FunctionTypeAliasElementHandle(
1500 summaryResynthesizer, location); 1503 summaryResynthesizer, location);
1501 break; 1504 break;
1505 case ReferenceKind.topLevelPropertyAccessor:
1506 element = new PropertyAccessorElementHandle(
1507 summaryResynthesizer, location);
1508 break;
1502 case ReferenceKind.propertyAccessor: 1509 case ReferenceKind.propertyAccessor:
1503 assert(location.components.length == 4); 1510 assert(location.components.length == 4);
1504 element = new PropertyAccessorElementHandle( 1511 element = new PropertyAccessorElementHandle(
1505 summaryResynthesizer, location); 1512 summaryResynthesizer, location);
1506 break; 1513 break;
1507 case ReferenceKind.method: 1514 case ReferenceKind.method:
1508 assert(location.components.length == 4); 1515 assert(location.components.length == 4);
1509 element = new MethodElementHandle(summaryResynthesizer, location); 1516 element = new MethodElementHandle(summaryResynthesizer, location);
1510 break; 1517 break;
1511 default: 1518 default:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1574 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1568 elementMap[accessor.identifier] = accessor; 1575 elementMap[accessor.identifier] = accessor;
1569 } 1576 }
1570 resummarizedElements[absoluteUri] = elementMap; 1577 resummarizedElements[absoluteUri] = elementMap;
1571 unitHolder = null; 1578 unitHolder = null;
1572 linkedUnit = null; 1579 linkedUnit = null;
1573 unlinkedUnit = null; 1580 unlinkedUnit = null;
1574 linkedTypeMap = null; 1581 linkedTypeMap = null;
1575 referenceInfos = null; 1582 referenceInfos = null;
1576 } 1583 }
1584
1585 /**
1586 * If the given [kind] is a top-level or class member property accessor, and
1587 * the given [name] does not end with `=`, i.e. does not denote a setter,
1588 * return the getter identifier by appending `?`.
1589 */
1590 static String _getElementIdentifier(String name, ReferenceKind kind) {
1591 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1592 kind == ReferenceKind.propertyAccessor) {
1593 if (!name.endsWith('=')) {
1594 return name + '?';
1595 }
1596 }
1597 return name;
1598 }
1577 } 1599 }
1578 1600
1579 /** 1601 /**
1580 * Data structure used during resynthesis to record all the information that is 1602 * Data structure used during resynthesis to record all the information that is
1581 * known about how to reserialize a single entry in [LinkedUnit.references] 1603 * known about how to resynthesize a single entry in [LinkedUnit.references]
1582 * (and its associated entry in [UnlinkedUnit.references], if it exists). 1604 * (and its associated entry in [UnlinkedUnit.references], if it exists).
1583 */ 1605 */
1584 class _ReferenceInfo { 1606 class _ReferenceInfo {
1585 /** 1607 /**
1586 * The name of the entity referred to by this reference. 1608 * The name of the entity referred to by this reference.
1587 */ 1609 */
1588 final String name; 1610 final String name;
1589 1611
1590 /** 1612 /**
1591 * The element referred to by this reference, or `null` if there is no 1613 * The element referred to by this reference, or `null` if there is no
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 return element; 1709 return element;
1688 }; 1710 };
1689 // TODO(paulberry): Is it a bug that we have to pass `false` for 1711 // TODO(paulberry): Is it a bug that we have to pass `false` for
1690 // isInstantiated? 1712 // isInstantiated?
1691 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 1713 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
1692 } else { 1714 } else {
1693 return null; 1715 return null;
1694 } 1716 }
1695 } 1717 }
1696 } 1718 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698