Chromium Code Reviews| 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/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 * | 65 * |
| 66 * The list will be empty if there were no errors, but will not be `null`. | 66 * The list will be empty if there were no errors, but will not be `null`. |
| 67 * | 67 * |
| 68 * The result is only available for [Source]s representing a library. | 68 * The result is only available for [Source]s representing a library. |
| 69 */ | 69 */ |
| 70 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = | 70 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = |
| 71 new ListResultDescriptor<AnalysisError>( | 71 new ListResultDescriptor<AnalysisError>( |
| 72 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); | 72 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * A list of the [ClassElement]s representing the classes defined in a | |
| 76 * compilation unit. | |
| 77 * | |
| 78 * The result is only available for [LibrarySpecificUnit]s, and only when strong | |
| 79 * mode is enabled. | |
| 80 */ | |
| 81 final ListResultDescriptor<ClassElement> CLASSES_IN_UNIT = | |
| 82 new ListResultDescriptor<ClassElement>('CLASSES_IN_UNIT', null); | |
| 83 | |
| 84 /** | |
| 85 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes | 75 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes |
| 86 * constants defined at top level, statically inside classes, and local to | 76 * constants defined at top level, statically inside classes, and local to |
| 87 * functions, as well as constant constructors, annotations, and default values | 77 * functions, as well as constant constructors, annotations, and default values |
| 88 * of parameters to constant constructors. | 78 * of parameters to constant constructors. |
| 89 */ | 79 */ |
| 90 final ListResultDescriptor< | 80 final ListResultDescriptor< |
| 91 ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS = | 81 ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS = |
| 92 new ListResultDescriptor<ConstantEvaluationTarget>( | 82 new ListResultDescriptor<ConstantEvaluationTarget>( |
| 93 'COMPILATION_UNIT_CONSTANTS', null, | 83 'COMPILATION_UNIT_CONSTANTS', null, |
| 94 cachingPolicy: ELEMENT_CACHING_POLICY); | 84 cachingPolicy: ELEMENT_CACHING_POLICY); |
| (...skipping 2601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2696 // | 2686 // |
| 2697 NodeLocator locator = new NodeLocator(variable.nameOffset); | 2687 NodeLocator locator = new NodeLocator(variable.nameOffset); |
| 2698 AstNode node = locator.searchWithin(unit); | 2688 AstNode node = locator.searchWithin(unit); |
| 2699 VariableDeclaration declaration = node | 2689 VariableDeclaration declaration = node |
| 2700 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); | 2690 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); |
| 2701 if (declaration == null || declaration.name != node) { | 2691 if (declaration == null || declaration.name != node) { |
| 2702 throw new AnalysisException( | 2692 throw new AnalysisException( |
| 2703 "NodeLocator failed to find a variable's declaration"); | 2693 "NodeLocator failed to find a variable's declaration"); |
| 2704 } | 2694 } |
| 2705 Expression initializer = declaration.initializer; | 2695 Expression initializer = declaration.initializer; |
| 2696 initializer.accept(new ResolutionEraser()); | |
| 2706 ResolutionContext resolutionContext = | 2697 ResolutionContext resolutionContext = |
| 2707 ResolutionContextBuilder.contextFor(initializer, errorListener); | 2698 ResolutionContextBuilder.contextFor(initializer, errorListener); |
| 2708 ResolverVisitor visitor = new ResolverVisitor( | 2699 ResolverVisitor visitor = new ResolverVisitor( |
| 2709 variable.library, variable.source, typeProvider, errorListener, | 2700 variable.library, variable.source, typeProvider, errorListener, |
| 2710 nameScope: resolutionContext.scope); | 2701 nameScope: resolutionContext.scope); |
| 2711 if (resolutionContext.enclosingClassDeclaration != null) { | 2702 if (resolutionContext.enclosingClassDeclaration != null) { |
| 2712 visitor.prepareToResolveMembersInClass( | 2703 visitor.prepareToResolveMembersInClass( |
| 2713 resolutionContext.enclosingClassDeclaration); | 2704 resolutionContext.enclosingClassDeclaration); |
| 2714 } | 2705 } |
| 2715 visitor.initForIncrementalResolution(); | 2706 visitor.initForIncrementalResolution(); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3134 */ | 3125 */ |
| 3135 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 3126 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
| 3136 | 3127 |
| 3137 /** | 3128 /** |
| 3138 * The task descriptor describing this kind of task. | 3129 * The task descriptor describing this kind of task. |
| 3139 */ | 3130 */ |
| 3140 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 3131 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3141 'PartiallyResolveUnitReferencesTask', | 3132 'PartiallyResolveUnitReferencesTask', |
| 3142 createTask, | 3133 createTask, |
| 3143 buildInputs, <ResultDescriptor>[ | 3134 buildInputs, <ResultDescriptor>[ |
| 3144 CLASSES_IN_UNIT, | |
| 3145 INFERABLE_STATIC_VARIABLES_IN_UNIT, | 3135 INFERABLE_STATIC_VARIABLES_IN_UNIT, |
| 3146 PARTIALLY_RESOLVE_REFERENCES_ERRORS, | 3136 PARTIALLY_RESOLVE_REFERENCES_ERRORS, |
| 3147 RESOLVED_UNIT5 | 3137 RESOLVED_UNIT5 |
| 3148 ]); | 3138 ]); |
| 3149 | 3139 |
| 3150 PartiallyResolveUnitReferencesTask( | 3140 PartiallyResolveUnitReferencesTask( |
| 3151 InternalAnalysisContext context, AnalysisTarget target) | 3141 InternalAnalysisContext context, AnalysisTarget target) |
| 3152 : super(context, target); | 3142 : super(context, target); |
| 3153 | 3143 |
| 3154 @override | 3144 @override |
| 3155 TaskDescriptor get descriptor => DESCRIPTOR; | 3145 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3156 | 3146 |
| 3157 @override | 3147 @override |
| 3158 void internalPerform() { | 3148 void internalPerform() { |
| 3159 RecordingErrorListener errorListener = new RecordingErrorListener(); | 3149 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 3160 // | 3150 // |
| 3161 // Prepare inputs. | 3151 // Prepare inputs. |
| 3162 // | 3152 // |
| 3163 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); | 3153 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); |
| 3164 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 3154 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 3165 CompilationUnitElement unitElement = unit.element; | 3155 CompilationUnitElement unitElement = unit.element; |
| 3166 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | 3156 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
| 3167 // | 3157 // |
| 3168 // Resolve references. | 3158 // Resolve references. |
| 3169 // | 3159 // |
| 3170 InheritanceManager inheritanceManager = | 3160 InheritanceManager inheritanceManager = |
| 3171 new InheritanceManager(libraryElement); | 3161 new InheritanceManager(libraryElement); |
| 3172 // TODO(brianwilkerson) Improve performance by not resolving anything inside | 3162 PartialResolverVisitor visitor = new PartialResolverVisitor( |
| 3173 // function bodies. Function bodies will be resolved later so this is wasted | |
| 3174 // effort. | |
| 3175 AstVisitor visitor = new ResolverVisitor( | |
| 3176 libraryElement, unitElement.source, typeProvider, errorListener, | 3163 libraryElement, unitElement.source, typeProvider, errorListener, |
| 3177 inheritanceManager: inheritanceManager); | 3164 inheritanceManager: inheritanceManager); |
| 3178 unit.accept(visitor); | 3165 unit.accept(visitor); |
| 3179 // | 3166 // |
| 3180 // Prepare targets for inference. | |
| 3181 // | |
| 3182 List<VariableElement> staticVariables = <VariableElement>[]; | |
| 3183 List<ClassElement> classes = <ClassElement>[]; | |
| 3184 if (context.analysisOptions.strongMode) { | |
| 3185 InferrenceFinder inferrenceFinder = new InferrenceFinder(); | |
| 3186 unit.accept(inferrenceFinder); | |
| 3187 staticVariables = inferrenceFinder.staticVariables; | |
| 3188 classes = inferrenceFinder.classes; | |
| 3189 } | |
| 3190 // | |
| 3191 // Record outputs. | 3167 // Record outputs. |
| 3192 // | 3168 // |
| 3193 outputs[CLASSES_IN_UNIT] = classes; | 3169 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = visitor.staticVariables; |
| 3194 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = staticVariables; | |
| 3195 outputs[PARTIALLY_RESOLVE_REFERENCES_ERRORS] = | 3170 outputs[PARTIALLY_RESOLVE_REFERENCES_ERRORS] = |
| 3196 removeDuplicateErrors(errorListener.errors); | 3171 removeDuplicateErrors(errorListener.errors); |
| 3197 outputs[RESOLVED_UNIT5] = unit; | 3172 outputs[RESOLVED_UNIT5] = unit; |
| 3198 } | 3173 } |
| 3199 | 3174 |
| 3200 /** | 3175 /** |
| 3201 * Return a map from the names of the inputs of this kind of task to the task | 3176 * Return a map from the names of the inputs of this kind of task to the task |
| 3202 * input descriptors describing those inputs for a task with the | 3177 * input descriptors describing those inputs for a task with the |
| 3203 * given [target]. | 3178 * given [target]. |
| 3204 */ | 3179 */ |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3431 RecordingErrorListener errorListener) { | 3406 RecordingErrorListener errorListener) { |
| 3432 ResolutionContext resolutionContext = | 3407 ResolutionContext resolutionContext = |
| 3433 ResolutionContextBuilder.contextFor(functionBody, errorListener); | 3408 ResolutionContextBuilder.contextFor(functionBody, errorListener); |
| 3434 ResolverVisitor visitor = new ResolverVisitor( | 3409 ResolverVisitor visitor = new ResolverVisitor( |
| 3435 unitElement.library, unitElement.source, typeProvider, errorListener, | 3410 unitElement.library, unitElement.source, typeProvider, errorListener, |
| 3436 nameScope: resolutionContext.scope); | 3411 nameScope: resolutionContext.scope); |
| 3437 if (resolutionContext.enclosingClassDeclaration != null) { | 3412 if (resolutionContext.enclosingClassDeclaration != null) { |
| 3438 visitor.prepareToResolveMembersInClass( | 3413 visitor.prepareToResolveMembersInClass( |
| 3439 resolutionContext.enclosingClassDeclaration); | 3414 resolutionContext.enclosingClassDeclaration); |
| 3440 } | 3415 } |
| 3441 visitor.initForIncrementalResolution(); | 3416 Declaration declaration = functionBody.getAncestor((AstNode node) => |
| 3417 node is ConstructorDeclaration || | |
| 3418 node is FunctionDeclaration || | |
| 3419 node is MethodDeclaration); | |
| 3420 visitor.initForIncrementalResolution(declaration); | |
| 3442 functionBody.accept(visitor); | 3421 functionBody.accept(visitor); |
| 3422 if (declaration is FunctionDeclaration) { | |
| 3423 // This is in the wrong place. The propagated return type is stored | |
| 3424 // locally in the resolver, not in the declaration (or element). Hence, | |
| 3425 // this needs to happen later. | |
|
Paul Berry
2015/09/08 16:13:30
I'm having trouble understanding this comment. Wo
Brian Wilkerson
2015/09/08 17:10:33
Actually, it looks like the consensus is to remove
| |
| 3426 declaration.accept(visitor.typeAnalyzer); | |
| 3427 } | |
| 3443 } | 3428 } |
| 3444 | 3429 |
| 3445 /** | 3430 /** |
| 3446 * Return a map from the names of the inputs of this kind of task to the task | 3431 * Return a map from the names of the inputs of this kind of task to the task |
| 3447 * input descriptors describing those inputs for a task with the given | 3432 * input descriptors describing those inputs for a task with the given |
| 3448 * [target]. | 3433 * [target]. |
| 3449 */ | 3434 */ |
| 3450 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3435 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3451 LibrarySpecificUnit unit = target; | 3436 LibrarySpecificUnit unit = target; |
| 3452 return <String, TaskInput>{ | 3437 return <String, TaskInput>{ |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4124 | 4109 |
| 4125 @override | 4110 @override |
| 4126 bool moveNext() { | 4111 bool moveNext() { |
| 4127 if (_newSources.isEmpty) { | 4112 if (_newSources.isEmpty) { |
| 4128 return false; | 4113 return false; |
| 4129 } | 4114 } |
| 4130 currentTarget = _newSources.removeLast(); | 4115 currentTarget = _newSources.removeLast(); |
| 4131 return true; | 4116 return true; |
| 4132 } | 4117 } |
| 4133 } | 4118 } |
| OLD | NEW |