| 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 dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
| 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
| 9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
| 10 class ElementAst { | 10 class ElementAst { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 final LITERAL_TYPE_NAMES = const [ | 130 final LITERAL_TYPE_NAMES = const [ |
| 131 'Map', 'List', 'num', 'int', 'double', 'bool' | 131 'Map', 'List', 'num', 'int', 'double', 'bool' |
| 132 ]; | 132 ]; |
| 133 final coreLibrary = compiler.coreLibrary; | 133 final coreLibrary = compiler.coreLibrary; |
| 134 for (final name in LITERAL_TYPE_NAMES) { | 134 for (final name in LITERAL_TYPE_NAMES) { |
| 135 ClassElement classElement = coreLibrary.findLocal(name); | 135 ClassElement classElement = coreLibrary.findLocal(name); |
| 136 classElement.ensureResolved(resolution); | 136 classElement.ensureResolved(resolution); |
| 137 } | 137 } |
| 138 // Enqueue the methods that the VM might invoke on user objects because | 138 // Enqueue the methods that the VM might invoke on user objects because |
| 139 // we don't trust the resolution to always get these included. | 139 // we don't trust the resolution to always get these included. |
| 140 world.registerDynamicUse(new UniverseSelector(Selectors.toString_, null)); | 140 world.registerDynamicUse(new DynamicUse(Selectors.toString_, null)); |
| 141 world.registerDynamicUse( | 141 world.registerDynamicUse( |
| 142 new UniverseSelector(Selectors.hashCode_, null)); | 142 new DynamicUse(Selectors.hashCode_, null)); |
| 143 world.registerDynamicUse( | 143 world.registerDynamicUse( |
| 144 new UniverseSelector(new Selector.binaryOperator('=='), null)); | 144 new DynamicUse(new Selector.binaryOperator('=='), null)); |
| 145 world.registerDynamicUse( | 145 world.registerDynamicUse( |
| 146 new UniverseSelector(Selectors.compareTo, null)); | 146 new DynamicUse(Selectors.compareTo, null)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 WorldImpact codegen(CodegenWorkItem work) { | 149 WorldImpact codegen(CodegenWorkItem work) { |
| 150 return const WorldImpact(); | 150 return const WorldImpact(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Tells whether we should output given element. Corelib classes like | 154 * Tells whether we should output given element. Corelib classes like |
| 155 * Object should not be in the resulting code. | 155 * Object should not be in the resulting code. |
| 156 */ | 156 */ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 {bool mirrorUsage: false}) { | 267 {bool mirrorUsage: false}) { |
| 268 registerPlatformMembers(type, registerUse: registry.registerDynamicUse); | 268 registerPlatformMembers(type, registerUse: registry.registerDynamicUse); |
| 269 super.registerInstantiatedType( | 269 super.registerInstantiatedType( |
| 270 type, enqueuer, registry, mirrorUsage: mirrorUsage); | 270 type, enqueuer, registry, mirrorUsage: mirrorUsage); |
| 271 } | 271 } |
| 272 | 272 |
| 273 /// Register dynamic access of members of [type] that implement members | 273 /// Register dynamic access of members of [type] that implement members |
| 274 /// of types defined in the platform libraries. | 274 /// of types defined in the platform libraries. |
| 275 void registerPlatformMembers( | 275 void registerPlatformMembers( |
| 276 InterfaceType type, | 276 InterfaceType type, |
| 277 {void registerUse(UniverseSelector selector)}) { | 277 {void registerUse(DynamicUse dynamicUse)}) { |
| 278 | 278 |
| 279 // Without patching, dart2dart has no way of performing sound tree-shaking | 279 // Without patching, dart2dart has no way of performing sound tree-shaking |
| 280 // in face external functions. Therefore we employ another scheme: | 280 // in face external functions. Therefore we employ another scheme: |
| 281 // | 281 // |
| 282 // Based on the assumption that the platform code only relies on the | 282 // Based on the assumption that the platform code only relies on the |
| 283 // interfaces of it's own classes, we can approximate the semantics of | 283 // interfaces of it's own classes, we can approximate the semantics of |
| 284 // external functions by eagerly registering dynamic invocation of instance | 284 // external functions by eagerly registering dynamic invocation of instance |
| 285 // members defined the platform interfaces. | 285 // members defined the platform interfaces. |
| 286 // | 286 // |
| 287 // Since we only need to generate code for non-platform classes we can | 287 // Since we only need to generate code for non-platform classes we can |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // Register selectors for all instance methods since these might | 320 // Register selectors for all instance methods since these might |
| 321 // be called on user classes from within the platform | 321 // be called on user classes from within the platform |
| 322 // implementation. | 322 // implementation. |
| 323 superclass.forEachLocalMember((MemberElement element) { | 323 superclass.forEachLocalMember((MemberElement element) { |
| 324 if (element.isConstructor || element.isStatic) return; | 324 if (element.isConstructor || element.isStatic) return; |
| 325 | 325 |
| 326 FunctionElement function = element.asFunctionElement(); | 326 FunctionElement function = element.asFunctionElement(); |
| 327 element.computeType(resolution); | 327 element.computeType(resolution); |
| 328 Selector selector = new Selector.fromElement(element); | 328 Selector selector = new Selector.fromElement(element); |
| 329 registerUse( | 329 registerUse( |
| 330 new UniverseSelector(selector, null)); | 330 new DynamicUse(selector, null)); |
| 331 }); | 331 }); |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 | 337 |
| 338 @override | 338 @override |
| 339 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { | 339 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { |
| 340 // TODO(sigurdm): Implement deferred loading for dart2dart. | 340 // TODO(sigurdm): Implement deferred loading for dart2dart. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 549 } |
| 550 | 550 |
| 551 // TODO(johnniwinther): Remove this when values are computed from the | 551 // TODO(johnniwinther): Remove this when values are computed from the |
| 552 // expressions. | 552 // expressions. |
| 553 @override | 553 @override |
| 554 void copyConstantValues(DartConstantTask task) { | 554 void copyConstantValues(DartConstantTask task) { |
| 555 constantCompiler.constantValueMap.addAll( | 555 constantCompiler.constantValueMap.addAll( |
| 556 task.constantCompiler.constantValueMap); | 556 task.constantCompiler.constantValueMap); |
| 557 } | 557 } |
| 558 } | 558 } |
| OLD | NEW |