Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: lib/compiler/implementation/world.dart

Issue 10832109: Refactor the way we emit no such method handlers so it's easier to optimize it later. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve NSM handling. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | runtime/lib/object.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class World { 5 class World {
6 Compiler compiler; // Set in populate().
6 final Map<ClassElement, Set<ClassElement>> subtypes; 7 final Map<ClassElement, Set<ClassElement>> subtypes;
7 8
8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>(); 9 World() : subtypes = new Map<ClassElement, Set<ClassElement>>();
9 10
10 void populate(Compiler compiler, Collection<LibraryElement> libraries) { 11 void populate(Compiler compiler, Collection<LibraryElement> libraries) {
11 void addSubtypes(ClassElement cls) { 12 void addSubtypes(ClassElement cls) {
12 for (Type type in cls.allSupertypes) { 13 for (Type type in cls.allSupertypes) {
13 Set<Element> subtypesOfCls = subtypes.putIfAbsent( 14 Set<Element> subtypesOfCls = subtypes.putIfAbsent(
14 type.element, 15 type.element,
15 () => new Set<ClassElement>()); 16 () => new Set<ClassElement>());
16 subtypesOfCls.add(cls); 17 subtypesOfCls.add(cls);
17 } 18 }
18 } 19 }
19 20
20 libraries.forEach((LibraryElement library) { 21 libraries.forEach((LibraryElement library) {
21 for (Link<Element> link = library.topLevelElements; 22 for (Link<Element> link = library.topLevelElements;
22 !link.isEmpty(); 23 !link.isEmpty();
23 link = link.tail) { 24 link = link.tail) {
24 Element element = link.head; 25 Element element = link.head;
25 if (!element.isClass()) continue; 26 if (!element.isClass()) continue;
26 ClassElement cls = element; 27 ClassElement cls = element;
27 compiler.resolveClass(cls); 28 compiler.resolveClass(cls);
28 addSubtypes(cls); 29 addSubtypes(cls);
29 } 30 }
30 }); 31 });
32
33 // Mark the world as populated.
34 assert(compiler !== null);
35 this.compiler = compiler;
31 } 36 }
32 37
33 /** 38 /**
34 * Returns a [MemberSet] that contains the possible targets of a 39 * Returns a [MemberSet] that contains the possible targets of a
35 * selector named [member] on a receiver whose type is [type]. 40 * selector named [member] on a receiver whose type is [type].
36 */ 41 */
37 MemberSet _memberSetFor(Type type, SourceString member) { 42 MemberSet _memberSetFor(Type type, SourceString member) {
43 assert(compiler !== null);
38 ClassElement cls = type.element; 44 ClassElement cls = type.element;
39 MemberSet result = new MemberSet(member); 45 MemberSet result = new MemberSet(member);
40 Element element = cls.lookupMember(member); 46 Element element = cls.lookupMember(member);
41 if (element !== null) result.add(element); 47 if (element !== null) result.add(element);
42 48
43 Set<ClassElement> subtypesOfCls = subtypes[cls]; 49 Set<ClassElement> subtypesOfCls = subtypes[cls];
44 if (subtypesOfCls !== null) { 50 if (subtypesOfCls !== null) {
45 for (ClassElement sub in subtypesOfCls) { 51 for (ClassElement sub in subtypesOfCls) {
46 element = sub.lookupLocalMember(member); 52 element = sub.lookupLocalMember(member);
47 if (element !== null) result.add(element); 53 if (element !== null) result.add(element);
(...skipping 14 matching lines...) Expand all
62 memberSet.elements.forEach((Element element) { 68 memberSet.elements.forEach((Element element) {
63 if (element.isField()) { 69 if (element.isField()) {
64 field = element; 70 field = element;
65 fieldCount++; 71 fieldCount++;
66 } else { 72 } else {
67 nonFieldCount++; 73 nonFieldCount++;
68 } 74 }
69 }); 75 });
70 return (fieldCount == 1 && nonFieldCount == 0) ? field : null; 76 return (fieldCount == 1 && nonFieldCount == 0) ? field : null;
71 } 77 }
78
79 bool mayHaveUserDefinedNoSuchMethod(Type type) {
ahe 2012/08/02 17:15:05 We should consider this class as "delete-only" as
kasperl 2012/08/03 05:21:00 Yeah, that's probably better.
80 MemberSet memberSet = _memberSetFor(type, Compiler.NO_SUCH_METHOD);
81 // TODO(kasperl): Only return true if the set contains an instance
82 // method with the right signature. Remember to disregard the
83 // implementation in Object.
84 for (Element element in memberSet.elements) {
85 if (element.getEnclosingClass() !== compiler.objectClass) return true;
86 }
87 return false;
88 }
72 } 89 }
73 90
74 /** 91 /**
75 * A [MemberSet] contains all the possible targets for a selector. 92 * A [MemberSet] contains all the possible targets for a selector.
76 */ 93 */
77 class MemberSet { 94 class MemberSet {
78 final Set<Element> elements; 95 final Set<Element> elements;
79 final SourceString name; 96 final SourceString name;
80 97
81 MemberSet(SourceString this.name) : elements = new Set<Element>(); 98 MemberSet(SourceString this.name) : elements = new Set<Element>();
82 99
83 void add(Element element) { 100 void add(Element element) {
84 elements.add(element); 101 elements.add(element);
85 } 102 }
86 103
87 bool isEmpty() => elements.isEmpty(); 104 bool isEmpty() => elements.isEmpty();
88 } 105 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | runtime/lib/object.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698