Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1437)

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/resolver.dart

Issue 42863002: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 library engine.resolver; 3 library engine.resolver;
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'java_core.dart'; 5 import 'java_core.dart';
6 import 'java_engine.dart'; 6 import 'java_engine.dart';
7 import 'instrumentation.dart'; 7 import 'instrumentation.dart';
8 import 'source.dart'; 8 import 'source.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'scanner.dart' as sc; 10 import 'scanner.dart' as sc;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 if (element is PropertyInducingElementImpl) { 610 if (element is PropertyInducingElementImpl) {
611 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl; 611 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl;
612 if (_inFieldContext) { 612 if (_inFieldContext) {
613 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC); 613 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC);
614 } 614 }
615 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable); 615 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable);
616 getter.getter = true; 616 getter.getter = true;
617 getter.static = variable.isStatic; 617 getter.static = variable.isStatic;
618 _currentHolder.addAccessor(getter); 618 _currentHolder.addAccessor(getter);
619 variable.getter = getter; 619 variable.getter = getter;
620 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con2( variable); 620 if (!isFinal) {
621 setter.setter = true; 621 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable);
622 setter.static = variable.isStatic; 622 setter.setter = true;
623 ParameterElementImpl parameter = new ParameterElementImpl.con2("_${variabl e.name}", variable.nameOffset); 623 setter.static = variable.isStatic;
624 parameter.synthetic = true; 624 ParameterElementImpl parameter = new ParameterElementImpl.con2("_${varia ble.name}", variable.nameOffset);
625 parameter.parameterKind = ParameterKind.REQUIRED; 625 parameter.synthetic = true;
626 setter.parameters = <ParameterElement> [parameter]; 626 parameter.parameterKind = ParameterKind.REQUIRED;
627 _currentHolder.addAccessor(setter); 627 setter.parameters = <ParameterElement> [parameter];
628 variable.setter = setter; 628 _currentHolder.addAccessor(setter);
629 variable.setter = setter;
630 }
629 } 631 }
630 return null; 632 return null;
631 } 633 }
632 634
633 /** 635 /**
634 * Creates the [ConstructorElement]s array with the single default constructor element. 636 * Creates the [ConstructorElement]s array with the single default constructor element.
635 * 637 *
636 * @param interfaceType the interface type for which to create a default const ructor 638 * @param interfaceType the interface type for which to create a default const ructor
637 * @return the [ConstructorElement]s array with the single default constructor element 639 * @return the [ConstructorElement]s array with the single default constructor element
638 */ 640 */
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 try { 1171 try {
1170 if (isScriptNode(node)) { 1172 if (isScriptNode(node)) {
1171 Source htmlSource = _htmlElement.source; 1173 Source htmlSource = _htmlElement.source;
1172 ht.XmlAttributeNode scriptAttribute = getScriptSourcePath(node); 1174 ht.XmlAttributeNode scriptAttribute = getScriptSourcePath(node);
1173 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribu te.text; 1175 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribu te.text;
1174 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePa th == null) { 1176 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePa th == null) {
1175 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementIm pl(node); 1177 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementIm pl(node);
1176 String contents = node.content; 1178 String contents = node.content;
1177 int attributeEnd = node.attributeEnd.end; 1179 int attributeEnd = node.attributeEnd.end;
1178 LineInfo_Location location = _lineInfo.getLocation(attributeEnd); 1180 LineInfo_Location location = _lineInfo.getLocation(attributeEnd);
1179 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, errorListener); 1181 sc.Scanner scanner = new sc.Scanner(htmlSource, new sc.SubSequenceRead er(new CharSequence(contents), attributeEnd), errorListener);
1180 scanner.setSourceStart(location.lineNumber, location.columnNumber, att ributeEnd); 1182 scanner.setSourceStart(location.lineNumber, location.columnNumber);
1181 sc.Token firstToken = scanner.tokenize(); 1183 sc.Token firstToken = scanner.tokenize();
1182 List<int> lineStarts = scanner.lineStarts; 1184 List<int> lineStarts = scanner.lineStarts;
1183 Parser parser = new Parser(htmlSource, errorListener); 1185 Parser parser = new Parser(htmlSource, errorListener);
1184 CompilationUnit unit = parser.parseCompilationUnit(firstToken); 1186 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
1185 try { 1187 try {
1186 LibraryResolver resolver = new LibraryResolver(_context); 1188 LibraryResolver resolver = new LibraryResolver(_context);
1187 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl; 1189 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl;
1188 script.scriptLibrary = library; 1190 script.scriptLibrary = library;
1189 resolvedLibraries.addAll(resolver.resolvedLibraries); 1191 resolvedLibraries.addAll(resolver.resolvedLibraries);
1190 errorListener.addAll(resolver.errorListener); 1192 errorListener.addAll(resolver.errorListener);
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 * The type representing the type 'type'. 2958 * The type representing the type 'type'.
2957 */ 2959 */
2958 Type2 _typeType; 2960 Type2 _typeType;
2959 2961
2960 /** 2962 /**
2961 * A utility class for the resolver to answer the question of "what are my sub types?". 2963 * A utility class for the resolver to answer the question of "what are my sub types?".
2962 */ 2964 */
2963 SubtypeManager _subtypeManager; 2965 SubtypeManager _subtypeManager;
2964 2966
2965 /** 2967 /**
2968 * The object keeping track of which elements have had their types promoted.
2969 */
2970 TypePromotionManager _promoteManager;
2971
2972 /**
2966 * The name of the method that can be implemented by a class to allow its inst ances to be invoked 2973 * The name of the method that can be implemented by a class to allow its inst ances to be invoked
2967 * as if they were a function. 2974 * as if they were a function.
2968 */ 2975 */
2969 static String CALL_METHOD_NAME = "call"; 2976 static String CALL_METHOD_NAME = "call";
2970 2977
2971 /** 2978 /**
2972 * The name of the method that will be invoked if an attempt is made to invoke an undefined method 2979 * The name of the method that will be invoked if an attempt is made to invoke an undefined method
2973 * on an object. 2980 * on an object.
2974 */ 2981 */
2975 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; 2982 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
2976 2983
2977 /** 2984 /**
2978 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 2985 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
2979 * 2986 *
2980 * @param resolver the resolver driving this participant 2987 * @param resolver the resolver driving this participant
2981 */ 2988 */
2982 ElementResolver(ResolverVisitor resolver) { 2989 ElementResolver(ResolverVisitor resolver) {
2983 this._resolver = resolver; 2990 this._resolver = resolver;
2984 AnalysisOptions options = resolver.definingLibrary.context.analysisOptions; 2991 AnalysisOptions options = resolver.definingLibrary.context.analysisOptions;
2985 _strictMode = options.strictMode; 2992 _strictMode = options.strictMode;
2986 _enableHints = options.hint; 2993 _enableHints = options.hint;
2987 _dynamicType = resolver.typeProvider.dynamicType; 2994 _dynamicType = resolver.typeProvider.dynamicType;
2988 _typeType = resolver.typeProvider.typeType; 2995 _typeType = resolver.typeProvider.typeType;
2989 _subtypeManager = new SubtypeManager(); 2996 _subtypeManager = new SubtypeManager();
2997 _promoteManager = resolver.promoteManager;
2990 } 2998 }
2991 Object visitAssignmentExpression(AssignmentExpression node) { 2999 Object visitAssignmentExpression(AssignmentExpression node) {
2992 sc.Token operator = node.operator; 3000 sc.Token operator = node.operator;
2993 sc.TokenType operatorType = operator.type; 3001 sc.TokenType operatorType = operator.type;
2994 if (operatorType != sc.TokenType.EQ) { 3002 if (operatorType != sc.TokenType.EQ) {
2995 operatorType = operatorFromCompoundAssignment(operatorType); 3003 operatorType = operatorFromCompoundAssignment(operatorType);
2996 Expression leftHandSide = node.leftHandSide; 3004 Expression leftHandSide = node.leftHandSide;
2997 if (leftHandSide != null) { 3005 if (leftHandSide != null) {
2998 String methodName = operatorType.lexeme; 3006 String methodName = operatorType.lexeme;
2999 Type2 staticType = getStaticType(leftHandSide); 3007 Type2 staticType = getStaticType(leftHandSide);
3000 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName); 3008 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName);
3001 node.staticElement = staticMethod; 3009 node.staticElement = staticMethod;
3002 Type2 propagatedType = getPropagatedType(leftHandSide); 3010 Type2 propagatedType = getPropagatedType(leftHandSide);
3003 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName); 3011 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName);
3004 node.propagatedElement = propagatedMethod; 3012 node.propagatedElement = propagatedMethod;
3005 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3013 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod));
3006 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false; 3014 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3007 if (shouldReportMissingMember_propagated) { 3015 if (shouldReportMissingMember_propagated) {
3008 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) { 3016 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3009 shouldReportMissingMember_propagated = false; 3017 shouldReportMissingMember_propagated = false;
3010 } 3018 }
3011 } 3019 }
3012 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3020 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3013 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode; 3021 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode;
3014 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [ 3022 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3015 methodName, 3023 methodName,
3016 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3024 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3017 } 3025 }
3018 } 3026 }
3019 } 3027 }
3020 return null; 3028 return null;
3021 } 3029 }
3022 Object visitBinaryExpression(BinaryExpression node) { 3030 Object visitBinaryExpression(BinaryExpression node) {
3023 sc.Token operator = node.operator; 3031 sc.Token operator = node.operator;
3024 if (operator.isUserDefinableOperator) { 3032 if (operator.isUserDefinableOperator) {
3025 Expression leftOperand = node.leftOperand; 3033 Expression leftOperand = node.leftOperand;
3026 if (leftOperand != null) { 3034 if (leftOperand != null) {
3027 String methodName = operator.lexeme; 3035 String methodName = operator.lexeme;
3028 Type2 staticType = getStaticType(leftOperand); 3036 Type2 staticType = getStaticType(leftOperand);
3029 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName); 3037 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName);
3030 node.staticElement = staticMethod; 3038 node.staticElement = staticMethod;
3031 Type2 propagatedType = getPropagatedType(leftOperand); 3039 Type2 propagatedType = getPropagatedType(leftOperand);
3032 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName); 3040 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName);
3033 node.propagatedElement = propagatedMethod; 3041 node.propagatedElement = propagatedMethod;
3034 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3042 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod));
3035 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false; 3043 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3036 if (shouldReportMissingMember_propagated) { 3044 if (shouldReportMissingMember_propagated) {
3037 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) { 3045 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3038 shouldReportMissingMember_propagated = false; 3046 shouldReportMissingMember_propagated = false;
3039 } 3047 }
3040 } 3048 }
3041 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3049 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3042 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3050 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3043 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [ 3051 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3044 methodName, 3052 methodName,
3045 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3053 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3046 } 3054 }
3047 } 3055 }
3048 } 3056 }
3049 return null; 3057 return null;
3050 } 3058 }
3051 Object visitBreakStatement(BreakStatement node) { 3059 Object visitBreakStatement(BreakStatement node) {
3052 SimpleIdentifier labelNode = node.label; 3060 SimpleIdentifier labelNode = node.label;
3053 LabelElementImpl labelElement = lookupLabel(node, labelNode); 3061 LabelElementImpl labelElement = lookupLabel(node, labelNode);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
3453 node.propagatedElement = propagatedMethod; 3461 node.propagatedElement = propagatedMethod;
3454 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 3462 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod));
3455 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false; 3463 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
3456 if (shouldReportMissingMember_propagated) { 3464 if (shouldReportMissingMember_propagated) {
3457 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) { 3465 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
3458 shouldReportMissingMember_propagated = false; 3466 shouldReportMissingMember_propagated = false;
3459 } 3467 }
3460 } 3468 }
3461 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 3469 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
3462 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3470 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3463 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, er rorCode, node.operator, [ 3471 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingMem ber_static ? staticType.element : propagatedType.element, errorCode, node.operat or, [
3464 methodName, 3472 methodName,
3465 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]); 3473 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]);
3466 } 3474 }
3467 return null; 3475 return null;
3468 } 3476 }
3469 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 3477 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
3470 SimpleIdentifier prefix = node.prefix; 3478 SimpleIdentifier prefix = node.prefix;
3471 SimpleIdentifier identifier = node.identifier; 3479 SimpleIdentifier identifier = node.identifier;
3472 Element prefixElement = prefix.staticElement; 3480 Element prefixElement = prefix.staticElement;
3473 if (prefixElement is PrefixElement) { 3481 if (prefixElement is PrefixElement) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 node.propagatedElement = propagatedMethod; 3529 node.propagatedElement = propagatedMethod;
3522 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod)); 3530 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod));
3523 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false; 3531 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false;
3524 if (shouldReportMissingMember_propagated) { 3532 if (shouldReportMissingMember_propagated) {
3525 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) { 3533 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) {
3526 shouldReportMissingMember_propagated = false; 3534 shouldReportMissingMember_propagated = false;
3527 } 3535 }
3528 } 3536 }
3529 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) { 3537 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) {
3530 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3538 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3531 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, errorCode, operator, [ 3539 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, operator, [
3532 methodName, 3540 methodName,
3533 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 3541 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3534 } 3542 }
3535 } 3543 }
3536 return null; 3544 return null;
3537 } 3545 }
3538 Object visitPropertyAccess(PropertyAccess node) { 3546 Object visitPropertyAccess(PropertyAccess node) {
3539 Expression target = node.realTarget; 3547 Expression target = node.realTarget;
3540 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) { 3548 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) {
3541 return null; 3549 return null;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3603 Annotation annotation = node.parent as Annotation; 3611 Annotation annotation = node.parent as Annotation;
3604 resolveAnnotationElement(annotation, element, null); 3612 resolveAnnotationElement(annotation, element, null);
3605 } 3613 }
3606 return null; 3614 return null;
3607 } 3615 }
3608 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 3616 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
3609 ClassElement enclosingClass = _resolver.enclosingClass; 3617 ClassElement enclosingClass = _resolver.enclosingClass;
3610 if (enclosingClass == null) { 3618 if (enclosingClass == null) {
3611 return null; 3619 return null;
3612 } 3620 }
3613 ClassElement superclass = getSuperclass(enclosingClass); 3621 InterfaceType superType = enclosingClass.supertype;
3614 if (superclass == null) { 3622 if (superType == null) {
3615 return null; 3623 return null;
3616 } 3624 }
3617 SimpleIdentifier name = node.constructorName; 3625 SimpleIdentifier name = node.constructorName;
3618 ConstructorElement element; 3626 String superName = name != null ? name.name : null;
3619 if (name == null) { 3627 ConstructorElement element = superType.lookUpConstructor(superName, _resolve r.definingLibrary);
3620 element = superclass.unnamedConstructor;
3621 } else {
3622 element = superclass.getNamedConstructor(name.name);
3623 }
3624 if (element == null) { 3628 if (element == null) {
3625 if (name != null) { 3629 if (name != null) {
3626 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superclass.name, name]); 3630 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]);
3627 } else { 3631 } else {
3628 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superclass.name]); 3632 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]);
3629 } 3633 }
3630 return null; 3634 return null;
3631 } else { 3635 } else {
3632 if (element.isFactory) { 3636 if (element.isFactory) {
3633 _resolver.reportError5(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); 3637 _resolver.reportError5(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]);
3634 } 3638 }
3635 } 3639 }
3636 if (name != null) { 3640 if (name != null) {
3637 name.staticElement = element; 3641 name.staticElement = element;
3638 } 3642 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3766 if (shouldReportMissingMember_propagated) { 3770 if (shouldReportMissingMember_propagated) {
3767 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) { 3771 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
3768 shouldReportMissingMember_propagated = false; 3772 shouldReportMissingMember_propagated = false;
3769 } 3773 }
3770 } 3774 }
3771 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 3775 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
3772 sc.Token leftBracket = node.leftBracket; 3776 sc.Token leftBracket = node.leftBracket;
3773 sc.Token rightBracket = node.rightBracket; 3777 sc.Token rightBracket = node.rightBracket;
3774 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3778 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3775 if (leftBracket == null || rightBracket == null) { 3779 if (leftBracket == null || rightBracket == null) {
3776 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, e rrorCode, node, [ 3780 _resolver.reportErrorProxyConditionalAnalysisError(shouldReportMissingMe mber_static ? staticType.element : propagatedType.element, errorCode, node, [
3777 methodName, 3781 methodName,
3778 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 3782 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3779 } else { 3783 } else {
3780 int offset = leftBracket.offset; 3784 int offset = leftBracket.offset;
3781 int length = rightBracket.offset - offset + 1; 3785 int length = rightBracket.offset - offset + 1;
3782 _resolver.reportErrorProxyConditionalAnalysisError2(staticType.element, errorCode, offset, length, [ 3786 _resolver.reportErrorProxyConditionalAnalysisError2(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, offset, l ength, [
3783 methodName, 3787 methodName,
3784 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 3788 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3785 } 3789 }
3786 return true; 3790 return true;
3787 } 3791 }
3788 return false; 3792 return false;
3789 } 3793 }
3790 3794
3791 /** 3795 /**
3792 * Given a list of arguments and the element that will be invoked using those argument, compute 3796 * Given a list of arguments and the element that will be invoked using those argument, compute
(...skipping 18 matching lines...) Expand all
3811 Element functionElement = ((getterReturnType as FunctionType)).element ; 3815 Element functionElement = ((getterReturnType as FunctionType)).element ;
3812 if (functionElement is ExecutableElement) { 3816 if (functionElement is ExecutableElement) {
3813 return resolveArgumentsToParameters(false, argumentList, functionEle ment as ExecutableElement); 3817 return resolveArgumentsToParameters(false, argumentList, functionEle ment as ExecutableElement);
3814 } 3818 }
3815 } 3819 }
3816 } 3820 }
3817 } else if (element is ExecutableElement) { 3821 } else if (element is ExecutableElement) {
3818 return resolveArgumentsToParameters(false, argumentList, element as Execut ableElement); 3822 return resolveArgumentsToParameters(false, argumentList, element as Execut ableElement);
3819 } else if (element is VariableElement) { 3823 } else if (element is VariableElement) {
3820 VariableElement variable = element as VariableElement; 3824 VariableElement variable = element as VariableElement;
3821 Type2 type = variable.type; 3825 Type2 type = _promoteManager.getStaticType(variable);
3822 if (type is FunctionType) { 3826 if (type is FunctionType) {
3823 FunctionType functionType = type as FunctionType; 3827 FunctionType functionType = type as FunctionType;
3824 List<ParameterElement> parameters = functionType.parameters; 3828 List<ParameterElement> parameters = functionType.parameters;
3825 return resolveArgumentsToParameters2(false, argumentList, parameters); 3829 return resolveArgumentsToParameters2(false, argumentList, parameters);
3826 } else if (type is InterfaceType) { 3830 } else if (type is InterfaceType) {
3827 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(CALL_M ETHOD_NAME, _resolver.definingLibrary); 3831 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(CALL_M ETHOD_NAME, _resolver.definingLibrary);
3828 if (callMethod != null) { 3832 if (callMethod != null) {
3829 List<ParameterElement> parameters = callMethod.parameters; 3833 List<ParameterElement> parameters = callMethod.parameters;
3830 return resolveArgumentsToParameters2(false, argumentList, parameters); 3834 return resolveArgumentsToParameters2(false, argumentList, parameters);
3831 } 3835 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3929 return _resolver.typeProvider.bottomType; 3933 return _resolver.typeProvider.bottomType;
3930 } 3934 }
3931 Type2 staticType = resolveTypeParameter(expression.staticType); 3935 Type2 staticType = resolveTypeParameter(expression.staticType);
3932 if (staticType is FunctionType) { 3936 if (staticType is FunctionType) {
3933 staticType = _resolver.typeProvider.functionType; 3937 staticType = _resolver.typeProvider.functionType;
3934 } 3938 }
3935 return staticType; 3939 return staticType;
3936 } 3940 }
3937 3941
3938 /** 3942 /**
3939 * Return the element representing the superclass of the given class.
3940 *
3941 * @param targetClass the class whose superclass is to be returned
3942 * @return the element representing the superclass of the given class
3943 */
3944 ClassElement getSuperclass(ClassElement targetClass) {
3945 InterfaceType superType = targetClass.supertype;
3946 if (superType == null) {
3947 return null;
3948 }
3949 return superType.element;
3950 }
3951
3952 /**
3953 * Return `true` if the given type represents an object that could be invoked using the call 3943 * Return `true` if the given type represents an object that could be invoked using the call
3954 * operator '()'. 3944 * operator '()'.
3955 * 3945 *
3956 * @param type the type being tested 3946 * @param type the type being tested
3957 * @return `true` if the given type represents an object that could be invoked 3947 * @return `true` if the given type represents an object that could be invoked
3958 */ 3948 */
3959 bool isExecutableType(Type2 type) { 3949 bool isExecutableType(Type2 type) {
3960 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) { 3950 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) {
3961 return true; 3951 return true;
3962 } else if (type is InterfaceType) { 3952 } else if (type is InterfaceType) {
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
4668 ExecutableElement propagatedElement = resolveProperty(target, propagatedType , propertyName); 4658 ExecutableElement propagatedElement = resolveProperty(target, propagatedType , propertyName);
4669 propertyName.propagatedElement = propagatedElement; 4659 propertyName.propagatedElement = propagatedElement;
4670 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement)); 4660 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement));
4671 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false; 4661 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false;
4672 if (shouldReportMissingMember_propagated) { 4662 if (shouldReportMissingMember_propagated) {
4673 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) { 4663 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
4674 shouldReportMissingMember_propagated = false; 4664 shouldReportMissingMember_propagated = false;
4675 } 4665 }
4676 } 4666 }
4677 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 4667 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
4678 Element selectedElement = select(staticElement, propagatedElement); 4668 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element;
4679 bool isStaticProperty = isStatic(selectedElement); 4669 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt);
4680 if (propertyName.inSetterContext()) { 4670 if (propertyName.inSetterContext()) {
4681 if (isStaticProperty) { 4671 if (isStaticProperty) {
4682 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 4672 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
4683 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [ 4673 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagatedE nclosingElt, errorCode, propertyName, [
4684 propertyName.name, 4674 propertyName.name,
4685 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 4675 staticOrPropagatedEnclosingElt.displayName]);
4686 } else { 4676 } else {
4687 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 4677 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
4688 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [ 4678 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagatedE nclosingElt, errorCode, propertyName, [
4689 propertyName.name, 4679 propertyName.name,
4690 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 4680 staticOrPropagatedEnclosingElt.displayName]);
4691 } 4681 }
4692 } else if (propertyName.inGetterContext()) { 4682 } else if (propertyName.inGetterContext()) {
4693 if (isStaticProperty) { 4683 if (isStaticProperty) {
4694 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode; 4684 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode;
4695 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [ 4685 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagatedE nclosingElt, errorCode, propertyName, [
4696 propertyName.name, 4686 propertyName.name,
4697 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 4687 staticOrPropagatedEnclosingElt.displayName]);
4698 } else { 4688 } else {
4699 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode; 4689 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode;
4700 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [ 4690 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagatedE nclosingElt, errorCode, propertyName, [
4701 propertyName.name, 4691 propertyName.name,
4702 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 4692 staticOrPropagatedEnclosingElt.displayName]);
4703 } 4693 }
4704 } else { 4694 } else {
4705 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, S taticWarningCode.UNDEFINED_IDENTIFIER, propertyName, [propertyName.name]); 4695 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagatedEnc losingElt, StaticWarningCode.UNDEFINED_IDENTIFIER, propertyName, [propertyName.n ame]);
4706 } 4696 }
4707 } 4697 }
4708 } 4698 }
4709 4699
4710 /** 4700 /**
4711 * Resolve the given simple identifier if possible. Return the element to whic h it could be 4701 * Resolve the given simple identifier if possible. Return the element to whic h it could be
4712 * resolved, or `null` if it could not be resolved. This does not record the r esults of the 4702 * resolved, or `null` if it could not be resolved. This does not record the r esults of the
4713 * resolution. 4703 * resolution.
4714 * 4704 *
4715 * @param node the identifier to be resolved 4705 * @param node the identifier to be resolved
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
6439 * Resolve the identifiers and perform type analysis in the given library. 6429 * Resolve the identifiers and perform type analysis in the given library.
6440 * 6430 *
6441 * @param library the library to be resolved 6431 * @param library the library to be resolved
6442 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 6432 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
6443 * the library cannot be analyzed 6433 * the library cannot be analyzed
6444 */ 6434 */
6445 void resolveReferencesAndTypes2(Library library) { 6435 void resolveReferencesAndTypes2(Library library) {
6446 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art(); 6436 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
6447 try { 6437 try {
6448 for (Source source in library.compilationUnitSources) { 6438 for (Source source in library.compilationUnitSources) {
6439 CompilationUnit ast = library.getAST(source);
6440 ast.accept(new VariableResolverVisitor(library, source, _typeProvider));
6449 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider); 6441 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider);
6450 library.getAST(source).accept(visitor); 6442 ast.accept(visitor);
6451 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) { 6443 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) {
6452 if (conditionalCode.shouldIncludeErrorCode()) { 6444 if (conditionalCode.shouldIncludeErrorCode()) {
6453 visitor.reportError(conditionalCode.analysisError); 6445 visitor.reportError(conditionalCode.analysisError);
6454 } 6446 }
6455 } 6447 }
6456 } 6448 }
6457 } finally { 6449 } finally {
6458 timeCounter.stop(); 6450 timeCounter.stop();
6459 } 6451 }
6460 } 6452 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
6731 * current node is not contained in a function. 6723 * current node is not contained in a function.
6732 */ 6724 */
6733 ExecutableElement enclosingFunction = null; 6725 ExecutableElement enclosingFunction = null;
6734 6726
6735 /** 6727 /**
6736 * The object keeping track of which elements have had their types overridden. 6728 * The object keeping track of which elements have had their types overridden.
6737 */ 6729 */
6738 final TypeOverrideManager overrideManager = new TypeOverrideManager(); 6730 final TypeOverrideManager overrideManager = new TypeOverrideManager();
6739 6731
6740 /** 6732 /**
6733 * The object keeping track of which elements have had their types promoted.
6734 */
6735 final TypePromotionManager promoteManager = new TypePromotionManager();
6736
6737 /**
6741 * Proxy conditional error codes. 6738 * Proxy conditional error codes.
6742 */ 6739 */
6743 final List<ProxyConditionalAnalysisError> proxyConditionalAnalysisErrors = new List<ProxyConditionalAnalysisError>(); 6740 final List<ProxyConditionalAnalysisError> proxyConditionalAnalysisErrors = new List<ProxyConditionalAnalysisError>();
6744 6741
6745 /** 6742 /**
6746 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 6743 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
6747 * 6744 *
6748 * @param library the library containing the compilation unit being resolved 6745 * @param library the library containing the compilation unit being resolved
6749 * @param source the source representing the compilation unit being visited 6746 * @param source the source representing the compilation unit being visited
6750 * @param typeProvider the object used to access the types from the core libra ry 6747 * @param typeProvider the object used to access the types from the core libra ry
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6782 } 6779 }
6783 Object visitBinaryExpression(BinaryExpression node) { 6780 Object visitBinaryExpression(BinaryExpression node) {
6784 sc.TokenType operatorType = node.operator.type; 6781 sc.TokenType operatorType = node.operator.type;
6785 Expression leftOperand = node.leftOperand; 6782 Expression leftOperand = node.leftOperand;
6786 Expression rightOperand = node.rightOperand; 6783 Expression rightOperand = node.rightOperand;
6787 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) { 6784 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) {
6788 safelyVisit(leftOperand); 6785 safelyVisit(leftOperand);
6789 if (rightOperand != null) { 6786 if (rightOperand != null) {
6790 try { 6787 try {
6791 overrideManager.enterScope(); 6788 overrideManager.enterScope();
6789 promoteManager.enterScope();
6792 propagateTrueState(leftOperand); 6790 propagateTrueState(leftOperand);
6791 promoteTypes(leftOperand);
6792 clearTypePromotionsIfPotentiallyMutatedIn(leftOperand);
6793 clearTypePromotionsIfPotentiallyMutatedIn(rightOperand);
6794 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(rightOperan d);
6793 rightOperand.accept(this); 6795 rightOperand.accept(this);
6794 } finally { 6796 } finally {
6795 overrideManager.exitScope(); 6797 overrideManager.exitScope();
6798 promoteManager.exitScope();
6796 } 6799 }
6797 } 6800 }
6798 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) { 6801 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) {
6799 safelyVisit(leftOperand); 6802 safelyVisit(leftOperand);
6800 if (rightOperand != null) { 6803 if (rightOperand != null) {
6801 try { 6804 try {
6802 overrideManager.enterScope(); 6805 overrideManager.enterScope();
6803 propagateFalseState(leftOperand); 6806 propagateFalseState(leftOperand);
6804 rightOperand.accept(this); 6807 rightOperand.accept(this);
6805 } finally { 6808 } finally {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
6869 node.accept(_typeAnalyzer); 6872 node.accept(_typeAnalyzer);
6870 return null; 6873 return null;
6871 } 6874 }
6872 Object visitConditionalExpression(ConditionalExpression node) { 6875 Object visitConditionalExpression(ConditionalExpression node) {
6873 Expression condition = node.condition; 6876 Expression condition = node.condition;
6874 safelyVisit(condition); 6877 safelyVisit(condition);
6875 Expression thenExpression = node.thenExpression; 6878 Expression thenExpression = node.thenExpression;
6876 if (thenExpression != null) { 6879 if (thenExpression != null) {
6877 try { 6880 try {
6878 overrideManager.enterScope(); 6881 overrideManager.enterScope();
6882 promoteManager.enterScope();
6879 propagateTrueState(condition); 6883 propagateTrueState(condition);
6884 promoteTypes(condition);
6885 clearTypePromotionsIfPotentiallyMutatedIn(thenExpression);
6886 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(thenExpressio n);
6880 thenExpression.accept(this); 6887 thenExpression.accept(this);
6881 } finally { 6888 } finally {
6882 overrideManager.exitScope(); 6889 overrideManager.exitScope();
6890 promoteManager.exitScope();
6883 } 6891 }
6884 } 6892 }
6885 Expression elseExpression = node.elseExpression; 6893 Expression elseExpression = node.elseExpression;
6886 if (elseExpression != null) { 6894 if (elseExpression != null) {
6887 try { 6895 try {
6888 overrideManager.enterScope(); 6896 overrideManager.enterScope();
6889 propagateFalseState(condition); 6897 propagateFalseState(condition);
6890 elseExpression.accept(this); 6898 elseExpression.accept(this);
6891 } finally { 6899 } finally {
6892 overrideManager.exitScope(); 6900 overrideManager.exitScope();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
7011 } 7019 }
7012 Object visitHideCombinator(HideCombinator node) => null; 7020 Object visitHideCombinator(HideCombinator node) => null;
7013 Object visitIfStatement(IfStatement node) { 7021 Object visitIfStatement(IfStatement node) {
7014 Expression condition = node.condition; 7022 Expression condition = node.condition;
7015 safelyVisit(condition); 7023 safelyVisit(condition);
7016 Map<Element, Type2> thenOverrides = null; 7024 Map<Element, Type2> thenOverrides = null;
7017 Statement thenStatement = node.thenStatement; 7025 Statement thenStatement = node.thenStatement;
7018 if (thenStatement != null) { 7026 if (thenStatement != null) {
7019 try { 7027 try {
7020 overrideManager.enterScope(); 7028 overrideManager.enterScope();
7029 promoteManager.enterScope();
7021 propagateTrueState(condition); 7030 propagateTrueState(condition);
7031 promoteTypes(condition);
7032 clearTypePromotionsIfPotentiallyMutatedIn(thenStatement);
7033 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(thenStatement );
7022 visitStatementInScope(thenStatement); 7034 visitStatementInScope(thenStatement);
7023 } finally { 7035 } finally {
7024 thenOverrides = overrideManager.captureLocalOverrides(); 7036 thenOverrides = overrideManager.captureLocalOverrides();
7025 overrideManager.exitScope(); 7037 overrideManager.exitScope();
7038 promoteManager.exitScope();
7026 } 7039 }
7027 } 7040 }
7028 Map<Element, Type2> elseOverrides = null; 7041 Map<Element, Type2> elseOverrides = null;
7029 Statement elseStatement = node.elseStatement; 7042 Statement elseStatement = node.elseStatement;
7030 if (elseStatement != null) { 7043 if (elseStatement != null) {
7031 try { 7044 try {
7032 overrideManager.enterScope(); 7045 overrideManager.enterScope();
7033 propagateFalseState(condition); 7046 propagateFalseState(condition);
7034 visitStatementInScope(elseStatement); 7047 visitStatementInScope(elseStatement);
7035 } finally { 7048 } finally {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
7191 } else if (expression is PropertyAccess) { 7204 } else if (expression is PropertyAccess) {
7192 element = ((expression as PropertyAccess)).propertyName.staticElement; 7205 element = ((expression as PropertyAccess)).propertyName.staticElement;
7193 } 7206 }
7194 if (element is VariableElement) { 7207 if (element is VariableElement) {
7195 return element as VariableElement; 7208 return element as VariableElement;
7196 } 7209 }
7197 return null; 7210 return null;
7198 } 7211 }
7199 7212
7200 /** 7213 /**
7214 * Return the static element associated with the given expression whose type c an be promoted, or
7215 * `null` if there is no element whose type can be promoted.
7216 *
7217 * @param expression the expression with which the element is associated
7218 * @return the element associated with the given expression
7219 */
7220 VariableElement getPromotionStaticElement(Expression expression) {
7221 if (expression is! SimpleIdentifier) {
7222 return null;
7223 }
7224 SimpleIdentifier identifier = expression as SimpleIdentifier;
7225 Element element = identifier.staticElement;
7226 if (element is! VariableElement) {
7227 return null;
7228 }
7229 ElementKind kind = element.kind;
7230 if (identical(kind, ElementKind.LOCAL_VARIABLE)) {
7231 return element as VariableElement;
7232 }
7233 if (identical(kind, ElementKind.PARAMETER)) {
7234 return element as VariableElement;
7235 }
7236 return null;
7237 }
7238
7239 /**
7201 * If it is appropriate to do so, override the current type of the static and propagated elements 7240 * If it is appropriate to do so, override the current type of the static and propagated elements
7202 * associated with the given expression with the given type. Generally speakin g, it is appropriate 7241 * associated with the given expression with the given type. Generally speakin g, it is appropriate
7203 * if the given type is more specific than the current type. 7242 * if the given type is more specific than the current type.
7204 * 7243 *
7205 * @param expression the expression used to access the static and propagated e lements whose types 7244 * @param expression the expression used to access the static and propagated e lements whose types
7206 * might be overridden 7245 * might be overridden
7207 * @param potentialType the potential type of the elements 7246 * @param potentialType the potential type of the elements
7208 */ 7247 */
7209 void override(Expression expression, Type2 potentialType) { 7248 void override(Expression expression, Type2 potentialType) {
7210 VariableElement element = getOverridableStaticElement(expression); 7249 VariableElement element = getOverridableStaticElement(expression);
(...skipping 24 matching lines...) Expand all
7235 return; 7274 return;
7236 } 7275 }
7237 } 7276 }
7238 Type2 currentType = getBestType(element); 7277 Type2 currentType = getBestType(element);
7239 if (currentType == null || !currentType.isMoreSpecificThan(potentialType)) { 7278 if (currentType == null || !currentType.isMoreSpecificThan(potentialType)) {
7240 overrideManager.setType(element, potentialType); 7279 overrideManager.setType(element, potentialType);
7241 } 7280 }
7242 } 7281 }
7243 7282
7244 /** 7283 /**
7284 * If it is appropriate to do so, promotes the current type of the static elem ent associated with
7285 * the given expression with the given type. Generally speaking, it is appropr iate if the given
7286 * type is more specific than the current type.
7287 *
7288 * @param expression the expression used to access the static element whose ty pes might be
7289 * promoted
7290 * @param potentialType the potential type of the elements
7291 */
7292 void promote(Expression expression, Type2 potentialType) {
7293 VariableElement element = getPromotionStaticElement(expression);
7294 if (element != null) {
7295 Type2 type = expression.staticType;
7296 if (type == null || type.isDynamic) {
7297 return;
7298 }
7299 if (potentialType == null || potentialType.isDynamic) {
7300 return;
7301 }
7302 if (!potentialType.isMoreSpecificThan(type)) {
7303 return;
7304 }
7305 promoteManager.setType(element, potentialType);
7306 }
7307 }
7308
7309 /**
7245 * Report a conditional analysis error with the given error code and arguments . 7310 * Report a conditional analysis error with the given error code and arguments .
7246 * 7311 *
7247 * @param enclosingElement the enclosing element 7312 * @param enclosingElement the enclosing element
7248 * @param errorCode the error code of the error to be reported 7313 * @param errorCode the error code of the error to be reported
7249 * @param node the node specifying the location of the error 7314 * @param node the node specifying the location of the error
7250 * @param arguments the arguments to the error, used to compose the error mess age 7315 * @param arguments the arguments to the error, used to compose the error mess age
7251 */ 7316 */
7252 void reportErrorProxyConditionalAnalysisError(Element enclosingElement, ErrorC ode errorCode, ASTNode node, List<Object> arguments) { 7317 void reportErrorProxyConditionalAnalysisError(Element enclosingElement, ErrorC ode errorCode, ASTNode node, List<Object> arguments) {
7253 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, node.offset, node.length, errorCode, a rguments))); 7318 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, node.offset, node.length, errorCode, a rguments)));
7254 } 7319 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
7319 try { 7384 try {
7320 propagateTrueState(node.condition); 7385 propagateTrueState(node.condition);
7321 visitStatementInScope(node.body); 7386 visitStatementInScope(node.body);
7322 node.updaters.accept(this); 7387 node.updaters.accept(this);
7323 } finally { 7388 } finally {
7324 overrideManager.exitScope(); 7389 overrideManager.exitScope();
7325 } 7390 }
7326 } 7391 }
7327 7392
7328 /** 7393 /**
7394 * Checks each promoted variable in the current scope for compliance with the following
7395 * specification statement:
7396 *
7397 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t hen the variable
7398 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>.
7399 */
7400 void clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(ASTNode target ) {
7401 for (Element element in promoteManager.promotedElements) {
7402 if (((element as VariableElementImpl)).isPotentiallyMutated) {
7403 if (isVariableAccessedInClosure(element, target)) {
7404 promoteManager.setType(element, null);
7405 }
7406 }
7407 }
7408 }
7409
7410 /**
7411 * Checks each promoted variable in the current scope for compliance with the following
7412 * specification statement:
7413 *
7414 * <i>v</i> is not potentially mutated in <i>s<sub>1</sub></i> or within a clo sure.
7415 */
7416 void clearTypePromotionsIfPotentiallyMutatedIn(ASTNode target) {
7417 for (Element element in promoteManager.promotedElements) {
7418 if (isVariablePotentiallyMutatedIn(element, target)) {
7419 promoteManager.setType(element, null);
7420 }
7421 }
7422 }
7423
7424 /**
7329 * Return the best type information available for the given element. If the ty pe of the element 7425 * Return the best type information available for the given element. If the ty pe of the element
7330 * has been overridden, then return the overriding type. Otherwise, return the static type. 7426 * has been overridden, then return the overriding type. Otherwise, return the static type.
7331 * 7427 *
7332 * @param element the element for which type information is to be returned 7428 * @param element the element for which type information is to be returned
7333 * @return the best type information available for the given element 7429 * @return the best type information available for the given element
7334 */ 7430 */
7335 Type2 getBestType(Element element) { 7431 Type2 getBestType(Element element) {
7336 Type2 bestType = overrideManager.getType(element); 7432 Type2 bestType = overrideManager.getType(element);
7337 if (bestType == null) { 7433 if (bestType == null) {
7338 if (element is LocalVariableElement) { 7434 if (element is LocalVariableElement) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7446 int size = statements.length; 7542 int size = statements.length;
7447 if (size == 0) { 7543 if (size == 0) {
7448 return false; 7544 return false;
7449 } 7545 }
7450 return isAbruptTermination2(statements[size - 1]); 7546 return isAbruptTermination2(statements[size - 1]);
7451 } 7547 }
7452 return false; 7548 return false;
7453 } 7549 }
7454 7550
7455 /** 7551 /**
7552 * Return `true` if the given variable is accessed within a closure in the giv en
7553 * [ASTNode] and also mutated somewhere in variable scope. This information is only
7554 * available for local variables (including parameters).
7555 *
7556 * @param variable the variable to check
7557 * @param target the [ASTNode] to check within
7558 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode
7559 */
7560 bool isVariableAccessedInClosure(Element variable, ASTNode target) {
7561 List<bool> result = [false];
7562 target.accept(new RecursiveASTVisitor_7(result, variable));
7563 return result[0];
7564 }
7565
7566 /**
7567 * Return `true` if the given variable is potentially mutated somewhere in the given
7568 * [ASTNode]. This information is only available for local variables (includin g parameters).
7569 *
7570 * @param variable the variable to check
7571 * @param target the [ASTNode] to check within
7572 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode
7573 */
7574 bool isVariablePotentiallyMutatedIn(Element variable, ASTNode target) {
7575 List<bool> result = [false];
7576 target.accept(new RecursiveASTVisitor_8(result, variable));
7577 return result[0];
7578 }
7579
7580 /**
7581 * Promotes type information using given condition.
7582 */
7583 void promoteTypes(Expression condition) {
7584 if (condition is BinaryExpression) {
7585 BinaryExpression binary = condition as BinaryExpression;
7586 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) {
7587 Expression left = binary.leftOperand;
7588 Expression right = binary.rightOperand;
7589 promoteTypes(left);
7590 promoteTypes(right);
7591 clearTypePromotionsIfPotentiallyMutatedIn(right);
7592 }
7593 } else if (condition is IsExpression) {
7594 IsExpression is2 = condition as IsExpression;
7595 if (is2.notOperator == null) {
7596 promote(is2.expression, is2.type.type);
7597 }
7598 } else if (condition is ParenthesizedExpression) {
7599 promoteTypes(((condition as ParenthesizedExpression)).expression);
7600 }
7601 }
7602
7603 /**
7456 * Propagate any type information that results from knowing that the given con dition will have 7604 * Propagate any type information that results from knowing that the given con dition will have
7457 * been evaluated to 'false'. 7605 * been evaluated to 'false'.
7458 * 7606 *
7459 * @param condition the condition that will have evaluated to 'false' 7607 * @param condition the condition that will have evaluated to 'false'
7460 */ 7608 */
7461 void propagateFalseState(Expression condition) { 7609 void propagateFalseState(Expression condition) {
7462 if (condition is BinaryExpression) { 7610 if (condition is BinaryExpression) {
7463 BinaryExpression binary = condition as BinaryExpression; 7611 BinaryExpression binary = condition as BinaryExpression;
7464 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { 7612 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) {
7465 propagateFalseState(binary.leftOperand); 7613 propagateFalseState(binary.leftOperand);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
7532 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; 7680 set elementResolver_J2DAccessor(__v) => _elementResolver = __v;
7533 get labelScope_J2DAccessor => labelScope; 7681 get labelScope_J2DAccessor => labelScope;
7534 set labelScope_J2DAccessor(__v) => labelScope = __v; 7682 set labelScope_J2DAccessor(__v) => labelScope = __v;
7535 get nameScope_J2DAccessor => nameScope; 7683 get nameScope_J2DAccessor => nameScope;
7536 set nameScope_J2DAccessor(__v) => nameScope = __v; 7684 set nameScope_J2DAccessor(__v) => nameScope = __v;
7537 get typeAnalyzer_J2DAccessor => _typeAnalyzer; 7685 get typeAnalyzer_J2DAccessor => _typeAnalyzer;
7538 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; 7686 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v;
7539 get enclosingClass_J2DAccessor => enclosingClass; 7687 get enclosingClass_J2DAccessor => enclosingClass;
7540 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v; 7688 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v;
7541 } 7689 }
7690 class RecursiveASTVisitor_7 extends RecursiveASTVisitor<Object> {
7691 List<bool> result;
7692 Element variable;
7693 RecursiveASTVisitor_7(this.result, this.variable) : super();
7694 bool _inClosure = false;
7695 Object visitFunctionExpression(FunctionExpression node) {
7696 bool inClosure = this._inClosure;
7697 try {
7698 this._inClosure = true;
7699 return super.visitFunctionExpression(node);
7700 } finally {
7701 this._inClosure = inClosure;
7702 }
7703 }
7704 Object visitSimpleIdentifier(SimpleIdentifier node) {
7705 if (result[0]) {
7706 return null;
7707 }
7708 if (_inClosure && identical(node.staticElement, variable)) {
7709 result[0] = javaBooleanOr(result[0], true);
7710 }
7711 return null;
7712 }
7713 }
7714 class RecursiveASTVisitor_8 extends RecursiveASTVisitor<Object> {
7715 List<bool> result;
7716 Element variable;
7717 RecursiveASTVisitor_8(this.result, this.variable) : super();
7718 Object visitSimpleIdentifier(SimpleIdentifier node) {
7719 if (result[0]) {
7720 return null;
7721 }
7722 if (identical(node.staticElement, variable)) {
7723 if (node.inSetterContext()) {
7724 result[0] = javaBooleanOr(result[0], true);
7725 }
7726 }
7727 return null;
7728 }
7729 }
7542 /** 7730 /**
7543 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is 7731 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is
7544 * being visited. 7732 * being visited.
7545 * 7733 *
7546 * @coverage dart.engine.resolver 7734 * @coverage dart.engine.resolver
7547 */ 7735 */
7548 abstract class ScopedVisitor extends UnifyingASTVisitor<Object> { 7736 abstract class ScopedVisitor extends UnifyingASTVisitor<Object> {
7549 7737
7550 /** 7738 /**
7551 * The element for the library containing the compilation unit being visited. 7739 * The element for the library containing the compilation unit being visited.
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
8099 * nodes are not within a class. 8287 * nodes are not within a class.
8100 */ 8288 */
8101 InterfaceType _thisType; 8289 InterfaceType _thisType;
8102 8290
8103 /** 8291 /**
8104 * The object keeping track of which elements have had their types overridden. 8292 * The object keeping track of which elements have had their types overridden.
8105 */ 8293 */
8106 TypeOverrideManager _overrideManager; 8294 TypeOverrideManager _overrideManager;
8107 8295
8108 /** 8296 /**
8297 * The object keeping track of which elements have had their types promoted.
8298 */
8299 TypePromotionManager _promoteManager;
8300
8301 /**
8109 * A table mapping [ExecutableElement]s to their propagated return types. 8302 * A table mapping [ExecutableElement]s to their propagated return types.
8110 */ 8303 */
8111 Map<ExecutableElement, Type2> _propagatedReturnTypes = new Map<ExecutableEleme nt, Type2>(); 8304 Map<ExecutableElement, Type2> _propagatedReturnTypes = new Map<ExecutableEleme nt, Type2>();
8112 8305
8113 /** 8306 /**
8114 * A table mapping HTML tag names to the names of the classes (in 'dart:html') that implement 8307 * A table mapping HTML tag names to the names of the classes (in 'dart:html') that implement
8115 * those tags. 8308 * those tags.
8116 */ 8309 */
8117 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa p(); 8310 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa p();
8118 8311
8119 /** 8312 /**
8120 * Initialize a newly created type analyzer. 8313 * Initialize a newly created type analyzer.
8121 * 8314 *
8122 * @param resolver the resolver driving this participant 8315 * @param resolver the resolver driving this participant
8123 */ 8316 */
8124 StaticTypeAnalyzer(ResolverVisitor resolver) { 8317 StaticTypeAnalyzer(ResolverVisitor resolver) {
8125 this._resolver = resolver; 8318 this._resolver = resolver;
8126 _typeProvider = resolver.typeProvider; 8319 _typeProvider = resolver.typeProvider;
8127 _dynamicType = _typeProvider.dynamicType; 8320 _dynamicType = _typeProvider.dynamicType;
8128 _overrideManager = resolver.overrideManager; 8321 _overrideManager = resolver.overrideManager;
8322 _promoteManager = resolver.promoteManager;
8129 } 8323 }
8130 8324
8131 /** 8325 /**
8132 * Set the type of the class being analyzed to the given type. 8326 * Set the type of the class being analyzed to the given type.
8133 * 8327 *
8134 * @param thisType the type representing the class containing the nodes being analyzed 8328 * @param thisType the type representing the class containing the nodes being analyzed
8135 */ 8329 */
8136 void set thisType(InterfaceType thisType) { 8330 void set thisType(InterfaceType thisType) {
8137 this._thisType = thisType; 8331 this._thisType = thisType;
8138 } 8332 }
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
9065 staticType = ((element as FunctionTypeAliasElement)).type; 9259 staticType = ((element as FunctionTypeAliasElement)).type;
9066 } else if (element is MethodElement) { 9260 } else if (element is MethodElement) {
9067 staticType = ((element as MethodElement)).type; 9261 staticType = ((element as MethodElement)).type;
9068 } else if (element is PropertyAccessorElement) { 9262 } else if (element is PropertyAccessorElement) {
9069 staticType = getType(element as PropertyAccessorElement, null); 9263 staticType = getType(element as PropertyAccessorElement, null);
9070 } else if (element is ExecutableElement) { 9264 } else if (element is ExecutableElement) {
9071 staticType = ((element as ExecutableElement)).type; 9265 staticType = ((element as ExecutableElement)).type;
9072 } else if (element is TypeParameterElement) { 9266 } else if (element is TypeParameterElement) {
9073 staticType = ((element as TypeParameterElement)).type; 9267 staticType = ((element as TypeParameterElement)).type;
9074 } else if (element is VariableElement) { 9268 } else if (element is VariableElement) {
9075 staticType = ((element as VariableElement)).type; 9269 VariableElement variable = element as VariableElement;
9270 staticType = _promoteManager.getStaticType(variable);
9076 } else if (element is PrefixElement) { 9271 } else if (element is PrefixElement) {
9077 return null; 9272 return null;
9078 } else { 9273 } else {
9079 staticType = _dynamicType; 9274 staticType = _dynamicType;
9080 } 9275 }
9081 recordStaticType(node, staticType); 9276 recordStaticType(node, staticType);
9082 Type2 propagatedType = _overrideManager.getType(element); 9277 Type2 propagatedType = _overrideManager.getType(element);
9083 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 9278 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
9084 recordPropagatedType2(node, propagatedType); 9279 recordPropagatedType2(node, propagatedType);
9085 } 9280 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
9188 * @param body the boy of the function whose propagated return type is to be c omputed 9383 * @param body the boy of the function whose propagated return type is to be c omputed
9189 * @return the propagated return type that was computed 9384 * @return the propagated return type that was computed
9190 */ 9385 */
9191 Type2 computePropagatedReturnType2(FunctionBody body) { 9386 Type2 computePropagatedReturnType2(FunctionBody body) {
9192 if (body is ExpressionFunctionBody) { 9387 if (body is ExpressionFunctionBody) {
9193 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody; 9388 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody;
9194 return expressionBody.expression.bestType; 9389 return expressionBody.expression.bestType;
9195 } 9390 }
9196 if (body is BlockFunctionBody) { 9391 if (body is BlockFunctionBody) {
9197 List<Type2> result = [null]; 9392 List<Type2> result = [null];
9198 body.accept(new GeneralizingASTVisitor_7(result)); 9393 body.accept(new GeneralizingASTVisitor_9(result));
9199 return result[0]; 9394 return result[0];
9200 } 9395 }
9201 return null; 9396 return null;
9202 } 9397 }
9203 9398
9204 /** 9399 /**
9205 * Compute the static return type of the method or function represented by the given element. 9400 * Compute the static return type of the method or function represented by the given element.
9206 * 9401 *
9207 * @param element the element representing the method or function invoked by t he given node 9402 * @param element the element representing the method or function invoked by t he given node
9208 * @return the static return type that was computed 9403 * @return the static return type that was computed
(...skipping 19 matching lines...) Expand all
9228 if (returnType != null) { 9423 if (returnType != null) {
9229 return returnType; 9424 return returnType;
9230 } 9425 }
9231 } 9426 }
9232 } else if (element is ExecutableElement) { 9427 } else if (element is ExecutableElement) {
9233 FunctionType type = ((element as ExecutableElement)).type; 9428 FunctionType type = ((element as ExecutableElement)).type;
9234 if (type != null) { 9429 if (type != null) {
9235 return type.returnType; 9430 return type.returnType;
9236 } 9431 }
9237 } else if (element is VariableElement) { 9432 } else if (element is VariableElement) {
9238 Type2 variableType = ((element as VariableElement)).type; 9433 VariableElement variable = element as VariableElement;
9434 Type2 variableType = _promoteManager.getStaticType(variable);
9239 if (variableType is FunctionType) { 9435 if (variableType is FunctionType) {
9240 return ((variableType as FunctionType)).returnType; 9436 return ((variableType as FunctionType)).returnType;
9241 } 9437 }
9242 } 9438 }
9243 return _dynamicType; 9439 return _dynamicType;
9244 } 9440 }
9245 9441
9246 /** 9442 /**
9247 * Given a function declaration, compute the return static type of the functio n. The return type 9443 * Given a function declaration, compute the return static type of the functio n. The return type
9248 * of functions with a block body is `dynamicType`, with an expression body it is the type 9444 * of functions with a block body is `dynamicType`, with an expression body it is the type
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
9547 if (getStaticType(node.rightOperand) == intType) { 9743 if (getStaticType(node.rightOperand) == intType) {
9548 staticType = intType; 9744 staticType = intType;
9549 } 9745 }
9550 } 9746 }
9551 } 9747 }
9552 return staticType; 9748 return staticType;
9553 } 9749 }
9554 get thisType_J2DAccessor => _thisType; 9750 get thisType_J2DAccessor => _thisType;
9555 set thisType_J2DAccessor(__v) => _thisType = __v; 9751 set thisType_J2DAccessor(__v) => _thisType = __v;
9556 } 9752 }
9557 class GeneralizingASTVisitor_7 extends GeneralizingASTVisitor<Object> { 9753 class GeneralizingASTVisitor_9 extends GeneralizingASTVisitor<Object> {
9558 List<Type2> result; 9754 List<Type2> result;
9559 GeneralizingASTVisitor_7(this.result) : super(); 9755 GeneralizingASTVisitor_9(this.result) : super();
9560 Object visitExpression(Expression node) => null; 9756 Object visitExpression(Expression node) => null;
9561 Object visitReturnStatement(ReturnStatement node) { 9757 Object visitReturnStatement(ReturnStatement node) {
9562 Type2 type; 9758 Type2 type;
9563 Expression expression = node.expression; 9759 Expression expression = node.expression;
9564 if (expression != null) { 9760 if (expression != null) {
9565 type = expression.bestType; 9761 type = expression.bestType;
9566 } else { 9762 } else {
9567 type = BottomTypeImpl.instance; 9763 type = BottomTypeImpl.instance;
9568 } 9764 }
9569 if (result[0] == null) { 9765 if (result[0] == null) {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
9908 * Set the overridden type of the given element to the given type 10104 * Set the overridden type of the given element to the given type
9909 * 10105 *
9910 * @param element the element whose type might have been overridden 10106 * @param element the element whose type might have been overridden
9911 * @param type the overridden type of the given element 10107 * @param type the overridden type of the given element
9912 */ 10108 */
9913 void setType(Element element, Type2 type) { 10109 void setType(Element element, Type2 type) {
9914 _overridenTypes[element] = type; 10110 _overridenTypes[element] = type;
9915 } 10111 }
9916 } 10112 }
9917 /** 10113 /**
10114 * Instances of the class `TypePromotionManager` manage the ability to promote t ypes of local
10115 * variables and formal parameters from their declared types based on control fl ow.
10116 */
10117 class TypePromotionManager {
10118
10119 /**
10120 * The current promotion scope, or `null` if no scope has been entered.
10121 */
10122 TypePromotionManager_TypePromoteScope _currentScope;
10123
10124 /**
10125 * Enter a new promotions scope.
10126 */
10127 void enterScope() {
10128 _currentScope = new TypePromotionManager_TypePromoteScope(_currentScope);
10129 }
10130
10131 /**
10132 * Exit the current promotion scope.
10133 */
10134 void exitScope() {
10135 if (_currentScope == null) {
10136 throw new IllegalStateException("No scope to exit");
10137 }
10138 _currentScope = _currentScope._outerScope;
10139 }
10140
10141 /**
10142 * Returns the elements with promoted types.
10143 */
10144 Iterable<Element> get promotedElements => _currentScope.promotedElements;
10145
10146 /**
10147 * Returns static type of the given variable - declared or promoted.
10148 *
10149 * @return the static type of the given variable - declared or promoted
10150 */
10151 Type2 getStaticType(VariableElement variable) {
10152 Type2 staticType = getType(variable);
10153 if (staticType == null) {
10154 staticType = variable.type;
10155 }
10156 return staticType;
10157 }
10158
10159 /**
10160 * Return the promoted type of the given element, or `null` if the type of the element has
10161 * not been promoted.
10162 *
10163 * @param element the element whose type might have been promoted
10164 * @return the promoted type of the given element
10165 */
10166 Type2 getType(Element element) {
10167 if (_currentScope == null) {
10168 return null;
10169 }
10170 return _currentScope.getType(element);
10171 }
10172
10173 /**
10174 * Set the promoted type of the given element to the given type.
10175 *
10176 * @param element the element whose type might have been promoted
10177 * @param type the promoted type of the given element
10178 */
10179 void setType(Element element, Type2 type) {
10180 if (_currentScope == null) {
10181 throw new IllegalStateException("Cannot promote without a scope");
10182 }
10183 _currentScope.setType(element, type);
10184 }
10185 }
10186 /**
10187 * Instances of the class `TypePromoteScope` represent a scope in which the type s of
10188 * elements can be promoted.
10189 */
10190 class TypePromotionManager_TypePromoteScope {
10191
10192 /**
10193 * The outer scope in which types might be promoter.
10194 */
10195 TypePromotionManager_TypePromoteScope _outerScope;
10196
10197 /**
10198 * A table mapping elements to the promoted type of that element.
10199 */
10200 Map<Element, Type2> _promotedTypes = new Map<Element, Type2>();
10201
10202 /**
10203 * Initialize a newly created scope to be an empty child of the given scope.
10204 *
10205 * @param outerScope the outer scope in which types might be promoted
10206 */
10207 TypePromotionManager_TypePromoteScope(TypePromotionManager_TypePromoteScope ou terScope) {
10208 this._outerScope = outerScope;
10209 }
10210
10211 /**
10212 * Returns the elements with promoted types.
10213 */
10214 Iterable<Element> get promotedElements => _promotedTypes.keys.toSet();
10215
10216 /**
10217 * Return the promoted type of the given element, or `null` if the type of the element has
10218 * not been promoted.
10219 *
10220 * @param element the element whose type might have been promoted
10221 * @return the promoted type of the given element
10222 */
10223 Type2 getType(Element element) {
10224 Type2 type = _promotedTypes[element];
10225 if (type == null && element is PropertyAccessorElement) {
10226 type = _promotedTypes[((element as PropertyAccessorElement)).variable];
10227 }
10228 if (type != null) {
10229 return type;
10230 } else if (_outerScope != null) {
10231 return _outerScope.getType(element);
10232 }
10233 return null;
10234 }
10235
10236 /**
10237 * Set the promoted type of the given element to the given type.
10238 *
10239 * @param element the element whose type might have been promoted
10240 * @param type the promoted type of the given element
10241 */
10242 void setType(Element element, Type2 type) {
10243 _promotedTypes[element] = type;
10244 }
10245 }
10246 /**
9918 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types 10247 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types
9919 * defined by the language. 10248 * defined by the language.
9920 * 10249 *
9921 * @coverage dart.engine.resolver 10250 * @coverage dart.engine.resolver
9922 */ 10251 */
9923 abstract class TypeProvider { 10252 abstract class TypeProvider {
9924 10253
9925 /** 10254 /**
9926 * Return the type representing the built-in type 'Null'. 10255 * Return the type representing the built-in type 'Null'.
9927 * 10256 *
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
10244 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) { 10573 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) {
10245 _dynamicType = typeProvider.dynamicType; 10574 _dynamicType = typeProvider.dynamicType;
10246 } 10575 }
10247 Object visitCatchClause(CatchClause node) { 10576 Object visitCatchClause(CatchClause node) {
10248 super.visitCatchClause(node); 10577 super.visitCatchClause(node);
10249 SimpleIdentifier exception = node.exceptionParameter; 10578 SimpleIdentifier exception = node.exceptionParameter;
10250 if (exception != null) { 10579 if (exception != null) {
10251 TypeName exceptionTypeName = node.exceptionType; 10580 TypeName exceptionTypeName = node.exceptionType;
10252 Type2 exceptionType; 10581 Type2 exceptionType;
10253 if (exceptionTypeName == null) { 10582 if (exceptionTypeName == null) {
10254 exceptionType = typeProvider.objectType; 10583 exceptionType = typeProvider.dynamicType;
10255 } else { 10584 } else {
10256 exceptionType = getType3(exceptionTypeName); 10585 exceptionType = getType3(exceptionTypeName);
10257 } 10586 }
10258 recordType(exception, exceptionType); 10587 recordType(exception, exceptionType);
10259 Element element = exception.staticElement; 10588 Element element = exception.staticElement;
10260 if (element is VariableElementImpl) { 10589 if (element is VariableElementImpl) {
10261 ((element as VariableElementImpl)).type = exceptionType; 10590 ((element as VariableElementImpl)).type = exceptionType;
10262 } else { 10591 } else {
10263 } 10592 }
10264 } 10593 }
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
11026 aliasElement.typeParameters = alias.typeParameters; 11355 aliasElement.typeParameters = alias.typeParameters;
11027 type.typeArguments = alias.type.typeArguments; 11356 type.typeArguments = alias.type.typeArguments;
11028 } else { 11357 } else {
11029 type.typeArguments = TypeImpl.EMPTY_ARRAY; 11358 type.typeArguments = TypeImpl.EMPTY_ARRAY;
11030 } 11359 }
11031 } 11360 }
11032 element.type = type; 11361 element.type = type;
11033 } 11362 }
11034 } 11363 }
11035 /** 11364 /**
11365 * Instances of the class `VariableResolverVisitor` are used to resolve
11366 * [SimpleIdentifier]s to local variables and formal parameters.
11367 *
11368 * @coverage dart.engine.resolver
11369 */
11370 class VariableResolverVisitor extends ScopedVisitor {
11371
11372 /**
11373 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
11374 *
11375 * @param library the library containing the compilation unit being resolved
11376 * @param source the source representing the compilation unit being visited
11377 * @param typeProvider the object used to access the types from the core libra ry
11378 */
11379 VariableResolverVisitor(Library library, Source source, TypeProvider typeProvi der) : super.con1(library, source, typeProvider);
11380 Object visitSimpleIdentifier(SimpleIdentifier node) {
11381 if (node.staticElement != null) {
11382 return null;
11383 }
11384 ASTNode parent = node.parent;
11385 if (parent is PrefixedIdentifier && identical(((parent as PrefixedIdentifier )).identifier, node)) {
11386 return null;
11387 }
11388 if (parent is PropertyAccess && identical(((parent as PropertyAccess)).prope rtyName, node)) {
11389 return null;
11390 }
11391 if (parent is MethodInvocation && identical(((parent as MethodInvocation)).m ethodName, node)) {
11392 return null;
11393 }
11394 if (parent is ConstructorName) {
11395 return null;
11396 }
11397 if (parent is Label) {
11398 return null;
11399 }
11400 Element element = nameScope.lookup(node, definingLibrary);
11401 if (element is! VariableElement) {
11402 return null;
11403 }
11404 ElementKind kind = element.kind;
11405 if (identical(kind, ElementKind.LOCAL_VARIABLE)) {
11406 node.staticElement = element;
11407 if (node.inSetterContext()) {
11408 ((element as LocalVariableElementImpl)).markPotentiallyMutated();
11409 }
11410 } else if (identical(kind, ElementKind.PARAMETER)) {
11411 node.staticElement = element;
11412 if (node.inSetterContext()) {
11413 ((element as ParameterElementImpl)).markPotentiallyMutated();
11414 }
11415 }
11416 return null;
11417 }
11418 }
11419 /**
11036 * Instances of the class `ClassScope` implement the scope defined by a class. 11420 * Instances of the class `ClassScope` implement the scope defined by a class.
11037 * 11421 *
11038 * @coverage dart.engine.resolver 11422 * @coverage dart.engine.resolver
11039 */ 11423 */
11040 class ClassScope extends EnclosedScope { 11424 class ClassScope extends EnclosedScope {
11041 11425
11042 /** 11426 /**
11043 * Initialize a newly created scope enclosed within another scope. 11427 * Initialize a newly created scope enclosed within another scope.
11044 * 11428 *
11045 * @param enclosingScope the scope in which this scope is lexically enclosed 11429 * @param enclosingScope the scope in which this scope is lexically enclosed
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
11130 javaSetAdd(_hiddenNames, name); 11514 javaSetAdd(_hiddenNames, name);
11131 } 11515 }
11132 } 11516 }
11133 } 11517 }
11134 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) { 11518 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) {
11135 Element element = localLookup(name, referencingLibrary); 11519 Element element = localLookup(name, referencingLibrary);
11136 if (element != null) { 11520 if (element != null) {
11137 return element; 11521 return element;
11138 } 11522 }
11139 if (_hiddenNames.contains(name)) { 11523 if (_hiddenNames.contains(name)) {
11140 return null; 11524 errorListener.onError(new AnalysisError.con2(source, identifier.offset, id entifier.length, CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, []));
11141 } 11525 }
11142 return enclosingScope.lookup3(identifier, name, referencingLibrary); 11526 return enclosingScope.lookup3(identifier, name, referencingLibrary);
11143 } 11527 }
11144 } 11528 }
11145 /** 11529 /**
11146 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 11530 * Instances of the class `FunctionScope` implement the scope defined by a funct ion.
11147 * 11531 *
11148 * @coverage dart.engine.resolver 11532 * @coverage dart.engine.resolver
11149 */ 11533 */
11150 class FunctionScope extends EnclosedScope { 11534 class FunctionScope extends EnclosedScope {
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
12233 } 12617 }
12234 12618
12235 /** 12619 /**
12236 * Validates that the given expression is a compile time constant. 12620 * Validates that the given expression is a compile time constant.
12237 * 12621 *
12238 * @param parameterElements the elements of parameters of constant constructor , they are 12622 * @param parameterElements the elements of parameters of constant constructor , they are
12239 * considered as a valid potentially constant expressions 12623 * considered as a valid potentially constant expressions
12240 * @param expression the expression to validate 12624 * @param expression the expression to validate
12241 */ 12625 */
12242 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) { 12626 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) {
12243 EvaluationResultImpl result = expression.accept(new ConstantVisitor_11(this, parameterElements)); 12627 EvaluationResultImpl result = expression.accept(new ConstantVisitor_13(this, parameterElements));
12244 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ; 12628 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ;
12245 } 12629 }
12246 12630
12247 /** 12631 /**
12248 * Validates that all of the arguments of a constructor initializer are compil e time constants. 12632 * Validates that all of the arguments of a constructor initializer are compil e time constants.
12249 * 12633 *
12250 * @param parameterElements the elements of parameters of constant constructor , they are 12634 * @param parameterElements the elements of parameters of constant constructor , they are
12251 * considered as a valid potentially constant expressions 12635 * considered as a valid potentially constant expressions
12252 * @param argumentList the argument list to validate 12636 * @param argumentList the argument list to validate
12253 */ 12637 */
(...skipping 24 matching lines...) Expand all
12278 RedirectingConstructorInvocation invocation = initializer as Redirecting ConstructorInvocation; 12662 RedirectingConstructorInvocation invocation = initializer as Redirecting ConstructorInvocation;
12279 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 12663 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
12280 } 12664 }
12281 if (initializer is SuperConstructorInvocation) { 12665 if (initializer is SuperConstructorInvocation) {
12282 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation; 12666 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation;
12283 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 12667 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
12284 } 12668 }
12285 } 12669 }
12286 } 12670 }
12287 } 12671 }
12288 class ConstantVisitor_11 extends ConstantVisitor { 12672 class ConstantVisitor_13 extends ConstantVisitor {
12289 final ConstantVerifier ConstantVerifier_this; 12673 final ConstantVerifier ConstantVerifier_this;
12290 List<ParameterElement> parameterElements; 12674 List<ParameterElement> parameterElements;
12291 ConstantVisitor_11(this.ConstantVerifier_this, this.parameterElements) : super (); 12675 ConstantVisitor_13(this.ConstantVerifier_this, this.parameterElements) : super ();
12292 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { 12676 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
12293 Element element = node.staticElement; 12677 Element element = node.staticElement;
12294 for (ParameterElement parameterElement in parameterElements) { 12678 for (ParameterElement parameterElement in parameterElements) {
12295 if (identical(parameterElement, element) && parameterElement != null) { 12679 if (identical(parameterElement, element) && parameterElement != null) {
12296 Type2 type = parameterElement.type; 12680 Type2 type = parameterElement.type;
12297 if (type != null) { 12681 if (type != null) {
12298 if (type.isDynamic) { 12682 if (type.isDynamic) {
12299 return ValidResult.RESULT_DYNAMIC; 12683 return ValidResult.RESULT_DYNAMIC;
12300 } 12684 }
12301 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { 12685 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
12452 */ 12836 */
12453 ClassElement _enclosingClass; 12837 ClassElement _enclosingClass;
12454 12838
12455 /** 12839 /**
12456 * The method or function that we are currently visiting, or `null` if we are not inside a 12840 * The method or function that we are currently visiting, or `null` if we are not inside a
12457 * method or function. 12841 * method or function.
12458 */ 12842 */
12459 ExecutableElement _enclosingFunction; 12843 ExecutableElement _enclosingFunction;
12460 12844
12461 /** 12845 /**
12846 * The number of return statements found in the method or function that we are currently visiting
12847 * that have a return value.
12848 */
12849 int _returnWithCount = 0;
12850
12851 /**
12852 * The number of return statements found in the method or function that we are currently visiting
12853 * that do not have a return value.
12854 */
12855 int _returnWithoutCount = 0;
12856
12857 /**
12462 * This map is initialized when visiting the contents of a class declaration. If the visitor is 12858 * This map is initialized when visiting the contents of a class declaration. If the visitor is
12463 * not in an enclosing class declaration, then the map is set to `null`. 12859 * not in an enclosing class declaration, then the map is set to `null`.
12464 * 12860 *
12465 * When set the map maps the set of [FieldElement]s in the class to an 12861 * When set the map maps the set of [FieldElement]s in the class to an
12466 * [INIT_STATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*< /code> 12862 * [INIT_STATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*< /code>
12467 * methods, specifically [checkForAllFinalInitializedErrorCodes], 12863 * methods, specifically [checkForAllFinalInitializedErrorCodes],
12468 * can make a copy of the map to compute error code states. <code>checkFor*</c ode> methods should 12864 * can make a copy of the map to compute error code states. <code>checkFor*</c ode> methods should
12469 * only ever make a copy, or read from this map after it has been set in 12865 * only ever make a copy, or read from this map after it has been set in
12470 * [visitClassDeclaration]. 12866 * [visitClassDeclaration].
12471 * 12867 *
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
12543 checkForInvalidAssignment(node); 12939 checkForInvalidAssignment(node);
12544 } 12940 }
12545 checkForAssignmentToFinal(node); 12941 checkForAssignmentToFinal(node);
12546 checkForArgumentTypeNotAssignable2(node.rightHandSide); 12942 checkForArgumentTypeNotAssignable2(node.rightHandSide);
12547 return super.visitAssignmentExpression(node); 12943 return super.visitAssignmentExpression(node);
12548 } 12944 }
12549 Object visitBinaryExpression(BinaryExpression node) { 12945 Object visitBinaryExpression(BinaryExpression node) {
12550 checkForArgumentTypeNotAssignable2(node.rightOperand); 12946 checkForArgumentTypeNotAssignable2(node.rightOperand);
12551 return super.visitBinaryExpression(node); 12947 return super.visitBinaryExpression(node);
12552 } 12948 }
12949 Object visitBlockFunctionBody(BlockFunctionBody node) {
12950 int previousReturnWithCount = _returnWithCount;
12951 int previousReturnWithoutCount = _returnWithoutCount;
12952 try {
12953 _returnWithCount = 0;
12954 _returnWithoutCount = 0;
12955 super.visitBlockFunctionBody(node);
12956 checkForMixedReturns(node);
12957 } finally {
12958 _returnWithCount = previousReturnWithCount;
12959 _returnWithoutCount = previousReturnWithoutCount;
12960 }
12961 return null;
12962 }
12553 Object visitCatchClause(CatchClause node) { 12963 Object visitCatchClause(CatchClause node) {
12554 bool previousIsInCatchClause = _isInCatchClause; 12964 bool previousIsInCatchClause = _isInCatchClause;
12555 try { 12965 try {
12556 _isInCatchClause = true; 12966 _isInCatchClause = true;
12557 return super.visitCatchClause(node); 12967 return super.visitCatchClause(node);
12558 } finally { 12968 } finally {
12559 _isInCatchClause = previousIsInCatchClause; 12969 _isInCatchClause = previousIsInCatchClause;
12560 } 12970 }
12561 } 12971 }
12562 Object visitClassDeclaration(ClassDeclaration node) { 12972 Object visitClassDeclaration(ClassDeclaration node) {
12563 ClassElement outerClass = _enclosingClass; 12973 ClassElement outerClass = _enclosingClass;
12564 try { 12974 try {
12565 _isInNativeClass = node.nativeClause != null; 12975 _isInNativeClass = node.nativeClause != null;
12566 _enclosingClass = node.element; 12976 _enclosingClass = node.element;
12567 WithClause withClause = node.withClause; 12977 WithClause withClause = node.withClause;
12568 ImplementsClause implementsClause = node.implementsClause; 12978 ImplementsClause implementsClause = node.implementsClause;
12569 ExtendsClause extendsClause = node.extendsClause; 12979 ExtendsClause extendsClause = node.extendsClause;
12570 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME); 12980 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
12571 checkForMemberWithClassName(); 12981 checkForMemberWithClassName();
12572 checkForNoDefaultSuperConstructorImplicit(node); 12982 checkForNoDefaultSuperConstructorImplicit(node);
12573 checkForAllMixinErrorCodes(withClause); 12983 checkForAllMixinErrorCodes(withClause);
12574 checkForConflictingTypeVariableErrorCodes(node); 12984 checkForConflictingTypeVariableErrorCodes(node);
12575 if (implementsClause != null || extendsClause != null) { 12985 if (implementsClause != null || extendsClause != null) {
12576 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause)) { 12986 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause)) {
12577 checkForNonAbstractClassInheritsAbstractMember(node); 12987 checkForNonAbstractClassInheritsAbstractMember(node);
12578 checkForInconsistentMethodInheritance(); 12988 checkForInconsistentMethodInheritance();
12579 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE lement>()); 12989 checkForRecursiveInterfaceInheritance(_enclosingClass);
12580 } 12990 }
12581 } 12991 }
12582 ClassElement classElement = node.element; 12992 ClassElement classElement = node.element;
12583 if (classElement != null) { 12993 if (classElement != null) {
12584 List<FieldElement> fieldElements = classElement.fields; 12994 List<FieldElement> fieldElements = classElement.fields;
12585 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); 12995 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
12586 for (FieldElement fieldElement in fieldElements) { 12996 for (FieldElement fieldElement in fieldElements) {
12587 if (!fieldElement.isSynthetic) { 12997 if (!fieldElement.isSynthetic) {
12588 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; 12998 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
12589 } 12999 }
(...skipping 10 matching lines...) Expand all
12600 _initialFieldElementsMap = null; 13010 _initialFieldElementsMap = null;
12601 _enclosingClass = outerClass; 13011 _enclosingClass = outerClass;
12602 } 13012 }
12603 } 13013 }
12604 Object visitClassTypeAlias(ClassTypeAlias node) { 13014 Object visitClassTypeAlias(ClassTypeAlias node) {
12605 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 13015 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
12606 checkForAllMixinErrorCodes(node.withClause); 13016 checkForAllMixinErrorCodes(node.withClause);
12607 ClassElement outerClassElement = _enclosingClass; 13017 ClassElement outerClassElement = _enclosingClass;
12608 try { 13018 try {
12609 _enclosingClass = node.element; 13019 _enclosingClass = node.element;
12610 checkForRecursiveInterfaceInheritance(node.element, new List<ClassElement> ()); 13020 checkForRecursiveInterfaceInheritance(node.element);
12611 checkForTypeAliasCannotReferenceItself_mixin(node); 13021 checkForTypeAliasCannotReferenceItself_mixin(node);
12612 } finally { 13022 } finally {
12613 _enclosingClass = outerClassElement; 13023 _enclosingClass = outerClassElement;
12614 } 13024 }
12615 return super.visitClassTypeAlias(node); 13025 return super.visitClassTypeAlias(node);
12616 } 13026 }
12617 Object visitComment(Comment node) { 13027 Object visitComment(Comment node) {
12618 _isInComment = true; 13028 _isInComment = true;
12619 try { 13029 try {
12620 return super.visitComment(node); 13030 return super.visitComment(node);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
12914 return super.visitRedirectingConstructorInvocation(node); 13324 return super.visitRedirectingConstructorInvocation(node);
12915 } finally { 13325 } finally {
12916 _isInConstructorInitializer = false; 13326 _isInConstructorInitializer = false;
12917 } 13327 }
12918 } 13328 }
12919 Object visitRethrowExpression(RethrowExpression node) { 13329 Object visitRethrowExpression(RethrowExpression node) {
12920 checkForRethrowOutsideCatch(node); 13330 checkForRethrowOutsideCatch(node);
12921 return super.visitRethrowExpression(node); 13331 return super.visitRethrowExpression(node);
12922 } 13332 }
12923 Object visitReturnStatement(ReturnStatement node) { 13333 Object visitReturnStatement(ReturnStatement node) {
13334 if (node.expression == null) {
13335 _returnWithoutCount++;
13336 } else {
13337 _returnWithCount++;
13338 }
12924 checkForAllReturnStatementErrorCodes(node); 13339 checkForAllReturnStatementErrorCodes(node);
12925 return super.visitReturnStatement(node); 13340 return super.visitReturnStatement(node);
12926 } 13341 }
12927 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 13342 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
12928 checkForConstFormalParameter(node); 13343 checkForConstFormalParameter(node);
12929 checkForPrivateOptionalParameter(node); 13344 checkForPrivateOptionalParameter(node);
12930 return super.visitSimpleFormalParameter(node); 13345 return super.visitSimpleFormalParameter(node);
12931 } 13346 }
12932 Object visitSimpleIdentifier(SimpleIdentifier node) { 13347 Object visitSimpleIdentifier(SimpleIdentifier node) {
12933 checkForReferenceToDeclaredVariableInInitializer(node); 13348 checkForReferenceToDeclaredVariableInInitializer(node);
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
13437 /** 13852 /**
13438 * This checks error related to the redirected constructors. 13853 * This checks error related to the redirected constructors.
13439 * 13854 *
13440 * @param node the constructor declaration to evaluate 13855 * @param node the constructor declaration to evaluate
13441 * @return `true` if and only if an error code is generated on the passed node 13856 * @return `true` if and only if an error code is generated on the passed node
13442 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE 13857 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE
13443 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE 13858 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE
13444 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR 13859 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR
13445 */ 13860 */
13446 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { 13861 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) {
13447 ConstructorName redirectedNode = node.redirectedConstructor; 13862 ConstructorName redirectedConstructor = node.redirectedConstructor;
13448 if (redirectedNode == null) { 13863 if (redirectedConstructor == null) {
13449 return false; 13864 return false;
13450 } 13865 }
13451 ConstructorElement redirectedElement = redirectedNode.staticElement; 13866 ConstructorElement redirectedElement = redirectedConstructor.staticElement;
13452 if (redirectedElement == null) { 13867 if (redirectedElement == null) {
13453 TypeName constructorTypeName = redirectedNode.type; 13868 TypeName constructorTypeName = redirectedConstructor.type;
13454 Type2 redirectedType = constructorTypeName.type; 13869 Type2 redirectedType = constructorTypeName.type;
13455 if (redirectedType != null && redirectedType.element != null && !redirecte dType.isDynamic) { 13870 if (redirectedType != null && redirectedType.element != null && !redirecte dType.isDynamic) {
13456 String constructorStrName = constructorTypeName.name.name; 13871 String constructorStrName = constructorTypeName.name.name;
13457 if (redirectedNode.name != null) { 13872 if (redirectedConstructor.name != null) {
13458 constructorStrName += ".${redirectedNode.name.name}"; 13873 constructorStrName += ".${redirectedConstructor.name.name}";
13459 } 13874 }
13460 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_MISSING_CONSTR UCTOR, redirectedNode, [constructorStrName, redirectedType.displayName]); 13875 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_MISSING_CONSTR UCTOR, redirectedConstructor, [constructorStrName, redirectedType.displayName]);
13461 return true; 13876 return true;
13462 } 13877 }
13463 return false; 13878 return false;
13464 } 13879 }
13465 FunctionType redirectedType = redirectedElement.type; 13880 FunctionType redirectedType = redirectedElement.type;
13466 Type2 redirectedReturnType = redirectedType.returnType; 13881 Type2 redirectedReturnType = redirectedType.returnType;
13467 FunctionType constructorType = node.element.type; 13882 FunctionType constructorType = node.element.type;
13468 Type2 constructorReturnType = constructorType.returnType; 13883 Type2 constructorReturnType = constructorType.returnType;
13469 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { 13884 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) {
13470 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedNode, [redirectedReturnType, constructorReturnType]); 13885 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedConstructor, [redirectedReturnType, constructorReturnType]);
13471 return true; 13886 return true;
13472 } 13887 }
13473 if (!redirectedType.isSubtypeOf(constructorType)) { 13888 if (!redirectedType.isSubtypeOf(constructorType)) {
13474 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedNode, [redirectedType, constructorType]); 13889 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedConstructor, [redirectedType, constructorType]);
13475 return true; 13890 return true;
13476 } 13891 }
13477 return false; 13892 return false;
13478 } 13893 }
13479 13894
13480 /** 13895 /**
13481 * This checks that the return statement of the form <i>return e;</i> is not i n a generative 13896 * This checks that the return statement of the form <i>return e;</i> is not i n a generative
13482 * constructor. 13897 * constructor.
13483 * 13898 *
13484 * This checks that return statements without expressions are not in a generat ive constructor and 13899 * This checks that return statements without expressions are not in a generat ive constructor and
(...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after
15118 } 15533 }
15119 return problemReported; 15534 return problemReported;
15120 } 15535 }
15121 15536
15122 /** 15537 /**
15123 * Check to make sure that all similarly typed accessors are of the same type (including inherited 15538 * Check to make sure that all similarly typed accessors are of the same type (including inherited
15124 * accessors). 15539 * accessors).
15125 * 15540 *
15126 * @param node the accessor currently being visited 15541 * @param node the accessor currently being visited
15127 * @return `true` if and only if an error code is generated on the passed node 15542 * @return `true` if and only if an error code is generated on the passed node
15543 * @see StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES
15544 * @see StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE
15128 */ 15545 */
15129 bool checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a ccessorTextName) { 15546 bool checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a ccessorTextName) {
15130 ExecutableElement accessorElement = accessorDeclaration.element as Executabl eElement; 15547 ExecutableElement accessorElement = accessorDeclaration.element as Executabl eElement;
15131 if (accessorElement is! PropertyAccessorElement) { 15548 if (accessorElement is! PropertyAccessorElement) {
15132 return false; 15549 return false;
15133 } 15550 }
15551 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert yAccessorElement;
15134 PropertyAccessorElement counterpartAccessor = null; 15552 PropertyAccessorElement counterpartAccessor = null;
15135 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert yAccessorElement; 15553 ClassElement enclosingClassForCounterpart = null;
15136 if (propertyAccessorElement.isGetter) { 15554 if (propertyAccessorElement.isGetter) {
15137 counterpartAccessor = propertyAccessorElement.correspondingSetter; 15555 counterpartAccessor = propertyAccessorElement.correspondingSetter;
15138 } else { 15556 } else {
15139 counterpartAccessor = propertyAccessorElement.correspondingGetter; 15557 counterpartAccessor = propertyAccessorElement.correspondingGetter;
15140 if (counterpartAccessor != null && identical(counterpartAccessor.enclosing Element, propertyAccessorElement.enclosingElement)) { 15558 if (counterpartAccessor != null && identical(counterpartAccessor.enclosing Element, propertyAccessorElement.enclosingElement)) {
15141 return false; 15559 return false;
15142 } 15560 }
15143 } 15561 }
15144 if (counterpartAccessor == null) { 15562 if (counterpartAccessor == null) {
15145 return false; 15563 if (_enclosingClass != null) {
15564 String lookupIdentifier = propertyAccessorElement.name;
15565 if (lookupIdentifier.endsWith("=")) {
15566 lookupIdentifier = lookupIdentifier.substring(0, lookupIdentifier.leng th - 1);
15567 } else {
15568 lookupIdentifier += "=";
15569 }
15570 ExecutableElement elementFromInheritance = _inheritanceManager.lookupInh eritance(_enclosingClass, lookupIdentifier);
15571 if (elementFromInheritance != null && elementFromInheritance is Property AccessorElement) {
15572 enclosingClassForCounterpart = elementFromInheritance.enclosingElement as ClassElement;
15573 counterpartAccessor = elementFromInheritance as PropertyAccessorElemen t;
15574 }
15575 }
15576 if (counterpartAccessor == null) {
15577 return false;
15578 }
15146 } 15579 }
15147 Type2 getterType = null; 15580 Type2 getterType = null;
15148 Type2 setterType = null; 15581 Type2 setterType = null;
15149 if (propertyAccessorElement.isGetter) { 15582 if (propertyAccessorElement.isGetter) {
15150 getterType = getGetterType(propertyAccessorElement); 15583 getterType = getGetterType(propertyAccessorElement);
15151 setterType = getSetterType(counterpartAccessor); 15584 setterType = getSetterType(counterpartAccessor);
15152 } else if (propertyAccessorElement.isSetter) { 15585 } else if (propertyAccessorElement.isSetter) {
15153 setterType = getSetterType(propertyAccessorElement); 15586 setterType = getSetterType(propertyAccessorElement);
15154 counterpartAccessor = propertyAccessorElement.correspondingGetter;
15155 getterType = getGetterType(counterpartAccessor); 15587 getterType = getGetterType(counterpartAccessor);
15156 } 15588 }
15157 if (setterType != null && getterType != null && !getterType.isAssignableTo(s etterType)) { 15589 if (setterType != null && getterType != null && !getterType.isAssignableTo(s etterType)) {
15158 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER _TYPES, accessorDeclaration, [ 15590 if (enclosingClassForCounterpart == null) {
15159 accessorTextName, 15591 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES, accessorDeclaration, [
15160 setterType.displayName, 15592 accessorTextName,
15161 getterType.displayName]); 15593 setterType.displayName,
15594 getterType.displayName]);
15595 return true;
15596 } else {
15597 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES_FROM_SUPERTYPE, accessorDeclaration, [
15598 accessorTextName,
15599 setterType.displayName,
15600 getterType.displayName,
15601 enclosingClassForCounterpart.displayName]);
15602 }
15603 }
15604 return false;
15605 }
15606
15607 /**
15608 * This verifies that the given function body does not contain return statemen ts that both have
15609 * and do not have return values.
15610 *
15611 * @param node the function body being tested
15612 * @return `true` if and only if an error code is generated on the passed node
15613 * @see StaticWarningCode#MIXED_RETURN_TYPES
15614 */
15615 bool checkForMixedReturns(BlockFunctionBody node) {
15616 if (_returnWithCount > 0 && _returnWithoutCount > 0) {
15617 _errorReporter.reportError2(StaticWarningCode.MIXED_RETURN_TYPES, node, [] );
15162 return true; 15618 return true;
15163 } 15619 }
15164 return false; 15620 return false;
15165 } 15621 }
15166 15622
15167 /** 15623 /**
15168 * This verifies that the passed mixin does not have an explicitly declared co nstructor. 15624 * This verifies that the passed mixin does not have an explicitly declared co nstructor.
15169 * 15625 *
15170 * @param mixinName the node to report problem on 15626 * @param mixinName the node to report problem on
15171 * @param mixinElement the mixing to evaluate 15627 * @param mixinElement the mixing to evaluate
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
15326 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR 15782 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR
15327 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU S 15783 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU S
15328 */ 15784 */
15329 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { 15785 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) {
15330 if (_enclosingClass.isAbstract) { 15786 if (_enclosingClass.isAbstract) {
15331 return false; 15787 return false;
15332 } 15788 }
15333 List<MethodElement> methods = _enclosingClass.methods; 15789 List<MethodElement> methods = _enclosingClass.methods;
15334 List<PropertyAccessorElement> accessors = _enclosingClass.accessors; 15790 List<PropertyAccessorElement> accessors = _enclosingClass.accessors;
15335 Set<String> methodsInEnclosingClass = new Set<String>(); 15791 Set<String> methodsInEnclosingClass = new Set<String>();
15792 for (MethodElement method in methods) {
15793 String methodName = method.name;
15794 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) {
15795 return false;
15796 }
15797 javaSetAdd(methodsInEnclosingClass, methodName);
15798 }
15336 Set<String> accessorsInEnclosingClass = new Set<String>(); 15799 Set<String> accessorsInEnclosingClass = new Set<String>();
15337 for (MethodElement method in methods) {
15338 javaSetAdd(methodsInEnclosingClass, method.name);
15339 }
15340 for (PropertyAccessorElement accessor in accessors) { 15800 for (PropertyAccessorElement accessor in accessors) {
15341 javaSetAdd(accessorsInEnclosingClass, accessor.name); 15801 javaSetAdd(accessorsInEnclosingClass, accessor.name);
15342 } 15802 }
15343 if (methodsInEnclosingClass.contains(ElementResolver.NO_SUCH_METHOD_METHOD_N AME)) {
15344 return false;
15345 }
15346 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>(); 15803 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>();
15347 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass); 15804 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass);
15348 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass); 15805 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass);
15349 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) { 15806 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) {
15350 String memberName = membersInheritedFromInterfaces.getKey(i); 15807 String memberName = membersInheritedFromInterfaces.getKey(i);
15351 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i); 15808 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i);
15352 if (memberName == null) { 15809 if (memberName == null) {
15353 break; 15810 break;
15354 } 15811 }
15355 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name); 15812 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
15612 return false; 16069 return false;
15613 } 16070 }
15614 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, redirectedConstructorNode, []); 16071 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, redirectedConstructorNode, []);
15615 return true; 16072 return true;
15616 } 16073 }
15617 16074
15618 /** 16075 /**
15619 * This checks the class declaration is not a superinterface to itself. 16076 * This checks the class declaration is not a superinterface to itself.
15620 * 16077 *
15621 * @param classElt the class element to test 16078 * @param classElt the class element to test
15622 * @param list a list containing the potentially cyclic implements path
15623 * @return `true` if and only if an error code is generated on the passed elem ent 16079 * @return `true` if and only if an error code is generated on the passed elem ent
15624 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE 16080 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE
15625 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 16081 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
15626 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS 16082 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS
15627 */ 16083 */
15628 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl ement> list) { 16084 bool checkForRecursiveInterfaceInheritance(ClassElement classElt) {
15629 if (classElt == null) { 16085 if (classElt == null) {
15630 return false; 16086 return false;
15631 } 16087 }
15632 InterfaceType supertype = classElt.supertype; 16088 return checkForRecursiveInterfaceInheritance2(classElt, new List<ClassElemen t>());
15633 list.add(classElt); 16089 }
15634 if (list.length != 1 && _enclosingClass == classElt) { 16090
16091 /**
16092 * This checks the class declaration is not a superinterface to itself.
16093 *
16094 * @param classElt the class element to test
16095 * @param path a list containing the potentially cyclic implements path
16096 * @return `true` if and only if an error code is generated on the passed elem ent
16097 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE
16098 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
16099 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS
16100 */
16101 bool checkForRecursiveInterfaceInheritance2(ClassElement classElt, List<ClassE lement> path) {
16102 int size = path.length;
16103 if (size > 0 && _enclosingClass == classElt) {
15635 String enclosingClassName = _enclosingClass.displayName; 16104 String enclosingClassName = _enclosingClass.displayName;
15636 if (list.length > 2) { 16105 if (size > 1) {
15637 String separator = ", "; 16106 String separator = ", ";
15638 int listLength = list.length;
15639 JavaStringBuilder builder = new JavaStringBuilder(); 16107 JavaStringBuilder builder = new JavaStringBuilder();
15640 for (int i = 0; i < listLength; i++) { 16108 for (int i = 0; i < size; i++) {
15641 builder.append(list[i].displayName); 16109 builder.append(path[i].displayName);
15642 if (i != listLength - 1) { 16110 builder.append(separator);
15643 builder.append(separator);
15644 }
15645 } 16111 }
16112 builder.append(classElt.displayName);
15646 _errorReporter.reportError3(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]); 16113 _errorReporter.reportError3(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]);
15647 return true; 16114 return true;
15648 } else if (list.length == 2) { 16115 } else {
16116 InterfaceType supertype = classElt.supertype;
15649 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS) a s ErrorCode; 16117 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS) a s ErrorCode;
15650 _errorReporter.reportError3(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]); 16118 _errorReporter.reportError3(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]);
15651 return true; 16119 return true;
15652 } 16120 }
15653 } 16121 }
15654 for (int i = 1; i < list.length - 1; i++) { 16122 if (path.indexOf(classElt) > 0) {
15655 if (classElt == list[i]) { 16123 return false;
15656 list.removeAt(list.length - 1);
15657 return false;
15658 }
15659 } 16124 }
15660 List<ClassElement> interfaceElements; 16125 path.add(classElt);
16126 InterfaceType supertype = classElt.supertype;
16127 if (supertype != null && checkForRecursiveInterfaceInheritance2(supertype.el ement, path)) {
16128 return true;
16129 }
15661 List<InterfaceType> interfaceTypes = classElt.interfaces; 16130 List<InterfaceType> interfaceTypes = classElt.interfaces;
15662 if (supertype != null && !supertype.isObject) { 16131 for (InterfaceType interfaceType in interfaceTypes) {
15663 interfaceElements = new List<ClassElement>(interfaceTypes.length + 1); 16132 if (checkForRecursiveInterfaceInheritance2(interfaceType.element, path)) {
15664 interfaceElements[0] = supertype.element;
15665 for (int i = 0; i < interfaceTypes.length; i++) {
15666 interfaceElements[i + 1] = interfaceTypes[i].element;
15667 }
15668 } else {
15669 interfaceElements = new List<ClassElement>(interfaceTypes.length);
15670 for (int i = 0; i < interfaceTypes.length; i++) {
15671 interfaceElements[i] = interfaceTypes[i].element;
15672 }
15673 }
15674 for (ClassElement classElt2 in interfaceElements) {
15675 if (checkForRecursiveInterfaceInheritance(classElt2, list)) {
15676 return true; 16133 return true;
15677 } 16134 }
15678 } 16135 }
15679 list.removeAt(list.length - 1); 16136 path.removeAt(path.length - 1);
15680 return false; 16137 return false;
15681 } 16138 }
15682 16139
15683 /** 16140 /**
15684 * This checks the passed constructor declaration has a valid combination of r edirected 16141 * This checks the passed constructor declaration has a valid combination of r edirected
15685 * constructor invocation(s), super constructor invocations and field initiali zers. 16142 * constructor invocation(s), super constructor invocations and field initiali zers.
15686 * 16143 *
15687 * @param node the constructor declaration to evaluate 16144 * @param node the constructor declaration to evaluate
15688 * @return `true` if and only if an error code is generated on the passed node 16145 * @return `true` if and only if an error code is generated on the passed node
16146 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
16147 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
15689 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS 16148 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS
15690 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR 16149 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR
15691 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
15692 */ 16150 */
15693 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { 16151 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
15694 int numProblems = 0; 16152 bool errorReported = false;
16153 ConstructorName redirectedConstructor = node.redirectedConstructor;
16154 if (redirectedConstructor != null) {
16155 for (FormalParameter parameter in node.parameters.parameters) {
16156 if (parameter is DefaultFormalParameter && ((parameter as DefaultFormalP arameter)).defaultValue != null) {
16157 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_REDI RECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []);
16158 errorReported = true;
16159 }
16160 }
16161 }
15695 int numRedirections = 0; 16162 int numRedirections = 0;
15696 for (ConstructorInitializer initializer in node.initializers) { 16163 for (ConstructorInitializer initializer in node.initializers) {
15697 if (initializer is RedirectingConstructorInvocation) { 16164 if (initializer is RedirectingConstructorInvocation) {
15698 if (numRedirections > 0) { 16165 if (numRedirections > 0) {
15699 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []); 16166 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []);
15700 numProblems++; 16167 errorReported = true;
15701 } 16168 }
15702 numRedirections++; 16169 numRedirections++;
15703 } 16170 }
15704 } 16171 }
15705 if (numRedirections > 0) { 16172 if (numRedirections > 0) {
15706 for (ConstructorInitializer initializer in node.initializers) { 16173 for (ConstructorInitializer initializer in node.initializers) {
15707 if (initializer is SuperConstructorInvocation) { 16174 if (initializer is SuperConstructorInvocation) {
15708 _errorReporter.reportError2(CompileTimeErrorCode.SUPER_IN_REDIRECTING_ CONSTRUCTOR, initializer, []); 16175 _errorReporter.reportError2(CompileTimeErrorCode.SUPER_IN_REDIRECTING_ CONSTRUCTOR, initializer, []);
15709 numProblems++; 16176 errorReported = true;
15710 } 16177 }
15711 if (initializer is ConstructorFieldInitializer) { 16178 if (initializer is ConstructorFieldInitializer) {
15712 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED IRECTING_CONSTRUCTOR, initializer, []); 16179 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED IRECTING_CONSTRUCTOR, initializer, []);
15713 numProblems++; 16180 errorReported = true;
15714 } 16181 }
15715 } 16182 }
15716 } 16183 }
15717 return numProblems != 0; 16184 return errorReported;
15718 } 16185 }
15719 16186
15720 /** 16187 /**
15721 * This checks if the passed constructor declaration has redirected constructo r and references 16188 * This checks if the passed constructor declaration has redirected constructo r and references
15722 * itself directly or indirectly. 16189 * itself directly or indirectly.
15723 * 16190 *
15724 * @param node the constructor declaration to evaluate 16191 * @param node the constructor declaration to evaluate
15725 * @return `true` if and only if an error code is generated on the passed node 16192 * @return `true` if and only if an error code is generated on the passed node
15726 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR 16193 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR
15727 */ 16194 */
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
16347 firstIteration = false; 16814 firstIteration = false;
16348 break; 16815 break;
16349 } else { 16816 } else {
16350 return true; 16817 return true;
16351 } 16818 }
16352 } 16819 }
16353 if (current != null && !checked.contains(current)) { 16820 if (current != null && !checked.contains(current)) {
16354 break; 16821 break;
16355 } 16822 }
16356 } 16823 }
16357 current.accept(new GeneralizingElementVisitor_12(target, toCheck)); 16824 current.accept(new GeneralizingElementVisitor_14(target, toCheck));
16358 javaSetAdd(checked, current); 16825 javaSetAdd(checked, current);
16359 } 16826 }
16360 } 16827 }
16361 16828
16362 /** 16829 /**
16363 * @return `true` if given [Type] implements operator <i>==</i>, and it is not 16830 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
16364 * <i>int</i> or <i>String</i>. 16831 * <i>int</i> or <i>String</i>.
16365 */ 16832 */
16366 bool implementsEqualsWhenNotAllowed(Type2 type) { 16833 bool implementsEqualsWhenNotAllowed(Type2 type) {
16367 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) { 16834 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
16543 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1); 17010 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1);
16544 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2); 17011 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2);
16545 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 3); 17012 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 3);
16546 static final List<INIT_STATE> values = [ 17013 static final List<INIT_STATE> values = [
16547 NOT_INIT, 17014 NOT_INIT,
16548 INIT_IN_DECLARATION, 17015 INIT_IN_DECLARATION,
16549 INIT_IN_FIELD_FORMAL, 17016 INIT_IN_FIELD_FORMAL,
16550 INIT_IN_INITIALIZERS]; 17017 INIT_IN_INITIALIZERS];
16551 INIT_STATE(String name, int ordinal) : super(name, ordinal); 17018 INIT_STATE(String name, int ordinal) : super(name, ordinal);
16552 } 17019 }
16553 class GeneralizingElementVisitor_12 extends GeneralizingElementVisitor<Object> { 17020 class GeneralizingElementVisitor_14 extends GeneralizingElementVisitor<Object> {
16554 Element target; 17021 Element target;
16555 List<Element> toCheck; 17022 List<Element> toCheck;
16556 GeneralizingElementVisitor_12(this.target, this.toCheck) : super(); 17023 GeneralizingElementVisitor_14(this.target, this.toCheck) : super();
16557 bool _inClass = false; 17024 bool _inClass = false;
16558 Object visitClassElement(ClassElement element) { 17025 Object visitClassElement(ClassElement element) {
16559 addTypeToCheck(element.supertype); 17026 addTypeToCheck(element.supertype);
16560 for (InterfaceType mixin in element.mixins) { 17027 for (InterfaceType mixin in element.mixins) {
16561 addTypeToCheck(mixin); 17028 addTypeToCheck(mixin);
16562 } 17029 }
16563 _inClass = !element.isTypedef; 17030 _inClass = !element.isTypedef;
16564 try { 17031 try {
16565 return super.visitClassElement(element); 17032 return super.visitClassElement(element);
16566 } finally { 17033 } finally {
16567 _inClass = false; 17034 _inClass = false;
16568 } 17035 }
16569 } 17036 }
16570 Object visitExecutableElement(ExecutableElement element) { 17037 Object visitExecutableElement(ExecutableElement element) {
16571 if (element.isSynthetic) { 17038 if (element.isSynthetic) {
16572 return null; 17039 return null;
16573 } 17040 }
16574 addTypeToCheck(element.returnType); 17041 addTypeToCheck(element.returnType);
16575 return super.visitExecutableElement(element); 17042 return super.visitExecutableElement(element);
16576 } 17043 }
16577 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { 17044 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
16578 addTypeToCheck(element.returnType); 17045 addTypeToCheck(element.returnType);
16579 return super.visitFunctionTypeAliasElement(element); 17046 return super.visitFunctionTypeAliasElement(element);
16580 } 17047 }
16581 Object visitParameterElement(ParameterElement element) { 17048 Object visitParameterElement(ParameterElement element) {
16582 addTypeToCheck(element.type); 17049 addTypeToCheck(element.type);
16583 return super.visitParameterElement(element); 17050 return super.visitParameterElement(element);
16584 } 17051 }
16585 Object visitTypeParameterElement(TypeParameterElement element) => null; 17052 Object visitTypeParameterElement(TypeParameterElement element) {
17053 addTypeToCheck(element.bound);
17054 return super.visitTypeParameterElement(element);
17055 }
16586 Object visitVariableElement(VariableElement element) { 17056 Object visitVariableElement(VariableElement element) {
16587 addTypeToCheck(element.type); 17057 addTypeToCheck(element.type);
16588 return super.visitVariableElement(element); 17058 return super.visitVariableElement(element);
16589 } 17059 }
16590 void addTypeToCheck(Type2 type) { 17060 void addTypeToCheck(Type2 type) {
16591 if (type == null) { 17061 if (type == null) {
16592 return; 17062 return;
16593 } 17063 }
16594 Element element = type.element; 17064 Element element = type.element;
16595 if (_inClass && target == element) { 17065 if (_inClass && target == element) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
16658 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) { 17128 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) {
16659 this._type = type; 17129 this._type = type;
16660 this._message = message; 17130 this._message = message;
16661 this.correction9 = correction; 17131 this.correction9 = correction;
16662 } 17132 }
16663 String get correction => correction9; 17133 String get correction => correction9;
16664 ErrorSeverity get errorSeverity => _type.severity; 17134 ErrorSeverity get errorSeverity => _type.severity;
16665 String get message => _message; 17135 String get message => _message;
16666 ErrorType get type => _type; 17136 ErrorType get type => _type;
16667 } 17137 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/parser.dart ('k') | pkg/analyzer_experimental/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698