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

Side by Side Diff: frog/type.dart

Issue 8679014: Remove duplicate resolveMember, fix type substitution for subtype of generic class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « frog/frogsh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
None
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 Type implements Named, Hashable { 5 class Type implements Named, Hashable {
6 final String name; 6 final String name;
7 bool isTested; 7 bool isTested;
8 8
9 /** 9 /**
10 * For core types (int, String, etc) this is the generated type assertion 10 * For core types (int, String, etc) this is the generated type assertion
11 * function (uses JS "typeof"). This field is null for all other types. 11 * function (uses JS "typeof"). This field is null for all other types.
12 */ 12 */
13 String typeCheckCode; 13 String typeCheckCode;
14 14
15 String _jsname; 15 String _jsname;
16 16
17 Member _typeMember; 17 Member _typeMember;
18 18
19 /** Stubs used to call into this method dynamically. Lazy initialized. */ 19 /** Stubs used to call into this method dynamically. Lazy initialized. */
20 Map<String, VarMember> varStubs; 20 Map<String, VarMember> varStubs;
21 21
22 Type(this.name): isTested = false; 22 /** Cache of [MemberSet]s that have been resolved. */
23 Map<String, MemberSet> _resolvedMembers;
24
25 Type(this.name): isTested = false, _resolvedMembers = {};
23 26
24 void markUsed() {} 27 void markUsed() {}
25 abstract void genMethod(Member method); 28 abstract void genMethod(Member method);
26 29
27 TypeMember get typeMember() { 30 TypeMember get typeMember() {
28 if (_typeMember == null) { 31 if (_typeMember == null) {
29 _typeMember = new TypeMember(this); 32 _typeMember = new TypeMember(this);
30 } 33 }
31 return _typeMember; 34 return _typeMember;
32 } 35 }
33 36
34 abstract SourceSpan get span(); 37 abstract SourceSpan get span();
35 38
36 abstract Type resolveType(TypeReference node, bool isRequired); 39 abstract Type resolveType(TypeReference node, bool isRequired);
37 40
38 abstract Type resolveTypeParams(ConcreteType inType); 41 abstract Type resolveTypeParams(ConcreteType inType);
39 42
40 abstract MemberSet resolveMember(String name);
41 Member getMember(String name) => null; 43 Member getMember(String name) => null;
42 abstract MethodMember getConstructor(String name); 44 abstract MethodMember getConstructor(String name);
43 abstract MethodMember getFactory(Type type, String name); 45 abstract MethodMember getFactory(Type type, String name);
44 abstract Type getOrMakeConcreteType(List<Type> typeArgs); 46 abstract Type getOrMakeConcreteType(List<Type> typeArgs);
45 abstract Map<String, MethodMember> get constructors(); 47 abstract Map<String, MethodMember> get constructors();
46 abstract addDirectSubtype(Type type); 48 abstract addDirectSubtype(Type type);
47 abstract bool get isClass(); 49 abstract bool get isClass();
48 abstract Library get library(); 50 abstract Library get library();
51 Set<Type> get subtypes() => null;
49 52
50 // TODO(jmesserly): rename to isDynamic? 53 // TODO(jmesserly): rename to isDynamic?
51 bool get isVar() => false; 54 bool get isVar() => false;
52 bool get isTop() => false; 55 bool get isTop() => false;
53 56
54 bool get isObject() => false; 57 bool get isObject() => false;
55 bool get isString() => false; 58 bool get isString() => false;
56 bool get isBool() => false; 59 bool get isBool() => false;
57 bool get isFunction() => false; 60 bool get isFunction() => false;
58 bool get isList() => false; 61 bool get isList() => false;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return ret; 163 return ret;
161 } 164 }
162 } 165 }
163 return null; 166 return null;
164 } else { 167 } else {
165 return world.objectType.getMember(memberName); 168 return world.objectType.getMember(memberName);
166 } 169 }
167 } 170 }
168 } 171 }
169 172
173 MemberSet resolveMember(String memberName) {
174 MemberSet ret = _resolvedMembers[memberName];
175 if (ret != null) return ret;
176
177 Member member = getMember(memberName);
178 if (member == null) {
179 // TODO(jimhug): Check for members on subtypes given dart's dynamism.
180 return null;
181 }
182
183 // TODO(jimhug): Move this adding subtypes logic to MemberSet?
184 ret = new MemberSet(member);
185 _resolvedMembers[memberName] = ret;
186 if (member.isStatic) {
187 return ret;
188 } else {
189 for (var t in subtypes) {
190 if (!isClass && t.isClass) {
191 // If this is an interface, the actual implementation may
192 // come from a class that does not implement this interface.
193 // TODO(vsm): Use a more efficient lookup strategy.
194 // TODO(jimhug): This is made uglier by need to avoid dups.
195 final m = t.getMember(memberName);
196 if (m != null && ret.members.indexOf(m) == -1) {
197 ret.add(m);
198 }
199 } else {
200 final m = t.members[memberName];
201 if (m != null) ret.add(m);
202 }
203 }
204 return ret;
205 }
206 }
207
170 void ensureSubtypeOf(Type other, SourceSpan span, [bool typeErrors=false]) { 208 void ensureSubtypeOf(Type other, SourceSpan span, [bool typeErrors=false]) {
171 if (!isSubtypeOf(other)) { 209 if (!isSubtypeOf(other)) {
172 var msg = 'type $name is not a subtype of ${other.name}'; 210 var msg = 'type $name is not a subtype of ${other.name}';
173 if (typeErrors) { 211 if (typeErrors) {
174 world.error(msg, span); 212 world.error(msg, span);
175 } else { 213 } else {
176 world.warning(msg, span); 214 world.warning(msg, span);
177 } 215 }
178 } 216 }
179 } 217 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 FactoryMap get factories() => type.factories; 513 FactoryMap get factories() => type.factories;
476 Collection<Type> get typeArgsInOrder() => type.typeArgsInOrder; 514 Collection<Type> get typeArgsInOrder() => type.typeArgsInOrder;
477 DefinedType get genericType() => type.genericType; 515 DefinedType get genericType() => type.genericType;
478 List<Type> get interfaces() => type.interfaces; 516 List<Type> get interfaces() => type.interfaces;
479 Type get parent() => type.parent; 517 Type get parent() => type.parent;
480 Map<String, Member> getAllMembers() => type.getAllMembers(); 518 Map<String, Member> getAllMembers() => type.getAllMembers();
481 bool get isNativeType() => type.isNativeType; 519 bool get isNativeType() => type.isNativeType;
482 } 520 }
483 521
484 /** A concrete version of a generic type. */ 522 /** A concrete version of a generic type. */

error: old chunk mismatch

OLDNEW
« no previous file with comments | « frog/frogsh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698