Chromium Code Reviews| Index: lib/compiler/implementation/universe.dart |
| =================================================================== |
| --- lib/compiler/implementation/universe.dart (revision 7416) |
| +++ lib/compiler/implementation/universe.dart (working copy) |
| @@ -15,6 +15,7 @@ |
| // TODO(ngeoffray): This should be a Set<Type>. |
| final Set<Element> isChecks; |
| final RuntimeTypeInformation rti; |
| + final Map<ClassElement, Set<ClassElement>> subtypes; |
| Universe() : generatedCode = new Map<Element, String>(), |
| generatedBailoutCode = new Map<Element, String>(), |
| @@ -26,6 +27,7 @@ |
| invokedGetters = new Map<SourceString, Set<Selector>>(), |
| invokedSetters = new Map<SourceString, Set<Selector>>(), |
| isChecks = new Set<Element>(), |
| + subtypes = new Map<ClassElement, Set<ClassElement>>(), |
| rti = new RuntimeTypeInformation(); |
| void addGeneratedCode(WorkItem work, String code) { |
| @@ -59,9 +61,49 @@ |
| bool hasSetter(Element member, Compiler compiler) { |
| return hasMatchingSelector( |
| compiler.universe.invokedSetters[member.name], member, compiler); |
| - } |
| + } |
| + |
| + /** |
| + * Returns a [MemberSet] that contains the possible targets of a |
| + * selector named [member] on a receiver whose type is [type]. |
|
kasperl
2012/05/09 08:04:23
Wouldn't it be more logical to let this be paramet
ngeoffray
2012/05/09 10:07:58
Yes, that's what I started with. But right now, th
|
| + */ |
| + MemberSet memberSetFor(Type type, SourceString member) { |
| + ClassElement cls = type.element; |
| + MemberSet result = new MemberSet(member); |
| + Element element = cls.lookupMember(member); |
| + if (element !== null) result.add(element); |
| + |
| + Set<ClassElement> subtypes = subtypes[cls]; |
| + if (subtypes !== null) { |
| + for (ClassElement sub in subtypes) { |
| + element = sub.lookupLocalMember(member); |
| + if (element !== null) result.add(element); |
| + } |
| + } |
| + return result; |
| + } |
| } |
| +/** |
| + * A [MemberSet] contains all the possible targets for a selector. |
| + */ |
| +class MemberSet { |
| + final Set<Element> elements; |
| + final SourceString name; |
| + |
| + MemberSet(SourceString this.name) : elements = new Set<Element>(); |
| + |
| + void add(Element element) { |
| + elements.add(element); |
| + } |
| + |
| + bool isEmpty() => elements.isEmpty(); |
| + |
| + bool hasJustFields() { |
| + return elements.every((Element element) => element.isField()); |
| + } |
| +} |
| + |
| class SelectorKind { |
| final String name; |
| const SelectorKind(this.name); |