| 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 UnlinkedUnit getRelativeUnit(String relativeUri) => | 149 |
| 150 getUnit(resolveRelativeUri(uri, Uri.parse(relativeUri)).toString()); | 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 |
| 151 linkedLibraries[absoluteUri] = prelink( | 160 linkedLibraries[absoluteUri] = prelink( |
| 152 getUnit(absoluteUri), | 161 getUnit(absoluteUri), |
| 153 getRelativeUnit, | 162 getRelativeUnit, |
| 154 (String relativeUri) => getRelativeUnit(relativeUri)?.publicNamespace, | 163 (String relativeUri) => getRelativeUnit(relativeUri)?.publicNamespace, |
| 155 getDeclaredVariable); | 164 getDeclaredVariable); |
| 156 } | 165 } |
| 157 return linkedLibraries; | 166 return linkedLibraries; |
| 158 } | 167 } |
| 159 | 168 |
| 160 /** | 169 /** |
| (...skipping 3144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 /** | 3314 /** |
| 3306 * Get the [UnlinkedUnit] for the defining compilation unit of this library. | 3315 * Get the [UnlinkedUnit] for the defining compilation unit of this library. |
| 3307 */ | 3316 */ |
| 3308 UnlinkedUnit get definingUnlinkedUnit => | 3317 UnlinkedUnit get definingUnlinkedUnit => |
| 3309 _definingUnlinkedUnit ??= _linker.getUnit(_absoluteUri.toString()); | 3318 _definingUnlinkedUnit ??= _linker.getUnit(_absoluteUri.toString()); |
| 3310 | 3319 |
| 3311 @override | 3320 @override |
| 3312 Element get enclosingElement => null; | 3321 Element get enclosingElement => null; |
| 3313 | 3322 |
| 3314 @override | 3323 @override |
| 3315 List<LibraryElementForLink> get exportedLibraries => _exportedLibraries ??= | 3324 List<LibraryElementForLink> get exportedLibraries => |
| 3316 _linkedLibrary.exportDependencies.map(_getDependency).toList(); | 3325 _exportedLibraries ??= _linkedLibrary.exportDependencies |
| 3326 .map(_getDependency) |
| 3327 .where((library) => library != null) |
| 3328 .toList(); |
| 3317 | 3329 |
| 3318 @override | 3330 @override |
| 3319 String get identifier => _absoluteUri.toString(); | 3331 String get identifier => _absoluteUri.toString(); |
| 3320 | 3332 |
| 3321 @override | 3333 @override |
| 3322 List<LibraryElementForLink> get importedLibraries => _importedLibraries ??= | 3334 List<LibraryElementForLink> get importedLibraries => _importedLibraries ??= |
| 3323 _linkedLibrary.importDependencies.map(_getDependency).toList(); | 3335 _linkedLibrary.importDependencies.map(_getDependency).toList(); |
| 3324 | 3336 |
| 3325 @override | 3337 @override |
| 3326 bool get isDartAsync => _absoluteUri.toString() == 'dart:async'; | 3338 bool get isDartAsync => _absoluteUri.toString() == 'dart:async'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3341 | 3353 |
| 3342 @override | 3354 @override |
| 3343 List<UnitElement> get units { | 3355 List<UnitElement> get units { |
| 3344 if (_units == null) { | 3356 if (_units == null) { |
| 3345 UnlinkedUnit definingUnit = definingUnlinkedUnit; | 3357 UnlinkedUnit definingUnit = definingUnlinkedUnit; |
| 3346 _units = <UnitElement>[ | 3358 _units = <UnitElement>[ |
| 3347 _makeUnitElement(definingUnit, 0, _absoluteUri.toString()) | 3359 _makeUnitElement(definingUnit, 0, _absoluteUri.toString()) |
| 3348 ]; | 3360 ]; |
| 3349 int numParts = definingUnit.parts.length; | 3361 int numParts = definingUnit.parts.length; |
| 3350 for (int i = 0; i < numParts; i++) { | 3362 for (int i = 0; i < numParts; i++) { |
| 3351 // TODO(paulberry): make sure we handle the case where Uri.parse fails. | |
| 3352 // TODO(paulberry): make sure we handle the case where | 3363 // TODO(paulberry): make sure we handle the case where |
| 3353 // resolveRelativeUri fails. | 3364 // resolveRelativeUri fails. |
| 3365 String partRelativeUriStr = definingUnit.publicNamespace.parts[i]; |
| 3366 |
| 3367 Uri partRelativeUri; |
| 3368 try { |
| 3369 partRelativeUri = Uri.parse(partRelativeUriStr); |
| 3370 } on FormatException { |
| 3371 continue; |
| 3372 } |
| 3373 |
| 3354 String partAbsoluteUri = resolveRelativeUri( | 3374 String partAbsoluteUri = resolveRelativeUri( |
| 3355 _absoluteUri, Uri.parse(definingUnit.publicNamespace.parts[i])) | 3375 _absoluteUri, partRelativeUri) |
| 3356 .toString(); | 3376 .toString(); |
| 3357 UnlinkedUnit partUnit = _linker.getUnit(partAbsoluteUri); | 3377 UnlinkedUnit partUnit = _linker.getUnit(partAbsoluteUri); |
| 3358 _units.add(_makeUnitElement( | 3378 _units.add(_makeUnitElement( |
| 3359 partUnit ?? new UnlinkedUnitBuilder(), i + 1, partAbsoluteUri)); | 3379 partUnit ?? new UnlinkedUnitBuilder(), i + 1, partAbsoluteUri)); |
| 3360 } | 3380 } |
| 3361 } | 3381 } |
| 3362 return _units; | 3382 return _units; |
| 3363 } | 3383 } |
| 3364 | 3384 |
| 3365 /** | 3385 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3388 | 3408 |
| 3389 @override | 3409 @override |
| 3390 String toString() => _absoluteUri.toString(); | 3410 String toString() => _absoluteUri.toString(); |
| 3391 | 3411 |
| 3392 /** | 3412 /** |
| 3393 * Return the [LibraryElement] corresponding to the given dependency [index]. | 3413 * Return the [LibraryElement] corresponding to the given dependency [index]. |
| 3394 */ | 3414 */ |
| 3395 LibraryElementForLink _getDependency(int index) { | 3415 LibraryElementForLink _getDependency(int index) { |
| 3396 LibraryElementForLink result = _dependencies[index]; | 3416 LibraryElementForLink result = _dependencies[index]; |
| 3397 if (result == null) { | 3417 if (result == null) { |
| 3398 String relativeUri = _linkedLibrary.dependencies[index].uri; | 3418 String relativeUriStr = _linkedLibrary.dependencies[index].uri; |
| 3399 Uri absoluteUri = relativeUri.isEmpty | 3419 |
| 3420 Uri relativeUri; |
| 3421 try { |
| 3422 relativeUri = Uri.parse(relativeUriStr); |
| 3423 } on FormatException { |
| 3424 return null; |
| 3425 } |
| 3426 |
| 3427 Uri absoluteUri = relativeUriStr.isEmpty |
| 3400 ? _absoluteUri | 3428 ? _absoluteUri |
| 3401 : resolveRelativeUri(_absoluteUri, Uri.parse(relativeUri)); | 3429 : resolveRelativeUri(_absoluteUri, relativeUri); |
| 3402 result = _linker.getLibrary(absoluteUri); | 3430 result = _linker.getLibrary(absoluteUri); |
| 3403 _dependencies[index] = result; | 3431 _dependencies[index] = result; |
| 3404 } | 3432 } |
| 3405 return result; | 3433 return result; |
| 3406 } | 3434 } |
| 3407 | 3435 |
| 3408 /** | 3436 /** |
| 3409 * Create a [UnitElement] for one of the library's compilation | 3437 * Create a [UnitElement] for one of the library's compilation |
| 3410 * units. | 3438 * units. |
| 3411 */ | 3439 */ |
| (...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5004 * there are no type parameters in scope. | 5032 * there are no type parameters in scope. |
| 5005 */ | 5033 */ |
| 5006 TypeParameterizedElementMixin get _typeParameterContext; | 5034 TypeParameterizedElementMixin get _typeParameterContext; |
| 5007 | 5035 |
| 5008 @override | 5036 @override |
| 5009 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 5037 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 5010 | 5038 |
| 5011 @override | 5039 @override |
| 5012 String toString() => '$enclosingElement.$name'; | 5040 String toString() => '$enclosingElement.$name'; |
| 5013 } | 5041 } |
| OLD | NEW |