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.fasta_accessors; | 5 library fasta.fasta_accessors; |
6 | 6 |
7 export 'frontend_accessors.dart' show wrapInvalid; | 7 export 'frontend_accessors.dart' show wrapInvalid; |
8 | 8 |
| 9 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
| 10 show KernelArguments, KernelMethodInvocation; |
| 11 |
9 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 12 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
10 | 13 |
11 import 'package:front_end/src/scanner/token.dart' show Token; | 14 import 'package:front_end/src/scanner/token.dart' show Token; |
12 | 15 |
13 import 'frontend_accessors.dart' show Accessor, buildIsNull, makeLet; | 16 import 'frontend_accessors.dart' show Accessor, buildIsNull, makeLet; |
14 | 17 |
15 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory; | |
16 | |
17 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' | 18 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' |
18 show TypePromoter; | 19 show TypePromoter; |
19 | 20 |
20 import 'package:kernel/ast.dart'; | 21 import 'package:kernel/ast.dart'; |
21 | 22 |
22 import '../errors.dart' show internalError; | 23 import '../errors.dart' show internalError; |
23 | 24 |
24 import '../scope.dart' show AccessErrorBuilder, ProblemBuilder, Scope; | 25 import '../scope.dart' show AccessErrorBuilder, ProblemBuilder, Scope; |
25 | 26 |
26 import 'frontend_accessors.dart' as kernel | 27 import 'frontend_accessors.dart' as kernel |
(...skipping 14 matching lines...) Expand all Loading... |
41 | 42 |
42 import '../names.dart' show callName; | 43 import '../names.dart' show callName; |
43 | 44 |
44 abstract class BuilderHelper { | 45 abstract class BuilderHelper { |
45 Uri get uri; | 46 Uri get uri; |
46 | 47 |
47 TypePromoter get typePromoter; | 48 TypePromoter get typePromoter; |
48 | 49 |
49 int get functionNestingLevel; | 50 int get functionNestingLevel; |
50 | 51 |
51 AstFactory get astFactory; | |
52 | |
53 Constructor lookupConstructor(Name name, {bool isSuper}); | 52 Constructor lookupConstructor(Name name, {bool isSuper}); |
54 | 53 |
55 Expression toSuperMethodInvocation(MethodInvocation node); | 54 Expression toSuperMethodInvocation(MethodInvocation node); |
56 | 55 |
57 Expression toValue(node); | 56 Expression toValue(node); |
58 | 57 |
59 Member lookupSuperMember(Name name, {bool isSetter: false}); | 58 Member lookupSuperMember(Name name, {bool isSetter: false}); |
60 | 59 |
61 scopeLookup(Scope scope, String name, Token token, | 60 scopeLookup(Scope scope, String name, Token token, |
62 {bool isQualified: false, PrefixBuilder prefix}); | 61 {bool isQualified: false, PrefixBuilder prefix}); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 "Can't use $plainNameForRead here.", | 110 "Can't use $plainNameForRead here.", |
112 offset), | 111 offset), |
113 offset); | 112 offset); |
114 } | 113 } |
115 | 114 |
116 Expression makeInvalidRead() { | 115 Expression makeInvalidRead() { |
117 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); | 116 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); |
118 } | 117 } |
119 | 118 |
120 Expression makeInvalidWrite(Expression value) { | 119 Expression makeInvalidWrite(Expression value) { |
121 return buildThrowNoSuchMethodError( | 120 return buildThrowNoSuchMethodError(new KernelArguments(<Expression>[value]), |
122 helper.astFactory.arguments(<Expression>[value]), | |
123 isSetter: true); | 121 isSetter: true); |
124 } | 122 } |
125 | 123 |
126 /* Expression | FastaAccessor | Initializer */ doInvocation( | 124 /* Expression | FastaAccessor | Initializer */ doInvocation( |
127 int offset, Arguments arguments); | 125 int offset, Arguments arguments); |
128 | 126 |
129 /* Expression | FastaAccessor */ buildPropertyAccess( | 127 /* Expression | FastaAccessor */ buildPropertyAccess( |
130 IncompleteSend send, bool isNullAware) { | 128 IncompleteSend send, bool isNullAware) { |
131 if (send is SendAccessor) { | 129 if (send is SendAccessor) { |
132 return buildMethodInvocation(helper.astFactory, buildSimpleRead(), | 130 return buildMethodInvocation(buildSimpleRead(), send.name, send.arguments, |
133 send.name, send.arguments, offsetForToken(send.token), | 131 offsetForToken(send.token), |
134 isNullAware: isNullAware); | 132 isNullAware: isNullAware); |
135 } else { | 133 } else { |
136 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), | 134 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), |
137 send.name, null, null, isNullAware); | 135 send.name, null, null, isNullAware); |
138 } | 136 } |
139 } | 137 } |
140 | 138 |
141 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( | 139 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( |
142 Arguments arguments, | 140 Arguments arguments, |
143 {bool isSuper: false, | 141 {bool isSuper: false, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 {bool isSuper: false, | 201 {bool isSuper: false, |
204 isGetter: false, | 202 isGetter: false, |
205 isSetter: false, | 203 isSetter: false, |
206 String name, | 204 String name, |
207 int offset}) { | 205 int offset}) { |
208 return this; | 206 return this; |
209 } | 207 } |
210 | 208 |
211 @override | 209 @override |
212 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 210 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
213 return buildError(helper.astFactory.arguments(<Expression>[value]), | 211 return buildError(new KernelArguments(<Expression>[value]), isSetter: true); |
214 isSetter: true); | |
215 } | 212 } |
216 | 213 |
217 @override | 214 @override |
218 Expression buildCompoundAssignment(Name binaryOperator, Expression value, | 215 Expression buildCompoundAssignment(Name binaryOperator, Expression value, |
219 {int offset: TreeNode.noOffset, | 216 {int offset: TreeNode.noOffset, |
220 bool voidContext: false, | 217 bool voidContext: false, |
221 Procedure interfaceTarget}) { | 218 Procedure interfaceTarget}) { |
222 return buildError(helper.astFactory.arguments(<Expression>[value]), | 219 return buildError(new KernelArguments(<Expression>[value]), isGetter: true); |
223 isGetter: true); | |
224 } | 220 } |
225 | 221 |
226 @override | 222 @override |
227 Expression buildPrefixIncrement(Name binaryOperator, | 223 Expression buildPrefixIncrement(Name binaryOperator, |
228 {int offset: TreeNode.noOffset, | 224 {int offset: TreeNode.noOffset, |
229 bool voidContext: false, | 225 bool voidContext: false, |
230 Procedure interfaceTarget}) { | 226 Procedure interfaceTarget}) { |
231 return buildError( | 227 return buildError(new KernelArguments(<Expression>[new IntLiteral(1)]), |
232 helper.astFactory.arguments(<Expression>[new IntLiteral(1)]), | |
233 isGetter: true); | 228 isGetter: true); |
234 } | 229 } |
235 | 230 |
236 @override | 231 @override |
237 Expression buildPostfixIncrement(Name binaryOperator, | 232 Expression buildPostfixIncrement(Name binaryOperator, |
238 {int offset: TreeNode.noOffset, | 233 {int offset: TreeNode.noOffset, |
239 bool voidContext: false, | 234 bool voidContext: false, |
240 Procedure interfaceTarget}) { | 235 Procedure interfaceTarget}) { |
241 return buildError( | 236 return buildError(new KernelArguments(<Expression>[new IntLiteral(1)]), |
242 helper.astFactory.arguments(<Expression>[new IntLiteral(1)]), | |
243 isGetter: true); | 237 isGetter: true); |
244 } | 238 } |
245 | 239 |
246 @override | 240 @override |
247 Expression buildNullAwareAssignment(Expression value, DartType type, | 241 Expression buildNullAwareAssignment(Expression value, DartType type, |
248 {bool voidContext: false}) { | 242 {bool voidContext: false}) { |
249 return buildError(helper.astFactory.arguments(<Expression>[value]), | 243 return buildError(new KernelArguments(<Expression>[value]), isSetter: true); |
250 isSetter: true); | |
251 } | 244 } |
252 | 245 |
253 @override | 246 @override |
254 Expression buildSimpleRead() => | 247 Expression buildSimpleRead() => |
255 buildError(new Arguments.empty(), isGetter: true); | 248 buildError(new Arguments.empty(), isGetter: true); |
256 | 249 |
257 @override | 250 @override |
258 Expression makeInvalidRead() => | 251 Expression makeInvalidRead() => |
259 buildError(new Arguments.empty(), isGetter: true); | 252 buildError(new Arguments.empty(), isGetter: true); |
260 | 253 |
261 @override | 254 @override |
262 Expression makeInvalidWrite(Expression value) { | 255 Expression makeInvalidWrite(Expression value) { |
263 return buildError(helper.astFactory.arguments(<Expression>[value]), | 256 return buildError(new KernelArguments(<Expression>[value]), isSetter: true); |
264 isSetter: true); | |
265 } | 257 } |
266 } | 258 } |
267 | 259 |
268 class ThisAccessor extends FastaAccessor { | 260 class ThisAccessor extends FastaAccessor { |
269 final BuilderHelper helper; | 261 final BuilderHelper helper; |
270 | 262 |
271 final Token token; | 263 final Token token; |
272 | 264 |
273 final bool isInitializer; | 265 final bool isInitializer; |
274 | 266 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 307 } |
316 | 308 |
317 buildPropertyAccess(IncompleteSend send, bool isNullAware) { | 309 buildPropertyAccess(IncompleteSend send, bool isNullAware) { |
318 if (isInitializer && send is SendAccessor) { | 310 if (isInitializer && send is SendAccessor) { |
319 return buildConstructorInitializer( | 311 return buildConstructorInitializer( |
320 offsetForToken(send.token), send.name, send.arguments); | 312 offsetForToken(send.token), send.name, send.arguments); |
321 } | 313 } |
322 if (send is SendAccessor) { | 314 if (send is SendAccessor) { |
323 // Notice that 'this' or 'super' can't be null. So we can ignore the | 315 // Notice that 'this' or 'super' can't be null. So we can ignore the |
324 // value of [isNullAware]. | 316 // value of [isNullAware]. |
325 MethodInvocation result = buildMethodInvocation( | 317 MethodInvocation result = buildMethodInvocation(new ThisExpression(), |
326 helper.astFactory, | 318 send.name, send.arguments, offsetForToken(token)); |
327 new ThisExpression(), | |
328 send.name, | |
329 send.arguments, | |
330 offsetForToken(token)); | |
331 return isSuper ? helper.toSuperMethodInvocation(result) : result; | 319 return isSuper ? helper.toSuperMethodInvocation(result) : result; |
332 } else { | 320 } else { |
333 if (isSuper) { | 321 if (isSuper) { |
334 Member getter = helper.lookupSuperMember(send.name); | 322 Member getter = helper.lookupSuperMember(send.name); |
335 Member setter = helper.lookupSuperMember(send.name, isSetter: true); | 323 Member setter = helper.lookupSuperMember(send.name, isSetter: true); |
336 return new SuperPropertyAccessor( | 324 return new SuperPropertyAccessor( |
337 helper, send.token, send.name, getter, setter); | 325 helper, send.token, send.name, getter, setter); |
338 } else { | 326 } else { |
339 return new ThisPropertyAccessor( | 327 return new ThisPropertyAccessor( |
340 helper, send.token, send.name, null, null); | 328 helper, send.token, send.name, null, null); |
341 } | 329 } |
342 } | 330 } |
343 } | 331 } |
344 | 332 |
345 doInvocation(int offset, Arguments arguments) { | 333 doInvocation(int offset, Arguments arguments) { |
346 if (isInitializer) { | 334 if (isInitializer) { |
347 return buildConstructorInitializer(offset, new Name(""), arguments); | 335 return buildConstructorInitializer(offset, new Name(""), arguments); |
348 } else { | 336 } else { |
349 return buildMethodInvocation( | 337 return buildMethodInvocation( |
350 helper.astFactory, new ThisExpression(), callName, arguments, offset); | 338 new ThisExpression(), callName, arguments, offset); |
351 } | 339 } |
352 } | 340 } |
353 | 341 |
354 Initializer buildConstructorInitializer( | 342 Initializer buildConstructorInitializer( |
355 int offset, Name name, Arguments arguments) { | 343 int offset, Name name, Arguments arguments) { |
356 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 344 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
357 if (constructor == null || | 345 if (constructor == null || |
358 !helper.checkArguments( | 346 !helper.checkArguments( |
359 constructor.function, arguments, <TypeParameter>[])) { | 347 constructor.function, arguments, <TypeParameter>[])) { |
360 return helper.buildInvalidIntializer( | 348 return helper.buildInvalidIntializer( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (builder == null || builder is AccessErrorBuilder) { | 484 if (builder == null || builder is AccessErrorBuilder) { |
497 return buildThrowNoSuchMethodError(arguments); | 485 return buildThrowNoSuchMethodError(arguments); |
498 } | 486 } |
499 if (builder.hasProblem) { | 487 if (builder.hasProblem) { |
500 result = helper.buildProblemExpression(builder, offsetForToken(token)); | 488 result = helper.buildProblemExpression(builder, offsetForToken(token)); |
501 } else { | 489 } else { |
502 Member target = builder.target; | 490 Member target = builder.target; |
503 if (target != null) { | 491 if (target != null) { |
504 if (target is Field) { | 492 if (target is Field) { |
505 result = buildMethodInvocation( | 493 result = buildMethodInvocation( |
506 helper.astFactory, | |
507 new StaticGet(target), | 494 new StaticGet(target), |
508 callName, | 495 callName, |
509 arguments, | 496 arguments, |
510 offsetForToken(token) + (target.name?.name?.length ?? 0), | 497 offsetForToken(token) + (target.name?.name?.length ?? 0), |
511 isNullAware: isNullAware); | 498 isNullAware: isNullAware); |
512 } else { | 499 } else { |
513 result = helper.buildStaticInvocation(target, arguments) | 500 result = helper.buildStaticInvocation(target, arguments) |
514 ..fileOffset = offsetForToken(token); | 501 ..fileOffset = offsetForToken(token); |
515 } | 502 } |
516 } else { | 503 } else { |
517 result = buildThrowNoSuchMethodError(arguments) | 504 result = buildThrowNoSuchMethodError(arguments) |
518 ..fileOffset = offsetForToken(token); | 505 ..fileOffset = offsetForToken(token); |
519 } | 506 } |
520 } | 507 } |
521 } else { | 508 } else { |
522 result = buildMethodInvocation(helper.astFactory, | 509 result = buildMethodInvocation( |
523 helper.toValue(receiver), name, arguments, offsetForToken(token), | 510 helper.toValue(receiver), name, arguments, offsetForToken(token), |
524 isNullAware: isNullAware); | 511 isNullAware: isNullAware); |
525 } | 512 } |
526 return result; | 513 return result; |
527 } | 514 } |
528 | 515 |
529 Expression buildNullAwareAssignment(Expression value, DartType type, | 516 Expression buildNullAwareAssignment(Expression value, DartType type, |
530 {bool voidContext: false}) { | 517 {bool voidContext: false}) { |
531 return internalError("Unhandled"); | 518 return internalError("Unhandled"); |
532 } | 519 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 IndexAccessor.internal(this.helper, Token token, Expression receiver, | 630 IndexAccessor.internal(this.helper, Token token, Expression receiver, |
644 Expression index, Procedure getter, Procedure setter) | 631 Expression index, Procedure getter, Procedure setter) |
645 : super.internal(helper, receiver, index, getter, setter, token); | 632 : super.internal(helper, receiver, index, getter, setter, token); |
646 | 633 |
647 String get plainNameForRead => "[]"; | 634 String get plainNameForRead => "[]"; |
648 | 635 |
649 String get plainNameForWrite => "[]="; | 636 String get plainNameForWrite => "[]="; |
650 | 637 |
651 Expression doInvocation(int offset, Arguments arguments) { | 638 Expression doInvocation(int offset, Arguments arguments) { |
652 return buildMethodInvocation( | 639 return buildMethodInvocation( |
653 helper.astFactory, buildSimpleRead(), callName, arguments, offset); | 640 buildSimpleRead(), callName, arguments, offset); |
654 } | 641 } |
655 | 642 |
656 toString() => "IndexAccessor()"; | 643 toString() => "IndexAccessor()"; |
657 | 644 |
658 static FastaAccessor make( | 645 static FastaAccessor make( |
659 BuilderHelper helper, | 646 BuilderHelper helper, |
660 Token token, | 647 Token token, |
661 Expression receiver, | 648 Expression receiver, |
662 Expression index, | 649 Expression index, |
663 Procedure getter, | 650 Procedure getter, |
(...skipping 12 matching lines...) Expand all Loading... |
676 | 663 |
677 PropertyAccessor.internal(this.helper, Token token, Expression receiver, | 664 PropertyAccessor.internal(this.helper, Token token, Expression receiver, |
678 Name name, Member getter, Member setter) | 665 Name name, Member getter, Member setter) |
679 : super.internal(helper, receiver, name, getter, setter, token); | 666 : super.internal(helper, receiver, name, getter, setter, token); |
680 | 667 |
681 String get plainNameForRead => name.name; | 668 String get plainNameForRead => name.name; |
682 | 669 |
683 bool get isThisPropertyAccessor => receiver is ThisExpression; | 670 bool get isThisPropertyAccessor => receiver is ThisExpression; |
684 | 671 |
685 Expression doInvocation(int offset, Arguments arguments) { | 672 Expression doInvocation(int offset, Arguments arguments) { |
686 return buildMethodInvocation( | 673 return buildMethodInvocation(receiver, name, arguments, offset); |
687 helper.astFactory, receiver, name, arguments, offset); | |
688 } | 674 } |
689 | 675 |
690 toString() => "PropertyAccessor()"; | 676 toString() => "PropertyAccessor()"; |
691 | 677 |
692 static FastaAccessor make( | 678 static FastaAccessor make( |
693 BuilderHelper helper, | 679 BuilderHelper helper, |
694 Token token, | 680 Token token, |
695 Expression receiver, | 681 Expression receiver, |
696 Name name, | 682 Name name, |
697 Member getter, | 683 Member getter, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 setter = builderSetter.target; | 720 setter = builderSetter.target; |
735 } | 721 } |
736 } | 722 } |
737 return new StaticAccessor(helper, token, getter, setter); | 723 return new StaticAccessor(helper, token, getter, setter); |
738 } | 724 } |
739 | 725 |
740 String get plainNameForRead => (readTarget ?? writeTarget).name.name; | 726 String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
741 | 727 |
742 Expression doInvocation(int offset, Arguments arguments) { | 728 Expression doInvocation(int offset, Arguments arguments) { |
743 if (readTarget == null || isFieldOrGetter(readTarget)) { | 729 if (readTarget == null || isFieldOrGetter(readTarget)) { |
744 return buildMethodInvocation(helper.astFactory, buildSimpleRead(), | 730 return buildMethodInvocation(buildSimpleRead(), callName, arguments, |
745 callName, arguments, offset + (readTarget?.name?.name?.length ?? 0)); | 731 offset + (readTarget?.name?.name?.length ?? 0)); |
746 } else { | 732 } else { |
747 return helper.buildStaticInvocation(readTarget, arguments) | 733 return helper.buildStaticInvocation(readTarget, arguments) |
748 ..fileOffset = offset; | 734 ..fileOffset = offset; |
749 } | 735 } |
750 } | 736 } |
751 | 737 |
752 toString() => "StaticAccessor()"; | 738 toString() => "StaticAccessor()"; |
753 } | 739 } |
754 | 740 |
755 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 741 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
756 with FastaAccessor { | 742 with FastaAccessor { |
757 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, | 743 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, |
758 Member getter, Member setter) | 744 Member getter, Member setter) |
759 : super(helper, name, getter, setter, token); | 745 : super(helper, name, getter, setter, token); |
760 | 746 |
761 String get plainNameForRead => name.name; | 747 String get plainNameForRead => name.name; |
762 | 748 |
763 Expression doInvocation(int offset, Arguments arguments) { | 749 Expression doInvocation(int offset, Arguments arguments) { |
764 if (getter == null || isFieldOrGetter(getter)) { | 750 if (getter == null || isFieldOrGetter(getter)) { |
765 return buildMethodInvocation( | 751 return buildMethodInvocation( |
766 helper.astFactory, buildSimpleRead(), callName, arguments, offset); | 752 buildSimpleRead(), callName, arguments, offset); |
767 } else { | 753 } else { |
768 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) | 754 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
769 ..fileOffset = offset; | 755 ..fileOffset = offset; |
770 } | 756 } |
771 } | 757 } |
772 | 758 |
773 toString() => "SuperPropertyAccessor()"; | 759 toString() => "SuperPropertyAccessor()"; |
774 } | 760 } |
775 | 761 |
776 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { | 762 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { |
777 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, | 763 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, |
778 Procedure getter, Procedure setter) | 764 Procedure getter, Procedure setter) |
779 : super(helper, index, getter, setter, token); | 765 : super(helper, index, getter, setter, token); |
780 | 766 |
781 String get plainNameForRead => "[]"; | 767 String get plainNameForRead => "[]"; |
782 | 768 |
783 String get plainNameForWrite => "[]="; | 769 String get plainNameForWrite => "[]="; |
784 | 770 |
785 Expression doInvocation(int offset, Arguments arguments) { | 771 Expression doInvocation(int offset, Arguments arguments) { |
786 return buildMethodInvocation( | 772 return buildMethodInvocation( |
787 helper.astFactory, buildSimpleRead(), callName, arguments, offset); | 773 buildSimpleRead(), callName, arguments, offset); |
788 } | 774 } |
789 | 775 |
790 toString() => "ThisIndexAccessor()"; | 776 toString() => "ThisIndexAccessor()"; |
791 } | 777 } |
792 | 778 |
793 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { | 779 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { |
794 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, | 780 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, |
795 Member getter, Member setter) | 781 Member getter, Member setter) |
796 : super(helper, index, getter, setter, token); | 782 : super(helper, index, getter, setter, token); |
797 | 783 |
798 String get plainNameForRead => "[]"; | 784 String get plainNameForRead => "[]"; |
799 | 785 |
800 String get plainNameForWrite => "[]="; | 786 String get plainNameForWrite => "[]="; |
801 | 787 |
802 Expression doInvocation(int offset, Arguments arguments) { | 788 Expression doInvocation(int offset, Arguments arguments) { |
803 return buildMethodInvocation( | 789 return buildMethodInvocation( |
804 helper.astFactory, buildSimpleRead(), callName, arguments, offset); | 790 buildSimpleRead(), callName, arguments, offset); |
805 } | 791 } |
806 | 792 |
807 toString() => "SuperIndexAccessor()"; | 793 toString() => "SuperIndexAccessor()"; |
808 } | 794 } |
809 | 795 |
810 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor | 796 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor |
811 with FastaAccessor { | 797 with FastaAccessor { |
812 final BuilderHelper helper; | 798 final BuilderHelper helper; |
813 | 799 |
814 ThisPropertyAccessor( | 800 ThisPropertyAccessor( |
815 this.helper, Token token, Name name, Member getter, Member setter) | 801 this.helper, Token token, Name name, Member getter, Member setter) |
816 : super(helper, name, getter, setter, token); | 802 : super(helper, name, getter, setter, token); |
817 | 803 |
818 String get plainNameForRead => name.name; | 804 String get plainNameForRead => name.name; |
819 | 805 |
820 bool get isThisPropertyAccessor => true; | 806 bool get isThisPropertyAccessor => true; |
821 | 807 |
822 Expression doInvocation(int offset, Arguments arguments) { | 808 Expression doInvocation(int offset, Arguments arguments) { |
823 Member interfaceTarget = getter; | 809 Member interfaceTarget = getter; |
824 if (interfaceTarget is Field) { | 810 if (interfaceTarget is Field) { |
825 // TODO(ahe): In strong mode we should probably rewrite this to | 811 // TODO(ahe): In strong mode we should probably rewrite this to |
826 // `this.name.call(arguments)`. | 812 // `this.name.call(arguments)`. |
827 interfaceTarget = null; | 813 interfaceTarget = null; |
828 } | 814 } |
829 return buildMethodInvocation( | 815 return buildMethodInvocation(new ThisExpression(), name, arguments, offset); |
830 helper.astFactory, new ThisExpression(), name, arguments, offset); | |
831 } | 816 } |
832 | 817 |
833 toString() => "ThisPropertyAccessor()"; | 818 toString() => "ThisPropertyAccessor()"; |
834 } | 819 } |
835 | 820 |
836 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor | 821 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor |
837 with FastaAccessor { | 822 with FastaAccessor { |
838 final BuilderHelper helper; | 823 final BuilderHelper helper; |
839 | 824 |
840 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, | 825 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, |
(...skipping 13 matching lines...) Expand all Loading... |
854 VariableAccessor( | 839 VariableAccessor( |
855 BuilderHelper helper, Token token, VariableDeclaration variable, | 840 BuilderHelper helper, Token token, VariableDeclaration variable, |
856 [DartType promotedType]) | 841 [DartType promotedType]) |
857 : super(helper, variable, promotedType, token); | 842 : super(helper, variable, promotedType, token); |
858 | 843 |
859 String get plainNameForRead => variable.name; | 844 String get plainNameForRead => variable.name; |
860 | 845 |
861 Expression doInvocation(int offset, Arguments arguments) { | 846 Expression doInvocation(int offset, Arguments arguments) { |
862 // Normally the offset is at the start of the token, but in this case, | 847 // Normally the offset is at the start of the token, but in this case, |
863 // because we insert a '.call', we want it at the end instead. | 848 // because we insert a '.call', we want it at the end instead. |
864 return buildMethodInvocation(helper.astFactory, buildSimpleRead(), callName, | 849 return buildMethodInvocation(buildSimpleRead(), callName, arguments, |
865 arguments, offset + (variable.name?.length ?? 0)); | 850 offset + (variable.name?.length ?? 0)); |
866 } | 851 } |
867 | 852 |
868 toString() => "VariableAccessor()"; | 853 toString() => "VariableAccessor()"; |
869 } | 854 } |
870 | 855 |
871 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { | 856 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { |
872 final String plainNameForRead; | 857 final String plainNameForRead; |
873 | 858 |
874 ReadOnlyAccessor(BuilderHelper helper, Expression expression, | 859 ReadOnlyAccessor(BuilderHelper helper, Expression expression, |
875 this.plainNameForRead, Token token) | 860 this.plainNameForRead, Token token) |
876 : super(helper, expression, token); | 861 : super(helper, expression, token); |
877 | 862 |
878 Expression doInvocation(int offset, Arguments arguments) { | 863 Expression doInvocation(int offset, Arguments arguments) { |
879 return buildMethodInvocation( | 864 return buildMethodInvocation( |
880 helper.astFactory, buildSimpleRead(), callName, arguments, offset); | 865 buildSimpleRead(), callName, arguments, offset); |
881 } | 866 } |
882 } | 867 } |
883 | 868 |
884 class ParenthesizedExpression extends ReadOnlyAccessor { | 869 class ParenthesizedExpression extends ReadOnlyAccessor { |
885 ParenthesizedExpression( | 870 ParenthesizedExpression( |
886 BuilderHelper helper, Expression expression, Token token) | 871 BuilderHelper helper, Expression expression, Token token) |
887 : super(helper, expression, "<a parenthesized expression>", token); | 872 : super(helper, expression, "<a parenthesized expression>", token); |
888 | 873 |
889 Expression makeInvalidWrite(Expression value) { | 874 Expression makeInvalidWrite(Expression value) { |
890 return helper.buildCompileTimeError( | 875 return helper.buildCompileTimeError( |
(...skipping 23 matching lines...) Expand all Loading... |
914 return helper.throwNoSuchMethodError( | 899 return helper.throwNoSuchMethodError( |
915 plainNameForRead, arguments, offset ?? offsetForToken(this.token), | 900 plainNameForRead, arguments, offset ?? offsetForToken(this.token), |
916 isGetter: isGetter, isSetter: isSetter); | 901 isGetter: isGetter, isSetter: isSetter); |
917 } | 902 } |
918 } | 903 } |
919 | 904 |
920 bool isFieldOrGetter(Member member) { | 905 bool isFieldOrGetter(Member member) { |
921 return member is Field || (member is Procedure && member.isGetter); | 906 return member is Field || (member is Procedure && member.isGetter); |
922 } | 907 } |
923 | 908 |
924 Expression buildMethodInvocation(AstFactory astFactory, Expression receiver, | 909 Expression buildMethodInvocation( |
925 Name name, Arguments arguments, int offset, | 910 Expression receiver, Name name, Arguments arguments, int offset, |
926 {bool isNullAware: false}) { | 911 {bool isNullAware: false}) { |
927 if (isNullAware) { | 912 if (isNullAware) { |
928 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); | 913 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); |
929 return makeLet( | 914 return makeLet( |
930 variable, | 915 variable, |
931 new ConditionalExpression( | 916 new ConditionalExpression( |
932 buildIsNull(astFactory, new VariableGet(variable)), | 917 buildIsNull(new VariableGet(variable)), |
933 new NullLiteral(), | 918 new NullLiteral(), |
934 astFactory.methodInvocation( | 919 new KernelMethodInvocation( |
935 new VariableGet(variable), name, arguments) | 920 new VariableGet(variable), name, arguments) |
936 ..fileOffset = offset, | 921 ..fileOffset = offset, |
937 const DynamicType())); | 922 const DynamicType())); |
938 } else { | 923 } else { |
939 return astFactory.methodInvocation(receiver, name, arguments) | 924 return new KernelMethodInvocation(receiver, name, arguments) |
940 ..fileOffset = offset; | 925 ..fileOffset = offset; |
941 } | 926 } |
942 } | 927 } |
OLD | NEW |