| 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.builder_accessors; | 5 library fasta.builder_accessors; |
| 6 | 6 |
| 7 export 'frontend_accessors.dart' show wrapInvalid; | 7 export 'frontend_accessors.dart' show wrapInvalid; |
| 8 | 8 |
| 9 import 'frontend_accessors.dart' show Accessor; | 9 import 'frontend_accessors.dart' show Accessor; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 SuperPropertyAccessor, | 26 SuperPropertyAccessor, |
| 27 ThisIndexAccessor, | 27 ThisIndexAccessor, |
| 28 ThisPropertyAccessor, | 28 ThisPropertyAccessor, |
| 29 VariableAccessor; | 29 VariableAccessor; |
| 30 | 30 |
| 31 import 'frontend_accessors.dart' show buildIsNull, makeLet; | 31 import 'frontend_accessors.dart' show buildIsNull, makeLet; |
| 32 | 32 |
| 33 import 'kernel_builder.dart' | 33 import 'kernel_builder.dart' |
| 34 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder; | 34 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder; |
| 35 | 35 |
| 36 import '../names.dart' show callName; |
| 37 |
| 36 abstract class BuilderHelper { | 38 abstract class BuilderHelper { |
| 37 Uri get uri; | 39 Uri get uri; |
| 38 | 40 |
| 39 CoreTypes get coreTypes; | 41 CoreTypes get coreTypes; |
| 40 | 42 |
| 41 Constructor lookupConstructor(Name name, {bool isSuper}); | 43 Constructor lookupConstructor(Name name, {bool isSuper}); |
| 42 | 44 |
| 43 Expression toSuperMethodInvocation(MethodInvocation node); | 45 Expression toSuperMethodInvocation(MethodInvocation node); |
| 44 | 46 |
| 45 Expression toValue(node); | 47 Expression toValue(node); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 helper, send.charOffset, send.name, null, null); | 226 helper, send.charOffset, send.name, null, null); |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 } | 229 } |
| 228 | 230 |
| 229 doInvocation(int charOffset, Arguments arguments) { | 231 doInvocation(int charOffset, Arguments arguments) { |
| 230 if (isInitializer) { | 232 if (isInitializer) { |
| 231 return buildConstructorInitializer(charOffset, new Name(""), arguments); | 233 return buildConstructorInitializer(charOffset, new Name(""), arguments); |
| 232 } else { | 234 } else { |
| 233 return buildMethodInvocation( | 235 return buildMethodInvocation( |
| 234 new ThisExpression(), new Name("call"), arguments, charOffset); | 236 new ThisExpression(), callName, arguments, charOffset); |
| 235 } | 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 Initializer buildConstructorInitializer( | 240 Initializer buildConstructorInitializer( |
| 239 int charOffset, Name name, Arguments arguments) { | 241 int charOffset, Name name, Arguments arguments) { |
| 240 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 242 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
| 241 Initializer result; | 243 Initializer result; |
| 242 if (constructor == null) { | 244 if (constructor == null) { |
| 243 result = new LocalInitializer(new VariableDeclaration.forValue( | 245 result = new LocalInitializer(new VariableDeclaration.forValue( |
| 244 throwNoSuchMethodError( | 246 throwNoSuchMethodError( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 Builder builder = receiver.findStaticBuilder(name.name, charOffset, uri); | 349 Builder builder = receiver.findStaticBuilder(name.name, charOffset, uri); |
| 348 if (builder == null) { | 350 if (builder == null) { |
| 349 return buildThrowNoSuchMethodError(arguments); | 351 return buildThrowNoSuchMethodError(arguments); |
| 350 } | 352 } |
| 351 if (builder.hasProblem) { | 353 if (builder.hasProblem) { |
| 352 result = helper.buildProblemExpression(builder, charOffset); | 354 result = helper.buildProblemExpression(builder, charOffset); |
| 353 } else { | 355 } else { |
| 354 Member target = builder.target; | 356 Member target = builder.target; |
| 355 if (target != null) { | 357 if (target != null) { |
| 356 if (target is Field) { | 358 if (target is Field) { |
| 357 result = buildMethodInvocation( | 359 result = buildMethodInvocation(new StaticGet(target), callName, |
| 358 new StaticGet(target), | 360 arguments, charOffset + (target.name?.name?.length ?? 0), |
| 359 new Name("call"), | |
| 360 arguments, | |
| 361 charOffset + (target.name?.name?.length ?? 0), | |
| 362 isNullAware: isNullAware); | 361 isNullAware: isNullAware); |
| 363 } else { | 362 } else { |
| 364 result = helper.buildStaticInvocation(target, arguments) | 363 result = helper.buildStaticInvocation(target, arguments) |
| 365 ..fileOffset = charOffset; | 364 ..fileOffset = charOffset; |
| 366 } | 365 } |
| 367 } else { | 366 } else { |
| 368 result = buildThrowNoSuchMethodError(arguments) | 367 result = buildThrowNoSuchMethodError(arguments) |
| 369 ..fileOffset = charOffset; | 368 ..fileOffset = charOffset; |
| 370 } | 369 } |
| 371 } | 370 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 IndexAccessor.internal(this.helper, int charOffset, Expression receiver, | 487 IndexAccessor.internal(this.helper, int charOffset, Expression receiver, |
| 489 Expression index, Procedure getter, Procedure setter) | 488 Expression index, Procedure getter, Procedure setter) |
| 490 : super.internal(receiver, index, getter, setter, charOffset); | 489 : super.internal(receiver, index, getter, setter, charOffset); |
| 491 | 490 |
| 492 String get plainNameForRead => "[]"; | 491 String get plainNameForRead => "[]"; |
| 493 | 492 |
| 494 String get plainNameForWrite => "[]="; | 493 String get plainNameForWrite => "[]="; |
| 495 | 494 |
| 496 Expression doInvocation(int charOffset, Arguments arguments) { | 495 Expression doInvocation(int charOffset, Arguments arguments) { |
| 497 return buildMethodInvocation( | 496 return buildMethodInvocation( |
| 498 buildSimpleRead(), new Name("call"), arguments, charOffset); | 497 buildSimpleRead(), callName, arguments, charOffset); |
| 499 } | 498 } |
| 500 | 499 |
| 501 toString() => "IndexAccessor()"; | 500 toString() => "IndexAccessor()"; |
| 502 | 501 |
| 503 static BuilderAccessor make( | 502 static BuilderAccessor make( |
| 504 BuilderHelper helper, | 503 BuilderHelper helper, |
| 505 int charOffset, | 504 int charOffset, |
| 506 Expression receiver, | 505 Expression receiver, |
| 507 Expression index, | 506 Expression index, |
| 508 Procedure getter, | 507 Procedure getter, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 setter = builderSetter.target; | 579 setter = builderSetter.target; |
| 581 } | 580 } |
| 582 } | 581 } |
| 583 return new StaticAccessor(helper, charOffset, getter, setter); | 582 return new StaticAccessor(helper, charOffset, getter, setter); |
| 584 } | 583 } |
| 585 | 584 |
| 586 String get plainNameForRead => (readTarget ?? writeTarget).name.name; | 585 String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
| 587 | 586 |
| 588 Expression doInvocation(int charOffset, Arguments arguments) { | 587 Expression doInvocation(int charOffset, Arguments arguments) { |
| 589 if (readTarget == null || isFieldOrGetter(readTarget)) { | 588 if (readTarget == null || isFieldOrGetter(readTarget)) { |
| 590 return buildMethodInvocation(buildSimpleRead(), new Name("call"), | 589 return buildMethodInvocation(buildSimpleRead(), callName, arguments, |
| 591 arguments, charOffset + (readTarget?.name?.name?.length ?? 0)); | 590 charOffset + (readTarget?.name?.name?.length ?? 0)); |
| 592 } else { | 591 } else { |
| 593 return helper.buildStaticInvocation(readTarget, arguments) | 592 return helper.buildStaticInvocation(readTarget, arguments) |
| 594 ..fileOffset = charOffset; | 593 ..fileOffset = charOffset; |
| 595 } | 594 } |
| 596 } | 595 } |
| 597 | 596 |
| 598 toString() => "StaticAccessor()"; | 597 toString() => "StaticAccessor()"; |
| 599 } | 598 } |
| 600 | 599 |
| 601 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 600 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
| 602 with BuilderAccessor { | 601 with BuilderAccessor { |
| 603 final BuilderHelper helper; | 602 final BuilderHelper helper; |
| 604 | 603 |
| 605 SuperPropertyAccessor( | 604 SuperPropertyAccessor( |
| 606 this.helper, int charOffset, Name name, Member getter, Member setter) | 605 this.helper, int charOffset, Name name, Member getter, Member setter) |
| 607 : super(name, getter, setter, charOffset); | 606 : super(name, getter, setter, charOffset); |
| 608 | 607 |
| 609 String get plainNameForRead => name.name; | 608 String get plainNameForRead => name.name; |
| 610 | 609 |
| 611 Expression doInvocation(int charOffset, Arguments arguments) { | 610 Expression doInvocation(int charOffset, Arguments arguments) { |
| 612 if (getter == null || isFieldOrGetter(getter)) { | 611 if (getter == null || isFieldOrGetter(getter)) { |
| 613 return buildMethodInvocation( | 612 return buildMethodInvocation( |
| 614 buildSimpleRead(), new Name("call"), arguments, charOffset); | 613 buildSimpleRead(), callName, arguments, charOffset); |
| 615 } else { | 614 } else { |
| 616 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) | 615 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
| 617 ..fileOffset = charOffset; | 616 ..fileOffset = charOffset; |
| 618 } | 617 } |
| 619 } | 618 } |
| 620 | 619 |
| 621 toString() => "SuperPropertyAccessor()"; | 620 toString() => "SuperPropertyAccessor()"; |
| 622 } | 621 } |
| 623 | 622 |
| 624 class ThisIndexAccessor extends kernel.ThisIndexAccessor with BuilderAccessor { | 623 class ThisIndexAccessor extends kernel.ThisIndexAccessor with BuilderAccessor { |
| 625 final BuilderHelper helper; | 624 final BuilderHelper helper; |
| 626 | 625 |
| 627 final int charOffset; | 626 final int charOffset; |
| 628 | 627 |
| 629 ThisIndexAccessor(this.helper, this.charOffset, Expression index, | 628 ThisIndexAccessor(this.helper, this.charOffset, Expression index, |
| 630 Procedure getter, Procedure setter) | 629 Procedure getter, Procedure setter) |
| 631 : super(index, getter, setter); | 630 : super(index, getter, setter); |
| 632 | 631 |
| 633 String get plainNameForRead => "[]"; | 632 String get plainNameForRead => "[]"; |
| 634 | 633 |
| 635 String get plainNameForWrite => "[]="; | 634 String get plainNameForWrite => "[]="; |
| 636 | 635 |
| 637 Expression doInvocation(int charOffset, Arguments arguments) { | 636 Expression doInvocation(int charOffset, Arguments arguments) { |
| 638 return buildMethodInvocation( | 637 return buildMethodInvocation( |
| 639 buildSimpleRead(), new Name("call"), arguments, charOffset); | 638 buildSimpleRead(), callName, arguments, charOffset); |
| 640 } | 639 } |
| 641 | 640 |
| 642 toString() => "ThisIndexAccessor()"; | 641 toString() => "ThisIndexAccessor()"; |
| 643 } | 642 } |
| 644 | 643 |
| 645 class SuperIndexAccessor extends kernel.SuperIndexAccessor | 644 class SuperIndexAccessor extends kernel.SuperIndexAccessor |
| 646 with BuilderAccessor { | 645 with BuilderAccessor { |
| 647 final BuilderHelper helper; | 646 final BuilderHelper helper; |
| 648 | 647 |
| 649 final int charOffset; | 648 final int charOffset; |
| 650 | 649 |
| 651 SuperIndexAccessor(this.helper, this.charOffset, Expression index, | 650 SuperIndexAccessor(this.helper, this.charOffset, Expression index, |
| 652 Member getter, Member setter) | 651 Member getter, Member setter) |
| 653 : super(index, getter, setter); | 652 : super(index, getter, setter); |
| 654 | 653 |
| 655 String get plainNameForRead => "[]"; | 654 String get plainNameForRead => "[]"; |
| 656 | 655 |
| 657 String get plainNameForWrite => "[]="; | 656 String get plainNameForWrite => "[]="; |
| 658 | 657 |
| 659 Expression doInvocation(int charOffset, Arguments arguments) { | 658 Expression doInvocation(int charOffset, Arguments arguments) { |
| 660 return buildMethodInvocation( | 659 return buildMethodInvocation( |
| 661 buildSimpleRead(), new Name("call"), arguments, charOffset); | 660 buildSimpleRead(), callName, arguments, charOffset); |
| 662 } | 661 } |
| 663 | 662 |
| 664 toString() => "SuperIndexAccessor()"; | 663 toString() => "SuperIndexAccessor()"; |
| 665 } | 664 } |
| 666 | 665 |
| 667 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor | 666 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor |
| 668 with BuilderAccessor { | 667 with BuilderAccessor { |
| 669 final BuilderHelper helper; | 668 final BuilderHelper helper; |
| 670 | 669 |
| 671 ThisPropertyAccessor( | 670 ThisPropertyAccessor( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 713 |
| 715 VariableAccessor(this.helper, int charOffset, VariableDeclaration variable, | 714 VariableAccessor(this.helper, int charOffset, VariableDeclaration variable, |
| 716 [DartType promotedType]) | 715 [DartType promotedType]) |
| 717 : super.internal(variable, charOffset, promotedType); | 716 : super.internal(variable, charOffset, promotedType); |
| 718 | 717 |
| 719 String get plainNameForRead => variable.name; | 718 String get plainNameForRead => variable.name; |
| 720 | 719 |
| 721 Expression doInvocation(int charOffset, Arguments arguments) { | 720 Expression doInvocation(int charOffset, Arguments arguments) { |
| 722 // Normally the offset is at the start of the token, but in this case, | 721 // Normally the offset is at the start of the token, but in this case, |
| 723 // because we insert a '.call', we want it at the end instead. | 722 // because we insert a '.call', we want it at the end instead. |
| 724 return buildMethodInvocation(buildSimpleRead(), new Name("call"), arguments, | 723 return buildMethodInvocation(buildSimpleRead(), callName, arguments, |
| 725 charOffset + (variable.name?.length ?? 0)); | 724 charOffset + (variable.name?.length ?? 0)); |
| 726 } | 725 } |
| 727 | 726 |
| 728 toString() => "VariableAccessor()"; | 727 toString() => "VariableAccessor()"; |
| 729 } | 728 } |
| 730 | 729 |
| 731 Expression throwNoSuchMethodError(String name, Arguments arguments, Uri uri, | 730 Expression throwNoSuchMethodError(String name, Arguments arguments, Uri uri, |
| 732 int charOffset, CoreTypes coreTypes, | 731 int charOffset, CoreTypes coreTypes, |
| 733 {bool isSuper: false, isGetter: false, isSetter: false}) { | 732 {bool isSuper: false, isGetter: false, isSetter: false}) { |
| 734 String errorName = name; | 733 String errorName = name; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 buildIsNull(new VariableGet(variable)), | 771 buildIsNull(new VariableGet(variable)), |
| 773 new NullLiteral(), | 772 new NullLiteral(), |
| 774 new MethodInvocation(new VariableGet(variable), name, arguments) | 773 new MethodInvocation(new VariableGet(variable), name, arguments) |
| 775 ..fileOffset = charOffset, | 774 ..fileOffset = charOffset, |
| 776 const DynamicType())); | 775 const DynamicType())); |
| 777 } else { | 776 } else { |
| 778 return new MethodInvocation(receiver, name, arguments) | 777 return new MethodInvocation(receiver, name, arguments) |
| 779 ..fileOffset = charOffset; | 778 ..fileOffset = charOffset; |
| 780 } | 779 } |
| 781 } | 780 } |
| OLD | NEW |