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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 3255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 void link(CompilationUnitElementInBuildUnit compilationUnit) { 3266 void link(CompilationUnitElementInBuildUnit compilationUnit) {
3267 compilationUnit._storeLinkedType( 3267 compilationUnit._storeLinkedType(
3268 _unlinkedParam.inferredTypeSlot, _inferredType, _typeParameterContext); 3268 _unlinkedParam.inferredTypeSlot, _inferredType, _typeParameterContext);
3269 } 3269 }
3270 3270
3271 @override 3271 @override
3272 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3272 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3273 } 3273 }
3274 3274
3275 /** 3275 /**
3276 * Element representing the parameter of a synthetic setter for a variable
3277 * resynthesized during linking.
3278 */
3279 class ParameterElementForLink_VariableSetter implements ParameterElementImpl {
3280 @override
3281 final PropertyAccessorElementForLink_Variable enclosingElement;
3282
3283 ParameterElementForLink_VariableSetter(this.enclosingElement);
3284
3285 @override
3286 bool get isSynthetic => true;
3287
3288 @override
3289 String get name => 'x';
3290
3291 @override
3292 ParameterKind get parameterKind => ParameterKind.REQUIRED;
3293
3294 @override
3295 DartType get type => enclosingElement.computeVariableType();
3296
3297 @override
3298 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3299 }
3300
3301 /**
3276 * Element representing a getter or setter resynthesized from a summary during 3302 * Element representing a getter or setter resynthesized from a summary during
3277 * linking. 3303 * linking.
3278 */ 3304 */
3279 abstract class PropertyAccessorElementForLink 3305 abstract class PropertyAccessorElementForLink
3280 implements PropertyAccessorElementImpl { 3306 implements PropertyAccessorElementImpl {
3281 void link(CompilationUnitElementInBuildUnit compilationUnit); 3307 void link(CompilationUnitElementInBuildUnit compilationUnit);
3282 } 3308 }
3283 3309
3284 /** 3310 /**
3285 * Specialization of [PropertyAccessorElementForLink] for non-synthetic 3311 * Specialization of [PropertyAccessorElementForLink] for non-synthetic
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3321 3347
3322 /** 3348 /**
3323 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors 3349 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors
3324 * implied by a field or variable declaration. 3350 * implied by a field or variable declaration.
3325 */ 3351 */
3326 class PropertyAccessorElementForLink_Variable 3352 class PropertyAccessorElementForLink_Variable
3327 implements PropertyAccessorElementForLink { 3353 implements PropertyAccessorElementForLink {
3328 @override 3354 @override
3329 final bool isSetter; 3355 final bool isSetter;
3330 3356
3331 final VariableElementForLink _variable; 3357 final VariableElementForLink variable;
3332 FunctionTypeImpl _type; 3358 FunctionTypeImpl _type;
3359 List<ParameterElement> _parameters;
3333 3360
3334 PropertyAccessorElementForLink_Variable(this._variable, this.isSetter); 3361 PropertyAccessorElementForLink_Variable(this.variable, this.isSetter);
3335 3362
3336 @override 3363 @override
3337 Element get enclosingElement => _variable.enclosingElement; 3364 Element get enclosingElement => variable.enclosingElement;
3338 3365
3339 @override 3366 @override
3340 bool get isGetter => !isSetter; 3367 bool get isGetter => !isSetter;
3341 3368
3342 @override 3369 @override
3343 bool get isStatic => _variable.isStatic; 3370 bool get isStatic => variable.isStatic;
3344 3371
3345 @override 3372 @override
3346 bool get isSynthetic => true; 3373 bool get isSynthetic => true;
3347 3374
3348 @override 3375 @override
3349 ElementKind get kind => isSetter ? ElementKind.SETTER : ElementKind.GETTER; 3376 ElementKind get kind => isSetter ? ElementKind.SETTER : ElementKind.GETTER;
3350 3377
3351 @override 3378 @override
3352 LibraryElementForLink get library => 3379 LibraryElementForLink get library =>
3353 _variable.compilationUnit.enclosingElement; 3380 variable.compilationUnit.enclosingElement;
3354 3381
3355 @override 3382 @override
3356 String get name => isSetter ? '${_variable.name}=' : _variable.name; 3383 String get name => isSetter ? '${variable.name}=' : variable.name;
3384
3385 @override
3386 List<ParameterElement> get parameters {
3387 if (_parameters == null) {
3388 _parameters = <ParameterElementForLink_VariableSetter>[];
3389 if (isSetter) {
3390 _parameters.add(new ParameterElementForLink_VariableSetter(this));
3391 }
3392 }
3393 return _parameters;
3394 }
3357 3395
3358 @override 3396 @override
3359 DartType get returnType { 3397 DartType get returnType {
3360 if (isSetter) { 3398 if (isSetter) {
3361 return VoidTypeImpl.instance; 3399 return VoidTypeImpl.instance;
3362 } else if (_variable.hasImplicitType &&
3363 !isStatic &&
3364 !_variable.compilationUnit.isTypeInferenceComplete) {
3365 // This is an instance field and we are currently inferring types in the
3366 // library cycle containing it. So we shouldn't use the inferred type
3367 // (even if we have already computed it), since that would lead to
3368 // non-deterministic type inference results.
3369 return DynamicTypeImpl.instance;
3370 } else { 3400 } else {
3371 return _variable.type; 3401 return computeVariableType();
3372 } 3402 }
3373 } 3403 }
3374 3404
3375 @override 3405 @override
3376 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); 3406 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
3377 3407
3378 @override 3408 @override
3379 List<TypeParameterElement> get typeParameters { 3409 List<TypeParameterElement> get typeParameters {
3380 // TODO(paulberry): is this correct for fields in generic classes? 3410 // TODO(paulberry): is this correct for fields in generic classes?
3381 return const []; 3411 return const [];
3382 } 3412 }
3383 3413
3414 /**
3415 * Compute the type of the corresponding variable, which may depend on the
3416 * progress of type inference.
3417 */
3418 DartType computeVariableType() {
3419 if (variable.hasImplicitType &&
3420 !isStatic &&
3421 !variable.compilationUnit.isTypeInferenceComplete) {
3422 // This is an instance field and we are currently inferring types in the
3423 // library cycle containing it. So we shouldn't use the inferred type
3424 // (even if we have already computed it), since that would lead to
3425 // non-deterministic type inference results.
3426 return DynamicTypeImpl.instance;
3427 } else {
3428 return variable.type;
3429 }
3430 }
3431
3384 @override 3432 @override
3385 bool isAccessibleIn(LibraryElement library) => 3433 bool isAccessibleIn(LibraryElement library) =>
3386 !Identifier.isPrivateName(name) || identical(this.library, library); 3434 !Identifier.isPrivateName(name) || identical(this.library, library);
3387 3435
3388 @override 3436 @override
3389 void link(CompilationUnitElementInBuildUnit compilationUnit) {} 3437 void link(CompilationUnitElementInBuildUnit compilationUnit) {}
3390 3438
3391 @override 3439 @override
3392 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3440 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3393 3441
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
3959 4007
3960 @override 4008 @override
3961 ReferenceableElementForLink getContainedName(String name) => this; 4009 ReferenceableElementForLink getContainedName(String name) => this;
3962 } 4010 }
3963 4011
3964 /** 4012 /**
3965 * Element representing a top level variable resynthesized from a 4013 * Element representing a top level variable resynthesized from a
3966 * summary during linking. 4014 * summary during linking.
3967 */ 4015 */
3968 class VariableElementForLink 4016 class VariableElementForLink
3969 implements VariableElementImpl, ReferenceableElementForLink { 4017 implements
4018 VariableElementImpl,
4019 PropertyInducingElement,
4020 ReferenceableElementForLink {
3970 /** 4021 /**
3971 * The unlinked representation of the variable in the summary. 4022 * The unlinked representation of the variable in the summary.
3972 */ 4023 */
3973 final UnlinkedVariable unlinkedVariable; 4024 final UnlinkedVariable unlinkedVariable;
3974 4025
3975 /** 4026 /**
3976 * If this variable is declared `const` and the enclosing library is 4027 * If this variable is declared `const` and the enclosing library is
3977 * part of the build unit being linked, the variable's node in the 4028 * part of the build unit being linked, the variable's node in the
3978 * constant evaluation dependency graph. Otherwise `null`. 4029 * constant evaluation dependency graph. Otherwise `null`.
3979 */ 4030 */
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4054 @override 4105 @override
4055 bool get isStatic; 4106 bool get isStatic;
4056 4107
4057 @override 4108 @override
4058 bool get isSynthetic => false; 4109 bool get isSynthetic => false;
4059 4110
4060 @override 4111 @override
4061 String get name => unlinkedVariable.name; 4112 String get name => unlinkedVariable.name;
4062 4113
4063 @override 4114 @override
4115 DartType get propagatedType {
4116 // TODO(paulberry): implement propagated types in the linker.
4117 return DynamicTypeImpl.instance;
4118 }
4119
4120 @override
4064 void set type(DartType newType) { 4121 void set type(DartType newType) {
4065 // TODO(paulberry): store inferred type. 4122 // TODO(paulberry): store inferred type.
4066 } 4123 }
4067 4124
4068 /** 4125 /**
4069 * The context in which type parameters should be interpreted, or `null` if 4126 * The context in which type parameters should be interpreted, or `null` if
4070 * there are no type parameters in scope. 4127 * there are no type parameters in scope.
4071 */ 4128 */
4072 TypeParameterizedElementForLink get _typeParameterContext; 4129 TypeParameterizedElementForLink get _typeParameterContext;
4073 4130
4074 @override 4131 @override
4075 DartType buildType(DartType getTypeArgument(int i), 4132 DartType buildType(DartType getTypeArgument(int i),
4076 List<int> implicitFunctionTypeIndices) => 4133 List<int> implicitFunctionTypeIndices) =>
4077 DynamicTypeImpl.instance; 4134 DynamicTypeImpl.instance;
4078 4135
4079 ReferenceableElementForLink getContainedName(String name) { 4136 ReferenceableElementForLink getContainedName(String name) {
4080 return new NonstaticMemberElementForLink(_constNode); 4137 return new NonstaticMemberElementForLink(_constNode);
4081 } 4138 }
4082 4139
4083 @override 4140 @override
4084 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4141 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4085 } 4142 }
OLDNEW
« 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