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

Side by Side Diff: pkg/compiler/lib/src/resolution/member_impl.dart

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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
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 part of dart2js.resolution.compute_members; 5 part of dart2js.resolution.compute_members;
6 6
7 class DeclaredMember implements Member { 7 class DeclaredMember implements Member {
8 final Name name; 8 final Name name;
9 final Element element; 9 final Element element;
10 final InterfaceType declarer; 10 final ResolutionInterfaceType declarer;
11 final DartType type; 11 final ResolutionDartType type;
12 final FunctionType functionType; 12 final ResolutionFunctionType functionType;
13 13
14 DeclaredMember( 14 DeclaredMember(
15 this.name, this.element, this.declarer, this.type, this.functionType); 15 this.name, this.element, this.declarer, this.type, this.functionType);
16 16
17 bool get isStatic => !element.isInstanceMember; 17 bool get isStatic => !element.isInstanceMember;
18 18
19 bool get isGetter => element.isGetter || (!isSetter && element.isField); 19 bool get isGetter => element.isGetter || (!isSetter && element.isField);
20 20
21 bool get isSetter => name.isSetter; 21 bool get isSetter => name.isSetter;
22 22
23 bool get isMethod => element.isFunction; 23 bool get isMethod => element.isFunction;
24 24
25 bool get isDeclaredByField => element.isField; 25 bool get isDeclaredByField => element.isField;
26 26
27 bool get isAbstract => false; 27 bool get isAbstract => false;
28 28
29 Member get implementation => this; 29 Member get implementation => this;
30 30
31 /// Returns this member as inherited from [instance]. 31 /// Returns this member as inherited from [instance].
32 /// 32 ///
33 /// For instance: 33 /// For instance:
34 /// class A<T> { T m() {} } 34 /// class A<T> { T m() {} }
35 /// class B<S> extends A<S> {} 35 /// class B<S> extends A<S> {}
36 /// class C<U> extends B<U> {} 36 /// class C<U> extends B<U> {}
37 /// The member `T m()` is declared in `A<T>` and inherited from `A<S>` into 37 /// The member `T m()` is declared in `A<T>` and inherited from `A<S>` into
38 /// `B` as `S m()`, and further from `B<U>` into `C` as `U m()`. 38 /// `B` as `S m()`, and further from `B<U>` into `C` as `U m()`.
39 DeclaredMember inheritFrom(InterfaceType instance) { 39 DeclaredMember inheritFrom(ResolutionInterfaceType instance) {
40 // If the member is declared in a non-generic class its type cannot change 40 // If the member is declared in a non-generic class its type cannot change
41 // as a result of inheritance. 41 // as a result of inheritance.
42 if (!declarer.isGeneric) return this; 42 if (!declarer.isGeneric) return this;
43 assert(declarer.element == instance.element); 43 assert(declarer.element == instance.element);
44 return _newInheritedMember(instance); 44 return _newInheritedMember(instance);
45 } 45 }
46 46
47 InheritedMember _newInheritedMember(InterfaceType instance) { 47 InheritedMember _newInheritedMember(ResolutionInterfaceType instance) {
48 return new InheritedMember(this, instance); 48 return new InheritedMember(this, instance);
49 } 49 }
50 50
51 Iterable<Member> get declarations => <Member>[this]; 51 Iterable<Member> get declarations => <Member>[this];
52 52
53 int get hashCode => element.hashCode + 13 * isSetter.hashCode; 53 int get hashCode => element.hashCode + 13 * isSetter.hashCode;
54 54
55 bool operator ==(other) { 55 bool operator ==(other) {
56 if (other is! Member) return false; 56 if (other is! Member) return false;
57 return element == other.element && isSetter == other.isSetter; 57 return element == other.element && isSetter == other.isSetter;
58 } 58 }
59 59
60 String toString() { 60 String toString() {
61 StringBuffer sb = new StringBuffer(); 61 StringBuffer sb = new StringBuffer();
62 printOn(sb, type); 62 printOn(sb, type);
63 return sb.toString(); 63 return sb.toString();
64 } 64 }
65 65
66 void printOn(StringBuffer sb, DartType type) { 66 void printOn(StringBuffer sb, ResolutionDartType type) {
67 if (isStatic) { 67 if (isStatic) {
68 sb.write('static '); 68 sb.write('static ');
69 } 69 }
70 if (isAbstract) { 70 if (isAbstract) {
71 sb.write('abstract '); 71 sb.write('abstract ');
72 } 72 }
73 if (isGetter) { 73 if (isGetter) {
74 sb.write(type); 74 sb.write(type);
75 sb.write(' get '); 75 sb.write(' get ');
76 sb.write(name); 76 sb.write(name);
77 } else if (isSetter) { 77 } else if (isSetter) {
78 sb.write('void set '); 78 sb.write('void set ');
79 sb.write(name.getter); 79 sb.write(name.getter);
80 sb.write('('); 80 sb.write('(');
81 sb.write(type); 81 sb.write(type);
82 sb.write(' _)'); 82 sb.write(' _)');
83 } else { 83 } else {
84 sb.write(type.getStringAsDeclared('$name')); 84 sb.write(type.getStringAsDeclared('$name'));
85 } 85 }
86 } 86 }
87 } 87 }
88 88
89 class DeclaredAbstractMember extends DeclaredMember { 89 class DeclaredAbstractMember extends DeclaredMember {
90 final DeclaredMember implementation; 90 final DeclaredMember implementation;
91 91
92 DeclaredAbstractMember(Name name, Element element, InterfaceType declarer, 92 DeclaredAbstractMember(
93 DartType type, FunctionType functionType, this.implementation) 93 Name name,
94 Element element,
95 ResolutionInterfaceType declarer,
96 ResolutionDartType type,
97 ResolutionFunctionType functionType,
98 this.implementation)
94 : super(name, element, declarer, type, functionType); 99 : super(name, element, declarer, type, functionType);
95 100
96 bool get isAbstract => true; 101 bool get isAbstract => true;
97 102
98 InheritedMember _newInheritedMember(InterfaceType instance) { 103 InheritedMember _newInheritedMember(ResolutionInterfaceType instance) {
99 return new InheritedAbstractMember(this, instance, 104 return new InheritedAbstractMember(this, instance,
100 implementation != null ? implementation.inheritFrom(instance) : null); 105 implementation != null ? implementation.inheritFrom(instance) : null);
101 } 106 }
102 } 107 }
103 108
104 class InheritedMember implements DeclaredMember { 109 class InheritedMember implements DeclaredMember {
105 final DeclaredMember declaration; 110 final DeclaredMember declaration;
106 final InterfaceType instance; 111 final ResolutionInterfaceType instance;
107 112
108 InheritedMember( 113 InheritedMember(
109 DeclaredMember this.declaration, InterfaceType this.instance) { 114 DeclaredMember this.declaration, ResolutionInterfaceType this.instance) {
110 assert(instance.isGeneric); 115 assert(instance.isGeneric);
111 assert(!declaration.isStatic); 116 assert(!declaration.isStatic);
112 } 117 }
113 118
114 Element get element => declaration.element; 119 Element get element => declaration.element;
115 120
116 Name get name => declaration.name; 121 Name get name => declaration.name;
117 122
118 InterfaceType get declarer => instance; 123 ResolutionInterfaceType get declarer => instance;
119 124
120 bool get isStatic => false; 125 bool get isStatic => false;
121 126
122 bool get isSetter => declaration.isSetter; 127 bool get isSetter => declaration.isSetter;
123 128
124 bool get isGetter => declaration.isGetter; 129 bool get isGetter => declaration.isGetter;
125 130
126 bool get isMethod => declaration.isMethod; 131 bool get isMethod => declaration.isMethod;
127 132
128 bool get isDeclaredByField => declaration.isDeclaredByField; 133 bool get isDeclaredByField => declaration.isDeclaredByField;
129 134
130 bool get isAbstract => false; 135 bool get isAbstract => false;
131 136
132 Member get implementation => this; 137 Member get implementation => this;
133 138
134 DartType get type => declaration.type.substByContext(instance); 139 ResolutionDartType get type => declaration.type.substByContext(instance);
135 140
136 FunctionType get functionType { 141 ResolutionFunctionType get functionType {
137 return declaration.functionType.substByContext(instance); 142 return declaration.functionType.substByContext(instance);
138 } 143 }
139 144
140 DeclaredMember inheritFrom(InterfaceType newInstance) { 145 DeclaredMember inheritFrom(ResolutionInterfaceType newInstance) {
141 assert(invariant(declaration.element, () { 146 assert(invariant(declaration.element, () {
142 // Assert that if [instance] contains type variables, then these are 147 // Assert that if [instance] contains type variables, then these are
143 // defined in the declaration of [newInstance] and will therefore be 148 // defined in the declaration of [newInstance] and will therefore be
144 // substituted into the context of [newInstance] in the created member. 149 // substituted into the context of [newInstance] in the created member.
145 ClassElement contextClass = Types.getClassContext(instance); 150 ClassElement contextClass = Types.getClassContext(instance);
146 return contextClass == null || contextClass == newInstance.element; 151 return contextClass == null || contextClass == newInstance.element;
147 }, message: () { 152 }, message: () {
148 return "Context mismatch: Context class " 153 return "Context mismatch: Context class "
149 "${Types.getClassContext(instance)} from $instance does match " 154 "${Types.getClassContext(instance)} from $instance does match "
150 "the new instance $newInstance."; 155 "the new instance $newInstance.";
151 })); 156 }));
152 return _newInheritedMember(newInstance); 157 return _newInheritedMember(newInstance);
153 } 158 }
154 159
155 InheritedMember _newInheritedMember(InterfaceType newInstance) { 160 InheritedMember _newInheritedMember(ResolutionInterfaceType newInstance) {
156 return new InheritedMember( 161 return new InheritedMember(
157 declaration, instance.substByContext(newInstance)); 162 declaration, instance.substByContext(newInstance));
158 } 163 }
159 164
160 Iterable<Member> get declarations => <Member>[this]; 165 Iterable<Member> get declarations => <Member>[this];
161 166
162 int get hashCode => declaration.hashCode + 17 * instance.hashCode; 167 int get hashCode => declaration.hashCode + 17 * instance.hashCode;
163 168
164 bool operator ==(other) { 169 bool operator ==(other) {
165 if (other is! InheritedMember) return false; 170 if (other is! InheritedMember) return false;
166 return declaration == other.declaration && instance == other.instance; 171 return declaration == other.declaration && instance == other.instance;
167 } 172 }
168 173
169 void printOn(StringBuffer sb, DartType type) { 174 void printOn(StringBuffer sb, ResolutionDartType type) {
170 declaration.printOn(sb, type); 175 declaration.printOn(sb, type);
171 sb.write(' inherited from $instance'); 176 sb.write(' inherited from $instance');
172 } 177 }
173 178
174 String toString() { 179 String toString() {
175 StringBuffer sb = new StringBuffer(); 180 StringBuffer sb = new StringBuffer();
176 printOn(sb, type); 181 printOn(sb, type);
177 return sb.toString(); 182 return sb.toString();
178 } 183 }
179 } 184 }
180 185
181 class InheritedAbstractMember extends InheritedMember { 186 class InheritedAbstractMember extends InheritedMember {
182 final DeclaredMember implementation; 187 final DeclaredMember implementation;
183 188
184 InheritedAbstractMember( 189 InheritedAbstractMember(DeclaredMember declaration,
185 DeclaredMember declaration, InterfaceType instance, this.implementation) 190 ResolutionInterfaceType instance, this.implementation)
186 : super(declaration, instance); 191 : super(declaration, instance);
187 192
188 bool get isAbstract => true; 193 bool get isAbstract => true;
189 194
190 InheritedMember _newInheritedMember(InterfaceType newInstance) { 195 InheritedMember _newInheritedMember(ResolutionInterfaceType newInstance) {
191 return new InheritedAbstractMember( 196 return new InheritedAbstractMember(
192 declaration, 197 declaration,
193 instance.substByContext(newInstance), 198 instance.substByContext(newInstance),
194 implementation != null 199 implementation != null
195 ? implementation.inheritFrom(newInstance) 200 ? implementation.inheritFrom(newInstance)
196 : null); 201 : null);
197 } 202 }
198 } 203 }
199 204
200 abstract class AbstractSyntheticMember implements MemberSignature { 205 abstract class AbstractSyntheticMember implements MemberSignature {
201 final Setlet<Member> inheritedMembers; 206 final Setlet<Member> inheritedMembers;
202 207
203 AbstractSyntheticMember(this.inheritedMembers); 208 AbstractSyntheticMember(this.inheritedMembers);
204 209
205 Member get member => inheritedMembers.first; 210 Member get member => inheritedMembers.first;
206 211
207 Iterable<Member> get declarations => inheritedMembers; 212 Iterable<Member> get declarations => inheritedMembers;
208 213
209 Name get name => member.name; 214 Name get name => member.name;
210 } 215 }
211 216
212 class SyntheticMember extends AbstractSyntheticMember { 217 class SyntheticMember extends AbstractSyntheticMember {
213 final DartType type; 218 final ResolutionDartType type;
214 final FunctionType functionType; 219 final ResolutionFunctionType functionType;
215 220
216 SyntheticMember(Setlet<Member> inheritedMembers, this.type, this.functionType) 221 SyntheticMember(Setlet<Member> inheritedMembers, this.type, this.functionType)
217 : super(inheritedMembers); 222 : super(inheritedMembers);
218 223
219 bool get isSetter => member.isSetter; 224 bool get isSetter => member.isSetter;
220 225
221 bool get isGetter => member.isGetter; 226 bool get isGetter => member.isGetter;
222 227
223 bool get isMethod => member.isMethod; 228 bool get isMethod => member.isMethod;
224 229
225 bool get isMalformed => false; 230 bool get isMalformed => false;
226 231
227 String toString() => '${type.getStringAsDeclared('$name')} synthesized ' 232 String toString() => '${type.getStringAsDeclared('$name')} synthesized '
228 'from ${inheritedMembers}'; 233 'from ${inheritedMembers}';
229 } 234 }
230 235
231 class ErroneousMember extends AbstractSyntheticMember { 236 class ErroneousMember extends AbstractSyntheticMember {
232 ErroneousMember(Setlet<Member> inheritedMembers) : super(inheritedMembers); 237 ErroneousMember(Setlet<Member> inheritedMembers) : super(inheritedMembers);
233 238
234 DartType get type => functionType; 239 ResolutionDartType get type => functionType;
235 240
236 FunctionType get functionType { 241 ResolutionFunctionType get functionType {
237 throw new UnsupportedError('Erroneous members have no type.'); 242 throw new UnsupportedError('Erroneous members have no type.');
238 } 243 }
239 244
240 bool get isSetter => false; 245 bool get isSetter => false;
241 246
242 bool get isGetter => false; 247 bool get isGetter => false;
243 248
244 bool get isMethod => false; 249 bool get isMethod => false;
245 250
246 bool get isMalformed => true; 251 bool get isMalformed => true;
247 252
248 String toString() => "erroneous member '$name' synthesized " 253 String toString() => "erroneous member '$name' synthesized "
249 "from ${inheritedMembers}"; 254 "from ${inheritedMembers}";
250 } 255 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/enum_creator.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698