Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 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 5561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5572 * A comment before a function should be resolved in the context of the | 5572 * A comment before a function should be resolved in the context of the |
| 5573 * function. But when we incrementally resolve a comment, we don't want to | 5573 * function. But when we incrementally resolve a comment, we don't want to |
| 5574 * resolve the whole function. | 5574 * resolve the whole function. |
| 5575 * | 5575 * |
| 5576 * So, this flag is set to `true`, when just context of the function should | 5576 * So, this flag is set to `true`, when just context of the function should |
| 5577 * be built and the comment resolved. | 5577 * be built and the comment resolved. |
| 5578 */ | 5578 */ |
| 5579 bool resolveOnlyCommentInFunctionBody = false; | 5579 bool resolveOnlyCommentInFunctionBody = false; |
| 5580 | 5580 |
| 5581 /** | 5581 /** |
| 5582 * True if we're analyzing in strong mode. | |
| 5583 */ | |
| 5584 bool _strongMode; | |
| 5585 | |
| 5586 /** | |
| 5582 * Body of the function currently being analyzed, if any. | 5587 * Body of the function currently being analyzed, if any. |
| 5583 */ | 5588 */ |
| 5584 FunctionBody _currentFunctionBody; | 5589 FunctionBody _currentFunctionBody; |
| 5585 | 5590 |
| 5586 /** | 5591 /** |
| 5587 * Initialize a newly created visitor to resolve the nodes in an AST node. | 5592 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 5588 * | 5593 * |
| 5589 * The [definingLibrary] is the element for the library containing the node | 5594 * The [definingLibrary] is the element for the library containing the node |
| 5590 * being visited. The [source] is the source representing the compilation unit | 5595 * being visited. The [source] is the source representing the compilation unit |
| 5591 * containing the node being visited. The [typeProvider] is the object used to | 5596 * containing the node being visited. The [typeProvider] is the object used to |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5602 */ | 5607 */ |
| 5603 ResolverVisitor(LibraryElement definingLibrary, Source source, | 5608 ResolverVisitor(LibraryElement definingLibrary, Source source, |
| 5604 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 5609 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 5605 {Scope nameScope}) | 5610 {Scope nameScope}) |
| 5606 : super(definingLibrary, source, typeProvider, errorListener, | 5611 : super(definingLibrary, source, typeProvider, errorListener, |
| 5607 nameScope: nameScope) { | 5612 nameScope: nameScope) { |
| 5608 this.elementResolver = new ElementResolver(this); | 5613 this.elementResolver = new ElementResolver(this); |
| 5609 this.typeSystem = definingLibrary.context.typeSystem; | 5614 this.typeSystem = definingLibrary.context.typeSystem; |
| 5610 bool strongModeHints = false; | 5615 bool strongModeHints = false; |
| 5611 AnalysisOptions options = definingLibrary.context.analysisOptions; | 5616 AnalysisOptions options = definingLibrary.context.analysisOptions; |
| 5617 _strongMode = options.strongMode; | |
| 5612 if (options is AnalysisOptionsImpl) { | 5618 if (options is AnalysisOptionsImpl) { |
| 5613 strongModeHints = options.strongModeHints; | 5619 strongModeHints = options.strongModeHints; |
| 5614 } | 5620 } |
| 5615 this.inferenceContext = new InferenceContext._( | 5621 this.inferenceContext = new InferenceContext._( |
| 5616 errorReporter, typeProvider, typeSystem, strongModeHints); | 5622 errorReporter, typeProvider, typeSystem, strongModeHints); |
| 5617 this.typeAnalyzer = new StaticTypeAnalyzer(this); | 5623 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 5618 } | 5624 } |
| 5619 | 5625 |
| 5620 /** | 5626 /** |
| 5621 * Return the element representing the function containing the current node, o r `null` if | 5627 * Return the element representing the function containing the current node, o r `null` if |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6292 // We do not visit the label because it needs to be visited in the context | 6298 // We do not visit the label because it needs to be visited in the context |
| 6293 // of the statement. | 6299 // of the statement. |
| 6294 // | 6300 // |
| 6295 node.accept(elementResolver); | 6301 node.accept(elementResolver); |
| 6296 node.accept(typeAnalyzer); | 6302 node.accept(typeAnalyzer); |
| 6297 return null; | 6303 return null; |
| 6298 } | 6304 } |
| 6299 | 6305 |
| 6300 @override | 6306 @override |
| 6301 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 6307 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 6302 InferenceContext.setType(node.defaultValue, node.parameter.element?.type); | 6308 ParameterElement element = node.element; |
| 6309 InferenceContext.setType(node.defaultValue, element.type); | |
|
Jennifer Messerly
2016/06/23 20:14:46
I verified with an assert that `node.parameter.ele
| |
| 6303 super.visitDefaultFormalParameter(node); | 6310 super.visitDefaultFormalParameter(node); |
| 6304 ParameterElement element = node.element; | |
| 6305 if (element.initializer != null && node.defaultValue != null) { | 6311 if (element.initializer != null && node.defaultValue != null) { |
| 6306 (element.initializer as FunctionElementImpl).returnType = | 6312 (element.initializer as FunctionElementImpl).returnType = |
| 6307 node.defaultValue.staticType; | 6313 node.defaultValue.staticType; |
| 6308 } | 6314 } |
| 6315 if (_strongMode && | |
| 6316 node.defaultValue != null && | |
| 6317 element.hasImplicitType && | |
| 6318 element is! FieldFormalParameterElement) { | |
|
Jennifer Messerly
2016/06/23 20:14:46
I experimented with allowing field formal paramete
| |
| 6319 | |
| 6320 DartType type = node.defaultValue.staticType; | |
| 6321 if (!type.isBottom && !type.isDynamic) { | |
|
Leaf
2016/06/23 22:21:17
Are we quite sure that type can't be null here?
Jennifer Messerly
2016/06/24 18:33:59
I think so? :) after resolving an expression, the
Leaf
2016/06/24 21:48:53
I'm ok leaving it. Just wanted to check since we
| |
| 6322 (element as ParameterElementImpl).type = type; | |
|
Leaf
2016/06/23 22:21:17
I'm been trying to record all inference events, ev
Jennifer Messerly
2016/06/24 18:33:59
Yeah that's a good idea ... the only strange part
| |
| 6323 } | |
| 6324 } | |
| 6309 // Clone the ASTs for default formal parameters, so that we can use them | 6325 // Clone the ASTs for default formal parameters, so that we can use them |
| 6310 // during constant evaluation. | 6326 // during constant evaluation. |
| 6311 if (!LibraryElementImpl.hasResolutionCapability( | 6327 if (!LibraryElementImpl.hasResolutionCapability( |
| 6312 definingLibrary, LibraryResolutionCapability.constantExpressions)) { | 6328 definingLibrary, LibraryResolutionCapability.constantExpressions)) { |
| 6313 (element as ConstVariableElement).constantInitializer = | 6329 (element as ConstVariableElement).constantInitializer = |
| 6314 new ConstantAstCloner().cloneNode(node.defaultValue); | 6330 new ConstantAstCloner().cloneNode(node.defaultValue); |
| 6315 } | 6331 } |
| 6316 return null; | 6332 return null; |
| 6317 } | 6333 } |
| 6318 | 6334 |
| (...skipping 4647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10966 return null; | 10982 return null; |
| 10967 } | 10983 } |
| 10968 if (identical(node.staticElement, variable)) { | 10984 if (identical(node.staticElement, variable)) { |
| 10969 if (node.inSetterContext()) { | 10985 if (node.inSetterContext()) { |
| 10970 result = true; | 10986 result = true; |
| 10971 } | 10987 } |
| 10972 } | 10988 } |
| 10973 return null; | 10989 return null; |
| 10974 } | 10990 } |
| 10975 } | 10991 } |
| OLD | NEW |