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' |
11 show | 11 show |
12 Class, | 12 Class, |
13 Constructor, | 13 Constructor, |
14 DartType, | 14 DartType, |
15 Expression, | 15 Expression, |
16 Field, | 16 Field, |
17 FunctionNode, | 17 FunctionNode, |
18 InterfaceType, | 18 InterfaceType, |
19 ListLiteral, | 19 ListLiteral, |
20 Member, | 20 Member, |
21 Name, | 21 Name, |
22 Procedure, | 22 Procedure, |
23 ProcedureKind, | 23 ProcedureKind, |
24 StaticGet, | 24 StaticGet, |
25 Supertype, | 25 Supertype, |
26 VariableDeclaration; | 26 VariableDeclaration; |
27 | 27 |
28 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 28 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
29 | 29 |
30 import '../errors.dart' show internalError; | 30 import '../deprecated_problems.dart' show deprecated_internalProblem; |
31 | 31 |
32 import '../dill/dill_member_builder.dart' show DillMemberBuilder; | 32 import '../dill/dill_member_builder.dart' show DillMemberBuilder; |
33 | 33 |
34 import 'kernel_builder.dart' | 34 import 'kernel_builder.dart' |
35 show | 35 show |
36 Builder, | 36 Builder, |
37 ClassBuilder, | 37 ClassBuilder, |
38 ConstructorReferenceBuilder, | 38 ConstructorReferenceBuilder, |
39 KernelLibraryBuilder, | 39 KernelLibraryBuilder, |
40 KernelProcedureBuilder, | 40 KernelProcedureBuilder, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 assert(arguments == null || cls.typeParameters.length == arguments.length); | 75 assert(arguments == null || cls.typeParameters.length == arguments.length); |
76 return arguments == null ? cls.rawType : new InterfaceType(cls, arguments); | 76 return arguments == null ? cls.rawType : new InterfaceType(cls, arguments); |
77 } | 77 } |
78 | 78 |
79 List<DartType> buildTypeArguments( | 79 List<DartType> buildTypeArguments( |
80 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 80 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
81 List<DartType> typeArguments = <DartType>[]; | 81 List<DartType> typeArguments = <DartType>[]; |
82 for (KernelTypeBuilder builder in arguments) { | 82 for (KernelTypeBuilder builder in arguments) { |
83 DartType type = builder.build(library); | 83 DartType type = builder.build(library); |
84 if (type == null) { | 84 if (type == null) { |
85 internalError("Bad type: ${builder.runtimeType}"); | 85 deprecated_internalProblem("Bad type: ${builder.runtimeType}"); |
86 } | 86 } |
87 typeArguments.add(type); | 87 typeArguments.add(type); |
88 } | 88 } |
89 return computeDefaultTypeArguments( | 89 return computeDefaultTypeArguments( |
90 library, cls.typeParameters, typeArguments); | 90 library, cls.typeParameters, typeArguments); |
91 } | 91 } |
92 | 92 |
93 InterfaceType buildType( | 93 InterfaceType buildType( |
94 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 94 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
95 List<DartType> typeArguments; | 95 List<DartType> typeArguments; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 addRedirectingConstructor(builder, library); | 127 addRedirectingConstructor(builder, library); |
128 if (targetBuilder is ProcedureBuilder) { | 128 if (targetBuilder is ProcedureBuilder) { |
129 Member target = targetBuilder.target; | 129 Member target = targetBuilder.target; |
130 builder.body = new RedirectingFactoryBody(target); | 130 builder.body = new RedirectingFactoryBody(target); |
131 } else if (targetBuilder is DillMemberBuilder) { | 131 } else if (targetBuilder is DillMemberBuilder) { |
132 builder.body = new RedirectingFactoryBody(targetBuilder.member); | 132 builder.body = new RedirectingFactoryBody(targetBuilder.member); |
133 } else { | 133 } else { |
134 String message = "Redirection constructor target not found: " | 134 String message = "Redirection constructor target not found: " |
135 "${redirectionTarget.fullNameForErrors}"; | 135 "${redirectionTarget.fullNameForErrors}"; |
136 if (builder.isConst) { | 136 if (builder.isConst) { |
137 addCompileTimeError(builder.charOffset, message); | 137 deprecated_addCompileTimeError(builder.charOffset, message); |
138 } else { | 138 } else { |
139 addWarning(builder.charOffset, message); | 139 deprecated_addWarning(builder.charOffset, message); |
140 } | 140 } |
141 // CoreTypes aren't computed yet, and this is the outline | 141 // CoreTypes aren't computed yet, and this is the outline |
142 // phase. So we can't and shouldn't create a method body. | 142 // phase. So we can't and shouldn't create a method body. |
143 builder.body = new RedirectingFactoryBody.unresolved( | 143 builder.body = new RedirectingFactoryBody.unresolved( |
144 redirectionTarget.fullNameForErrors); | 144 redirectionTarget.fullNameForErrors); |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 hierarchy.forEachCrossOverridePair(cls, handleCrossOverride); |
186 } | 186 } |
187 | 187 |
188 void checkOverride( | 188 void checkOverride( |
189 Member declaredMember, Member interfaceMember, bool isSetter) { | 189 Member declaredMember, Member interfaceMember, bool isSetter) { |
190 if (declaredMember is Constructor || interfaceMember is Constructor) { | 190 if (declaredMember is Constructor || interfaceMember is Constructor) { |
191 internalError( | 191 deprecated_internalProblem( |
192 "Constructor in override check.", fileUri, declaredMember.fileOffset); | 192 "Constructor in override check.", fileUri, declaredMember.fileOffset); |
193 } | 193 } |
194 if (declaredMember is Procedure && interfaceMember is Procedure) { | 194 if (declaredMember is Procedure && interfaceMember is Procedure) { |
195 if (declaredMember.kind == ProcedureKind.Method && | 195 if (declaredMember.kind == ProcedureKind.Method && |
196 interfaceMember.kind == ProcedureKind.Method) { | 196 interfaceMember.kind == ProcedureKind.Method) { |
197 checkMethodOverride(declaredMember, interfaceMember); | 197 checkMethodOverride(declaredMember, interfaceMember); |
198 } | 198 } |
199 } | 199 } |
200 // TODO(ahe): Handle other cases: accessors, operators, and fields. | 200 // TODO(ahe): Handle other cases: accessors, operators, and fields. |
201 | 201 |
(...skipping 23 matching lines...) Expand all Loading... |
225 // TODO(ahe): Include these checks as well, but the message needs to | 225 // TODO(ahe): Include these checks as well, but the message needs to |
226 // explain that [declaredMember] is inherited. | 226 // explain that [declaredMember] is inherited. |
227 return; | 227 return; |
228 } | 228 } |
229 assert(declaredMember.kind == ProcedureKind.Method); | 229 assert(declaredMember.kind == ProcedureKind.Method); |
230 assert(interfaceMember.kind == ProcedureKind.Method); | 230 assert(interfaceMember.kind == ProcedureKind.Method); |
231 FunctionNode declaredFunction = declaredMember.function; | 231 FunctionNode declaredFunction = declaredMember.function; |
232 FunctionNode interfaceFunction = interfaceMember.function; | 232 FunctionNode interfaceFunction = interfaceMember.function; |
233 if (declaredFunction.typeParameters?.length != | 233 if (declaredFunction.typeParameters?.length != |
234 interfaceFunction.typeParameters?.length) { | 234 interfaceFunction.typeParameters?.length) { |
235 addWarning( | 235 deprecated_addWarning( |
236 declaredMember.fileOffset, | 236 declaredMember.fileOffset, |
237 "Declared type variables of '$name::${declaredMember.name.name}' " | 237 "Declared type variables of '$name::${declaredMember.name.name}' " |
238 "doesn't match those on overridden method " | 238 "doesn't match those on overridden method " |
239 "'${interfaceMember.enclosingClass.name}::" | 239 "'${interfaceMember.enclosingClass.name}::" |
240 "${interfaceMember.name.name}'."); | 240 "${interfaceMember.name.name}'."); |
241 } | 241 } |
242 if (declaredFunction.positionalParameters.length < | 242 if (declaredFunction.positionalParameters.length < |
243 interfaceFunction.requiredParameterCount || | 243 interfaceFunction.requiredParameterCount || |
244 declaredFunction.positionalParameters.length < | 244 declaredFunction.positionalParameters.length < |
245 interfaceFunction.positionalParameters.length) { | 245 interfaceFunction.positionalParameters.length) { |
246 addWarning( | 246 deprecated_addWarning( |
247 declaredMember.fileOffset, | 247 declaredMember.fileOffset, |
248 "The method '$name::${declaredMember.name.name}' has fewer " | 248 "The method '$name::${declaredMember.name.name}' has fewer " |
249 "positional arguments than those of overridden method " | 249 "positional arguments than those of overridden method " |
250 "'${interfaceMember.enclosingClass.name}::" | 250 "'${interfaceMember.enclosingClass.name}::" |
251 "${interfaceMember.name.name}'."); | 251 "${interfaceMember.name.name}'."); |
252 } | 252 } |
253 if (interfaceFunction.requiredParameterCount < | 253 if (interfaceFunction.requiredParameterCount < |
254 declaredFunction.requiredParameterCount) { | 254 declaredFunction.requiredParameterCount) { |
255 addWarning( | 255 deprecated_addWarning( |
256 declaredMember.fileOffset, | 256 declaredMember.fileOffset, |
257 "The method '$name::${declaredMember.name.name}' has more " | 257 "The method '$name::${declaredMember.name.name}' has more " |
258 "required arguments than those of overridden method " | 258 "required arguments than those of overridden method " |
259 "'${interfaceMember.enclosingClass.name}::" | 259 "'${interfaceMember.enclosingClass.name}::" |
260 "${interfaceMember.name.name}'."); | 260 "${interfaceMember.name.name}'."); |
261 } | 261 } |
262 if (declaredFunction.namedParameters.isEmpty && | 262 if (declaredFunction.namedParameters.isEmpty && |
263 interfaceFunction.namedParameters.isEmpty) { | 263 interfaceFunction.namedParameters.isEmpty) { |
264 return; | 264 return; |
265 } | 265 } |
266 if (declaredFunction.namedParameters.length < | 266 if (declaredFunction.namedParameters.length < |
267 interfaceFunction.namedParameters.length) { | 267 interfaceFunction.namedParameters.length) { |
268 addWarning( | 268 deprecated_addWarning( |
269 declaredMember.fileOffset, | 269 declaredMember.fileOffset, |
270 "The method '$name::${declaredMember.name.name}' has fewer named " | 270 "The method '$name::${declaredMember.name.name}' has fewer named " |
271 "arguments than those of overridden method " | 271 "arguments than those of overridden method " |
272 "'${interfaceMember.enclosingClass.name}::" | 272 "'${interfaceMember.enclosingClass.name}::" |
273 "${interfaceMember.name.name}'."); | 273 "${interfaceMember.name.name}'."); |
274 } | 274 } |
275 Iterator<VariableDeclaration> declaredNamedParameters = | 275 Iterator<VariableDeclaration> declaredNamedParameters = |
276 declaredFunction.namedParameters.iterator; | 276 declaredFunction.namedParameters.iterator; |
277 Iterator<VariableDeclaration> interfaceNamedParameters = | 277 Iterator<VariableDeclaration> interfaceNamedParameters = |
278 interfaceFunction.namedParameters.iterator; | 278 interfaceFunction.namedParameters.iterator; |
279 outer: | 279 outer: |
280 while (declaredNamedParameters.moveNext() && | 280 while (declaredNamedParameters.moveNext() && |
281 interfaceNamedParameters.moveNext()) { | 281 interfaceNamedParameters.moveNext()) { |
282 while (declaredNamedParameters.current.name != | 282 while (declaredNamedParameters.current.name != |
283 interfaceNamedParameters.current.name) { | 283 interfaceNamedParameters.current.name) { |
284 if (!declaredNamedParameters.moveNext()) { | 284 if (!declaredNamedParameters.moveNext()) { |
285 addWarning( | 285 deprecated_addWarning( |
286 declaredMember.fileOffset, | 286 declaredMember.fileOffset, |
287 "The method '$name::${declaredMember.name.name}' doesn't have " | 287 "The method '$name::${declaredMember.name.name}' doesn't have " |
288 "the named parameter '${interfaceNamedParameters.current.name}' " | 288 "the named parameter '${interfaceNamedParameters.current.name}' " |
289 "of overriden method '${interfaceMember.enclosingClass.name}::" | 289 "of overriden method '${interfaceMember.enclosingClass.name}::" |
290 "${interfaceMember.name.name}'."); | 290 "${interfaceMember.name.name}'."); |
291 break outer; | 291 break outer; |
292 } | 292 } |
293 } | 293 } |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 String get fullNameForErrors { | 297 String get fullNameForErrors { |
298 return isMixinApplication | 298 return isMixinApplication |
299 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" | 299 ? "${supertype.fullNameForErrors} with ${mixedInType.fullNameForErrors}" |
300 : name; | 300 : name; |
301 } | 301 } |
302 } | 302 } |
OLD | NEW |