| 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'; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 * constants, initializations of global and static fields, and default values of | 111 * constants, initializations of global and static fields, and default values of |
| 112 * optional parameters for the JavaScript interpretation of constants. | 112 * optional parameters for the JavaScript interpretation of constants. |
| 113 */ | 113 */ |
| 114 class JavaScriptConstantCompiler extends ConstantCompilerBase | 114 class JavaScriptConstantCompiler extends ConstantCompilerBase |
| 115 implements BackendConstantEnvironment { | 115 implements BackendConstantEnvironment { |
| 116 /** Set of all registered compiled constants. */ | 116 /** Set of all registered compiled constants. */ |
| 117 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); | 117 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); |
| 118 | 118 |
| 119 // TODO(johnniwinther): Move this to the backend constant handler. | 119 // TODO(johnniwinther): Move this to the backend constant handler. |
| 120 /** Caches the statics where the initial value cannot be eagerly compiled. */ | 120 /** Caches the statics where the initial value cannot be eagerly compiled. */ |
| 121 final Set<VariableElement> lazyStatics = new Set<VariableElement>(); | 121 final Set<FieldElement> lazyStatics = new Set<FieldElement>(); |
| 122 | 122 |
| 123 // Constants computed for constant expressions. | 123 // Constants computed for constant expressions. |
| 124 final Map<Node, ConstantExpression> nodeConstantMap = | 124 final Map<Node, ConstantExpression> nodeConstantMap = |
| 125 new Map<Node, ConstantExpression>(); | 125 new Map<Node, ConstantExpression>(); |
| 126 | 126 |
| 127 // Constants computed for metadata. | 127 // Constants computed for metadata. |
| 128 // TODO(johnniwinther): Remove this when no longer used by | 128 // TODO(johnniwinther): Remove this when no longer used by |
| 129 // poi/forget_element_test. | 129 // poi/forget_element_test. |
| 130 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap = | 130 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap = |
| 131 new Map<MetadataAnnotation, ConstantExpression>(); | 131 new Map<MetadataAnnotation, ConstantExpression>(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 150 | 150 |
| 151 @override | 151 @override |
| 152 void registerLazyStatic(FieldElement element) { | 152 void registerLazyStatic(FieldElement element) { |
| 153 lazyStatics.add(element); | 153 lazyStatics.add(element); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void addCompileTimeConstantForEmission(ConstantValue constant) { | 156 void addCompileTimeConstantForEmission(ConstantValue constant) { |
| 157 compiledConstants.add(constant); | 157 compiledConstants.add(constant); |
| 158 } | 158 } |
| 159 | 159 |
| 160 List<VariableElement> getLazilyInitializedFieldsForEmission() { | 160 List<FieldElement> getLazilyInitializedFieldsForEmission() { |
| 161 return new List<VariableElement>.from(lazyStatics); | 161 return new List<FieldElement>.from(lazyStatics); |
| 162 } | 162 } |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * Returns a list of constants topologically sorted so that dependencies | 165 * Returns a list of constants topologically sorted so that dependencies |
| 166 * appear before the dependent constant. [preSortCompare] is a comparator | 166 * appear before the dependent constant. [preSortCompare] is a comparator |
| 167 * function that gives the constants a consistent order prior to the | 167 * function that gives the constants a consistent order prior to the |
| 168 * topological sort which gives the constants an ordering that is less | 168 * topological sort which gives the constants an ordering that is less |
| 169 * sensitive to perturbations in the source code. | 169 * sensitive to perturbations in the source code. |
| 170 */ | 170 */ |
| 171 List<ConstantValue> getConstantsForEmission([preSortCompare]) { | 171 List<ConstantValue> getConstantsForEmission([preSortCompare]) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 class ForgetConstantNodeVisitor extends Visitor { | 269 class ForgetConstantNodeVisitor extends Visitor { |
| 270 final JavaScriptConstantCompiler constants; | 270 final JavaScriptConstantCompiler constants; |
| 271 | 271 |
| 272 ForgetConstantNodeVisitor(this.constants); | 272 ForgetConstantNodeVisitor(this.constants); |
| 273 | 273 |
| 274 void visitNode(Node node) { | 274 void visitNode(Node node) { |
| 275 node.visitChildren(this); | 275 node.visitChildren(this); |
| 276 constants.nodeConstantMap.remove(node); | 276 constants.nodeConstantMap.remove(node); |
| 277 } | 277 } |
| 278 } | 278 } |
| OLD | NEW |