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