OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.resolver; | 8 library engine.resolver; |
9 | 9 |
10 import 'dart:collection'; | 10 import 'dart:collection'; |
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 invalidKeys.add(key); | 1454 invalidKeys.add(key); |
1455 } else { | 1455 } else { |
1456 keys.add(value); | 1456 keys.add(value); |
1457 } | 1457 } |
1458 DartType type = value.type; | 1458 DartType type = value.type; |
1459 if (_implementsEqualsWhenNotAllowed(type)) { | 1459 if (_implementsEqualsWhenNotAllowed(type)) { |
1460 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_MAP_KEY
_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, key, [type.displayName]); | 1460 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_MAP_KEY
_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, key, [type.displayName]); |
1461 } | 1461 } |
1462 } | 1462 } |
1463 } else { | 1463 } else { |
1464 EvaluationResultImpl result = key.accept(new ConstantVisitor(_typeProvid
er)); | 1464 EvaluationResultImpl result = key.accept(new ConstantVisitor.con1(_typeP
rovider)); |
1465 if (result is ValidResult) { | 1465 if (result is ValidResult) { |
1466 DartObject value = result.value; | 1466 DartObject value = result.value; |
1467 if (keys.contains(value)) { | 1467 if (keys.contains(value)) { |
1468 invalidKeys.add(key); | 1468 invalidKeys.add(key); |
1469 } else { | 1469 } else { |
1470 keys.add(value); | 1470 keys.add(value); |
1471 } | 1471 } |
1472 } else { | 1472 } else { |
1473 reportEqualKeys = false; | 1473 reportEqualKeys = false; |
1474 } | 1474 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 | 1639 |
1640 /** | 1640 /** |
1641 * Validate that the given expression is a compile time constant. Return the v
alue of the compile | 1641 * Validate that the given expression is a compile time constant. Return the v
alue of the compile |
1642 * time constant, or `null` if the expression is not a compile time constant. | 1642 * time constant, or `null` if the expression is not a compile time constant. |
1643 * | 1643 * |
1644 * @param expression the expression to be validated | 1644 * @param expression the expression to be validated |
1645 * @param errorCode the error code to be used if the expression is not a compi
le time constant | 1645 * @param errorCode the error code to be used if the expression is not a compi
le time constant |
1646 * @return the value of the compile time constant | 1646 * @return the value of the compile time constant |
1647 */ | 1647 */ |
1648 EvaluationResultImpl _validate(Expression expression, ErrorCode errorCode) { | 1648 EvaluationResultImpl _validate(Expression expression, ErrorCode errorCode) { |
1649 EvaluationResultImpl result = expression.accept(new ConstantVisitor(_typePro
vider)); | 1649 EvaluationResultImpl result = expression.accept(new ConstantVisitor.con1(_ty
peProvider)); |
1650 _reportErrors(result, errorCode); | 1650 _reportErrors(result, errorCode); |
1651 return result; | 1651 return result; |
1652 } | 1652 } |
1653 | 1653 |
1654 /** | 1654 /** |
1655 * Validate that if the passed arguments are constant expressions. | 1655 * Validate that if the passed arguments are constant expressions. |
1656 * | 1656 * |
1657 * @param argumentList the argument list to evaluate | 1657 * @param argumentList the argument list to evaluate |
1658 */ | 1658 */ |
1659 void _validateConstantArguments(ArgumentList argumentList) { | 1659 void _validateConstantArguments(ArgumentList argumentList) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 } | 1763 } |
1764 _validateConstantArguments(argumentList); | 1764 _validateConstantArguments(argumentList); |
1765 } | 1765 } |
1766 } | 1766 } |
1767 | 1767 |
1768 class ConstantVisitor_ConstantVerifier_validateInitializerExpression extends Con
stantVisitor { | 1768 class ConstantVisitor_ConstantVerifier_validateInitializerExpression extends Con
stantVisitor { |
1769 final ConstantVerifier ConstantVerifier_this; | 1769 final ConstantVerifier ConstantVerifier_this; |
1770 | 1770 |
1771 List<ParameterElement> parameterElements; | 1771 List<ParameterElement> parameterElements; |
1772 | 1772 |
1773 ConstantVisitor_ConstantVerifier_validateInitializerExpression(TypeProvider ar
g0, this.ConstantVerifier_this, this.parameterElements) : super(arg0); | 1773 ConstantVisitor_ConstantVerifier_validateInitializerExpression(TypeProvider ar
g0, this.ConstantVerifier_this, this.parameterElements) : super.con1(arg0); |
1774 | 1774 |
1775 @override | 1775 @override |
1776 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { | 1776 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { |
1777 Element element = node.staticElement; | 1777 Element element = node.staticElement; |
1778 for (ParameterElement parameterElement in parameterElements) { | 1778 for (ParameterElement parameterElement in parameterElements) { |
1779 if (identical(parameterElement, element) && parameterElement != null) { | 1779 if (identical(parameterElement, element) && parameterElement != null) { |
1780 DartType type = parameterElement.type; | 1780 DartType type = parameterElement.type; |
1781 if (type != null) { | 1781 if (type != null) { |
1782 if (type.isDynamic) { | 1782 if (type.isDynamic) { |
1783 return ConstantVerifier_this._valid(ConstantVerifier_this._typeProvi
der.objectType, DynamicState.DYNAMIC_STATE); | 1783 return ConstantVerifier_this._valid(ConstantVerifier_this._typeProvi
der.objectType, DynamicState.DYNAMIC_STATE); |
(...skipping 3362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5146 targetTypeName = targetType == null ? null : targetType.displayName; | 5146 targetTypeName = targetType == null ? null : targetType.displayName; |
5147 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD); | 5147 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD); |
5148 if (_doesClassElementHaveProxy(targetType.element)) { | 5148 if (_doesClassElementHaveProxy(targetType.element)) { |
5149 _resolver.reportErrorForNode(proxyErrorCode, methodName, [methodName.n
ame, targetTypeName]); | 5149 _resolver.reportErrorForNode(proxyErrorCode, methodName, [methodName.n
ame, targetTypeName]); |
5150 } | 5150 } |
5151 } | 5151 } |
5152 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { | 5152 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { |
5153 // Generate the type name. | 5153 // Generate the type name. |
5154 // The error code will never be generated via type propagation | 5154 // The error code will never be generated via type propagation |
5155 DartType targetType = _getStaticType(target); | 5155 DartType targetType = _getStaticType(target); |
| 5156 if (targetType is InterfaceType && !targetType.isObject) { |
| 5157 targetType = (targetType as InterfaceType).superclass; |
| 5158 } |
5156 String targetTypeName = targetType == null ? null : targetType.name; | 5159 String targetTypeName = targetType == null ? null : targetType.name; |
5157 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD,
methodName, [methodName.name, targetTypeName]); | 5160 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD,
methodName, [methodName.name, targetTypeName]); |
5158 } | 5161 } |
5159 return null; | 5162 return null; |
5160 } | 5163 } |
5161 | 5164 |
5162 @override | 5165 @override |
5163 Object visitPartDirective(PartDirective node) { | 5166 Object visitPartDirective(PartDirective node) { |
5164 _setMetadata(node.element, node); | 5167 _setMetadata(node.element, node); |
5165 return null; | 5168 return null; |
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7256 return super.visitAnnotation(node); | 7259 return super.visitAnnotation(node); |
7257 } | 7260 } |
7258 | 7261 |
7259 @override | 7262 @override |
7260 Object visitArgumentList(ArgumentList node) { | 7263 Object visitArgumentList(ArgumentList node) { |
7261 _checkForArgumentTypesNotAssignableInList(node); | 7264 _checkForArgumentTypesNotAssignableInList(node); |
7262 return super.visitArgumentList(node); | 7265 return super.visitArgumentList(node); |
7263 } | 7266 } |
7264 | 7267 |
7265 @override | 7268 @override |
| 7269 Object visitAsExpression(AsExpression node) { |
| 7270 _checkForTypeAnnotationDeferredClass(node.type); |
| 7271 return super.visitAsExpression(node); |
| 7272 } |
| 7273 |
| 7274 @override |
7266 Object visitAssertStatement(AssertStatement node) { | 7275 Object visitAssertStatement(AssertStatement node) { |
7267 _checkForNonBoolExpression(node); | 7276 _checkForNonBoolExpression(node); |
7268 return super.visitAssertStatement(node); | 7277 return super.visitAssertStatement(node); |
7269 } | 7278 } |
7270 | 7279 |
7271 @override | 7280 @override |
7272 Object visitAssignmentExpression(AssignmentExpression node) { | 7281 Object visitAssignmentExpression(AssignmentExpression node) { |
7273 sc.TokenType operatorType = node.operator.type; | 7282 sc.TokenType operatorType = node.operator.type; |
7274 Expression lhs = node.leftHandSide; | 7283 Expression lhs = node.leftHandSide; |
7275 Expression rhs = node.rightHandSide; | 7284 Expression rhs = node.rightHandSide; |
7276 if (operatorType == sc.TokenType.EQ) { | 7285 if (operatorType == sc.TokenType.EQ) { |
7277 _checkForInvalidAssignment(lhs, rhs); | 7286 _checkForInvalidAssignment(lhs, rhs); |
7278 } else { | 7287 } else { |
7279 _checkForInvalidCompoundAssignment(node, lhs, rhs); | 7288 _checkForInvalidCompoundAssignment(node, lhs, rhs); |
7280 } | 7289 } |
7281 _checkForAssignmentToFinal(lhs); | 7290 _checkForAssignmentToFinal(lhs); |
7282 _checkForArgumentTypeNotAssignableForArgument(rhs); | 7291 _checkForArgumentTypeNotAssignableForArgument(rhs); |
7283 return super.visitAssignmentExpression(node); | 7292 return super.visitAssignmentExpression(node); |
7284 } | 7293 } |
7285 | 7294 |
7286 @override | 7295 @override |
7287 Object visitBinaryExpression(BinaryExpression node) { | 7296 Object visitBinaryExpression(BinaryExpression node) { |
7288 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); | 7297 sc.Token operator = node.operator; |
| 7298 sc.TokenType type = operator.type; |
| 7299 if (type == sc.TokenType.AMPERSAND_AMPERSAND || type == sc.TokenType.BAR_BAR
) { |
| 7300 String lexeme = operator.lexeme; |
| 7301 _checkForAssignability(node.leftOperand, _boolType, StaticTypeWarningCode.
NON_BOOL_OPERAND, [lexeme]); |
| 7302 _checkForAssignability(node.rightOperand, _boolType, StaticTypeWarningCode
.NON_BOOL_OPERAND, [lexeme]); |
| 7303 } else { |
| 7304 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); |
| 7305 } |
7289 return super.visitBinaryExpression(node); | 7306 return super.visitBinaryExpression(node); |
7290 } | 7307 } |
7291 | 7308 |
7292 @override | 7309 @override |
7293 Object visitBlockFunctionBody(BlockFunctionBody node) { | 7310 Object visitBlockFunctionBody(BlockFunctionBody node) { |
7294 bool previousHasReturnWithoutValue = _hasReturnWithoutValue; | 7311 bool previousHasReturnWithoutValue = _hasReturnWithoutValue; |
7295 _hasReturnWithoutValue = false; | 7312 _hasReturnWithoutValue = false; |
7296 List<ReturnStatement> previousReturnsWith = _returnsWith; | 7313 List<ReturnStatement> previousReturnsWith = _returnsWith; |
7297 List<ReturnStatement> previousReturnsWithout = _returnsWithout; | 7314 List<ReturnStatement> previousReturnsWithout = _returnsWithout; |
7298 try { | 7315 try { |
(...skipping 19 matching lines...) Expand all Loading... |
7318 } | 7335 } |
7319 } | 7336 } |
7320 return null; | 7337 return null; |
7321 } | 7338 } |
7322 | 7339 |
7323 @override | 7340 @override |
7324 Object visitCatchClause(CatchClause node) { | 7341 Object visitCatchClause(CatchClause node) { |
7325 bool previousIsInCatchClause = _isInCatchClause; | 7342 bool previousIsInCatchClause = _isInCatchClause; |
7326 try { | 7343 try { |
7327 _isInCatchClause = true; | 7344 _isInCatchClause = true; |
| 7345 _checkForTypeAnnotationDeferredClass(node.exceptionType); |
7328 return super.visitCatchClause(node); | 7346 return super.visitCatchClause(node); |
7329 } finally { | 7347 } finally { |
7330 _isInCatchClause = previousIsInCatchClause; | 7348 _isInCatchClause = previousIsInCatchClause; |
7331 } | 7349 } |
7332 } | 7350 } |
7333 | 7351 |
7334 @override | 7352 @override |
7335 Object visitClassDeclaration(ClassDeclaration node) { | 7353 Object visitClassDeclaration(ClassDeclaration node) { |
7336 ClassElement outerClass = _enclosingClass; | 7354 ClassElement outerClass = _enclosingClass; |
7337 try { | 7355 try { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7656 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); | 7674 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); |
7657 } | 7675 } |
7658 } | 7676 } |
7659 return super.visitInstanceCreationExpression(node); | 7677 return super.visitInstanceCreationExpression(node); |
7660 } finally { | 7678 } finally { |
7661 _isInConstInstanceCreation = false; | 7679 _isInConstInstanceCreation = false; |
7662 } | 7680 } |
7663 } | 7681 } |
7664 | 7682 |
7665 @override | 7683 @override |
| 7684 Object visitIsExpression(IsExpression node) { |
| 7685 _checkForTypeAnnotationDeferredClass(node.type); |
| 7686 return super.visitIsExpression(node); |
| 7687 } |
| 7688 |
| 7689 @override |
7666 Object visitListLiteral(ListLiteral node) { | 7690 Object visitListLiteral(ListLiteral node) { |
7667 TypeArgumentList typeArguments = node.typeArguments; | 7691 TypeArgumentList typeArguments = node.typeArguments; |
7668 if (typeArguments != null) { | 7692 if (typeArguments != null) { |
7669 if (node.constKeyword != null) { | 7693 if (node.constKeyword != null) { |
7670 NodeList<TypeName> arguments = typeArguments.arguments; | 7694 NodeList<TypeName> arguments = typeArguments.arguments; |
7671 if (arguments.length != 0) { | 7695 if (arguments.length != 0) { |
7672 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime
ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); | 7696 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime
ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); |
7673 } | 7697 } |
7674 } | 7698 } |
7675 _checkForExpectedOneListTypeArgument(node, typeArguments); | 7699 _checkForExpectedOneListTypeArgument(node, typeArguments); |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8682 return false; | 8706 return false; |
8683 } | 8707 } |
8684 bool problemReported = false; | 8708 bool problemReported = false; |
8685 for (Expression argument in argumentList.arguments) { | 8709 for (Expression argument in argumentList.arguments) { |
8686 problemReported = javaBooleanOr(problemReported, _checkForArgumentTypeNotA
ssignableForArgument(argument)); | 8710 problemReported = javaBooleanOr(problemReported, _checkForArgumentTypeNotA
ssignableForArgument(argument)); |
8687 } | 8711 } |
8688 return problemReported; | 8712 return problemReported; |
8689 } | 8713 } |
8690 | 8714 |
8691 /** | 8715 /** |
| 8716 * Check that the static type of the given expression is assignable to the giv
en type. If it |
| 8717 * isn't, report an error with the given error code. |
| 8718 * |
| 8719 * @param expression the expression being tested |
| 8720 * @param type the type that the expression must be assignable to |
| 8721 * @param errorCode the error code to be reported |
| 8722 * @param arguments the arguments to pass in when creating the error |
| 8723 * @return `true` if an error was reported |
| 8724 */ |
| 8725 bool _checkForAssignability(Expression expression, InterfaceType type, ErrorCo
de errorCode, List<Object> arguments) { |
| 8726 if (expression == null) { |
| 8727 return false; |
| 8728 } |
| 8729 DartType expressionType = expression.staticType; |
| 8730 if (expressionType == null) { |
| 8731 return false; |
| 8732 } |
| 8733 if (expressionType.isAssignableTo(type)) { |
| 8734 return false; |
| 8735 } |
| 8736 _errorReporter.reportErrorForNode(errorCode, expression, arguments); |
| 8737 return true; |
| 8738 } |
| 8739 |
| 8740 /** |
8692 * This verifies that the passed expression is not final. | 8741 * This verifies that the passed expression is not final. |
8693 * | 8742 * |
8694 * @param node the expression to evaluate | 8743 * @param node the expression to evaluate |
8695 * @return `true` if and only if an error code is generated on the passed node | 8744 * @return `true` if and only if an error code is generated on the passed node |
8696 * @see StaticWarningCode#ASSIGNMENT_TO_CONST | 8745 * @see StaticWarningCode#ASSIGNMENT_TO_CONST |
8697 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 8746 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
8698 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD | 8747 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD |
8699 */ | 8748 */ |
8700 bool _checkForAssignmentToFinal(Expression expression) { | 8749 bool _checkForAssignmentToFinal(Expression expression) { |
8701 // prepare element | 8750 // prepare element |
(...skipping 14 matching lines...) Expand all Loading... |
8716 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 8765 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
8717 element = accessor.variable; | 8766 element = accessor.variable; |
8718 } | 8767 } |
8719 if (element is VariableElement) { | 8768 if (element is VariableElement) { |
8720 VariableElement variable = element as VariableElement; | 8769 VariableElement variable = element as VariableElement; |
8721 if (variable.isConst) { | 8770 if (variable.isConst) { |
8722 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST,
expression, []); | 8771 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST,
expression, []); |
8723 return true; | 8772 return true; |
8724 } | 8773 } |
8725 if (variable.isFinal) { | 8774 if (variable.isFinal) { |
| 8775 if (variable is FieldElementImpl && variable.setter == null && variable.
isSynthetic) { |
| 8776 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINA
L_NO_SETTER, highlightedNode, [variable.name, variable.enclosingElement.displayN
ame]); |
| 8777 return true; |
| 8778 } |
8726 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL,
highlightedNode, [variable.name]); | 8779 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL,
highlightedNode, [variable.name]); |
8727 return true; | 8780 return true; |
8728 } | 8781 } |
8729 return false; | 8782 return false; |
8730 } | 8783 } |
8731 if (element is FunctionElement) { | 8784 if (element is FunctionElement) { |
8732 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FUNCTION
, expression, []); | 8785 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FUNCTION
, expression, []); |
8733 return true; | 8786 return true; |
8734 } | 8787 } |
8735 if (element is MethodElement) { | 8788 if (element is MethodElement) { |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9205 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER | 9258 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER |
9206 */ | 9259 */ |
9207 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { | 9260 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { |
9208 if (!_isEnclosingConstructorConst) { | 9261 if (!_isEnclosingConstructorConst) { |
9209 return false; | 9262 return false; |
9210 } | 9263 } |
9211 // OK, const factory, checked elsewhere | 9264 // OK, const factory, checked elsewhere |
9212 if (node.factoryKeyword != null) { | 9265 if (node.factoryKeyword != null) { |
9213 return false; | 9266 return false; |
9214 } | 9267 } |
| 9268 // check for mixins |
| 9269 if (_enclosingClass.mixins.length != 0) { |
| 9270 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_W
ITH_MIXIN, node.returnType, []); |
| 9271 return true; |
| 9272 } |
9215 // try to find and check super constructor invocation | 9273 // try to find and check super constructor invocation |
9216 for (ConstructorInitializer initializer in node.initializers) { | 9274 for (ConstructorInitializer initializer in node.initializers) { |
9217 if (initializer is SuperConstructorInvocation) { | 9275 if (initializer is SuperConstructorInvocation) { |
9218 SuperConstructorInvocation superInvocation = initializer; | 9276 SuperConstructorInvocation superInvocation = initializer; |
9219 ConstructorElement element = superInvocation.staticElement; | 9277 ConstructorElement element = superInvocation.staticElement; |
9220 if (element == null || element.isConst) { | 9278 if (element == null || element.isConst) { |
9221 return false; | 9279 return false; |
9222 } | 9280 } |
9223 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR
_WITH_NON_CONST_SUPER, superInvocation, []); | 9281 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR
_WITH_NON_CONST_SUPER, superInvocation, [element.enclosingElement.displayName]); |
9224 return true; | 9282 return true; |
9225 } | 9283 } |
9226 } | 9284 } |
9227 // no explicit super constructor invocation, check default constructor | 9285 // no explicit super constructor invocation, check default constructor |
9228 InterfaceType supertype = _enclosingClass.supertype; | 9286 InterfaceType supertype = _enclosingClass.supertype; |
9229 if (supertype == null) { | 9287 if (supertype == null) { |
9230 return false; | 9288 return false; |
9231 } | 9289 } |
9232 if (supertype.isObject) { | 9290 if (supertype.isObject) { |
9233 return false; | 9291 return false; |
9234 } | 9292 } |
9235 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor
; | 9293 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor
; |
9236 if (unnamedConstructor == null) { | 9294 if (unnamedConstructor == null) { |
9237 return false; | 9295 return false; |
9238 } | 9296 } |
9239 if (unnamedConstructor.isConst) { | 9297 if (unnamedConstructor.isConst) { |
9240 return false; | 9298 return false; |
9241 } | 9299 } |
9242 // default constructor is not 'const', report problem | 9300 // default constructor is not 'const', report problem |
9243 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT
H_NON_CONST_SUPER, node.returnType, []); | 9301 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT
H_NON_CONST_SUPER, node.returnType, [supertype.displayName]); |
9244 return true; | 9302 return true; |
9245 } | 9303 } |
9246 | 9304 |
9247 /** | 9305 /** |
9248 * This verifies that if the passed constructor declaration is 'const' then th
ere are no non-final | 9306 * This verifies that if the passed constructor declaration is 'const' then th
ere are no non-final |
9249 * instance variable. | 9307 * instance variable. |
9250 * | 9308 * |
9251 * @param node the constructor declaration to evaluate | 9309 * @param node the constructor declaration to evaluate |
9252 * @param constructorElement the constructor element | 9310 * @param constructorElement the constructor element |
9253 * @return `true` if and only if an error code is generated on the passed node | 9311 * @return `true` if and only if an error code is generated on the passed node |
(...skipping 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11998 /** | 12056 /** |
11999 * Set to `true` when a `break` is encountered, and reset to `false` when a | 12057 * Set to `true` when a `break` is encountered, and reset to `false` when a |
12000 * `do`, `while`, `for` or `switch` block is entered. | 12058 * `do`, `while`, `for` or `switch` block is entered. |
12001 */ | 12059 */ |
12002 bool _enclosingBlockContainsBreak = false; | 12060 bool _enclosingBlockContainsBreak = false; |
12003 | 12061 |
12004 @override | 12062 @override |
12005 bool visitArgumentList(ArgumentList node) => _visitExpressions(node.arguments)
; | 12063 bool visitArgumentList(ArgumentList node) => _visitExpressions(node.arguments)
; |
12006 | 12064 |
12007 @override | 12065 @override |
12008 bool visitAsExpression(AsExpression node) => node.expression.accept(this); | 12066 bool visitAsExpression(AsExpression node) => _nodeExits(node.expression); |
12009 | 12067 |
12010 @override | 12068 @override |
12011 bool visitAssertStatement(AssertStatement node) => node.condition.accept(this)
; | 12069 bool visitAssertStatement(AssertStatement node) => _nodeExits(node.condition); |
12012 | 12070 |
12013 @override | 12071 @override |
12014 bool visitAssignmentExpression(AssignmentExpression node) => node.leftHandSide
.accept(this) || node.rightHandSide.accept(this); | 12072 bool visitAssignmentExpression(AssignmentExpression node) => _nodeExits(node.l
eftHandSide) || _nodeExits(node.rightHandSide); |
12015 | 12073 |
12016 @override | 12074 @override |
12017 bool visitBinaryExpression(BinaryExpression node) { | 12075 bool visitBinaryExpression(BinaryExpression node) { |
12018 Expression lhsExpression = node.leftOperand; | 12076 Expression lhsExpression = node.leftOperand; |
12019 sc.TokenType operatorType = node.operator.type; | 12077 sc.TokenType operatorType = node.operator.type; |
12020 // If the operator is || and the left hand side is false literal, don't cons
ider the RHS of the | 12078 // If the operator is || and the left hand side is false literal, don't cons
ider the RHS of the |
12021 // binary expression. | 12079 // binary expression. |
12022 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} | 12080 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} |
12023 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? | 12081 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? |
12024 if (operatorType == sc.TokenType.BAR_BAR) { | 12082 if (operatorType == sc.TokenType.BAR_BAR) { |
12025 if (lhsExpression is BooleanLiteral) { | 12083 if (lhsExpression is BooleanLiteral) { |
12026 BooleanLiteral booleanLiteral = lhsExpression; | 12084 BooleanLiteral booleanLiteral = lhsExpression; |
12027 if (!booleanLiteral.value) { | 12085 if (!booleanLiteral.value) { |
12028 return false; | 12086 return false; |
12029 } | 12087 } |
12030 } | 12088 } |
12031 } | 12089 } |
12032 // If the operator is && and the left hand side is true literal, don't consi
der the RHS of the | 12090 // If the operator is && and the left hand side is true literal, don't consi
der the RHS of the |
12033 // binary expression. | 12091 // binary expression. |
12034 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) { | 12092 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) { |
12035 if (lhsExpression is BooleanLiteral) { | 12093 if (lhsExpression is BooleanLiteral) { |
12036 BooleanLiteral booleanLiteral = lhsExpression; | 12094 BooleanLiteral booleanLiteral = lhsExpression; |
12037 if (booleanLiteral.value) { | 12095 if (booleanLiteral.value) { |
12038 return false; | 12096 return false; |
12039 } | 12097 } |
12040 } | 12098 } |
12041 } | 12099 } |
12042 Expression rhsExpression = node.rightOperand; | 12100 Expression rhsExpression = node.rightOperand; |
12043 return (lhsExpression != null && lhsExpression.accept(this)) || (rhsExpressi
on != null && rhsExpression.accept(this)); | 12101 return _nodeExits(lhsExpression) || _nodeExits(rhsExpression); |
12044 } | 12102 } |
12045 | 12103 |
12046 @override | 12104 @override |
12047 bool visitBlock(Block node) => _visitStatements(node.statements); | 12105 bool visitBlock(Block node) => _visitStatements(node.statements); |
12048 | 12106 |
12049 @override | 12107 @override |
12050 bool visitBlockFunctionBody(BlockFunctionBody node) => node.block.accept(this)
; | 12108 bool visitBlockFunctionBody(BlockFunctionBody node) => _nodeExits(node.block); |
12051 | 12109 |
12052 @override | 12110 @override |
12053 bool visitBreakStatement(BreakStatement node) { | 12111 bool visitBreakStatement(BreakStatement node) { |
12054 _enclosingBlockContainsBreak = true; | 12112 _enclosingBlockContainsBreak = true; |
12055 return false; | 12113 return false; |
12056 } | 12114 } |
12057 | 12115 |
12058 @override | 12116 @override |
12059 bool visitCascadeExpression(CascadeExpression node) { | 12117 bool visitCascadeExpression(CascadeExpression node) => _nodeExits(node.target)
|| _visitExpressions(node.cascadeSections); |
12060 Expression target = node.target; | |
12061 if (target.accept(this)) { | |
12062 return true; | |
12063 } | |
12064 return _visitExpressions(node.cascadeSections); | |
12065 } | |
12066 | 12118 |
12067 @override | 12119 @override |
12068 bool visitConditionalExpression(ConditionalExpression node) { | 12120 bool visitConditionalExpression(ConditionalExpression node) { |
12069 Expression conditionExpression = node.condition; | 12121 Expression conditionExpression = node.condition; |
12070 Expression thenStatement = node.thenExpression; | 12122 Expression thenStatement = node.thenExpression; |
12071 Expression elseStatement = node.elseExpression; | 12123 Expression elseStatement = node.elseExpression; |
12072 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} | 12124 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} |
12073 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? | 12125 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? |
12074 if (conditionExpression.accept(this)) { | 12126 if (_nodeExits(conditionExpression)) { |
12075 return true; | 12127 return true; |
12076 } | 12128 } |
12077 if (thenStatement == null || elseStatement == null) { | 12129 if (thenStatement == null || elseStatement == null) { |
12078 return false; | 12130 return false; |
12079 } | 12131 } |
12080 return thenStatement.accept(this) && elseStatement.accept(this); | 12132 return thenStatement.accept(this) && elseStatement.accept(this); |
12081 } | 12133 } |
12082 | 12134 |
12083 @override | 12135 @override |
12084 bool visitContinueStatement(ContinueStatement node) => false; | 12136 bool visitContinueStatement(ContinueStatement node) => false; |
12085 | 12137 |
12086 @override | 12138 @override |
12087 bool visitDoStatement(DoStatement node) { | 12139 bool visitDoStatement(DoStatement node) { |
12088 bool outerBreakValue = _enclosingBlockContainsBreak; | 12140 bool outerBreakValue = _enclosingBlockContainsBreak; |
12089 _enclosingBlockContainsBreak = false; | 12141 _enclosingBlockContainsBreak = false; |
12090 try { | 12142 try { |
12091 Expression conditionExpression = node.condition; | 12143 Expression conditionExpression = node.condition; |
12092 if (conditionExpression.accept(this)) { | 12144 if (_nodeExits(conditionExpression)) { |
12093 return true; | 12145 return true; |
12094 } | 12146 } |
12095 // TODO(jwren) Do we want to take all constant expressions into account? | 12147 // TODO(jwren) Do we want to take all constant expressions into account? |
12096 if (conditionExpression is BooleanLiteral) { | 12148 if (conditionExpression is BooleanLiteral) { |
12097 BooleanLiteral booleanLiteral = conditionExpression; | 12149 BooleanLiteral booleanLiteral = conditionExpression; |
12098 // If do {} while (true), and the body doesn't return or the body doesn'
t have a break, then | 12150 // If do {} while (true), and the body doesn't return or the body doesn'
t have a break, then |
12099 // return true. | 12151 // return true. |
12100 bool blockReturns = node.body.accept(this); | 12152 bool blockReturns = _nodeExits(node.body); |
12101 if (booleanLiteral.value && (blockReturns || !_enclosingBlockContainsBre
ak)) { | 12153 if (booleanLiteral.value && (blockReturns || !_enclosingBlockContainsBre
ak)) { |
12102 return true; | 12154 return true; |
12103 } | 12155 } |
12104 } | 12156 } |
12105 return false; | 12157 return false; |
12106 } finally { | 12158 } finally { |
12107 _enclosingBlockContainsBreak = outerBreakValue; | 12159 _enclosingBlockContainsBreak = outerBreakValue; |
12108 } | 12160 } |
12109 } | 12161 } |
12110 | 12162 |
12111 @override | 12163 @override |
12112 bool visitEmptyStatement(EmptyStatement node) => false; | 12164 bool visitEmptyStatement(EmptyStatement node) => false; |
12113 | 12165 |
12114 @override | 12166 @override |
12115 bool visitExpressionStatement(ExpressionStatement node) => node.expression.acc
ept(this); | 12167 bool visitExpressionStatement(ExpressionStatement node) => _nodeExits(node.exp
ression); |
12116 | 12168 |
12117 @override | 12169 @override |
12118 bool visitForEachStatement(ForEachStatement node) { | 12170 bool visitForEachStatement(ForEachStatement node) { |
12119 bool outerBreakValue = _enclosingBlockContainsBreak; | 12171 bool outerBreakValue = _enclosingBlockContainsBreak; |
12120 _enclosingBlockContainsBreak = false; | 12172 _enclosingBlockContainsBreak = false; |
12121 try { | 12173 try { |
12122 return node.iterator.accept(this); | 12174 return _nodeExits(node.iterator); |
12123 } finally { | 12175 } finally { |
12124 _enclosingBlockContainsBreak = outerBreakValue; | 12176 _enclosingBlockContainsBreak = outerBreakValue; |
12125 } | 12177 } |
12126 } | 12178 } |
12127 | 12179 |
12128 @override | 12180 @override |
12129 bool visitForStatement(ForStatement node) { | 12181 bool visitForStatement(ForStatement node) { |
12130 bool outerBreakValue = _enclosingBlockContainsBreak; | 12182 bool outerBreakValue = _enclosingBlockContainsBreak; |
12131 _enclosingBlockContainsBreak = false; | 12183 _enclosingBlockContainsBreak = false; |
12132 try { | 12184 try { |
12133 if (node.variables != null && _visitVariableDeclarations(node.variables.va
riables)) { | 12185 if (node.variables != null && _visitVariableDeclarations(node.variables.va
riables)) { |
12134 return true; | 12186 return true; |
12135 } | 12187 } |
12136 if (node.initialization != null && node.initialization.accept(this)) { | 12188 if (node.initialization != null && _nodeExits(node.initialization)) { |
12137 return true; | 12189 return true; |
12138 } | 12190 } |
12139 Expression conditionExpression = node.condition; | 12191 Expression conditionExpression = node.condition; |
12140 if (conditionExpression != null && conditionExpression.accept(this)) { | 12192 if (conditionExpression != null && _nodeExits(conditionExpression)) { |
12141 return true; | 12193 return true; |
12142 } | 12194 } |
12143 if (_visitExpressions(node.updaters)) { | 12195 if (_visitExpressions(node.updaters)) { |
12144 return true; | 12196 return true; |
12145 } | 12197 } |
12146 // TODO(jwren) Do we want to take all constant expressions into account? | 12198 // TODO(jwren) Do we want to take all constant expressions into account? |
12147 // If for(; true; ) (or for(;;)), and the body doesn't return or the body
doesn't have a | 12199 // If for(; true; ) (or for(;;)), and the body doesn't return or the body
doesn't have a |
12148 // break, then return true. | 12200 // break, then return true. |
12149 bool implicitOrExplictTrue = conditionExpression == null || (conditionExpr
ession is BooleanLiteral && conditionExpression.value); | 12201 bool implicitOrExplictTrue = conditionExpression == null || (conditionExpr
ession is BooleanLiteral && conditionExpression.value); |
12150 if (implicitOrExplictTrue) { | 12202 if (implicitOrExplictTrue) { |
12151 bool blockReturns = node.body.accept(this); | 12203 bool blockReturns = _nodeExits(node.body); |
12152 if (blockReturns || !_enclosingBlockContainsBreak) { | 12204 if (blockReturns || !_enclosingBlockContainsBreak) { |
12153 return true; | 12205 return true; |
12154 } | 12206 } |
12155 } | 12207 } |
12156 return false; | 12208 return false; |
12157 } finally { | 12209 } finally { |
12158 _enclosingBlockContainsBreak = outerBreakValue; | 12210 _enclosingBlockContainsBreak = outerBreakValue; |
12159 } | 12211 } |
12160 } | 12212 } |
12161 | 12213 |
12162 @override | 12214 @override |
12163 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => f
alse; | 12215 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => f
alse; |
12164 | 12216 |
12165 @override | 12217 @override |
12166 bool visitFunctionExpression(FunctionExpression node) => false; | 12218 bool visitFunctionExpression(FunctionExpression node) => false; |
12167 | 12219 |
12168 @override | 12220 @override |
12169 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 12221 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
12170 if (node.function.accept(this)) { | 12222 if (_nodeExits(node.function)) { |
12171 return true; | 12223 return true; |
12172 } | 12224 } |
12173 return node.argumentList.accept(this); | 12225 return node.argumentList.accept(this); |
12174 } | 12226 } |
12175 | 12227 |
12176 @override | 12228 @override |
12177 bool visitIdentifier(Identifier node) => false; | 12229 bool visitIdentifier(Identifier node) => false; |
12178 | 12230 |
12179 @override | 12231 @override |
12180 bool visitIfStatement(IfStatement node) { | 12232 bool visitIfStatement(IfStatement node) { |
12181 Expression conditionExpression = node.condition; | 12233 Expression conditionExpression = node.condition; |
12182 Statement thenStatement = node.thenStatement; | 12234 Statement thenStatement = node.thenStatement; |
12183 Statement elseStatement = node.elseStatement; | 12235 Statement elseStatement = node.elseStatement; |
12184 if (conditionExpression.accept(this)) { | 12236 if (_nodeExits(conditionExpression)) { |
12185 return true; | 12237 return true; |
12186 } | 12238 } |
12187 // TODO(jwren) Do we want to take all constant expressions into account? | 12239 // TODO(jwren) Do we want to take all constant expressions into account? |
12188 if (conditionExpression is BooleanLiteral) { | 12240 if (conditionExpression is BooleanLiteral) { |
12189 BooleanLiteral booleanLiteral = conditionExpression; | 12241 BooleanLiteral booleanLiteral = conditionExpression; |
12190 if (booleanLiteral.value) { | 12242 if (booleanLiteral.value) { |
12191 // if(true) ... | 12243 // if(true) ... |
12192 return thenStatement.accept(this); | 12244 return _nodeExits(thenStatement); |
12193 } else if (elseStatement != null) { | 12245 } else if (elseStatement != null) { |
12194 // if (false) ... | 12246 // if (false) ... |
12195 return elseStatement.accept(this); | 12247 return _nodeExits(elseStatement); |
12196 } | 12248 } |
12197 } | 12249 } |
12198 if (thenStatement == null || elseStatement == null) { | 12250 if (thenStatement == null || elseStatement == null) { |
12199 return false; | 12251 return false; |
12200 } | 12252 } |
12201 return thenStatement.accept(this) && elseStatement.accept(this); | 12253 return _nodeExits(thenStatement) && _nodeExits(elseStatement); |
12202 } | 12254 } |
12203 | 12255 |
12204 @override | 12256 @override |
12205 bool visitIndexExpression(IndexExpression node) { | 12257 bool visitIndexExpression(IndexExpression node) { |
12206 Expression target = node.realTarget; | 12258 Expression target = node.realTarget; |
12207 if (target != null && target.accept(this)) { | 12259 if (_nodeExits(target)) { |
12208 return true; | 12260 return true; |
12209 } | 12261 } |
12210 if (node.index.accept(this)) { | 12262 if (_nodeExits(node.index)) { |
12211 return true; | 12263 return true; |
12212 } | 12264 } |
12213 return false; | 12265 return false; |
12214 } | 12266 } |
12215 | 12267 |
12216 @override | 12268 @override |
12217 bool visitInstanceCreationExpression(InstanceCreationExpression node) => node.
argumentList.accept(this); | 12269 bool visitInstanceCreationExpression(InstanceCreationExpression node) => _node
Exits(node.argumentList); |
12218 | 12270 |
12219 @override | 12271 @override |
12220 bool visitIsExpression(IsExpression node) => node.expression.accept(this); | 12272 bool visitIsExpression(IsExpression node) => node.expression.accept(this); |
12221 | 12273 |
12222 @override | 12274 @override |
12223 bool visitLabel(Label node) => false; | 12275 bool visitLabel(Label node) => false; |
12224 | 12276 |
12225 @override | 12277 @override |
12226 bool visitLabeledStatement(LabeledStatement node) => node.statement.accept(thi
s); | 12278 bool visitLabeledStatement(LabeledStatement node) => node.statement.accept(thi
s); |
12227 | 12279 |
12228 @override | 12280 @override |
12229 bool visitLiteral(Literal node) => false; | 12281 bool visitLiteral(Literal node) => false; |
12230 | 12282 |
12231 @override | 12283 @override |
12232 bool visitMethodInvocation(MethodInvocation node) { | 12284 bool visitMethodInvocation(MethodInvocation node) { |
12233 Expression target = node.realTarget; | 12285 Expression target = node.realTarget; |
12234 if (target != null && target.accept(this)) { | 12286 if (target != null && target.accept(this)) { |
12235 return true; | 12287 return true; |
12236 } | 12288 } |
12237 return node.argumentList.accept(this); | 12289 return _nodeExits(node.argumentList); |
12238 } | 12290 } |
12239 | 12291 |
12240 @override | 12292 @override |
12241 bool visitNamedExpression(NamedExpression node) => node.expression.accept(this
); | 12293 bool visitNamedExpression(NamedExpression node) => node.expression.accept(this
); |
12242 | 12294 |
12243 @override | 12295 @override |
12244 bool visitParenthesizedExpression(ParenthesizedExpression node) => node.expres
sion.accept(this); | 12296 bool visitParenthesizedExpression(ParenthesizedExpression node) => node.expres
sion.accept(this); |
12245 | 12297 |
12246 @override | 12298 @override |
12247 bool visitPostfixExpression(PostfixExpression node) => false; | 12299 bool visitPostfixExpression(PostfixExpression node) => false; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12303 } | 12355 } |
12304 | 12356 |
12305 @override | 12357 @override |
12306 bool visitThisExpression(ThisExpression node) => false; | 12358 bool visitThisExpression(ThisExpression node) => false; |
12307 | 12359 |
12308 @override | 12360 @override |
12309 bool visitThrowExpression(ThrowExpression node) => true; | 12361 bool visitThrowExpression(ThrowExpression node) => true; |
12310 | 12362 |
12311 @override | 12363 @override |
12312 bool visitTryStatement(TryStatement node) { | 12364 bool visitTryStatement(TryStatement node) { |
12313 if (node.body.accept(this)) { | 12365 if (_nodeExits(node.body)) { |
12314 return true; | 12366 return true; |
12315 } | 12367 } |
12316 Block finallyBlock = node.finallyBlock; | 12368 Block finallyBlock = node.finallyBlock; |
12317 if (finallyBlock != null && finallyBlock.accept(this)) { | 12369 if (_nodeExits(finallyBlock)) { |
12318 return true; | 12370 return true; |
12319 } | 12371 } |
12320 return false; | 12372 return false; |
12321 } | 12373 } |
12322 | 12374 |
12323 @override | 12375 @override |
12324 bool visitTypeName(TypeName node) => false; | 12376 bool visitTypeName(TypeName node) => false; |
12325 | 12377 |
12326 @override | 12378 @override |
12327 bool visitVariableDeclaration(VariableDeclaration node) { | 12379 bool visitVariableDeclaration(VariableDeclaration node) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12364 if (booleanLiteral.value && (blockReturns || !_enclosingBlockContainsBre
ak)) { | 12416 if (booleanLiteral.value && (blockReturns || !_enclosingBlockContainsBre
ak)) { |
12365 return true; | 12417 return true; |
12366 } | 12418 } |
12367 } | 12419 } |
12368 return false; | 12420 return false; |
12369 } finally { | 12421 } finally { |
12370 _enclosingBlockContainsBreak = outerBreakValue; | 12422 _enclosingBlockContainsBreak = outerBreakValue; |
12371 } | 12423 } |
12372 } | 12424 } |
12373 | 12425 |
| 12426 /** |
| 12427 * Return `true` if the given node exits. |
| 12428 * |
| 12429 * @param node the node being tested |
| 12430 * @return `true` if the given node exits |
| 12431 */ |
| 12432 bool _nodeExits(AstNode node) { |
| 12433 if (node == null) { |
| 12434 return false; |
| 12435 } |
| 12436 return node.accept(this); |
| 12437 } |
| 12438 |
12374 bool _visitExpressions(NodeList<Expression> expressions) { | 12439 bool _visitExpressions(NodeList<Expression> expressions) { |
12375 for (int i = expressions.length - 1; i >= 0; i--) { | 12440 for (int i = expressions.length - 1; i >= 0; i--) { |
12376 if (expressions[i].accept(this)) { | 12441 if (expressions[i].accept(this)) { |
12377 return true; | 12442 return true; |
12378 } | 12443 } |
12379 } | 12444 } |
12380 return false; | 12445 return false; |
12381 } | 12446 } |
12382 | 12447 |
12383 bool _visitStatements(NodeList<Statement> statements) { | 12448 bool _visitStatements(NodeList<Statement> statements) { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12771 ht.XmlAttributeNode scriptAttribute = _getScriptSourcePath(node); | 12836 ht.XmlAttributeNode scriptAttribute = _getScriptSourcePath(node); |
12772 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute
.text; | 12837 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute
.text; |
12773 if (node.attributeEnd.type == ht.TokenType.GT && scriptSourcePath == null)
{ | 12838 if (node.attributeEnd.type == ht.TokenType.GT && scriptSourcePath == null)
{ |
12774 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl
(node); | 12839 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl
(node); |
12775 try { | 12840 try { |
12776 LibraryResolver resolver = new LibraryResolver(_context); | 12841 LibraryResolver resolver = new LibraryResolver(_context); |
12777 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc
e, _modificationStamp, node.script, true) as LibraryElementImpl; | 12842 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc
e, _modificationStamp, node.script, true) as LibraryElementImpl; |
12778 script.scriptLibrary = library; | 12843 script.scriptLibrary = library; |
12779 _resolvedLibraries.addAll(resolver.resolvedLibraries); | 12844 _resolvedLibraries.addAll(resolver.resolvedLibraries); |
12780 _errorListener.addAll(resolver.errorListener); | 12845 _errorListener.addAll(resolver.errorListener); |
12781 } on AnalysisException catch (exception) { | 12846 } on AnalysisException catch (exception, stackTrace) { |
12782 //TODO (danrubel): Handle or forward the exception | 12847 //TODO (danrubel): Handle or forward the exception |
12783 AnalysisEngine.instance.logger.logError2("Could not resolve script tag
", exception); | 12848 AnalysisEngine.instance.logger.logError2("Could not resolve script tag
", new CaughtException(exception, stackTrace)); |
12784 } | 12849 } |
12785 node.scriptElement = script; | 12850 node.scriptElement = script; |
12786 _scripts.add(script); | 12851 _scripts.add(script); |
12787 } else { | 12852 } else { |
12788 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl
(node); | 12853 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl
(node); |
12789 if (scriptSourcePath != null) { | 12854 if (scriptSourcePath != null) { |
12790 try { | 12855 try { |
12791 scriptSourcePath = Uri.encodeFull(scriptSourcePath); | 12856 scriptSourcePath = Uri.encodeFull(scriptSourcePath); |
12792 // Force an exception to be thrown if the URI is invalid so that we
can report the | 12857 // Force an exception to be thrown if the URI is invalid so that we
can report the |
12793 // problem. | 12858 // problem. |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13321 /** | 13386 /** |
13322 * Resolve the given node, reporting any errors or warnings to the given liste
ner. | 13387 * Resolve the given node, reporting any errors or warnings to the given liste
ner. |
13323 * | 13388 * |
13324 * @param node the root of the AST structure to be resolved | 13389 * @param node the root of the AST structure to be resolved |
13325 * @throws AnalysisException if the node could not be resolved | 13390 * @throws AnalysisException if the node could not be resolved |
13326 */ | 13391 */ |
13327 void resolve(AstNode node) { | 13392 void resolve(AstNode node) { |
13328 AstNode rootNode = _findResolutionRoot(node); | 13393 AstNode rootNode = _findResolutionRoot(node); |
13329 Scope scope = ScopeBuilder.scopeFor(rootNode, _errorListener); | 13394 Scope scope = ScopeBuilder.scopeFor(rootNode, _errorListener); |
13330 if (_elementModelChanged(rootNode.parent)) { | 13395 if (_elementModelChanged(rootNode.parent)) { |
13331 throw new AnalysisException.con1("Cannot resolve node: element model chang
ed"); | 13396 throw new AnalysisException("Cannot resolve node: element model changed"); |
13332 } | 13397 } |
13333 _resolveTypes(node, scope); | 13398 _resolveTypes(node, scope); |
13334 _resolveVariables(node, scope); | 13399 _resolveVariables(node, scope); |
13335 _resolveReferences(node, scope); | 13400 _resolveReferences(node, scope); |
13336 } | 13401 } |
13337 | 13402 |
13338 /** | 13403 /** |
13339 * Return `true` if the given node can be resolved independently of any other
nodes. | 13404 * Return `true` if the given node can be resolved independently of any other
nodes. |
13340 * | 13405 * |
13341 * <b>Note:</b> This method needs to be kept in sync with [ScopeBuilder#scopeF
orAstNode]. | 13406 * <b>Note:</b> This method needs to be kept in sync with [ScopeBuilder#scopeF
orAstNode]. |
13342 * | 13407 * |
13343 * @param node the node being tested | 13408 * @param node the node being tested |
13344 * @return `true` if the given node can be resolved independently of any other
nodes | 13409 * @return `true` if the given node can be resolved independently of any other
nodes |
13345 */ | 13410 */ |
13346 bool _canBeResolved(AstNode node) => node is ClassDeclaration || node is Class
TypeAlias || node is CompilationUnit || node is ConstructorDeclaration || node i
s FunctionDeclaration || node is FunctionTypeAlias || node is MethodDeclaration; | 13411 bool _canBeResolved(AstNode node) => node is ClassDeclaration || node is Class
TypeAlias || node is CompilationUnit || node is ConstructorDeclaration || node i
s FunctionDeclaration || node is FunctionTypeAlias || node is MethodDeclaration; |
13347 | 13412 |
13348 /** | 13413 /** |
13349 * Return `true` if the portion of the element model defined by the given node
has changed. | 13414 * Return `true` if the portion of the element model defined by the given node
has changed. |
13350 * | 13415 * |
13351 * @param node the node defining the portion of the element model being tested | 13416 * @param node the node defining the portion of the element model being tested |
13352 * @return `true` if the element model defined by the given node has changed | 13417 * @return `true` if the element model defined by the given node has changed |
13353 * @throws AnalysisException if the correctness of the element model cannot be
determined | 13418 * @throws AnalysisException if the correctness of the element model cannot be
determined |
13354 */ | 13419 */ |
13355 bool _elementModelChanged(AstNode node) { | 13420 bool _elementModelChanged(AstNode node) { |
13356 Element element = _getElement(node); | 13421 Element element = _getElement(node); |
13357 if (element == null) { | 13422 if (element == null) { |
13358 throw new AnalysisException.con1("Cannot resolve node: a ${node.runtimeTyp
e.toString()} does not define an element"); | 13423 throw new AnalysisException("Cannot resolve node: a ${node.runtimeType.toS
tring()} does not define an element"); |
13359 } | 13424 } |
13360 DeclarationMatcher matcher = new DeclarationMatcher(); | 13425 DeclarationMatcher matcher = new DeclarationMatcher(); |
13361 return !matcher.matches(node, element); | 13426 return !matcher.matches(node, element); |
13362 } | 13427 } |
13363 | 13428 |
13364 /** | 13429 /** |
13365 * Starting at the given node, find the smallest AST node that can be resolved
independently of | 13430 * Starting at the given node, find the smallest AST node that can be resolved
independently of |
13366 * any other nodes. Return the node that was found. | 13431 * any other nodes. Return the node that was found. |
13367 * | 13432 * |
13368 * @param node the node at which the search is to begin | 13433 * @param node the node at which the search is to begin |
13369 * @return the smallest AST node that can be resolved independently of any oth
er nodes | 13434 * @return the smallest AST node that can be resolved independently of any oth
er nodes |
13370 * @throws AnalysisException if there is no such node | 13435 * @throws AnalysisException if there is no such node |
13371 */ | 13436 */ |
13372 AstNode _findResolutionRoot(AstNode node) { | 13437 AstNode _findResolutionRoot(AstNode node) { |
13373 AstNode result = node; | 13438 AstNode result = node; |
13374 AstNode parent = result.parent; | 13439 AstNode parent = result.parent; |
13375 while (parent != null && !_canBeResolved(parent)) { | 13440 while (parent != null && !_canBeResolved(parent)) { |
13376 result = parent; | 13441 result = parent; |
13377 parent = result.parent; | 13442 parent = result.parent; |
13378 } | 13443 } |
13379 if (parent == null) { | 13444 if (parent == null) { |
13380 throw new AnalysisException.con1("Cannot resolve node: no resolvable node"
); | 13445 throw new AnalysisException("Cannot resolve node: no resolvable node"); |
13381 } | 13446 } |
13382 return result; | 13447 return result; |
13383 } | 13448 } |
13384 | 13449 |
13385 /** | 13450 /** |
13386 * Return the element defined by the given node, or `null` if the node does no
t define an | 13451 * Return the element defined by the given node, or `null` if the node does no
t define an |
13387 * element. | 13452 * element. |
13388 * | 13453 * |
13389 * @param node the node defining the element to be returned | 13454 * @param node the node defining the element to be returned |
13390 * @return the element defined by the given node | 13455 * @return the element defined by the given node |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14544 | 14609 |
14545 /** | 14610 /** |
14546 * Return the library element representing this library, creating it if necess
ary. | 14611 * Return the library element representing this library, creating it if necess
ary. |
14547 * | 14612 * |
14548 * @return the library element representing this library | 14613 * @return the library element representing this library |
14549 */ | 14614 */ |
14550 LibraryElementImpl get libraryElement { | 14615 LibraryElementImpl get libraryElement { |
14551 if (_libraryElement == null) { | 14616 if (_libraryElement == null) { |
14552 try { | 14617 try { |
14553 _libraryElement = _analysisContext.computeLibraryElement(librarySource)
as LibraryElementImpl; | 14618 _libraryElement = _analysisContext.computeLibraryElement(librarySource)
as LibraryElementImpl; |
14554 } on AnalysisException catch (exception) { | 14619 } on AnalysisException catch (exception, stackTrace) { |
14555 AnalysisEngine.instance.logger.logError2("Could not compute library elem
ent for ${librarySource.fullName}", exception); | 14620 AnalysisEngine.instance.logger.logError2("Could not compute library elem
ent for ${librarySource.fullName}", new CaughtException(exception, stackTrace)); |
14556 } | 14621 } |
14557 } | 14622 } |
14558 return _libraryElement; | 14623 return _libraryElement; |
14559 } | 14624 } |
14560 | 14625 |
14561 /** | 14626 /** |
14562 * Return the library scope used when resolving elements within this library's
compilation units. | 14627 * Return the library scope used when resolving elements within this library's
compilation units. |
14563 * | 14628 * |
14564 * @return the library scope used when resolving elements within this library'
s compilation units | 14629 * @return the library scope used when resolving elements within this library'
s compilation units |
14565 */ | 14630 */ |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15189 instrumentation.data3("fullName", librarySource.fullName); | 15254 instrumentation.data3("fullName", librarySource.fullName); |
15190 // | 15255 // |
15191 // Create the objects representing the library being resolved and the core
library. | 15256 // Create the objects representing the library being resolved and the core
library. |
15192 // | 15257 // |
15193 Library targetLibrary = _createLibraryWithUnit(librarySource, modification
Stamp, unit); | 15258 Library targetLibrary = _createLibraryWithUnit(librarySource, modification
Stamp, unit); |
15194 _coreLibrary = _libraryMap[_coreLibrarySource]; | 15259 _coreLibrary = _libraryMap[_coreLibrarySource]; |
15195 if (_coreLibrary == null) { | 15260 if (_coreLibrary == null) { |
15196 // This will be true unless the library being analyzed is the core libra
ry. | 15261 // This will be true unless the library being analyzed is the core libra
ry. |
15197 _coreLibrary = createLibrary(_coreLibrarySource); | 15262 _coreLibrary = createLibrary(_coreLibrarySource); |
15198 if (_coreLibrary == null) { | 15263 if (_coreLibrary == null) { |
15199 throw new AnalysisException.con1("Core library does not exist"); | 15264 throw new AnalysisException("Core library does not exist"); |
15200 } | 15265 } |
15201 } | 15266 } |
15202 instrumentation.metric3("createLibrary", "complete"); | 15267 instrumentation.metric3("createLibrary", "complete"); |
15203 // | 15268 // |
15204 // Compute the set of libraries that need to be resolved together. | 15269 // Compute the set of libraries that need to be resolved together. |
15205 // | 15270 // |
15206 _computeEmbeddedLibraryDependencies(targetLibrary, unit); | 15271 _computeEmbeddedLibraryDependencies(targetLibrary, unit); |
15207 _librariesInCycles = _computeLibrariesInCycles(targetLibrary); | 15272 _librariesInCycles = _computeLibrariesInCycles(targetLibrary); |
15208 // | 15273 // |
15209 // Build the element models representing the libraries being resolved. Thi
s is done in three | 15274 // Build the element models representing the libraries being resolved. Thi
s is done in three |
15210 // steps: | 15275 // steps: |
15211 // | 15276 // |
15212 // 1. Build the basic element models without making any connections betwee
n elements other than | 15277 // 1. Build the basic element models without making any connections betwee
n elements other than |
15213 // the basic parent/child relationships. This includes building the ele
ments representing the | 15278 // the basic parent/child relationships. This includes building the ele
ments representing the |
15214 // libraries. | 15279 // libraries. |
15215 // 2. Build the elements for the import and export directives. This requir
es that we have the | 15280 // 2. Build the elements for the import and export directives. This requir
es that we have the |
15216 // elements built for the referenced libraries, but because of the poss
ibility of circular | 15281 // elements built for the referenced libraries, but because of the poss
ibility of circular |
15217 // references needs to happen after all of the library elements have be
en created. | 15282 // references needs to happen after all of the library elements have be
en created. |
15218 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This | 15283 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This |
15219 // requires that we be able to compute the names visible in the librari
es being resolved, | 15284 // requires that we be able to compute the names visible in the librari
es being resolved, |
15220 // which in turn requires that we have resolved the import directives. | 15285 // which in turn requires that we have resolved the import directives. |
15221 // | 15286 // |
15222 _buildElementModels(); | 15287 _buildElementModels(); |
15223 instrumentation.metric3("buildElementModels", "complete"); | 15288 instrumentation.metric3("buildElementModels", "complete"); |
15224 LibraryElement coreElement = _coreLibrary.libraryElement; | 15289 LibraryElement coreElement = _coreLibrary.libraryElement; |
15225 if (coreElement == null) { | 15290 if (coreElement == null) { |
15226 throw new AnalysisException.con1("Could not resolve dart:core"); | 15291 throw new AnalysisException("Could not resolve dart:core"); |
15227 } | 15292 } |
15228 _buildDirectiveModels(); | 15293 _buildDirectiveModels(); |
15229 instrumentation.metric3("buildDirectiveModels", "complete"); | 15294 instrumentation.metric3("buildDirectiveModels", "complete"); |
15230 _typeProvider = new TypeProviderImpl(coreElement); | 15295 _typeProvider = new TypeProviderImpl(coreElement); |
15231 _buildTypeHierarchies(); | 15296 _buildTypeHierarchies(); |
15232 instrumentation.metric3("buildTypeHierarchies", "complete"); | 15297 instrumentation.metric3("buildTypeHierarchies", "complete"); |
15233 // | 15298 // |
15234 // Perform resolution and type analysis. | 15299 // Perform resolution and type analysis. |
15235 // | 15300 // |
15236 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we | 15301 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15273 instrumentation.data3("fullName", librarySource.fullName); | 15338 instrumentation.data3("fullName", librarySource.fullName); |
15274 // | 15339 // |
15275 // Create the objects representing the library being resolved and the core
library. | 15340 // Create the objects representing the library being resolved and the core
library. |
15276 // | 15341 // |
15277 Library targetLibrary = createLibrary(librarySource); | 15342 Library targetLibrary = createLibrary(librarySource); |
15278 _coreLibrary = _libraryMap[_coreLibrarySource]; | 15343 _coreLibrary = _libraryMap[_coreLibrarySource]; |
15279 if (_coreLibrary == null) { | 15344 if (_coreLibrary == null) { |
15280 // This will be true unless the library being analyzed is the core libra
ry. | 15345 // This will be true unless the library being analyzed is the core libra
ry. |
15281 _coreLibrary = _createLibraryOrNull(_coreLibrarySource); | 15346 _coreLibrary = _createLibraryOrNull(_coreLibrarySource); |
15282 if (_coreLibrary == null) { | 15347 if (_coreLibrary == null) { |
15283 throw new AnalysisException.con1("Core library does not exist"); | 15348 throw new AnalysisException("Core library does not exist"); |
15284 } | 15349 } |
15285 } | 15350 } |
15286 instrumentation.metric3("createLibrary", "complete"); | 15351 instrumentation.metric3("createLibrary", "complete"); |
15287 // | 15352 // |
15288 // Compute the set of libraries that need to be resolved together. | 15353 // Compute the set of libraries that need to be resolved together. |
15289 // | 15354 // |
15290 _computeLibraryDependencies(targetLibrary); | 15355 _computeLibraryDependencies(targetLibrary); |
15291 _librariesInCycles = _computeLibrariesInCycles(targetLibrary); | 15356 _librariesInCycles = _computeLibrariesInCycles(targetLibrary); |
15292 // | 15357 // |
15293 // Build the element models representing the libraries being resolved. Thi
s is done in three | 15358 // Build the element models representing the libraries being resolved. Thi
s is done in three |
15294 // steps: | 15359 // steps: |
15295 // | 15360 // |
15296 // 1. Build the basic element models without making any connections betwee
n elements other than | 15361 // 1. Build the basic element models without making any connections betwee
n elements other than |
15297 // the basic parent/child relationships. This includes building the ele
ments representing the | 15362 // the basic parent/child relationships. This includes building the ele
ments representing the |
15298 // libraries. | 15363 // libraries. |
15299 // 2. Build the elements for the import and export directives. This requir
es that we have the | 15364 // 2. Build the elements for the import and export directives. This requir
es that we have the |
15300 // elements built for the referenced libraries, but because of the poss
ibility of circular | 15365 // elements built for the referenced libraries, but because of the poss
ibility of circular |
15301 // references needs to happen after all of the library elements have be
en created. | 15366 // references needs to happen after all of the library elements have be
en created. |
15302 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This | 15367 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This |
15303 // requires that we be able to compute the names visible in the librari
es being resolved, | 15368 // requires that we be able to compute the names visible in the librari
es being resolved, |
15304 // which in turn requires that we have resolved the import directives. | 15369 // which in turn requires that we have resolved the import directives. |
15305 // | 15370 // |
15306 _buildElementModels(); | 15371 _buildElementModels(); |
15307 instrumentation.metric3("buildElementModels", "complete"); | 15372 instrumentation.metric3("buildElementModels", "complete"); |
15308 LibraryElement coreElement = _coreLibrary.libraryElement; | 15373 LibraryElement coreElement = _coreLibrary.libraryElement; |
15309 if (coreElement == null) { | 15374 if (coreElement == null) { |
15310 throw new AnalysisException.con1("Could not resolve dart:core"); | 15375 throw new AnalysisException("Could not resolve dart:core"); |
15311 } | 15376 } |
15312 _buildDirectiveModels(); | 15377 _buildDirectiveModels(); |
15313 instrumentation.metric3("buildDirectiveModels", "complete"); | 15378 instrumentation.metric3("buildDirectiveModels", "complete"); |
15314 _typeProvider = new TypeProviderImpl(coreElement); | 15379 _typeProvider = new TypeProviderImpl(coreElement); |
15315 _buildTypeHierarchies(); | 15380 _buildTypeHierarchies(); |
15316 instrumentation.metric3("buildTypeHierarchies", "complete"); | 15381 instrumentation.metric3("buildTypeHierarchies", "complete"); |
15317 // | 15382 // |
15318 // Perform resolution and type analysis. | 15383 // Perform resolution and type analysis. |
15319 // | 15384 // |
15320 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we | 15385 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15753 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); | 15818 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); |
15754 try { | 15819 try { |
15755 ConstantValueComputer computer = new ConstantValueComputer(_typeProvider); | 15820 ConstantValueComputer computer = new ConstantValueComputer(_typeProvider); |
15756 for (Library library in _librariesInCycles) { | 15821 for (Library library in _librariesInCycles) { |
15757 for (Source source in library.compilationUnitSources) { | 15822 for (Source source in library.compilationUnitSources) { |
15758 try { | 15823 try { |
15759 CompilationUnit unit = library.getAST(source); | 15824 CompilationUnit unit = library.getAST(source); |
15760 if (unit != null) { | 15825 if (unit != null) { |
15761 computer.add(unit); | 15826 computer.add(unit); |
15762 } | 15827 } |
15763 } on AnalysisException catch (exception) { | 15828 } on AnalysisException catch (exception, stackTrace) { |
15764 AnalysisEngine.instance.logger.logError2("Internal Error: Could not
access AST for ${source.fullName} during constant evaluation", exception); | 15829 AnalysisEngine.instance.logger.logError2("Internal Error: Could not
access AST for ${source.fullName} during constant evaluation", new CaughtExcepti
on(exception, stackTrace)); |
15765 } | 15830 } |
15766 } | 15831 } |
15767 } | 15832 } |
15768 computer.computeValues(); | 15833 computer.computeValues(); |
15769 } finally { | 15834 } finally { |
15770 timeCounter.stop(); | 15835 timeCounter.stop(); |
15771 } | 15836 } |
15772 } | 15837 } |
15773 | 15838 |
15774 /** | 15839 /** |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15948 // elements built for the referenced libraries, but because of the poss
ibility of circular | 16013 // elements built for the referenced libraries, but because of the poss
ibility of circular |
15949 // references needs to happen after all of the library elements have be
en created. | 16014 // references needs to happen after all of the library elements have be
en created. |
15950 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This | 16015 // 3. Build the rest of the type model by connecting superclasses, mixins,
and interfaces. This |
15951 // requires that we be able to compute the names visible in the librari
es being resolved, | 16016 // requires that we be able to compute the names visible in the librari
es being resolved, |
15952 // which in turn requires that we have resolved the import directives. | 16017 // which in turn requires that we have resolved the import directives. |
15953 // | 16018 // |
15954 _buildElementModels(); | 16019 _buildElementModels(); |
15955 instrumentation.metric3("buildElementModels", "complete"); | 16020 instrumentation.metric3("buildElementModels", "complete"); |
15956 LibraryElement coreElement = _coreLibrary.libraryElement; | 16021 LibraryElement coreElement = _coreLibrary.libraryElement; |
15957 if (coreElement == null) { | 16022 if (coreElement == null) { |
15958 throw new AnalysisException.con1("Could not resolve dart:core"); | 16023 throw new AnalysisException("Could not resolve dart:core"); |
15959 } | 16024 } |
15960 _buildDirectiveModels(); | 16025 _buildDirectiveModels(); |
15961 instrumentation.metric3("buildDirectiveModels", "complete"); | 16026 instrumentation.metric3("buildDirectiveModels", "complete"); |
15962 _typeProvider = new TypeProviderImpl(coreElement); | 16027 _typeProvider = new TypeProviderImpl(coreElement); |
15963 _buildTypeHierarchies(); | 16028 _buildTypeHierarchies(); |
15964 instrumentation.metric3("buildTypeHierarchies", "complete"); | 16029 instrumentation.metric3("buildTypeHierarchies", "complete"); |
15965 // | 16030 // |
15966 // Perform resolution and type analysis. | 16031 // Perform resolution and type analysis. |
15967 // | 16032 // |
15968 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we | 16033 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we |
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19073 * Return the scope in which the given AST structure should be resolved. | 19138 * Return the scope in which the given AST structure should be resolved. |
19074 * | 19139 * |
19075 * @param node the root of the AST structure to be resolved | 19140 * @param node the root of the AST structure to be resolved |
19076 * @param errorListener the listener to which analysis errors will be reported | 19141 * @param errorListener the listener to which analysis errors will be reported |
19077 * @return the scope in which the given AST structure should be resolved | 19142 * @return the scope in which the given AST structure should be resolved |
19078 * @throws AnalysisException if the AST structure has not been resolved or is
not part of a | 19143 * @throws AnalysisException if the AST structure has not been resolved or is
not part of a |
19079 * [CompilationUnit] | 19144 * [CompilationUnit] |
19080 */ | 19145 */ |
19081 static Scope scopeFor(AstNode node, AnalysisErrorListener errorListener) { | 19146 static Scope scopeFor(AstNode node, AnalysisErrorListener errorListener) { |
19082 if (node == null) { | 19147 if (node == null) { |
19083 throw new AnalysisException.con1("Cannot create scope: node is null"); | 19148 throw new AnalysisException("Cannot create scope: node is null"); |
19084 } else if (node is CompilationUnit) { | 19149 } else if (node is CompilationUnit) { |
19085 ScopeBuilder builder = new ScopeBuilder(errorListener); | 19150 ScopeBuilder builder = new ScopeBuilder(errorListener); |
19086 return builder._scopeForAstNode(node); | 19151 return builder._scopeForAstNode(node); |
19087 } | 19152 } |
19088 AstNode parent = node.parent; | 19153 AstNode parent = node.parent; |
19089 if (parent == null) { | 19154 if (parent == null) { |
19090 throw new AnalysisException.con1("Cannot create scope: node is not part of
a CompilationUnit"); | 19155 throw new AnalysisException("Cannot create scope: node is not part of a Co
mpilationUnit"); |
19091 } | 19156 } |
19092 ScopeBuilder builder = new ScopeBuilder(errorListener); | 19157 ScopeBuilder builder = new ScopeBuilder(errorListener); |
19093 return builder._scopeForAstNode(parent); | 19158 return builder._scopeForAstNode(parent); |
19094 } | 19159 } |
19095 | 19160 |
19096 /** | 19161 /** |
19097 * The listener to which analysis errors will be reported. | 19162 * The listener to which analysis errors will be reported. |
19098 */ | 19163 */ |
19099 final AnalysisErrorListener _errorListener; | 19164 final AnalysisErrorListener _errorListener; |
19100 | 19165 |
(...skipping 15 matching lines...) Expand all Loading... |
19116 * @return the scope in which the given AST structure should be resolved | 19181 * @return the scope in which the given AST structure should be resolved |
19117 * @throws AnalysisException if the AST structure has not been resolved or is
not part of a | 19182 * @throws AnalysisException if the AST structure has not been resolved or is
not part of a |
19118 * [CompilationUnit] | 19183 * [CompilationUnit] |
19119 */ | 19184 */ |
19120 Scope _scopeForAstNode(AstNode node) { | 19185 Scope _scopeForAstNode(AstNode node) { |
19121 if (node is CompilationUnit) { | 19186 if (node is CompilationUnit) { |
19122 return _scopeForCompilationUnit(node); | 19187 return _scopeForCompilationUnit(node); |
19123 } | 19188 } |
19124 AstNode parent = node.parent; | 19189 AstNode parent = node.parent; |
19125 if (parent == null) { | 19190 if (parent == null) { |
19126 throw new AnalysisException.con1("Cannot create scope: node is not part of
a CompilationUnit"); | 19191 throw new AnalysisException("Cannot create scope: node is not part of a Co
mpilationUnit"); |
19127 } | 19192 } |
19128 Scope scope = _scopeForAstNode(parent); | 19193 Scope scope = _scopeForAstNode(parent); |
19129 if (node is ClassDeclaration) { | 19194 if (node is ClassDeclaration) { |
19130 ClassElement element = node.element; | 19195 ClassElement element = node.element; |
19131 if (element == null) { | 19196 if (element == null) { |
19132 throw new AnalysisException.con1("Cannot build a scope for an unresolved
class"); | 19197 throw new AnalysisException("Cannot build a scope for an unresolved clas
s"); |
19133 } | 19198 } |
19134 scope = new ClassScope(scope, element); | 19199 scope = new ClassScope(scope, element); |
19135 } else if (node is ClassTypeAlias) { | 19200 } else if (node is ClassTypeAlias) { |
19136 ClassElement element = node.element; | 19201 ClassElement element = node.element; |
19137 if (element == null) { | 19202 if (element == null) { |
19138 throw new AnalysisException.con1("Cannot build a scope for an unresolved
class type alias"); | 19203 throw new AnalysisException("Cannot build a scope for an unresolved clas
s type alias"); |
19139 } | 19204 } |
19140 scope = new ClassScope(scope, element); | 19205 scope = new ClassScope(scope, element); |
19141 } else if (node is ConstructorDeclaration) { | 19206 } else if (node is ConstructorDeclaration) { |
19142 ConstructorElement element = node.element; | 19207 ConstructorElement element = node.element; |
19143 if (element == null) { | 19208 if (element == null) { |
19144 throw new AnalysisException.con1("Cannot build a scope for an unresolved
constructor"); | 19209 throw new AnalysisException("Cannot build a scope for an unresolved cons
tructor"); |
19145 } | 19210 } |
19146 FunctionScope functionScope = new FunctionScope(scope, element); | 19211 FunctionScope functionScope = new FunctionScope(scope, element); |
19147 functionScope.defineParameters(); | 19212 functionScope.defineParameters(); |
19148 scope = functionScope; | 19213 scope = functionScope; |
19149 } else if (node is FunctionDeclaration) { | 19214 } else if (node is FunctionDeclaration) { |
19150 ExecutableElement element = node.element; | 19215 ExecutableElement element = node.element; |
19151 if (element == null) { | 19216 if (element == null) { |
19152 throw new AnalysisException.con1("Cannot build a scope for an unresolved
function"); | 19217 throw new AnalysisException("Cannot build a scope for an unresolved func
tion"); |
19153 } | 19218 } |
19154 FunctionScope functionScope = new FunctionScope(scope, element); | 19219 FunctionScope functionScope = new FunctionScope(scope, element); |
19155 functionScope.defineParameters(); | 19220 functionScope.defineParameters(); |
19156 scope = functionScope; | 19221 scope = functionScope; |
19157 } else if (node is FunctionTypeAlias) { | 19222 } else if (node is FunctionTypeAlias) { |
19158 scope = new FunctionTypeScope(scope, node.element); | 19223 scope = new FunctionTypeScope(scope, node.element); |
19159 } else if (node is MethodDeclaration) { | 19224 } else if (node is MethodDeclaration) { |
19160 ExecutableElement element = node.element; | 19225 ExecutableElement element = node.element; |
19161 if (element == null) { | 19226 if (element == null) { |
19162 throw new AnalysisException.con1("Cannot build a scope for an unresolved
method"); | 19227 throw new AnalysisException("Cannot build a scope for an unresolved meth
od"); |
19163 } | 19228 } |
19164 FunctionScope functionScope = new FunctionScope(scope, element); | 19229 FunctionScope functionScope = new FunctionScope(scope, element); |
19165 functionScope.defineParameters(); | 19230 functionScope.defineParameters(); |
19166 scope = functionScope; | 19231 scope = functionScope; |
19167 } | 19232 } |
19168 return scope; | 19233 return scope; |
19169 } | 19234 } |
19170 | 19235 |
19171 Scope _scopeForCompilationUnit(CompilationUnit node) { | 19236 Scope _scopeForCompilationUnit(CompilationUnit node) { |
19172 CompilationUnitElement unitElement = node.element; | 19237 CompilationUnitElement unitElement = node.element; |
19173 if (unitElement == null) { | 19238 if (unitElement == null) { |
19174 throw new AnalysisException.con1("Cannot create scope: compilation unit is
not resolved"); | 19239 throw new AnalysisException("Cannot create scope: compilation unit is not
resolved"); |
19175 } | 19240 } |
19176 LibraryElement libraryElement = unitElement.library; | 19241 LibraryElement libraryElement = unitElement.library; |
19177 if (libraryElement == null) { | 19242 if (libraryElement == null) { |
19178 throw new AnalysisException.con1("Cannot create scope: compilation unit is
not part of a library"); | 19243 throw new AnalysisException("Cannot create scope: compilation unit is not
part of a library"); |
19179 } | 19244 } |
19180 return new LibraryScope(libraryElement, _errorListener); | 19245 return new LibraryScope(libraryElement, _errorListener); |
19181 } | 19246 } |
19182 } | 19247 } |
19183 | 19248 |
19184 /** | 19249 /** |
19185 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST
structure is | 19250 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST
structure is |
19186 * being visited. | 19251 * being visited. |
19187 */ | 19252 */ |
19188 abstract class ScopedVisitor extends UnifyingAstVisitor<Object> { | 19253 abstract class ScopedVisitor extends UnifyingAstVisitor<Object> { |
(...skipping 4306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23495 parameterImpl.markPotentiallyMutatedInScope(); | 23560 parameterImpl.markPotentiallyMutatedInScope(); |
23496 // If we are in some closure, check if it is not the same as where varia
ble is declared. | 23561 // If we are in some closure, check if it is not the same as where varia
ble is declared. |
23497 if (_enclosingFunction != null && (element.enclosingElement != _enclosin
gFunction)) { | 23562 if (_enclosingFunction != null && (element.enclosingElement != _enclosin
gFunction)) { |
23498 parameterImpl.markPotentiallyMutatedInClosure(); | 23563 parameterImpl.markPotentiallyMutatedInClosure(); |
23499 } | 23564 } |
23500 } | 23565 } |
23501 } | 23566 } |
23502 return null; | 23567 return null; |
23503 } | 23568 } |
23504 } | 23569 } |
OLD | NEW |