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/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 11656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11667 * The type representing typenames that can't be resolved. | 11667 * The type representing typenames that can't be resolved. |
| 11668 */ | 11668 */ |
| 11669 DartType _undefinedType; | 11669 DartType _undefinedType; |
| 11670 | 11670 |
| 11671 /** | 11671 /** |
| 11672 * The flag specifying if currently visited class references 'super' expressio n. | 11672 * The flag specifying if currently visited class references 'super' expressio n. |
| 11673 */ | 11673 */ |
| 11674 bool _hasReferenceToSuper = false; | 11674 bool _hasReferenceToSuper = false; |
| 11675 | 11675 |
| 11676 /** | 11676 /** |
| 11677 * True if we're analyzing in strong mode. | |
| 11678 */ | |
| 11679 bool _strongMode; | |
| 11680 | |
| 11681 /** | |
| 11677 * Initialize a newly created visitor to resolve the nodes in an AST node. | 11682 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 11678 * | 11683 * |
| 11679 * [definingLibrary] is the element for the library containing the node being | 11684 * [definingLibrary] is the element for the library containing the node being |
| 11680 * visited. | 11685 * visited. |
| 11681 * [source] is the source representing the compilation unit containing the | 11686 * [source] is the source representing the compilation unit containing the |
| 11682 * node being visited. | 11687 * node being visited. |
| 11683 * [typeProvider] is the object used to access the types from the core | 11688 * [typeProvider] is the object used to access the types from the core |
| 11684 * library. | 11689 * library. |
| 11685 * [errorListener] is the error listener that will be informed of any errors | 11690 * [errorListener] is the error listener that will be informed of any errors |
| 11686 * that are found during resolution. | 11691 * that are found during resolution. |
| 11687 * [nameScope] is the scope used to resolve identifiers in the node that will | 11692 * [nameScope] is the scope used to resolve identifiers in the node that will |
| 11688 * first be visited. If `null` or unspecified, a new [LibraryScope] will be | 11693 * first be visited. If `null` or unspecified, a new [LibraryScope] will be |
| 11689 * created based on [definingLibrary] and [typeProvider]. | 11694 * created based on [definingLibrary] and [typeProvider]. |
| 11690 */ | 11695 */ |
| 11691 TypeResolverVisitor(LibraryElement definingLibrary, Source source, | 11696 TypeResolverVisitor(LibraryElement definingLibrary, Source source, |
| 11692 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 11697 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 11693 {Scope nameScope}) | 11698 {Scope nameScope}) |
| 11694 : super(definingLibrary, source, typeProvider, errorListener, | 11699 : super(definingLibrary, source, typeProvider, errorListener, |
| 11695 nameScope: nameScope) { | 11700 nameScope: nameScope) { |
| 11696 _dynamicType = typeProvider.dynamicType; | 11701 _dynamicType = typeProvider.dynamicType; |
| 11697 _undefinedType = typeProvider.undefinedType; | 11702 _undefinedType = typeProvider.undefinedType; |
| 11703 _strongMode = definingLibrary.context.analysisOptions.strongMode; | |
| 11698 } | 11704 } |
| 11699 | 11705 |
| 11700 @override | 11706 @override |
| 11701 Object visitAnnotation(Annotation node) { | 11707 Object visitAnnotation(Annotation node) { |
| 11702 // | 11708 // |
| 11703 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" | 11709 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" |
| 11704 // resolves to the proxy annotation in dart.core, then create create the | 11710 // resolves to the proxy annotation in dart.core, then create create the |
| 11705 // ElementAnnotationImpl and set it as the metadata on the enclosing class. | 11711 // ElementAnnotationImpl and set it as the metadata on the enclosing class. |
| 11706 // | 11712 // |
| 11707 // Element resolution is done in the ElementResolver, and this work will be | 11713 // Element resolution is done in the ElementResolver, and this work will be |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11928 buffer.write("The element for the top-level function "); | 11934 buffer.write("The element for the top-level function "); |
| 11929 buffer.write(node.name); | 11935 buffer.write(node.name); |
| 11930 buffer.write(" in "); | 11936 buffer.write(" in "); |
| 11931 buffer.write(source.fullName); | 11937 buffer.write(source.fullName); |
| 11932 buffer.write(" was not set while trying to resolve types."); | 11938 buffer.write(" was not set while trying to resolve types."); |
| 11933 AnalysisEngine.instance.logger.logError(buffer.toString(), | 11939 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 11934 new CaughtException(new AnalysisException(), null)); | 11940 new CaughtException(new AnalysisException(), null)); |
| 11935 } | 11941 } |
| 11936 element.returnType = _computeReturnType(node.returnType); | 11942 element.returnType = _computeReturnType(node.returnType); |
| 11937 element.type = new FunctionTypeImpl(element); | 11943 element.type = new FunctionTypeImpl(element); |
| 11944 _inferSetterReturnType(element); | |
| 11938 return null; | 11945 return null; |
| 11939 } | 11946 } |
| 11940 | 11947 |
| 11941 @override | 11948 @override |
| 11942 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 11949 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 11943 FunctionTypeAliasElementImpl element = | 11950 FunctionTypeAliasElementImpl element = |
| 11944 node.element as FunctionTypeAliasElementImpl; | 11951 node.element as FunctionTypeAliasElementImpl; |
| 11945 super.visitFunctionTypeAlias(node); | 11952 super.visitFunctionTypeAlias(node); |
| 11946 element.returnType = _computeReturnType(node.returnType); | 11953 element.returnType = _computeReturnType(node.returnType); |
| 11947 return null; | 11954 return null; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 11976 buffer.write(classNode.name.name); | 11983 buffer.write(classNode.name.name); |
| 11977 } | 11984 } |
| 11978 buffer.write(" in "); | 11985 buffer.write(" in "); |
| 11979 buffer.write(source.fullName); | 11986 buffer.write(source.fullName); |
| 11980 buffer.write(" was not set while trying to resolve types."); | 11987 buffer.write(" was not set while trying to resolve types."); |
| 11981 AnalysisEngine.instance.logger.logError(buffer.toString(), | 11988 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 11982 new CaughtException(new AnalysisException(), null)); | 11989 new CaughtException(new AnalysisException(), null)); |
| 11983 } | 11990 } |
| 11984 element.returnType = _computeReturnType(node.returnType); | 11991 element.returnType = _computeReturnType(node.returnType); |
| 11985 element.type = new FunctionTypeImpl(element); | 11992 element.type = new FunctionTypeImpl(element); |
| 11993 _inferSetterReturnType(element); | |
| 11986 if (element is PropertyAccessorElement) { | 11994 if (element is PropertyAccessorElement) { |
| 11987 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 11995 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
| 11988 PropertyInducingElementImpl variable = | 11996 PropertyInducingElementImpl variable = |
| 11989 accessor.variable as PropertyInducingElementImpl; | 11997 accessor.variable as PropertyInducingElementImpl; |
| 11990 if (accessor.isGetter) { | 11998 if (accessor.isGetter) { |
| 11991 variable.type = element.returnType; | 11999 variable.type = element.returnType; |
| 11992 } else if (variable.type == null) { | 12000 } else if (variable.type == null) { |
| 11993 List<ParameterElement> parameters = element.parameters; | 12001 List<ParameterElement> parameters = element.parameters; |
| 11994 if (parameters != null && parameters.length > 0) { | 12002 if (parameters != null && parameters.length > 0) { |
| 11995 variable.type = parameters[0].type; | 12003 variable.type = parameters[0].type; |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12504 if (element is ClassElement) { | 12512 if (element is ClassElement) { |
| 12505 if (type != null) { | 12513 if (type != null) { |
| 12506 return null; | 12514 return null; |
| 12507 } | 12515 } |
| 12508 type = element.type; | 12516 type = element.type; |
| 12509 } | 12517 } |
| 12510 } | 12518 } |
| 12511 return type; | 12519 return type; |
| 12512 } | 12520 } |
| 12513 | 12521 |
| 12522 /** | |
| 12523 * In strong mode we infer "void" as the setter return type (as void is the | |
| 12524 * only legal return type for a setter). This allows us to give better | |
| 12525 * errors later if an invalid type is returned. | |
| 12526 */ | |
| 12527 void _inferSetterReturnType(ExecutableElementImpl element) { | |
| 12528 if (_strongMode && | |
| 12529 element is PropertyAccessorElementImpl && | |
| 12530 element.isSetter && | |
| 12531 element.returnType.isDynamic) { | |
|
Brian Wilkerson
2015/12/17 17:57:59
We should check that the type 'dynamic' was not ex
Jennifer Messerly
2016/01/05 00:42:44
Good catch! I thought it was okay because it's inv
| |
| 12532 element.returnType = VoidTypeImpl.instance; | |
| 12533 } | |
| 12534 } | |
| 12535 | |
| 12514 DartType _instantiateType(DartType type, List<DartType> typeArguments) { | 12536 DartType _instantiateType(DartType type, List<DartType> typeArguments) { |
| 12515 if (type is InterfaceTypeImpl) { | 12537 if (type is InterfaceTypeImpl) { |
| 12516 return type.substitute4(typeArguments); | 12538 return type.substitute4(typeArguments); |
| 12517 } else if (type is FunctionTypeImpl) { | 12539 } else if (type is FunctionTypeImpl) { |
| 12518 return type.instantiate(typeArguments); | 12540 return type.instantiate(typeArguments); |
| 12519 } else { | 12541 } else { |
| 12520 // TODO(brianwilkerson) Report this internal error. | 12542 // TODO(brianwilkerson) Report this internal error. |
| 12521 return type; | 12543 return type; |
| 12522 } | 12544 } |
| 12523 } | 12545 } |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13347 nonFields.add(node); | 13369 nonFields.add(node); |
| 13348 return null; | 13370 return null; |
| 13349 } | 13371 } |
| 13350 | 13372 |
| 13351 @override | 13373 @override |
| 13352 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 13374 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 13353 | 13375 |
| 13354 @override | 13376 @override |
| 13355 Object visitWithClause(WithClause node) => null; | 13377 Object visitWithClause(WithClause node) => null; |
| 13356 } | 13378 } |
| OLD | NEW |