| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 * The libraries are prelinked, and a map is returned whose keys are the URIs of | 139 * The libraries are prelinked, and a map is returned whose keys are the URIs of |
| 140 * the libraries in this build unit, and whose values are the corresponding | 140 * the libraries in this build unit, and whose values are the corresponding |
| 141 * [LinkedLibraryBuilder]s. | 141 * [LinkedLibraryBuilder]s. |
| 142 */ | 142 */ |
| 143 Map<String, LinkedLibraryBuilder> setupForLink(Set<String> libraryUris, | 143 Map<String, LinkedLibraryBuilder> setupForLink(Set<String> libraryUris, |
| 144 GetUnitCallback getUnit, GetDeclaredVariable getDeclaredVariable) { | 144 GetUnitCallback getUnit, GetDeclaredVariable getDeclaredVariable) { |
| 145 Map<String, LinkedLibraryBuilder> linkedLibraries = | 145 Map<String, LinkedLibraryBuilder> linkedLibraries = |
| 146 <String, LinkedLibraryBuilder>{}; | 146 <String, LinkedLibraryBuilder>{}; |
| 147 for (String absoluteUri in libraryUris) { | 147 for (String absoluteUri in libraryUris) { |
| 148 Uri uri = Uri.parse(absoluteUri); | 148 Uri uri = Uri.parse(absoluteUri); |
| 149 | |
| 150 UnlinkedUnit getRelativeUnit(String relativeUriStr) { | |
| 151 Uri relativeUri; | |
| 152 try { | |
| 153 relativeUri = Uri.parse(relativeUriStr); | |
| 154 } on FormatException { | |
| 155 return new UnlinkedUnitBuilder(); | |
| 156 } | |
| 157 return getUnit(resolveRelativeUri(uri, relativeUri).toString()); | |
| 158 } | |
| 159 | |
| 160 linkedLibraries[absoluteUri] = prelink( | 149 linkedLibraries[absoluteUri] = prelink( |
| 150 absoluteUri, |
| 161 getUnit(absoluteUri), | 151 getUnit(absoluteUri), |
| 162 getRelativeUnit, | 152 getUnit, |
| 163 (String relativeUri) => getRelativeUnit(relativeUri)?.publicNamespace, | 153 (String absoluteUri) => getUnit(absoluteUri)?.publicNamespace, |
| 164 getDeclaredVariable); | 154 getDeclaredVariable); |
| 165 } | 155 } |
| 166 return linkedLibraries; | 156 return linkedLibraries; |
| 167 } | 157 } |
| 168 | 158 |
| 169 /** | 159 /** |
| 170 * Create an [EntityRefBuilder] representing the given [type], in a form | 160 * Create an [EntityRefBuilder] representing the given [type], in a form |
| 171 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the | 161 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the |
| 172 * compilation unit in which the type will be used. If [slot] is provided, it | 162 * compilation unit in which the type will be used. If [slot] is provided, it |
| 173 * is stored in [EntityRefBuilder.slot]. | 163 * is stored in [EntityRefBuilder.slot]. |
| (...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3364 // resolveRelativeUri fails. | 3354 // resolveRelativeUri fails. |
| 3365 String partRelativeUriStr = definingUnit.publicNamespace.parts[i]; | 3355 String partRelativeUriStr = definingUnit.publicNamespace.parts[i]; |
| 3366 | 3356 |
| 3367 Uri partRelativeUri; | 3357 Uri partRelativeUri; |
| 3368 try { | 3358 try { |
| 3369 partRelativeUri = Uri.parse(partRelativeUriStr); | 3359 partRelativeUri = Uri.parse(partRelativeUriStr); |
| 3370 } on FormatException { | 3360 } on FormatException { |
| 3371 continue; | 3361 continue; |
| 3372 } | 3362 } |
| 3373 | 3363 |
| 3374 String partAbsoluteUri = resolveRelativeUri( | 3364 String partAbsoluteUri = |
| 3375 _absoluteUri, partRelativeUri) | 3365 resolveRelativeUri(_absoluteUri, partRelativeUri).toString(); |
| 3376 .toString(); | |
| 3377 UnlinkedUnit partUnit = _linker.getUnit(partAbsoluteUri); | 3366 UnlinkedUnit partUnit = _linker.getUnit(partAbsoluteUri); |
| 3378 _units.add(_makeUnitElement( | 3367 _units.add(_makeUnitElement( |
| 3379 partUnit ?? new UnlinkedUnitBuilder(), i + 1, partAbsoluteUri)); | 3368 partUnit ?? new UnlinkedUnitBuilder(), i + 1, partAbsoluteUri)); |
| 3380 } | 3369 } |
| 3381 } | 3370 } |
| 3382 return _units; | 3371 return _units; |
| 3383 } | 3372 } |
| 3384 | 3373 |
| 3385 /** | 3374 /** |
| 3386 * The linked representation of the library in the summary. | 3375 * The linked representation of the library in the summary. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3408 | 3397 |
| 3409 @override | 3398 @override |
| 3410 String toString() => _absoluteUri.toString(); | 3399 String toString() => _absoluteUri.toString(); |
| 3411 | 3400 |
| 3412 /** | 3401 /** |
| 3413 * Return the [LibraryElement] corresponding to the given dependency [index]. | 3402 * Return the [LibraryElement] corresponding to the given dependency [index]. |
| 3414 */ | 3403 */ |
| 3415 LibraryElementForLink _getDependency(int index) { | 3404 LibraryElementForLink _getDependency(int index) { |
| 3416 LibraryElementForLink result = _dependencies[index]; | 3405 LibraryElementForLink result = _dependencies[index]; |
| 3417 if (result == null) { | 3406 if (result == null) { |
| 3418 String relativeUriStr = _linkedLibrary.dependencies[index].uri; | 3407 Uri uri; |
| 3419 | 3408 String uriStr = _linkedLibrary.dependencies[index].uri; |
| 3420 Uri relativeUri; | 3409 if (uriStr.isEmpty) { |
| 3421 try { | 3410 uri = _absoluteUri; |
| 3422 relativeUri = Uri.parse(relativeUriStr); | 3411 } else { |
| 3423 } on FormatException { | 3412 try { |
| 3424 return null; | 3413 uri = Uri.parse(uriStr); |
| 3414 } on FormatException { |
| 3415 return null; |
| 3416 } |
| 3425 } | 3417 } |
| 3426 | 3418 |
| 3427 Uri absoluteUri = relativeUriStr.isEmpty | 3419 result = _linker.getLibrary(uri); |
| 3428 ? _absoluteUri | |
| 3429 : resolveRelativeUri(_absoluteUri, relativeUri); | |
| 3430 result = _linker.getLibrary(absoluteUri); | |
| 3431 _dependencies[index] = result; | 3420 _dependencies[index] = result; |
| 3432 } | 3421 } |
| 3433 return result; | 3422 return result; |
| 3434 } | 3423 } |
| 3435 | 3424 |
| 3436 /** | 3425 /** |
| 3437 * Create a [UnitElement] for one of the library's compilation | 3426 * Create a [UnitElement] for one of the library's compilation |
| 3438 * units. | 3427 * units. |
| 3439 */ | 3428 */ |
| 3440 UnitElement _makeUnitElement( | 3429 UnitElement _makeUnitElement( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3485 int addDependency(LibraryElementForLink library) { | 3474 int addDependency(LibraryElementForLink library) { |
| 3486 for (int i = 0; i < _linkedLibrary.dependencies.length; i++) { | 3475 for (int i = 0; i < _linkedLibrary.dependencies.length; i++) { |
| 3487 if (identical(_getDependency(i), library)) { | 3476 if (identical(_getDependency(i), library)) { |
| 3488 return i; | 3477 return i; |
| 3489 } | 3478 } |
| 3490 } | 3479 } |
| 3491 int result = _linkedLibrary.dependencies.length; | 3480 int result = _linkedLibrary.dependencies.length; |
| 3492 Uri libraryUri = library._absoluteUri; | 3481 Uri libraryUri = library._absoluteUri; |
| 3493 List<String> partsRelativeToDependency = | 3482 List<String> partsRelativeToDependency = |
| 3494 library.definingUnlinkedUnit.publicNamespace.parts; | 3483 library.definingUnlinkedUnit.publicNamespace.parts; |
| 3495 List<String> partsRelativeToLibraryBeingLinked = partsRelativeToDependency | 3484 List<String> partsAbsolute = partsRelativeToDependency |
| 3496 .map((partUri) => | 3485 .map((partUri) => |
| 3497 resolveRelativeUri(libraryUri, Uri.parse(partUri)).toString()) | 3486 resolveRelativeUri(libraryUri, Uri.parse(partUri)).toString()) |
| 3498 .toList(); | 3487 .toList(); |
| 3499 _linkedLibrary.dependencies.add(new LinkedDependencyBuilder( | 3488 _linkedLibrary.dependencies.add(new LinkedDependencyBuilder( |
| 3500 parts: partsRelativeToLibraryBeingLinked, uri: libraryUri.toString())); | 3489 parts: partsAbsolute, uri: libraryUri.toString())); |
| 3501 _dependencies.add(library); | 3490 _dependencies.add(library); |
| 3502 return result; | 3491 return result; |
| 3503 } | 3492 } |
| 3504 | 3493 |
| 3505 /** | 3494 /** |
| 3506 * Perform type inference and const cycle detection on this library. | 3495 * Perform type inference and const cycle detection on this library. |
| 3507 */ | 3496 */ |
| 3508 void link() { | 3497 void link() { |
| 3509 for (CompilationUnitElementInBuildUnit unit in units) { | 3498 for (CompilationUnitElementInBuildUnit unit in units) { |
| 3510 unit.link(); | 3499 unit.link(); |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5037 * there are no type parameters in scope. | 5026 * there are no type parameters in scope. |
| 5038 */ | 5027 */ |
| 5039 TypeParameterizedElementMixin get _typeParameterContext; | 5028 TypeParameterizedElementMixin get _typeParameterContext; |
| 5040 | 5029 |
| 5041 @override | 5030 @override |
| 5042 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 5031 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 5043 | 5032 |
| 5044 @override | 5033 @override |
| 5045 String toString() => '$enclosingElement.$name'; | 5034 String toString() => '$enclosingElement.$name'; |
| 5046 } | 5035 } |
| OLD | NEW |