| 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 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 | 1014 |
| 1015 if (!foundSuperOrRedirect) { | 1015 if (!foundSuperOrRedirect) { |
| 1016 // No super initializer found. Try to find the default constructor if | 1016 // No super initializer found. Try to find the default constructor if |
| 1017 // the class is not Object. | 1017 // the class is not Object. |
| 1018 ClassElement enclosingClass = constructor.enclosingClass; | 1018 ClassElement enclosingClass = constructor.enclosingClass; |
| 1019 ClassElement superClass = enclosingClass.superclass; | 1019 ClassElement superClass = enclosingClass.superclass; |
| 1020 if (enclosingClass != compiler.objectClass) { | 1020 if (enclosingClass != compiler.objectClass) { |
| 1021 assert(superClass != null); | 1021 assert(superClass != null); |
| 1022 assert(superClass.resolutionState == STATE_DONE); | 1022 assert(superClass.resolutionState == STATE_DONE); |
| 1023 | 1023 |
| 1024 Selector selector = | |
| 1025 new Selector.callDefaultConstructor(enclosingClass.library); | |
| 1026 | |
| 1027 FunctionElement targetConstructor = | 1024 FunctionElement targetConstructor = |
| 1028 superClass.lookupConstructor(selector); | 1025 superClass.lookupDefaultConstructor(); |
| 1029 if (targetConstructor == null) { | 1026 // If we do not find a default constructor, an error was reported |
| 1030 compiler.internalError(functionNode, | 1027 // already and compilation will fail anyway. So just ignore that case. |
| 1031 "No default constructor available."); | 1028 if (targetConstructor != null) { |
| 1029 Selector selector = |
| 1030 new Selector.callDefaultConstructor(enclosingClass.library); |
| 1031 List<AstConstant> compiledArguments = evaluateArgumentsToConstructor( |
| 1032 functionNode, selector, const Link<Node>(), targetConstructor); |
| 1033 evaluateSuperOrRedirectSend(compiledArguments, targetConstructor); |
| 1032 } | 1034 } |
| 1033 List<AstConstant> compiledArguments = | |
| 1034 evaluateArgumentsToConstructor( | |
| 1035 functionNode, selector, const Link<Node>(), targetConstructor); | |
| 1036 evaluateSuperOrRedirectSend(compiledArguments, targetConstructor); | |
| 1037 } | 1035 } |
| 1038 } | 1036 } |
| 1039 } | 1037 } |
| 1040 | 1038 |
| 1041 /** | 1039 /** |
| 1042 * Simulates the execution of the [constructor] with the given | 1040 * Simulates the execution of the [constructor] with the given |
| 1043 * [arguments] to obtain the field values that need to be passed to the | 1041 * [arguments] to obtain the field values that need to be passed to the |
| 1044 * native JavaScript constructor. | 1042 * native JavaScript constructor. |
| 1045 */ | 1043 */ |
| 1046 void evaluateConstructorFieldValues(List<AstConstant> arguments) { | 1044 void evaluateConstructorFieldValues(List<AstConstant> arguments) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 return new AstConstant( | 1089 return new AstConstant( |
| 1092 element, | 1090 element, |
| 1093 element.initializer != null ? element.initializer : element.node, | 1091 element.initializer != null ? element.initializer : element.node, |
| 1094 constant); | 1092 constant); |
| 1095 } | 1093 } |
| 1096 | 1094 |
| 1097 ConstantValue get value => expression.value; | 1095 ConstantValue get value => expression.value; |
| 1098 | 1096 |
| 1099 String toString() => expression.toString(); | 1097 String toString() => expression.toString(); |
| 1100 } | 1098 } |
| OLD | NEW |