Chromium Code Reviews| 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 // Note: copied from package:kernel at revision 7346348. | 5 // Note: copied from package:kernel at revision 7346348. |
| 6 | 6 |
| 7 /// A library to help transform compounds and null-aware accessors into | 7 /// A library to help transform compounds and null-aware accessors into |
| 8 /// let expressions. | 8 /// let expressions. |
| 9 library kernel.frontend.accessors; | 9 library kernel.frontend.accessors; |
| 10 | 10 |
| 11 import 'package:kernel/ast.dart'; | 11 import 'package:kernel/ast.dart'; |
| 12 | 12 |
| 13 abstract class Accessor { | 13 abstract class Accessor { |
| 14 Expression buildSimpleRead() { | 14 Expression buildSimpleRead() { |
| 15 return _finish(_makeSimpleRead()); | 15 return _finish(_makeSimpleRead()); |
| 16 } | 16 } |
| 17 | 17 |
| 18 /// Returns an assignment to the accessor. | 18 /// Returns an assignment to the accessor. |
| 19 /// | 19 /// |
| 20 /// The returned expression evaluates to the assigned value, unless | 20 /// The returned expression evaluates to the assigned value, unless |
| 21 /// [voidContext] is true, in which case it may evaluate to anything. | 21 /// [voidContext] is true, in which case it may evaluate to anything. |
| 22 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 22 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
| 23 return _finish(_makeSimpleWrite(value, voidContext)); | 23 return _finish(_makeSimpleWrite(value, voidContext)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 Expression buildNullAwareAssignment(Expression value, DartType type, | 26 Expression buildNullAwareAssignment(Expression value, DartType type, |
| 27 {bool voidContext: false}) { | 27 {bool voidContext: false}) { |
| 28 if (voidContext) { | 28 if (voidContext) { |
| 29 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), | 29 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), |
| 30 _makeWrite(value, voidContext), new NullLiteral(), type)); | 30 _makeWrite(value, false), new NullLiteral(), type)); |
|
ahe
2017/02/01 14:02:38
I think this hits more cases than you expect, so I
kustermann
2017/02/01 14:23:42
The result of _makeWrite() is used, namely in a Co
ahe
2017/02/01 14:33:16
I was wrong. Thank's for clarifying.
| |
| 31 } | 31 } |
| 32 var tmp = new VariableDeclaration.forValue(_makeRead()); | 32 var tmp = new VariableDeclaration.forValue(_makeRead()); |
| 33 return _finish(makeLet( | 33 return _finish(makeLet( |
| 34 tmp, | 34 tmp, |
| 35 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), | 35 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), |
| 36 _makeWrite(value, voidContext), new VariableGet(tmp), type))); | 36 _makeWrite(value, false), new VariableGet(tmp), type))); |
| 37 } | 37 } |
| 38 | 38 |
| 39 Expression buildCompoundAssignment(Name binaryOperator, Expression value, | 39 Expression buildCompoundAssignment(Name binaryOperator, Expression value, |
| 40 {bool voidContext: false, Procedure interfaceTarget}) { | 40 {bool voidContext: false, Procedure interfaceTarget}) { |
| 41 return _finish(_makeWrite( | 41 return _finish(_makeWrite( |
| 42 makeBinary(_makeRead(), binaryOperator, interfaceTarget, value), | 42 makeBinary(_makeRead(), binaryOperator, interfaceTarget, value), |
| 43 voidContext)); | 43 voidContext)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 Expression buildPrefixIncrement(Name binaryOperator, | 46 Expression buildPrefixIncrement(Name binaryOperator, |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 420 |
| 421 VariableDeclaration makeOrReuseVariable(Expression value) { | 421 VariableDeclaration makeOrReuseVariable(Expression value) { |
| 422 // TODO: Devise a way to remember if a variable declaration was reused | 422 // TODO: Devise a way to remember if a variable declaration was reused |
| 423 // or is fresh (hence needs a let binding). | 423 // or is fresh (hence needs a let binding). |
| 424 return new VariableDeclaration.forValue(value); | 424 return new VariableDeclaration.forValue(value); |
| 425 } | 425 } |
| 426 | 426 |
| 427 Expression wrapInvalid(Expression e) { | 427 Expression wrapInvalid(Expression e) { |
| 428 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 428 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
| 429 } | 429 } |
| OLD | NEW |