| 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 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart2jslib.dart' hide SourceString; | 8 import 'dart2jslib.dart' hide SourceString; |
| 9 import 'elements/elements.dart'; | 9 import 'elements/elements.dart'; |
| 10 import 'js_backend/js_backend.dart'; | 10 import 'js_backend/js_backend.dart'; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 ClassElement _annotationCreatesClass; | 98 ClassElement _annotationCreatesClass; |
| 99 ClassElement _annotationReturnsClass; | 99 ClassElement _annotationReturnsClass; |
| 100 ClassElement _annotationJsNameClass; | 100 ClassElement _annotationJsNameClass; |
| 101 | 101 |
| 102 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 102 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 103 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); | 103 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); |
| 104 | 104 |
| 105 void processNativeClasses(Collection<LibraryElement> libraries) { | 105 void processNativeClasses(Collection<LibraryElement> libraries) { |
| 106 libraries.forEach(processNativeClassesInLibrary); | 106 libraries.forEach(processNativeClassesInLibrary); |
| 107 processNativeClass(compiler.listClass); |
| 108 processNativeClass(compiler.stringClass); |
| 109 processNativeClass(compiler.intClass); |
| 110 processNativeClass(compiler.doubleClass); |
| 111 processNativeClass(compiler.nullClass); |
| 107 if (!enableLiveTypeAnalysis) { | 112 if (!enableLiveTypeAnalysis) { |
| 108 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); | 113 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); |
| 109 flushQueue(); | 114 flushQueue(); |
| 110 } | 115 } |
| 111 } | 116 } |
| 112 | 117 |
| 113 void processNativeClassesInLibrary(LibraryElement library) { | 118 void processNativeClassesInLibrary(LibraryElement library) { |
| 114 // Use implementation to ensure the inclusion of injected members. | 119 // Use implementation to ensure the inclusion of injected members. |
| 115 library.implementation.forEachLocalMember((Element element) { | 120 library.implementation.forEachLocalMember((Element element) { |
| 116 if (element.kind == ElementKind.CLASS) { | 121 if (element.isClass() && element.isNative()) { |
| 117 ClassElement classElement = element; | 122 processNativeClass(element); |
| 118 if (classElement.isNative()) { | |
| 119 nativeClasses.add(classElement); | |
| 120 unusedClasses.add(classElement); | |
| 121 | |
| 122 // Resolve class to ensure the class has valid inheritance info. | |
| 123 classElement.ensureResolved(compiler); | |
| 124 } | |
| 125 } | 123 } |
| 126 }); | 124 }); |
| 127 } | 125 } |
| 128 | 126 |
| 127 void processNativeClass(ClassElement classElement) { |
| 128 nativeClasses.add(classElement); |
| 129 unusedClasses.add(classElement); |
| 130 // Resolve class to ensure the class has valid inheritance info. |
| 131 classElement.ensureResolved(compiler); |
| 132 } |
| 133 |
| 129 ClassElement get annotationCreatesClass { | 134 ClassElement get annotationCreatesClass { |
| 130 findAnnotationClasses(); | 135 findAnnotationClasses(); |
| 131 return _annotationCreatesClass; | 136 return _annotationCreatesClass; |
| 132 } | 137 } |
| 133 | 138 |
| 134 ClassElement get annotationReturnsClass { | 139 ClassElement get annotationReturnsClass { |
| 135 findAnnotationClasses(); | 140 findAnnotationClasses(); |
| 136 return _annotationReturnsClass; | 141 return _annotationReturnsClass; |
| 137 } | 142 } |
| 138 | 143 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 flushQueue(); | 309 flushQueue(); |
| 305 } | 310 } |
| 306 | 311 |
| 307 processNativeBehavior(NativeBehavior behavior, cause) { | 312 processNativeBehavior(NativeBehavior behavior, cause) { |
| 308 bool allUsedBefore = unusedClasses.isEmpty; | 313 bool allUsedBefore = unusedClasses.isEmpty; |
| 309 for (var type in behavior.typesInstantiated) { | 314 for (var type in behavior.typesInstantiated) { |
| 310 if (matchedTypeConstraints.contains(type)) continue; | 315 if (matchedTypeConstraints.contains(type)) continue; |
| 311 matchedTypeConstraints.add(type); | 316 matchedTypeConstraints.add(type); |
| 312 if (type is SpecialType) { | 317 if (type is SpecialType) { |
| 313 if (type == SpecialType.JsArray) { | 318 if (type == SpecialType.JsArray) { |
| 314 world.registerInstantiatedClass(compiler.listClass); | 319 enqueueClass(compiler.listClass, 'core type'); |
| 315 } else if (type == SpecialType.JsObject) { | 320 } else if (type == SpecialType.JsObject) { |
| 316 world.registerInstantiatedClass(compiler.objectClass); | 321 enqueueClass(compiler.objectClass, 'core type'); |
| 317 } | 322 } |
| 318 continue; | 323 continue; |
| 319 } | 324 } |
| 320 if (type is InterfaceType) { | |
| 321 if (type.element == compiler.intClass) { | |
| 322 world.registerInstantiatedClass(compiler.intClass); | |
| 323 } else if (type.element == compiler.doubleClass) { | |
| 324 world.registerInstantiatedClass(compiler.doubleClass); | |
| 325 } else if (type.element == compiler.numClass) { | |
| 326 world.registerInstantiatedClass(compiler.numClass); | |
| 327 } else if (type.element == compiler.stringClass) { | |
| 328 world.registerInstantiatedClass(compiler.stringClass); | |
| 329 } else if (type.element == compiler.nullClass) { | |
| 330 world.registerInstantiatedClass(compiler.nullClass); | |
| 331 } else if (type.element == compiler.boolClass) { | |
| 332 world.registerInstantiatedClass(compiler.boolClass); | |
| 333 } | |
| 334 } | |
| 335 assert(type is DartType); | 325 assert(type is DartType); |
| 336 enqueueUnusedClassesMatching( | 326 enqueueUnusedClassesMatching( |
| 337 (nativeClass) => compiler.types.isSubtype(nativeClass.thisType, type), | 327 (nativeClass) => compiler.types.isSubtype(nativeClass.thisType, type), |
| 338 cause, | 328 cause, |
| 339 'subtypeof($type)'); | 329 'subtypeof($type)'); |
| 340 } | 330 } |
| 341 | 331 |
| 342 // Give an info so that library developers can compile with -v to find why | 332 // Give an info so that library developers can compile with -v to find why |
| 343 // all the native classes are included. | 333 // all the native classes are included. |
| 344 if (unusedClasses.isEmpty && !allUsedBefore) { | 334 if (unusedClasses.isEmpty && !allUsedBefore) { |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 builder.add(new HForeign( | 878 builder.add(new HForeign( |
| 889 new DartString.literal('${parameter.name.slowToString()} = #'), | 879 new DartString.literal('${parameter.name.slowToString()} = #'), |
| 890 const LiteralDartString('void'), | 880 const LiteralDartString('void'), |
| 891 <HInstruction>[jsClosure])); | 881 <HInstruction>[jsClosure])); |
| 892 } | 882 } |
| 893 }); | 883 }); |
| 894 LiteralString jsCode = nativeBody.asLiteralString(); | 884 LiteralString jsCode = nativeBody.asLiteralString(); |
| 895 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 885 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
| 896 } | 886 } |
| 897 } | 887 } |
| OLD | NEW |