| 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 library dart2js.common.codegen; | 5 library dart2js.common.codegen; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../compiler.dart' show | 8 import '../compiler.dart' show |
| 9 Compiler; | 9 Compiler; |
| 10 import '../constants/values.dart' show | 10 import '../constants/values.dart' show |
| 11 ConstantValue; | 11 ConstantValue; |
| 12 import '../dart_types.dart' show | 12 import '../dart_types.dart' show |
| 13 DartType, | 13 DartType, |
| 14 InterfaceType; | 14 InterfaceType; |
| 15 import '../elements/elements.dart' show | 15 import '../elements/elements.dart' show |
| 16 AstElement, | 16 AstElement, |
| 17 ClassElement, | 17 ClassElement, |
| 18 Element, | 18 Element, |
| 19 FunctionElement, | 19 FunctionElement, |
| 20 LocalFunctionElement; | 20 LocalFunctionElement; |
| 21 import '../enqueue.dart' show | 21 import '../enqueue.dart' show |
| 22 CodegenEnqueuer; | 22 CodegenEnqueuer; |
| 23 import '../js_backend/js_backend.dart' show | |
| 24 JavaScriptBackend; | |
| 25 import '../resolution/tree_elements.dart' show | 23 import '../resolution/tree_elements.dart' show |
| 26 TreeElements; | 24 TreeElements; |
| 27 import '../universe/selector.dart' show | |
| 28 Selector; | |
| 29 import '../universe/universe.dart' show | 25 import '../universe/universe.dart' show |
| 30 UniverseSelector; | 26 UniverseSelector; |
| 27 import '../universe/use.dart' show |
| 28 StaticUse; |
| 31 import '../universe/world_impact.dart' show | 29 import '../universe/world_impact.dart' show |
| 32 WorldImpact, | 30 WorldImpact, |
| 33 WorldImpactBuilder; | 31 WorldImpactBuilder; |
| 34 import '../util/util.dart' show | 32 import '../util/util.dart' show |
| 35 Pair, | 33 Pair, |
| 36 Setlet; | 34 Setlet; |
| 37 import 'registry.dart' show | 35 import 'registry.dart' show |
| 38 Registry, | 36 Registry, |
| 39 EagerRegistry; | 37 EagerRegistry; |
| 40 import 'work.dart' show | 38 import 'work.dart' show |
| 41 ItemCompilationContext, | 39 ItemCompilationContext, |
| 42 WorkItem; | 40 WorkItem; |
| 43 | 41 |
| 44 class CodegenImpact extends WorldImpact { | 42 class CodegenImpact extends WorldImpact { |
| 45 const CodegenImpact(); | 43 const CodegenImpact(); |
| 46 | 44 |
| 47 // TODO(johnniwinther): Remove this. | 45 // TODO(johnniwinther): Remove this. |
| 48 Registry get registry => null; | 46 Registry get registry => null; |
| 49 | 47 |
| 50 Iterable<Element> get getterForSuperElements => const <Element>[]; | |
| 51 | |
| 52 Iterable<Element> get fieldGetters => const <Element>[]; | |
| 53 | |
| 54 Iterable<Element> get fieldSetters => const <Element>[]; | |
| 55 | |
| 56 Iterable<ConstantValue> get compileTimeConstants => const <ConstantValue>[]; | 48 Iterable<ConstantValue> get compileTimeConstants => const <ConstantValue>[]; |
| 57 | 49 |
| 58 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { | 50 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { |
| 59 return const <Pair<DartType, DartType>>[]; | 51 return const <Pair<DartType, DartType>>[]; |
| 60 } | 52 } |
| 61 | 53 |
| 62 Iterable<String> get constSymbols => const <String>[]; | 54 Iterable<String> get constSymbols => const <String>[]; |
| 63 | 55 |
| 64 Iterable<Set<ClassElement>> get specializedGetInterceptors { | 56 Iterable<Set<ClassElement>> get specializedGetInterceptors { |
| 65 return const <Set<ClassElement>>[]; | 57 return const <Set<ClassElement>>[]; |
| 66 } | 58 } |
| 67 | 59 |
| 68 bool get usesInterceptor => false; | 60 bool get usesInterceptor => false; |
| 69 | 61 |
| 70 Iterable<ClassElement> get typeConstants => const <ClassElement>[]; | 62 Iterable<ClassElement> get typeConstants => const <ClassElement>[]; |
| 71 | 63 |
| 72 Iterable<Element> get asyncMarkers => const <FunctionElement>[]; | 64 Iterable<Element> get asyncMarkers => const <FunctionElement>[]; |
| 73 } | 65 } |
| 74 | 66 |
| 75 class _CodegenImpact extends WorldImpactBuilder implements CodegenImpact { | 67 class _CodegenImpact extends WorldImpactBuilder implements CodegenImpact { |
| 76 // TODO(johnniwinther): Remove this. | 68 // TODO(johnniwinther): Remove this. |
| 77 final Registry registry; | 69 final Registry registry; |
| 78 | 70 |
| 79 | |
| 80 Setlet<Element> _getterForSuperElements; | |
| 81 Setlet<Element> _fieldGetters; | |
| 82 Setlet<Element> _fieldSetters; | |
| 83 Setlet<ConstantValue> _compileTimeConstants; | 71 Setlet<ConstantValue> _compileTimeConstants; |
| 84 Setlet<Pair<DartType, DartType>> _typeVariableBoundsSubtypeChecks; | 72 Setlet<Pair<DartType, DartType>> _typeVariableBoundsSubtypeChecks; |
| 85 Setlet<String> _constSymbols; | 73 Setlet<String> _constSymbols; |
| 86 List<Set<ClassElement>> _specializedGetInterceptors; | 74 List<Set<ClassElement>> _specializedGetInterceptors; |
| 87 bool _usesInterceptor = false; | 75 bool _usesInterceptor = false; |
| 88 Setlet<ClassElement> _typeConstants; | 76 Setlet<ClassElement> _typeConstants; |
| 89 Setlet<FunctionElement> _asyncMarkers; | 77 Setlet<FunctionElement> _asyncMarkers; |
| 90 | 78 |
| 91 _CodegenImpact(this.registry); | 79 _CodegenImpact(this.registry); |
| 92 | 80 |
| 93 void registerGetterForSuperMethod(Element element) { | |
| 94 if (_getterForSuperElements == null) { | |
| 95 _getterForSuperElements = new Setlet<Element>(); | |
| 96 } | |
| 97 _getterForSuperElements.add(element); | |
| 98 } | |
| 99 | |
| 100 Iterable<Element> get getterForSuperElements { | |
| 101 return _getterForSuperElements != null | |
| 102 ? _getterForSuperElements : const <Element>[]; | |
| 103 } | |
| 104 | |
| 105 void registerFieldGetter(Element element) { | |
| 106 if (_fieldGetters == null) { | |
| 107 _fieldGetters = new Setlet<Element>(); | |
| 108 } | |
| 109 _fieldGetters.add(element); | |
| 110 } | |
| 111 | |
| 112 Iterable<Element> get fieldGetters { | |
| 113 return _fieldGetters != null | |
| 114 ? _fieldGetters : const <Element>[]; | |
| 115 } | |
| 116 | |
| 117 void registerFieldSetter(Element element) { | |
| 118 if (_fieldSetters == null) { | |
| 119 _fieldSetters = new Setlet<Element>(); | |
| 120 } | |
| 121 _fieldSetters.add(element); | |
| 122 } | |
| 123 | |
| 124 Iterable<Element> get fieldSetters { | |
| 125 return _fieldSetters != null | |
| 126 ? _fieldSetters : const <Element>[]; | |
| 127 } | |
| 128 | |
| 129 void registerCompileTimeConstant(ConstantValue constant) { | 81 void registerCompileTimeConstant(ConstantValue constant) { |
| 130 if (_compileTimeConstants == null) { | 82 if (_compileTimeConstants == null) { |
| 131 _compileTimeConstants = new Setlet<ConstantValue>(); | 83 _compileTimeConstants = new Setlet<ConstantValue>(); |
| 132 } | 84 } |
| 133 _compileTimeConstants.add(constant); | 85 _compileTimeConstants.add(constant); |
| 134 } | 86 } |
| 135 | 87 |
| 136 Iterable<ConstantValue> get compileTimeConstants { | 88 Iterable<ConstantValue> get compileTimeConstants { |
| 137 return _compileTimeConstants != null | 89 return _compileTimeConstants != null |
| 138 ? _compileTimeConstants : const <ConstantValue>[]; | 90 ? _compileTimeConstants : const <ConstantValue>[]; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 CodegenRegistry(Compiler compiler, AstElement currentElement) | 169 CodegenRegistry(Compiler compiler, AstElement currentElement) |
| 218 : this.compiler = compiler, | 170 : this.compiler = compiler, |
| 219 this.currentElement = currentElement, | 171 this.currentElement = currentElement, |
| 220 this.worldImpact = new _CodegenImpact(new EagerRegistry( | 172 this.worldImpact = new _CodegenImpact(new EagerRegistry( |
| 221 'EagerRegistry for $currentElement', compiler.enqueuer.codegen)); | 173 'EagerRegistry for $currentElement', compiler.enqueuer.codegen)); |
| 222 | 174 |
| 223 bool get isForResolution => false; | 175 bool get isForResolution => false; |
| 224 | 176 |
| 225 String toString() => 'CodegenRegistry for $currentElement'; | 177 String toString() => 'CodegenRegistry for $currentElement'; |
| 226 | 178 |
| 179 @deprecated |
| 227 void registerInstantiatedClass(ClassElement element) { | 180 void registerInstantiatedClass(ClassElement element) { |
| 228 registerInstantiatedType(element.rawType); | 181 registerInstantiation(element.rawType); |
| 229 } | 182 } |
| 230 | 183 |
| 231 void registerInstantiatedType(InterfaceType type) { | 184 void registerStaticUse(StaticUse staticUse) { |
| 232 worldImpact.registerInstantiatedType(type); | 185 worldImpact.registerStaticUse(staticUse); |
| 233 } | 186 } |
| 234 | 187 |
| 235 void registerStaticUse(Element element) { | 188 void registerDynamicUse(UniverseSelector selector) { |
| 236 worldImpact.registerStaticUse(element); | 189 worldImpact.registerDynamicUse(selector); |
| 237 } | |
| 238 | |
| 239 void registerDynamicInvocation(UniverseSelector selector) { | |
| 240 worldImpact.registerDynamicInvocation(selector); | |
| 241 compiler.dumpInfoTask.elementUsesSelector(currentElement, selector); | 190 compiler.dumpInfoTask.elementUsesSelector(currentElement, selector); |
| 242 } | 191 } |
| 243 | 192 |
| 244 void registerDynamicSetter(UniverseSelector selector) { | |
| 245 worldImpact.registerDynamicSetter(selector); | |
| 246 compiler.dumpInfoTask.elementUsesSelector(currentElement, selector); | |
| 247 } | |
| 248 | |
| 249 void registerDynamicGetter(UniverseSelector selector) { | |
| 250 worldImpact.registerDynamicGetter(selector); | |
| 251 compiler.dumpInfoTask.elementUsesSelector(currentElement, selector); | |
| 252 } | |
| 253 | |
| 254 void registerGetterForSuperMethod(Element element) { | |
| 255 worldImpact.registerGetterForSuperMethod(element); | |
| 256 } | |
| 257 | |
| 258 void registerFieldGetter(Element element) { | |
| 259 worldImpact.registerFieldGetter(element); | |
| 260 } | |
| 261 | |
| 262 void registerFieldSetter(Element element) { | |
| 263 worldImpact.registerFieldSetter(element); | |
| 264 } | |
| 265 | |
| 266 void registerIsCheck(DartType type) { | 193 void registerIsCheck(DartType type) { |
| 267 worldImpact.registerIsCheck(type); | 194 worldImpact.registerIsCheck(type); |
| 268 } | 195 } |
| 269 | 196 |
| 270 void registerCompileTimeConstant(ConstantValue constant) { | 197 void registerCompileTimeConstant(ConstantValue constant) { |
| 271 worldImpact.registerCompileTimeConstant(constant); | 198 worldImpact.registerCompileTimeConstant(constant); |
| 272 } | 199 } |
| 273 | 200 |
| 274 void registerTypeVariableBoundsSubtypeCheck(DartType subtype, | 201 void registerTypeVariableBoundsSubtypeCheck(DartType subtype, |
| 275 DartType supertype) { | 202 DartType supertype) { |
| 276 worldImpact.registerTypeVariableBoundsSubtypeCheck(subtype, supertype); | 203 worldImpact.registerTypeVariableBoundsSubtypeCheck(subtype, supertype); |
| 277 } | 204 } |
| 278 | 205 |
| 279 void registerInstantiatedClosure(LocalFunctionElement element) { | 206 void registerInstantiatedClosure(LocalFunctionElement element) { |
| 280 worldImpact.registerClosure(element); | 207 worldImpact.registerClosure(element); |
| 281 } | 208 } |
| 282 | 209 |
| 283 void registerGetOfStaticFunction(FunctionElement element) { | |
| 284 worldImpact.registerClosurizedFunction(element); | |
| 285 } | |
| 286 | |
| 287 void registerSelectorUse(Selector selector) { | |
| 288 if (selector.isGetter) { | |
| 289 registerDynamicGetter(new UniverseSelector(selector, null)); | |
| 290 } else if (selector.isSetter) { | |
| 291 registerDynamicSetter(new UniverseSelector(selector, null)); | |
| 292 } else { | |
| 293 registerDynamicInvocation(new UniverseSelector(selector, null)); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 void registerConstSymbol(String name) { | 210 void registerConstSymbol(String name) { |
| 298 worldImpact.registerConstSymbol(name); | 211 worldImpact.registerConstSymbol(name); |
| 299 } | 212 } |
| 300 | 213 |
| 301 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { | 214 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { |
| 302 worldImpact.registerSpecializedGetInterceptor(classes); | 215 worldImpact.registerSpecializedGetInterceptor(classes); |
| 303 } | 216 } |
| 304 | 217 |
| 305 void registerUseInterceptor() { | 218 void registerUseInterceptor() { |
| 306 worldImpact.registerUseInterceptor(); | 219 worldImpact.registerUseInterceptor(); |
| 307 } | 220 } |
| 308 | 221 |
| 309 void registerTypeConstant(ClassElement element) { | 222 void registerTypeConstant(ClassElement element) { |
| 310 worldImpact.registerTypeConstant(element); | 223 worldImpact.registerTypeConstant(element); |
| 311 } | 224 } |
| 312 | 225 |
| 313 void registerStaticInvocation(Element element) { | |
| 314 registerStaticUse(element); | |
| 315 } | |
| 316 | |
| 317 void registerSuperInvocation(Element element) { | |
| 318 registerStaticUse(element); | |
| 319 } | |
| 320 | |
| 321 void registerDirectInvocation(Element element) { | |
| 322 registerStaticUse(element); | |
| 323 } | |
| 324 | |
| 325 void registerInstantiation(InterfaceType type) { | 226 void registerInstantiation(InterfaceType type) { |
| 326 registerInstantiatedType(type); | 227 worldImpact.registerInstantiatedType(type); |
| 327 } | 228 } |
| 328 | 229 |
| 329 void registerAsyncMarker(FunctionElement element) { | 230 void registerAsyncMarker(FunctionElement element) { |
| 330 worldImpact.registerAsyncMarker(element); | 231 worldImpact.registerAsyncMarker(element); |
| 331 } | 232 } |
| 332 } | 233 } |
| 333 | 234 |
| 334 /// [WorkItem] used exclusively by the [CodegenEnqueuer]. | 235 /// [WorkItem] used exclusively by the [CodegenEnqueuer]. |
| 335 class CodegenWorkItem extends WorkItem { | 236 class CodegenWorkItem extends WorkItem { |
| 336 CodegenRegistry registry; | 237 CodegenRegistry registry; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 358 | 259 |
| 359 TreeElements get resolutionTree => element.resolvedAst.elements; | 260 TreeElements get resolutionTree => element.resolvedAst.elements; |
| 360 | 261 |
| 361 WorldImpact run(Compiler compiler, CodegenEnqueuer world) { | 262 WorldImpact run(Compiler compiler, CodegenEnqueuer world) { |
| 362 if (world.isProcessed(element)) return const WorldImpact(); | 263 if (world.isProcessed(element)) return const WorldImpact(); |
| 363 | 264 |
| 364 registry = new CodegenRegistry(compiler, element); | 265 registry = new CodegenRegistry(compiler, element); |
| 365 return compiler.codegen(this, world); | 266 return compiler.codegen(this, world); |
| 366 } | 267 } |
| 367 } | 268 } |
| OLD | NEW |