Chromium Code Reviews| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /// A [ConstantEnvironment] provides access for constants compiled for variable | 7 /// A [ConstantEnvironment] provides access for constants compiled for variable |
| 8 /// initializers. | 8 /// initializers. |
| 9 abstract class ConstantEnvironment { | 9 abstract class ConstantEnvironment { |
| 10 /// Returns the constant for the initializer of [element]. | 10 /// Returns the constant for the initializer of [element]. |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 potentiallyCheckType(node, element, constant); | 947 potentiallyCheckType(node, element, constant); |
| 948 fieldValues[element] = constant; | 948 fieldValues[element] = constant; |
| 949 } | 949 } |
| 950 | 950 |
| 951 /** | 951 /** |
| 952 * Given the arguments (a list of constants) assigns them to the parameters, | 952 * Given the arguments (a list of constants) assigns them to the parameters, |
| 953 * updating the definitions map. If the constructor has field-initializer | 953 * updating the definitions map. If the constructor has field-initializer |
| 954 * parameters (like [:this.x:]), also updates the [fieldValues] map. | 954 * parameters (like [:this.x:]), also updates the [fieldValues] map. |
| 955 */ | 955 */ |
| 956 void assignArgumentsToParameters(List<AstConstant> arguments) { | 956 void assignArgumentsToParameters(List<AstConstant> arguments) { |
| 957 if (constructor.isErroneous) return; | |
|
Johnni Winther
2015/01/15 09:31:48
Shouldn't we generate an ErroneousConstantExpressi
ahe
2015/01/15 12:07:21
I'll look at that in a follow up.
| |
| 957 // Assign arguments to parameters. | 958 // Assign arguments to parameters. |
| 958 FunctionSignature signature = constructor.functionSignature; | 959 FunctionSignature signature = constructor.functionSignature; |
| 959 int index = 0; | 960 int index = 0; |
| 960 signature.orderedForEachParameter((ParameterElement parameter) { | 961 signature.orderedForEachParameter((ParameterElement parameter) { |
| 961 AstConstant argument = arguments[index++]; | 962 AstConstant argument = arguments[index++]; |
| 962 Node node = parameter.node; | 963 Node node = parameter.node; |
| 963 if (parameter.isInitializingFormal) { | 964 if (parameter.isInitializingFormal) { |
| 964 InitializingFormalElement initializingFormal = parameter; | 965 InitializingFormalElement initializingFormal = parameter; |
| 965 updateFieldValue(node, initializingFormal.fieldElement, argument); | 966 updateFieldValue(node, initializingFormal.fieldElement, argument); |
| 966 } else { | 967 } else { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 } | 1059 } |
| 1059 } | 1060 } |
| 1060 } | 1061 } |
| 1061 | 1062 |
| 1062 /** | 1063 /** |
| 1063 * Simulates the execution of the [constructor] with the given | 1064 * Simulates the execution of the [constructor] with the given |
| 1064 * [arguments] to obtain the field values that need to be passed to the | 1065 * [arguments] to obtain the field values that need to be passed to the |
| 1065 * native JavaScript constructor. | 1066 * native JavaScript constructor. |
| 1066 */ | 1067 */ |
| 1067 void evaluateConstructorFieldValues(List<AstConstant> arguments) { | 1068 void evaluateConstructorFieldValues(List<AstConstant> arguments) { |
| 1069 if (constructor.isErroneous) return; | |
| 1068 compiler.withCurrentElement(constructor, () { | 1070 compiler.withCurrentElement(constructor, () { |
| 1069 assignArgumentsToParameters(arguments); | 1071 assignArgumentsToParameters(arguments); |
| 1070 evaluateConstructorInitializers(); | 1072 evaluateConstructorInitializers(); |
| 1071 }); | 1073 }); |
| 1072 } | 1074 } |
| 1073 | 1075 |
| 1074 /// Builds a normalized list of the constant values for each field in the | 1076 /// Builds a normalized list of the constant values for each field in the |
| 1075 /// inheritance chain of [classElement]. | 1077 /// inheritance chain of [classElement]. |
| 1076 List<AstConstant> buildFieldConstants(ClassElement classElement) { | 1078 List<AstConstant> buildFieldConstants(ClassElement classElement) { |
| 1077 List<AstConstant> fieldConstants = <AstConstant>[]; | 1079 List<AstConstant> fieldConstants = <AstConstant>[]; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 ConstantValue get value => expression.value; | 1120 ConstantValue get value => expression.value; |
| 1119 | 1121 |
| 1120 String toString() => expression.toString(); | 1122 String toString() => expression.toString(); |
| 1121 } | 1123 } |
| 1122 | 1124 |
| 1123 /// A synthetic constant used to recover from errors. | 1125 /// A synthetic constant used to recover from errors. |
| 1124 class ErroneousAstConstant extends AstConstant { | 1126 class ErroneousAstConstant extends AstConstant { |
| 1125 ErroneousAstConstant(Element element, Node node) | 1127 ErroneousAstConstant(Element element, Node node) |
| 1126 : super(element, node, new ErroneousConstantExpression()); | 1128 : super(element, node, new ErroneousConstantExpression()); |
| 1127 } | 1129 } |
| OLD | NEW |