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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart

Issue 2946273002: Implement override-based type inference for instance methods. (Closed)
Patch Set: Created 3 years, 6 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) 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_procedure_builder; 5 library fasta.kernel_procedure_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 KernelProcedure; 8 show KernelProcedure;
9 9
10 import 'package:front_end/src/fasta/source/source_library_builder.dart' 10 import 'package:front_end/src/fasta/source/source_library_builder.dart'
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 String name, 208 String name,
209 List<TypeVariableBuilder> typeVariables, 209 List<TypeVariableBuilder> typeVariables,
210 List<FormalParameterBuilder> formals, 210 List<FormalParameterBuilder> formals,
211 ProcedureKind kind, 211 ProcedureKind kind,
212 KernelLibraryBuilder compilationUnit, 212 KernelLibraryBuilder compilationUnit,
213 int charOffset, 213 int charOffset,
214 this.charOpenParenOffset, 214 this.charOpenParenOffset,
215 int charEndOffset, 215 int charEndOffset,
216 [String nativeMethodName, 216 [String nativeMethodName,
217 this.redirectionTarget]) 217 this.redirectionTarget])
218 : procedure = new KernelProcedure(null, kind, null, 218 : procedure = new KernelProcedure(null, kind, null, returnType == null,
219 fileUri: compilationUnit?.relativeFileUri) 219 fileUri: compilationUnit?.relativeFileUri)
220 ..fileOffset = charOffset 220 ..fileOffset = charOffset
221 ..fileEndOffset = charEndOffset, 221 ..fileEndOffset = charEndOffset,
222 super(metadata, modifiers, returnType, name, typeVariables, formals, 222 super(metadata, modifiers, returnType, name, typeVariables, formals,
223 compilationUnit, charOffset, nativeMethodName); 223 compilationUnit, charOffset, nativeMethodName);
224 224
225 ProcedureKind get kind => procedure.kind; 225 ProcedureKind get kind => procedure.kind;
226 226
227 AsyncMarker get asyncModifier => actualAsyncModifier; 227 AsyncMarker get asyncModifier => actualAsyncModifier;
228 228
229 Statement get body { 229 Statement get body {
230 if (actualBody == null && 230 if (actualBody == null &&
231 redirectionTarget == null && 231 redirectionTarget == null &&
232 !isAbstract && 232 !isAbstract &&
233 !isExternal) { 233 !isExternal) {
234 actualBody = new EmptyStatement(); 234 actualBody = new EmptyStatement();
235 } 235 }
236 return actualBody; 236 return actualBody;
237 } 237 }
238 238
239 void set asyncModifier(AsyncMarker newModifier) { 239 void set asyncModifier(AsyncMarker newModifier) {
240 actualAsyncModifier = newModifier; 240 actualAsyncModifier = newModifier;
241 if (function != null) { 241 if (function != null) {
242 // No parent, it's an enum. 242 // No parent, it's an enum.
243 function.asyncMarker = actualAsyncModifier; 243 function.asyncMarker = actualAsyncModifier;
244 function.dartAsyncMarker = actualAsyncModifier; 244 function.dartAsyncMarker = actualAsyncModifier;
245 } 245 }
246 } 246 }
247 247
248 bool get isEligibleForGetterSetterInference { 248 bool get isEligibleForTopLevelInference {
249 if (!isInstanceMember) return false; 249 if (!isInstanceMember) return false;
250 if (isGetter) { 250 if (returnType == null) {
251 return returnType == null; 251 // For now, we skip inferred return types of setters.
Siggi Cherem (dart-lang) 2017/06/21 20:19:08 aren't they always void (otherwise it is an error)
Paul Berry 2017/06/21 20:54:47 Not quite. In strong mode if no type is specified
252 } else if (isSetter) { 252 // TODO(paulberry): fix this.
253 return formals != null && formals.length > 0 && formals[0].type == null; 253 if (!isSetter) return true;
254 } else {
255 return false;
256 } 254 }
255 if (formals != null) {
256 for (var formal in formals) {
257 if (formal.type == null) return true;
258 }
259 }
260 return false;
257 } 261 }
258 262
259 Procedure build(SourceLibraryBuilder library) { 263 Procedure build(SourceLibraryBuilder library) {
260 // TODO(ahe): I think we may call this twice on parts. Investigate. 264 // TODO(ahe): I think we may call this twice on parts. Investigate.
261 if (procedure.name == null) { 265 if (procedure.name == null) {
262 procedure.function = buildFunction(library); 266 procedure.function = buildFunction(library);
263 procedure.function.parent = procedure; 267 procedure.function.parent = procedure;
264 procedure.function.fileOffset = charOpenParenOffset; 268 procedure.function.fileOffset = charOpenParenOffset;
265 procedure.function.fileEndOffset = procedure.fileEndOffset; 269 procedure.function.fileEndOffset = procedure.fileEndOffset;
266 procedure.isAbstract = isAbstract; 270 procedure.isAbstract = isAbstract;
267 procedure.isStatic = isStatic; 271 procedure.isStatic = isStatic;
268 procedure.isExternal = isExternal; 272 procedure.isExternal = isExternal;
269 procedure.isConst = isConst; 273 procedure.isConst = isConst;
270 procedure.name = new Name(name, library.target); 274 procedure.name = new Name(name, library.target);
271 } 275 }
272 if (isEligibleForGetterSetterInference) { 276 if (isEligibleForTopLevelInference) {
273 library.loader.typeInferenceEngine.recordMember(procedure); 277 library.loader.typeInferenceEngine.recordMember(procedure);
274 } 278 }
275 return procedure; 279 return procedure;
276 } 280 }
277 281
278 Procedure get target => procedure; 282 Procedure get target => procedure;
279 283
280 @override 284 @override
281 void prepareInitializerInference( 285 void prepareInitializerInference(
282 SourceLibraryBuilder library, ClassBuilder currentClass) { 286 SourceLibraryBuilder library, ClassBuilder currentClass) {
283 if (isEligibleForGetterSetterInference) { 287 if (isEligibleForTopLevelInference) {
284 var typeInferenceEngine = library.loader.typeInferenceEngine; 288 var typeInferenceEngine = library.loader.typeInferenceEngine;
285 var listener = new TypeInferenceListener(); 289 var listener = new TypeInferenceListener();
286 typeInferenceEngine.createTopLevelTypeInferrer( 290 typeInferenceEngine.createTopLevelTypeInferrer(
287 listener, procedure.enclosingClass?.thisType, procedure); 291 listener, procedure.enclosingClass?.thisType, procedure);
288 } 292 }
289 } 293 }
290 } 294 }
291 295
292 // TODO(ahe): Move this to own file? 296 // TODO(ahe): Move this to own file?
293 class KernelConstructorBuilder extends KernelFunctionBuilder { 297 class KernelConstructorBuilder extends KernelFunctionBuilder {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 410 }
407 } 411 }
408 initializers.add(initializer..parent = constructor); 412 initializers.add(initializer..parent = constructor);
409 initializers.add(superInitializer); 413 initializers.add(superInitializer);
410 return; 414 return;
411 } 415 }
412 initializers.add(initializer); 416 initializers.add(initializer);
413 initializer.parent = constructor; 417 initializer.parent = constructor;
414 } 418 }
415 } 419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698