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

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

Issue 1842183002: Use standard TypeImpl classes during linking. (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 | no next file » | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * 53 *
54 * - As much as possible, bookkeeping data is pointed to directly by 54 * - As much as possible, bookkeeping data is pointed to directly by
55 * the element objects, rather than being stored in maps. 55 * the element objects, rather than being stored in maps.
56 * 56 *
57 * - Where possible, we favor method dispatch instead of "is" and "as" 57 * - Where possible, we favor method dispatch instead of "is" and "as"
58 * checks. E.g. see [ReferenceableElementForLink.asConstructor]. 58 * checks. E.g. see [ReferenceableElementForLink.asConstructor].
59 */ 59 */
60 60
61 import 'package:analyzer/dart/element/element.dart'; 61 import 'package:analyzer/dart/element/element.dart';
62 import 'package:analyzer/dart/element/type.dart'; 62 import 'package:analyzer/dart/element/type.dart';
63 import 'package:analyzer/src/dart/element/type.dart';
63 import 'package:analyzer/src/generated/utilities_dart.dart'; 64 import 'package:analyzer/src/generated/utilities_dart.dart';
64 import 'package:analyzer/src/summary/format.dart'; 65 import 'package:analyzer/src/summary/format.dart';
65 import 'package:analyzer/src/summary/idl.dart'; 66 import 'package:analyzer/src/summary/idl.dart';
66 import 'package:analyzer/src/summary/prelink.dart'; 67 import 'package:analyzer/src/summary/prelink.dart';
67 68
68 /** 69 /**
69 * Link together the build unit consisting of [libraryUris], using 70 * Link together the build unit consisting of [libraryUris], using
70 * [getDependency] to fetch the [LinkedLibrary] objects from other 71 * [getDependency] to fetch the [LinkedLibrary] objects from other
71 * build units, and [getUnit] to fetch the [UnlinkedUnit] objects from 72 * build units, and [getUnit] to fetch the [UnlinkedUnit] objects from
72 * both this build unit and other build units. 73 * both this build unit and other build units.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 */ 196 */
196 final UnlinkedClass _unlinkedClass; 197 final UnlinkedClass _unlinkedClass;
197 198
198 @override 199 @override
199 final CompilationUnitElementForLink enclosingElement; 200 final CompilationUnitElementForLink enclosingElement;
200 201
201 List<ConstructorElementForLink> _constructors; 202 List<ConstructorElementForLink> _constructors;
202 ConstructorElementForLink _unnamedConstructor; 203 ConstructorElementForLink _unnamedConstructor;
203 bool _unnamedConstructorComputed = false; 204 bool _unnamedConstructorComputed = false;
204 List<FieldElementForLink_ClassField> _fields; 205 List<FieldElementForLink_ClassField> _fields;
205 InterfaceTypeForLink _supertype; 206 InterfaceType _supertype;
206 InterfaceTypeForLink _type; 207 InterfaceType _type;
207 List<TypeParameterTypeForLink> _typeParameterTypes; 208 List<TypeParameterType> _typeParameterTypes;
208 209
209 ClassElementForLink_Class(this.enclosingElement, this._unlinkedClass); 210 ClassElementForLink_Class(this.enclosingElement, this._unlinkedClass);
210 211
211 @override 212 @override
212 List<ConstructorElementForLink> get constructors { 213 List<ConstructorElementForLink> get constructors {
213 if (_constructors == null) { 214 if (_constructors == null) {
214 _constructors = <ConstructorElementForLink>[]; 215 _constructors = <ConstructorElementForLink>[];
215 for (UnlinkedExecutable unlinkedExecutable 216 for (UnlinkedExecutable unlinkedExecutable
216 in _unlinkedClass.executables) { 217 in _unlinkedClass.executables) {
217 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { 218 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) {
218 _constructors 219 _constructors
219 .add(new ConstructorElementForLink(this, unlinkedExecutable)); 220 .add(new ConstructorElementForLink(this, unlinkedExecutable));
220 } 221 }
221 } 222 }
222 } 223 }
223 return _constructors; 224 return _constructors;
224 } 225 }
225 226
226 @override 227 @override
228 String get displayName => _unlinkedClass.name;
229
230 @override
227 List<FieldElementForLink_ClassField> get fields { 231 List<FieldElementForLink_ClassField> get fields {
228 if (_fields == null) { 232 if (_fields == null) {
229 _fields = <FieldElementForLink_ClassField>[]; 233 _fields = <FieldElementForLink_ClassField>[];
230 for (UnlinkedVariable field in _unlinkedClass.fields) { 234 for (UnlinkedVariable field in _unlinkedClass.fields) {
231 _fields.add(new FieldElementForLink_ClassField(this, field)); 235 _fields.add(new FieldElementForLink_ClassField(this, field));
232 } 236 }
233 } 237 }
234 return _fields; 238 return _fields;
235 } 239 }
236 240
237 @override 241 @override
238 bool get isObject => _unlinkedClass.hasNoSupertype; 242 bool get isObject => _unlinkedClass.hasNoSupertype;
239 243
240 @override 244 @override
241 String get name => _unlinkedClass.name; 245 String get name => _unlinkedClass.name;
242 246
243 @override 247 @override
244 InterfaceTypeForLink get supertype { 248 InterfaceType get supertype {
245 if (isObject) { 249 if (isObject) {
246 return null; 250 return null;
247 } 251 }
248 return _supertype ??= _computeSupertype(); 252 return _supertype ??= _computeSupertype();
249 } 253 }
250 254
251 /** 255 /**
252 * Get a list of [TypeParameterTypeForLink] objects corresponding to the 256 * Get a list of [TypeParameterType] objects corresponding to the
253 * class's type parameters. 257 * class's type parameters.
254 */ 258 */
255 List<TypeParameterTypeForLink> get typeParameterTypes { 259 List<TypeParameterType> get typeParameterTypes {
256 if (_typeParameterTypes == null) { 260 if (_typeParameterTypes == null) {
257 _typeParameterTypes = _unlinkedClass.typeParameters 261 _typeParameterTypes = _unlinkedClass.typeParameters
258 .map((UnlinkedTypeParam _) => new TypeParameterTypeForLink()) 262 .map((UnlinkedTypeParam p) =>
263 new TypeParameterTypeImpl(new TypeParameterElementForLink(p)))
259 .toList(); 264 .toList();
260 } 265 }
261 return _typeParameterTypes; 266 return _typeParameterTypes;
262 } 267 }
263 268
264 @override 269 @override
265 ConstructorElementForLink get unnamedConstructor { 270 ConstructorElementForLink get unnamedConstructor {
266 if (!_unnamedConstructorComputed) { 271 if (!_unnamedConstructorComputed) {
267 for (ConstructorElementForLink constructor in constructors) { 272 for (ConstructorElementForLink constructor in constructors) {
268 if (constructor.name.isEmpty) { 273 if (constructor.name.isEmpty) {
269 _unnamedConstructor = constructor; 274 _unnamedConstructor = constructor;
270 break; 275 break;
271 } 276 }
272 } 277 }
273 _unnamedConstructorComputed = true; 278 _unnamedConstructorComputed = true;
274 } 279 }
275 return _unnamedConstructor; 280 return _unnamedConstructor;
276 } 281 }
277 282
278 @override 283 @override
279 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 284 DartType buildType(
280 List<int> implicitFunctionTypeIndices) { 285 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
281 if (_unlinkedClass.typeParameters.length != 0) { 286 int numTypeParameters = _unlinkedClass.typeParameters.length;
282 return new InterfaceTypeForLink(this); 287 if (numTypeParameters != 0) {
288 return new InterfaceTypeImpl(this);
283 } else { 289 } else {
284 return _type ??= new InterfaceTypeForLink(this); 290 List<DartType> typeArguments = new List<DartType>(numTypeParameters);
291 for (int i = 0; i < numTypeParameters; i++) {
292 typeArguments[i] = getTypeArgument(i);
293 }
294 return _type ??= new InterfaceTypeImpl.elementWithNameAndArgs(
scheglov 2016/03/30 19:54:15 Maybe we should use explicit if != null to avoid c
Paul Berry 2016/03/30 19:59:53 Whoops, you're right. Thanks for catching this.
295 this, name, typeArguments);
285 } 296 }
286 } 297 }
287 298
288 @override 299 @override
289 TypeParameterTypeForLink getTypeParameterType(int index) { 300 TypeParameterType getTypeParameterType(int index) {
290 List<TypeParameterTypeForLink> types = typeParameterTypes; 301 List<TypeParameterType> types = typeParameterTypes;
291 return types[types.length - index]; 302 return types[types.length - index];
292 } 303 }
293 304
294 @override 305 @override
295 void link(LinkedUnitBuilder linkedUnit) { 306 void link(LinkedUnitBuilder linkedUnit) {
296 for (ConstructorElementForLink constructorElement in constructors) { 307 for (ConstructorElementForLink constructorElement in constructors) {
297 constructorElement.link(linkedUnit); 308 constructorElement.link(linkedUnit);
298 } 309 }
299 } 310 }
300 311
301 InterfaceTypeForLink _computeSupertype() { 312 InterfaceType _computeSupertype() {
302 if (_unlinkedClass.supertype != null) { 313 if (_unlinkedClass.supertype != null) {
303 DartTypeForLink supertype = 314 DartType supertype =
304 enclosingElement._resolveTypeRef(_unlinkedClass.supertype, this); 315 enclosingElement._resolveTypeRef(_unlinkedClass.supertype, this);
305 if (supertype is InterfaceTypeForLink) { 316 if (supertype is InterfaceType) {
306 return supertype; 317 return supertype;
307 } 318 }
308 // In the event that the supertype isn't an interface type (which may 319 // In the event that the supertype isn't an interface type (which may
309 // happen in the event of erroneous code) just fall through and pretend 320 // happen in the event of erroneous code) just fall through and pretend
310 // the supertype is `Object`. 321 // the supertype is `Object`.
311 } 322 }
312 return enclosingElement.enclosingElement._linker.objectType; 323 return enclosingElement.enclosingElement._linker.objectType;
313 } 324 }
314 } 325 }
315 326
316 /** 327 /**
317 * Element representing an enum resynthesized from a summary during 328 * Element representing an enum resynthesized from a summary during
318 * linking. 329 * linking.
319 */ 330 */
320 class ClassElementForLink_Enum extends ClassElementForLink { 331 class ClassElementForLink_Enum extends ClassElementForLink {
321 /** 332 /**
322 * The unlinked representation of the enum in the summary. 333 * The unlinked representation of the enum in the summary.
323 */ 334 */
324 final UnlinkedEnum _unlinkedEnum; 335 final UnlinkedEnum _unlinkedEnum;
325 336
326 InterfaceTypeForLink _type; 337 InterfaceType _type;
327 List<FieldElementForLink_EnumField> _fields; 338 List<FieldElementForLink_EnumField> _fields;
328 339
329 ClassElementForLink_Enum(this._unlinkedEnum); 340 ClassElementForLink_Enum(this._unlinkedEnum);
330 341
331 @override 342 @override
332 List<ConstructorElementForLink> get constructors => const []; 343 List<ConstructorElementForLink> get constructors => const [];
333 344
334 @override 345 @override
346 String get displayName => _unlinkedEnum.name;
347
348 @override
335 List<FieldElementForLink_EnumField> get fields { 349 List<FieldElementForLink_EnumField> get fields {
336 if (_fields == null) { 350 if (_fields == null) {
337 _fields = <FieldElementForLink_EnumField>[]; 351 _fields = <FieldElementForLink_EnumField>[];
338 _fields.add(new FieldElementForLink_EnumField(null)); 352 _fields.add(new FieldElementForLink_EnumField(null));
339 for (UnlinkedEnumValue value in _unlinkedEnum.values) { 353 for (UnlinkedEnumValue value in _unlinkedEnum.values) {
340 _fields.add(new FieldElementForLink_EnumField(value)); 354 _fields.add(new FieldElementForLink_EnumField(value));
341 } 355 }
342 } 356 }
343 return _fields; 357 return _fields;
344 } 358 }
345 359
346 @override 360 @override
347 bool get isObject => false; 361 bool get isObject => false;
348 362
349 @override 363 @override
350 String get name => _unlinkedEnum.name; 364 String get name => _unlinkedEnum.name;
351 365
352 @override 366 @override
353 ConstructorElementForLink get unnamedConstructor => null; 367 ConstructorElementForLink get unnamedConstructor => null;
354 368
355 @override 369 @override
356 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 370 DartType buildType(DartType getTypeArgument(int i),
357 List<int> implicitFunctionTypeIndices) => 371 List<int> implicitFunctionTypeIndices) =>
358 _type ??= new InterfaceTypeForLink(this); 372 _type ??= new InterfaceTypeImpl(this);
359 373
360 @override 374 @override
361 void link(LinkedUnitBuilder linkedUnit) {} 375 void link(LinkedUnitBuilder linkedUnit) {}
362 } 376 }
363 377
364 /** 378 /**
365 * Element representing a compilation unit resynthesized from a 379 * Element representing a compilation unit resynthesized from a
366 * summary during linking. 380 * summary during linking.
367 */ 381 */
368 abstract class CompilationUnitElementForLink implements CompilationUnitElement { 382 abstract class CompilationUnitElementForLink implements CompilationUnitElement {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return _references[index]; 506 return _references[index];
493 } 507 }
494 508
495 /** 509 /**
496 * Resolve an [EntityRef] into a type. If the reference is 510 * Resolve an [EntityRef] into a type. If the reference is
497 * unresolved, return [DynamicTypeImpl.instance]. 511 * unresolved, return [DynamicTypeImpl.instance].
498 * 512 *
499 * TODO(paulberry): or should we have a class representing an 513 * TODO(paulberry): or should we have a class representing an
500 * unresolved type, for consistency with the full element model? 514 * unresolved type, for consistency with the full element model?
501 */ 515 */
502 DartTypeForLink _resolveTypeRef( 516 DartType _resolveTypeRef(
503 EntityRef type, TypeParameterContext typeParameterContext, 517 EntityRef type, TypeParameterContext typeParameterContext,
504 {bool defaultVoid: false}) { 518 {bool defaultVoid: false}) {
505 if (type == null) { 519 if (type == null) {
506 if (defaultVoid) { 520 if (defaultVoid) {
507 return VoidTypeForLink.instance; 521 return VoidTypeImpl.instance;
508 } else { 522 } else {
509 return DynamicTypeForLink.instance; 523 return DynamicTypeImpl.instance;
510 } 524 }
511 } 525 }
512 if (type.paramReference != 0) { 526 if (type.paramReference != 0) {
513 return typeParameterContext.getTypeParameterType(type.paramReference); 527 return typeParameterContext.getTypeParameterType(type.paramReference);
514 } else if (type.syntheticReturnType != null) { 528 } else if (type.syntheticReturnType != null) {
515 // TODO(paulberry): implement. 529 // TODO(paulberry): implement.
516 throw new UnimplementedError(); 530 throw new UnimplementedError();
517 } else { 531 } else {
518 DartTypeForLink getTypeArgument(int i) { 532 DartType getTypeArgument(int i) {
519 if (i < type.typeArguments.length) { 533 if (i < type.typeArguments.length) {
520 return _resolveTypeRef(type.typeArguments[i], typeParameterContext); 534 return _resolveTypeRef(type.typeArguments[i], typeParameterContext);
521 } else { 535 } else {
522 return DynamicTypeForLink.instance; 536 return DynamicTypeImpl.instance;
523 } 537 }
524 } 538 }
525 ReferenceableElementForLink element = _resolveRef(type.reference); 539 ReferenceableElementForLink element = _resolveRef(type.reference);
526 return element.buildType( 540 return element.buildType(
527 getTypeArgument, type.implicitFunctionTypeIndices); 541 getTypeArgument, type.implicitFunctionTypeIndices);
528 } 542 }
529 } 543 }
530 } 544 }
531 545
532 /** 546 /**
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 _parameters = <ParameterElementForLink>[]; 863 _parameters = <ParameterElementForLink>[];
850 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { 864 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) {
851 _parameters.add(new ParameterElementForLink( 865 _parameters.add(new ParameterElementForLink(
852 unlinkedParam, enclosingElement.enclosingElement)); 866 unlinkedParam, enclosingElement.enclosingElement));
853 } 867 }
854 } 868 }
855 return _parameters; 869 return _parameters;
856 } 870 }
857 871
858 @override 872 @override
859 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 873 DartType buildType(DartType getTypeArgument(int i),
860 List<int> implicitFunctionTypeIndices) => 874 List<int> implicitFunctionTypeIndices) =>
861 DynamicTypeForLink.instance; 875 DynamicTypeImpl.instance;
862 876
863 @override 877 @override
864 ReferenceableElementForLink getContainedName(String name) => 878 ReferenceableElementForLink getContainedName(String name) =>
865 UndefinedElementForLink.instance; 879 UndefinedElementForLink.instance;
866 880
867 /** 881 /**
868 * Perform const cycle detection on this constructor. 882 * Perform const cycle detection on this constructor.
869 */ 883 */
870 void link(LinkedUnitBuilder linkedUnit) { 884 void link(LinkedUnitBuilder linkedUnit) {
871 if (_constNode != null && !isCycleFree) { 885 if (_constNode != null && !isCycleFree) {
(...skipping 23 matching lines...) Expand all
895 List<ConstNode> dependencies = <ConstNode>[]; 909 List<ConstNode> dependencies = <ConstNode>[];
896 collectDependencies( 910 collectDependencies(
897 dependencies, 911 dependencies,
898 variableElement.unlinkedVariable.constExpr, 912 variableElement.unlinkedVariable.constExpr,
899 variableElement.compilationUnit); 913 variableElement.compilationUnit);
900 return dependencies; 914 return dependencies;
901 } 915 }
902 } 916 }
903 917
904 /** 918 /**
905 * Representation of a type resynthesized from a summary during linking.
906 */
907 class DartTypeForLink implements DartType {
908 const DartTypeForLink();
909
910 @override
911 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
912 }
913
914 /**
915 * An instance of [DependencyWalker] contains the core algorithms for 919 * An instance of [DependencyWalker] contains the core algorithms for
916 * walking a dependency graph and evaluating nodes in a safe order. 920 * walking a dependency graph and evaluating nodes in a safe order.
917 */ 921 */
918 abstract class DependencyWalker<NodeType extends Node<NodeType>> { 922 abstract class DependencyWalker<NodeType extends Node<NodeType>> {
919 /** 923 /**
920 * Called by [walk] to evaluate a single non-cyclical node, after 924 * Called by [walk] to evaluate a single non-cyclical node, after
921 * all that node's dependencies have been evaluated. 925 * all that node's dependencies have been evaluated.
922 */ 926 */
923 void evaluate(NodeType v); 927 void evaluate(NodeType v);
924 928
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1035 }
1032 } 1036 }
1033 } 1037 }
1034 1038
1035 // Kick off the algorithm starting with the starting point. 1039 // Kick off the algorithm starting with the starting point.
1036 strongConnect(startingPoint); 1040 strongConnect(startingPoint);
1037 } 1041 }
1038 } 1042 }
1039 1043
1040 /** 1044 /**
1041 * Representation of the dynamic type during linking.
1042 */
1043 class DynamicTypeForLink extends DartTypeForLink {
1044 /**
1045 * Singleton instance of the dynamic type.
1046 */
1047 static const DynamicTypeForLink instance = const DynamicTypeForLink._();
1048
1049 const DynamicTypeForLink._();
1050 }
1051
1052 /**
1053 * Element representing a field resynthesized from a summary during 1045 * Element representing a field resynthesized from a summary during
1054 * linking. 1046 * linking.
1055 */ 1047 */
1056 abstract class FieldElementForLink 1048 abstract class FieldElementForLink
1057 implements FieldElement, ReferenceableElementForLink {} 1049 implements FieldElement, ReferenceableElementForLink {}
1058 1050
1059 /** 1051 /**
1060 * Specialization of [FieldElementForLink] for class fields. 1052 * Specialization of [FieldElementForLink] for class fields.
1061 */ 1053 */
1062 class FieldElementForLink_ClassField extends VariableElementForLink 1054 class FieldElementForLink_ClassField extends VariableElementForLink
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 } 1090 }
1099 1091
1100 @override 1092 @override
1101 bool get isStatic => true; 1093 bool get isStatic => true;
1102 1094
1103 @override 1095 @override
1104 String get name => 1096 String get name =>
1105 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name; 1097 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name;
1106 1098
1107 @override 1099 @override
1108 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 1100 DartType buildType(DartType getTypeArgument(int i),
1109 List<int> implicitFunctionTypeIndices) => 1101 List<int> implicitFunctionTypeIndices) =>
1110 DynamicTypeForLink.instance; 1102 DynamicTypeImpl.instance;
1111 1103
1112 @override 1104 @override
1113 ReferenceableElementForLink getContainedName(String name) => 1105 ReferenceableElementForLink getContainedName(String name) =>
1114 UndefinedElementForLink.instance; 1106 UndefinedElementForLink.instance;
1115 1107
1116 @override 1108 @override
1117 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1109 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1118 } 1110 }
1119 1111
1120 /** 1112 /**
1121 * Representation of an interface type during linking.
1122 *
1123 * TODO(paulberry): add the ability to represent type arguments.
1124 */
1125 class InterfaceTypeForLink extends DartTypeForLink implements InterfaceType {
1126 @override
1127 final ClassElementForLink element;
1128
1129 InterfaceTypeForLink(this.element);
1130 }
1131
1132 /**
1133 * Element representing a library resynthesied from a summary during 1113 * Element representing a library resynthesied from a summary during
1134 * linking. The type parameter, [UnitElement], represents the type 1114 * linking. The type parameter, [UnitElement], represents the type
1135 * that will be used for the compilation unit elements. 1115 * that will be used for the compilation unit elements.
1136 */ 1116 */
1137 abstract class LibraryElementForLink< 1117 abstract class LibraryElementForLink<
1138 UnitElement extends CompilationUnitElementForLink> 1118 UnitElement extends CompilationUnitElementForLink>
1139 implements LibraryElement { 1119 implements LibraryElement {
1140 /** 1120 /**
1141 * Pointer back to the linker. 1121 * Pointer back to the linker.
1142 */ 1122 */
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 1308
1329 NonstaticMemberElementForLink(this._constNode); 1309 NonstaticMemberElementForLink(this._constNode);
1330 1310
1331 @override 1311 @override
1332 ConstructorElementForLink get asConstructor => null; 1312 ConstructorElementForLink get asConstructor => null;
1333 1313
1334 @override 1314 @override
1335 ConstVariableNode get asConstVariable => _constNode; 1315 ConstVariableNode get asConstVariable => _constNode;
1336 1316
1337 @override 1317 @override
1338 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 1318 DartType buildType(DartType getTypeArgument(int i),
1339 List<int> implicitFunctionTypeIndices) => 1319 List<int> implicitFunctionTypeIndices) =>
1340 DynamicTypeForLink.instance; 1320 DynamicTypeImpl.instance;
1341 1321
1342 @override 1322 @override
1343 ReferenceableElementForLink getContainedName(String name) => this; 1323 ReferenceableElementForLink getContainedName(String name) => this;
1344 } 1324 }
1345 1325
1346 /** 1326 /**
1347 * Element representing a function or method parameter resynthesized 1327 * Element representing a function or method parameter resynthesized
1348 * from a summary during linking. 1328 * from a summary during linking.
1349 */ 1329 */
1350 class ParameterElementForLink implements ParameterElement { 1330 class ParameterElementForLink implements ParameterElement {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 * constant variable, return the [ConstVariableNode] for the 1372 * constant variable, return the [ConstVariableNode] for the
1393 * constant value. Otherwise return `null`. 1373 * constant value. Otherwise return `null`.
1394 */ 1374 */
1395 ConstVariableNode get asConstVariable; 1375 ConstVariableNode get asConstVariable;
1396 1376
1397 /** 1377 /**
1398 * Return the type indicated by this element when it is used in a 1378 * Return the type indicated by this element when it is used in a
1399 * type instantiation context. If this element can't legally be 1379 * type instantiation context. If this element can't legally be
1400 * instantiated as a type, return the dynamic type. 1380 * instantiated as a type, return the dynamic type.
1401 */ 1381 */
1402 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 1382 DartType buildType(
1403 List<int> implicitFunctionTypeIndices); 1383 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices);
1404 1384
1405 /** 1385 /**
1406 * If this element contains other named elements, return the 1386 * If this element contains other named elements, return the
1407 * contained element having the given [name]. If this element can't 1387 * contained element having the given [name]. If this element can't
1408 * contain other named elements, or it doesn't contain an element 1388 * contain other named elements, or it doesn't contain an element
1409 * with the given name, return the singleton of 1389 * with the given name, return the singleton of
1410 * [UndefinedElementForLink]. 1390 * [UndefinedElementForLink].
1411 */ 1391 */
1412 ReferenceableElementForLink getContainedName(String name); 1392 ReferenceableElementForLink getContainedName(String name);
1413 } 1393 }
(...skipping 13 matching lines...) Expand all
1427 } 1407 }
1428 1408
1429 /** 1409 /**
1430 * Interface representing elements which can serve as the context within which 1410 * Interface representing elements which can serve as the context within which
1431 * type parameter indices are interpreted. 1411 * type parameter indices are interpreted.
1432 */ 1412 */
1433 abstract class TypeParameterContext { 1413 abstract class TypeParameterContext {
1434 /** 1414 /**
1435 * Convert the given [index] into a type parameter type. 1415 * Convert the given [index] into a type parameter type.
1436 */ 1416 */
1437 TypeParameterTypeForLink getTypeParameterType(int index); 1417 TypeParameterType getTypeParameterType(int index);
1438 } 1418 }
1439 1419
1440 /** 1420 /**
1441 * Representation of a type based on a type parameter during linking. 1421 * Element representing a type parameter resynthesized from a summary during
1442 * 1422 * linking.
1443 * TODO(paulberry): add more functionality as needed.
1444 */ 1423 */
1445 class TypeParameterTypeForLink extends DartTypeForLink 1424 class TypeParameterElementForLink implements TypeParameterElement {
1446 implements TypeParameterType {} 1425 /**
1426 * The unlinked representation of the type parameter in the summary.
1427 */
1428 final UnlinkedTypeParam _unlinkedTypeParam;
1429
1430 TypeParameterElementForLink(this._unlinkedTypeParam);
1431
1432 @override
1433 String get name => _unlinkedTypeParam.name;
1434
1435 @override
1436 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1437 }
1447 1438
1448 /** 1439 /**
1449 * Singleton element used for unresolved references. 1440 * Singleton element used for unresolved references.
1450 */ 1441 */
1451 class UndefinedElementForLink implements ReferenceableElementForLink { 1442 class UndefinedElementForLink implements ReferenceableElementForLink {
1452 static const UndefinedElementForLink instance = 1443 static const UndefinedElementForLink instance =
1453 const UndefinedElementForLink._(); 1444 const UndefinedElementForLink._();
1454 1445
1455 const UndefinedElementForLink._(); 1446 const UndefinedElementForLink._();
1456 1447
1457 @override 1448 @override
1458 ConstructorElementForLink get asConstructor => null; 1449 ConstructorElementForLink get asConstructor => null;
1459 1450
1460 @override 1451 @override
1461 ConstVariableNode get asConstVariable => null; 1452 ConstVariableNode get asConstVariable => null;
1462 1453
1463 @override 1454 @override
1464 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 1455 DartType buildType(DartType getTypeArgument(int i),
1465 List<int> implicitFunctionTypeIndices) => 1456 List<int> implicitFunctionTypeIndices) =>
1466 DynamicTypeForLink.instance; 1457 DynamicTypeImpl.instance;
1467 1458
1468 @override 1459 @override
1469 ReferenceableElementForLink getContainedName(String name) => this; 1460 ReferenceableElementForLink getContainedName(String name) => this;
1470 } 1461 }
1471 1462
1472 /** 1463 /**
1473 * Element representing a top level variable resynthesized from a 1464 * Element representing a top level variable resynthesized from a
1474 * summary during linking. 1465 * summary during linking.
1475 */ 1466 */
1476 class VariableElementForLink 1467 class VariableElementForLink
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 @override 1501 @override
1511 bool get isFinal => unlinkedVariable.isFinal; 1502 bool get isFinal => unlinkedVariable.isFinal;
1512 1503
1513 @override 1504 @override
1514 bool get isStatic; 1505 bool get isStatic;
1515 1506
1516 @override 1507 @override
1517 String get name => unlinkedVariable.name; 1508 String get name => unlinkedVariable.name;
1518 1509
1519 @override 1510 @override
1520 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), 1511 DartType buildType(DartType getTypeArgument(int i),
1521 List<int> implicitFunctionTypeIndices) => 1512 List<int> implicitFunctionTypeIndices) =>
1522 DynamicTypeForLink.instance; 1513 DynamicTypeImpl.instance;
1523 1514
1524 ReferenceableElementForLink getContainedName(String name) { 1515 ReferenceableElementForLink getContainedName(String name) {
1525 return new NonstaticMemberElementForLink(_constNode); 1516 return new NonstaticMemberElementForLink(_constNode);
1526 } 1517 }
1527 1518
1528 @override 1519 @override
1529 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1520 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1530 } 1521 }
1531 1522
1532 /** 1523 /**
1533 * Representation of the void type during linking.
1534 */
1535 class VoidTypeForLink extends DartTypeForLink {
1536 static const VoidTypeForLink instance = const VoidTypeForLink._();
1537 const VoidTypeForLink._();
1538 }
1539
1540 /**
1541 * Instances of [_Linker] contain the necessary information to link 1524 * Instances of [_Linker] contain the necessary information to link
1542 * together a single build unit. 1525 * together a single build unit.
1543 */ 1526 */
1544 class _Linker { 1527 class _Linker {
1545 /** 1528 /**
1546 * Callback to ask the client for a [LinkedLibrary] for a 1529 * Callback to ask the client for a [LinkedLibrary] for a
1547 * dependency. 1530 * dependency.
1548 */ 1531 */
1549 final GetDependencyCallback getDependency; 1532 final GetDependencyCallback getDependency;
1550 1533
(...skipping 10 matching lines...) Expand all
1561 final Map<Uri, LibraryElementForLink> _libraries = 1544 final Map<Uri, LibraryElementForLink> _libraries =
1562 <Uri, LibraryElementForLink>{}; 1545 <Uri, LibraryElementForLink>{};
1563 1546
1564 /** 1547 /**
1565 * List of library elements for the libraries in the build unit 1548 * List of library elements for the libraries in the build unit
1566 * being linked. 1549 * being linked.
1567 */ 1550 */
1568 final List<LibraryElementInBuildUnit> _librariesInBuildUnit = 1551 final List<LibraryElementInBuildUnit> _librariesInBuildUnit =
1569 <LibraryElementInBuildUnit>[]; 1552 <LibraryElementInBuildUnit>[];
1570 1553
1571 InterfaceTypeForLink _objectType; 1554 InterfaceType _objectType;
1572 LibraryElementForLink _coreLibrary; 1555 LibraryElementForLink _coreLibrary;
1573 1556
1574 _Linker(Map<String, LinkedLibraryBuilder> linkedLibraries, this.getDependency, 1557 _Linker(Map<String, LinkedLibraryBuilder> linkedLibraries, this.getDependency,
1575 this.getUnit) { 1558 this.getUnit) {
1576 // Create elements for the libraries to be linked. The rest of 1559 // Create elements for the libraries to be linked. The rest of
1577 // the element model will be created on demand. 1560 // the element model will be created on demand.
1578 linkedLibraries 1561 linkedLibraries
1579 .forEach((String absoluteUri, LinkedLibraryBuilder linkedLibrary) { 1562 .forEach((String absoluteUri, LinkedLibraryBuilder linkedLibrary) {
1580 Uri uri = Uri.parse(absoluteUri); 1563 Uri uri = Uri.parse(absoluteUri);
1581 _librariesInBuildUnit.add(_libraries[uri] = 1564 _librariesInBuildUnit.add(_libraries[uri] =
1582 new LibraryElementInBuildUnit(this, uri, linkedLibrary)); 1565 new LibraryElementInBuildUnit(this, uri, linkedLibrary));
1583 }); 1566 });
1584 } 1567 }
1585 1568
1586 /** 1569 /**
1587 * Get the library element for `dart:core`. 1570 * Get the library element for `dart:core`.
1588 */ 1571 */
1589 LibraryElementForLink get coreLibrary => 1572 LibraryElementForLink get coreLibrary =>
1590 _coreLibrary ??= getLibrary(Uri.parse('dart:core')); 1573 _coreLibrary ??= getLibrary(Uri.parse('dart:core'));
1591 1574
1592 /** 1575 /**
1593 * Get the `InterfaceType` for the type `Object`. 1576 * Get the `InterfaceType` for the type `Object`.
1594 */ 1577 */
1595 InterfaceTypeForLink get objectType => _objectType ??= coreLibrary 1578 InterfaceType get objectType => _objectType ??= coreLibrary
1596 .getContainedName('Object') 1579 .getContainedName('Object')
1597 .buildType((int i) => DynamicTypeForLink.instance, const []); 1580 .buildType((int i) => DynamicTypeImpl.instance, const []);
1598 1581
1599 /** 1582 /**
1600 * Get the library element for the library having the given [uri]. 1583 * Get the library element for the library having the given [uri].
1601 */ 1584 */
1602 LibraryElementForLink getLibrary(Uri uri) => _libraries.putIfAbsent( 1585 LibraryElementForLink getLibrary(Uri uri) => _libraries.putIfAbsent(
1603 uri, 1586 uri,
1604 () => new LibraryElementInDependency( 1587 () => new LibraryElementInDependency(
1605 this, uri, getDependency(uri.toString()))); 1588 this, uri, getDependency(uri.toString())));
1606 1589
1607 /** 1590 /**
1608 * Perform type inference and const cycle detection on all libraries 1591 * Perform type inference and const cycle detection on all libraries
1609 * in the build unit being linked. 1592 * in the build unit being linked.
1610 */ 1593 */
1611 void link() { 1594 void link() {
1612 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { 1595 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) {
1613 library.link(); 1596 library.link();
1614 } 1597 }
1615 // TODO(paulberry): set dependencies. 1598 // TODO(paulberry): set dependencies.
1616 } 1599 }
1617 1600
1618 /** 1601 /**
1619 * Throw away any information produced by a previous call to [link]. 1602 * Throw away any information produced by a previous call to [link].
1620 */ 1603 */
1621 void unlink() { 1604 void unlink() {
1622 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { 1605 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) {
1623 library.unlink(); 1606 library.unlink();
1624 } 1607 }
1625 } 1608 }
1626 } 1609 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698