OLD | NEW |
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 extends Element { |
6 final String name; | |
7 bool isTested; | 6 bool isTested; |
8 | 7 |
9 /** | 8 /** |
10 * For core types (int, String, etc) this is the generated type assertion | 9 * 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. | 10 * function (uses JS "typeof"). This field is null for all other types. |
12 */ | 11 */ |
13 String typeCheckCode; | 12 String typeCheckCode; |
14 | 13 |
15 String _jsname; | |
16 | |
17 Member _typeMember; | 14 Member _typeMember; |
18 | 15 |
19 /** Stubs used to call into this method dynamically. Lazy initialized. */ | 16 /** Stubs used to call into this method dynamically. Lazy initialized. */ |
20 Map<String, VarMember> varStubs; | 17 Map<String, VarMember> varStubs; |
21 | 18 |
22 /** Cache of [MemberSet]s that have been resolved. */ | 19 /** Cache of [MemberSet]s that have been resolved. */ |
23 Map<String, MemberSet> _resolvedMembers; | 20 Map<String, MemberSet> _resolvedMembers; |
24 | 21 |
25 Type(this.name): isTested = false, _resolvedMembers = {}; | 22 Type(String name): isTested = false, _resolvedMembers = {}, super(name, null); |
26 | 23 |
27 void markUsed() {} | 24 void markUsed() {} |
28 abstract void genMethod(Member method); | 25 abstract void genMethod(Member method); |
29 | 26 |
30 TypeMember get typeMember() { | 27 TypeMember get typeMember() { |
31 if (_typeMember == null) { | 28 if (_typeMember == null) { |
32 _typeMember = new TypeMember(this); | 29 _typeMember = new TypeMember(this); |
33 } | 30 } |
34 return _typeMember; | 31 return _typeMember; |
35 } | 32 } |
36 | 33 |
37 abstract SourceSpan get span(); | |
38 | |
39 abstract Type resolveType(TypeReference node, bool isRequired); | |
40 | |
41 abstract Type resolveTypeParams(ConcreteType inType); | 34 abstract Type resolveTypeParams(ConcreteType inType); |
42 | 35 |
43 Member getMember(String name) => null; | 36 Member getMember(String name) => null; |
44 abstract MethodMember getConstructor(String name); | 37 abstract MethodMember getConstructor(String name); |
45 abstract MethodMember getFactory(Type type, String name); | 38 abstract MethodMember getFactory(Type type, String name); |
46 abstract Type getOrMakeConcreteType(List<Type> typeArgs); | 39 abstract Type getOrMakeConcreteType(List<Type> typeArgs); |
47 abstract Map<String, MethodMember> get constructors(); | 40 abstract Map<String, MethodMember> get constructors(); |
48 abstract addDirectSubtype(Type type); | 41 abstract addDirectSubtype(Type type); |
49 abstract bool get isClass(); | 42 abstract bool get isClass(); |
50 abstract Library get library(); | |
51 Set<Type> get subtypes() => null; | 43 Set<Type> get subtypes() => null; |
52 | 44 |
53 // TODO(jmesserly): rename to isDynamic? | 45 // TODO(jmesserly): rename to isDynamic? |
54 bool get isVar() => false; | 46 bool get isVar() => false; |
55 bool get isTop() => false; | 47 bool get isTop() => false; |
56 | 48 |
57 bool get isObject() => false; | 49 bool get isObject() => false; |
58 bool get isString() => false; | 50 bool get isString() => false; |
59 bool get isBool() => false; | 51 bool get isBool() => false; |
60 bool get isFunction() => false; | 52 bool get isFunction() => false; |
(...skipping 14 matching lines...) Expand all Loading... |
75 | 67 |
76 /** Gets the $call method for a function type. */ | 68 /** Gets the $call method for a function type. */ |
77 MethodMember getCallMethod() => null; | 69 MethodMember getCallMethod() => null; |
78 | 70 |
79 /** These types may not be implemented or extended by user code. */ | 71 /** These types may not be implemented or extended by user code. */ |
80 bool get isClosed() => isString || isBool || isNum || isFunction || isVar; | 72 bool get isClosed() => isString || isBool || isNum || isFunction || isVar; |
81 | 73 |
82 bool get isUsed() => false; | 74 bool get isUsed() => false; |
83 | 75 |
84 bool get isGeneric() => false; | 76 bool get isGeneric() => false; |
85 bool get isNativeType() => false; | |
86 | |
87 bool get isNative() => isNativeType; // TODO(jimhug): remove isNativeType. | |
88 | 77 |
89 bool get isHiddenNativeType() => false; | 78 bool get isHiddenNativeType() => false; |
90 | 79 |
91 bool get hasTypeParams() => false; | 80 bool get hasTypeParams() => false; |
92 | 81 |
93 String get typeofName() => null; | 82 String get typeofName() => null; |
94 | 83 |
95 String get jsname() => _jsname == null ? name : _jsname; | |
96 | |
97 set jsname(String name) => _jsname = name; | |
98 | |
99 Map<String, Member> get members() => null; | 84 Map<String, Member> get members() => null; |
100 Definition get definition() => null; | 85 Definition get definition() => null; |
101 FactoryMap get factories() => null; | 86 FactoryMap get factories() => null; |
102 | 87 |
103 // TODO(jmesserly): should try using a const list instead of null to represent | 88 // TODO(jmesserly): should try using a const list instead of null to represent |
104 // the absence of type parameters. | 89 // the absence of type parameters. |
105 Collection<Type> get typeArgsInOrder() => null; | 90 Collection<Type> get typeArgsInOrder() => null; |
106 DefinedType get genericType() => this; | 91 DefinedType get genericType() => this; |
107 | 92 |
108 // TODO(jmesserly): what should these do for ParameterType? | 93 // TODO(jmesserly): what should these do for ParameterType? |
109 List<Type> get interfaces() => null; | 94 List<Type> get interfaces() => null; |
110 Type get parent() => null; | 95 Type get parent() => null; |
111 | 96 |
112 Map<String, Member> getAllMembers() => {}; | 97 Map<String, Member> getAllMembers() => {}; |
113 | 98 |
114 int hashCode() => name.hashCode(); | |
115 | |
116 bool _hasNativeSubtypes; | 99 bool _hasNativeSubtypes; |
117 bool get hasNativeSubtypes() { | 100 bool get hasNativeSubtypes() { |
118 if (_hasNativeSubtypes == null) { | 101 if (_hasNativeSubtypes == null) { |
119 _hasNativeSubtypes = subtypes.some((t) => t.isNativeType); | 102 _hasNativeSubtypes = subtypes.some((t) => t.isNative); |
120 } | 103 } |
121 return _hasNativeSubtypes; | 104 return _hasNativeSubtypes; |
122 } | 105 } |
123 | 106 |
124 void _checkOverride(Member member) { | 107 void _checkOverride(Member member) { |
125 // always look in parents to check that any overloads are legal | 108 // always look in parents to check that any overloads are legal |
126 var parentMember = _getMemberInParents(member.name); | 109 var parentMember = _getMemberInParents(member.name); |
127 if (parentMember != null) { | 110 if (parentMember != null) { |
128 // TODO(jimhug): Ensure that this is only done once. | 111 // TODO(jimhug): Ensure that this is only done once. |
129 if (!member.isPrivate || member.library == parentMember.library) { | 112 if (!member.isPrivate || member.library == parentMember.library) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 world.internalError('no constructors on type parameters yet'); | 430 world.internalError('no constructors on type parameters yet'); |
448 } | 431 } |
449 | 432 |
450 Type getOrMakeConcreteType(List<Type> typeArgs) { | 433 Type getOrMakeConcreteType(List<Type> typeArgs) { |
451 world.internalError('no concrete types of type parameters yet', span); | 434 world.internalError('no concrete types of type parameters yet', span); |
452 } | 435 } |
453 | 436 |
454 Type resolveTypeParams(ConcreteType inType) { | 437 Type resolveTypeParams(ConcreteType inType) { |
455 return inType.typeArguments[name]; | 438 return inType.typeArguments[name]; |
456 } | 439 } |
error: old chunk mismatch |
None
OLD | NEW |