| 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.constant; | 8 library engine.constant; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 */ | 543 */ |
| 544 void _computeValueFor(AstNode constNode) { | 544 void _computeValueFor(AstNode constNode) { |
| 545 beforeComputeValue(constNode); | 545 beforeComputeValue(constNode); |
| 546 if (constNode is VariableDeclaration) { | 546 if (constNode is VariableDeclaration) { |
| 547 VariableDeclaration declaration = constNode; | 547 VariableDeclaration declaration = constNode; |
| 548 VariableElement element = declaration.element; | 548 VariableElement element = declaration.element; |
| 549 RecordingErrorListener errorListener = new RecordingErrorListener(); | 549 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 550 ErrorReporter errorReporter = new ErrorReporter(errorListener, element.sou
rce); | 550 ErrorReporter errorReporter = new ErrorReporter(errorListener, element.sou
rce); |
| 551 DartObjectImpl dartObject = declaration.initializer.accept(createConstantV
isitor(errorReporter)); | 551 DartObjectImpl dartObject = declaration.initializer.accept(createConstantV
isitor(errorReporter)); |
| 552 if (dartObject != null) { | 552 if (dartObject != null) { |
| 553 if (!dartObject.isNull && !dartObject.type.isSubtypeOf(element.type)) { | 553 if (!_runtimeTypeMatch(dartObject, element.type)) { |
| 554 errorReporter.reportErrorForNode( | 554 errorReporter.reportErrorForNode( |
| 555 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 555 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 556 declaration, [dartObject.type, element.type]); | 556 declaration, [dartObject.type, element.type]); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 (element as VariableElementImpl).evaluationResult = new EvaluationResultIm
pl.con2(dartObject, errorListener.errors); | 559 (element as VariableElementImpl).evaluationResult = new EvaluationResultIm
pl.con2(dartObject, errorListener.errors); |
| 560 } else if (constNode is InstanceCreationExpression) { | 560 } else if (constNode is InstanceCreationExpression) { |
| 561 InstanceCreationExpression expression = constNode; | 561 InstanceCreationExpression expression = constNode; |
| 562 ConstructorElement constructor = expression.staticElement; | 562 ConstructorElement constructor = expression.staticElement; |
| 563 if (constructor == null) { | 563 if (constructor == null) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 beforeGetParameterDefault(baseParameter); | 726 beforeGetParameterDefault(baseParameter); |
| 727 EvaluationResultImpl evaluationResult = (baseParameter as ParameterEleme
ntImpl).evaluationResult; | 727 EvaluationResultImpl evaluationResult = (baseParameter as ParameterEleme
ntImpl).evaluationResult; |
| 728 if (evaluationResult == null) { | 728 if (evaluationResult == null) { |
| 729 // No default was provided, so the default value is null. | 729 // No default was provided, so the default value is null. |
| 730 argumentValue = constantVisitor.null2; | 730 argumentValue = constantVisitor.null2; |
| 731 } else if (evaluationResult.value != null) { | 731 } else if (evaluationResult.value != null) { |
| 732 argumentValue = evaluationResult.value; | 732 argumentValue = evaluationResult.value; |
| 733 } | 733 } |
| 734 } | 734 } |
| 735 if (argumentValue != null) { | 735 if (argumentValue != null) { |
| 736 if (!argumentValue.isNull && !argumentValue.type.isSubtypeOf(parameter.t
ype)) { | 736 if (!_runtimeTypeMatch(argumentValue, parameter.type)) { |
| 737 errorReporter.reportErrorForNode( | 737 errorReporter.reportErrorForNode( |
| 738 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA
TCH, | 738 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA
TCH, |
| 739 errorTarget, | 739 errorTarget, |
| 740 [argumentValue.type, parameter.type]); | 740 [argumentValue.type, parameter.type]); |
| 741 } | 741 } |
| 742 if (baseParameter.isInitializingFormal) { | 742 if (baseParameter.isInitializingFormal) { |
| 743 FieldElement field = (parameter as FieldFormalParameterElement).field; | 743 FieldElement field = (parameter as FieldFormalParameterElement).field; |
| 744 if (field != null) { | 744 if (field != null) { |
| 745 DartType fieldType = field.type; | 745 DartType fieldType = field.type; |
| 746 if (fieldType != parameter.type) { | 746 if (fieldType != parameter.type) { |
| 747 // We've already checked that the argument can be assigned to the | 747 // We've already checked that the argument can be assigned to the |
| 748 // parameter; we also need to check that it can be assigned to | 748 // parameter; we also need to check that it can be assigned to |
| 749 // the field. | 749 // the field. |
| 750 if (!argumentValue.isNull && | 750 if (!_runtimeTypeMatch(argumentValue, fieldType)) { |
| 751 !argumentValue.type.isSubtypeOf(fieldType)) { | |
| 752 errorReporter.reportErrorForNode( | 751 errorReporter.reportErrorForNode( |
| 753 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE
_MISMATCH, | 752 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE
_MISMATCH, |
| 754 errorTarget, | 753 errorTarget, |
| 755 [argumentValue.type, fieldType]); | 754 [argumentValue.type, fieldType]); |
| 756 } | 755 } |
| 757 } | 756 } |
| 758 String fieldName = field.name; | 757 String fieldName = field.name; |
| 759 fieldMap[fieldName] = argumentValue; | 758 fieldMap[fieldName] = argumentValue; |
| 760 } | 759 } |
| 761 } else { | 760 } else { |
| 762 String name = baseParameter.name; | 761 String name = baseParameter.name; |
| 763 parameterMap[name] = argumentValue; | 762 parameterMap[name] = argumentValue; |
| 764 } | 763 } |
| 765 } | 764 } |
| 766 } | 765 } |
| 767 ConstantVisitor initializerVisitor = new ConstantVisitor.con2(typeProvider,
parameterMap, errorReporter); | 766 ConstantVisitor initializerVisitor = new ConstantVisitor.con2(typeProvider,
parameterMap, errorReporter); |
| 768 String superName = null; | 767 String superName = null; |
| 769 NodeList<Expression> superArguments = null; | 768 NodeList<Expression> superArguments = null; |
| 770 for (ConstructorInitializer initializer in initializers) { | 769 for (ConstructorInitializer initializer in initializers) { |
| 771 if (initializer is ConstructorFieldInitializer) { | 770 if (initializer is ConstructorFieldInitializer) { |
| 772 ConstructorFieldInitializer constructorFieldInitializer = initializer; | 771 ConstructorFieldInitializer constructorFieldInitializer = initializer; |
| 773 Expression initializerExpression = constructorFieldInitializer.expressio
n; | 772 Expression initializerExpression = constructorFieldInitializer.expressio
n; |
| 774 DartObjectImpl evaluationResult = initializerExpression.accept(initializ
erVisitor); | 773 DartObjectImpl evaluationResult = initializerExpression.accept(initializ
erVisitor); |
| 775 if (evaluationResult != null) { | 774 if (evaluationResult != null) { |
| 776 String fieldName = constructorFieldInitializer.fieldName.name; | 775 String fieldName = constructorFieldInitializer.fieldName.name; |
| 777 fieldMap[fieldName] = evaluationResult; | 776 fieldMap[fieldName] = evaluationResult; |
| 778 PropertyAccessorElement getter = definingClass.getGetter(fieldName); | 777 PropertyAccessorElement getter = definingClass.getGetter(fieldName); |
| 779 if (getter != null) { | 778 if (getter != null) { |
| 780 PropertyInducingElement field = getter.variable; | 779 PropertyInducingElement field = getter.variable; |
| 781 if (!evaluationResult.isNull && | 780 if (!_runtimeTypeMatch(evaluationResult, field.type)) { |
| 782 !evaluationResult.type.isSubtypeOf(field.type)) { | |
| 783 errorReporter.reportErrorForNode( | 781 errorReporter.reportErrorForNode( |
| 784 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_M
ISMATCH, | 782 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_M
ISMATCH, |
| 785 node, [evaluationResult.type, fieldName, field.type]); | 783 node, [evaluationResult.type, fieldName, field.type]); |
| 786 } | 784 } |
| 787 } | 785 } |
| 788 } | 786 } |
| 789 } else if (initializer is SuperConstructorInvocation) { | 787 } else if (initializer is SuperConstructorInvocation) { |
| 790 SuperConstructorInvocation superConstructorInvocation = initializer; | 788 SuperConstructorInvocation superConstructorInvocation = initializer; |
| 791 SimpleIdentifier name = superConstructorInvocation.constructorName; | 789 SimpleIdentifier name = superConstructorInvocation.constructorName; |
| 792 if (name != null) { | 790 if (name != null) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 void _generateCycleError(List<AstNode> constantsInCycle, AstNode constant) { | 867 void _generateCycleError(List<AstNode> constantsInCycle, AstNode constant) { |
| 870 // TODO(brianwilkerson) Implement this. | 868 // TODO(brianwilkerson) Implement this. |
| 871 } | 869 } |
| 872 | 870 |
| 873 ConstructorElement _getConstructorBase(ConstructorElement constructor) { | 871 ConstructorElement _getConstructorBase(ConstructorElement constructor) { |
| 874 while (constructor is ConstructorMember) { | 872 while (constructor is ConstructorMember) { |
| 875 constructor = (constructor as ConstructorMember).baseElement; | 873 constructor = (constructor as ConstructorMember).baseElement; |
| 876 } | 874 } |
| 877 return constructor; | 875 return constructor; |
| 878 } | 876 } |
| 877 |
| 878 /** |
| 879 * Check if the object [obj] matches the type [type] according |
| 880 * to runtime type checking rules. |
| 881 */ |
| 882 bool _runtimeTypeMatch(DartObjectImpl obj, DartType type) { |
| 883 if (obj.isNull) { |
| 884 return true; |
| 885 } |
| 886 if (type.isUndefined) { |
| 887 return false; |
| 888 } |
| 889 return obj.type.isSubtypeOf(type); |
| 890 } |
| 879 } | 891 } |
| 880 | 892 |
| 881 /** | 893 /** |
| 882 * [AstCloner] that copies the necessary information from the AST to allow const
constructor | 894 * [AstCloner] that copies the necessary information from the AST to allow const
constructor |
| 883 * initializers to be evaluated. | 895 * initializers to be evaluated. |
| 884 */ | 896 */ |
| 885 class ConstantValueComputer_InitializerCloner extends AstCloner { | 897 class ConstantValueComputer_InitializerCloner extends AstCloner { |
| 886 @override | 898 @override |
| 887 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp
ression node) { | 899 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp
ression node) { |
| 888 InstanceCreationExpression expression = super.visitInstanceCreationExpressio
n(node); | 900 InstanceCreationExpression expression = super.visitInstanceCreationExpressio
n(node); |
| (...skipping 3755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4644 | 4656 |
| 4645 @override | 4657 @override |
| 4646 String get typeName => "Type"; | 4658 String get typeName => "Type"; |
| 4647 | 4659 |
| 4648 @override | 4660 @override |
| 4649 int get hashCode => _element == null ? 0 : _element.hashCode; | 4661 int get hashCode => _element == null ? 0 : _element.hashCode; |
| 4650 | 4662 |
| 4651 @override | 4663 @override |
| 4652 String toString() => _element == null ? "-unknown-" : _element.name; | 4664 String toString() => _element == null ? "-unknown-" : _element.name; |
| 4653 } | 4665 } |
| OLD | NEW |