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 /// 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 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return builtGetter = new MethodInvocation(receiverAccess(), _indexGet, | 248 return builtGetter = new MethodInvocation(receiverAccess(), _indexGet, |
249 new Arguments(<Expression>[indexAccess()]), getter); | 249 new Arguments(<Expression>[indexAccess()]), getter); |
250 } | 250 } |
251 | 251 |
252 _makeWrite(Expression value, bool voidContext) { | 252 _makeWrite(Expression value, bool voidContext) { |
253 if (!voidContext) return _makeWriteAndReturn(value); | 253 if (!voidContext) return _makeWriteAndReturn(value); |
254 return new MethodInvocation(receiverAccess(), _indexSet, | 254 return new MethodInvocation(receiverAccess(), _indexSet, |
255 new Arguments(<Expression>[indexAccess(), value]), setter); | 255 new Arguments(<Expression>[indexAccess(), value]), setter); |
256 } | 256 } |
257 | 257 |
| 258 // TODO(dmitryas): remove this method after the "[]=" operator of the Context |
| 259 // class is made to return a value. |
258 _makeWriteAndReturn(Expression value) { | 260 _makeWriteAndReturn(Expression value) { |
259 // The call to []= does not return the value like direct-style assignments | 261 // The call to []= does not return the value like direct-style assignments |
260 // do. We need to bind the value in a let. | 262 // do. We need to bind the value in a let. |
261 var valueVariable = new VariableDeclaration.forValue(value); | 263 var valueVariable = new VariableDeclaration.forValue(value); |
262 var dummy = new VariableDeclaration.forValue(new MethodInvocation( | 264 var dummy = new VariableDeclaration.forValue(new MethodInvocation( |
263 receiverAccess(), | 265 receiverAccess(), |
264 _indexSet, | 266 _indexSet, |
265 new Arguments( | 267 new Arguments( |
266 <Expression>[indexAccess(), new VariableGet(valueVariable)]), | 268 <Expression>[indexAccess(), new VariableGet(valueVariable)]), |
267 setter)); | 269 setter)); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 429 |
428 VariableDeclaration makeOrReuseVariable(Expression value) { | 430 VariableDeclaration makeOrReuseVariable(Expression value) { |
429 // TODO: Devise a way to remember if a variable declaration was reused | 431 // TODO: Devise a way to remember if a variable declaration was reused |
430 // or is fresh (hence needs a let binding). | 432 // or is fresh (hence needs a let binding). |
431 return new VariableDeclaration.forValue(value); | 433 return new VariableDeclaration.forValue(value); |
432 } | 434 } |
433 | 435 |
434 Expression wrapInvalid(Expression e) { | 436 Expression wrapInvalid(Expression e) { |
435 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 437 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
436 } | 438 } |
OLD | NEW |