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

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

Issue 2780483002: Complain about assignments to parenthesized expressions. (Closed)
Patch Set: Created 3 years, 8 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
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 export 'package:kernel/frontend/accessors.dart' show wrapInvalid; 7 export 'package:kernel/frontend/accessors.dart' show wrapInvalid;
8 8
9 import 'package:kernel/frontend/accessors.dart' 9 import 'package:kernel/frontend/accessors.dart'
10 show Accessor, buildIsNull, makeLet; 10 show Accessor, buildIsNull, makeLet;
11 11
12 import 'package:kernel/ast.dart'; 12 import 'package:kernel/ast.dart';
13 13
14 import '../errors.dart' show internalError; 14 import '../errors.dart' show internalError;
15 15
16 import '../builder/scope.dart' show AccessErrorBuilder, ProblemBuilder; 16 import '../builder/scope.dart' show AccessErrorBuilder, ProblemBuilder;
17 17
18 import 'package:kernel/frontend/accessors.dart' as kernel 18 import 'package:kernel/frontend/accessors.dart' as kernel
19 show 19 show
20 IndexAccessor, 20 IndexAccessor,
21 NullAwarePropertyAccessor, 21 NullAwarePropertyAccessor,
22 PropertyAccessor, 22 PropertyAccessor,
23 ReadOnlyAccessor,
23 StaticAccessor, 24 StaticAccessor,
24 SuperIndexAccessor, 25 SuperIndexAccessor,
25 SuperPropertyAccessor, 26 SuperPropertyAccessor,
26 ThisIndexAccessor, 27 ThisIndexAccessor,
27 ThisPropertyAccessor, 28 ThisPropertyAccessor,
28 VariableAccessor; 29 VariableAccessor;
29 30
30 import 'kernel_builder.dart' 31 import 'kernel_builder.dart'
31 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder; 32 show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder;
32 33
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 Expression doInvocation(int offset, Arguments arguments) { 769 Expression doInvocation(int offset, Arguments arguments) {
769 // Normally the offset is at the start of the token, but in this case, 770 // Normally the offset is at the start of the token, but in this case,
770 // because we insert a '.call', we want it at the end instead. 771 // because we insert a '.call', we want it at the end instead.
771 return buildMethodInvocation(buildSimpleRead(), callName, arguments, 772 return buildMethodInvocation(buildSimpleRead(), callName, arguments,
772 offset + (variable.name?.length ?? 0)); 773 offset + (variable.name?.length ?? 0));
773 } 774 }
774 775
775 toString() => "VariableAccessor()"; 776 toString() => "VariableAccessor()";
776 } 777 }
777 778
779 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor {
780 final BuilderHelper helper;
781
782 final String plainNameForRead;
783
784 ReadOnlyAccessor(
785 this.helper, Expression expression, this.plainNameForRead, int offset)
786 : super(expression, offset);
787
788 Expression doInvocation(int offset, Arguments arguments) {
789 return buildMethodInvocation(
790 buildSimpleRead(), callName, arguments, offset);
791 }
792 }
793
794 class ParenthesizedExpression extends ReadOnlyAccessor {
795 ParenthesizedExpression(
796 BuilderHelper helper, Expression expression, int offset)
797 : super(helper, expression, "<a parenthesized expression>", offset);
798
799 Expression makeInvalidWrite(Expression value) {
800 return helper.buildCompileTimeError(
801 "Can't assign to a parenthesized expression.", offset);
802 }
803 }
804
778 bool isFieldOrGetter(Member member) { 805 bool isFieldOrGetter(Member member) {
779 return member is Field || (member is Procedure && member.isGetter); 806 return member is Field || (member is Procedure && member.isGetter);
780 } 807 }
781 808
782 Expression buildMethodInvocation( 809 Expression buildMethodInvocation(
783 Expression receiver, Name name, Arguments arguments, int offset, 810 Expression receiver, Name name, Arguments arguments, int offset,
784 {bool isNullAware: false}) { 811 {bool isNullAware: false}) {
785 if (isNullAware) { 812 if (isNullAware) {
786 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); 813 VariableDeclaration variable = new VariableDeclaration.forValue(receiver);
787 return makeLet( 814 return makeLet(
788 variable, 815 variable,
789 new ConditionalExpression( 816 new ConditionalExpression(
790 buildIsNull(new VariableGet(variable)), 817 buildIsNull(new VariableGet(variable)),
791 new NullLiteral(), 818 new NullLiteral(),
792 new MethodInvocation(new VariableGet(variable), name, arguments) 819 new MethodInvocation(new VariableGet(variable), name, arguments)
793 ..fileOffset = offset, 820 ..fileOffset = offset,
794 const DynamicType())); 821 const DynamicType()));
795 } else { 822 } else {
796 return new MethodInvocation(receiver, name, arguments)..fileOffset = offset; 823 return new MethodInvocation(receiver, name, arguments)..fileOffset = offset;
797 } 824 }
798 } 825 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/parser/token_stream_rewriter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698