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

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

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

Powered by Google App Engine
This is Rietveld 408576698