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

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

Issue 14205011: Issue 9845. Compare runtime types using ==. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months 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 3
4 library engine.resolver; 4 library engine.resolver;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'instrumentation.dart'; 9 import 'instrumentation.dart';
10 import 'source.dart'; 10 import 'source.dart';
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 _enclosingExecutable = outerExecutable; 1006 _enclosingExecutable = outerExecutable;
1007 } 1007 }
1008 } 1008 }
1009 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 1009 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
1010 SimpleIdentifier variableName = node.identifier; 1010 SimpleIdentifier variableName = node.identifier;
1011 find3(_enclosingExecutable.localVariables, variableName); 1011 find3(_enclosingExecutable.localVariables, variableName);
1012 return super.visitDeclaredIdentifier(node); 1012 return super.visitDeclaredIdentifier(node);
1013 } 1013 }
1014 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 1014 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
1015 SimpleIdentifier parameterName = node.parameter.identifier; 1015 SimpleIdentifier parameterName = node.parameter.identifier;
1016 ParameterElement element = find3(_enclosingExecutable.parameters, parameterN ame); 1016 ParameterElement element = null;
1017 if (_enclosingExecutable != null) {
1018 element = find3(_enclosingExecutable.parameters, parameterName);
1019 } else {
1020 PrintStringWriter writer = new PrintStringWriter();
1021 writer.println("Invalid state found in the Analysis Engine:");
1022 writer.println("DeclarationResolver.visitDefaultFormalParameter() is visit ing a parameter that does not appear to be in a method or function.");
1023 writer.println("Ancestors:");
1024 ASTNode parent14 = node.parent;
1025 while (parent14 != null) {
1026 writer.println(parent14.runtimeType.toString());
1027 writer.println("---------");
1028 parent14 = parent14.parent;
1029 }
1030 print(new AnalysisException());
Brian Wilkerson 2013/04/17 18:59:42 Didn't this need to be "writer.print(...)"?
1031 AnalysisEngine.instance.logger.logError(writer.toString());
1032 }
1017 Expression defaultValue2 = node.defaultValue; 1033 Expression defaultValue2 = node.defaultValue;
1018 if (defaultValue2 != null) { 1034 if (defaultValue2 != null) {
1019 ExecutableElement outerExecutable = _enclosingExecutable; 1035 ExecutableElement outerExecutable = _enclosingExecutable;
1020 try { 1036 try {
1021 if (element == null) { 1037 if (element == null) {
1022 } else { 1038 } else {
1023 _enclosingExecutable = element.initializer; 1039 _enclosingExecutable = element.initializer;
1024 } 1040 }
1025 defaultValue2.accept(this); 1041 defaultValue2.accept(this);
1026 } finally { 1042 } finally {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 if (fieldElement != null && !fieldElement.isSynthetic()) { 1509 if (fieldElement != null && !fieldElement.isSynthetic()) {
1494 recordResolution(fieldName2, fieldElement); 1510 recordResolution(fieldName2, fieldElement);
1495 } 1511 }
1496 return null; 1512 return null;
1497 } 1513 }
1498 Object visitConstructorName(ConstructorName node) { 1514 Object visitConstructorName(ConstructorName node) {
1499 Type2 type14 = node.type.type; 1515 Type2 type14 = node.type.type;
1500 if (type14 is DynamicTypeImpl) { 1516 if (type14 is DynamicTypeImpl) {
1501 return null; 1517 return null;
1502 } else if (type14 is! InterfaceType) { 1518 } else if (type14 is! InterfaceType) {
1503 ASTNode parent14 = node.parent; 1519 ASTNode parent15 = node.parent;
Brian Wilkerson 2013/04/17 18:59:42 Enhancement request: It would be nice if we could
1504 if (parent14 is InstanceCreationExpression) { 1520 if (parent15 is InstanceCreationExpression) {
1505 if (((parent14 as InstanceCreationExpression)).isConst()) { 1521 if (((parent15 as InstanceCreationExpression)).isConst()) {
1506 } else { 1522 } else {
1507 } 1523 }
1508 } else { 1524 } else {
1509 } 1525 }
1510 return null; 1526 return null;
1511 } 1527 }
1512 ClassElement classElement = ((type14 as InterfaceType)).element; 1528 ClassElement classElement = ((type14 as InterfaceType)).element;
1513 ConstructorElement constructor; 1529 ConstructorElement constructor;
1514 SimpleIdentifier name17 = node.name; 1530 SimpleIdentifier name17 = node.name;
1515 if (name17 == null) { 1531 if (name17 == null) {
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 } 3687 }
3672 } 3688 }
3673 return overrides; 3689 return overrides;
3674 } 3690 }
3675 /** 3691 /**
3676 * Return {@code true} if the given expression terminates abruptly (that is, i f any expression 3692 * Return {@code true} if the given expression terminates abruptly (that is, i f any expression
3677 * following the given expression will not be reached). 3693 * following the given expression will not be reached).
3678 * @param expression the expression being tested 3694 * @param expression the expression being tested
3679 * @return {@code true} if the given expression terminates abruptly 3695 * @return {@code true} if the given expression terminates abruptly
3680 */ 3696 */
3681 bool isAbruptTermination(Expression expression18) { 3697 bool isAbruptTermination(Expression expression19) {
3682 while (expression18 is ParenthesizedExpression) { 3698 while (expression19 is ParenthesizedExpression) {
3683 expression18 = ((expression18 as ParenthesizedExpression)).expression; 3699 expression19 = ((expression19 as ParenthesizedExpression)).expression;
3684 } 3700 }
3685 return expression18 is ThrowExpression || expression18 is RethrowExpression; 3701 return expression19 is ThrowExpression || expression19 is RethrowExpression;
3686 } 3702 }
3687 /** 3703 /**
3688 * Return {@code true} if the given statement terminates abruptly (that is, if any statement 3704 * Return {@code true} if the given statement terminates abruptly (that is, if any statement
3689 * following the given statement will not be reached). 3705 * following the given statement will not be reached).
3690 * @param statement the statement being tested 3706 * @param statement the statement being tested
3691 * @return {@code true} if the given statement terminates abruptly 3707 * @return {@code true} if the given statement terminates abruptly
3692 */ 3708 */
3693 bool isAbruptTermination2(Statement statement) { 3709 bool isAbruptTermination2(Statement statement) {
3694 if (statement is ReturnStatement) { 3710 if (statement is ReturnStatement) {
3695 return true; 3711 return true;
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
5100 * @param library the library being tested 5116 * @param library the library being tested
5101 * @return {@code true} if the library is 'dart:html' 5117 * @return {@code true} if the library is 'dart:html'
5102 */ 5118 */
5103 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; 5119 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html";
5104 /** 5120 /**
5105 * Return {@code true} if the given node is not a type literal. 5121 * Return {@code true} if the given node is not a type literal.
5106 * @param node the node being tested 5122 * @param node the node being tested
5107 * @return {@code true} if the given node is not a type literal 5123 * @return {@code true} if the given node is not a type literal
5108 */ 5124 */
5109 bool isNotTypeLiteral(Identifier node) { 5125 bool isNotTypeLiteral(Identifier node) {
5110 ASTNode parent15 = node.parent; 5126 ASTNode parent16 = node.parent;
5111 return parent15 is TypeName || (parent15 is PrefixedIdentifier && (parent15. parent is TypeName || identical(((parent15 as PrefixedIdentifier)).prefix, node) )) || (parent15 is PropertyAccess && identical(((parent15 as PropertyAccess)).ta rget, node)) || (parent15 is MethodInvocation && identical(node, ((parent15 as M ethodInvocation)).target)); 5127 return parent16 is TypeName || (parent16 is PrefixedIdentifier && (parent16. parent is TypeName || identical(((parent16 as PrefixedIdentifier)).prefix, node) )) || (parent16 is PropertyAccess && identical(((parent16 as PropertyAccess)).ta rget, node)) || (parent16 is MethodInvocation && identical(node, ((parent16 as M ethodInvocation)).target));
5112 } 5128 }
5113 /** 5129 /**
5114 * If it is appropriate to do so, override the type of the given element. Use the static type and 5130 * If it is appropriate to do so, override the type of the given element. Use the static type and
5115 * inferred type of the element to determine whether or not it is appropriate. 5131 * inferred type of the element to determine whether or not it is appropriate.
5116 * @param element the element whose type might be overridden 5132 * @param element the element whose type might be overridden
5117 * @param staticType the static type of the element 5133 * @param staticType the static type of the element
5118 * @param inferredType the inferred type of the element 5134 * @param inferredType the inferred type of the element
5119 */ 5135 */
5120 void override(VariableElement element, Type2 staticType, Type2 inferredType) { 5136 void override(VariableElement element, Type2 staticType, Type2 inferredType) {
5121 if (identical(inferredType, BottomTypeImpl.instance) || element is! Variable Element) { 5137 if (identical(inferredType, BottomTypeImpl.instance) || element is! Variable Element) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
5730 return null; 5746 return null;
5731 } 5747 }
5732 VoidTypeImpl voidType = VoidTypeImpl.instance; 5748 VoidTypeImpl voidType = VoidTypeImpl.instance;
5733 if (typeName.name == voidType.name) { 5749 if (typeName.name == voidType.name) {
5734 if (argumentList != null) { 5750 if (argumentList != null) {
5735 } 5751 }
5736 typeName.staticType = voidType; 5752 typeName.staticType = voidType;
5737 node.type = voidType; 5753 node.type = voidType;
5738 return null; 5754 return null;
5739 } 5755 }
5740 ASTNode parent16 = node.parent; 5756 ASTNode parent17 = node.parent;
5741 if (typeName is PrefixedIdentifier && parent16 is ConstructorName && argum entList == null) { 5757 if (typeName is PrefixedIdentifier && parent17 is ConstructorName && argum entList == null) {
5742 ConstructorName name = parent16 as ConstructorName; 5758 ConstructorName name = parent17 as ConstructorName;
5743 if (name.name == null) { 5759 if (name.name == null) {
5744 SimpleIdentifier prefix7 = ((typeName as PrefixedIdentifier)).prefix; 5760 SimpleIdentifier prefix7 = ((typeName as PrefixedIdentifier)).prefix;
5745 element = nameScope.lookup(prefix7, definingLibrary); 5761 element = nameScope.lookup(prefix7, definingLibrary);
5746 if (element is PrefixElement) { 5762 if (element is PrefixElement) {
5747 return null; 5763 return null;
5748 } else if (element != null) { 5764 } else if (element != null) {
5749 name.name = ((typeName as PrefixedIdentifier)).identifier; 5765 name.name = ((typeName as PrefixedIdentifier)).identifier;
5750 name.period = ((typeName as PrefixedIdentifier)).period; 5766 name.period = ((typeName as PrefixedIdentifier)).period;
5751 node.name = prefix7; 5767 node.name = prefix7;
5752 typeName = prefix7; 5768 typeName = prefix7;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 } 5916 }
5901 /** 5917 /**
5902 * The number of type arguments in the given type name does not match the numb er of parameters in 5918 * The number of type arguments in the given type name does not match the numb er of parameters in
5903 * the corresponding class element. Return the error code that should be used to report this 5919 * the corresponding class element. Return the error code that should be used to report this
5904 * error. 5920 * error.
5905 * @param node the type name with the wrong number of type arguments 5921 * @param node the type name with the wrong number of type arguments
5906 * @return the error code that should be used to report that the wrong number of type arguments 5922 * @return the error code that should be used to report that the wrong number of type arguments
5907 * were provided 5923 * were provided
5908 */ 5924 */
5909 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { 5925 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) {
5910 ASTNode parent17 = node.parent; 5926 ASTNode parent18 = node.parent;
5911 if (parent17 is ConstructorName) { 5927 if (parent18 is ConstructorName) {
5912 parent17 = parent17.parent; 5928 parent18 = parent18.parent;
5913 if (parent17 is InstanceCreationExpression) { 5929 if (parent18 is InstanceCreationExpression) {
5914 if (((parent17 as InstanceCreationExpression)).isConst()) { 5930 if (((parent18 as InstanceCreationExpression)).isConst()) {
5915 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; 5931 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS;
5916 } else { 5932 } else {
5917 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; 5933 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS;
5918 } 5934 }
5919 } 5935 }
5920 } 5936 }
5921 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; 5937 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
5922 } 5938 }
5923 /** 5939 /**
5924 * Given the multiple elements to which a single name could potentially be res olved, return the 5940 * Given the multiple elements to which a single name could potentially be res olved, return the
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
7133 Object visitReturnStatement(ReturnStatement node) { 7149 Object visitReturnStatement(ReturnStatement node) {
7134 checkForReturnOfInvalidType(node); 7150 checkForReturnOfInvalidType(node);
7135 return super.visitReturnStatement(node); 7151 return super.visitReturnStatement(node);
7136 } 7152 }
7137 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 7153 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
7138 checkForConstFormalParameter(node); 7154 checkForConstFormalParameter(node);
7139 return super.visitSimpleFormalParameter(node); 7155 return super.visitSimpleFormalParameter(node);
7140 } 7156 }
7141 Object visitSwitchStatement(SwitchStatement node) { 7157 Object visitSwitchStatement(SwitchStatement node) {
7142 checkForCaseExpressionTypeImplementsEquals(node); 7158 checkForCaseExpressionTypeImplementsEquals(node);
7159 checkForInconsistentCaseExpressionTypes(node);
7143 return super.visitSwitchStatement(node); 7160 return super.visitSwitchStatement(node);
7144 } 7161 }
7145 Object visitThrowExpression(ThrowExpression node) { 7162 Object visitThrowExpression(ThrowExpression node) {
7146 checkForConstEvalThrowsException(node); 7163 checkForConstEvalThrowsException(node);
7147 return super.visitThrowExpression(node); 7164 return super.visitThrowExpression(node);
7148 } 7165 }
7149 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 7166 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
7150 checkForFinalNotInitialized2(node.variables); 7167 checkForFinalNotInitialized2(node.variables);
7151 return super.visitTopLevelVariableDeclaration(node); 7168 return super.visitTopLevelVariableDeclaration(node);
7152 } 7169 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
7487 } 7504 }
7488 return false; 7505 return false;
7489 } 7506 }
7490 /** 7507 /**
7491 * This verifies that the passed field formal parameter is in a constructor de claration. 7508 * This verifies that the passed field formal parameter is in a constructor de claration.
7492 * @param node the field formal parameter to test 7509 * @param node the field formal parameter to test
7493 * @return return {@code true} if and only if an error code is generated on th e passed node 7510 * @return return {@code true} if and only if an error code is generated on th e passed node
7494 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 7511 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
7495 */ 7512 */
7496 bool checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) { 7513 bool checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) {
7497 ASTNode parent18 = node.parent; 7514 ASTNode parent19 = node.parent;
7498 if (parent18 != null) { 7515 if (parent19 != null) {
7499 ASTNode grandparent = parent18.parent; 7516 ASTNode grandparent = parent19.parent;
7500 if (grandparent != null && grandparent is! ConstructorDeclaration && grand parent.parent is! ConstructorDeclaration) { 7517 if (grandparent != null && grandparent is! ConstructorDeclaration && grand parent.parent is! ConstructorDeclaration) {
7501 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSID E_CONSTRUCTOR, node, []); 7518 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSID E_CONSTRUCTOR, node, []);
7502 return true; 7519 return true;
7503 } 7520 }
7504 } 7521 }
7505 return false; 7522 return false;
7506 } 7523 }
7507 /** 7524 /**
7508 * This verifies that final fields that are declared, without any constructors in the enclosing 7525 * This verifies that final fields that are declared, without any constructors in the enclosing
7509 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end 7526 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7556 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 7573 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS
7557 */ 7574 */
7558 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { 7575 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) {
7559 bool foundError = false; 7576 bool foundError = false;
7560 for (TypeName type in implementsClause.interfaces) { 7577 for (TypeName type in implementsClause.interfaces) {
7561 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); 7578 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS));
7562 } 7579 }
7563 return foundError; 7580 return foundError;
7564 } 7581 }
7565 /** 7582 /**
7583 * This verifies that the passed switch statement case expressions all have th e same type.
7584 * @param node the switch statement to evaluate
7585 * @return return {@code true} if and only if an error code is generated on th e passed node
7586 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES
7587 */
7588 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) {
7589 NodeList<SwitchMember> switchMembers = node.members;
7590 bool foundError = false;
7591 Type2 firstType = null;
7592 for (SwitchMember switchMember in switchMembers) {
7593 if (switchMember is SwitchCase) {
7594 SwitchCase switchCase = switchMember as SwitchCase;
7595 Expression expression17 = switchCase.expression;
7596 if (firstType == null) {
7597 firstType = expression17.staticType;
7598 } else {
7599 Type2 nType = expression17.staticType;
7600 if (firstType != nType) {
7601 _errorReporter.reportError(CompileTimeErrorCode.INCONSISTENT_CASE_EX PRESSION_TYPES, expression17, [expression17.toSource(), firstType.name]);
7602 foundError = true;
7603 }
7604 }
7605 }
7606 }
7607 return foundError;
7608 }
7609 /**
7566 * This verifies that the passed assignment expression represents a valid assi gnment. 7610 * This verifies that the passed assignment expression represents a valid assi gnment.
7567 * @param node the assignment expression to evaluate 7611 * @param node the assignment expression to evaluate
7568 * @return return {@code true} if and only if an error code is generated on th e passed node 7612 * @return return {@code true} if and only if an error code is generated on th e passed node
7569 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 7613 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
7570 */ 7614 */
7571 bool checkForInvalidAssignment(AssignmentExpression node) { 7615 bool checkForInvalidAssignment(AssignmentExpression node) {
7572 Expression lhs = node.leftHandSide; 7616 Expression lhs = node.leftHandSide;
7573 Expression rhs = node.rightHandSide; 7617 Expression rhs = node.rightHandSide;
7574 VariableElement leftElement = getVariableElement(lhs); 7618 VariableElement leftElement = getVariableElement(lhs);
7575 Type2 leftType = (leftElement == null) ? getType(lhs) : leftElement.type; 7619 Type2 leftType = (leftElement == null) ? getType(lhs) : leftElement.type;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
7770 this._type = type; 7814 this._type = type;
7771 this._message = message; 7815 this._message = message;
7772 } 7816 }
7773 ErrorSeverity get errorSeverity => _type.severity; 7817 ErrorSeverity get errorSeverity => _type.severity;
7774 String get message => _message; 7818 String get message => _message;
7775 ErrorType get type => _type; 7819 ErrorType get type => _type;
7776 bool needsRecompilation() => true; 7820 bool needsRecompilation() => true;
7777 int compareTo(ResolverErrorCode other) => __ordinal - other.__ordinal; 7821 int compareTo(ResolverErrorCode other) => __ordinal - other.__ordinal;
7778 String toString() => __name; 7822 String toString() => __name;
7779 } 7823 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698