OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 * component in the import/export graph in which the target resides. | 410 * component in the import/export graph in which the target resides. |
411 * | 411 * |
412 * Only non-empty in strongMode. | 412 * Only non-empty in strongMode. |
413 * | 413 * |
414 * The result is only available for [Source]s representing a library. | 414 * The result is only available for [Source]s representing a library. |
415 */ | 415 */ |
416 final ListResultDescriptor<LibraryElement> LIBRARY_CYCLE = | 416 final ListResultDescriptor<LibraryElement> LIBRARY_CYCLE = |
417 new ListResultDescriptor<LibraryElement>('LIBRARY_CYCLE', null); | 417 new ListResultDescriptor<LibraryElement>('LIBRARY_CYCLE', null); |
418 | 418 |
419 /** | 419 /** |
420 * A list of the [CompilationUnitElement]s that comprise all of the parts and | 420 * A list of the [LibrarySpecificUnit]s that comprise all of the parts and |
421 * libraries in the direct import/export dependencies of the library cycle | 421 * libraries in the direct import/export dependencies of the library cycle |
422 * of the target, with the intra-component dependencies excluded. | 422 * of the target, with the intra-component dependencies excluded. |
423 * | 423 * |
424 * Only non-empty in strongMode. | 424 * Only non-empty in strongMode. |
425 * | 425 * |
426 * The result is only available for [Source]s representing a library. | 426 * The result is only available for [Source]s representing a library. |
427 */ | 427 */ |
428 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_DEPENDENCIES = | 428 final ListResultDescriptor<LibrarySpecificUnit> LIBRARY_CYCLE_DEPENDENCIES = |
429 new ListResultDescriptor<CompilationUnitElement>( | 429 new ListResultDescriptor<LibrarySpecificUnit>( |
430 'LIBRARY_CYCLE_DEPENDENCIES', null); | 430 'LIBRARY_CYCLE_DEPENDENCIES', null); |
431 | 431 |
432 /** | 432 /** |
433 * A list of the [CompilationUnitElement]s (including all parts) that make up | 433 * A list of the [LibrarySpecificUnit]s (including all parts) that make up |
434 * the strongly connected component in the import/export graph in which the | 434 * the strongly connected component in the import/export graph in which the |
435 * target resides. | 435 * target resides. |
436 * | 436 * |
437 * Only non-empty in strongMode. | 437 * Only non-empty in strongMode. |
438 * | 438 * |
439 * The result is only available for [Source]s representing a library. | 439 * The result is only available for [Source]s representing a library. |
440 */ | 440 */ |
441 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_UNITS = | 441 final ListResultDescriptor<LibrarySpecificUnit> LIBRARY_CYCLE_UNITS = |
442 new ListResultDescriptor<CompilationUnitElement>( | 442 new ListResultDescriptor<LibrarySpecificUnit>('LIBRARY_CYCLE_UNITS', null); |
443 'LIBRARY_CYCLE_UNITS', null); | |
444 | 443 |
445 /** | 444 /** |
446 * The partial [LibraryElement] associated with a library. | 445 * The partial [LibraryElement] associated with a library. |
447 * | 446 * |
448 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each | 447 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each |
449 * other. Directives 'library', 'part' and 'part of' are resolved. | 448 * other. Directives 'library', 'part' and 'part of' are resolved. |
450 * | 449 * |
451 * The result is only available for [Source]s representing a library. | 450 * The result is only available for [Source]s representing a library. |
452 */ | 451 */ |
453 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = | 452 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 // from a node is changed, its LIBRARY_CYCLE results will be re-computed | 2191 // from a node is changed, its LIBRARY_CYCLE results will be re-computed |
2193 // here (possibly re-using the result from the element model if invalidation | 2192 // here (possibly re-using the result from the element model if invalidation |
2194 // did not cause it to be erased). In summary, task model dependencies | 2193 // did not cause it to be erased). In summary, task model dependencies |
2195 // on the import/export source closure ensure that this method will be | 2194 // on the import/export source closure ensure that this method will be |
2196 // re-run if anything reachable from this target has been invalidated, | 2195 // re-run if anything reachable from this target has been invalidated, |
2197 // and the invalidation code (invalidateLibraryCycles) will ensure that | 2196 // and the invalidation code (invalidateLibraryCycles) will ensure that |
2198 // element model results will be re-used here only if they are still valid. | 2197 // element model results will be re-used here only if they are still valid. |
2199 if (context.analysisOptions.strongMode) { | 2198 if (context.analysisOptions.strongMode) { |
2200 LibraryElement library = getRequiredInput(LIBRARY_ELEMENT_INPUT); | 2199 LibraryElement library = getRequiredInput(LIBRARY_ELEMENT_INPUT); |
2201 List<LibraryElement> component = library.libraryCycle; | 2200 List<LibraryElement> component = library.libraryCycle; |
2202 Set<LibraryElement> filter = new Set<LibraryElement>.from(component); | 2201 Set<LibraryElement> filter = component.toSet(); |
2203 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>(); | 2202 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>(); |
2204 void addLibrary(LibraryElement l) { | 2203 void addLibrary(LibraryElement l) { |
2205 if (!filter.contains(l)) { | 2204 if (!filter.contains(l)) { |
2206 deps.addAll(l.units); | 2205 deps.addAll(l.units); |
2207 } | 2206 } |
2208 } | 2207 } |
2209 | 2208 |
2210 int length = component.length; | 2209 int length = component.length; |
2211 for (int i = 0; i < length; i++) { | 2210 for (int i = 0; i < length; i++) { |
2212 LibraryElement library = component[i]; | 2211 LibraryElement library = component[i]; |
2213 library.importedLibraries.forEach(addLibrary); | 2212 library.importedLibraries.forEach(addLibrary); |
2214 library.exportedLibraries.forEach(addLibrary); | 2213 library.exportedLibraries.forEach(addLibrary); |
2215 } | 2214 } |
2216 // | 2215 // |
2217 // Record outputs. | 2216 // Record outputs. |
2218 // | 2217 // |
| 2218 LibrarySpecificUnit unitToLSU(CompilationUnitElement unit) => |
| 2219 new LibrarySpecificUnit(unit.librarySource, unit.source); |
2219 outputs[LIBRARY_CYCLE] = component; | 2220 outputs[LIBRARY_CYCLE] = component; |
2220 outputs[LIBRARY_CYCLE_UNITS] = component.expand((l) => l.units).toList(); | 2221 outputs[LIBRARY_CYCLE_UNITS] = |
2221 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.toList(); | 2222 component.expand((l) => l.units).map(unitToLSU).toList(); |
| 2223 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.map(unitToLSU).toList(); |
2222 } else { | 2224 } else { |
2223 outputs[LIBRARY_CYCLE] = []; | 2225 outputs[LIBRARY_CYCLE] = []; |
2224 outputs[LIBRARY_CYCLE_UNITS] = []; | 2226 outputs[LIBRARY_CYCLE_UNITS] = []; |
2225 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; | 2227 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; |
2226 } | 2228 } |
2227 } | 2229 } |
2228 | 2230 |
2229 /** | 2231 /** |
2230 * Return a map from the names of the inputs of this kind of task to the task | 2232 * Return a map from the names of the inputs of this kind of task to the task |
2231 * input descriptors describing those inputs for a task with the | 2233 * input descriptors describing those inputs for a task with the |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3423 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
3422 LibrarySpecificUnit unit = target; | 3424 LibrarySpecificUnit unit = target; |
3423 return <String, TaskInput>{ | 3425 return <String, TaskInput>{ |
3424 UNIT_INPUT: RESOLVED_UNIT9.of(unit), | 3426 UNIT_INPUT: RESOLVED_UNIT9.of(unit), |
3425 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 3427 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
3426 // In strong mode, add additional dependencies to enforce inference | 3428 // In strong mode, add additional dependencies to enforce inference |
3427 // ordering. | 3429 // ordering. |
3428 | 3430 |
3429 // Require that field re-resolution be complete for all units in the | 3431 // Require that field re-resolution be complete for all units in the |
3430 // current library cycle. | 3432 // current library cycle. |
3431 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit.library).toList( | 3433 'orderLibraryCycleTasks': |
3432 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT9.of( | 3434 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT9), |
3433 new LibrarySpecificUnit( | |
3434 (unit as CompilationUnitElementImpl).librarySource, | |
3435 unit.source))), | |
3436 // Require that full inference be complete for all dependencies of the | 3435 // Require that full inference be complete for all dependencies of the |
3437 // current library cycle. | 3436 // current library cycle. |
3438 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit.library).toList( | 3437 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES |
3439 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT10.of( | 3438 .of(unit.library) |
3440 new LibrarySpecificUnit( | 3439 .toListOf(CREATED_RESOLVED_UNIT10) |
3441 (unit as CompilationUnitElementImpl).librarySource, | |
3442 unit.source))) | |
3443 }; | 3440 }; |
3444 } | 3441 } |
3445 | 3442 |
3446 /** | 3443 /** |
3447 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in | 3444 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in |
3448 * the given [context]. | 3445 * the given [context]. |
3449 */ | 3446 */ |
3450 static InferInstanceMembersInUnitTask createTask( | 3447 static InferInstanceMembersInUnitTask createTask( |
3451 AnalysisContext context, AnalysisTarget target) { | 3448 AnalysisContext context, AnalysisTarget target) { |
3452 return new InferInstanceMembersInUnitTask(context, target); | 3449 return new InferInstanceMembersInUnitTask(context, target); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3715 DEPENDENCIES_INPUT: INFERABLE_STATIC_VARIABLE_DEPENDENCIES | 3712 DEPENDENCIES_INPUT: INFERABLE_STATIC_VARIABLE_DEPENDENCIES |
3716 .of(variable) | 3713 .of(variable) |
3717 .toListOf(INFERRED_STATIC_VARIABLE), | 3714 .toListOf(INFERRED_STATIC_VARIABLE), |
3718 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 3715 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
3719 UNIT_INPUT: RESOLVED_UNIT7.of(unit), | 3716 UNIT_INPUT: RESOLVED_UNIT7.of(unit), |
3720 // In strong mode, add additional dependencies to enforce inference | 3717 // In strong mode, add additional dependencies to enforce inference |
3721 // ordering. | 3718 // ordering. |
3722 | 3719 |
3723 // Require that full inference be complete for all dependencies of the | 3720 // Require that full inference be complete for all dependencies of the |
3724 // current library cycle. | 3721 // current library cycle. |
3725 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit.library).toList( | 3722 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES |
3726 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT10.of( | 3723 .of(unit.library) |
3727 new LibrarySpecificUnit( | 3724 .toListOf(CREATED_RESOLVED_UNIT10) |
3728 (unit as CompilationUnitElementImpl).librarySource, | |
3729 unit.source))) | |
3730 }; | 3725 }; |
3731 } | 3726 } |
3732 | 3727 |
3733 /** | 3728 /** |
3734 * Create a [InferStaticVariableTypeTask] based on the given [target] in the | 3729 * Create a [InferStaticVariableTypeTask] based on the given [target] in the |
3735 * given [context]. | 3730 * given [context]. |
3736 */ | 3731 */ |
3737 static InferStaticVariableTypeTask createTask( | 3732 static InferStaticVariableTypeTask createTask( |
3738 AnalysisContext context, AnalysisTarget target) { | 3733 AnalysisContext context, AnalysisTarget target) { |
3739 return new InferStaticVariableTypeTask(context, target); | 3734 return new InferStaticVariableTypeTask(context, target); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4231 return <String, TaskInput>{ | 4226 return <String, TaskInput>{ |
4232 'fullyBuiltLibraryElements': READY_LIBRARY_ELEMENT6.of(unit.library), | 4227 'fullyBuiltLibraryElements': READY_LIBRARY_ELEMENT6.of(unit.library), |
4233 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library), | 4228 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library), |
4234 UNIT_INPUT: RESOLVED_UNIT6.of(unit), | 4229 UNIT_INPUT: RESOLVED_UNIT6.of(unit), |
4235 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 4230 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
4236 // In strong mode, add additional dependencies to enforce inference | 4231 // In strong mode, add additional dependencies to enforce inference |
4237 // ordering. | 4232 // ordering. |
4238 | 4233 |
4239 // Require that full inference be complete for all dependencies of the | 4234 // Require that full inference be complete for all dependencies of the |
4240 // current library cycle. | 4235 // current library cycle. |
4241 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit.library).toList( | 4236 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES |
4242 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT10.of( | 4237 .of(unit.library) |
4243 new LibrarySpecificUnit( | 4238 .toListOf(CREATED_RESOLVED_UNIT10) |
4244 (unit as CompilationUnitElementImpl).librarySource, | |
4245 unit.source))) | |
4246 }; | 4239 }; |
4247 } | 4240 } |
4248 | 4241 |
4249 /** | 4242 /** |
4250 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target] | 4243 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target] |
4251 * in the given [context]. | 4244 * in the given [context]. |
4252 */ | 4245 */ |
4253 static PartiallyResolveUnitReferencesTask createTask( | 4246 static PartiallyResolveUnitReferencesTask createTask( |
4254 AnalysisContext context, AnalysisTarget target) { | 4247 AnalysisContext context, AnalysisTarget target) { |
4255 return new PartiallyResolveUnitReferencesTask(context, target); | 4248 return new PartiallyResolveUnitReferencesTask(context, target); |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5148 LibrarySpecificUnit unit = target; | 5141 LibrarySpecificUnit unit = target; |
5149 return <String, TaskInput>{ | 5142 return <String, TaskInput>{ |
5150 UNIT_INPUT: RESOLVED_UNIT8.of(unit), | 5143 UNIT_INPUT: RESOLVED_UNIT8.of(unit), |
5151 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library), | 5144 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library), |
5152 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 5145 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
5153 // In strong mode, add additional dependencies to enforce inference | 5146 // In strong mode, add additional dependencies to enforce inference |
5154 // ordering. | 5147 // ordering. |
5155 | 5148 |
5156 // Require that static variable inference be complete for all units in | 5149 // Require that static variable inference be complete for all units in |
5157 // the current library cycle. | 5150 // the current library cycle. |
5158 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit.library).toList( | 5151 'orderLibraryCycleTasks': |
5159 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT8.of( | 5152 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT8), |
5160 new LibrarySpecificUnit( | |
5161 (unit as CompilationUnitElementImpl).librarySource, | |
5162 unit.source))), | |
5163 // Require that full inference be complete for all dependencies of the | 5153 // Require that full inference be complete for all dependencies of the |
5164 // current library cycle. | 5154 // current library cycle. |
5165 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit.library).toList( | 5155 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES |
5166 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT10.of( | 5156 .of(unit.library) |
5167 new LibrarySpecificUnit( | 5157 .toListOf(CREATED_RESOLVED_UNIT10) |
5168 (unit as CompilationUnitElementImpl).librarySource, | |
5169 unit.source))) | |
5170 }; | 5158 }; |
5171 } | 5159 } |
5172 | 5160 |
5173 /** | 5161 /** |
5174 * Create a [ResolveInstanceFieldsInUnitTask] based on the given [target] in | 5162 * Create a [ResolveInstanceFieldsInUnitTask] based on the given [target] in |
5175 * the given [context]. | 5163 * the given [context]. |
5176 */ | 5164 */ |
5177 static ResolveInstanceFieldsInUnitTask createTask( | 5165 static ResolveInstanceFieldsInUnitTask createTask( |
5178 AnalysisContext context, AnalysisTarget target) { | 5166 AnalysisContext context, AnalysisTarget target) { |
5179 return new ResolveInstanceFieldsInUnitTask(context, target); | 5167 return new ResolveInstanceFieldsInUnitTask(context, target); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5615 LibrarySpecificUnit unit = target; | 5603 LibrarySpecificUnit unit = target; |
5616 return <String, TaskInput>{ | 5604 return <String, TaskInput>{ |
5617 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(unit.library), | 5605 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(unit.library), |
5618 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 5606 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
5619 UNIT_INPUT: RESOLVED_UNIT10.of(unit), | 5607 UNIT_INPUT: RESOLVED_UNIT10.of(unit), |
5620 // In strong mode, add additional dependencies to enforce inference | 5608 // In strong mode, add additional dependencies to enforce inference |
5621 // ordering. | 5609 // ordering. |
5622 | 5610 |
5623 // Require that inference be complete for all units in the | 5611 // Require that inference be complete for all units in the |
5624 // current library cycle. | 5612 // current library cycle. |
5625 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit.library).toList( | 5613 'orderLibraryCycleTasks': |
5626 (CompilationUnitElement unit) => CREATED_RESOLVED_UNIT10.of( | 5614 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT10) |
5627 new LibrarySpecificUnit( | |
5628 (unit as CompilationUnitElementImpl).librarySource, | |
5629 unit.source))) | |
5630 }; | 5615 }; |
5631 } | 5616 } |
5632 | 5617 |
5633 /** | 5618 /** |
5634 * Create a [ResolveUnitTask] based on the given [target] in | 5619 * Create a [ResolveUnitTask] based on the given [target] in |
5635 * the given [context]. | 5620 * the given [context]. |
5636 */ | 5621 */ |
5637 static ResolveUnitTask createTask( | 5622 static ResolveUnitTask createTask( |
5638 AnalysisContext context, AnalysisTarget target) { | 5623 AnalysisContext context, AnalysisTarget target) { |
5639 return new ResolveUnitTask(context, target); | 5624 return new ResolveUnitTask(context, target); |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6359 | 6344 |
6360 @override | 6345 @override |
6361 bool moveNext() { | 6346 bool moveNext() { |
6362 if (_newSources.isEmpty) { | 6347 if (_newSources.isEmpty) { |
6363 return false; | 6348 return false; |
6364 } | 6349 } |
6365 currentTarget = _newSources.removeLast(); | 6350 currentTarget = _newSources.removeLast(); |
6366 return true; | 6351 return true; |
6367 } | 6352 } |
6368 } | 6353 } |
OLD | NEW |