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 2543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2554 // | 2554 // |
| 2555 // Prepare inputs. | 2555 // Prepare inputs. |
| 2556 // | 2556 // |
| 2557 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping | 2557 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping |
| 2558 // dependency to ensure that the variables that this variable references | 2558 // dependency to ensure that the variables that this variable references |
| 2559 // have types inferred before inferring the type of this variable. | 2559 // have types inferred before inferring the type of this variable. |
| 2560 // | 2560 // |
| 2561 VariableElementImpl variable = target; | 2561 VariableElementImpl variable = target; |
| 2562 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2562 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 2563 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | 2563 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
| 2564 // | 2564 if (dependencyCycle == null) { |
| 2565 // Re-resolve the variable's initializer so that the inferred types of other | 2565 // |
| 2566 // variables will be propagated. | 2566 // Re-resolve the variable's initializer so that the inferred types of oth er |
| 2567 // | 2567 // variables will be propagated. |
| 2568 NodeLocator locator = new NodeLocator(variable.nameOffset); | 2568 // |
| 2569 AstNode node = locator.searchWithin(unit); | 2569 NodeLocator locator = new NodeLocator(variable.nameOffset); |
| 2570 VariableDeclaration declaration = | 2570 AstNode node = locator.searchWithin(unit); |
| 2571 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); | 2571 VariableDeclaration declaration = node |
| 2572 if (declaration == null || declaration.name != node) { | 2572 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); |
| 2573 throw new AnalysisException( | 2573 if (declaration == null || declaration.name != node) { |
| 2574 "NodeLocator failed to find a variable's declaration"); | 2574 throw new AnalysisException( |
| 2575 } | 2575 "NodeLocator failed to find a variable's declaration"); |
| 2576 RecordingErrorListener errorListener = new RecordingErrorListener(); | 2576 } |
| 2577 Expression initializer = declaration.initializer; | 2577 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 2578 ResolutionContext resolutionContext = | 2578 Expression initializer = declaration.initializer; |
| 2579 ResolutionContextBuilder.contextFor(initializer, errorListener); | 2579 ResolutionContext resolutionContext = |
| 2580 ResolverVisitor visitor = new ResolverVisitor( | 2580 ResolutionContextBuilder.contextFor(initializer, errorListener); |
| 2581 variable.library, variable.source, typeProvider, errorListener, | 2581 ResolverVisitor visitor = new ResolverVisitor( |
| 2582 nameScope: resolutionContext.scope); | 2582 variable.library, variable.source, typeProvider, errorListener, |
| 2583 if (resolutionContext.enclosingClassDeclaration != null) { | 2583 nameScope: resolutionContext.scope); |
| 2584 visitor.prepareToResolveMembersInClass( | 2584 if (resolutionContext.enclosingClassDeclaration != null) { |
| 2585 resolutionContext.enclosingClassDeclaration); | 2585 visitor.prepareToResolveMembersInClass( |
| 2586 } | 2586 resolutionContext.enclosingClassDeclaration); |
| 2587 visitor.initForIncrementalResolution(); | 2587 } |
| 2588 initializer.accept(visitor); | 2588 visitor.initForIncrementalResolution(); |
| 2589 // | 2589 initializer.accept(visitor); |
| 2590 // Record the type of the variable. | 2590 // |
| 2591 // | 2591 // Record the type of the variable. |
| 2592 DartType newType = initializer.staticType; | 2592 // |
| 2593 variable.type = newType; | 2593 DartType newType = initializer.staticType; |
| 2594 (variable.initializer as ExecutableElementImpl).returnType = newType; | 2594 if (newType == null || newType.isBottom) { |
| 2595 if (variable is PropertyInducingElementImpl) { | 2595 newType = typeProvider.dynamicType; |
| 2596 setReturnType(variable.getter, newType); | 2596 } |
| 2597 setParameterType(variable.setter, newType); | 2597 variable.type = newType; |
| 2598 (variable.initializer as ExecutableElementImpl).returnType = newType; | |
| 2599 if (variable is PropertyInducingElementImpl) { | |
| 2600 setReturnType(variable.getter, newType); | |
| 2601 setParameterType(variable.setter, newType); | |
| 2602 } | |
| 2603 } else { | |
| 2604 // TODO(brianwilkerson) For now we simply don't infer any type for | |
| 2605 // variables or fields involved in a cycle. We could try to be smarter | |
| 2606 // by re-resolving the initializer in a context in which the types of all | |
| 2607 // of the variables in the cycle are assumed to be `null`, but it isn't | |
| 2608 // clear to me that this would produce better results often enough to | |
| 2609 // warrent the extra effort. | |
|
Leaf
2015/08/31 21:07:03
warrent -> warrant
Brian Wilkerson
2015/08/31 21:27:47
Thanks! I really miss spell checking :-(
| |
| 2598 } | 2610 } |
| 2599 // | 2611 // |
| 2600 // Record outputs. | 2612 // Record outputs. |
| 2601 // | 2613 // |
| 2602 outputs[INFERRED_STATIC_VARIABLE] = variable; | 2614 outputs[INFERRED_STATIC_VARIABLE] = variable; |
| 2603 } | 2615 } |
| 2604 | 2616 |
| 2605 /** | 2617 /** |
| 2606 * Return a map from the names of the inputs of this kind of task to the task | 2618 * Return a map from the names of the inputs of this kind of task to the task |
| 2607 * input descriptors describing those inputs for a task with the given | 2619 * input descriptors describing those inputs for a task with the given |
| (...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3950 | 3962 |
| 3951 @override | 3963 @override |
| 3952 bool moveNext() { | 3964 bool moveNext() { |
| 3953 if (_newSources.isEmpty) { | 3965 if (_newSources.isEmpty) { |
| 3954 return false; | 3966 return false; |
| 3955 } | 3967 } |
| 3956 currentTarget = _newSources.removeLast(); | 3968 currentTarget = _newSources.removeLast(); |
| 3957 return true; | 3969 return true; |
| 3958 } | 3970 } |
| 3959 } | 3971 } |
| OLD | NEW |