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

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

Issue 10511008: Support overriding fields with fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 6 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
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 final Map<ClassElement, Set<ClassElement>> subtypes; 6 final Map<ClassElement, Set<ClassElement>> subtypes;
7 7
8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>(); 8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>();
9 9
10 void populate(Compiler compiler, Collection<LibraryElement> libraries) { 10 void populate(Compiler compiler, Collection<LibraryElement> libraries) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 Set<ClassElement> subtypesOfCls = subtypes[cls]; 43 Set<ClassElement> subtypesOfCls = subtypes[cls];
44 if (subtypesOfCls !== null) { 44 if (subtypesOfCls !== null) {
45 for (ClassElement sub in subtypesOfCls) { 45 for (ClassElement sub in subtypesOfCls) {
46 element = sub.lookupLocalMember(member); 46 element = sub.lookupLocalMember(member);
47 if (element !== null) result.add(element); 47 if (element !== null) result.add(element);
48 } 48 }
49 } 49 }
50 return result; 50 return result;
51 } 51 }
52 52
53 bool isOnlyFields(Type type, SourceString member) { 53 /**
54 * Returns the single field with the given name, if such a field
55 * exists. If there are multple fields, or none, return null.
56 */
57 VariableElement locateSingleField(Type type, SourceString member) {
54 MemberSet memberSet = _memberSetFor(type, member); 58 MemberSet memberSet = _memberSetFor(type, member);
55 return !memberSet.isEmpty() && memberSet.hasJustFields(); 59 int fieldCount = 0;
60 int nonFieldCount = 0;
61 VariableElement field;
62 memberSet.elements.forEach((Element element) {
63 if (element.isField()) {
64 field = element;
65 fieldCount++;
66 } else {
67 nonFieldCount++;
68 }
69 });
70 return (fieldCount == 1 && nonFieldCount == 0) ? field : null;
56 } 71 }
57 } 72 }
58 73
59 /** 74 /**
60 * A [MemberSet] contains all the possible targets for a selector. 75 * A [MemberSet] contains all the possible targets for a selector.
61 */ 76 */
62 class MemberSet { 77 class MemberSet {
63 final Set<Element> elements; 78 final Set<Element> elements;
64 final SourceString name; 79 final SourceString name;
65 80
66 MemberSet(SourceString this.name) : elements = new Set<Element>(); 81 MemberSet(SourceString this.name) : elements = new Set<Element>();
67 82
68 void add(Element element) { 83 void add(Element element) {
69 elements.add(element); 84 elements.add(element);
70 } 85 }
71 86
72 bool isEmpty() => elements.isEmpty(); 87 bool isEmpty() => elements.isEmpty();
73
74 bool hasJustFields() {
75 return elements.every((Element element) => element.isField());
76 }
77 } 88 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/ssa/optimize.dart ('k') | dart/tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698