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

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

Issue 1938403003: Use property accessor elements for type inference rather than field elements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/link.dart
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index a022e8c6196dcca6db2ad1a855b0943864734424..21bcb8b62e76c0d05295b7f5a01f9dc30b99f194 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -319,16 +319,8 @@ abstract class ClassElementForLink
for (ConstructorElementForLink constructor in constructors) {
_containedNames[constructor.name] = constructor;
}
- for (FieldElementForLink field in fields) {
- // TODO(paulberry): do we need to handle nonstatic fields for
- // consistent behavior with erroneous code?
- if (field.isStatic) {
- _containedNames[field.name] = field;
- }
- }
for (PropertyAccessorElementForLink accessor in accessors) {
- if (accessor.isStatic && !accessor.isSynthetic) {
- // TODO(paulberry): add synthetic elements too?
+ if (accessor.isStatic) {
_containedNames[accessor.name] = accessor;
}
}
@@ -403,11 +395,9 @@ class ClassElementForLink_Class extends ClassElementForLink
}
}
for (FieldElementForLink_ClassField field in fields) {
- _accessors
- .add(new PropertyAccessorElementForLink_Variable(field, false));
+ _accessors.add(field.getter);
if (!field.isConst && !field.isFinal) {
- _accessors
- .add(new PropertyAccessorElementForLink_Variable(field, true));
+ _accessors.add(field.setter);
}
}
}
@@ -1263,7 +1253,7 @@ class ConstConstructorNode extends ConstNode {
// Note: non-static const isn't allowed but we handle it anyway so
// that we won't be confused by incorrect code.
if ((field.isFinal || field.isConst) && !field.isStatic) {
- safeAddDependency(field.asConstVariable);
+ safeAddDependency(field.getter.asConstVariable);
}
}
for (ParameterElementForLink parameterElement
@@ -2458,8 +2448,13 @@ class ExprTypeComputer {
* Element representing a field resynthesized from a summary during
* linking.
*/
-abstract class FieldElementForLink
- implements FieldElement, ReferenceableElementForLink {}
+abstract class FieldElementForLink implements FieldElement {
+ @override
+ PropertyAccessorElementForLink get getter;
+
+ @override
+ PropertyAccessorElementForLink get setter;
+}
/**
* Specialization of [FieldElementForLink] for class fields.
@@ -2469,6 +2464,9 @@ class FieldElementForLink_ClassField extends VariableElementForLink
@override
final ClassElementForLink_Class enclosingElement;
+ PropertyAccessorElementForLink_Variable _getter;
+ PropertyAccessorElementForLink_Variable _setter;
+
/**
* If this is an instance field, the type that was computed by
* [InstanceMemberInferrer] (if any). Otherwise `null`.
@@ -2481,9 +2479,23 @@ class FieldElementForLink_ClassField extends VariableElementForLink
super(unlinkedVariable, enclosingElement.enclosingElement);
@override
+ PropertyAccessorElementForLink_Variable get getter =>
+ _getter ??= new PropertyAccessorElementForLink_Variable(this, false);
+
+ @override
bool get isStatic => unlinkedVariable.isStatic;
@override
+ PropertyAccessorElementForLink_Variable get setter {
+ if (!isConst && !isFinal) {
+ return _setter ??=
+ new PropertyAccessorElementForLink_Variable(this, true);
+ } else {
+ return null;
+ }
+ }
+
+ @override
void set type(DartType inferredType) {
assert(!isStatic);
assert(_inferredInstanceType == null);
@@ -2527,23 +2539,6 @@ class FieldElementForLink_EnumField extends FieldElementForLink
FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement);
@override
- ConstructorElementForLink get asConstructor => null;
-
- @override
- ConstVariableNode get asConstVariable {
- // Even though enum fields are constants, there is no need to include them
- // in the const dependency graph because they can't participate in a
- // circularity.
- return null;
- }
-
- @override
- DartType get asStaticType => enclosingElement.type;
-
- @override
- TypeInferenceNode get asTypeInferenceNode => null;
-
- @override
bool get isStatic => true;
@override
@@ -2554,15 +2549,6 @@ class FieldElementForLink_EnumField extends FieldElementForLink
unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name;
@override
- DartType buildType(DartType getTypeArgument(int i),
- List<int> implicitFunctionTypeIndices) =>
- DynamicTypeImpl.instance;
-
- @override
- ReferenceableElementForLink getContainedName(String name) =>
- UndefinedElementForLink.instance;
-
- @override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
@override
@@ -3590,6 +3576,18 @@ class PropertyAccessorElementForLink_Variable
PropertyAccessorElementForLink_Variable(this.variable, this.isSetter);
@override
+ ConstructorElementForLink get asConstructor => null;
+
+ @override
+ ConstVariableNode get asConstVariable => variable._constNode;
+
+ @override
+ DartType get asStaticType => returnType;
+
+ @override
+ TypeInferenceNode get asTypeInferenceNode => variable._typeInferenceNode;
+
+ @override
Element get enclosingElement => variable.enclosingElement;
@override
@@ -3640,6 +3638,11 @@ class PropertyAccessorElementForLink_Variable
return const [];
}
+ @override
+ DartType buildType(DartType getTypeArgument(int i),
+ List<int> implicitFunctionTypeIndices) =>
+ DynamicTypeImpl.instance;
+
/**
* Compute the type of the corresponding variable, which may depend on the
* progress of type inference.
@@ -3659,6 +3662,10 @@ class PropertyAccessorElementForLink_Variable
}
@override
+ ReferenceableElementForLink getContainedName(String name) =>
+ UndefinedElementForLink.instance;
+
+ @override
bool isAccessibleIn(LibraryElement library) =>
!Identifier.isPrivateName(name) || identical(this.library, library);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698