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

Side by Side Diff: lib/frontend/accessors.dart

Issue 2465263002: Always store the type of a conditional expression on the node. (Closed)
Patch Set: Update test expectation Created 4 years, 1 month 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 | « lib/ast.dart ('k') | lib/type_checker.dart » ('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 /// 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 library kernel.frontend.accessors; 7 library kernel.frontend.accessors;
8 8
9 import '../ast.dart'; 9 import '../ast.dart';
10 10
11 abstract class Accessor { 11 abstract class Accessor {
12 Expression buildSimpleRead() { 12 Expression buildSimpleRead() {
13 return _finish(_makeSimpleRead()); 13 return _finish(_makeSimpleRead());
14 } 14 }
15 15
16 /// Returns an assignment to the accessor. 16 /// Returns an assignment to the accessor.
17 /// 17 ///
18 /// The returned expression evaluates to the assigned value, unless 18 /// The returned expression evaluates to the assigned value, unless
19 /// [voidContext] is true, in which case it may evaluate to anything. 19 /// [voidContext] is true, in which case it may evaluate to anything.
20 Expression buildAssignment(Expression value, {bool voidContext: false}) { 20 Expression buildAssignment(Expression value, {bool voidContext: false}) {
21 return _finish(_makeSimpleWrite(value, voidContext)); 21 return _finish(_makeSimpleWrite(value, voidContext));
22 } 22 }
23 23
24 Expression buildNullAwareAssignment(Expression value, 24 Expression buildNullAwareAssignment(Expression value, DartType type,
25 {bool voidContext: false}) { 25 {bool voidContext: false}) {
26 if (voidContext) { 26 if (voidContext) {
27 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), 27 return _finish(new ConditionalExpression(buildIsNull(_makeRead()),
28 _makeWrite(value, voidContext), new NullLiteral())); 28 _makeWrite(value, voidContext), new NullLiteral(), type));
29 } 29 }
30 var tmp = new VariableDeclaration.forValue(_makeRead()); 30 var tmp = new VariableDeclaration.forValue(_makeRead());
31 return _finish(makeLet( 31 return _finish(makeLet(
32 tmp, 32 tmp,
33 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), 33 new ConditionalExpression(buildIsNull(new VariableGet(tmp)),
34 _makeWrite(value, voidContext), new VariableGet(tmp)))); 34 _makeWrite(value, voidContext), new VariableGet(tmp), type)));
35 } 35 }
36 36
37 Expression buildCompoundAssignment(Name binaryOperator, Expression value, 37 Expression buildCompoundAssignment(Name binaryOperator, Expression value,
38 {bool voidContext: false, Procedure interfaceTarget}) { 38 {bool voidContext: false, Procedure interfaceTarget}) {
39 return _finish(_makeWrite( 39 return _finish(_makeWrite(
40 makeBinary(_makeRead(), binaryOperator, interfaceTarget, value), 40 makeBinary(_makeRead(), binaryOperator, interfaceTarget, value),
41 voidContext)); 41 voidContext));
42 } 42 }
43 43
44 Expression buildPrefixIncrement(Name binaryOperator, 44 Expression buildPrefixIncrement(Name binaryOperator,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 _makeWrite(Expression value, bool voidContext) { 144 _makeWrite(Expression value, bool voidContext) {
145 return new PropertySet(new ThisExpression(), name, value, setter); 145 return new PropertySet(new ThisExpression(), name, value, setter);
146 } 146 }
147 } 147 }
148 148
149 class NullAwarePropertyAccessor extends Accessor { 149 class NullAwarePropertyAccessor extends Accessor {
150 VariableDeclaration receiver; 150 VariableDeclaration receiver;
151 Name name; 151 Name name;
152 Member getter, setter; 152 Member getter, setter;
153 DartType type;
153 154
154 NullAwarePropertyAccessor( 155 NullAwarePropertyAccessor(
155 Expression receiver, this.name, this.getter, this.setter) 156 Expression receiver, this.name, this.getter, this.setter, this.type)
156 : this.receiver = makeOrReuseVariable(receiver); 157 : this.receiver = makeOrReuseVariable(receiver);
157 158
158 receiverAccess() => new VariableGet(receiver); 159 receiverAccess() => new VariableGet(receiver);
159 160
160 _makeRead() => new PropertyGet(receiverAccess(), name, getter); 161 _makeRead() => new PropertyGet(receiverAccess(), name, getter);
161 162
162 _makeWrite(Expression value, bool voidContext) { 163 _makeWrite(Expression value, bool voidContext) {
163 return new PropertySet(receiverAccess(), name, value, setter); 164 return new PropertySet(receiverAccess(), name, value, setter);
164 } 165 }
165 166
166 _finish(Expression body) => makeLet( 167 _finish(Expression body) => makeLet(
167 receiver, 168 receiver,
168 new ConditionalExpression( 169 new ConditionalExpression(
169 buildIsNull(receiverAccess()), new NullLiteral(), body)); 170 buildIsNull(receiverAccess()), new NullLiteral(), body, type));
170 } 171 }
171 172
172 class SuperPropertyAccessor extends Accessor { 173 class SuperPropertyAccessor extends Accessor {
173 Name name; 174 Name name;
174 Member getter, setter; 175 Member getter, setter;
175 176
176 SuperPropertyAccessor(this.name, this.getter, this.setter); 177 SuperPropertyAccessor(this.name, this.getter, this.setter);
177 178
178 _makeRead() => new SuperPropertyGet(name, getter); 179 _makeRead() => new SuperPropertyGet(name, getter);
179 180
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 405
405 VariableDeclaration makeOrReuseVariable(Expression value) { 406 VariableDeclaration makeOrReuseVariable(Expression value) {
406 // TODO: Devise a way to remember if a variable declaration was reused 407 // TODO: Devise a way to remember if a variable declaration was reused
407 // or is fresh (hence needs a let binding). 408 // or is fresh (hence needs a let binding).
408 return new VariableDeclaration.forValue(value); 409 return new VariableDeclaration.forValue(value);
409 } 410 }
410 411
411 Expression wrapInvalid(Expression e) { 412 Expression wrapInvalid(Expression e) {
412 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); 413 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression());
413 } 414 }
OLDNEW
« no previous file with comments | « lib/ast.dart ('k') | lib/type_checker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698