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 |
Anders Johnsen
2015/06/26 12:14:18
Take out function signature here
FunctionSignat
Johnni Winther
2015/06/26 12:50:23
Done.
| |
793 if (!callStructure.signatureApplies(target)) { | 793 if (!callStructure.signatureApplies(target.functionSignature)) { |
794 String name = Elements.constructorNameForDiagnostics( | 794 String name = Elements.constructorNameForDiagnostics( |
795 target.enclosingClass.name, target.name); | 795 target.enclosingClass.name, target.name); |
796 compiler.reportError( | 796 compiler.reportError( |
797 node, | 797 node, |
798 MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS, | 798 MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS, |
799 {'constructorName': name}); | 799 {'constructorName': name}); |
800 | 800 |
801 return new List<AstConstant>.filled( | 801 return new List<AstConstant>.filled( |
802 target.functionSignature.parameterCount, | 802 target.functionSignature.parameterCount, |
803 new ErroneousAstConstant(context, node)); | 803 new ErroneousAstConstant(context, node)); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 CallStructure callStructure, | 1021 CallStructure callStructure, |
1022 List<AstConstant> concreteArguments, | 1022 List<AstConstant> concreteArguments, |
1023 List<AstConstant> normalizedArguments) { | 1023 List<AstConstant> normalizedArguments) { |
1024 if (target.isRedirectingFactory) { | 1024 if (target.isRedirectingFactory) { |
1025 // This happens is case of cyclic redirection. | 1025 // This happens is case of cyclic redirection. |
1026 assert(invariant(node, compiler.compilationFailed, | 1026 assert(invariant(node, compiler.compilationFailed, |
1027 message: "makeConstructedConstant can only be called with the " | 1027 message: "makeConstructedConstant can only be called with the " |
1028 "effective target: $constructor")); | 1028 "effective target: $constructor")); |
1029 return new ErroneousAstConstant(context, node); | 1029 return new ErroneousAstConstant(context, node); |
1030 } | 1030 } |
1031 assert(invariant(node, callStructure.signatureApplies(constructor) || | 1031 assert(invariant( |
1032 compiler.compilationFailed, | 1032 node, |
1033 callStructure.signatureApplies(constructor.functionSignature) || | |
1034 compiler.compilationFailed, | |
1033 message: "Call structure $callStructure does not apply to constructor " | 1035 message: "Call structure $callStructure does not apply to constructor " |
1034 "$constructor.")); | 1036 "$constructor.")); |
1035 | 1037 |
1036 ConstructorEvaluator evaluator = new ConstructorEvaluator( | 1038 ConstructorEvaluator evaluator = new ConstructorEvaluator( |
1037 constructedType, target, handler, compiler); | 1039 constructedType, target, handler, compiler); |
1038 evaluator.evaluateConstructorFieldValues(normalizedArguments); | 1040 evaluator.evaluateConstructorFieldValues(normalizedArguments); |
1039 Map<FieldElement, AstConstant> fieldConstants = | 1041 Map<FieldElement, AstConstant> fieldConstants = |
1040 evaluator.buildFieldConstants(target.enclosingClass); | 1042 evaluator.buildFieldConstants(target.enclosingClass); |
1041 Map<FieldElement, ConstantValue> fieldValues = | 1043 Map<FieldElement, ConstantValue> fieldValues = |
1042 <FieldElement, ConstantValue>{}; | 1044 <FieldElement, ConstantValue>{}; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 // TODO(johnniwinther): Return a [NonConstantValue] instead. | 1332 // TODO(johnniwinther): Return a [NonConstantValue] instead. |
1331 new ErroneousConstantExpression(), new NullConstantValue()); | 1333 new ErroneousConstantExpression(), new NullConstantValue()); |
1332 } | 1334 } |
1333 | 1335 |
1334 // TODO(johnniwinther): Avoid the need for this hack. | 1336 // TODO(johnniwinther): Avoid the need for this hack. |
1335 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { | 1337 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { |
1336 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); | 1338 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); |
1337 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); | 1339 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); |
1338 return element.resolvedAst.elements; | 1340 return element.resolvedAst.elements; |
1339 } | 1341 } |
OLD | NEW |