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 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter"); | 7 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter"); |
8 | 8 |
9 /** | 9 /** |
10 * Generates the code for all used classes in the program. Static fields (even | 10 * Generates the code for all used classes in the program. Static fields (even |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // 1. We need to generate all classes that are instantiated. | 276 // 1. We need to generate all classes that are instantiated. |
277 addClassesWithSuperclasses(instantiatedClasses); | 277 addClassesWithSuperclasses(instantiatedClasses); |
278 | 278 |
279 // 2. Add all classes used as mixins. | 279 // 2. Add all classes used as mixins. |
280 Set<ClassElement> mixinClasses = neededClasses | 280 Set<ClassElement> mixinClasses = neededClasses |
281 .where((ClassElement element) => element.isMixinApplication) | 281 .where((ClassElement element) => element.isMixinApplication) |
282 .map(computeMixinClass) | 282 .map(computeMixinClass) |
283 .toSet(); | 283 .toSet(); |
284 neededClasses.addAll(mixinClasses); | 284 neededClasses.addAll(mixinClasses); |
285 | 285 |
286 // 3. If we need noSuchMethod support, we run through all needed | 286 // 3. Find all classes needed for rti. |
287 // classes to figure out if we need the support on any native | |
288 // class. If so, we let the native emitter deal with it. | |
289 if (compiler.enabledNoSuchMethod) { | |
290 String noSuchMethodName = Compiler.NO_SUCH_METHOD; | |
291 Selector noSuchMethodSelector = compiler.noSuchMethodSelector; | |
292 for (ClassElement element in neededClasses) { | |
293 if (!element.isNative) continue; | |
294 Element member = element.lookupLocalMember(noSuchMethodName); | |
295 if (member == null) continue; | |
296 if (noSuchMethodSelector.applies(member, compiler.world)) { | |
297 nativeEmitter.handleNoSuchMethod = true; | |
298 break; | |
299 } | |
300 } | |
301 } | |
302 | |
303 // 4. Find all classes needed for rti. | |
304 // It is important that this is the penultimate step, at this point, | 287 // It is important that this is the penultimate step, at this point, |
305 // neededClasses must only contain classes that have been resolved and | 288 // neededClasses must only contain classes that have been resolved and |
306 // codegen'd. The rtiNeededClasses may contain additional classes, but | 289 // codegen'd. The rtiNeededClasses may contain additional classes, but |
307 // these are thought to not have been instantiated, so we neeed to be able | 290 // these are thought to not have been instantiated, so we neeed to be able |
308 // to identify them later and make sure we only emit "empty shells" without | 291 // to identify them later and make sure we only emit "empty shells" without |
309 // fields, etc. | 292 // fields, etc. |
310 typeTestRegistry.computeRtiNeededClasses(); | 293 typeTestRegistry.computeRtiNeededClasses(); |
311 | 294 |
312 // TODO(floitsch): either change the name, or get the rti-classes | 295 // TODO(floitsch): either change the name, or get the rti-classes |
313 // differently. | 296 // differently. |
(...skipping 14 matching lines...) Expand all Loading... |
328 if (neededClasses.contains(backend.jsStringClass)) { | 311 if (neededClasses.contains(backend.jsStringClass)) { |
329 neededClasses.add(compiler.stringClass); | 312 neededClasses.add(compiler.stringClass); |
330 } | 313 } |
331 if (neededClasses.contains(backend.jsBoolClass)) { | 314 if (neededClasses.contains(backend.jsBoolClass)) { |
332 neededClasses.add(compiler.boolClass); | 315 neededClasses.add(compiler.boolClass); |
333 } | 316 } |
334 if (neededClasses.contains(backend.jsArrayClass)) { | 317 if (neededClasses.contains(backend.jsArrayClass)) { |
335 neededClasses.add(compiler.listClass); | 318 neededClasses.add(compiler.listClass); |
336 } | 319 } |
337 | 320 |
338 // 5. Finally, sort the classes. | 321 // 4. Finally, sort the classes. |
339 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses); | 322 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses); |
340 | 323 |
341 for (ClassElement element in sortedClasses) { | 324 for (ClassElement element in sortedClasses) { |
342 if (Elements.isNativeOrExtendsNative(element) && | 325 if (Elements.isNativeOrExtendsNative(element) && |
343 !typeTestRegistry.rtiNeededClasses.contains(element)) { | 326 !typeTestRegistry.rtiNeededClasses.contains(element)) { |
344 // For now, native classes and related classes cannot be deferred. | 327 // For now, native classes and related classes cannot be deferred. |
345 nativeClassesAndSubclasses.add(element); | 328 nativeClassesAndSubclasses.add(element); |
346 assert(invariant(element, | 329 assert(invariant(element, |
347 !compiler.deferredLoadTask.isDeferred(element))); | 330 !compiler.deferredLoadTask.isDeferred(element))); |
348 outputClassLists.putIfAbsent(compiler.deferredLoadTask.mainOutputUnit, | 331 outputClassLists.putIfAbsent(compiler.deferredLoadTask.mainOutputUnit, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 jsAst.Expression typeAccess(Element e); | 442 jsAst.Expression typeAccess(Element e); |
460 | 443 |
461 /// Returns the JS expression representing a function that returns 'null' | 444 /// Returns the JS expression representing a function that returns 'null' |
462 jsAst.Expression generateFunctionThatReturnsNull(); | 445 jsAst.Expression generateFunctionThatReturnsNull(); |
463 | 446 |
464 int compareConstants(ConstantValue a, ConstantValue b); | 447 int compareConstants(ConstantValue a, ConstantValue b); |
465 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); | 448 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); |
466 | 449 |
467 void invalidateCaches(); | 450 void invalidateCaches(); |
468 } | 451 } |
OLD | NEW |