OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.kernel_class_builder; | 5 library fasta.kernel_class_builder; |
6 | 6 |
7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
8 show KernelMember; | 8 show KernelMember; |
9 | 9 |
10 import 'package:kernel/ast.dart' | 10 import 'package:kernel/ast.dart' |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return new DillMemberBuilder(field, this); | 175 return new DillMemberBuilder(field, this); |
176 }); | 176 }); |
177 Field field = constructorsField.target; | 177 Field field = constructorsField.target; |
178 ListLiteral literal = field.initializer; | 178 ListLiteral literal = field.initializer; |
179 literal.expressions | 179 literal.expressions |
180 .add(new StaticGet(constructor.target)..parent = literal); | 180 .add(new StaticGet(constructor.target)..parent = literal); |
181 } | 181 } |
182 | 182 |
183 void checkOverrides(ClassHierarchy hierarchy) { | 183 void checkOverrides(ClassHierarchy hierarchy) { |
184 hierarchy.forEachOverridePair(cls, checkOverride); | 184 hierarchy.forEachOverridePair(cls, checkOverride); |
| 185 hierarchy.forEachCrossOverridePair(cls, handleCrossOverride); |
185 } | 186 } |
186 | 187 |
187 void checkOverride( | 188 void checkOverride( |
188 Member declaredMember, Member interfaceMember, bool isSetter) { | 189 Member declaredMember, Member interfaceMember, bool isSetter) { |
189 if (declaredMember is Constructor || interfaceMember is Constructor) { | 190 if (declaredMember is Constructor || interfaceMember is Constructor) { |
190 internalError( | 191 internalError( |
191 "Constructor in override check.", fileUri, declaredMember.fileOffset); | 192 "Constructor in override check.", fileUri, declaredMember.fileOffset); |
192 } | 193 } |
193 if (declaredMember is Procedure && interfaceMember is Procedure) { | 194 if (declaredMember is Procedure && interfaceMember is Procedure) { |
194 if (declaredMember.kind == ProcedureKind.Method && | 195 if (declaredMember.kind == ProcedureKind.Method && |
195 interfaceMember.kind == ProcedureKind.Method) { | 196 interfaceMember.kind == ProcedureKind.Method) { |
196 checkMethodOverride(declaredMember, interfaceMember); | 197 checkMethodOverride(declaredMember, interfaceMember); |
197 return; | 198 return; |
198 } | 199 } |
199 } | 200 } |
200 // TODO(ahe): Handle other cases: accessors, operators, and fields. | 201 // TODO(ahe): Handle other cases: accessors, operators, and fields. |
201 | 202 |
202 // Also record any cases where a field or getter/setter overrides something | 203 // Also record any cases where a field or getter/setter overrides something |
203 // in a superclass, since this information will be needed for type | 204 // in a superclass, since this information will be needed for type |
204 // inference. | 205 // inference. |
205 if (declaredMember is KernelMember && | 206 if (declaredMember is KernelMember && |
206 identical(declaredMember.enclosingClass, cls)) { | 207 identical(declaredMember.enclosingClass, cls)) { |
207 KernelMember.recordOverride(declaredMember, interfaceMember); | 208 KernelMember.recordOverride(declaredMember, interfaceMember); |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
| 212 void handleCrossOverride( |
| 213 Member declaredMember, Member interfaceMember, bool isSetter) { |
| 214 // Record any cases where a field or getter/setter has a corresponding (but |
| 215 // opposite) getter/setter in a superclass, since this information will be |
| 216 // needed for type inference. |
| 217 if (declaredMember is KernelMember && |
| 218 identical(declaredMember.enclosingClass, cls)) { |
| 219 KernelMember.recordCrossOverride(declaredMember, interfaceMember); |
| 220 } |
| 221 } |
| 222 |
211 void checkMethodOverride( | 223 void checkMethodOverride( |
212 Procedure declaredMember, Procedure interfaceMember) { | 224 Procedure declaredMember, Procedure interfaceMember) { |
213 if (declaredMember.enclosingClass != cls) { | 225 if (declaredMember.enclosingClass != cls) { |
214 // TODO(ahe): Include these checks as well, but the message needs to | 226 // TODO(ahe): Include these checks as well, but the message needs to |
215 // explain that [declaredMember] is inherited. | 227 // explain that [declaredMember] is inherited. |
216 return; | 228 return; |
217 } | 229 } |
218 assert(declaredMember.kind == ProcedureKind.Method); | 230 assert(declaredMember.kind == ProcedureKind.Method); |
219 assert(interfaceMember.kind == ProcedureKind.Method); | 231 assert(interfaceMember.kind == ProcedureKind.Method); |
220 FunctionNode declaredFunction = declaredMember.function; | 232 FunctionNode declaredFunction = declaredMember.function; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 294 } |
283 } | 295 } |
284 } | 296 } |
285 | 297 |
286 String get fullNameForErrors { | 298 String get fullNameForErrors { |
287 return isMixinApplication | 299 return isMixinApplication |
288 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" | 300 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" |
289 : name; | 301 : name; |
290 } | 302 } |
291 } | 303 } |
OLD | NEW |