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

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

Issue 2911023002: Various checks for constant expressions. (Closed)
Patch Set: Remove unneeded check. 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
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | tests/co19/co19-kernel.status » ('j') | 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 4
5 library fasta.fasta_accessors; 5 library fasta.fasta_accessors;
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 KernelArguments; 8 show KernelArguments;
9 9
10 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; 10 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken;
(...skipping 21 matching lines...) Expand all
32 StaticAccessor, 32 StaticAccessor,
33 SuperIndexAccessor, 33 SuperIndexAccessor,
34 SuperPropertyAccessor, 34 SuperPropertyAccessor,
35 ThisIndexAccessor, 35 ThisIndexAccessor,
36 ThisPropertyAccessor, 36 ThisPropertyAccessor,
37 VariableAccessor; 37 VariableAccessor;
38 38
39 import 'kernel_builder.dart' 39 import 'kernel_builder.dart'
40 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder; 40 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder;
41 41
42 import '../names.dart' show callName; 42 import '../names.dart' show callName, lengthName;
43 43
44 abstract class BuilderHelper { 44 abstract class BuilderHelper {
45 Uri get uri; 45 Uri get uri;
46 46
47 TypePromoter get typePromoter; 47 TypePromoter get typePromoter;
48 48
49 int get functionNestingLevel; 49 int get functionNestingLevel;
50 50
51 bool get constantExpressionRequired; 51 bool get constantExpressionRequired;
52 52
(...skipping 30 matching lines...) Expand all
83 String name, Arguments arguments, int offset, 83 String name, Arguments arguments, int offset,
84 {bool isSuper, bool isGetter, bool isSetter}); 84 {bool isSuper, bool isGetter, bool isSetter});
85 85
86 bool checkArguments(FunctionNode function, Arguments arguments, 86 bool checkArguments(FunctionNode function, Arguments arguments,
87 List<TypeParameter> typeParameters); 87 List<TypeParameter> typeParameters);
88 88
89 StaticGet makeStaticGet(Member readTarget, Token token); 89 StaticGet makeStaticGet(Member readTarget, Token token);
90 90
91 dynamic addCompileTimeError(int charOffset, String message, {bool silent}); 91 dynamic addCompileTimeError(int charOffset, String message, {bool silent});
92 92
93 bool isIdentical(Member member);
94
93 Expression buildMethodInvocation( 95 Expression buildMethodInvocation(
94 Expression receiver, Name name, Arguments arguments, int offset, 96 Expression receiver, Name name, Arguments arguments, int offset,
95 {bool isConstantExpression, bool isNullAware}); 97 {bool isConstantExpression, bool isNullAware});
96 } 98 }
97 99
98 abstract class FastaAccessor implements Accessor { 100 abstract class FastaAccessor implements Accessor {
99 BuilderHelper get helper; 101 BuilderHelper get helper;
100 102
101 String get plainNameForRead; 103 String get plainNameForRead;
102 104
(...skipping 28 matching lines...) Expand all
131 /* Expression | FastaAccessor | Initializer */ doInvocation( 133 /* Expression | FastaAccessor | Initializer */ doInvocation(
132 int offset, Arguments arguments); 134 int offset, Arguments arguments);
133 135
134 /* Expression | FastaAccessor */ buildPropertyAccess( 136 /* Expression | FastaAccessor */ buildPropertyAccess(
135 IncompleteSend send, bool isNullAware) { 137 IncompleteSend send, bool isNullAware) {
136 if (send is SendAccessor) { 138 if (send is SendAccessor) {
137 return helper.buildMethodInvocation(buildSimpleRead(), send.name, 139 return helper.buildMethodInvocation(buildSimpleRead(), send.name,
138 send.arguments, offsetForToken(send.token), 140 send.arguments, offsetForToken(send.token),
139 isNullAware: isNullAware); 141 isNullAware: isNullAware);
140 } else { 142 } else {
143 if (helper.constantExpressionRequired && send.name != lengthName) {
144 helper.addCompileTimeError(
145 offsetForToken(token), "Not a constant expression.");
146 }
141 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), 147 return PropertyAccessor.make(helper, send.token, buildSimpleRead(),
142 send.name, null, null, isNullAware); 148 send.name, null, null, isNullAware);
143 } 149 }
144 } 150 }
145 151
146 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( 152 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError(
147 Arguments arguments, 153 Arguments arguments,
148 {bool isSuper: false, 154 {bool isSuper: false,
149 bool isGetter: false, 155 bool isGetter: false,
150 bool isSetter: false, 156 bool isSetter: false,
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (builderSetter?.target?.hasSetter ?? false) { 691 if (builderSetter?.target?.hasSetter ?? false) {
686 setter = builderSetter.target; 692 setter = builderSetter.target;
687 } 693 }
688 } 694 }
689 return new StaticAccessor(helper, token, getter, setter); 695 return new StaticAccessor(helper, token, getter, setter);
690 } 696 }
691 697
692 String get plainNameForRead => (readTarget ?? writeTarget).name.name; 698 String get plainNameForRead => (readTarget ?? writeTarget).name.name;
693 699
694 Expression doInvocation(int offset, Arguments arguments) { 700 Expression doInvocation(int offset, Arguments arguments) {
701 if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) {
702 helper.addCompileTimeError(offset, "Not a constant expression.");
703 }
695 if (readTarget == null || isFieldOrGetter(readTarget)) { 704 if (readTarget == null || isFieldOrGetter(readTarget)) {
696 return helper.buildMethodInvocation(buildSimpleRead(), callName, 705 return helper.buildMethodInvocation(buildSimpleRead(), callName,
697 arguments, offset + (readTarget?.name?.name?.length ?? 0)); 706 arguments, offset + (readTarget?.name?.name?.length ?? 0),
707 // This isn't a constant expression, but we have checked if a
708 // constant expression error should be emitted already.
709 isConstantExpression: true);
698 } else { 710 } else {
699 return helper.buildStaticInvocation(readTarget, arguments) 711 return helper.buildStaticInvocation(readTarget, arguments)
700 ..fileOffset = offset; 712 ..fileOffset = offset;
701 } 713 }
702 } 714 }
703 715
704 toString() => "StaticAccessor()"; 716 toString() => "StaticAccessor()";
705 } 717 }
706 718
707 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor 719 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor
708 with FastaAccessor { 720 with FastaAccessor {
709 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, 721 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name,
710 Member getter, Member setter) 722 Member getter, Member setter)
711 : super(helper, name, getter, setter, token); 723 : super(helper, name, getter, setter, token);
712 724
713 String get plainNameForRead => name.name; 725 String get plainNameForRead => name.name;
714 726
715 Expression doInvocation(int offset, Arguments arguments) { 727 Expression doInvocation(int offset, Arguments arguments) {
728 if (helper.constantExpressionRequired) {
729 helper.addCompileTimeError(offset, "Not a constant expression.");
730 }
716 if (getter == null || isFieldOrGetter(getter)) { 731 if (getter == null || isFieldOrGetter(getter)) {
717 return helper.buildMethodInvocation( 732 return helper.buildMethodInvocation(
718 buildSimpleRead(), callName, arguments, offset); 733 buildSimpleRead(), callName, arguments, offset,
734 // This isn't a constant expression, but we have checked if a
735 // constant expression error should be emitted already.
736 isConstantExpression: true);
719 } else { 737 } else {
720 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) 738 return new DirectMethodInvocation(new ThisExpression(), getter, arguments)
721 ..fileOffset = offset; 739 ..fileOffset = offset;
722 } 740 }
723 } 741 }
724 742
725 toString() => "SuperPropertyAccessor()"; 743 toString() => "SuperPropertyAccessor()";
726 } 744 }
727 745
728 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { 746 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 {bool isGetter: false, bool isSetter: false, int offset}) { 883 {bool isGetter: false, bool isSetter: false, int offset}) {
866 return helper.throwNoSuchMethodError( 884 return helper.throwNoSuchMethodError(
867 plainNameForRead, arguments, offset ?? offsetForToken(this.token), 885 plainNameForRead, arguments, offset ?? offsetForToken(this.token),
868 isGetter: isGetter, isSetter: isSetter); 886 isGetter: isGetter, isSetter: isSetter);
869 } 887 }
870 } 888 }
871 889
872 bool isFieldOrGetter(Member member) { 890 bool isFieldOrGetter(Member member) {
873 return member is Field || (member is Procedure && member.isGetter); 891 return member is Field || (member is Procedure && member.isGetter);
874 } 892 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698