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

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

Issue 1853433006: Add more type inference uses cases to AST-based summaries. (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/summarize_ast_strong_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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (type is InterfaceType) { 134 if (type is InterfaceType) {
135 ClassElementForLink element = type.element; 135 ClassElementForLink element = type.element;
136 int dependency = compilationUnit.library.addDependency(element.library); 136 int dependency = compilationUnit.library.addDependency(element.library);
137 result.reference = compilationUnit.addReference(dependency, element.name, 137 result.reference = compilationUnit.addReference(dependency, element.name,
138 element.typeParameters.length, element.enclosingElement.unitNum); 138 element.typeParameters.length, element.enclosingElement.unitNum);
139 if (element.typeParameters.isNotEmpty) { 139 if (element.typeParameters.isNotEmpty) {
140 // TODO(paulberry): implement. 140 // TODO(paulberry): implement.
141 throw new UnimplementedError(); 141 throw new UnimplementedError();
142 } 142 }
143 return result; 143 return result;
144 } else if (type is VoidTypeImpl) {
145 result.reference = compilationUnit.addReference(0, 'void', 0, 0);
146 return result;
144 } 147 }
145 throw new UnimplementedError('${type.runtimeType}'); 148 throw new UnimplementedError('${type.runtimeType}');
146 } 149 }
147 150
148 /** 151 /**
149 * Type of the callback used by [link] and [relink] to request 152 * Type of the callback used by [link] and [relink] to request
150 * [LinkedLibrary] objects from other build units. 153 * [LinkedLibrary] objects from other build units.
151 */ 154 */
152 typedef LinkedLibrary GetDependencyCallback(String absoluteUri); 155 typedef LinkedLibrary GetDependencyCallback(String absoluteUri);
153 156
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 * Throw away any information produced by a previous call to [link]. 243 * Throw away any information produced by a previous call to [link].
241 */ 244 */
242 void unlink(); 245 void unlink();
243 } 246 }
244 247
245 /** 248 /**
246 * Element representing a class resynthesized from a summary during 249 * Element representing a class resynthesized from a summary during
247 * linking. 250 * linking.
248 */ 251 */
249 class ClassElementForLink_Class extends ClassElementForLink 252 class ClassElementForLink_Class extends ClassElementForLink
250 implements TypeParameterContext { 253 with TypeParameterizedElementForLink {
251 /** 254 /**
252 * The unlinked representation of the class in the summary. 255 * The unlinked representation of the class in the summary.
253 */ 256 */
254 final UnlinkedClass _unlinkedClass; 257 final UnlinkedClass _unlinkedClass;
255 258
256 List<ConstructorElementForLink> _constructors; 259 List<ConstructorElementForLink> _constructors;
257 ConstructorElementForLink _unnamedConstructor; 260 ConstructorElementForLink _unnamedConstructor;
258 bool _unnamedConstructorComputed = false; 261 bool _unnamedConstructorComputed = false;
259 List<FieldElementForLink_ClassField> _fields; 262 List<FieldElementForLink_ClassField> _fields;
260 InterfaceType _supertype; 263 InterfaceType _supertype;
261 InterfaceType _type; 264 InterfaceType _type;
262 List<TypeParameterElementForLink> _typeParameters;
263 List<TypeParameterType> _typeParameterTypes;
264 List<MethodElementForLink> _methods; 265 List<MethodElementForLink> _methods;
265 List<InterfaceType> _mixins; 266 List<InterfaceType> _mixins;
266 List<InterfaceType> _interfaces; 267 List<InterfaceType> _interfaces;
268 List<PropertyAccessorElementForLink> _accessors;
267 269
268 ClassElementForLink_Class( 270 ClassElementForLink_Class(
269 CompilationUnitElementForLink enclosingElement, this._unlinkedClass) 271 CompilationUnitElementForLink enclosingElement, this._unlinkedClass)
270 : super(enclosingElement); 272 : super(enclosingElement);
271 273
272 @override 274 @override
273 List<PropertyAccessorElement> get accessors { 275 List<PropertyAccessorElementForLink> get accessors {
274 // TODO(paulberry): implement 276 if (_accessors == null) {
275 return const []; 277 _accessors = <PropertyAccessorElementForLink>[];
278 Map<String, SyntheticVariableElementForLink> syntheticVariables =
279 <String, SyntheticVariableElementForLink>{};
280 for (UnlinkedExecutable unlinkedExecutable
281 in _unlinkedClass.executables) {
282 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter ||
283 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
284 String name = unlinkedExecutable.name;
285 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
286 assert(name.endsWith('='));
287 name = name.substring(0, name.length - 1);
288 }
289 SyntheticVariableElementForLink syntheticVariable = syntheticVariables
290 .putIfAbsent(name, () => new SyntheticVariableElementForLink());
291 PropertyAccessorElementForLink accessor =
292 new PropertyAccessorElementForLink(
293 this, unlinkedExecutable, syntheticVariable);
294 _accessors.add(accessor);
295 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) {
296 syntheticVariable._getter = accessor;
297 } else {
298 syntheticVariable._setter = accessor;
299 }
300 }
301 }
302 }
303 return _accessors;
276 } 304 }
277 305
278 @override 306 @override
279 List<ConstructorElementForLink> get constructors { 307 List<ConstructorElementForLink> get constructors {
280 if (_constructors == null) { 308 if (_constructors == null) {
281 _constructors = <ConstructorElementForLink>[]; 309 _constructors = <ConstructorElementForLink>[];
282 for (UnlinkedExecutable unlinkedExecutable 310 for (UnlinkedExecutable unlinkedExecutable
283 in _unlinkedClass.executables) { 311 in _unlinkedClass.executables) {
284 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { 312 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) {
285 _constructors 313 _constructors
286 .add(new ConstructorElementForLink(this, unlinkedExecutable)); 314 .add(new ConstructorElementForLink(this, unlinkedExecutable));
287 } 315 }
288 } 316 }
289 } 317 }
290 return _constructors; 318 return _constructors;
291 } 319 }
292 320
293 @override 321 @override
294 String get displayName => _unlinkedClass.name; 322 String get displayName => _unlinkedClass.name;
295 323
296 @override 324 @override
325 TypeParameterContext get enclosingTypeParameterContext => null;
326
327 @override
297 List<FieldElementForLink_ClassField> get fields { 328 List<FieldElementForLink_ClassField> get fields {
298 if (_fields == null) { 329 if (_fields == null) {
299 _fields = <FieldElementForLink_ClassField>[]; 330 _fields = <FieldElementForLink_ClassField>[];
300 for (UnlinkedVariable field in _unlinkedClass.fields) { 331 for (UnlinkedVariable field in _unlinkedClass.fields) {
301 _fields.add(new FieldElementForLink_ClassField(this, field)); 332 _fields.add(new FieldElementForLink_ClassField(this, field));
302 } 333 }
303 } 334 }
304 return _fields; 335 return _fields;
305 } 336 }
306 337
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 369
339 @override 370 @override
340 InterfaceType get supertype { 371 InterfaceType get supertype {
341 if (isObject) { 372 if (isObject) {
342 return null; 373 return null;
343 } 374 }
344 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype); 375 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype);
345 } 376 }
346 377
347 @override 378 @override
348 List<TypeParameterElementForLink> get typeParameters {
349 if (_typeParameters == null) {
350 _typeParameters = _unlinkedClass.typeParameters
351 .map((UnlinkedTypeParam p) => new TypeParameterElementForLink(p))
352 .toList();
353 }
354 return _typeParameters;
355 }
356
357 /**
358 * Get a list of [TypeParameterType] objects corresponding to the
359 * class's type parameters.
360 */
361 List<TypeParameterType> get typeParameterTypes {
362 if (_typeParameterTypes == null) {
363 _typeParameterTypes = typeParameters
364 .map((TypeParameterElementForLink e) => new TypeParameterTypeImpl(e))
365 .toList();
366 }
367 return _typeParameterTypes;
368 }
369
370 @override
371 ConstructorElementForLink get unnamedConstructor { 379 ConstructorElementForLink get unnamedConstructor {
372 if (!_unnamedConstructorComputed) { 380 if (!_unnamedConstructorComputed) {
373 for (ConstructorElementForLink constructor in constructors) { 381 for (ConstructorElementForLink constructor in constructors) {
374 if (constructor.name.isEmpty) { 382 if (constructor.name.isEmpty) {
375 _unnamedConstructor = constructor; 383 _unnamedConstructor = constructor;
376 break; 384 break;
377 } 385 }
378 } 386 }
379 _unnamedConstructorComputed = true; 387 _unnamedConstructorComputed = true;
380 } 388 }
381 return _unnamedConstructor; 389 return _unnamedConstructor;
382 } 390 }
383 391
384 @override 392 @override
393 List<UnlinkedTypeParam> get _unlinkedTypeParams =>
394 _unlinkedClass.typeParameters;
395
396 @override
385 DartType buildType( 397 DartType buildType(
386 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { 398 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
387 int numTypeParameters = _unlinkedClass.typeParameters.length; 399 int numTypeParameters = _unlinkedClass.typeParameters.length;
388 if (numTypeParameters != 0) { 400 if (numTypeParameters != 0) {
389 return new InterfaceTypeImpl(this); 401 return new InterfaceTypeImpl(this);
390 } else { 402 } else {
391 if (_type == null) { 403 if (_type == null) {
392 List<DartType> typeArguments = new List<DartType>(numTypeParameters); 404 List<DartType> typeArguments = new List<DartType>(numTypeParameters);
393 for (int i = 0; i < numTypeParameters; i++) { 405 for (int i = 0; i < numTypeParameters; i++) {
394 typeArguments[i] = getTypeArgument(i); 406 typeArguments[i] = getTypeArgument(i);
395 } 407 }
396 _type = new InterfaceTypeImpl.elementWithNameAndArgs( 408 _type = new InterfaceTypeImpl.elementWithNameAndArgs(
397 this, name, typeArguments); 409 this, name, typeArguments);
398 } 410 }
399 return _type; 411 return _type;
400 } 412 }
401 } 413 }
402 414
403 @override 415 @override
404 TypeParameterType getTypeParameterType(int index) {
405 List<TypeParameterType> types = typeParameterTypes;
406 return types[types.length - index];
407 }
408
409 @override
410 void link(CompilationUnitElementInBuildUnit compilationUnit) { 416 void link(CompilationUnitElementInBuildUnit compilationUnit) {
411 for (ConstructorElementForLink constructorElement in constructors) { 417 for (ConstructorElementForLink constructorElement in constructors) {
412 constructorElement.link(compilationUnit); 418 constructorElement.link(compilationUnit);
413 } 419 }
414 for (MethodElementForLink methodElement in methods) { 420 for (MethodElementForLink methodElement in methods) {
415 methodElement.link(compilationUnit); 421 methodElement.link(compilationUnit);
416 } 422 }
423 for (PropertyAccessorElementForLink propertyAccessorElement in accessors) {
424 propertyAccessorElement.link(compilationUnit);
425 }
426 for (FieldElementForLink_ClassField fieldElement in fields) {
427 fieldElement.link(compilationUnit);
428 }
417 } 429 }
418 430
419 @override 431 @override
420 void unlink() { 432 void unlink() {
421 hasBeenInferred = false; 433 hasBeenInferred = false;
422 for (MethodElementForLink methodElement in methods) { 434 for (MethodElementForLink methodElement in methods) {
423 methodElement.unlink(); 435 methodElement.unlink();
424 } 436 }
437 for (PropertyAccessorElementForLink propertyAccessorElement in accessors) {
438 propertyAccessorElement.unlink();
439 }
440 for (FieldElementForLink_ClassField fieldElement in fields) {
441 fieldElement.unlink();
442 }
425 } 443 }
426 444
427 /** 445 /**
428 * Convert [typeRef] into an [InterfaceType]. 446 * Convert [typeRef] into an [InterfaceType].
429 */ 447 */
430 InterfaceType _computeInterfaceType(EntityRef typeRef) { 448 InterfaceType _computeInterfaceType(EntityRef typeRef) {
431 if (_unlinkedClass.supertype != null) { 449 if (_unlinkedClass.supertype != null) {
432 DartType supertype = enclosingElement._resolveTypeRef(typeRef, this); 450 DartType supertype = enclosingElement._resolveTypeRef(typeRef, this);
433 if (supertype is InterfaceType) { 451 if (supertype is InterfaceType) {
434 return supertype; 452 return supertype;
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 } 1271 }
1254 } 1272 }
1255 } 1273 }
1256 1274
1257 // Kick off the algorithm starting with the starting point. 1275 // Kick off the algorithm starting with the starting point.
1258 strongConnect(startingPoint); 1276 strongConnect(startingPoint);
1259 } 1277 }
1260 } 1278 }
1261 1279
1262 /** 1280 /**
1281 * Base class for executable elements resynthesized from a summary during
1282 * linking.
1283 */
1284 abstract class ExecutableElementForLink extends Object
1285 with TypeParameterizedElementForLink
1286 implements ExecutableElementImpl, TypeParameterContext {
1287 /**
1288 * The unlinked representation of the method in the summary.
1289 */
1290 final UnlinkedExecutable _unlinkedExecutable;
1291
1292 DartType _declaredReturnType;
1293 DartType _inferredReturnType;
1294 FunctionTypeImpl _type;
1295 List<TypeParameterElementForLink> _typeParameters;
1296 List<ParameterElementForLink> _parameters;
1297
1298 /**
1299 * TODO(paulberry): this won't always be a class element.
1300 */
1301 @override
1302 final ClassElementForLink_Class enclosingElement;
1303
1304 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable);
1305
1306 @override
1307 TypeParameterContext get enclosingTypeParameterContext => enclosingElement;
1308
1309 @override
1310 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null;
1311
1312 @override
1313 bool get isStatic => _unlinkedExecutable.isStatic;
1314
1315 @override
1316 bool get isSynthetic => false;
1317
1318 @override
1319 LibraryElementForLink get library => enclosingElement.library;
1320
1321 @override
1322 String get name => _unlinkedExecutable.name;
1323
1324 @override
1325 List<ParameterElementForLink> get parameters {
1326 if (_parameters == null) {
1327 _parameters = <ParameterElementForLink>[];
1328 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) {
1329 _parameters.add(new ParameterElementForLink(
1330 unlinkedParam, this, enclosingElement.enclosingElement));
1331 }
1332 }
1333 return _parameters;
1334 }
1335
1336 @override
1337 DartType get returnType {
1338 if (_inferredReturnType != null) {
1339 return _inferredReturnType;
1340 } else if (_declaredReturnType == null) {
1341 if (_unlinkedExecutable.returnType == null) {
1342 // In strong mode, setters without an explicit return type are
1343 // considered to return `void`.
1344 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter &&
1345 library._linker.strongMode) {
1346 _declaredReturnType = VoidTypeImpl.instance;
1347 } else {
1348 _declaredReturnType = DynamicTypeImpl.instance;
1349 }
1350 } else {
1351 _declaredReturnType = enclosingElement.enclosingElement
1352 ._resolveTypeRef(_unlinkedExecutable.returnType, this);
1353 }
1354 }
1355 return _declaredReturnType;
1356 }
1357
1358 @override
1359 void set returnType(DartType inferredType) {
1360 assert(_inferredReturnType == null);
1361 _inferredReturnType = inferredType;
1362 }
1363
1364 @override
1365 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
1366
1367 @override
1368 List<TypeParameterElementForLink> get typeParameters {
1369 if (_typeParameters == null) {
1370 _typeParameters = _unlinkedExecutable.typeParameters
1371 .map((UnlinkedTypeParam p) => new TypeParameterElementForLink(p))
1372 .toList();
1373 }
1374 return _typeParameters;
1375 }
1376
1377 @override
1378 bool isAccessibleIn(LibraryElement library) =>
1379 !Identifier.isPrivateName(name) || identical(this.library, library);
1380
1381 /**
1382 * Store the results of type inference for this method in [compilationUnit].
1383 */
1384 void link(CompilationUnitElementInBuildUnit compilationUnit) {
1385 compilationUnit._storeLinkedType(
1386 _unlinkedExecutable.inferredReturnTypeSlot, returnType);
1387 for (ParameterElementForLink parameterElement in parameters) {
1388 parameterElement.link(compilationUnit);
1389 }
1390 }
1391
1392 /**
1393 * Throw away any information produced by type inference.
1394 */
1395 void unlink() {
1396 for (ParameterElementForLink parameterElement in parameters) {
1397 parameterElement.unlink();
1398 }
1399 _inferredReturnType = null;
1400 }
1401 }
1402
1403 /**
1263 * Element representing a field resynthesized from a summary during 1404 * Element representing a field resynthesized from a summary during
1264 * linking. 1405 * linking.
1265 */ 1406 */
1266 abstract class FieldElementForLink 1407 abstract class FieldElementForLink
1267 implements FieldElement, ReferenceableElementForLink {} 1408 implements FieldElement, ReferenceableElementForLink {}
1268 1409
1269 /** 1410 /**
1270 * Specialization of [FieldElementForLink] for class fields. 1411 * Specialization of [FieldElementForLink] for class fields.
1271 */ 1412 */
1272 class FieldElementForLink_ClassField extends VariableElementForLink 1413 class FieldElementForLink_ClassField extends VariableElementForLink
1273 implements FieldElementForLink { 1414 implements FieldElementForLink {
1274 @override 1415 @override
1275 final ClassElementForLink_Class enclosingElement; 1416 final ClassElementForLink_Class enclosingElement;
1276 1417
1418 DartType _inferredType;
1419 DartType _declaredType;
1420
1277 FieldElementForLink_ClassField(ClassElementForLink_Class enclosingElement, 1421 FieldElementForLink_ClassField(ClassElementForLink_Class enclosingElement,
1278 UnlinkedVariable unlinkedVariable) 1422 UnlinkedVariable unlinkedVariable)
1279 : enclosingElement = enclosingElement, 1423 : enclosingElement = enclosingElement,
1280 super(unlinkedVariable, enclosingElement.enclosingElement); 1424 super(unlinkedVariable, enclosingElement.enclosingElement);
1281 1425
1282 @override 1426 @override
1283 bool get isStatic => unlinkedVariable.isStatic; 1427 bool get isStatic => unlinkedVariable.isStatic;
1428
1429 @override
1430 DartType get type {
1431 if (_inferredType != null) {
1432 return _inferredType;
1433 } else if (_declaredType == null) {
1434 if (unlinkedVariable.type == null) {
1435 _declaredType = DynamicTypeImpl.instance;
1436 } else {
1437 _declaredType = compilationUnit._resolveTypeRef(
1438 unlinkedVariable.type, enclosingElement);
1439 }
1440 }
1441 return _declaredType;
1442 }
1443
1444 @override
1445 void set type(DartType inferredType) {
1446 assert(_inferredType == null);
1447 _inferredType = inferredType;
1448 }
1449
1450 /**
1451 * Store the results of type inference for this field in
1452 * [compilationUnit].
1453 */
1454 void link(CompilationUnitElementInBuildUnit compilationUnit) {
1455 compilationUnit._storeLinkedType(
1456 unlinkedVariable.inferredTypeSlot, _inferredType);
1457 }
1458
1459 /**
1460 * Throw away any information produced by type inference.
1461 */
1462 void unlink() {
1463 _inferredType = null;
1464 }
1284 } 1465 }
1285 1466
1286 /** 1467 /**
1287 * Specialization of [FieldElementForLink] for enum fields. 1468 * Specialization of [FieldElementForLink] for enum fields.
1288 */ 1469 */
1289 class FieldElementForLink_EnumField extends FieldElementForLink 1470 class FieldElementForLink_EnumField extends FieldElementForLink
1290 implements FieldElement { 1471 implements FieldElement {
1291 /** 1472 /**
1292 * The unlinked representation of the field in the summary, or `null` if this 1473 * The unlinked representation of the field in the summary, or `null` if this
1293 * is an enum's `values` field. 1474 * is an enum's `values` field.
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 @override 1707 @override
1527 CompilationUnitElementInDependency _makeUnitElement( 1708 CompilationUnitElementInDependency _makeUnitElement(
1528 UnlinkedUnit unlinkedUnit, int i) => 1709 UnlinkedUnit unlinkedUnit, int i) =>
1529 new CompilationUnitElementInDependency( 1710 new CompilationUnitElementInDependency(
1530 this, unlinkedUnit, _linkedLibrary.units[i], i); 1711 this, unlinkedUnit, _linkedLibrary.units[i], i);
1531 } 1712 }
1532 1713
1533 /** 1714 /**
1534 * Element representing a method resynthesized from a summary during linking. 1715 * Element representing a method resynthesized from a summary during linking.
1535 */ 1716 */
1536 class MethodElementForLink implements MethodElementImpl, TypeParameterContext { 1717 class MethodElementForLink extends ExecutableElementForLink
1537 /** 1718 implements MethodElementImpl {
1538 * The unlinked representation of the method in the summary. 1719 MethodElementForLink(ClassElementForLink_Class enclosingElement,
1539 */ 1720 UnlinkedExecutable unlinkedExecutable)
1540 final UnlinkedExecutable _unlinkedExecutable; 1721 : super(enclosingElement, unlinkedExecutable);
1541
1542 DartType _declaredReturnType;
1543 DartType _inferredReturnType;
1544 FunctionTypeImpl _type;
1545 List<TypeParameterElementForLink> _typeParameters;
1546 List<ParameterElementForLink> _parameters;
1547
1548 @override
1549 final ClassElementForLink_Class enclosingElement;
1550
1551 MethodElementForLink(this.enclosingElement, this._unlinkedExecutable);
1552
1553 @override
1554 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null;
1555
1556 @override
1557 bool get isStatic => _unlinkedExecutable.isStatic;
1558
1559 @override
1560 bool get isSynthetic => false;
1561 1722
1562 @override 1723 @override
1563 ElementKind get kind => ElementKind.METHOD; 1724 ElementKind get kind => ElementKind.METHOD;
1564 1725
1565 @override 1726 @override
1566 LibraryElementForLink get library => enclosingElement.library;
1567
1568 @override
1569 String get name => _unlinkedExecutable.name;
1570
1571 @override
1572 List<ParameterElementForLink> get parameters {
1573 if (_parameters == null) {
1574 _parameters = <ParameterElementForLink>[];
1575 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) {
1576 _parameters.add(new ParameterElementForLink(
1577 unlinkedParam, this, enclosingElement.enclosingElement));
1578 }
1579 }
1580 return _parameters;
1581 }
1582
1583 @override
1584 DartType get returnType {
1585 if (_inferredReturnType != null) {
1586 return _inferredReturnType;
1587 } else if (_declaredReturnType == null) {
1588 if (_unlinkedExecutable.returnType == null) {
1589 _declaredReturnType = DynamicTypeImpl.instance;
1590 } else {
1591 _declaredReturnType = enclosingElement.enclosingElement
1592 ._resolveTypeRef(_unlinkedExecutable.returnType, this);
1593 }
1594 }
1595 return _declaredReturnType;
1596 }
1597
1598 @override
1599 void set returnType(DartType inferredType) {
1600 assert(_inferredReturnType == null);
1601 _inferredReturnType = inferredType;
1602 }
1603
1604 @override
1605 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
1606
1607 @override
1608 List<TypeParameterElementForLink> get typeParameters {
1609 if (_typeParameters == null) {
1610 _typeParameters = _unlinkedExecutable.typeParameters
1611 .map((UnlinkedTypeParam p) => new TypeParameterElementForLink(p))
1612 .toList();
1613 }
1614 return _typeParameters;
1615 }
1616
1617 @override
1618 TypeParameterType getTypeParameterType(int index) {
1619 // TODO(paulberry): implement.
1620 throw new UnimplementedError();
1621 }
1622
1623 @override
1624 bool isAccessibleIn(LibraryElement library) =>
1625 !Identifier.isPrivateName(name) || identical(this.library, library);
1626
1627 /**
1628 * Store the results of type inference for this method in [compilationUnit].
1629 */
1630 void link(CompilationUnitElementInBuildUnit compilationUnit) {
1631 compilationUnit._storeLinkedType(
1632 _unlinkedExecutable.inferredReturnTypeSlot, _inferredReturnType);
1633 for (ParameterElementForLink parameterElement in parameters) {
1634 parameterElement.link(compilationUnit);
1635 }
1636 }
1637
1638 @override
1639 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1727 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1640
1641 /**
1642 * Throw away any information produced by type inference.
1643 */
1644 void unlink() {
1645 for (ParameterElementForLink parameterElement in parameters) {
1646 parameterElement.unlink();
1647 }
1648 _inferredReturnType = null;
1649 }
1650 } 1728 }
1651 1729
1652 /** 1730 /**
1653 * Instances of [Node] represent nodes in a dependency graph. The 1731 * Instances of [Node] represent nodes in a dependency graph. The
1654 * type parameter, [NodeType], is the derived type (this affords some 1732 * type parameter, [NodeType], is the derived type (this affords some
1655 * extra type safety by making it difficult to accidentally construct 1733 * extra type safety by making it difficult to accidentally construct
1656 * bridges between unrelated dependency graphs). 1734 * bridges between unrelated dependency graphs).
1657 */ 1735 */
1658 abstract class Node<NodeType> { 1736 abstract class Node<NodeType> {
1659 /** 1737 /**
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 1886
1809 /** 1887 /**
1810 * Throw away any information produced by type inference. 1888 * Throw away any information produced by type inference.
1811 */ 1889 */
1812 void unlink() { 1890 void unlink() {
1813 _inferredType = null; 1891 _inferredType = null;
1814 } 1892 }
1815 } 1893 }
1816 1894
1817 /** 1895 /**
1896 * Element representing a getter or setter resynthesized from a summary during
1897 * linking.
1898 */
1899 class PropertyAccessorElementForLink extends ExecutableElementForLink
1900 implements PropertyAccessorElementImpl {
1901 @override
1902 SyntheticVariableElementForLink variable;
1903
1904 PropertyAccessorElementForLink(ClassElementForLink_Class enclosingElement,
1905 UnlinkedExecutable unlinkedExecutable, this.variable)
1906 : super(enclosingElement, unlinkedExecutable);
1907
1908 @override
1909 PropertyAccessorElementForLink get correspondingGetter => variable.getter;
1910
1911 @override
1912 bool get isGetter =>
1913 _unlinkedExecutable.kind == UnlinkedExecutableKind.getter;
1914
1915 @override
1916 bool get isSetter =>
1917 _unlinkedExecutable.kind == UnlinkedExecutableKind.setter;
1918
1919 @override
1920 ElementKind get kind => _unlinkedExecutable.kind ==
1921 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER;
1922
1923 @override
1924 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1925 }
1926
1927 /**
1818 * Abstract base class representing an element which can be the target 1928 * Abstract base class representing an element which can be the target
1819 * of a reference. 1929 * of a reference.
1820 */ 1930 */
1821 abstract class ReferenceableElementForLink { 1931 abstract class ReferenceableElementForLink {
1822 /** 1932 /**
1823 * If this element can be used in a constructor invocation context, 1933 * If this element can be used in a constructor invocation context,
1824 * return the associated constructor (which may be `this` or some 1934 * return the associated constructor (which may be `this` or some
1825 * other element). Otherwise return `null`. 1935 * other element). Otherwise return `null`.
1826 */ 1936 */
1827 ConstructorElementForLink get asConstructor; 1937 ConstructorElementForLink get asConstructor;
(...skipping 17 matching lines...) Expand all
1845 * If this element contains other named elements, return the 1955 * If this element contains other named elements, return the
1846 * contained element having the given [name]. If this element can't 1956 * contained element having the given [name]. If this element can't
1847 * contain other named elements, or it doesn't contain an element 1957 * contain other named elements, or it doesn't contain an element
1848 * with the given name, return the singleton of 1958 * with the given name, return the singleton of
1849 * [UndefinedElementForLink]. 1959 * [UndefinedElementForLink].
1850 */ 1960 */
1851 ReferenceableElementForLink getContainedName(String name); 1961 ReferenceableElementForLink getContainedName(String name);
1852 } 1962 }
1853 1963
1854 /** 1964 /**
1965 * Element representing a synthetic variable resynthesized from a summary during
1966 * linking.
1967 */
1968 class SyntheticVariableElementForLink implements PropertyInducingElementImpl {
1969 PropertyAccessorElementForLink _getter;
1970 PropertyAccessorElementForLink _setter;
1971
1972 @override
1973 PropertyAccessorElementForLink get getter => _getter;
1974
1975 @override
1976 PropertyAccessorElementForLink get setter => _setter;
1977
1978 @override
1979 void set type(DartType inferredType) {}
1980
1981 @override
1982 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1983 }
1984
1985 /**
1855 * Element representing a top level variable resynthesized from a 1986 * Element representing a top level variable resynthesized from a
1856 * summary during linking. 1987 * summary during linking.
1857 */ 1988 */
1858 class TopLevelVariableElementForLink extends VariableElementForLink 1989 class TopLevelVariableElementForLink extends VariableElementForLink
1859 implements TopLevelVariableElement { 1990 implements TopLevelVariableElement {
1860 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement, 1991 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement,
1861 UnlinkedVariable unlinkedVariable) 1992 UnlinkedVariable unlinkedVariable)
1862 : super(unlinkedVariable, enclosingElement); 1993 : super(unlinkedVariable, enclosingElement);
1863 1994
1864 @override 1995 @override
(...skipping 23 matching lines...) Expand all
1888 2019
1889 TypeParameterElementForLink(this._unlinkedTypeParam); 2020 TypeParameterElementForLink(this._unlinkedTypeParam);
1890 2021
1891 @override 2022 @override
1892 String get name => _unlinkedTypeParam.name; 2023 String get name => _unlinkedTypeParam.name;
1893 2024
1894 @override 2025 @override
1895 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2026 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1896 } 2027 }
1897 2028
2029 /**
2030 * Mixin representing an element which can have type parameters.
2031 */
2032 abstract class TypeParameterizedElementForLink
2033 implements TypeParameterizedElement, TypeParameterContext {
2034 List<TypeParameterType> _typeParameterTypes;
2035 List<TypeParameterElementForLink> _typeParameters;
2036
2037 /**
2038 * Get the type parameter context enclosing this one, if any.
2039 */
2040 TypeParameterContext get enclosingTypeParameterContext;
2041
2042 List<TypeParameterElementForLink> get typeParameters {
2043 if (_typeParameters == null) {
2044 _typeParameters = _unlinkedTypeParams
2045 .map((UnlinkedTypeParam p) => new TypeParameterElementForLink(p))
2046 .toList();
2047 }
2048 return _typeParameters;
2049 }
2050
2051 /**
2052 * Get a list of [TypeParameterType] objects corresponding to the
2053 * element's type parameters.
2054 */
2055 List<TypeParameterType> get typeParameterTypes {
2056 if (_typeParameterTypes == null) {
2057 _typeParameterTypes = typeParameters
2058 .map((TypeParameterElementForLink e) => new TypeParameterTypeImpl(e))
2059 .toList();
2060 }
2061 return _typeParameterTypes;
2062 }
2063
2064 /**
2065 * Get the [UnlinkedTypeParam]s representing the type parameters declared by
2066 * this element.
2067 */
2068 List<UnlinkedTypeParam> get _unlinkedTypeParams;
2069
2070 @override
2071 TypeParameterType getTypeParameterType(int index) {
2072 List<TypeParameterType> types = typeParameterTypes;
2073 if (index <= types.length) {
2074 return types[types.length - index];
2075 } else if (enclosingTypeParameterContext != null) {
2076 return enclosingTypeParameterContext
2077 .getTypeParameterType(index - types.length);
2078 } else {
2079 // If we get here, it means that a summary contained a type parameter inde x
2080 // that was out of range.
2081 throw new RangeError('Invalid type parameter index');
2082 }
2083 }
2084 }
2085
1898 class TypeProviderForLink implements TypeProvider { 2086 class TypeProviderForLink implements TypeProvider {
1899 final _Linker _linker; 2087 final _Linker _linker;
1900 2088
1901 InterfaceType _boolType; 2089 InterfaceType _boolType;
1902 InterfaceType _deprecatedType; 2090 InterfaceType _deprecatedType;
1903 InterfaceType _doubleType; 2091 InterfaceType _doubleType;
1904 InterfaceType _functionType; 2092 InterfaceType _functionType;
1905 InterfaceType _futureDynamicType; 2093 InterfaceType _futureDynamicType;
1906 InterfaceType _futureNullType; 2094 InterfaceType _futureNullType;
1907 InterfaceType _futureType; 2095 InterfaceType _futureType;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 2420
2233 /** 2421 /**
2234 * Throw away any information produced by a previous call to [link]. 2422 * Throw away any information produced by a previous call to [link].
2235 */ 2423 */
2236 void unlink() { 2424 void unlink() {
2237 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { 2425 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) {
2238 library.unlink(); 2426 library.unlink();
2239 } 2427 }
2240 } 2428 }
2241 } 2429 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summarize_ast_strong_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698