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

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

Issue 2906253004: Avoid using Invalid{Statement,Expression,Initializer}. (Closed)
Patch Set: 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
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 /// 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,
11 KernelMethodInvocation, 11 KernelMethodInvocation,
12 KernelPropertyGet, 12 KernelPropertyGet,
13 KernelPropertySet, 13 KernelPropertySet,
14 KernelVariableGet, 14 KernelVariableGet,
15 KernelVariableSet; 15 KernelVariableSet;
16 16
17 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; 17 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken;
18 18
19 import 'package:front_end/src/scanner/token.dart' show Token; 19 import 'package:front_end/src/scanner/token.dart' show Token;
20 20
21 import 'package:front_end/src/fasta/kernel/fasta_accessors.dart' 21 import 'package:front_end/src/fasta/kernel/fasta_accessors.dart'
22 show BuilderHelper; 22 show BuilderHelper;
23 23
24 import 'package:kernel/ast.dart' hide MethodInvocation; 24 import 'package:kernel/ast.dart' hide MethodInvocation, InvalidExpression;
25 25
26 import '../names.dart' show equalsName, indexGetName, indexSetName; 26 import '../names.dart' show equalsName, indexGetName, indexSetName;
27 27
28 import '../errors.dart' show internalError;
29
28 /// An [Accessor] represents a subexpression for which we can't yet build a 30 /// An [Accessor] represents a subexpression for which we can't yet build a
29 /// kernel [Expression] because we don't yet know the context in which it is 31 /// kernel [Expression] because we don't yet know the context in which it is
30 /// used. 32 /// used.
31 /// 33 ///
32 /// Once the context is known, an [Accessor] can be converted into an 34 /// Once the context is known, an [Accessor] can be converted into an
33 /// [Expression] by calling a "build" method. 35 /// [Expression] by calling a "build" method.
34 /// 36 ///
35 /// For example, when building a kernel representation for `a[x] = b`, after 37 /// For example, when building a kernel representation for `a[x] = b`, after
36 /// parsing `a[x]` but before parsing `= b`, we don't yet know whether to 38 /// parsing `a[x]` but before parsing `= b`, we don't yet know whether to
37 /// generate an invocation of `operator[]` or `operator[]=`, so we generate an 39 /// generate an invocation of `operator[]` or `operator[]=`, so we generate an
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 131
130 Expression _makeRead(); 132 Expression _makeRead();
131 133
132 Expression _makeWrite(Expression value, bool voidContext); 134 Expression _makeWrite(Expression value, bool voidContext);
133 135
134 Expression _finish(Expression body) => body; 136 Expression _finish(Expression body) => body;
135 137
136 /// Returns an [Expression] representing a compile-time error. 138 /// Returns an [Expression] representing a compile-time error.
137 /// 139 ///
138 /// At runtime, an exception will be thrown. 140 /// At runtime, an exception will be thrown.
139 makeInvalidRead() => new InvalidExpression(); 141 makeInvalidRead() {
142 return internalError(
143 "Unhandled compile-time error.", null, offsetForToken(token));
144 }
140 145
141 /// Returns an [Expression] representing a compile-time error wrapping 146 /// Returns an [Expression] representing a compile-time error wrapping
142 /// [value]. 147 /// [value].
143 /// 148 ///
144 /// At runtime, [value] will be evaluated before throwing an exception. 149 /// At runtime, [value] will be evaluated before throwing an exception.
145 makeInvalidWrite(Expression value) => wrapInvalid(value); 150 makeInvalidWrite(Expression value) {
151 return internalError(
152 "Unhandled compile-time error.", null, offsetForToken(token));
153 }
146 } 154 }
147 155
148 abstract class VariableAccessor extends Accessor { 156 abstract class VariableAccessor extends Accessor {
149 VariableDeclaration variable; 157 VariableDeclaration variable;
150 DartType promotedType; 158 DartType promotedType;
151 159
152 VariableAccessor( 160 VariableAccessor(
153 BuilderHelper helper, this.variable, this.promotedType, Token token) 161 BuilderHelper helper, this.variable, this.promotedType, Token token)
154 : super(helper, token); 162 : super(helper, token);
155 163
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 531
524 Expression buildIsNull(Expression value, {int offset: TreeNode.noOffset}) { 532 Expression buildIsNull(Expression value, {int offset: TreeNode.noOffset}) {
525 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset); 533 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset);
526 } 534 }
527 535
528 VariableDeclaration makeOrReuseVariable(Expression value) { 536 VariableDeclaration makeOrReuseVariable(Expression value) {
529 // TODO: Devise a way to remember if a variable declaration was reused 537 // TODO: Devise a way to remember if a variable declaration was reused
530 // or is fresh (hence needs a let binding). 538 // or is fresh (hence needs a let binding).
531 return new VariableDeclaration.forValue(value); 539 return new VariableDeclaration.forValue(value);
532 } 540 }
533
534 Expression wrapInvalid(Expression e) {
535 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression());
536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698