| 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; | 5 part of dart2js; |
| 6 | 6 |
| 7 class EnqueueTask extends CompilerTask { | 7 class EnqueueTask extends CompilerTask { |
| 8 final ResolutionEnqueuer resolution; | 8 final ResolutionEnqueuer resolution; |
| 9 final CodegenEnqueuer codegen; | 9 final CodegenEnqueuer codegen; |
| 10 | 10 |
| 11 /// A reverse map from name to *all* elements with that name, not | 11 /// A reverse map from name to *all* elements with that name, not |
| 12 /// just instance members of instantiated classes. | 12 /// just instance members of instantiated classes. |
| 13 final Map<String, Link<Element>> allElementsByName | 13 final Map<String, Link<Element>> allElementsByName |
| 14 = new Map<String, Link<Element>>(); | 14 = new Map<String, Link<Element>>(); |
| 15 | 15 |
| 16 void ensureAllElementsByName() { | 16 void ensureAllElementsByName() { |
| 17 if (!allElementsByName.isEmpty) return; | 17 if (!allElementsByName.isEmpty) return; |
| 18 | 18 |
| 19 void addMemberByName(Element element) { | 19 void addMemberByName(Element element) { |
| 20 element = element.declaration; | 20 element = element.declaration; |
| 21 String name = element.name.slowToString(); | 21 String name = element.name.slowToString(); |
| 22 Link<Element> members = const Link<Element>(); | 22 ScopeContainerElement container = null; |
| 23 if (element.isLibrary()) { | 23 if (element.isLibrary()) { |
| 24 LibraryElementX library = element; | 24 LibraryElement library = element; |
| 25 // Don't include private implementation libraries. These | 25 // Don't include private implementation libraries. These |
| 26 // libraries contain special classes that cause problems | 26 // libraries contain special classes that cause problems |
| 27 // in other parts of the resolver (in particular Null and Void). | 27 // in other parts of the resolver (in particular Null and Void). |
| 28 // TODO(ahe): Consider lifting this restriction. | 28 // TODO(ahe): Consider lifting this restriction. |
| 29 if (!library.isInternalLibrary) { | 29 if (!library.isInternalLibrary) { |
| 30 members = library.localMembers; | 30 container = library; |
| 31 // TODO(ahe): Is this right? Is this necessary? | 31 // TODO(ahe): Is this right? Is this necessary? |
| 32 name = library.getLibraryOrScriptName(); | 32 name = library.getLibraryOrScriptName(); |
| 33 } | 33 } |
| 34 } else if (element.isClass() && !element.isMixinApplication) { | 34 } else if (element.isClass()) { |
| 35 // TODO(ahe): Investigate what makes mixin applications crash | 35 ClassElement cls = element; |
| 36 // this method. | |
| 37 ClassElementX cls = element; | |
| 38 cls.ensureResolved(compiler); | 36 cls.ensureResolved(compiler); |
| 39 members = cls.localMembers; | 37 container = cls; |
| 40 for (var link = cls.computeTypeParameters(compiler); | 38 for (var link = cls.computeTypeParameters(compiler); |
| 41 !link.isEmpty; | 39 !link.isEmpty; |
| 42 link = link.tail) { | 40 link = link.tail) { |
| 43 addMemberByName(link.head.element); | 41 addMemberByName(link.head.element); |
| 44 } | 42 } |
| 45 } | 43 } |
| 46 allElementsByName[name] = allElementsByName.putIfAbsent( | 44 allElementsByName[name] = allElementsByName.putIfAbsent( |
| 47 name, () => const Link<Element>()).prepend(element); | 45 name, () => const Link<Element>()).prepend(element); |
| 48 for (var link = members; !link.isEmpty; link = link.tail) { | 46 if (container != null) { |
| 49 addMemberByName(link.head); | 47 container.forEachLocalMember(addMemberByName); |
| 50 } | 48 } |
| 51 } | 49 } |
| 52 | 50 |
| 53 compiler.libraries.values.forEach(addMemberByName); | 51 compiler.libraries.values.forEach(addMemberByName); |
| 54 } | 52 } |
| 55 | 53 |
| 56 String get name => 'Enqueue'; | 54 String get name => 'Enqueue'; |
| 57 | 55 |
| 58 EnqueueTask(Compiler compiler) | 56 EnqueueTask(Compiler compiler) |
| 59 : resolution = new ResolutionEnqueuer( | 57 : resolution = new ResolutionEnqueuer( |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 if (!compiler.backend.isNeededForReflection(element)) return; | 314 if (!compiler.backend.isNeededForReflection(element)) return; |
| 317 if (Elements.isUnresolved(element)) { | 315 if (Elements.isUnresolved(element)) { |
| 318 // Ignore. | 316 // Ignore. |
| 319 } else if (element.isSynthesized | 317 } else if (element.isSynthesized |
| 320 && element.getLibrary().isPlatformLibrary) { | 318 && element.getLibrary().isPlatformLibrary) { |
| 321 // TODO(ahe): Work-around for http://dartbug.com/11205. | 319 // TODO(ahe): Work-around for http://dartbug.com/11205. |
| 322 } else if (element.isConstructor()) { | 320 } else if (element.isConstructor()) { |
| 323 ClassElement cls = element.declaration.getEnclosingClass(); | 321 ClassElement cls = element.declaration.getEnclosingClass(); |
| 324 registerInstantiatedType(cls.rawType, elements); | 322 registerInstantiatedType(cls.rawType, elements); |
| 325 registerStaticUse(element.declaration); | 323 registerStaticUse(element.declaration); |
| 326 } else if (element.isMixinApplication) { | |
| 327 // Don't enqueue mixin applications. | |
| 328 } else if (element.isClass()) { | 324 } else if (element.isClass()) { |
| 329 ClassElement cls = element.declaration; | 325 ClassElement cls = element.declaration; |
| 330 registerInstantiatedType(cls.rawType, elements); | 326 registerInstantiatedClass(cls, elements); |
| 331 // Make sure that even abstract classes are considered instantiated. | 327 // Make sure that even abstract classes are considered instantiated. |
| 332 universe.instantiatedClasses.add(cls); | 328 universe.instantiatedClasses.add(cls); |
| 333 } else if (element.impliesType()) { | 329 } else if (element.impliesType()) { |
| 334 // Don't enqueue typedefs, and type variables. | 330 // Don't enqueue typedefs, and type variables. |
| 335 } else if (Elements.isStaticOrTopLevel(element)) { | 331 } else if (Elements.isStaticOrTopLevel(element)) { |
| 336 registerStaticUse(element.declaration); | 332 registerStaticUse(element.declaration); |
| 337 } else if (element.isInstanceMember()) { | 333 } else if (element.isInstanceMember()) { |
| 338 Selector selector = new Selector.fromElement(element, compiler); | 334 Selector selector = new Selector.fromElement(element, compiler); |
| 339 registerSelectorUse(selector); | 335 registerSelectorUse(selector); |
| 340 if (element.isField()) { | 336 if (element.isField()) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 while(!queue.isEmpty) { | 729 while(!queue.isEmpty) { |
| 734 // TODO(johnniwinther): Find an optimal process order for codegen. | 730 // TODO(johnniwinther): Find an optimal process order for codegen. |
| 735 f(queue.removeLast()); | 731 f(queue.removeLast()); |
| 736 } | 732 } |
| 737 } | 733 } |
| 738 | 734 |
| 739 void _logSpecificSummary(log(message)) { | 735 void _logSpecificSummary(log(message)) { |
| 740 log('Compiled ${generatedCode.length} methods.'); | 736 log('Compiled ${generatedCode.length} methods.'); |
| 741 } | 737 } |
| 742 } | 738 } |
| OLD | NEW |