| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library dart2js.compile_time_constant_evaluator; | 5 library dart2js.compile_time_constant_evaluator; |
| 6 | 6 |
| 7 import 'constant_system_dart.dart'; | 7 import 'constant_system_dart.dart'; |
| 8 import 'constants/constant_system.dart'; | 8 import 'constants/constant_system.dart'; |
| 9 import 'constants/expressions.dart'; | 9 import 'constants/expressions.dart'; |
| 10 import 'constants/values.dart'; | 10 import 'constants/values.dart'; |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 * Returns the normalized list of constant arguments that are passed to the | 772 * Returns the normalized list of constant arguments that are passed to the |
| 773 * constructor including both the concrete arguments and default values for | 773 * constructor including both the concrete arguments and default values for |
| 774 * omitted optional arguments. | 774 * omitted optional arguments. |
| 775 * | 775 * |
| 776 * Invariant: [target] must be an implementation element. | 776 * Invariant: [target] must be an implementation element. |
| 777 */ | 777 */ |
| 778 List<AstConstant> evaluateArgumentsToConstructor( | 778 List<AstConstant> evaluateArgumentsToConstructor( |
| 779 Node node, | 779 Node node, |
| 780 CallStructure callStructure, | 780 CallStructure callStructure, |
| 781 Link<Node> arguments, | 781 Link<Node> arguments, |
| 782 FunctionElement target, | 782 ConstructorElement target, |
| 783 {AstConstant compileArgument(Node node)}) { | 783 {AstConstant compileArgument(Node node)}) { |
| 784 assert(invariant(node, target.isImplementation)); | 784 assert(invariant(node, target.isImplementation)); |
| 785 | 785 |
| 786 AstConstant compileDefaultValue(VariableElement element) { | 786 AstConstant compileDefaultValue(VariableElement element) { |
| 787 ConstantExpression constant = handler.compileConstant(element); | 787 ConstantExpression constant = handler.compileConstant(element); |
| 788 return new AstConstant.fromDefaultValue( | 788 return new AstConstant.fromDefaultValue( |
| 789 element, constant, handler.getConstantValue(constant)); | 789 element, constant, handler.getConstantValue(constant)); |
| 790 } | 790 } |
| 791 target.computeType(compiler); | 791 target.computeType(compiler); |
| 792 | 792 |
| 793 if (!callStructure.signatureApplies(target)) { | 793 FunctionSignature signature = target.functionSignature; |
| 794 if (!callStructure.signatureApplies(signature)) { |
| 794 String name = Elements.constructorNameForDiagnostics( | 795 String name = Elements.constructorNameForDiagnostics( |
| 795 target.enclosingClass.name, target.name); | 796 target.enclosingClass.name, target.name); |
| 796 compiler.reportError( | 797 compiler.reportError( |
| 797 node, | 798 node, |
| 798 MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS, | 799 MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS, |
| 799 {'constructorName': name}); | 800 {'constructorName': name}); |
| 800 | 801 |
| 801 return new List<AstConstant>.filled( | 802 return new List<AstConstant>.filled( |
| 802 target.functionSignature.parameterCount, | 803 target.functionSignature.parameterCount, |
| 803 new ErroneousAstConstant(context, node)); | 804 new ErroneousAstConstant(context, node)); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 CallStructure callStructure, | 1022 CallStructure callStructure, |
| 1022 List<AstConstant> concreteArguments, | 1023 List<AstConstant> concreteArguments, |
| 1023 List<AstConstant> normalizedArguments) { | 1024 List<AstConstant> normalizedArguments) { |
| 1024 if (target.isRedirectingFactory) { | 1025 if (target.isRedirectingFactory) { |
| 1025 // This happens is case of cyclic redirection. | 1026 // This happens is case of cyclic redirection. |
| 1026 assert(invariant(node, compiler.compilationFailed, | 1027 assert(invariant(node, compiler.compilationFailed, |
| 1027 message: "makeConstructedConstant can only be called with the " | 1028 message: "makeConstructedConstant can only be called with the " |
| 1028 "effective target: $constructor")); | 1029 "effective target: $constructor")); |
| 1029 return new ErroneousAstConstant(context, node); | 1030 return new ErroneousAstConstant(context, node); |
| 1030 } | 1031 } |
| 1031 assert(invariant(node, callStructure.signatureApplies(constructor) || | 1032 assert(invariant( |
| 1032 compiler.compilationFailed, | 1033 node, |
| 1034 callStructure.signatureApplies(constructor.functionSignature) || |
| 1035 compiler.compilationFailed, |
| 1033 message: "Call structure $callStructure does not apply to constructor " | 1036 message: "Call structure $callStructure does not apply to constructor " |
| 1034 "$constructor.")); | 1037 "$constructor.")); |
| 1035 | 1038 |
| 1036 ConstructorEvaluator evaluator = new ConstructorEvaluator( | 1039 ConstructorEvaluator evaluator = new ConstructorEvaluator( |
| 1037 constructedType, target, handler, compiler); | 1040 constructedType, target, handler, compiler); |
| 1038 evaluator.evaluateConstructorFieldValues(normalizedArguments); | 1041 evaluator.evaluateConstructorFieldValues(normalizedArguments); |
| 1039 Map<FieldElement, AstConstant> fieldConstants = | 1042 Map<FieldElement, AstConstant> fieldConstants = |
| 1040 evaluator.buildFieldConstants(target.enclosingClass); | 1043 evaluator.buildFieldConstants(target.enclosingClass); |
| 1041 Map<FieldElement, ConstantValue> fieldValues = | 1044 Map<FieldElement, ConstantValue> fieldValues = |
| 1042 <FieldElement, ConstantValue>{}; | 1045 <FieldElement, ConstantValue>{}; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 // TODO(johnniwinther): Return a [NonConstantValue] instead. | 1333 // TODO(johnniwinther): Return a [NonConstantValue] instead. |
| 1331 new ErroneousConstantExpression(), new NullConstantValue()); | 1334 new ErroneousConstantExpression(), new NullConstantValue()); |
| 1332 } | 1335 } |
| 1333 | 1336 |
| 1334 // TODO(johnniwinther): Avoid the need for this hack. | 1337 // TODO(johnniwinther): Avoid the need for this hack. |
| 1335 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { | 1338 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { |
| 1336 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); | 1339 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); |
| 1337 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); | 1340 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); |
| 1338 return element.resolvedAst.elements; | 1341 return element.resolvedAst.elements; |
| 1339 } | 1342 } |
| OLD | NEW |