| 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('native'); | 5 #library('native'); |
| 6 #import('dart:uri'); | 6 #import('dart:uri'); |
| 7 #import('leg.dart'); | 7 #import('leg.dart'); |
| 8 #import('elements/elements.dart'); | 8 #import('elements/elements.dart'); |
| 9 #import('scanner/scannerlib.dart'); | 9 #import('scanner/scannerlib.dart'); |
| 10 #import('ssa/ssa.dart'); | 10 #import('ssa/ssa.dart'); |
| 11 #import('tree/tree.dart'); | 11 #import('tree/tree.dart'); |
| 12 #import('util/util.dart'); | 12 #import('util/util.dart'); |
| 13 | 13 |
| 14 void processNativeClasses(CodeEmitterTask emitter, | 14 void processNativeClasses(Enqueuer world, |
| 15 CodeEmitterTask emitter, |
| 15 Collection<LibraryElement> libraries) { | 16 Collection<LibraryElement> libraries) { |
| 16 for (LibraryElement library in libraries) { | 17 for (LibraryElement library in libraries) { |
| 17 processNativeClassesInLibrary(emitter, library); | 18 processNativeClassesInLibrary(world, emitter, library); |
| 18 } | 19 } |
| 19 } | 20 } |
| 20 | 21 |
| 21 void addSubtypes(ClassElement cls, | 22 void addSubtypes(ClassElement cls, |
| 22 NativeEmitter emitter) { | 23 NativeEmitter emitter) { |
| 23 for (Type type in cls.allSupertypes) { | 24 for (Type type in cls.allSupertypes) { |
| 24 List<Element> subtypes = emitter.subtypes.putIfAbsent( | 25 List<Element> subtypes = emitter.subtypes.putIfAbsent( |
| 25 type.element, | 26 type.element, |
| 26 () => <ClassElement>[]); | 27 () => <ClassElement>[]); |
| 27 subtypes.add(cls); | 28 subtypes.add(cls); |
| 28 } | 29 } |
| 29 | 30 |
| 30 List<Element> directSubtypes = emitter.directSubtypes.putIfAbsent( | 31 List<Element> directSubtypes = emitter.directSubtypes.putIfAbsent( |
| 31 cls.superclass, | 32 cls.superclass, |
| 32 () => <ClassElement>[]); | 33 () => <ClassElement>[]); |
| 33 directSubtypes.add(cls); | 34 directSubtypes.add(cls); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void processNativeClassesInLibrary(CodeEmitterTask emitter, | 37 void processNativeClassesInLibrary(Enqueuer world, |
| 38 CodeEmitterTask emitter, |
| 37 LibraryElement library) { | 39 LibraryElement library) { |
| 38 bool hasNativeClass = false; | 40 bool hasNativeClass = false; |
| 39 final compiler = emitter.compiler; | 41 final compiler = emitter.compiler; |
| 40 for (Link<Element> link = library.topLevelElements; | 42 for (Link<Element> link = library.topLevelElements; |
| 41 !link.isEmpty(); link = link.tail) { | 43 !link.isEmpty(); link = link.tail) { |
| 42 Element element = link.head; | 44 Element element = link.head; |
| 43 if (element.kind == ElementKind.CLASS) { | 45 if (element.kind == ElementKind.CLASS) { |
| 44 ClassElement classElement = element; | 46 ClassElement classElement = element; |
| 45 if (classElement.isNative()) { | 47 if (classElement.isNative()) { |
| 46 hasNativeClass = true; | 48 hasNativeClass = true; |
| 47 compiler.registerInstantiatedClass(classElement); | 49 world.registerInstantiatedClass(classElement); |
| 48 // Also parse the node to know all its methods because | 50 // Also parse the node to know all its methods because |
| 49 // otherwise it will only be parsed if there is a call to | 51 // otherwise it will only be parsed if there is a call to |
| 50 // one of its constructor. | 52 // one of its constructor. |
| 51 classElement.parseNode(compiler); | 53 classElement.parseNode(compiler); |
| 52 // Resolve to setup the inheritance. | 54 // Resolve to setup the inheritance. |
| 53 classElement.ensureResolved(compiler); | 55 classElement.ensureResolved(compiler); |
| 54 // Add the information that this class is a subtype of | 56 // Add the information that this class is a subtype of |
| 55 // its supertypes. The code emitter and the ssa builder use that | 57 // its supertypes. The code emitter and the ssa builder use that |
| 56 // information. | 58 // information. |
| 57 addSubtypes(classElement, emitter.nativeEmitter); | 59 addSubtypes(classElement, emitter.nativeEmitter); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 if (hasNativeClass) { | 63 if (hasNativeClass) { |
| 62 final worlds = [compiler.enqueuer.resolution, compiler.enqueuer.codegen]; | 64 world.registerStaticUse(compiler.findHelper( |
| 63 for (var world in worlds) { | 65 const SourceString('dynamicFunction'))); |
| 64 world.registerStaticUse(compiler.findHelper( | 66 world.registerStaticUse(compiler.findHelper( |
| 65 const SourceString('dynamicFunction'))); | 67 const SourceString('dynamicSetMetadata'))); |
| 66 world.registerStaticUse(compiler.findHelper( | 68 world.registerStaticUse(compiler.findHelper( |
| 67 const SourceString('dynamicSetMetadata'))); | 69 const SourceString('defineProperty'))); |
| 68 world.registerStaticUse(compiler.findHelper( | 70 world.registerStaticUse(compiler.findHelper( |
| 69 const SourceString('defineProperty'))); | 71 const SourceString('toStringForNativeObject'))); |
| 70 world.registerStaticUse(compiler.findHelper( | |
| 71 const SourceString('toStringForNativeObject'))); | |
| 72 } | |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 void maybeEnableNative(Compiler compiler, | 75 void maybeEnableNative(Compiler compiler, |
| 77 LibraryElement library, | 76 LibraryElement library, |
| 78 Uri uri) { | 77 Uri uri) { |
| 79 String libraryName = uri.toString(); | 78 String libraryName = uri.toString(); |
| 80 if (library.script.name.contains('dart/frog/tests/frog_native') | 79 if (library.script.name.contains('dart/frog/tests/frog_native') |
| 81 || libraryName == 'dart:dom_deprecated' | 80 || libraryName == 'dart:dom_deprecated' |
| 82 || libraryName == 'dart:isolate' | 81 || libraryName == 'dart:isolate' |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 String parameters) { | 349 String parameters) { |
| 351 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); | 350 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); |
| 352 buffer.add("('$methodName')) {\n"); | 351 buffer.add("('$methodName')) {\n"); |
| 353 buffer.add(" $code"); | 352 buffer.add(" $code"); |
| 354 buffer.add(" } else {\n"); | 353 buffer.add(" } else {\n"); |
| 355 buffer.add(" return Object.prototype.$methodName.call(this"); | 354 buffer.add(" return Object.prototype.$methodName.call(this"); |
| 356 buffer.add(parameters == '' ? '' : ', $parameters'); | 355 buffer.add(parameters == '' ? '' : ', $parameters'); |
| 357 buffer.add(");\n"); | 356 buffer.add(");\n"); |
| 358 buffer.add(" }\n"); | 357 buffer.add(" }\n"); |
| 359 } | 358 } |
| OLD | NEW |