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

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

Issue 1897513002: Fill out the implementation of synthetic getters/setters in the summary linker. (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 | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | 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 a4b896dd97198bba49ec40695821f1fd7ed2a6e6..2972635963e6dd7fceae815f92bfb949e3001a72 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -3273,6 +3273,32 @@ class ParameterElementForLink implements ParameterElementImpl {
}
/**
+ * Element representing the parameter of a synthetic setter for a variable
+ * resynthesized during linking.
+ */
+class ParameterElementForLink_VariableSetter implements ParameterElementImpl {
+ @override
+ final PropertyAccessorElementForLink_Variable enclosingElement;
+
+ ParameterElementForLink_VariableSetter(this.enclosingElement);
+
+ @override
+ bool get isSynthetic => true;
+
+ @override
+ String get name => 'x';
+
+ @override
+ ParameterKind get parameterKind => ParameterKind.REQUIRED;
+
+ @override
+ DartType get type => enclosingElement.computeVariableType();
+
+ @override
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
+/**
* Element representing a getter or setter resynthesized from a summary during
* linking.
*/
@@ -3328,19 +3354,20 @@ class PropertyAccessorElementForLink_Variable
@override
final bool isSetter;
- final VariableElementForLink _variable;
+ final VariableElementForLink variable;
FunctionTypeImpl _type;
+ List<ParameterElement> _parameters;
- PropertyAccessorElementForLink_Variable(this._variable, this.isSetter);
+ PropertyAccessorElementForLink_Variable(this.variable, this.isSetter);
@override
- Element get enclosingElement => _variable.enclosingElement;
+ Element get enclosingElement => variable.enclosingElement;
@override
bool get isGetter => !isSetter;
@override
- bool get isStatic => _variable.isStatic;
+ bool get isStatic => variable.isStatic;
@override
bool get isSynthetic => true;
@@ -3350,25 +3377,28 @@ class PropertyAccessorElementForLink_Variable
@override
LibraryElementForLink get library =>
- _variable.compilationUnit.enclosingElement;
+ variable.compilationUnit.enclosingElement;
+
+ @override
+ String get name => isSetter ? '${variable.name}=' : variable.name;
@override
- String get name => isSetter ? '${_variable.name}=' : _variable.name;
+ List<ParameterElement> get parameters {
+ if (_parameters == null) {
+ _parameters = <ParameterElementForLink_VariableSetter>[];
+ if (isSetter) {
+ _parameters.add(new ParameterElementForLink_VariableSetter(this));
+ }
+ }
+ return _parameters;
+ }
@override
DartType get returnType {
if (isSetter) {
return VoidTypeImpl.instance;
- } else if (_variable.hasImplicitType &&
- !isStatic &&
- !_variable.compilationUnit.isTypeInferenceComplete) {
- // This is an instance field and we are currently inferring types in the
- // library cycle containing it. So we shouldn't use the inferred type
- // (even if we have already computed it), since that would lead to
- // non-deterministic type inference results.
- return DynamicTypeImpl.instance;
} else {
- return _variable.type;
+ return computeVariableType();
}
}
@@ -3381,6 +3411,24 @@ class PropertyAccessorElementForLink_Variable
return const [];
}
+ /**
+ * Compute the type of the corresponding variable, which may depend on the
+ * progress of type inference.
+ */
+ DartType computeVariableType() {
+ if (variable.hasImplicitType &&
+ !isStatic &&
+ !variable.compilationUnit.isTypeInferenceComplete) {
+ // This is an instance field and we are currently inferring types in the
+ // library cycle containing it. So we shouldn't use the inferred type
+ // (even if we have already computed it), since that would lead to
+ // non-deterministic type inference results.
+ return DynamicTypeImpl.instance;
+ } else {
+ return variable.type;
+ }
+ }
+
@override
bool isAccessibleIn(LibraryElement library) =>
!Identifier.isPrivateName(name) || identical(this.library, library);
@@ -3966,7 +4014,10 @@ class UndefinedElementForLink implements ReferenceableElementForLink {
* summary during linking.
*/
class VariableElementForLink
- implements VariableElementImpl, ReferenceableElementForLink {
+ implements
+ VariableElementImpl,
+ PropertyInducingElement,
+ ReferenceableElementForLink {
/**
* The unlinked representation of the variable in the summary.
*/
@@ -4061,6 +4112,12 @@ class VariableElementForLink
String get name => unlinkedVariable.name;
@override
+ DartType get propagatedType {
+ // TODO(paulberry): implement propagated types in the linker.
+ return DynamicTypeImpl.instance;
+ }
+
+ @override
void set type(DartType newType) {
// TODO(paulberry): store inferred type.
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698