| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /// [ConstantCompilerTask] for compilation of constants for the JavaScript | 7 /// [ConstantCompilerTask] for compilation of constants for the JavaScript |
| 8 /// backend. | 8 /// backend. |
| 9 /// | 9 /// |
| 10 /// Since this task needs to distinguish between frontend and backend constants | 10 /// Since this task needs to distinguish between frontend and backend constants |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); | 108 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); |
| 109 | 109 |
| 110 // TODO(johnniwinther): Move this to the backend constant handler. | 110 // TODO(johnniwinther): Move this to the backend constant handler. |
| 111 /** Caches the statics where the initial value cannot be eagerly compiled. */ | 111 /** Caches the statics where the initial value cannot be eagerly compiled. */ |
| 112 final Set<VariableElement> lazyStatics = new Set<VariableElement>(); | 112 final Set<VariableElement> lazyStatics = new Set<VariableElement>(); |
| 113 | 113 |
| 114 // Constants computed for constant expressions. | 114 // Constants computed for constant expressions. |
| 115 final Map<Node, ConstantExpression> nodeConstantMap = | 115 final Map<Node, ConstantExpression> nodeConstantMap = |
| 116 new Map<Node, ConstantExpression>(); | 116 new Map<Node, ConstantExpression>(); |
| 117 | 117 |
| 118 // Constants computed for metadata. |
| 119 // TODO(johnniwinther): Remove this when no longer used by |
| 120 // poi/forget_element_test. |
| 121 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap = |
| 122 new Map<MetadataAnnotation, ConstantExpression>(); |
| 123 |
| 118 JavaScriptConstantCompiler(Compiler compiler) | 124 JavaScriptConstantCompiler(Compiler compiler) |
| 119 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM); | 125 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM); |
| 120 | 126 |
| 121 ConstantExpression compileVariableWithDefinitions( | 127 ConstantExpression compileVariableWithDefinitions( |
| 122 VariableElement element, TreeElements definitions, | 128 VariableElement element, TreeElements definitions, |
| 123 {bool isConst: false, bool checkType: true}) { | 129 {bool isConst: false, bool checkType: true}) { |
| 124 if (!isConst && lazyStatics.contains(element)) { | 130 if (!isConst && lazyStatics.contains(element)) { |
| 125 return null; | 131 return null; |
| 126 } | 132 } |
| 127 ConstantExpression value = super.compileVariableWithDefinitions( | 133 ConstantExpression value = super.compileVariableWithDefinitions( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (constant != null) { | 210 if (constant != null) { |
| 205 return constant; | 211 return constant; |
| 206 } | 212 } |
| 207 return definitions.getConstant(node); | 213 return definitions.getConstant(node); |
| 208 } | 214 } |
| 209 | 215 |
| 210 ConstantValue getConstantValueForMetadata(MetadataAnnotation metadata) { | 216 ConstantValue getConstantValueForMetadata(MetadataAnnotation metadata) { |
| 211 return getConstantValue(metadata.constant); | 217 return getConstantValue(metadata.constant); |
| 212 } | 218 } |
| 213 | 219 |
| 220 @override |
| 221 ConstantExpression compileMetadata( |
| 222 MetadataAnnotation metadata, Node node, TreeElements elements) { |
| 223 ConstantExpression constant = |
| 224 super.compileMetadata(metadata, node, elements); |
| 225 metadataConstantMap[metadata] = constant; |
| 226 return constant; |
| 227 } |
| 228 |
| 214 void forgetElement(Element element) { | 229 void forgetElement(Element element) { |
| 215 super.forgetElement(element); | 230 super.forgetElement(element); |
| 216 const ForgetConstantElementVisitor().visit(element, this); | 231 const ForgetConstantElementVisitor().visit(element, this); |
| 217 if (element is AstElement && element.hasNode) { | 232 if (element is AstElement && element.hasNode) { |
| 218 element.node.accept(new ForgetConstantNodeVisitor(this)); | 233 element.node.accept(new ForgetConstantNodeVisitor(this)); |
| 219 } | 234 } |
| 220 } | 235 } |
| 221 } | 236 } |
| 222 | 237 |
| 223 class ForgetConstantElementVisitor | 238 class ForgetConstantElementVisitor |
| 224 extends BaseElementVisitor<dynamic, JavaScriptConstantCompiler> { | 239 extends BaseElementVisitor<dynamic, JavaScriptConstantCompiler> { |
| 225 const ForgetConstantElementVisitor(); | 240 const ForgetConstantElementVisitor(); |
| 226 | 241 |
| 227 void visitElement(Element e, JavaScriptConstantCompiler constants) { | 242 void visitElement(Element e, JavaScriptConstantCompiler constants) { |
| 228 for (MetadataAnnotation data in e.implementation.metadata) { | 243 for (MetadataAnnotation data in e.implementation.metadata) { |
| 244 constants.metadataConstantMap.remove(data); |
| 229 if (data.hasNode) { | 245 if (data.hasNode) { |
| 230 data.node.accept(new ForgetConstantNodeVisitor(constants)); | 246 data.node.accept(new ForgetConstantNodeVisitor(constants)); |
| 231 } | 247 } |
| 232 } | 248 } |
| 233 } | 249 } |
| 234 | 250 |
| 235 void visitFunctionElement( | 251 void visitFunctionElement( |
| 236 FunctionElement e, JavaScriptConstantCompiler constants) { | 252 FunctionElement e, JavaScriptConstantCompiler constants) { |
| 237 super.visitFunctionElement(e, constants); | 253 super.visitFunctionElement(e, constants); |
| 238 if (e.hasFunctionSignature) { | 254 if (e.hasFunctionSignature) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 253 // TODO(ahe): This doesn't belong here. Rename this class and generalize. | 269 // TODO(ahe): This doesn't belong here. Rename this class and generalize. |
| 254 var closureClassMap = constants | 270 var closureClassMap = constants |
| 255 .compiler.closureToClassMapper.closureMappingCache | 271 .compiler.closureToClassMapper.closureMappingCache |
| 256 .remove(node); | 272 .remove(node); |
| 257 if (closureClassMap != null) { | 273 if (closureClassMap != null) { |
| 258 closureClassMap | 274 closureClassMap |
| 259 .removeMyselfFrom(constants.compiler.enqueuer.codegen.universe); | 275 .removeMyselfFrom(constants.compiler.enqueuer.codegen.universe); |
| 260 } | 276 } |
| 261 } | 277 } |
| 262 } | 278 } |
| OLD | NEW |