Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * Return the boolean state representing the given boolean [value]. | 140 * Return the boolean state representing the given boolean [value]. |
| 141 */ | 141 */ |
| 142 static BoolState from(bool value) => | 142 static BoolState from(bool value) => |
| 143 value ? BoolState.TRUE_STATE : BoolState.FALSE_STATE; | 143 value ? BoolState.TRUE_STATE : BoolState.FALSE_STATE; |
| 144 } | 144 } |
| 145 | 145 |
| 146 /** | 146 /** |
| 147 * An [AstCloner] that copies the necessary information from the AST to allow | 147 * An [AstCloner] that copies the necessary information from the AST to allow |
| 148 * const constructor initializers to be evaluated. | 148 * constants to be evaluated. |
| 149 */ | 149 */ |
| 150 class ConstantAstCloner extends AstCloner { | 150 class ConstantAstCloner extends AstCloner { |
| 151 ConstantAstCloner() : super(true); | 151 ConstantAstCloner() : super(true); |
| 152 | 152 |
| 153 @override | 153 @override |
| 154 InstanceCreationExpression visitInstanceCreationExpression( | 154 InstanceCreationExpression visitInstanceCreationExpression( |
| 155 InstanceCreationExpression node) { | 155 InstanceCreationExpression node) { |
| 156 InstanceCreationExpression expression = | 156 InstanceCreationExpression expression = |
| 157 super.visitInstanceCreationExpression(node); | 157 super.visitInstanceCreationExpression(node); |
| 158 expression.evaluationResult = node.evaluationResult; | 158 expression.constantHandle = node.constantHandle; |
| 159 return expression; | 159 return expression; |
| 160 } | 160 } |
| 161 | 161 |
| 162 @override | 162 @override |
| 163 RedirectingConstructorInvocation visitRedirectingConstructorInvocation( | 163 RedirectingConstructorInvocation visitRedirectingConstructorInvocation( |
| 164 RedirectingConstructorInvocation node) { | 164 RedirectingConstructorInvocation node) { |
| 165 RedirectingConstructorInvocation invocation = | 165 RedirectingConstructorInvocation invocation = |
| 166 super.visitRedirectingConstructorInvocation(node); | 166 super.visitRedirectingConstructorInvocation(node); |
| 167 invocation.staticElement = node.staticElement; | 167 invocation.staticElement = node.staticElement; |
| 168 return invocation; | 168 return invocation; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 * A visitor used to traverse the AST structures of all of the compilation units | 275 * A visitor used to traverse the AST structures of all of the compilation units |
| 276 * being resolved and build tables of the constant variables, constant | 276 * being resolved and build tables of the constant variables, constant |
| 277 * constructors, constant constructor invocations, and annotations found in | 277 * constructors, constant constructor invocations, and annotations found in |
| 278 * those compilation units. | 278 * those compilation units. |
| 279 */ | 279 */ |
| 280 class ConstantFinder extends RecursiveAstVisitor<Object> { | 280 class ConstantFinder extends RecursiveAstVisitor<Object> { |
| 281 /** | 281 /** |
| 282 * A table mapping constant variable elements to the declarations of those | 282 * A table mapping constant variable elements to the declarations of those |
| 283 * variables. | 283 * variables. |
| 284 */ | 284 */ |
| 285 final HashMap<VariableElement, VariableDeclaration> variableMap = | 285 final HashMap<PotentiallyConstVariableElementImpl, VariableDeclaration> variab leMap = |
| 286 new HashMap<VariableElement, VariableDeclaration>(); | 286 new HashMap<PotentiallyConstVariableElementImpl, VariableDeclaration>(); |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * A table mapping constant constructors to the declarations of those | 289 * A table mapping constant constructors to the declarations of those |
| 290 * constructors. | 290 * constructors. |
| 291 */ | 291 */ |
| 292 final HashMap<ConstructorElement, ConstructorDeclaration> constructorMap = | 292 final HashMap<ConstructorElement, ConstructorDeclaration> constructorMap = |
| 293 new HashMap<ConstructorElement, ConstructorDeclaration>(); | 293 new HashMap<ConstructorElement, ConstructorDeclaration>(); |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * A collection of constant constructor invocations. | 296 * A collection of constant constructor invocations. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 constructorInvocations.add(node); | 329 constructorInvocations.add(node); |
| 330 } | 330 } |
| 331 return null; | 331 return null; |
| 332 } | 332 } |
| 333 | 333 |
| 334 @override | 334 @override |
| 335 Object visitVariableDeclaration(VariableDeclaration node) { | 335 Object visitVariableDeclaration(VariableDeclaration node) { |
| 336 super.visitVariableDeclaration(node); | 336 super.visitVariableDeclaration(node); |
| 337 Expression initializer = node.initializer; | 337 Expression initializer = node.initializer; |
| 338 if (initializer != null && node.isConst) { | 338 if (initializer != null && node.isConst) { |
| 339 VariableElement element = node.element; | 339 PotentiallyConstVariableElementImpl element = node.element; |
| 340 if (element != null) { | 340 if (element != null) { |
| 341 variableMap[element] = node; | 341 variableMap[element] = node; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 return null; | 344 return null; |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 /** | 348 /** |
| 349 * An object used to compute the values of constant variables and constant | 349 * An object used to compute the values of constant variables and constant |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 | 400 |
| 401 /** | 401 /** |
| 402 * A graph in which the nodes are the constants, and the edges are from each | 402 * A graph in which the nodes are the constants, and the edges are from each |
| 403 * constant to the other constants that are referenced by it. | 403 * constant to the other constants that are referenced by it. |
| 404 */ | 404 */ |
| 405 DirectedGraph<AstNode> referenceGraph = new DirectedGraph<AstNode>(); | 405 DirectedGraph<AstNode> referenceGraph = new DirectedGraph<AstNode>(); |
| 406 | 406 |
| 407 /** | 407 /** |
| 408 * A table mapping constant variables to the declarations of those variables. | 408 * A table mapping constant variables to the declarations of those variables. |
| 409 */ | 409 */ |
| 410 HashMap<VariableElement, VariableDeclaration> _variableDeclarationMap; | 410 HashMap<PotentiallyConstVariableElementImpl, VariableDeclaration> _variableDec larationMap; |
| 411 | 411 |
| 412 /** | 412 /** |
| 413 * A table mapping constant constructors to the declarations of those | 413 * A table mapping constant constructors to the declarations of those |
| 414 * constructors. | 414 * constructors. |
| 415 */ | 415 */ |
| 416 HashMap<ConstructorElement, ConstructorDeclaration> constructorDeclarationMap; | 416 HashMap<ConstructorElement, ConstructorDeclaration> constructorDeclarationMap; |
| 417 | 417 |
| 418 /** | 418 /** |
| 419 * A collection of constant constructor invocations. | 419 * A collection of constant constructor invocations. |
| 420 */ | 420 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 _variableDeclarationMap = _constantFinder.variableMap; | 475 _variableDeclarationMap = _constantFinder.variableMap; |
| 476 constructorDeclarationMap = _constantFinder.constructorMap; | 476 constructorDeclarationMap = _constantFinder.constructorMap; |
| 477 _constructorInvocations = _constantFinder.constructorInvocations; | 477 _constructorInvocations = _constantFinder.constructorInvocations; |
| 478 _annotations = _constantFinder.annotations; | 478 _annotations = _constantFinder.annotations; |
| 479 _variableDeclarationMap.values.forEach((VariableDeclaration declaration) { | 479 _variableDeclarationMap.values.forEach((VariableDeclaration declaration) { |
| 480 ReferenceFinder referenceFinder = new ReferenceFinder(declaration, | 480 ReferenceFinder referenceFinder = new ReferenceFinder(declaration, |
| 481 referenceGraph, _variableDeclarationMap, constructorDeclarationMap); | 481 referenceGraph, _variableDeclarationMap, constructorDeclarationMap); |
| 482 referenceGraph.addNode(declaration); | 482 referenceGraph.addNode(declaration); |
| 483 declaration.initializer.accept(referenceFinder); | 483 declaration.initializer.accept(referenceFinder); |
| 484 }); | 484 }); |
| 485 constructorDeclarationMap.forEach((ConstructorElement element, | 485 constructorDeclarationMap.forEach((ConstructorElementImpl element, |
| 486 ConstructorDeclaration declaration) { | 486 ConstructorDeclaration declaration) { |
| 487 element.isCycleFree = false; | |
| 487 ConstructorElement redirectedConstructor = | 488 ConstructorElement redirectedConstructor = |
| 488 _getConstRedirectedConstructor(element); | 489 _getConstRedirectedConstructor(element); |
| 489 if (redirectedConstructor != null) { | 490 if (redirectedConstructor != null) { |
| 490 ConstructorElement redirectedConstructorBase = | 491 ConstructorElement redirectedConstructorBase = |
| 491 _getConstructorBase(redirectedConstructor); | 492 _getConstructorBase(redirectedConstructor); |
| 492 ConstructorDeclaration redirectedConstructorDeclaration = | 493 ConstructorDeclaration redirectedConstructorDeclaration = |
| 493 findConstructorDeclaration(redirectedConstructorBase); | 494 findConstructorDeclaration(redirectedConstructorBase); |
| 494 referenceGraph.addEdge(declaration, redirectedConstructorDeclaration); | 495 referenceGraph.addEdge(declaration, redirectedConstructorDeclaration); |
| 495 return; | 496 return; |
| 496 } | 497 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 String name = argumentValues[0].stringValue; | 645 String name = argumentValues[0].stringValue; |
| 645 return isValidPublicSymbol(name); | 646 return isValidPublicSymbol(name); |
| 646 } | 647 } |
| 647 | 648 |
| 648 /** | 649 /** |
| 649 * Compute a value for the given [constNode]. | 650 * Compute a value for the given [constNode]. |
| 650 */ | 651 */ |
| 651 void _computeValueFor(AstNode constNode) { | 652 void _computeValueFor(AstNode constNode) { |
| 652 beforeComputeValue(constNode); | 653 beforeComputeValue(constNode); |
| 653 if (constNode is VariableDeclaration) { | 654 if (constNode is VariableDeclaration) { |
| 654 VariableDeclaration declaration = constNode; | 655 PotentiallyConstVariableElementImpl element = constNode.element; |
| 655 VariableElement element = declaration.element; | |
| 656 RecordingErrorListener errorListener = new RecordingErrorListener(); | 656 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 657 ErrorReporter errorReporter = | 657 ErrorReporter errorReporter = |
| 658 new ErrorReporter(errorListener, element.source); | 658 new ErrorReporter(errorListener, element.source); |
| 659 DartObjectImpl dartObject = | 659 DartObjectImpl dartObject = element.constantInitializer |
| 660 declaration.initializer.accept(createConstantVisitor(errorReporter)); | 660 .accept(createConstantVisitor(errorReporter)); |
| 661 if (dartObject != null) { | 661 if (dartObject != null) { |
| 662 if (!_runtimeTypeMatch(dartObject, element.type)) { | 662 if (!_runtimeTypeMatch(dartObject, element.type)) { |
| 663 errorReporter.reportErrorForNode( | 663 errorReporter.reportErrorForElement( |
| 664 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 664 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, element, [ |
| 665 declaration, [dartObject.type, element.type]); | 665 dartObject.type, |
| 666 element.type | |
| 667 ]); | |
| 666 } | 668 } |
| 667 } | 669 } |
| 668 (element as VariableElementImpl).evaluationResult = | 670 (element as VariableElementImpl).evaluationResult = |
| 669 new EvaluationResultImpl.con2(dartObject, errorListener.errors); | 671 new EvaluationResultImpl.con2(dartObject, errorListener.errors); |
| 670 } else if (constNode is InstanceCreationExpression) { | 672 } else if (constNode is InstanceCreationExpression) { |
| 671 InstanceCreationExpression expression = constNode; | 673 InstanceCreationExpression expression = constNode; |
| 672 ConstructorElement constructor = expression.staticElement; | 674 ConstructorElement constructor = expression.staticElement; |
| 673 if (constructor == null) { | 675 if (constructor == null) { |
| 674 // Couldn't resolve the constructor so we can't compute a value. | 676 // Couldn't resolve the constructor so we can't compute a value. |
| 675 // No problem - the error has already been reported. | 677 // No problem - the error has already been reported. |
| 676 // But we still need to store an evaluation result. | 678 // But we still need to store an evaluation result. |
| 677 expression.evaluationResult = new EvaluationResultImpl.con1(null); | 679 expression.constantHandle.evaluationResult = |
| 680 new EvaluationResultImpl.con1(null); | |
| 678 return; | 681 return; |
| 679 } | 682 } |
| 680 RecordingErrorListener errorListener = new RecordingErrorListener(); | 683 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 681 CompilationUnit sourceCompilationUnit = | 684 CompilationUnit sourceCompilationUnit = |
| 682 expression.getAncestor((node) => node is CompilationUnit); | 685 expression.getAncestor((node) => node is CompilationUnit); |
| 683 ErrorReporter errorReporter = new ErrorReporter( | 686 ErrorReporter errorReporter = new ErrorReporter( |
| 684 errorListener, sourceCompilationUnit.element.source); | 687 errorListener, sourceCompilationUnit.element.source); |
| 685 ConstantVisitor constantVisitor = createConstantVisitor(errorReporter); | 688 ConstantVisitor constantVisitor = createConstantVisitor(errorReporter); |
| 686 DartObjectImpl result = _evaluateConstructorCall(constNode, | 689 DartObjectImpl result = _evaluateConstructorCall(constNode, |
| 687 expression.argumentList.arguments, constructor, constantVisitor, | 690 expression.argumentList.arguments, constructor, constantVisitor, |
| 688 errorReporter); | 691 errorReporter); |
| 689 expression.evaluationResult = | 692 expression.constantHandle.evaluationResult = |
| 690 new EvaluationResultImpl.con2(result, errorListener.errors); | 693 new EvaluationResultImpl.con2(result, errorListener.errors); |
| 691 } else if (constNode is ConstructorDeclaration) { | 694 } else if (constNode is ConstructorDeclaration) { |
| 692 ConstructorDeclaration declaration = constNode; | 695 // No evaluation needs to be done; constructor declarations are only in |
| 693 NodeList<ConstructorInitializer> initializers = declaration.initializers; | 696 // the dependency graph to ensure that any constants referred to in |
| 694 ConstructorElementImpl constructor = | 697 // initializer lists and parameter defaults are evaluated before |
| 695 declaration.element as ConstructorElementImpl; | 698 // invocations of the constructor. However we do need to annotate the |
| 696 constructor.constantInitializers = | 699 // element as being free of constant evaluation cycles so that later code |
| 697 new ConstantAstCloner().cloneNodeList(initializers); | 700 // will know that it is safe to evaluate. |
| 701 ConstructorElementImpl constructor = constNode.element; | |
| 702 constructor.isCycleFree = true; | |
| 698 } else if (constNode is FormalParameter) { | 703 } else if (constNode is FormalParameter) { |
| 699 if (constNode is DefaultFormalParameter) { | 704 if (constNode is DefaultFormalParameter) { |
| 700 DefaultFormalParameter parameter = constNode; | 705 DefaultFormalParameter parameter = constNode; |
| 701 ParameterElement element = parameter.element; | 706 ParameterElement element = parameter.element; |
| 702 Expression defaultValue = parameter.defaultValue; | 707 Expression defaultValue = parameter.defaultValue; |
| 703 if (defaultValue != null) { | 708 if (defaultValue != null) { |
| 704 RecordingErrorListener errorListener = new RecordingErrorListener(); | 709 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 705 ErrorReporter errorReporter = | 710 ErrorReporter errorReporter = |
| 706 new ErrorReporter(errorListener, element.source); | 711 new ErrorReporter(errorListener, element.source); |
| 707 DartObjectImpl dartObject = | 712 DartObjectImpl dartObject = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 // that for analysis because it's likely to lead to cascading errors. | 790 // that for analysis because it's likely to lead to cascading errors. |
| 786 // So just leave [value] in the unknown state. | 791 // So just leave [value] in the unknown state. |
| 787 } | 792 } |
| 788 } | 793 } |
| 789 return value; | 794 return value; |
| 790 } | 795 } |
| 791 | 796 |
| 792 DartObjectImpl _evaluateConstructorCall(AstNode node, | 797 DartObjectImpl _evaluateConstructorCall(AstNode node, |
| 793 NodeList<Expression> arguments, ConstructorElement constructor, | 798 NodeList<Expression> arguments, ConstructorElement constructor, |
| 794 ConstantVisitor constantVisitor, ErrorReporter errorReporter) { | 799 ConstantVisitor constantVisitor, ErrorReporter errorReporter) { |
| 800 if (!_getConstructorBase(constructor).isCycleFree) { | |
| 801 // It's not safe to evaluate this constructor, so bail out. | |
| 802 return new DartObjectImpl.validWithUnknownValue(constructor.returnType); | |
|
Brian Wilkerson
2015/04/01 20:31:54
I'm guessing that we will create (or will have cre
Paul Berry
2015/04/02 15:18:49
Correct. Currently we report the unhelpful error
| |
| 803 } | |
| 795 int argumentCount = arguments.length; | 804 int argumentCount = arguments.length; |
| 796 List<DartObjectImpl> argumentValues = | 805 List<DartObjectImpl> argumentValues = |
| 797 new List<DartObjectImpl>(argumentCount); | 806 new List<DartObjectImpl>(argumentCount); |
| 798 List<Expression> argumentNodes = new List<Expression>(argumentCount); | 807 List<Expression> argumentNodes = new List<Expression>(argumentCount); |
| 799 HashMap<String, DartObjectImpl> namedArgumentValues = | 808 HashMap<String, DartObjectImpl> namedArgumentValues = |
| 800 new HashMap<String, DartObjectImpl>(); | 809 new HashMap<String, DartObjectImpl>(); |
| 801 HashMap<String, NamedExpression> namedArgumentNodes = | 810 HashMap<String, NamedExpression> namedArgumentNodes = |
| 802 new HashMap<String, NamedExpression>(); | 811 new HashMap<String, NamedExpression>(); |
| 803 for (int i = 0; i < argumentCount; i++) { | 812 for (int i = 0; i < argumentCount; i++) { |
| 804 Expression argument = arguments[i]; | 813 Expression argument = arguments[i]; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 String argumentValue = argumentValues[0].stringValue; | 871 String argumentValue = argumentValues[0].stringValue; |
| 863 return new DartObjectImpl( | 872 return new DartObjectImpl( |
| 864 definingClass, new SymbolState(argumentValue)); | 873 definingClass, new SymbolState(argumentValue)); |
| 865 } | 874 } |
| 866 // Either it's an external const factory constructor that we can't | 875 // Either it's an external const factory constructor that we can't |
| 867 // emulate, or an error occurred (a cycle, or a const constructor trying | 876 // emulate, or an error occurred (a cycle, or a const constructor trying |
| 868 // to delegate to a non-const constructor). | 877 // to delegate to a non-const constructor). |
| 869 // In the former case, the best we can do is consider it an unknown value. | 878 // In the former case, the best we can do is consider it an unknown value. |
| 870 // In the latter case, the error has already been reported, so considering | 879 // In the latter case, the error has already been reported, so considering |
| 871 // it an unknown value will suppress further errors. | 880 // it an unknown value will suppress further errors. |
| 872 return constantVisitor._validWithUnknownValue(definingClass); | 881 return new DartObjectImpl.validWithUnknownValue(definingClass); |
| 873 } | 882 } |
| 874 beforeGetConstantInitializers(constructor); | 883 beforeGetConstantInitializers(constructor); |
| 875 ConstructorElementImpl constructorBase = | 884 ConstructorElementImpl constructorBase = _getConstructorBase(constructor); |
| 876 _getConstructorBase(constructor) as ConstructorElementImpl; | |
| 877 List<ConstructorInitializer> initializers = | 885 List<ConstructorInitializer> initializers = |
| 878 constructorBase.constantInitializers; | 886 constructorBase.constantInitializers; |
| 879 if (initializers == null) { | 887 if (initializers == null) { |
| 880 // This can happen in some cases where there are compile errors in the | 888 // This can happen in some cases where there are compile errors in the |
| 881 // code being analyzed (for example if the code is trying to create a | 889 // code being analyzed (for example if the code is trying to create a |
| 882 // const instance using a non-const constructor, or the node we're | 890 // const instance using a non-const constructor, or the node we're |
| 883 // visiting is involved in a cycle). The error has already been reported, | 891 // visiting is involved in a cycle). The error has already been reported, |
| 884 // so consider it an unknown value to suppress further errors. | 892 // so consider it an unknown value to suppress further errors. |
| 885 return constantVisitor._validWithUnknownValue(definingClass); | 893 return new DartObjectImpl.validWithUnknownValue(definingClass); |
| 886 } | 894 } |
| 887 HashMap<String, DartObjectImpl> fieldMap = | 895 HashMap<String, DartObjectImpl> fieldMap = |
| 888 new HashMap<String, DartObjectImpl>(); | 896 new HashMap<String, DartObjectImpl>(); |
| 889 HashMap<String, DartObjectImpl> parameterMap = | 897 HashMap<String, DartObjectImpl> parameterMap = |
| 890 new HashMap<String, DartObjectImpl>(); | 898 new HashMap<String, DartObjectImpl>(); |
| 891 List<ParameterElement> parameters = constructor.parameters; | 899 List<ParameterElement> parameters = constructor.parameters; |
| 892 int parameterCount = parameters.length; | 900 int parameterCount = parameters.length; |
| 893 for (int i = 0; i < parameterCount; i++) { | 901 for (int i = 0; i < parameterCount; i++) { |
| 894 ParameterElement parameter = parameters[i]; | 902 ParameterElement parameter = parameters[i]; |
| 895 ParameterElement baseParameter = parameter; | 903 ParameterElement baseParameter = parameter; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 } | 1100 } |
| 1093 if (!redirectedConstructor.isConst) { | 1101 if (!redirectedConstructor.isConst) { |
| 1094 // Delegating to a non-const constructor--this is not allowed (and | 1102 // Delegating to a non-const constructor--this is not allowed (and |
| 1095 // is checked elsewhere--see | 1103 // is checked elsewhere--see |
| 1096 // [ErrorVerifier.checkForRedirectToNonConstConstructor()]). | 1104 // [ErrorVerifier.checkForRedirectToNonConstConstructor()]). |
| 1097 return null; | 1105 return null; |
| 1098 } | 1106 } |
| 1099 return redirectedConstructor; | 1107 return redirectedConstructor; |
| 1100 } | 1108 } |
| 1101 | 1109 |
| 1102 ConstructorElement _getConstructorBase(ConstructorElement constructor) { | 1110 ConstructorElementImpl _getConstructorBase(ConstructorElement constructor) { |
| 1103 while (constructor is ConstructorMember) { | 1111 while (constructor is ConstructorMember) { |
| 1104 constructor = (constructor as ConstructorMember).baseElement; | 1112 constructor = (constructor as ConstructorMember).baseElement; |
| 1105 } | 1113 } |
| 1106 return constructor; | 1114 return constructor; |
| 1107 } | 1115 } |
| 1108 | 1116 |
| 1109 /** | 1117 /** |
| 1110 * Check if the object [obj] matches the type [type] according to runtime type | 1118 * Check if the object [obj] matches the type [type] according to runtime type |
| 1111 * checking rules. | 1119 * checking rules. |
| 1112 */ | 1120 */ |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 if (conditionResult == null) { | 1360 if (conditionResult == null) { |
| 1353 return conditionResult; | 1361 return conditionResult; |
| 1354 } | 1362 } |
| 1355 if (conditionResult.isTrue) { | 1363 if (conditionResult.isTrue) { |
| 1356 return thenResult; | 1364 return thenResult; |
| 1357 } else if (conditionResult.isFalse) { | 1365 } else if (conditionResult.isFalse) { |
| 1358 return elseResult; | 1366 return elseResult; |
| 1359 } | 1367 } |
| 1360 ParameterizedType thenType = thenResult.type; | 1368 ParameterizedType thenType = thenResult.type; |
| 1361 ParameterizedType elseType = elseResult.type; | 1369 ParameterizedType elseType = elseResult.type; |
| 1362 return _validWithUnknownValue( | 1370 return new DartObjectImpl.validWithUnknownValue( |
| 1363 thenType.getLeastUpperBound(elseType) as InterfaceType); | 1371 thenType.getLeastUpperBound(elseType) as InterfaceType); |
| 1364 } | 1372 } |
| 1365 | 1373 |
| 1366 @override | 1374 @override |
| 1367 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => | 1375 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => |
| 1368 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); | 1376 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); |
| 1369 | 1377 |
| 1370 @override | 1378 @override |
| 1371 DartObjectImpl visitInstanceCreationExpression( | 1379 DartObjectImpl visitInstanceCreationExpression( |
| 1372 InstanceCreationExpression node) { | 1380 InstanceCreationExpression node) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 } else if (element is ClassElement || | 1664 } else if (element is ClassElement || |
| 1657 element is FunctionTypeAliasElement || | 1665 element is FunctionTypeAliasElement || |
| 1658 element is DynamicElementImpl) { | 1666 element is DynamicElementImpl) { |
| 1659 return new DartObjectImpl(_typeProvider.typeType, new TypeState(element)); | 1667 return new DartObjectImpl(_typeProvider.typeType, new TypeState(element)); |
| 1660 } | 1668 } |
| 1661 // TODO(brianwilkerson) Figure out which error to report. | 1669 // TODO(brianwilkerson) Figure out which error to report. |
| 1662 _error(node, null); | 1670 _error(node, null); |
| 1663 return null; | 1671 return null; |
| 1664 } | 1672 } |
| 1665 | 1673 |
| 1666 DartObjectImpl _validWithUnknownValue(InterfaceType type) { | |
| 1667 if (type.element.library.isDartCore) { | |
| 1668 String typeName = type.name; | |
| 1669 if (typeName == "bool") { | |
| 1670 return new DartObjectImpl(type, BoolState.UNKNOWN_VALUE); | |
| 1671 } else if (typeName == "double") { | |
| 1672 return new DartObjectImpl(type, DoubleState.UNKNOWN_VALUE); | |
| 1673 } else if (typeName == "int") { | |
| 1674 return new DartObjectImpl(type, IntState.UNKNOWN_VALUE); | |
| 1675 } else if (typeName == "String") { | |
| 1676 return new DartObjectImpl(type, StringState.UNKNOWN_VALUE); | |
| 1677 } | |
| 1678 } | |
| 1679 return new DartObjectImpl(type, GenericState.UNKNOWN_VALUE); | |
| 1680 } | |
| 1681 | |
| 1682 /** | 1674 /** |
| 1683 * Return the value of the given [expression], or a representation of 'null' | 1675 * Return the value of the given [expression], or a representation of 'null' |
| 1684 * if the expression cannot be evaluated. | 1676 * if the expression cannot be evaluated. |
| 1685 */ | 1677 */ |
| 1686 DartObjectImpl _valueOf(Expression expression) { | 1678 DartObjectImpl _valueOf(Expression expression) { |
| 1687 DartObjectImpl expressionValue = expression.accept(this); | 1679 DartObjectImpl expressionValue = expression.accept(this); |
| 1688 if (expressionValue != null) { | 1680 if (expressionValue != null) { |
| 1689 return expressionValue; | 1681 return expressionValue; |
| 1690 } | 1682 } |
| 1691 return _typeProvider.nullObject; | 1683 return _typeProvider.nullObject; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2121 /** | 2113 /** |
| 2122 * The state of the object. | 2114 * The state of the object. |
| 2123 */ | 2115 */ |
| 2124 final InstanceState _state; | 2116 final InstanceState _state; |
| 2125 | 2117 |
| 2126 /** | 2118 /** |
| 2127 * Initialize a newly created object to have the given [type] and [_state]. | 2119 * Initialize a newly created object to have the given [type] and [_state]. |
| 2128 */ | 2120 */ |
| 2129 DartObjectImpl(this.type, this._state); | 2121 DartObjectImpl(this.type, this._state); |
| 2130 | 2122 |
| 2123 /** | |
| 2124 * Create an object to represent an unknown value. | |
| 2125 */ | |
| 2126 factory DartObjectImpl.validWithUnknownValue(InterfaceType type) { | |
| 2127 if (type.element.library.isDartCore) { | |
| 2128 String typeName = type.name; | |
| 2129 if (typeName == "bool") { | |
| 2130 return new DartObjectImpl(type, BoolState.UNKNOWN_VALUE); | |
| 2131 } else if (typeName == "double") { | |
| 2132 return new DartObjectImpl(type, DoubleState.UNKNOWN_VALUE); | |
| 2133 } else if (typeName == "int") { | |
| 2134 return new DartObjectImpl(type, IntState.UNKNOWN_VALUE); | |
| 2135 } else if (typeName == "String") { | |
| 2136 return new DartObjectImpl(type, StringState.UNKNOWN_VALUE); | |
| 2137 } | |
| 2138 } | |
| 2139 return new DartObjectImpl(type, GenericState.UNKNOWN_VALUE); | |
| 2140 } | |
| 2141 | |
| 2131 @override | 2142 @override |
| 2132 bool get boolValue { | 2143 bool get boolValue { |
| 2133 if (_state is BoolState) { | 2144 if (_state is BoolState) { |
| 2134 return (_state as BoolState).value; | 2145 return (_state as BoolState).value; |
| 2135 } | 2146 } |
| 2136 return null; | 2147 return null; |
| 2137 } | 2148 } |
| 2138 | 2149 |
| 2139 @override | 2150 @override |
| 2140 double get doubleValue { | 2151 double get doubleValue { |
| (...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4784 /** | 4795 /** |
| 4785 * A graph in which the nodes are the constant variables and the edges are | 4796 * A graph in which the nodes are the constant variables and the edges are |
| 4786 * from each variable to the other constant variables that are referenced in | 4797 * from each variable to the other constant variables that are referenced in |
| 4787 * the head's initializer. | 4798 * the head's initializer. |
| 4788 */ | 4799 */ |
| 4789 final DirectedGraph<AstNode> _referenceGraph; | 4800 final DirectedGraph<AstNode> _referenceGraph; |
| 4790 | 4801 |
| 4791 /** | 4802 /** |
| 4792 * A table mapping constant variables to the declarations of those variables. | 4803 * A table mapping constant variables to the declarations of those variables. |
| 4793 */ | 4804 */ |
| 4794 final HashMap<VariableElement, VariableDeclaration> _variableDeclarationMap; | 4805 final HashMap<PotentiallyConstVariableElementImpl, VariableDeclaration> _varia bleDeclarationMap; |
| 4795 | 4806 |
| 4796 /** | 4807 /** |
| 4797 * A table mapping constant constructors to the declarations of those | 4808 * A table mapping constant constructors to the declarations of those |
| 4798 * constructors. | 4809 * constructors. |
| 4799 */ | 4810 */ |
| 4800 final HashMap<ConstructorElement, ConstructorDeclaration> _constructorDeclarat ionMap; | 4811 final HashMap<ConstructorElement, ConstructorDeclaration> _constructorDeclarat ionMap; |
| 4801 | 4812 |
| 4802 /** | 4813 /** |
| 4803 * Initialize a newly created reference finder to find references from a given | 4814 * Initialize a newly created reference finder to find references from a given |
| 4804 * variable to other variables and to add those references to the given graph. | 4815 * variable to other variables and to add those references to the given graph. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5087 return BoolState.from(_element == rightElement); | 5098 return BoolState.from(_element == rightElement); |
| 5088 } else if (rightOperand is DynamicState) { | 5099 } else if (rightOperand is DynamicState) { |
| 5089 return BoolState.UNKNOWN_VALUE; | 5100 return BoolState.UNKNOWN_VALUE; |
| 5090 } | 5101 } |
| 5091 return BoolState.FALSE_STATE; | 5102 return BoolState.FALSE_STATE; |
| 5092 } | 5103 } |
| 5093 | 5104 |
| 5094 @override | 5105 @override |
| 5095 String toString() => _element == null ? "-unknown-" : _element.name; | 5106 String toString() => _element == null ? "-unknown-" : _element.name; |
| 5096 } | 5107 } |
| OLD | NEW |