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 6590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6601 | 6601 |
6602 // Pretend the return type of Future<T>.then<S> first parameter is | 6602 // Pretend the return type of Future<T>.then<S> first parameter is |
6603 // | 6603 // |
6604 // T -> (S | Future<S>) | 6604 // T -> (S | Future<S>) |
6605 // | 6605 // |
6606 // We can't represent this in Dart so we populate it here during | 6606 // We can't represent this in Dart so we populate it here during |
6607 // inference. | 6607 // inference. |
6608 var typeParamS = | 6608 var typeParamS = |
6609 futureThenType.returnType.flattenFutures(typeSystem); | 6609 futureThenType.returnType.flattenFutures(typeSystem); |
6610 returnType = | 6610 returnType = |
6611 FutureUnionType.from(typeParamS, typeProvider, typeSystem); | 6611 FutureUnionType.from(typeParamS, typeProvider, typeSystem); |
6612 } else { | 6612 } else { |
6613 returnType = _computeReturnOrYieldType(functionType.returnType); | 6613 returnType = _computeReturnOrYieldType(functionType.returnType); |
6614 } | 6614 } |
6615 | 6615 |
6616 InferenceContext.setType(node.body, returnType); | 6616 InferenceContext.setType(node.body, returnType); |
6617 } | 6617 } |
6618 } | 6618 } |
6619 super.visitFunctionExpression(node); | 6619 super.visitFunctionExpression(node); |
6620 } finally { | 6620 } finally { |
6621 _overrideManager.exitScope(); | 6621 _overrideManager.exitScope(); |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7775 Scope pushNameScope() { | 7775 Scope pushNameScope() { |
7776 Scope newScope = new EnclosedScope(nameScope); | 7776 Scope newScope = new EnclosedScope(nameScope); |
7777 nameScope = newScope; | 7777 nameScope = newScope; |
7778 return nameScope; | 7778 return nameScope; |
7779 } | 7779 } |
7780 | 7780 |
7781 @override | 7781 @override |
7782 Object visitBlock(Block node) { | 7782 Object visitBlock(Block node) { |
7783 Scope outerScope = nameScope; | 7783 Scope outerScope = nameScope; |
7784 try { | 7784 try { |
7785 EnclosedScope enclosedScope = new EnclosedScope(nameScope); | 7785 EnclosedScope enclosedScope = new BlockScope(nameScope, node); |
7786 _hideNamesDefinedInBlock(enclosedScope, node); | |
7787 nameScope = enclosedScope; | 7786 nameScope = enclosedScope; |
7788 super.visitBlock(node); | 7787 super.visitBlock(node); |
7789 } finally { | 7788 } finally { |
7790 nameScope = outerScope; | 7789 nameScope = outerScope; |
7791 } | 7790 } |
7792 return null; | 7791 return null; |
7793 } | 7792 } |
7794 | 7793 |
7795 @override | 7794 @override |
7796 Object visitBlockFunctionBody(BlockFunctionBody node) { | 7795 Object visitBlockFunctionBody(BlockFunctionBody node) { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8300 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { | 8299 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { |
8301 LabelScope outerScope = labelScope; | 8300 LabelScope outerScope = labelScope; |
8302 for (Label label in labels) { | 8301 for (Label label in labels) { |
8303 SimpleIdentifier labelNameNode = label.label; | 8302 SimpleIdentifier labelNameNode = label.label; |
8304 String labelName = labelNameNode.name; | 8303 String labelName = labelNameNode.name; |
8305 LabelElement labelElement = labelNameNode.staticElement as LabelElement; | 8304 LabelElement labelElement = labelNameNode.staticElement as LabelElement; |
8306 labelScope = new LabelScope(labelScope, labelName, node, labelElement); | 8305 labelScope = new LabelScope(labelScope, labelName, node, labelElement); |
8307 } | 8306 } |
8308 return outerScope; | 8307 return outerScope; |
8309 } | 8308 } |
8310 | |
8311 /** | |
8312 * Marks the local declarations of the given [Block] hidden in the enclosing s
cope. | |
8313 * According to the scoping rules name is hidden if block defines it, but name
is defined after | |
8314 * its declaration statement. | |
8315 */ | |
8316 void _hideNamesDefinedInBlock(EnclosedScope scope, Block block) { | |
8317 NodeList<Statement> statements = block.statements; | |
8318 int statementCount = statements.length; | |
8319 for (int i = 0; i < statementCount; i++) { | |
8320 Statement statement = statements[i]; | |
8321 if (statement is VariableDeclarationStatement) { | |
8322 NodeList<VariableDeclaration> variables = statement.variables.variables; | |
8323 int variableCount = variables.length; | |
8324 for (int j = 0; j < variableCount; j++) { | |
8325 scope.hide(variables[j].element); | |
8326 } | |
8327 } else if (statement is FunctionDeclarationStatement) { | |
8328 scope.hide(statement.functionDeclaration.element); | |
8329 } | |
8330 } | |
8331 } | |
8332 } | 8309 } |
8333 | 8310 |
8334 /** | 8311 /** |
8335 * Instances of this class manage the knowledge of what the set of subtypes are
for a given type. | 8312 * Instances of this class manage the knowledge of what the set of subtypes are
for a given type. |
8336 */ | 8313 */ |
8337 class SubtypeManager { | 8314 class SubtypeManager { |
8338 /** | 8315 /** |
8339 * A map between [ClassElement]s and a set of [ClassElement]s that are subtype
s of the | 8316 * A map between [ClassElement]s and a set of [ClassElement]s that are subtype
s of the |
8340 * key. | 8317 * key. |
8341 */ | 8318 */ |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8822 } else { | 8799 } else { |
8823 AstNode parent = typeName.parent; | 8800 AstNode parent = typeName.parent; |
8824 while (parent is TypeName) { | 8801 while (parent is TypeName) { |
8825 parent = parent.parent; | 8802 parent = parent.parent; |
8826 } | 8803 } |
8827 if (parent is ExtendsClause || | 8804 if (parent is ExtendsClause || |
8828 parent is ImplementsClause || | 8805 parent is ImplementsClause || |
8829 parent is WithClause || | 8806 parent is WithClause || |
8830 parent is ClassTypeAlias) { | 8807 parent is ClassTypeAlias) { |
8831 // Ignored. The error will be reported elsewhere. | 8808 // Ignored. The error will be reported elsewhere. |
| 8809 } else if (element is LocalVariableElement || |
| 8810 (element is FunctionElement && |
| 8811 element.enclosingElement is ExecutableElement)) { |
| 8812 reportErrorForNode(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, |
| 8813 typeName, [typeName.name]); |
8832 } else { | 8814 } else { |
8833 reportErrorForNode( | 8815 reportErrorForNode( |
8834 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); | 8816 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); |
8835 } | 8817 } |
8836 } | 8818 } |
8837 typeName.staticType = dynamicType; | 8819 typeName.staticType = dynamicType; |
8838 node.type = dynamicType; | 8820 node.type = dynamicType; |
8839 return; | 8821 return; |
8840 } | 8822 } |
8841 if (argumentList != null) { | 8823 if (argumentList != null) { |
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11154 return null; | 11136 return null; |
11155 } | 11137 } |
11156 if (identical(node.staticElement, variable)) { | 11138 if (identical(node.staticElement, variable)) { |
11157 if (node.inSetterContext()) { | 11139 if (node.inSetterContext()) { |
11158 result = true; | 11140 result = true; |
11159 } | 11141 } |
11160 } | 11142 } |
11161 return null; | 11143 return null; |
11162 } | 11144 } |
11163 } | 11145 } |
OLD | NEW |