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 /// A library to help transform compounds and null-aware accessors into | 5 /// A library to help transform compounds and null-aware accessors into |
6 /// let expressions. | 6 /// let expressions. |
7 | 7 |
8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
9 show | 9 show |
10 KernelArguments, | 10 KernelArguments, |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 class ThisIndexAccessor extends Accessor { | 504 class ThisIndexAccessor extends Accessor { |
505 Expression index; | 505 Expression index; |
506 VariableDeclaration indexVariable; | 506 VariableDeclaration indexVariable; |
507 Procedure getter, setter; | 507 Procedure getter, setter; |
508 | 508 |
509 ThisIndexAccessor( | 509 ThisIndexAccessor( |
510 BuilderHelper helper, this.index, this.getter, this.setter, Token token) | 510 BuilderHelper helper, this.index, this.getter, this.setter, Token token) |
511 : super(helper, token); | 511 : super(helper, token); |
512 | 512 |
513 Expression _makeSimpleRead() { | 513 Expression _makeSimpleRead() { |
514 return new KernelMethodInvocation(new ThisExpression(), indexGetName, | 514 return new KernelMethodInvocation(new KernelThisExpression(), indexGetName, |
515 new KernelArguments(<Expression>[index]), | 515 new KernelArguments(<Expression>[index]), |
516 interfaceTarget: getter); | 516 interfaceTarget: getter); |
517 } | 517 } |
518 | 518 |
519 Expression _makeSimpleWrite(Expression value, bool voidContext, | 519 Expression _makeSimpleWrite(Expression value, bool voidContext, |
520 KernelComplexAssignment complexAssignment) { | 520 KernelComplexAssignment complexAssignment) { |
521 if (!voidContext) return _makeWriteAndReturn(value, complexAssignment); | 521 if (!voidContext) return _makeWriteAndReturn(value, complexAssignment); |
522 var write = new KernelMethodInvocation(new ThisExpression(), indexSetName, | 522 var write = new KernelMethodInvocation(new KernelThisExpression(), |
523 new KernelArguments(<Expression>[index, value]), | 523 indexSetName, new KernelArguments(<Expression>[index, value]), |
524 interfaceTarget: setter) | 524 interfaceTarget: setter) |
525 ..fileOffset = offsetForToken(token); | 525 ..fileOffset = offsetForToken(token); |
526 complexAssignment?.write = write; | 526 complexAssignment?.write = write; |
527 return write; | 527 return write; |
528 } | 528 } |
529 | 529 |
530 indexAccess() { | 530 indexAccess() { |
531 indexVariable ??= new VariableDeclaration.forValue(index); | 531 indexVariable ??= new VariableDeclaration.forValue(index); |
532 return new VariableGet(indexVariable); | 532 return new VariableGet(indexVariable); |
533 } | 533 } |
534 | 534 |
535 Expression _makeRead(KernelComplexAssignment complexAssignment) { | 535 Expression _makeRead(KernelComplexAssignment complexAssignment) { |
536 var read = new KernelMethodInvocation(new ThisExpression(), indexGetName, | 536 var read = new KernelMethodInvocation(new KernelThisExpression(), |
537 new KernelArguments(<Expression>[indexAccess()]), | 537 indexGetName, new KernelArguments(<Expression>[indexAccess()]), |
538 interfaceTarget: getter) | 538 interfaceTarget: getter) |
539 ..fileOffset = offsetForToken(token); | 539 ..fileOffset = offsetForToken(token); |
540 complexAssignment?.read = read; | 540 complexAssignment?.read = read; |
541 return read; | 541 return read; |
542 } | 542 } |
543 | 543 |
544 Expression _makeWrite(Expression value, bool voidContext, | 544 Expression _makeWrite(Expression value, bool voidContext, |
545 KernelComplexAssignment complexAssignment) { | 545 KernelComplexAssignment complexAssignment) { |
546 if (!voidContext) return _makeWriteAndReturn(value, complexAssignment); | 546 if (!voidContext) return _makeWriteAndReturn(value, complexAssignment); |
547 var write = new KernelMethodInvocation(new ThisExpression(), indexSetName, | 547 var write = new KernelMethodInvocation(new KernelThisExpression(), |
548 new KernelArguments(<Expression>[indexAccess(), value]), | 548 indexSetName, new KernelArguments(<Expression>[indexAccess(), value]), |
549 interfaceTarget: setter) | 549 interfaceTarget: setter) |
550 ..fileOffset = offsetForToken(token); | 550 ..fileOffset = offsetForToken(token); |
551 complexAssignment?.write = write; | 551 complexAssignment?.write = write; |
552 return write; | 552 return write; |
553 } | 553 } |
554 | 554 |
555 _makeWriteAndReturn( | 555 _makeWriteAndReturn( |
556 Expression value, KernelComplexAssignment complexAssignment) { | 556 Expression value, KernelComplexAssignment complexAssignment) { |
557 var valueVariable = new VariableDeclaration.forValue(value); | 557 var valueVariable = new VariableDeclaration.forValue(value); |
558 var write = new KernelMethodInvocation( | 558 var write = new KernelMethodInvocation( |
559 new ThisExpression(), | 559 new KernelThisExpression(), |
560 indexSetName, | 560 indexSetName, |
561 new KernelArguments( | 561 new KernelArguments( |
562 <Expression>[indexAccess(), new VariableGet(valueVariable)]), | 562 <Expression>[indexAccess(), new VariableGet(valueVariable)]), |
563 interfaceTarget: setter) | 563 interfaceTarget: setter) |
564 ..fileOffset = offsetForToken(token); | 564 ..fileOffset = offsetForToken(token); |
565 complexAssignment?.write = write; | 565 complexAssignment?.write = write; |
566 var dummy = new VariableDeclaration.forValue(write); | 566 var dummy = new VariableDeclaration.forValue(write); |
567 return makeLet( | 567 return makeLet( |
568 valueVariable, makeLet(dummy, new VariableGet(valueVariable))); | 568 valueVariable, makeLet(dummy, new VariableGet(valueVariable))); |
569 } | 569 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 723 |
724 Expression buildIsNull(Expression value, int offset) { | 724 Expression buildIsNull(Expression value, int offset) { |
725 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset); | 725 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset); |
726 } | 726 } |
727 | 727 |
728 VariableDeclaration makeOrReuseVariable(Expression value) { | 728 VariableDeclaration makeOrReuseVariable(Expression value) { |
729 // TODO: Devise a way to remember if a variable declaration was reused | 729 // TODO: Devise a way to remember if a variable declaration was reused |
730 // or is fresh (hence needs a let binding). | 730 // or is fresh (hence needs a let binding). |
731 return new VariableDeclaration.forValue(value); | 731 return new VariableDeclaration.forValue(value); |
732 } | 732 } |
OLD | NEW |