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

Side by Side Diff: pkg/kernel/lib/transformations/insert_covariance_checks.dart

Issue 2718363003: Add source information to the covariance checks inserted for strong mode (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library kernel.transformations.insert_covariance_checks; 4 library kernel.transformations.insert_covariance_checks;
5 5
6 import '../class_hierarchy.dart'; 6 import '../class_hierarchy.dart';
7 import '../clone.dart'; 7 import '../clone.dart';
8 import '../core_types.dart'; 8 import '../core_types.dart';
9 import '../kernel.dart'; 9 import '../kernel.dart';
10 import '../log.dart'; 10 import '../log.dart';
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 var unsafeInputs = unsafeParameterTypes[parameter]; 370 var unsafeInputs = unsafeParameterTypes[parameter];
371 if (unsafeInputs == null) { 371 if (unsafeInputs == null) {
372 return new VariableGet(cloneParameter); // No check needed. 372 return new VariableGet(cloneParameter); // No check needed.
373 } 373 }
374 // Change the actual parameter type to the safe type, and cast to the 374 // Change the actual parameter type to the safe type, and cast to the
375 // type declared on the original parameter. 375 // type declared on the original parameter.
376 // Use the cloner to map function type parameters to the cloned 376 // Use the cloner to map function type parameters to the cloned
377 // function type parameters (in case the function is generic). 377 // function type parameters (in case the function is generic).
378 var targetType = cloneParameter.type; 378 var targetType = cloneParameter.type;
379 cloneParameter.type = cloner.visitType(getSafeType(unsafeInputs)); 379 cloneParameter.type = cloner.visitType(getSafeType(unsafeInputs));
380 return new AsExpression(new VariableGet(cloneParameter), targetType); 380 return new AsExpression(new VariableGet(cloneParameter), targetType)
381 ..fileOffset = parameter.fileOffset;
381 } 382 }
382 383
383 // TODO: Insert checks for type parameter bounds. 384 // TODO: Insert checks for type parameter bounds.
384 var types = checkedFunction.typeParameters 385 var types = checkedFunction.typeParameters
385 .map((p) => new TypeParameterType(p)) 386 .map((p) => new TypeParameterType(p))
386 .toList(); 387 .toList();
387 var positional = function.positionalParameters.map(getParameter).toList(); 388 var positional = function.positionalParameters.map(getParameter).toList();
388 var named = function.namedParameters 389 var named = function.namedParameters
389 .map((p) => new NamedExpression(p.name, getParameter(p))) 390 .map((p) => new NamedExpression(p.name, getParameter(p)))
390 .toList(); 391 .toList();
(...skipping 18 matching lines...) Expand all
409 global.unsafeMemberEntryPoint[procedure] = checkedProcedure; 410 global.unsafeMemberEntryPoint[procedure] = checkedProcedure;
410 } 411 }
411 } 412 }
412 413
413 void generateCheckedFieldSetter(Field field) { 414 void generateCheckedFieldSetter(Field field) {
414 var parameter = getFieldSetterParameter(field); 415 var parameter = getFieldSetterParameter(field);
415 var unsafeTypes = unsafeParameterTypes[parameter]; 416 var unsafeTypes = unsafeParameterTypes[parameter];
416 Expression argument = new VariableGet(parameter); 417 Expression argument = new VariableGet(parameter);
417 if (unsafeTypes != null) { 418 if (unsafeTypes != null) {
418 var castType = substitute(field.type, ownSubstitution); 419 var castType = substitute(field.type, ownSubstitution);
419 argument = new AsExpression(argument, castType); 420 argument = new AsExpression(argument, castType)
421 ..fileOffset = field.fileOffset;
420 var inputType = substitute(getSafeType(unsafeTypes), ownSubstitution); 422 var inputType = substitute(getSafeType(unsafeTypes), ownSubstitution);
421 parameter.type = inputType; 423 parameter.type = inputType;
422 } 424 }
423 425
424 Statement body = field.isInExternalLibrary 426 Statement body = field.isInExternalLibrary
425 ? null 427 ? null
426 : new ExpressionStatement( 428 : new ExpressionStatement(
427 new DirectPropertySet(new ThisExpression(), field, argument)); 429 new DirectPropertySet(new ThisExpression(), field, argument));
428 430
429 var setter = new Procedure( 431 var setter = new Procedure(
430 covariantCheckedName(field.name), 432 covariantCheckedName(field.name),
431 ProcedureKind.Setter, 433 ProcedureKind.Setter,
432 new FunctionNode(body, positionalParameters: [parameter])); 434 new FunctionNode(body, positionalParameters: [parameter]))
435 ..fileUri = field.fileUri;
433 host.addMember(setter); 436 host.addMember(setter);
434 437
435 if (field.enclosingClass == host) { 438 if (field.enclosingClass == host) {
436 global.unsafeMemberEntryPoint[field] = setter; 439 global.unsafeMemberEntryPoint[field] = setter;
437 } 440 }
438 } 441 }
439 442
440 /// Generates a synthetic name representing the covariant-checked entry point 443 /// Generates a synthetic name representing the covariant-checked entry point
441 /// to a method. 444 /// to a method.
442 static Name covariantCheckedName(Name name) { 445 static Name covariantCheckedName(Name name) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 @override 516 @override
514 visitPropertySet(PropertySet node) { 517 visitPropertySet(PropertySet node) {
515 var target = getChecked(node.receiver, node.interfaceTarget); 518 var target = getChecked(node.receiver, node.interfaceTarget);
516 if (target != null) { 519 if (target != null) {
517 node.interfaceTarget = target; 520 node.interfaceTarget = target;
518 node.name = target.name; 521 node.name = target.name;
519 } 522 }
520 node.visitChildren(this); 523 node.visitChildren(this);
521 } 524 }
522 } 525 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698