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/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 break; | 404 break; |
| 405 case UnlinkedConstOperation.makeUntypedMap: | 405 case UnlinkedConstOperation.makeUntypedMap: |
| 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++]; | |
| 415 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference]; | |
| 416 if (info.type != null) { | |
|
Paul Berry
2016/01/31 13:41:02
This won't work properly if the class in question
scheglov
2016/01/31 18:55:29
Done.
| |
| 417 Identifier node = _buildTypeIdentifierAst(info.type); | |
| 418 _push(node); | |
| 419 } else { | |
| 420 throw new StateError( | |
| 421 'Unsupported reference ${info.element?.runtimeType}'); | |
| 422 } | |
| 423 break; | |
| 414 case UnlinkedConstOperation.invokeConstructor: | 424 case UnlinkedConstOperation.invokeConstructor: |
| 415 case UnlinkedConstOperation.length: | 425 case UnlinkedConstOperation.length: |
| 416 return AstFactory.nullLiteral(); | 426 return AstFactory.nullLiteral(); |
| 417 // throw new StateError('Unsupported constant operation $operation'); | 427 // throw new StateError('Unsupported constant operation $operation'); |
| 418 } | 428 } |
| 419 } | 429 } |
| 420 return stack.single; | 430 return stack.single; |
| 421 } | 431 } |
| 422 | 432 |
| 423 TypeName _buildTypeAst(DartType type) { | 433 TypeName _buildTypeAst(DartType type) { |
| 424 if (type is DynamicTypeImpl) { | 434 if (type is DynamicTypeImpl) { |
| 425 TypeName node = AstFactory.typeName4('dynamic'); | 435 TypeName node = AstFactory.typeName4('dynamic'); |
| 426 node.type = type; | 436 node.type = type; |
| 427 (node.name as SimpleIdentifier).staticElement = type.element; | 437 (node.name as SimpleIdentifier).staticElement = type.element; |
| 428 return node; | 438 return node; |
| 429 } else if (type is InterfaceType) { | 439 } else if (type is InterfaceType) { |
| 430 List<TypeName> argumentNodes = | 440 List<TypeName> argumentNodes = |
| 431 type.typeArguments.map(_buildTypeAst).toList(); | 441 type.typeArguments.map(_buildTypeAst).toList(); |
| 432 TypeName node = AstFactory.typeName4(type.name, argumentNodes); | 442 TypeName node = AstFactory.typeName4(type.name, argumentNodes); |
| 433 node.type = type; | 443 node.type = type; |
| 434 (node.name as SimpleIdentifier).staticElement = type.element; | 444 (node.name as SimpleIdentifier).staticElement = type.element; |
| 435 return node; | 445 return node; |
| 436 } | 446 } |
| 437 throw new StateError('Unsupported type $type'); | 447 throw new StateError('Unsupported type $type'); |
| 438 } | 448 } |
| 439 | 449 |
| 450 Identifier _buildTypeIdentifierAst(DartType type) { | |
| 451 String name = type.name; | |
| 452 SimpleIdentifier node = AstFactory.identifier3(name); | |
| 453 node.staticElement = type.element; | |
| 454 // TODO(scheglov) it seems that resolver does not do this | |
| 455 // node.staticType = resynthesizer.summaryResynthesizer.typeProvider.typeType ; | |
|
Paul Berry
2016/01/31 13:41:02
I'm confused about this commented out code and the
scheglov
2016/01/31 18:55:29
1. We should do this.
2. Resolver does not do this
scheglov
2016/01/31 20:24:01
Actually, I'm wrong.
Resolver does set the type co
| |
| 456 return node; | |
| 457 } | |
| 458 | |
| 440 InterpolationElement _newInterpolationElement(Expression expr) { | 459 InterpolationElement _newInterpolationElement(Expression expr) { |
| 441 if (expr is SimpleStringLiteral) { | 460 if (expr is SimpleStringLiteral) { |
| 442 return new InterpolationString(expr.literal, expr.value); | 461 return new InterpolationString(expr.literal, expr.value); |
| 443 } else { | 462 } else { |
| 444 return new InterpolationExpression( | 463 return new InterpolationExpression( |
| 445 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), | 464 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), |
| 446 expr, | 465 expr, |
| 447 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | 466 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); |
| 448 } | 467 } |
| 449 } | 468 } |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1584 DartType type; | 1603 DartType type; |
| 1585 | 1604 |
| 1586 /** | 1605 /** |
| 1587 * The number of type parameters accepted by the entity referred to by this | 1606 * The number of type parameters accepted by the entity referred to by this |
| 1588 * reference, or zero if it doesn't accept any type parameters. | 1607 * reference, or zero if it doesn't accept any type parameters. |
| 1589 */ | 1608 */ |
| 1590 final int numTypeParameters; | 1609 final int numTypeParameters; |
| 1591 | 1610 |
| 1592 /** | 1611 /** |
| 1593 * Create a new [_ReferenceInfo] object referring to an element called [name] | 1612 * Create a new [_ReferenceInfo] object referring to an element called [name] |
| 1594 * via the element handle [elementHandle], and having [numTypeParameters] | 1613 * via the element handle [element], and having [numTypeParameters] type |
| 1595 * type parameters. | 1614 * parameters. |
| 1596 * | 1615 * |
| 1597 * For the special types `dynamic` and `void`, [specialType] should point to | 1616 * For the special types `dynamic` and `void`, [specialType] should point to |
| 1598 * the type itself. Otherwise, pass `null` and the type will be computed | 1617 * the type itself. Otherwise, pass `null` and the type will be computed |
| 1599 * when appropriate. | 1618 * when appropriate. |
| 1600 */ | 1619 */ |
| 1601 _ReferenceInfo( | 1620 _ReferenceInfo( |
| 1602 this.name, this.element, DartType specialType, this.numTypeParameters) { | 1621 this.name, this.element, DartType specialType, this.numTypeParameters) { |
| 1603 if (specialType != null) { | 1622 if (specialType != null) { |
| 1604 type = specialType; | 1623 type = specialType; |
| 1605 } else if (numTypeParameters == 0) { | 1624 } else if (numTypeParameters == 0) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1672 return element; | 1691 return element; |
| 1673 }; | 1692 }; |
| 1674 // TODO(paulberry): Is it a bug that we have to pass `false` for | 1693 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 1675 // isInstantiated? | 1694 // isInstantiated? |
| 1676 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 1695 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 1677 } else { | 1696 } else { |
| 1678 return null; | 1697 return null; |
| 1679 } | 1698 } |
| 1680 } | 1699 } |
| 1681 } | 1700 } |
| OLD | NEW |