| OLD | NEW |
| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 * [UnlinkedUnit] objects. | 116 * [UnlinkedUnit] objects. |
| 117 */ | 117 */ |
| 118 typedef UnlinkedUnit GetUnitCallback(String absoluteUri); | 118 typedef UnlinkedUnit GetUnitCallback(String absoluteUri); |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Element representing a class or enum resynthesized from a summary | 121 * Element representing a class or enum resynthesized from a summary |
| 122 * during linking. | 122 * during linking. |
| 123 */ | 123 */ |
| 124 abstract class ClassElementForLink | 124 abstract class ClassElementForLink |
| 125 implements ClassElement, ReferenceableElementForLink { | 125 implements ClassElement, ReferenceableElementForLink { |
| 126 Map<String, ReferenceableElementForLink> _containedNames; |
| 127 |
| 126 @override | 128 @override |
| 127 ConstructorElementForLink get asConstructor => unnamedConstructor; | 129 ConstructorElementForLink get asConstructor => unnamedConstructor; |
| 128 | 130 |
| 131 @override |
| 132 ConstVariableNode get asConstVariable { |
| 133 // TODO(paulberry): implement. |
| 134 throw new UnimplementedError(); |
| 135 } |
| 136 |
| 137 @override |
| 138 List<ConstructorElementForLink> get constructors; |
| 139 |
| 140 @override |
| 141 List<FieldElementForLink> get fields; |
| 142 |
| 129 /** | 143 /** |
| 130 * Indicates whether this is the core class `Object`. | 144 * Indicates whether this is the core class `Object`. |
| 131 */ | 145 */ |
| 132 bool get isObject; | 146 bool get isObject; |
| 133 | 147 |
| 134 @override | 148 @override |
| 135 String get name; | 149 String get name; |
| 136 | 150 |
| 137 @override | 151 @override |
| 138 ConstructorElementForLink get unnamedConstructor; | 152 ConstructorElementForLink get unnamedConstructor; |
| 139 | 153 |
| 154 @override |
| 155 ReferenceableElementForLink getContainedName(name) { |
| 156 if (_containedNames == null) { |
| 157 _containedNames = <String, ReferenceableElementForLink>{}; |
| 158 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 159 for (ConstructorElementForLink constructor in constructors) { |
| 160 _containedNames[constructor.name] = constructor; |
| 161 } |
| 162 for (FieldElementForLink field in fields) { |
| 163 // TODO(paulberry): do we need to handle nonstatic fields for |
| 164 // consistent behavior with erroneous code? |
| 165 if (field.isStatic) { |
| 166 _containedNames[field.name] = field; |
| 167 } |
| 168 } |
| 169 // TODO(paulberry): add methods. |
| 170 } |
| 171 return _containedNames.putIfAbsent( |
| 172 name, () => UndefinedElementForLink.instance); |
| 173 } |
| 174 |
| 140 /** | 175 /** |
| 141 * Perform type inference and cycle detection on this class and | 176 * Perform type inference and cycle detection on this class and |
| 142 * store the resulting information in the enclosing elements. | 177 * store the resulting information in the enclosing elements. |
| 143 */ | 178 */ |
| 144 void link(LinkedUnitBuilder linkedUnit); | 179 void link(LinkedUnitBuilder linkedUnit); |
| 145 | 180 |
| 146 @override | 181 @override |
| 147 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 182 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 148 } | 183 } |
| 149 | 184 |
| 150 /** | 185 /** |
| 151 * Element representing a class resynthesized from a summary during | 186 * Element representing a class resynthesized from a summary during |
| 152 * linking. | 187 * linking. |
| 153 */ | 188 */ |
| 154 class ClassElementForLink_Class extends ClassElementForLink { | 189 class ClassElementForLink_Class extends ClassElementForLink { |
| 155 /** | 190 /** |
| 156 * The unlinked representation of the class in the summary. | 191 * The unlinked representation of the class in the summary. |
| 157 */ | 192 */ |
| 158 final UnlinkedClass _unlinkedClass; | 193 final UnlinkedClass _unlinkedClass; |
| 159 | 194 |
| 160 @override | 195 @override |
| 161 final CompilationUnitElementForLink enclosingElement; | 196 final CompilationUnitElementForLink enclosingElement; |
| 162 | 197 |
| 163 List<ConstructorElementForLink> _constructors; | 198 List<ConstructorElementForLink> _constructors; |
| 164 ConstructorElementForLink _unnamedConstructor; | 199 ConstructorElementForLink _unnamedConstructor; |
| 165 bool _unnamedConstructorComputed = false; | 200 bool _unnamedConstructorComputed = false; |
| 166 List<FieldElementForLink> _fields; | 201 List<FieldElementForLink_ClassField> _fields; |
| 167 InterfaceTypeForLink _supertype; | 202 InterfaceTypeForLink _supertype; |
| 168 InterfaceTypeForLink _type; | 203 InterfaceTypeForLink _type; |
| 169 | 204 |
| 170 ClassElementForLink_Class(this.enclosingElement, this._unlinkedClass); | 205 ClassElementForLink_Class(this.enclosingElement, this._unlinkedClass); |
| 171 | 206 |
| 172 @override | 207 @override |
| 173 List<ConstructorElementForLink> get constructors { | 208 List<ConstructorElementForLink> get constructors { |
| 174 if (_constructors == null) { | 209 if (_constructors == null) { |
| 175 _constructors = <ConstructorElementForLink>[]; | 210 _constructors = <ConstructorElementForLink>[]; |
| 176 for (UnlinkedExecutable unlinkedExecutable | 211 for (UnlinkedExecutable unlinkedExecutable |
| 177 in _unlinkedClass.executables) { | 212 in _unlinkedClass.executables) { |
| 178 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { | 213 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { |
| 179 _constructors | 214 _constructors |
| 180 .add(new ConstructorElementForLink(this, unlinkedExecutable)); | 215 .add(new ConstructorElementForLink(this, unlinkedExecutable)); |
| 181 } | 216 } |
| 182 } | 217 } |
| 183 } | 218 } |
| 184 return _constructors; | 219 return _constructors; |
| 185 } | 220 } |
| 186 | 221 |
| 187 @override | 222 @override |
| 188 List<FieldElementForLink> get fields { | 223 List<FieldElementForLink_ClassField> get fields { |
| 189 if (_fields == null) { | 224 if (_fields == null) { |
| 190 _fields = <FieldElementForLink>[]; | 225 _fields = <FieldElementForLink_ClassField>[]; |
| 191 for (UnlinkedVariable field in _unlinkedClass.fields) { | 226 for (UnlinkedVariable field in _unlinkedClass.fields) { |
| 192 _fields.add(new FieldElementForLink(this, field)); | 227 _fields.add(new FieldElementForLink_ClassField(this, field)); |
| 193 } | 228 } |
| 194 } | 229 } |
| 195 return _fields; | 230 return _fields; |
| 196 } | 231 } |
| 197 | 232 |
| 198 @override | 233 @override |
| 199 bool get isObject => _unlinkedClass.hasNoSupertype; | 234 bool get isObject => _unlinkedClass.hasNoSupertype; |
| 200 | 235 |
| 201 @override | 236 @override |
| 202 String get name => _unlinkedClass.name; | 237 String get name => _unlinkedClass.name; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 222 } | 257 } |
| 223 _unnamedConstructorComputed = true; | 258 _unnamedConstructorComputed = true; |
| 224 } | 259 } |
| 225 return _unnamedConstructor; | 260 return _unnamedConstructor; |
| 226 } | 261 } |
| 227 | 262 |
| 228 @override | 263 @override |
| 229 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), | 264 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 230 List<int> implicitFunctionTypeIndices) { | 265 List<int> implicitFunctionTypeIndices) { |
| 231 if (_unlinkedClass.typeParameters.length != 0) { | 266 if (_unlinkedClass.typeParameters.length != 0) { |
| 232 // TODO(paulberry): implement. | 267 return new InterfaceTypeForLink(this); |
| 233 throw new UnimplementedError(); | |
| 234 } else { | 268 } else { |
| 235 return _type ??= new InterfaceTypeForLink(this); | 269 return _type ??= new InterfaceTypeForLink(this); |
| 236 } | 270 } |
| 237 } | 271 } |
| 238 | 272 |
| 239 @override | 273 @override |
| 240 ReferenceableElementForLink getContainedName(name) { | |
| 241 // TODO(paulberry): implement. | |
| 242 throw new UnimplementedError(); | |
| 243 } | |
| 244 | |
| 245 @override | |
| 246 void link(LinkedUnitBuilder linkedUnit) { | 274 void link(LinkedUnitBuilder linkedUnit) { |
| 247 for (ConstructorElementForLink constructorElement in constructors) { | 275 for (ConstructorElementForLink constructorElement in constructors) { |
| 248 constructorElement.link(linkedUnit); | 276 constructorElement.link(linkedUnit); |
| 249 } | 277 } |
| 250 } | 278 } |
| 251 } | 279 } |
| 252 | 280 |
| 253 /** | 281 /** |
| 254 * Element representing an enum resynthesized from a summary during | 282 * Element representing an enum resynthesized from a summary during |
| 255 * linking. | 283 * linking. |
| 256 */ | 284 */ |
| 257 class ClassElementForLink_Enum extends ClassElementForLink { | 285 class ClassElementForLink_Enum extends ClassElementForLink { |
| 258 /** | 286 /** |
| 259 * The unlinked representation of the enum in the summary. | 287 * The unlinked representation of the enum in the summary. |
| 260 */ | 288 */ |
| 261 final UnlinkedEnum _unlinkedEnum; | 289 final UnlinkedEnum _unlinkedEnum; |
| 262 | 290 |
| 291 InterfaceTypeForLink _type; |
| 292 List<FieldElementForLink_EnumField> _fields; |
| 293 |
| 263 ClassElementForLink_Enum(this._unlinkedEnum); | 294 ClassElementForLink_Enum(this._unlinkedEnum); |
| 264 | 295 |
| 265 @override | 296 @override |
| 297 List<ConstructorElementForLink> get constructors => const []; |
| 298 |
| 299 @override |
| 300 List<FieldElementForLink_EnumField> get fields { |
| 301 if (_fields == null) { |
| 302 _fields = <FieldElementForLink_EnumField>[]; |
| 303 _fields.add(new FieldElementForLink_EnumField(null)); |
| 304 for (UnlinkedEnumValue value in _unlinkedEnum.values) { |
| 305 _fields.add(new FieldElementForLink_EnumField(value)); |
| 306 } |
| 307 } |
| 308 return _fields; |
| 309 } |
| 310 |
| 311 @override |
| 266 bool get isObject => false; | 312 bool get isObject => false; |
| 267 | 313 |
| 268 @override | 314 @override |
| 269 String get name => _unlinkedEnum.name; | 315 String get name => _unlinkedEnum.name; |
| 270 | 316 |
| 271 @override | 317 @override |
| 272 ConstructorElementForLink get unnamedConstructor => null; | 318 ConstructorElementForLink get unnamedConstructor => null; |
| 273 | 319 |
| 274 @override | 320 @override |
| 275 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), | 321 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 276 List<int> implicitFunctionTypeIndices) { | 322 List<int> implicitFunctionTypeIndices) => |
| 277 // TODO(paulberry): implement. | 323 _type ??= new InterfaceTypeForLink(this); |
| 278 throw new UnimplementedError(); | |
| 279 } | |
| 280 | |
| 281 @override | |
| 282 ReferenceableElementForLink getContainedName(name) { | |
| 283 // TODO(paulberry): implement. | |
| 284 throw new UnimplementedError(); | |
| 285 } | |
| 286 | 324 |
| 287 @override | 325 @override |
| 288 void link(LinkedUnitBuilder linkedUnit) {} | 326 void link(LinkedUnitBuilder linkedUnit) {} |
| 289 } | 327 } |
| 290 | 328 |
| 291 /** | 329 /** |
| 292 * Element representing a compilation unit resynthesized from a | 330 * Element representing a compilation unit resynthesized from a |
| 293 * summary during linking. | 331 * summary during linking. |
| 294 */ | 332 */ |
| 295 abstract class CompilationUnitElementForLink implements CompilationUnitElement { | 333 abstract class CompilationUnitElementForLink implements CompilationUnitElement { |
| 296 /** | 334 /** |
| 297 * The unlinked representation of the compilation unit in the | 335 * The unlinked representation of the compilation unit in the |
| 298 * summary. | 336 * summary. |
| 299 */ | 337 */ |
| 300 final UnlinkedUnit _unlinkedUnit; | 338 final UnlinkedUnit _unlinkedUnit; |
| 301 | 339 |
| 302 /** | 340 /** |
| 303 * For each entry in [UnlinkedUnit.references], the element referred | 341 * For each entry in [UnlinkedUnit.references], the element referred |
| 304 * to by the reference, or `null` if it hasn't been located yet. | 342 * to by the reference, or `null` if it hasn't been located yet. |
| 305 */ | 343 */ |
| 306 final List<ReferenceableElementForLink> _references; | 344 final List<ReferenceableElementForLink> _references; |
| 307 | 345 |
| 308 List<ClassElementForLink> _types; | 346 List<ClassElementForLink> _types; |
| 309 Map<String, ReferenceableElementForLink> _containedNames; | 347 Map<String, ReferenceableElementForLink> _containedNames; |
| 348 List<TopLevelVariableElementForLink> _topLevelVariables; |
| 310 | 349 |
| 311 @override | 350 @override |
| 312 final LibraryElementForLink enclosingElement; | 351 final LibraryElementForLink enclosingElement; |
| 313 | 352 |
| 314 CompilationUnitElementForLink( | 353 CompilationUnitElementForLink( |
| 315 this.enclosingElement, UnlinkedUnit unlinkedUnit) | 354 this.enclosingElement, UnlinkedUnit unlinkedUnit) |
| 316 : _references = new List<ReferenceableElementForLink>( | 355 : _references = new List<ReferenceableElementForLink>( |
| 317 unlinkedUnit.references.length), | 356 unlinkedUnit.references.length), |
| 318 _unlinkedUnit = unlinkedUnit; | 357 _unlinkedUnit = unlinkedUnit; |
| 319 | 358 |
| 320 @override | 359 @override |
| 321 bool get isInBuildUnit; | 360 bool get isInBuildUnit; |
| 322 | 361 |
| 323 @override | 362 @override |
| 363 List<TopLevelVariableElementForLink> get topLevelVariables { |
| 364 if (_topLevelVariables == null) { |
| 365 _topLevelVariables = <TopLevelVariableElementForLink>[]; |
| 366 for (UnlinkedVariable unlinkedVariable in _unlinkedUnit.variables) { |
| 367 _topLevelVariables |
| 368 .add(new TopLevelVariableElementForLink(this, unlinkedVariable)); |
| 369 } |
| 370 } |
| 371 return _topLevelVariables; |
| 372 } |
| 373 |
| 374 @override |
| 324 List<ClassElementForLink> get types { | 375 List<ClassElementForLink> get types { |
| 325 if (_types == null) { | 376 if (_types == null) { |
| 326 _types = <ClassElementForLink>[]; | 377 _types = <ClassElementForLink>[]; |
| 327 for (UnlinkedClass unlinkedClass in _unlinkedUnit.classes) { | 378 for (UnlinkedClass unlinkedClass in _unlinkedUnit.classes) { |
| 328 _types.add(new ClassElementForLink_Class(this, unlinkedClass)); | 379 _types.add(new ClassElementForLink_Class(this, unlinkedClass)); |
| 329 } | 380 } |
| 330 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { | 381 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { |
| 331 _types.add(new ClassElementForLink_Enum(unlinkedEnum)); | 382 _types.add(new ClassElementForLink_Enum(unlinkedEnum)); |
| 332 } | 383 } |
| 333 } | 384 } |
| 334 return _types; | 385 return _types; |
| 335 } | 386 } |
| 336 | 387 |
| 337 /** | 388 /** |
| 338 * The linked representation of the compilation unit in the summary. | 389 * The linked representation of the compilation unit in the summary. |
| 339 */ | 390 */ |
| 340 LinkedUnit get _linkedUnit; | 391 LinkedUnit get _linkedUnit; |
| 341 | 392 |
| 342 /** | 393 /** |
| 343 * Search the unit for a top level element with the given [name]. | 394 * Search the unit for a top level element with the given [name]. |
| 344 * If no name is found, return the singleton instance of | 395 * If no name is found, return the singleton instance of |
| 345 * [UndefinedElementForLink]. | 396 * [UndefinedElementForLink]. |
| 346 */ | 397 */ |
| 347 ReferenceableElementForLink getContainedName(name) { | 398 ReferenceableElementForLink getContainedName(name) { |
| 348 if (_containedNames == null) { | 399 if (_containedNames == null) { |
| 349 _containedNames = <String, ReferenceableElementForLink>{}; | 400 _containedNames = <String, ReferenceableElementForLink>{}; |
| 401 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 350 for (ClassElementForLink type in types) { | 402 for (ClassElementForLink type in types) { |
| 351 // TODO(paulberry): what's the correct way to handle name conflicts? | |
| 352 _containedNames[type.name] = type; | 403 _containedNames[type.name] = type; |
| 353 } | 404 } |
| 354 // TODO(paulberry): fill in other top level entities. | 405 for (TopLevelVariableElementForLink variable in topLevelVariables) { |
| 406 _containedNames[variable.name] = variable; |
| 407 } |
| 408 // TODO(paulberry): fill in other top level entities (typedefs |
| 409 // and executables). |
| 355 } | 410 } |
| 356 return _containedNames.putIfAbsent( | 411 return _containedNames.putIfAbsent( |
| 357 name, () => UndefinedElementForLink.instance); | 412 name, () => UndefinedElementForLink.instance); |
| 358 } | 413 } |
| 359 | 414 |
| 360 @override | 415 @override |
| 361 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 416 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 362 | 417 |
| 363 /** | 418 /** |
| 364 * Return the element referred to by the given [index] in | 419 * Return the element referred to by the given [index] in |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (superClass != null && !superClass.isObject) { | 592 if (superClass != null && !superClass.isObject) { |
| 538 ConstructorElementForLink unnamedConstructor = | 593 ConstructorElementForLink unnamedConstructor = |
| 539 superClass.unnamedConstructor; | 594 superClass.unnamedConstructor; |
| 540 safeAddDependency(unnamedConstructor?._constNode); | 595 safeAddDependency(unnamedConstructor?._constNode); |
| 541 } | 596 } |
| 542 } | 597 } |
| 543 for (FieldElementForLink field in enclosingClass.fields) { | 598 for (FieldElementForLink field in enclosingClass.fields) { |
| 544 // Note: non-static const isn't allowed but we handle it anyway so | 599 // Note: non-static const isn't allowed but we handle it anyway so |
| 545 // that we won't be confused by incorrect code. | 600 // that we won't be confused by incorrect code. |
| 546 if ((field.isFinal || field.isConst) && !field.isStatic) { | 601 if ((field.isFinal || field.isConst) && !field.isStatic) { |
| 547 safeAddDependency(field._constNode); | 602 safeAddDependency(field.asConstVariable); |
| 548 } | 603 } |
| 549 } | 604 } |
| 550 for (ParameterElementForLink parameterElement | 605 for (ParameterElementForLink parameterElement |
| 551 in constructorElement.parameters) { | 606 in constructorElement.parameters) { |
| 552 safeAddDependency(parameterElement._constNode); | 607 safeAddDependency(parameterElement._constNode); |
| 553 } | 608 } |
| 554 } | 609 } |
| 555 return dependencies; | 610 return dependencies; |
| 556 } | 611 } |
| 557 | 612 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 List<ConstNode> dependencies, | 661 List<ConstNode> dependencies, |
| 607 UnlinkedConst unlinkedConst, | 662 UnlinkedConst unlinkedConst, |
| 608 CompilationUnitElementForLink compilationUnit) { | 663 CompilationUnitElementForLink compilationUnit) { |
| 609 if (unlinkedConst == null) { | 664 if (unlinkedConst == null) { |
| 610 return; | 665 return; |
| 611 } | 666 } |
| 612 int refPtr = 0; | 667 int refPtr = 0; |
| 613 for (UnlinkedConstOperation operation in unlinkedConst.operations) { | 668 for (UnlinkedConstOperation operation in unlinkedConst.operations) { |
| 614 switch (operation) { | 669 switch (operation) { |
| 615 case UnlinkedConstOperation.pushReference: | 670 case UnlinkedConstOperation.pushReference: |
| 616 // TODO(paulberry): implement. | 671 EntityRef ref = unlinkedConst.references[refPtr++]; |
| 617 throw new UnimplementedError(); | 672 ConstVariableNode variable = |
| 673 compilationUnit._resolveRef(ref.reference).asConstVariable; |
| 674 if (variable != null) { |
| 675 dependencies.add(variable); |
| 676 } |
| 677 break; |
| 618 case UnlinkedConstOperation.makeTypedList: | 678 case UnlinkedConstOperation.makeTypedList: |
| 619 refPtr++; | 679 refPtr++; |
| 620 break; | 680 break; |
| 621 case UnlinkedConstOperation.makeTypedMap: | 681 case UnlinkedConstOperation.makeTypedMap: |
| 622 refPtr += 2; | 682 refPtr += 2; |
| 623 break; | 683 break; |
| 624 case UnlinkedConstOperation.invokeConstructor: | 684 case UnlinkedConstOperation.invokeConstructor: |
| 625 EntityRef ref = unlinkedConst.references[refPtr++]; | 685 EntityRef ref = unlinkedConst.references[refPtr++]; |
| 626 ConstructorElementForLink element = | 686 ConstructorElementForLink element = |
| 627 compilationUnit._resolveRef(ref.reference).asConstructor; | 687 compilationUnit._resolveRef(ref.reference).asConstructor; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 657 parameterElement._unlinkedParam.defaultValue, | 717 parameterElement._unlinkedParam.defaultValue, |
| 658 parameterElement.compilationUnit); | 718 parameterElement.compilationUnit); |
| 659 return dependencies; | 719 return dependencies; |
| 660 } | 720 } |
| 661 } | 721 } |
| 662 | 722 |
| 663 /** | 723 /** |
| 664 * Element representing a constructor resynthesized from a summary | 724 * Element representing a constructor resynthesized from a summary |
| 665 * during linking. | 725 * during linking. |
| 666 */ | 726 */ |
| 667 class ConstructorElementForLink implements ConstructorElement { | 727 class ConstructorElementForLink |
| 728 implements ConstructorElement, ReferenceableElementForLink { |
| 668 /** | 729 /** |
| 669 * The unlinked representation of the constructor in the summary. | 730 * The unlinked representation of the constructor in the summary. |
| 670 */ | 731 */ |
| 671 final UnlinkedExecutable _unlinkedExecutable; | 732 final UnlinkedExecutable _unlinkedExecutable; |
| 672 | 733 |
| 673 /** | 734 /** |
| 674 * If this is a `const` constructor and the enclosing library is | 735 * If this is a `const` constructor and the enclosing library is |
| 675 * part of the build unit being linked, the constructor's node in | 736 * part of the build unit being linked, the constructor's node in |
| 676 * the constant evaluation dependency graph. Otherwise `null`. | 737 * the constant evaluation dependency graph. Otherwise `null`. |
| 677 */ | 738 */ |
| 678 ConstConstructorNode _constNode; | 739 ConstConstructorNode _constNode; |
| 679 | 740 |
| 680 @override | 741 @override |
| 681 final ClassElementForLink_Class enclosingElement; | 742 final ClassElementForLink_Class enclosingElement; |
| 682 | 743 |
| 683 List<ParameterElementForLink> _parameters; | 744 List<ParameterElementForLink> _parameters; |
| 684 | 745 |
| 685 ConstructorElementForLink(this.enclosingElement, this._unlinkedExecutable) { | 746 ConstructorElementForLink(this.enclosingElement, this._unlinkedExecutable) { |
| 686 if (enclosingElement.enclosingElement.isInBuildUnit && | 747 if (enclosingElement.enclosingElement.isInBuildUnit && |
| 687 _unlinkedExecutable.constCycleSlot != 0) { | 748 _unlinkedExecutable.constCycleSlot != 0) { |
| 688 _constNode = new ConstConstructorNode(this); | 749 _constNode = new ConstConstructorNode(this); |
| 689 } | 750 } |
| 690 } | 751 } |
| 691 | 752 |
| 692 @override | 753 @override |
| 754 ConstructorElementForLink get asConstructor => this; |
| 755 |
| 756 @override |
| 757 ConstVariableNode get asConstVariable => null; |
| 758 |
| 759 @override |
| 693 bool get isCycleFree { | 760 bool get isCycleFree { |
| 694 if (!_constNode.isEvaluated) { | 761 if (!_constNode.isEvaluated) { |
| 695 new ConstDependencyWalker().walk(_constNode); | 762 new ConstDependencyWalker().walk(_constNode); |
| 696 } | 763 } |
| 697 return _constNode.isCycleFree; | 764 return _constNode.isCycleFree; |
| 698 } | 765 } |
| 699 | 766 |
| 700 @override | 767 @override |
| 701 String get name => _unlinkedExecutable.name; | 768 String get name => _unlinkedExecutable.name; |
| 702 | 769 |
| 703 @override | 770 @override |
| 704 List<ParameterElementForLink> get parameters { | 771 List<ParameterElementForLink> get parameters { |
| 705 if (_parameters == null) { | 772 if (_parameters == null) { |
| 706 _parameters = <ParameterElementForLink>[]; | 773 _parameters = <ParameterElementForLink>[]; |
| 707 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { | 774 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { |
| 708 _parameters.add(new ParameterElementForLink( | 775 _parameters.add(new ParameterElementForLink( |
| 709 unlinkedParam, enclosingElement.enclosingElement)); | 776 unlinkedParam, enclosingElement.enclosingElement)); |
| 710 } | 777 } |
| 711 } | 778 } |
| 712 return _parameters; | 779 return _parameters; |
| 713 } | 780 } |
| 714 | 781 |
| 782 @override |
| 783 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 784 List<int> implicitFunctionTypeIndices) => |
| 785 DynamicTypeForLink.instance; |
| 786 |
| 787 @override |
| 788 ReferenceableElementForLink getContainedName(name) => |
| 789 UndefinedElementForLink.instance; |
| 790 |
| 715 /** | 791 /** |
| 716 * Perform const cycle detection on this constructor. | 792 * Perform const cycle detection on this constructor. |
| 717 */ | 793 */ |
| 718 void link(LinkedUnitBuilder linkedUnit) { | 794 void link(LinkedUnitBuilder linkedUnit) { |
| 719 if (_constNode != null && !isCycleFree) { | 795 if (_constNode != null && !isCycleFree) { |
| 720 linkedUnit.constCycles.add(_unlinkedExecutable.constCycleSlot); | 796 linkedUnit.constCycles.add(_unlinkedExecutable.constCycleSlot); |
| 721 } | 797 } |
| 722 } | 798 } |
| 723 | 799 |
| 724 @override | 800 @override |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 class DynamicTypeForLink extends DartTypeForLink { | 979 class DynamicTypeForLink extends DartTypeForLink { |
| 904 /** | 980 /** |
| 905 * Singleton instance of the dynamic type. | 981 * Singleton instance of the dynamic type. |
| 906 */ | 982 */ |
| 907 static const DynamicTypeForLink instance = const DynamicTypeForLink._(); | 983 static const DynamicTypeForLink instance = const DynamicTypeForLink._(); |
| 908 | 984 |
| 909 const DynamicTypeForLink._(); | 985 const DynamicTypeForLink._(); |
| 910 } | 986 } |
| 911 | 987 |
| 912 /** | 988 /** |
| 913 * Element representing a field resynthesized from a summary during linking. | 989 * Element representing a field resynthesized from a summary during |
| 990 * linking. |
| 914 */ | 991 */ |
| 915 class FieldElementForLink extends VariableElementForLink | 992 abstract class FieldElementForLink |
| 916 implements FieldElement { | 993 implements FieldElement, ReferenceableElementForLink {} |
| 917 /** | 994 |
| 918 * The unlinked representation of the field in the summary. | 995 /** |
| 919 */ | 996 * Specialization of [FieldElementForLink] for class fields. |
| 997 */ |
| 998 class FieldElementForLink_ClassField extends VariableElementForLink |
| 999 implements FieldElementForLink { |
| 1000 @override |
| 920 final ClassElementForLink_Class enclosingElement; | 1001 final ClassElementForLink_Class enclosingElement; |
| 921 | 1002 |
| 922 FieldElementForLink(ClassElementForLink_Class enclosingElement, | 1003 FieldElementForLink_ClassField(ClassElementForLink_Class enclosingElement, |
| 923 UnlinkedVariable unlinkedVariable) | 1004 UnlinkedVariable unlinkedVariable) |
| 924 : enclosingElement = enclosingElement, | 1005 : enclosingElement = enclosingElement, |
| 925 super(unlinkedVariable, enclosingElement.enclosingElement); | 1006 super(unlinkedVariable, enclosingElement.enclosingElement); |
| 926 | 1007 |
| 927 @override | 1008 @override |
| 928 bool get isConst => unlinkedVariable.isConst; | 1009 bool get isStatic => unlinkedVariable.isStatic; |
| 1010 } |
| 1011 |
| 1012 /** |
| 1013 * Specialization of [FieldElementForLink] for enum fields. |
| 1014 */ |
| 1015 class FieldElementForLink_EnumField extends FieldElementForLink |
| 1016 implements FieldElement { |
| 1017 /** |
| 1018 * The unlinked representation of the field in the summary, or `null` if this |
| 1019 * is an enum's `values` field. |
| 1020 */ |
| 1021 final UnlinkedEnumValue unlinkedEnumValue; |
| 1022 |
| 1023 FieldElementForLink_EnumField(this.unlinkedEnumValue); |
| 929 | 1024 |
| 930 @override | 1025 @override |
| 931 bool get isFinal => unlinkedVariable.isFinal; | 1026 ConstructorElementForLink get asConstructor => null; |
| 932 | 1027 |
| 933 @override | 1028 @override |
| 934 bool get isStatic => unlinkedVariable.isStatic; | 1029 ConstVariableNode get asConstVariable { |
| 1030 // Even though enum fields are constants, there is no need to include them |
| 1031 // in the const dependency graph because they can't participate in a |
| 1032 // circularity. |
| 1033 return null; |
| 1034 } |
| 1035 |
| 1036 @override |
| 1037 bool get isStatic => true; |
| 1038 |
| 1039 @override |
| 1040 String get name => |
| 1041 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name; |
| 1042 |
| 1043 @override |
| 1044 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 1045 List<int> implicitFunctionTypeIndices) => |
| 1046 DynamicTypeForLink.instance; |
| 1047 |
| 1048 @override |
| 1049 ReferenceableElementForLink getContainedName(name) => |
| 1050 UndefinedElementForLink.instance; |
| 935 | 1051 |
| 936 @override | 1052 @override |
| 937 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1053 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 938 } | 1054 } |
| 939 | 1055 |
| 940 /** | 1056 /** |
| 941 * Representation of an interface type during linking. | 1057 * Representation of an interface type during linking. |
| 1058 * |
| 1059 * TODO(paulberry): add the ability to represent type arguments. |
| 942 */ | 1060 */ |
| 943 class InterfaceTypeForLink extends DartTypeForLink implements InterfaceType { | 1061 class InterfaceTypeForLink extends DartTypeForLink implements InterfaceType { |
| 944 @override | 1062 @override |
| 945 final ClassElementForLink element; | 1063 final ClassElementForLink element; |
| 946 | 1064 |
| 947 InterfaceTypeForLink(this.element); | 1065 InterfaceTypeForLink(this.element); |
| 948 } | 1066 } |
| 949 | 1067 |
| 950 /** | 1068 /** |
| 951 * Element representing a library resynthesied from a summary during | 1069 * Element representing a library resynthesied from a summary during |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 */ | 1277 */ |
| 1160 abstract class ReferenceableElementForLink { | 1278 abstract class ReferenceableElementForLink { |
| 1161 /** | 1279 /** |
| 1162 * If this element can be used in a constructor invocation context, | 1280 * If this element can be used in a constructor invocation context, |
| 1163 * return the associated constructor (which may be `this` or some | 1281 * return the associated constructor (which may be `this` or some |
| 1164 * other element). Otherwise return `null`. | 1282 * other element). Otherwise return `null`. |
| 1165 */ | 1283 */ |
| 1166 ConstructorElementForLink get asConstructor; | 1284 ConstructorElementForLink get asConstructor; |
| 1167 | 1285 |
| 1168 /** | 1286 /** |
| 1287 * If this element can be used in a getter context to refer to a |
| 1288 * constant variable, return the [ConstVariableNode] for the |
| 1289 * constant value. Otherwise return `null`. |
| 1290 */ |
| 1291 ConstVariableNode get asConstVariable; |
| 1292 |
| 1293 /** |
| 1169 * Return the type indicated by this element when it is used in a | 1294 * Return the type indicated by this element when it is used in a |
| 1170 * type instantiation context. If this element can't legally be | 1295 * type instantiation context. If this element can't legally be |
| 1171 * instantiated as a type, return the dynamic type. | 1296 * instantiated as a type, return the dynamic type. |
| 1172 */ | 1297 */ |
| 1173 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), | 1298 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 1174 List<int> implicitFunctionTypeIndices); | 1299 List<int> implicitFunctionTypeIndices); |
| 1175 | 1300 |
| 1176 /** | 1301 /** |
| 1177 * If this element contains other named elements, return the | 1302 * If this element contains other named elements, return the |
| 1178 * contained element having the given [name]. If this element can't | 1303 * contained element having the given [name]. If this element can't |
| 1179 * contain other named elements, or it doesn't contain an element | 1304 * contain other named elements, or it doesn't contain an element |
| 1180 * with the given name, return the singleton of | 1305 * with the given name, return the singleton of |
| 1181 * [UndefinedElementForLink]. | 1306 * [UndefinedElementForLink]. |
| 1182 */ | 1307 */ |
| 1183 ReferenceableElementForLink getContainedName(name); | 1308 ReferenceableElementForLink getContainedName(name); |
| 1184 } | 1309 } |
| 1185 | 1310 |
| 1186 /** | 1311 /** |
| 1312 * Element representing a top level variable resynthesized from a |
| 1313 * summary during linking. |
| 1314 */ |
| 1315 class TopLevelVariableElementForLink extends VariableElementForLink |
| 1316 implements TopLevelVariableElement { |
| 1317 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement, |
| 1318 UnlinkedVariable unlinkedVariable) |
| 1319 : super(unlinkedVariable, enclosingElement); |
| 1320 |
| 1321 @override |
| 1322 bool get isStatic => true; |
| 1323 } |
| 1324 |
| 1325 /** |
| 1187 * Singleton element used for unresolved references. | 1326 * Singleton element used for unresolved references. |
| 1188 */ | 1327 */ |
| 1189 class UndefinedElementForLink implements ReferenceableElementForLink { | 1328 class UndefinedElementForLink implements ReferenceableElementForLink { |
| 1190 static const UndefinedElementForLink instance = | 1329 static const UndefinedElementForLink instance = |
| 1191 const UndefinedElementForLink._(); | 1330 const UndefinedElementForLink._(); |
| 1192 | 1331 |
| 1193 const UndefinedElementForLink._(); | 1332 const UndefinedElementForLink._(); |
| 1194 | 1333 |
| 1195 @override | 1334 @override |
| 1196 ConstructorElementForLink get asConstructor => null; | 1335 ConstructorElementForLink get asConstructor => null; |
| 1197 | 1336 |
| 1198 @override | 1337 @override |
| 1338 ConstVariableNode get asConstVariable => null; |
| 1339 |
| 1340 @override |
| 1199 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), | 1341 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 1200 List<int> implicitFunctionTypeIndices) => | 1342 List<int> implicitFunctionTypeIndices) => |
| 1201 DynamicTypeForLink.instance; | 1343 DynamicTypeForLink.instance; |
| 1202 | 1344 |
| 1203 @override | 1345 @override |
| 1204 ReferenceableElementForLink getContainedName(name) => this; | 1346 ReferenceableElementForLink getContainedName(name) => this; |
| 1205 } | 1347 } |
| 1206 | 1348 |
| 1207 /** | 1349 /** |
| 1208 * Element representing a top level variable resynthesized from a | 1350 * Element representing a top level variable resynthesized from a |
| 1209 * summary during linking. | 1351 * summary during linking. |
| 1210 */ | 1352 */ |
| 1211 class VariableElementForLink { | 1353 class VariableElementForLink |
| 1354 implements VariableElement, ReferenceableElementForLink { |
| 1212 /** | 1355 /** |
| 1213 * The unlinked representation of the variable in the summary. | 1356 * The unlinked representation of the variable in the summary. |
| 1214 */ | 1357 */ |
| 1215 final UnlinkedVariable unlinkedVariable; | 1358 final UnlinkedVariable unlinkedVariable; |
| 1216 | 1359 |
| 1217 /** | 1360 /** |
| 1218 * If this variable is declared `const` and the enclosing library is | 1361 * If this variable is declared `const` and the enclosing library is |
| 1219 * part of the build unit being linked, the variable's node in the | 1362 * part of the build unit being linked, the variable's node in the |
| 1220 * constant evaluation dependency graph. Otherwise `null`. | 1363 * constant evaluation dependency graph. Otherwise `null`. |
| 1221 */ | 1364 */ |
| 1222 ConstNode _constNode; | 1365 ConstNode _constNode; |
| 1223 | 1366 |
| 1224 /** | 1367 /** |
| 1225 * The compilation unit in which this variable appears. | 1368 * The compilation unit in which this variable appears. |
| 1226 */ | 1369 */ |
| 1227 final CompilationUnitElementForLink compilationUnit; | 1370 final CompilationUnitElementForLink compilationUnit; |
| 1228 | 1371 |
| 1229 VariableElementForLink(this.unlinkedVariable, this.compilationUnit) { | 1372 VariableElementForLink(this.unlinkedVariable, this.compilationUnit) { |
| 1230 if (compilationUnit.isInBuildUnit && unlinkedVariable.constExpr != null) { | 1373 if (compilationUnit.isInBuildUnit && unlinkedVariable.constExpr != null) { |
| 1231 _constNode = new ConstVariableNode(this); | 1374 _constNode = new ConstVariableNode(this); |
| 1232 } | 1375 } |
| 1233 } | 1376 } |
| 1377 |
| 1378 @override |
| 1379 ConstructorElementForLink get asConstructor => null; |
| 1380 |
| 1381 @override |
| 1382 ConstVariableNode get asConstVariable => _constNode; |
| 1383 |
| 1384 @override |
| 1385 bool get isConst => unlinkedVariable.isConst; |
| 1386 |
| 1387 @override |
| 1388 bool get isFinal => unlinkedVariable.isFinal; |
| 1389 |
| 1390 @override |
| 1391 bool get isStatic; |
| 1392 |
| 1393 @override |
| 1394 String get name => unlinkedVariable.name; |
| 1395 |
| 1396 @override |
| 1397 DartTypeForLink buildType(DartTypeForLink getTypeArgument(int i), |
| 1398 List<int> implicitFunctionTypeIndices) => |
| 1399 DynamicTypeForLink.instance; |
| 1400 |
| 1401 ReferenceableElementForLink getContainedName(name) { |
| 1402 // TODO(paulberry): implement. |
| 1403 // TODO(paulberry): make sure that circularities involving |
| 1404 // ".length" are handled correctly. |
| 1405 return UndefinedElementForLink.instance; |
| 1406 } |
| 1407 |
| 1408 @override |
| 1409 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1234 } | 1410 } |
| 1235 | 1411 |
| 1236 /** | 1412 /** |
| 1237 * Representation of the void type during linking. | 1413 * Representation of the void type during linking. |
| 1238 */ | 1414 */ |
| 1239 class VoidTypeForLink extends DartTypeForLink { | 1415 class VoidTypeForLink extends DartTypeForLink { |
| 1240 static const VoidTypeForLink instance = const VoidTypeForLink._(); | 1416 static const VoidTypeForLink instance = const VoidTypeForLink._(); |
| 1241 const VoidTypeForLink._(); | 1417 const VoidTypeForLink._(); |
| 1242 } | 1418 } |
| 1243 | 1419 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 | 1497 |
| 1322 /** | 1498 /** |
| 1323 * Throw away any information produced by a previous call to [link]. | 1499 * Throw away any information produced by a previous call to [link]. |
| 1324 */ | 1500 */ |
| 1325 void unlink() { | 1501 void unlink() { |
| 1326 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { | 1502 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { |
| 1327 library.unlink(); | 1503 library.unlink(); |
| 1328 } | 1504 } |
| 1329 } | 1505 } |
| 1330 } | 1506 } |
| OLD | NEW |