| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 8 final Set<HInstruction> boundsChecked; | 8 final Set<HInstruction> boundsChecked; |
| 9 | 9 |
| 10 JavaScriptItemCompilationContext() | 10 JavaScriptItemCompilationContext() |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 final Namer namer; | 91 final Namer namer; |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Interface used to determine if an object has the JavaScript | 94 * Interface used to determine if an object has the JavaScript |
| 95 * indexing behavior. The interface is only visible to specific | 95 * indexing behavior. The interface is only visible to specific |
| 96 * libraries. | 96 * libraries. |
| 97 */ | 97 */ |
| 98 ClassElement jsIndexingBehaviorInterface; | 98 ClassElement jsIndexingBehaviorInterface; |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * A collection of selectors of intercepted method calls. The | |
| 102 * emitter uses this set to generate the [:ObjectInterceptor:] class | |
| 103 * whose members just forward the call to the intercepted receiver. | |
| 104 */ | |
| 105 final Set<Selector> usedInterceptors; | |
| 106 | |
| 107 /** | |
| 108 * A collection of selectors that must have a one shot interceptor | 101 * A collection of selectors that must have a one shot interceptor |
| 109 * generated. | 102 * generated. |
| 110 */ | 103 */ |
| 111 final Map<String, Selector> oneShotInterceptors; | 104 final Map<String, Selector> oneShotInterceptors; |
| 112 | 105 |
| 113 /** | 106 /** |
| 114 * The members of instantiated interceptor classes: maps a member name to the | 107 * The members of instantiated interceptor classes: maps a member name to the |
| 115 * list of members that have that name. This map is used by the codegen to | 108 * list of members that have that name. This map is used by the codegen to |
| 116 * know whether a send must be intercepted or not. | 109 * know whether a send must be intercepted or not. |
| 117 */ | 110 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 /// Holds the method "disableTreeShaking" in js_mirrors when | 151 /// Holds the method "disableTreeShaking" in js_mirrors when |
| 159 /// dart:mirrors has been loaded. | 152 /// dart:mirrors has been loaded. |
| 160 FunctionElement disableTreeShakingMarker; | 153 FunctionElement disableTreeShakingMarker; |
| 161 | 154 |
| 162 /// Holds the method "preserveNames" in js_mirrors when | 155 /// Holds the method "preserveNames" in js_mirrors when |
| 163 /// dart:mirrors has been loaded. | 156 /// dart:mirrors has been loaded. |
| 164 FunctionElement preserveNamesMarker; | 157 FunctionElement preserveNamesMarker; |
| 165 | 158 |
| 166 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval) | 159 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval) |
| 167 : namer = determineNamer(compiler), | 160 : namer = determineNamer(compiler), |
| 168 usedInterceptors = new Set<Selector>(), | |
| 169 oneShotInterceptors = new Map<String, Selector>(), | 161 oneShotInterceptors = new Map<String, Selector>(), |
| 170 interceptedElements = new Map<SourceString, Set<Element>>(), | 162 interceptedElements = new Map<SourceString, Set<Element>>(), |
| 171 rti = new RuntimeTypes(compiler), | 163 rti = new RuntimeTypes(compiler), |
| 172 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), | 164 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), |
| 173 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { | 165 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { |
| 174 emitter = disableEval | 166 emitter = disableEval |
| 175 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) | 167 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) |
| 176 : new CodeEmitterTask(compiler, namer, generateSourceMap); | 168 : new CodeEmitterTask(compiler, namer, generateSourceMap); |
| 177 builder = new SsaBuilderTask(this); | 169 builder = new SsaBuilderTask(this); |
| 178 optimizer = new SsaOptimizerTask(this); | 170 optimizer = new SsaOptimizerTask(this); |
| 179 generator = new SsaCodeGeneratorTask(this); | 171 generator = new SsaCodeGeneratorTask(this); |
| 180 } | 172 } |
| 181 | 173 |
| 182 static Namer determineNamer(Compiler compiler) { | 174 static Namer determineNamer(Compiler compiler) { |
| 183 return compiler.enableMinification ? | 175 return compiler.enableMinification ? |
| 184 new MinifyNamer(compiler) : | 176 new MinifyNamer(compiler) : |
| 185 new Namer(compiler); | 177 new Namer(compiler); |
| 186 } | 178 } |
| 187 | 179 |
| 188 bool isInterceptorClass(ClassElement element) { | 180 bool isInterceptorClass(ClassElement element) { |
| 189 if (element == null) return false; | 181 if (element == null) return false; |
| 190 if (element.isNative()) return true; | 182 if (element.isNative()) return true; |
| 191 if (interceptedClasses.contains(element)) return true; | 183 if (interceptedClasses.contains(element)) return true; |
| 192 if (classesMixedIntoNativeClasses.contains(element)) return true; | 184 if (classesMixedIntoNativeClasses.contains(element)) return true; |
| 193 return false; | 185 return false; |
| 194 } | 186 } |
| 195 | 187 |
| 196 void addInterceptedSelector(Selector selector) { | |
| 197 usedInterceptors.add(selector); | |
| 198 } | |
| 199 | |
| 200 String registerOneShotInterceptor(Selector selector) { | 188 String registerOneShotInterceptor(Selector selector) { |
| 201 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); | 189 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); |
| 202 String name = namer.getOneShotInterceptorName(selector, classes); | 190 String name = namer.getOneShotInterceptorName(selector, classes); |
| 203 if (!oneShotInterceptors.containsKey(name)) { | 191 if (!oneShotInterceptors.containsKey(name)) { |
| 204 registerSpecializedGetInterceptor(classes); | 192 registerSpecializedGetInterceptor(classes); |
| 205 oneShotInterceptors[name] = selector; | 193 oneShotInterceptors[name] = selector; |
| 206 } | 194 } |
| 207 return name; | 195 return name; |
| 208 } | 196 } |
| 209 | 197 |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 } | 1119 } |
| 1132 | 1120 |
| 1133 void registerStaticUse(Element element, Enqueuer enqueuer) { | 1121 void registerStaticUse(Element element, Enqueuer enqueuer) { |
| 1134 if (element == disableTreeShakingMarker) { | 1122 if (element == disableTreeShakingMarker) { |
| 1135 enqueuer.enqueueEverything(); | 1123 enqueuer.enqueueEverything(); |
| 1136 compiler.disableTypeInferenceForMirrors = true; | 1124 compiler.disableTypeInferenceForMirrors = true; |
| 1137 } else if (element == preserveNamesMarker) { | 1125 } else if (element == preserveNamesMarker) { |
| 1138 } | 1126 } |
| 1139 } | 1127 } |
| 1140 } | 1128 } |
| OLD | NEW |