| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 * summary. | 336 * summary. |
| 337 */ | 337 */ |
| 338 final UnlinkedUnit _unlinkedUnit; | 338 final UnlinkedUnit _unlinkedUnit; |
| 339 | 339 |
| 340 /** | 340 /** |
| 341 * For each entry in [UnlinkedUnit.references], the element referred | 341 * For each entry in [UnlinkedUnit.references], the element referred |
| 342 * 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. |
| 343 */ | 343 */ |
| 344 final List<ReferenceableElementForLink> _references; | 344 final List<ReferenceableElementForLink> _references; |
| 345 | 345 |
| 346 List<ClassElementForLink> _types; | 346 List<ClassElementForLink_Class> _types; |
| 347 Map<String, ReferenceableElementForLink> _containedNames; | 347 Map<String, ReferenceableElementForLink> _containedNames; |
| 348 List<TopLevelVariableElementForLink> _topLevelVariables; | 348 List<TopLevelVariableElementForLink> _topLevelVariables; |
| 349 List<ClassElementForLink_Enum> _enums; |
| 349 | 350 |
| 350 @override | 351 @override |
| 351 final LibraryElementForLink enclosingElement; | 352 final LibraryElementForLink enclosingElement; |
| 352 | 353 |
| 353 CompilationUnitElementForLink( | 354 CompilationUnitElementForLink( |
| 354 this.enclosingElement, UnlinkedUnit unlinkedUnit) | 355 this.enclosingElement, UnlinkedUnit unlinkedUnit) |
| 355 : _references = new List<ReferenceableElementForLink>( | 356 : _references = new List<ReferenceableElementForLink>( |
| 356 unlinkedUnit.references.length), | 357 unlinkedUnit.references.length), |
| 357 _unlinkedUnit = unlinkedUnit; | 358 _unlinkedUnit = unlinkedUnit; |
| 358 | 359 |
| 359 @override | 360 @override |
| 361 List<ClassElementForLink_Enum> get enums { |
| 362 if (_enums == null) { |
| 363 _enums = <ClassElementForLink_Enum>[]; |
| 364 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { |
| 365 _enums.add(new ClassElementForLink_Enum(unlinkedEnum)); |
| 366 } |
| 367 } |
| 368 return _enums; |
| 369 } |
| 370 |
| 371 /** |
| 372 * Indicates whether this compilation element is part of the build unit |
| 373 * currently being linked. |
| 374 */ |
| 360 bool get isInBuildUnit; | 375 bool get isInBuildUnit; |
| 361 | 376 |
| 362 @override | 377 @override |
| 363 List<TopLevelVariableElementForLink> get topLevelVariables { | 378 List<TopLevelVariableElementForLink> get topLevelVariables { |
| 364 if (_topLevelVariables == null) { | 379 if (_topLevelVariables == null) { |
| 365 _topLevelVariables = <TopLevelVariableElementForLink>[]; | 380 _topLevelVariables = <TopLevelVariableElementForLink>[]; |
| 366 for (UnlinkedVariable unlinkedVariable in _unlinkedUnit.variables) { | 381 for (UnlinkedVariable unlinkedVariable in _unlinkedUnit.variables) { |
| 367 _topLevelVariables | 382 _topLevelVariables |
| 368 .add(new TopLevelVariableElementForLink(this, unlinkedVariable)); | 383 .add(new TopLevelVariableElementForLink(this, unlinkedVariable)); |
| 369 } | 384 } |
| 370 } | 385 } |
| 371 return _topLevelVariables; | 386 return _topLevelVariables; |
| 372 } | 387 } |
| 373 | 388 |
| 374 @override | 389 @override |
| 375 List<ClassElementForLink> get types { | 390 List<ClassElementForLink_Class> get types { |
| 376 if (_types == null) { | 391 if (_types == null) { |
| 377 _types = <ClassElementForLink>[]; | 392 _types = <ClassElementForLink_Class>[]; |
| 378 for (UnlinkedClass unlinkedClass in _unlinkedUnit.classes) { | 393 for (UnlinkedClass unlinkedClass in _unlinkedUnit.classes) { |
| 379 _types.add(new ClassElementForLink_Class(this, unlinkedClass)); | 394 _types.add(new ClassElementForLink_Class(this, unlinkedClass)); |
| 380 } | 395 } |
| 381 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { | |
| 382 _types.add(new ClassElementForLink_Enum(unlinkedEnum)); | |
| 383 } | |
| 384 } | 396 } |
| 385 return _types; | 397 return _types; |
| 386 } | 398 } |
| 387 | 399 |
| 388 /** | 400 /** |
| 389 * The linked representation of the compilation unit in the summary. | 401 * The linked representation of the compilation unit in the summary. |
| 390 */ | 402 */ |
| 391 LinkedUnit get _linkedUnit; | 403 LinkedUnit get _linkedUnit; |
| 392 | 404 |
| 393 /** | 405 /** |
| 394 * Search the unit for a top level element with the given [name]. | 406 * Search the unit for a top level element with the given [name]. |
| 395 * If no name is found, return the singleton instance of | 407 * If no name is found, return the singleton instance of |
| 396 * [UndefinedElementForLink]. | 408 * [UndefinedElementForLink]. |
| 397 */ | 409 */ |
| 398 ReferenceableElementForLink getContainedName(name) { | 410 ReferenceableElementForLink getContainedName(name) { |
| 399 if (_containedNames == null) { | 411 if (_containedNames == null) { |
| 400 _containedNames = <String, ReferenceableElementForLink>{}; | 412 _containedNames = <String, ReferenceableElementForLink>{}; |
| 401 // TODO(paulberry): what's the correct way to handle name conflicts? | 413 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 402 for (ClassElementForLink type in types) { | 414 for (ClassElementForLink_Class type in types) { |
| 403 _containedNames[type.name] = type; | 415 _containedNames[type.name] = type; |
| 404 } | 416 } |
| 417 for (ClassElementForLink_Enum enm in enums) { |
| 418 _containedNames[enm.name] = enm; |
| 419 } |
| 405 for (TopLevelVariableElementForLink variable in topLevelVariables) { | 420 for (TopLevelVariableElementForLink variable in topLevelVariables) { |
| 406 _containedNames[variable.name] = variable; | 421 _containedNames[variable.name] = variable; |
| 407 } | 422 } |
| 408 // TODO(paulberry): fill in other top level entities (typedefs | 423 // TODO(paulberry): fill in other top level entities (typedefs |
| 409 // and executables). | 424 // and executables). |
| 410 } | 425 } |
| 411 return _containedNames.putIfAbsent( | 426 return _containedNames.putIfAbsent( |
| 412 name, () => UndefinedElementForLink.instance); | 427 name, () => UndefinedElementForLink.instance); |
| 413 } | 428 } |
| 414 | 429 |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 | 1518 |
| 1504 /** | 1519 /** |
| 1505 * Throw away any information produced by a previous call to [link]. | 1520 * Throw away any information produced by a previous call to [link]. |
| 1506 */ | 1521 */ |
| 1507 void unlink() { | 1522 void unlink() { |
| 1508 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { | 1523 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { |
| 1509 library.unlink(); | 1524 library.unlink(); |
| 1510 } | 1525 } |
| 1511 } | 1526 } |
| 1512 } | 1527 } |
| OLD | NEW |