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

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

Issue 1902593005: In summary linker, drop trailing type args of type `dynamic`. (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/summary_common.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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 */ 159 */
160 EntityRefBuilder _createLinkedType( 160 EntityRefBuilder _createLinkedType(
161 DartType type, 161 DartType type,
162 CompilationUnitElementInBuildUnit compilationUnit, 162 CompilationUnitElementInBuildUnit compilationUnit,
163 TypeParameterizedElementForLink typeParameterContext, 163 TypeParameterizedElementForLink typeParameterContext,
164 {int slot}) { 164 {int slot}) {
165 EntityRefBuilder result = new EntityRefBuilder(slot: slot); 165 EntityRefBuilder result = new EntityRefBuilder(slot: slot);
166 if (type is InterfaceType) { 166 if (type is InterfaceType) {
167 ClassElementForLink element = type.element; 167 ClassElementForLink element = type.element;
168 result.reference = compilationUnit.addReference(element); 168 result.reference = compilationUnit.addReference(element);
169 if (type.typeArguments.isNotEmpty) { 169 _storeTypeArguments(
170 result.typeArguments = type.typeArguments 170 type.typeArguments, result, compilationUnit, typeParameterContext);
171 .map((DartType t) =>
172 _createLinkedType(t, compilationUnit, typeParameterContext))
173 .toList();
174 }
175 return result; 171 return result;
176 } else if (type is DynamicTypeImpl) { 172 } else if (type is DynamicTypeImpl) {
177 result.reference = compilationUnit.addRawReference('dynamic'); 173 result.reference = compilationUnit.addRawReference('dynamic');
178 return result; 174 return result;
179 } else if (type is VoidTypeImpl) { 175 } else if (type is VoidTypeImpl) {
180 result.reference = compilationUnit.addRawReference('void'); 176 result.reference = compilationUnit.addRawReference('void');
181 return result; 177 return result;
182 } else if (type is BottomTypeImpl) { 178 } else if (type is BottomTypeImpl) {
183 result.reference = compilationUnit.addRawReference('*bottom*'); 179 result.reference = compilationUnit.addRawReference('*bottom*');
184 return result; 180 return result;
185 } else if (type is TypeParameterType) { 181 } else if (type is TypeParameterType) {
186 TypeParameterElementForLink element = type.element; 182 TypeParameterElementForLink element = type.element;
187 result.paramReference = 183 result.paramReference =
188 typeParameterContext.typeParameterNestingLevel - element.nestingLevel; 184 typeParameterContext.typeParameterNestingLevel - element.nestingLevel;
189 return result; 185 return result;
190 } else if (type is FunctionType) { 186 } else if (type is FunctionType) {
191 Element element = type.element; 187 Element element = type.element;
192 if (element is FunctionElementForLink_FunctionTypedParam) { 188 if (element is FunctionElementForLink_FunctionTypedParam) {
193 result.reference = 189 result.reference =
194 compilationUnit.addReference(element.innermostExecutable); 190 compilationUnit.addReference(element.innermostExecutable);
195 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices; 191 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices;
196 if (type.typeArguments.isNotEmpty) { 192 _storeTypeArguments(
197 result.typeArguments = type.typeArguments 193 type.typeArguments, result, compilationUnit, typeParameterContext);
198 .map((DartType t) =>
199 _createLinkedType(t, compilationUnit, typeParameterContext))
200 .toList();
201 }
202 return result; 194 return result;
203 } 195 }
204 if (element is TopLevelFunctionElementForLink) { 196 if (element is TopLevelFunctionElementForLink) {
205 result.reference = compilationUnit.addReference(element); 197 result.reference = compilationUnit.addReference(element);
206 if (type.typeArguments.isNotEmpty) { 198 _storeTypeArguments(
207 result.typeArguments = type.typeArguments 199 type.typeArguments, result, compilationUnit, typeParameterContext);
208 .map((DartType t) =>
209 _createLinkedType(t, compilationUnit, typeParameterContext))
210 .toList();
211 }
212 return result; 200 return result;
213 } 201 }
214 if (element is MethodElementForLink) { 202 if (element is MethodElementForLink) {
215 result.reference = compilationUnit.addReference(element); 203 result.reference = compilationUnit.addReference(element);
216 if (type.typeArguments.isNotEmpty) { 204 _storeTypeArguments(
217 result.typeArguments = type.typeArguments 205 type.typeArguments, result, compilationUnit, typeParameterContext);
218 .map((DartType t) =>
219 _createLinkedType(t, compilationUnit, typeParameterContext))
220 .toList();
221 }
222 return result; 206 return result;
223 } 207 }
224 // TODO(paulberry): implement other cases. 208 // TODO(paulberry): implement other cases.
225 throw new UnimplementedError('${element.runtimeType}'); 209 throw new UnimplementedError('${element.runtimeType}');
226 } 210 }
227 // TODO(paulberry): implement other cases. 211 // TODO(paulberry): implement other cases.
228 throw new UnimplementedError('${type.runtimeType}'); 212 throw new UnimplementedError('${type.runtimeType}');
229 } 213 }
230 214
231 /** 215 /**
216 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and
217 * [typeParameterContext] to serialize them.
218 *
219 * Trailing arguments of type `dynamic` are dropped.
220 */
221 void _storeTypeArguments(
222 List<DartType> typeArguments,
223 EntityRefBuilder encodedType,
224 CompilationUnitElementInBuildUnit compilationUnit,
225 TypeParameterizedElementForLink typeParameterContext) {
226 int count = typeArguments.length;
227 while (count > 0) {
228 if (typeArguments[count - 1].isDynamic) {
229 count--;
230 } else {
231 List<EntityRefBuilder> encodedTypeArguments =
232 new List<EntityRefBuilder>(count);
233 for (int i = 0; i < count; i++) {
234 encodedTypeArguments[i] = _createLinkedType(
235 typeArguments[i], compilationUnit, typeParameterContext);
236 }
237 encodedType.typeArguments = encodedTypeArguments;
238 break;
239 }
240 }
241 }
242
243 /**
232 * Type of the callback used by [link] and [relink] to request 244 * Type of the callback used by [link] and [relink] to request
233 * [LinkedLibrary] objects from other build units. 245 * [LinkedLibrary] objects from other build units.
234 */ 246 */
235 typedef LinkedLibrary GetDependencyCallback(String absoluteUri); 247 typedef LinkedLibrary GetDependencyCallback(String absoluteUri);
236 248
237 /** 249 /**
238 * Type of the callback used by [link] and [relink] to request 250 * Type of the callback used by [link] and [relink] to request
239 * [UnlinkedUnit] objects. 251 * [UnlinkedUnit] objects.
240 */ 252 */
241 typedef UnlinkedUnit GetUnitCallback(String absoluteUri); 253 typedef UnlinkedUnit GetUnitCallback(String absoluteUri);
(...skipping 4106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4348 if (type is InterfaceType) { 4360 if (type is InterfaceType) {
4349 Element result = type.lookUpGetter(name, compilationUnit.library); 4361 Element result = type.lookUpGetter(name, compilationUnit.library);
4350 result ??= type.lookUpMethod(name, compilationUnit.library); 4362 result ??= type.lookUpMethod(name, compilationUnit.library);
4351 return result; 4363 return result;
4352 } 4364 }
4353 } 4365 }
4354 // TODO(scheglov): implement for propagated types 4366 // TODO(scheglov): implement for propagated types
4355 return null; 4367 return null;
4356 } 4368 }
4357 } 4369 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698