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

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

Issue 10383065: Start creating a MemberSet abstraction, and use it to fold getters/setters into field accesses. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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/universe.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class World {
6 final Map<ClassElement, Set<ClassElement>> subtypes;
7
8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>();
9
10 void populate(Compiler compiler, Collection<LibraryElement> libraries) {
11 void addSubtypes(ClassElement cls) {
12 for (Type type in cls.allSupertypes) {
13 List<Element> subtypes = subtypes.putIfAbsent(
14 type.element,
15 () => <ClassElement>[]);
16 subtypes.add(cls);
17 }
18 }
19
20 libraries.forEach((LibraryElement library) {
21 for (Link<Element> link = library.topLevelElements;
22 !link.isEmpty();
23 link = link.tail) {
24 Element element = link.head;
25 if (!element.isClass()) continue;
26 ClassElement cls = element;
27 compiler.resolveClass(cls);
28 addSubtypes(cls);
29 }
30 });
31 }
32
33 /**
34 * Returns a [MemberSet] that contains the possible targets of a
35 * selector named [member] on a receiver whose type is [type].
36 */
37 MemberSet _memberSetFor(Type type, SourceString member) {
38 ClassElement cls = type.element;
39 MemberSet result = new MemberSet(member);
40 Element element = cls.lookupMember(member);
41 if (element !== null) result.add(element);
42
43 Set<ClassElement> subtypes = subtypes[cls];
44 if (subtypes !== null) {
45 for (ClassElement sub in subtypes) {
46 element = sub.lookupLocalMember(member);
47 if (element !== null) result.add(element);
48 }
49 }
50 return result;
51 }
52
53 bool isOnlyFields(Type type, SourceString member) {
54 MemberSet memberSet = _memberSetFor(type, member);
55 return !memberSet.isEmpty() && memberSet.hasJustFields();
56 }
57 }
58
59 /**
60 * A [MemberSet] contains all the possible targets for a selector.
61 */
62 class MemberSet {
63 final Set<Element> elements;
64 final SourceString name;
65
66 MemberSet(SourceString this.name) : elements = new Set<Element>();
67
68 void add(Element element) {
69 elements.add(element);
70 }
71
72 bool isEmpty() => elements.isEmpty();
73
74 bool hasJustFields() {
75 return elements.every((Element element) => element.isField());
76 }
77 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/universe.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698