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

Unified Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1859493002: Replace 'length' with more generic 'extractProperty' operation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/summary/resynthesize.dart
diff --git a/pkg/analyzer/lib/src/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
index 4b08c5fe1e39c99e87c4a1c2428398069de35827..fca6e60afe888346dbf33adbdb1de5de2fb1d317 100644
--- a/pkg/analyzer/lib/src/summary/resynthesize.dart
+++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
@@ -438,33 +438,14 @@ class _ConstExprBuilder {
_pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType]));
break;
case UnlinkedConstOperation.pushReference:
- EntityRef ref = uc.references[refPtr++];
- _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference];
- if (info.enclosing != null &&
- info.enclosing.element != null &&
- info.enclosing.element is! ClassElement) {
- SimpleIdentifier prefix = AstFactory.identifier3(
- info.enclosing.name)..staticElement = info.enclosing.element;
- SimpleIdentifier name = AstFactory.identifier3(info.name)
- ..staticElement = info.element;
- PrefixedIdentifier node = AstFactory.identifier(prefix, name);
- _push(node);
- } else {
- SimpleIdentifier node = AstFactory.identifier3(info.name);
- node.staticElement = info.element;
- _push(node);
- }
+ _pushReference();
+ break;
+ case UnlinkedConstOperation.extractProperty:
+ _pushExtractProperty();
break;
case UnlinkedConstOperation.invokeConstructor:
_pushInstanceCreation();
break;
- case UnlinkedConstOperation.length:
- Expression target = _pop();
- SimpleIdentifier property = AstFactory.identifier3('length');
- property.staticElement =
- resynthesizer._buildStringLengthPropertyAccessorElement();
- _push(AstFactory.propertyAccess(target, property));
- break;
case UnlinkedConstOperation.pushConstructorParameter:
String name = uc.strings[stringPtr++];
SimpleIdentifier identifier = AstFactory.identifier3(name);
@@ -479,6 +460,32 @@ class _ConstExprBuilder {
return stack.single;
}
+ /**
+ * Build the identifier sequence (a single or prefixed identifier, or a
+ * property access) corresponding to the given reference [info].
+ */
+ Expression _buildIdentifierSequence(_ReferenceInfo info) {
+ Expression enclosing;
+ if (info.enclosing != null) {
+ enclosing = _buildIdentifierSequence(info.enclosing);
+ }
+ Element element = info.element;
+ if (element == null && info.name == 'length') {
+ element = _getStringLengthElement();
+ }
+ if (enclosing == null) {
+ return AstFactory.identifier3(info.name)..staticElement = element;
+ }
+ if (enclosing is SimpleIdentifier) {
+ SimpleIdentifier identifier = AstFactory.identifier3(info.name)
+ ..staticElement = element;
+ return AstFactory.identifier(enclosing, identifier);
+ }
+ SimpleIdentifier property = AstFactory.identifier3(info.name)
+ ..staticElement = element;
+ return AstFactory.propertyAccess(enclosing, property);
+ }
+
TypeName _buildTypeAst(DartType type) {
List<TypeName> argumentNodes;
if (type is ParameterizedType) {
@@ -493,6 +500,9 @@ class _ConstExprBuilder {
return node;
}
+ PropertyAccessorElement _getStringLengthElement() =>
+ resynthesizer.typeProvider.stringType.getGetter('length');
+
InterpolationElement _newInterpolationElement(Expression expr) {
if (expr is SimpleStringLiteral) {
return new InterpolationString(expr.literal, expr.value);
@@ -526,6 +536,17 @@ class _ConstExprBuilder {
_push(AstFactory.binaryExpression(left, operator, right));
}
+ void _pushExtractProperty() {
+ Expression target = _pop();
+ String name = uc.strings[stringPtr++];
+ // TODO(scheglov) Only String.length property access is supported.
+ assert(name == 'length');
+ _push(AstFactory.propertyAccess(
+ target,
+ AstFactory.identifier3('length')
+ ..staticElement = _getStringLengthElement()));
+ }
+
void _pushInstanceCreation() {
EntityRef ref = uc.references[refPtr++];
_ReferenceInfo info = resynthesizer.referenceInfos[ref.reference];
@@ -630,6 +651,13 @@ class _ConstExprBuilder {
_push(AstFactory.prefixExpression(operator, operand));
}
+ void _pushReference() {
+ EntityRef ref = uc.references[refPtr++];
+ _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference];
+ Expression node = _buildIdentifierSequence(info);
+ _push(node);
+ }
+
List<Expression> _removeTopItems(int count) {
int start = stack.length - count;
int end = stack.length;
@@ -965,7 +993,6 @@ class _LibraryResynthesizer {
case ReferenceKind.function:
case ReferenceKind.propertyAccessor:
case ReferenceKind.method:
- case ReferenceKind.length:
case ReferenceKind.prefix:
case ReferenceKind.unresolved:
case ReferenceKind.variable:
@@ -2006,7 +2033,7 @@ class _UnitResynthesizer {
*/
LocalVariableElement buildLocalVariable(UnlinkedVariable serializedVariable) {
LocalVariableElementImpl element;
- if (serializedVariable.constExpr != null) {
+ if (serializedVariable.constExpr != null && serializedVariable.isConst) {
ConstLocalVariableElementImpl constElement =
new ConstLocalVariableElementImpl(
serializedVariable.name, serializedVariable.nameOffset);
@@ -2233,7 +2260,7 @@ class _UnitResynthesizer {
[ElementHolder holder]) {
if (holder == null) {
TopLevelVariableElementImpl element;
- if (serializedVariable.constExpr != null) {
+ if (serializedVariable.constExpr != null && serializedVariable.isConst) {
ConstTopLevelVariableElementImpl constElement =
new ConstTopLevelVariableElementImpl(
serializedVariable.name, serializedVariable.nameOffset);
@@ -2249,7 +2276,9 @@ class _UnitResynthesizer {
buildImplicitAccessors(element, unitHolder);
} else {
FieldElementImpl element;
- if (serializedVariable.constExpr != null) {
+ if (serializedVariable.constExpr != null &&
+ (serializedVariable.isConst ||
+ serializedVariable.isFinal && !serializedVariable.isStatic)) {
ConstFieldElementImpl constElement = new ConstFieldElementImpl(
serializedVariable.name, serializedVariable.nameOffset);
element = constElement;
@@ -2409,9 +2438,6 @@ class _UnitResynthesizer {
element =
new ConstructorElementHandle(summaryResynthesizer, location);
break;
- case ReferenceKind.length:
- element = _buildStringLengthPropertyAccessorElement();
- break;
case ReferenceKind.method:
assert(location.components.length == 4);
element = new MethodElementHandle(summaryResynthesizer, location);
@@ -2539,15 +2565,6 @@ class _UnitResynthesizer {
}
/**
- * Return the new handle of the `String.length` getter element.
- */
- PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() =>
- new PropertyAccessorElementHandle(
- summaryResynthesizer,
- new ElementLocationImpl.con3(
- <String>['dart:core', 'dart:core', 'String', 'length?']));
-
- /**
* Return the defining type for a [ConstructorElement] by applying
* [typeArgumentRefs] to the given linked [info].
*/

Powered by Google App Engine
This is Rietveld 408576698