| 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 class NativeEmitter { | 7 class NativeEmitter { |
| 8 | 8 |
| 9 final Map<Element, ClassBuilder> cachedBuilders; | 9 final Map<Element, ClassBuilder> cachedBuilders; |
| 10 | 10 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 .computeClassesModifiedByEmitRuntimeTypeSupport(); | 118 .computeClassesModifiedByEmitRuntimeTypeSupport(); |
| 119 | 119 |
| 120 for (Class cls in preOrder.reversed) { | 120 for (Class cls in preOrder.reversed) { |
| 121 ClassElement classElement = cls.element; | 121 ClassElement classElement = cls.element; |
| 122 // Post-order traversal ensures we visit the subclasses before their | 122 // Post-order traversal ensures we visit the subclasses before their |
| 123 // superclass. This makes it easy to tell if a class is needed because a | 123 // superclass. This makes it easy to tell if a class is needed because a |
| 124 // subclass is needed. | 124 // subclass is needed. |
| 125 ClassBuilder builder = builders[cls]; | 125 ClassBuilder builder = builders[cls]; |
| 126 bool needed = false; | 126 bool needed = false; |
| 127 if (builder == null) { | 127 if (builder == null) { |
| 128 assert(!cls.isNative); |
| 128 // Mixin applications (native+mixin) are non-native, so [classElement] | 129 // Mixin applications (native+mixin) are non-native, so [classElement] |
| 129 // has already been emitted as a regular class. Mark [classElement] as | 130 // has already been emitted as a regular class. Mark [classElement] as |
| 130 // 'needed' to ensure the native superclass is needed. | 131 // 'needed' to ensure the native superclass is needed. |
| 131 needed = true; | 132 needed = true; |
| 132 } else if (!builder.isTrivial) { | 133 } else if (!builder.isTrivial) { |
| 133 needed = true; | 134 needed = true; |
| 134 } else if (neededByConstant.contains(classElement)) { | 135 } else if (neededByConstant.contains(classElement)) { |
| 135 needed = true; | 136 needed = true; |
| 136 } else if (modifiedClasses.contains(classElement)) { | 137 } else if (modifiedClasses.contains(classElement)) { |
| 137 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer | 138 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 () => new Map<String, jsAst.Expression>()); | 224 () => new Map<String, jsAst.Expression>()); |
| 224 properties[backend.namer.nativeSpecProperty] = js.string(encoding); | 225 properties[backend.namer.nativeSpecProperty] = js.string(encoding); |
| 225 } | 226 } |
| 226 } else { | 227 } else { |
| 227 builder.addProperty( | 228 builder.addProperty( |
| 228 backend.namer.nativeSpecProperty, js.string(encoding)); | 229 backend.namer.nativeSpecProperty, js.string(encoding)); |
| 229 } | 230 } |
| 230 } | 231 } |
| 231 generateClassInfo(jsInterceptorClass); | 232 generateClassInfo(jsInterceptorClass); |
| 232 for (Class cls in classes) { | 233 for (Class cls in classes) { |
| 233 generateClassInfo(cls); | 234 if (!cls.isNative || neededClasses.contains(cls)) { |
| 235 generateClassInfo(cls); |
| 236 } |
| 234 } | 237 } |
| 235 } | 238 } |
| 236 | 239 |
| 237 // Emit the native class interceptors that were actually used. | 240 // Emit the native class interceptors that were actually used. |
| 238 for (Class cls in classes) { | 241 for (Class cls in classes) { |
| 239 ClassElement classElement = cls.element; | 242 ClassElement classElement = cls.element; |
| 240 if (!cls.isNative) continue; | 243 if (!cls.isNative) continue; |
| 241 if (neededClasses.contains(cls)) { | 244 if (neededClasses.contains(cls)) { |
| 242 ClassBuilder builder = builders[classElement]; | 245 ClassBuilder builder = builders[classElement]; |
| 243 | 246 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 targetOutput.add(';'); | 489 targetOutput.add(';'); |
| 487 } | 490 } |
| 488 targetOutput.addBuffer(jsAst.prettyPrint( | 491 targetOutput.addBuffer(jsAst.prettyPrint( |
| 489 new jsAst.ExpressionStatement(init), compiler)); | 492 new jsAst.ExpressionStatement(init), compiler)); |
| 490 targetOutput.add('\n'); | 493 targetOutput.add('\n'); |
| 491 } | 494 } |
| 492 | 495 |
| 493 targetOutput.add('\n'); | 496 targetOutput.add('\n'); |
| 494 } | 497 } |
| 495 } | 498 } |
| OLD | NEW |