| 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 import '../compile_time_constants.dart'; | 5 import '../compile_time_constants.dart'; |
| 6 import '../compiler.dart' show Compiler; | 6 import '../compiler.dart' show Compiler; |
| 7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 11 import '../elements/entities.dart'; | |
| 12 import '../elements/visitor.dart' show BaseElementVisitor; | 11 import '../elements/visitor.dart' show BaseElementVisitor; |
| 13 import '../resolution/tree_elements.dart' show TreeElements; | 12 import '../resolution/tree_elements.dart' show TreeElements; |
| 14 import '../tree/tree.dart'; | 13 import '../tree/tree.dart'; |
| 15 import 'constant_system_javascript.dart'; | 14 import 'constant_system_javascript.dart'; |
| 16 | 15 |
| 17 /// [ConstantCompilerTask] for compilation of constants for the JavaScript | 16 /// [ConstantCompilerTask] for compilation of constants for the JavaScript |
| 18 /// backend. | 17 /// backend. |
| 19 /// | 18 /// |
| 20 /// Since this task needs to distinguish between frontend and backend constants | 19 /// Since this task needs to distinguish between frontend and backend constants |
| 21 /// the actual compilation of the constants is forwarded to a | 20 /// the actual compilation of the constants is forwarded to a |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 108 |
| 110 /** | 109 /** |
| 111 * The [JavaScriptConstantCompiler] is used to keep track of compile-time | 110 * The [JavaScriptConstantCompiler] is used to keep track of compile-time |
| 112 * constants, initializations of global and static fields, and default values of | 111 * constants, initializations of global and static fields, and default values of |
| 113 * optional parameters for the JavaScript interpretation of constants. | 112 * optional parameters for the JavaScript interpretation of constants. |
| 114 */ | 113 */ |
| 115 class JavaScriptConstantCompiler extends ConstantCompilerBase | 114 class JavaScriptConstantCompiler extends ConstantCompilerBase |
| 116 implements BackendConstantEnvironment { | 115 implements BackendConstantEnvironment { |
| 117 // TODO(johnniwinther): Move this to the backend constant handler. | 116 // TODO(johnniwinther): Move this to the backend constant handler. |
| 118 /** Caches the statics where the initial value cannot be eagerly compiled. */ | 117 /** Caches the statics where the initial value cannot be eagerly compiled. */ |
| 119 final Set<FieldEntity> lazyStatics = new Set<FieldEntity>(); | 118 final Set<FieldElement> lazyStatics = new Set<FieldElement>(); |
| 120 | 119 |
| 121 // Constants computed for constant expressions. | 120 // Constants computed for constant expressions. |
| 122 final Map<Node, ConstantExpression> nodeConstantMap = | 121 final Map<Node, ConstantExpression> nodeConstantMap = |
| 123 new Map<Node, ConstantExpression>(); | 122 new Map<Node, ConstantExpression>(); |
| 124 | 123 |
| 125 // Constants computed for metadata. | 124 // Constants computed for metadata. |
| 126 // TODO(johnniwinther): Remove this when no longer used by | 125 // TODO(johnniwinther): Remove this when no longer used by |
| 127 // poi/forget_element_test. | 126 // poi/forget_element_test. |
| 128 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap = | 127 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap = |
| 129 new Map<MetadataAnnotation, ConstantExpression>(); | 128 new Map<MetadataAnnotation, ConstantExpression>(); |
| 130 | 129 |
| 131 JavaScriptConstantCompiler(Compiler compiler) | 130 JavaScriptConstantCompiler(Compiler compiler) |
| 132 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM); | 131 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM); |
| 133 | 132 |
| 134 ConstantExpression compileVariableWithDefinitions( | 133 ConstantExpression compileVariableWithDefinitions( |
| 135 VariableElement element, TreeElements definitions, | 134 VariableElement element, TreeElements definitions, |
| 136 {bool isConst: false, bool checkType: true}) { | 135 {bool isConst: false, bool checkType: true}) { |
| 137 if (!isConst && lazyStatics.contains(element)) { | 136 if (!isConst && lazyStatics.contains(element)) { |
| 138 return null; | 137 return null; |
| 139 } | 138 } |
| 140 ConstantExpression value = super.compileVariableWithDefinitions( | 139 ConstantExpression value = super.compileVariableWithDefinitions( |
| 141 element, definitions, | 140 element, definitions, |
| 142 isConst: isConst, checkType: checkType); | 141 isConst: isConst, checkType: checkType); |
| 143 if (!isConst && value == null) { | 142 if (!isConst && value == null) { |
| 144 FieldElement field = element; | 143 registerLazyStatic(element); |
| 145 registerLazyStatic(field); | |
| 146 } | 144 } |
| 147 return value; | 145 return value; |
| 148 } | 146 } |
| 149 | 147 |
| 150 @override | 148 @override |
| 151 void registerLazyStatic(FieldEntity element) { | 149 void registerLazyStatic(FieldElement element) { |
| 152 lazyStatics.add(element); | 150 lazyStatics.add(element); |
| 153 } | 151 } |
| 154 | 152 |
| 155 List<FieldEntity> getLazilyInitializedFieldsForEmission() { | 153 List<FieldElement> getLazilyInitializedFieldsForEmission() { |
| 156 return new List<FieldEntity>.from(lazyStatics); | 154 return new List<FieldElement>.from(lazyStatics); |
| 157 } | 155 } |
| 158 | 156 |
| 159 ConstantExpression compileNode(Node node, TreeElements elements, | 157 ConstantExpression compileNode(Node node, TreeElements elements, |
| 160 {bool enforceConst: true}) { | 158 {bool enforceConst: true}) { |
| 161 return compileNodeWithDefinitions(node, elements, isConst: enforceConst); | 159 return compileNodeWithDefinitions(node, elements, isConst: enforceConst); |
| 162 } | 160 } |
| 163 | 161 |
| 164 ConstantExpression compileNodeWithDefinitions( | 162 ConstantExpression compileNodeWithDefinitions( |
| 165 Node node, TreeElements definitions, | 163 Node node, TreeElements definitions, |
| 166 {bool isConst: true}) { | 164 {bool isConst: true}) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 class ForgetConstantNodeVisitor extends Visitor { | 225 class ForgetConstantNodeVisitor extends Visitor { |
| 228 final JavaScriptConstantCompiler constants; | 226 final JavaScriptConstantCompiler constants; |
| 229 | 227 |
| 230 ForgetConstantNodeVisitor(this.constants); | 228 ForgetConstantNodeVisitor(this.constants); |
| 231 | 229 |
| 232 void visitNode(Node node) { | 230 void visitNode(Node node) { |
| 233 node.visitChildren(this); | 231 node.visitChildren(this); |
| 234 constants.nodeConstantMap.remove(node); | 232 constants.nodeConstantMap.remove(node); |
| 235 } | 233 } |
| 236 } | 234 } |
| OLD | NEW |