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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/universe.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/world.dart
===================================================================
--- lib/compiler/implementation/world.dart (revision 0)
+++ lib/compiler/implementation/world.dart (revision 0)
@@ -0,0 +1,77 @@
+// 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>>();
+
+ void populate(Compiler compiler, Collection<LibraryElement> libraries) {
+ void addSubtypes(ClassElement cls) {
+ for (Type type in cls.allSupertypes) {
+ List<Element> subtypes = subtypes.putIfAbsent(
+ type.element,
+ () => <ClassElement>[]);
+ subtypes.add(cls);
+ }
+ }
+
+ libraries.forEach((LibraryElement library) {
+ for (Link<Element> link = library.topLevelElements;
+ !link.isEmpty();
+ link = link.tail) {
+ Element element = link.head;
+ if (!element.isClass()) continue;
+ ClassElement cls = element;
+ compiler.resolveClass(cls);
+ addSubtypes(cls);
+ }
+ });
+ }
+
+ /**
+ * 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) {
+ 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;
+ }
+
+ bool isOnlyFields(Type type, SourceString member) {
+ MemberSet memberSet = _memberSetFor(type, member);
+ return !memberSet.isEmpty() && memberSet.hasJustFields();
+ }
+}
+
+/**
+ * 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());
+ }
+}
« 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