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

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

Issue 1956473004: Fix ast-based serialization of out-of-scope type parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove temporary debugging code. Created 4 years, 7 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 result.reference = compilationUnit.addRawReference('dynamic'); 173 result.reference = compilationUnit.addRawReference('dynamic');
174 return result; 174 return result;
175 } else if (type is VoidTypeImpl) { 175 } else if (type is VoidTypeImpl) {
176 result.reference = compilationUnit.addRawReference('void'); 176 result.reference = compilationUnit.addRawReference('void');
177 return result; 177 return result;
178 } else if (type is BottomTypeImpl) { 178 } else if (type is BottomTypeImpl) {
179 result.reference = compilationUnit.addRawReference('*bottom*'); 179 result.reference = compilationUnit.addRawReference('*bottom*');
180 return result; 180 return result;
181 } else if (type is TypeParameterType) { 181 } else if (type is TypeParameterType) {
182 TypeParameterElementForLink element = type.element; 182 TypeParameterElementForLink element = type.element;
183 result.paramReference = 183 if (typeParameterContext.isTypeParameterInScope(element)) {
184 typeParameterContext.typeParameterNestingLevel - element.nestingLevel; 184 result.paramReference =
185 typeParameterContext.typeParameterNestingLevel - element.nestingLevel;
186 } else {
187 // Out-of-scope type parameters only occur in circumstances where they
188 // are irrelevant (i.e. when a type parameter is unused). So we can
189 // safely convert them to `dynamic`.
190 result.reference = compilationUnit.addRawReference('dynamic');
191 }
185 return result; 192 return result;
186 } else if (type is FunctionType) { 193 } else if (type is FunctionType) {
187 Element element = type.element; 194 Element element = type.element;
188 if (element is FunctionElementForLink_FunctionTypedParam) { 195 if (element is FunctionElementForLink_FunctionTypedParam) {
189 result.reference = 196 result.reference =
190 compilationUnit.addReference(element.typeParameterContext); 197 compilationUnit.addReference(element.typeParameterContext);
191 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices; 198 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices;
192 _storeTypeArguments( 199 _storeTypeArguments(
193 type.typeArguments, result, compilationUnit, typeParameterContext); 200 type.typeArguments, result, compilationUnit, typeParameterContext);
194 return result; 201 return result;
(...skipping 3995 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 return types[types.length - index]; 4197 return types[types.length - index];
4191 } else if (enclosingTypeParameterContext != null) { 4198 } else if (enclosingTypeParameterContext != null) {
4192 return enclosingTypeParameterContext 4199 return enclosingTypeParameterContext
4193 .getTypeParameterType(index - types.length); 4200 .getTypeParameterType(index - types.length);
4194 } else { 4201 } else {
4195 // If we get here, it means that a summary contained a type parameter inde x 4202 // If we get here, it means that a summary contained a type parameter inde x
4196 // that was out of range. 4203 // that was out of range.
4197 throw new RangeError('Invalid type parameter index'); 4204 throw new RangeError('Invalid type parameter index');
4198 } 4205 }
4199 } 4206 }
4207
4208 /**
4209 * Find out if the given [typeParameter] is in scope in this context.
4210 */
4211 bool isTypeParameterInScope(TypeParameterElementForLink typeParameter) {
4212 if (typeParameter.enclosingElement == this) {
4213 return true;
4214 } else if (enclosingTypeParameterContext != null) {
4215 return enclosingTypeParameterContext
4216 .isTypeParameterInScope(typeParameter);
4217 } else {
4218 return false;
4219 }
4220 }
4200 } 4221 }
4201 4222
4202 class TypeProviderForLink implements TypeProvider { 4223 class TypeProviderForLink implements TypeProvider {
4203 final Linker _linker; 4224 final Linker _linker;
4204 4225
4205 InterfaceType _boolType; 4226 InterfaceType _boolType;
4206 InterfaceType _deprecatedType; 4227 InterfaceType _deprecatedType;
4207 InterfaceType _doubleType; 4228 InterfaceType _doubleType;
4208 InterfaceType _functionType; 4229 InterfaceType _functionType;
4209 InterfaceType _futureDynamicType; 4230 InterfaceType _futureDynamicType;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4521 * there are no type parameters in scope. 4542 * there are no type parameters in scope.
4522 */ 4543 */
4523 TypeParameterizedElementForLink get _typeParameterContext; 4544 TypeParameterizedElementForLink get _typeParameterContext;
4524 4545
4525 @override 4546 @override
4526 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4547 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4527 4548
4528 @override 4549 @override
4529 String toString() => '$enclosingElement.$name'; 4550 String toString() => '$enclosingElement.$name';
4530 } 4551 }
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