Chromium Code Reviews| Index: lib/compiler/implementation/world.dart |
| =================================================================== |
| --- lib/compiler/implementation/world.dart (revision 0) |
| +++ lib/compiler/implementation/world.dart (revision 0) |
| @@ -0,0 +1,49 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +class World { |
| + final Map<ClassElement, Set<ClassElement>> subtypes; |
| + |
| + World() : subtypes = new Map<ClassElement, Set<ClassElement>>(); |
| + |
| + /** |
| + * Returns a [MemberSet] that contains the possible targets of a |
| + * selector named [member] on a receiver whose type is [type]. |
| + */ |
| + MemberSet memberSetFor(Type type, SourceString member) { |
|
kasperl
2012/05/09 11:13:03
I'm not sure this functionality needs to be expose
ngeoffray
2012/05/09 11:34:22
Made it library private.
|
| + 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()); |
| + } |
| +} |