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

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: merged Created 9 years 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return ret; 165 return ret;
163 } 166 }
164 } 167 }
165 return null; 168 return null;
166 } else { 169 } else {
167 return world.objectType.getMember(memberName); 170 return world.objectType.getMember(memberName);
168 } 171 }
169 } 172 }
170 } 173 }
171 174
175 MemberSet resolveMember(String memberName) {
176 MemberSet ret = _resolvedMembers[memberName];
177 if (ret != null) return ret;
178
179 Member member = getMember(memberName);
180 if (member == null) {
181 // TODO(jimhug): Check for members on subtypes given dart's dynamism.
182 return null;
183 }
184
185 // TODO(jimhug): Move this adding subtypes logic to MemberSet?
186 ret = new MemberSet(member);
187 _resolvedMembers[memberName] = ret;
188 if (member.isStatic) {
189 return ret;
190 } else {
191 for (var t in subtypes) {
192 if (!isClass && t.isClass) {
193 // If this is an interface, the actual implementation may
194 // come from a class that does not implement this interface.
195 // TODO(vsm): Use a more efficient lookup strategy.
196 // TODO(jimhug): This is made uglier by need to avoid dups.
197 final m = t.getMember(memberName);
198 if (m != null && ret.members.indexOf(m) == -1) {
199 ret.add(m);
200 }
201 } else {
202 final m = t.members[memberName];
203 if (m != null) ret.add(m);
204 }
205 }
206 return ret;
207 }
208 }
209
172 void ensureSubtypeOf(Type other, SourceSpan span, [bool typeErrors=false]) { 210 void ensureSubtypeOf(Type other, SourceSpan span, [bool typeErrors=false]) {
173 if (!isSubtypeOf(other)) { 211 if (!isSubtypeOf(other)) {
174 var msg = 'type $name is not a subtype of ${other.name}'; 212 var msg = 'type $name is not a subtype of ${other.name}';
175 if (typeErrors) { 213 if (typeErrors) {
176 world.error(msg, span); 214 world.error(msg, span);
177 } else { 215 } else {
178 world.warning(msg, span); 216 world.warning(msg, span);
179 } 217 }
180 } 218 }
181 } 219 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 FactoryMap get factories() => type.factories; 515 FactoryMap get factories() => type.factories;
478 Collection<Type> get typeArgsInOrder() => type.typeArgsInOrder; 516 Collection<Type> get typeArgsInOrder() => type.typeArgsInOrder;
479 DefinedType get genericType() => type.genericType; 517 DefinedType get genericType() => type.genericType;
480 List<Type> get interfaces() => type.interfaces; 518 List<Type> get interfaces() => type.interfaces;
481 Type get parent() => type.parent; 519 Type get parent() => type.parent;
482 Map<String, Member> getAllMembers() => type.getAllMembers(); 520 Map<String, Member> getAllMembers() => type.getAllMembers();
483 bool get isNativeType() => type.isNativeType; 521 bool get isNativeType() => type.isNativeType;
484 } 522 }
485 523
486 /** A concrete version of a generic type. */ 524 /** 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