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

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

Issue 1668983002: Resynthesize 'String.length' getter references in constants. (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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 node.staticElement = info.element; 419 node.staticElement = info.element;
420 _push(node); 420 _push(node);
421 } else { 421 } else {
422 throw new StateError('Unsupported reference ${ref.toMap()}'); 422 throw new StateError('Unsupported reference ${ref.toMap()}');
423 } 423 }
424 break; 424 break;
425 case UnlinkedConstOperation.invokeConstructor: 425 case UnlinkedConstOperation.invokeConstructor:
426 _pushInstanceCreation(); 426 _pushInstanceCreation();
427 break; 427 break;
428 case UnlinkedConstOperation.length: 428 case UnlinkedConstOperation.length:
429 return AstFactory.nullLiteral(); 429 Expression target = _pop();
430 // throw new StateError('Unsupported constant operation $operation'); 430 SimpleIdentifier property = AstFactory.identifier3('length');
431 property.staticElement =
432 resynthesizer._buildStringLengthPropertyAccessorElement();
433 _push(AstFactory.propertyAccess(target, property));
434 break;
431 } 435 }
432 } 436 }
433 return stack.single; 437 return stack.single;
434 } 438 }
435 439
436 TypeName _buildTypeAst(DartType type) { 440 TypeName _buildTypeAst(DartType type) {
437 if (type is DynamicTypeImpl) { 441 if (type is DynamicTypeImpl) {
438 TypeName node = AstFactory.typeName4('dynamic'); 442 TypeName node = AstFactory.typeName4('dynamic');
439 node.type = type; 443 node.type = type;
440 (node.name as SimpleIdentifier).staticElement = type.element; 444 (node.name as SimpleIdentifier).staticElement = type.element;
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 break; 1618 break;
1615 case ReferenceKind.propertyAccessor: 1619 case ReferenceKind.propertyAccessor:
1616 assert(location.components.length == 4); 1620 assert(location.components.length == 4);
1617 element = new PropertyAccessorElementHandle( 1621 element = new PropertyAccessorElementHandle(
1618 summaryResynthesizer, location); 1622 summaryResynthesizer, location);
1619 break; 1623 break;
1620 case ReferenceKind.method: 1624 case ReferenceKind.method:
1621 assert(location.components.length == 4); 1625 assert(location.components.length == 4);
1622 element = new MethodElementHandle(summaryResynthesizer, location); 1626 element = new MethodElementHandle(summaryResynthesizer, location);
1623 break; 1627 break;
1628 case ReferenceKind.length:
1629 element = _buildStringLengthPropertyAccessorElement();
1630 break;
1624 default: 1631 default:
1625 // This is an element that doesn't (yet) need to be referred to 1632 // This is an element that doesn't (yet) need to be referred to
1626 // directly, so don't bother populating an element for it. 1633 // directly, so don't bother populating an element for it.
1627 // TODO(paulberry): add support for more kinds, as needed. 1634 // TODO(paulberry): add support for more kinds, as needed.
1628 break; 1635 break;
1629 } 1636 }
1630 } 1637 }
1631 referenceInfos[i] = new _ReferenceInfo( 1638 referenceInfos[i] = new _ReferenceInfo(
1632 enclosingInfo, name, element, type, numTypeParameters); 1639 enclosingInfo, name, element, type, numTypeParameters);
1633 } 1640 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 } 1689 }
1683 resummarizedElements[absoluteUri] = elementMap; 1690 resummarizedElements[absoluteUri] = elementMap;
1684 unitHolder = null; 1691 unitHolder = null;
1685 linkedUnit = null; 1692 linkedUnit = null;
1686 unlinkedUnit = null; 1693 unlinkedUnit = null;
1687 linkedTypeMap = null; 1694 linkedTypeMap = null;
1688 referenceInfos = null; 1695 referenceInfos = null;
1689 } 1696 }
1690 1697
1691 /** 1698 /**
1699 * Return the new handle of the `String.length` getter element.
1700 */
1701 PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() =>
1702 new PropertyAccessorElementHandle(
1703 summaryResynthesizer,
1704 new ElementLocationImpl.con3(
1705 <String>['dart:core', 'dart:core', 'String', 'length?']));
1706
1707 /**
1692 * If the given [kind] is a top-level or class member property accessor, and 1708 * If the given [kind] is a top-level or class member property accessor, and
1693 * the given [name] does not end with `=`, i.e. does not denote a setter, 1709 * the given [name] does not end with `=`, i.e. does not denote a setter,
1694 * return the getter identifier by appending `?`. 1710 * return the getter identifier by appending `?`.
1695 */ 1711 */
1696 static String _getElementIdentifier(String name, ReferenceKind kind) { 1712 static String _getElementIdentifier(String name, ReferenceKind kind) {
1697 if (kind == ReferenceKind.topLevelPropertyAccessor || 1713 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1698 kind == ReferenceKind.propertyAccessor) { 1714 kind == ReferenceKind.propertyAccessor) {
1699 if (!name.endsWith('=')) { 1715 if (!name.endsWith('=')) {
1700 return name + '?'; 1716 return name + '?';
1701 } 1717 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 } 1838 }
1823 : () => this.element; 1839 : () => this.element;
1824 // TODO(paulberry): Is it a bug that we have to pass `false` for 1840 // TODO(paulberry): Is it a bug that we have to pass `false` for
1825 // isInstantiated? 1841 // isInstantiated?
1826 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 1842 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
1827 } else { 1843 } else {
1828 return null; 1844 return null;
1829 } 1845 }
1830 } 1846 }
1831 } 1847 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698