| 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 14 matching lines...) Expand all Loading... |
| 25 /// The returned expression evaluates to the assigned value, unless | 25 /// The returned expression evaluates to the assigned value, unless |
| 26 /// [voidContext] is true, in which case it may evaluate to anything. | 26 /// [voidContext] is true, in which case it may evaluate to anything. |
| 27 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 27 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
| 28 return _finish(_makeSimpleWrite(value, voidContext)); | 28 return _finish(_makeSimpleWrite(value, voidContext)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 Expression buildNullAwareAssignment(Expression value, DartType type, | 31 Expression buildNullAwareAssignment(Expression value, DartType type, |
| 32 {bool voidContext: false}) { | 32 {bool voidContext: false}) { |
| 33 if (voidContext) { | 33 if (voidContext) { |
| 34 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), | 34 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), |
| 35 _makeWrite(value, voidContext), new NullLiteral(), type)); | 35 _makeWrite(value, false), new NullLiteral(), type)); |
| 36 } | 36 } |
| 37 var tmp = new VariableDeclaration.forValue(_makeRead()); | 37 var tmp = new VariableDeclaration.forValue(_makeRead()); |
| 38 return _finish(makeLet( | 38 return _finish(makeLet( |
| 39 tmp, | 39 tmp, |
| 40 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), | 40 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), |
| 41 _makeWrite(value, voidContext), new VariableGet(tmp), type))); | 41 _makeWrite(value, false), new VariableGet(tmp), type))); |
| 42 } | 42 } |
| 43 | 43 |
| 44 Expression buildCompoundAssignment(Name binaryOperator, Expression value, | 44 Expression buildCompoundAssignment(Name binaryOperator, Expression value, |
| 45 {int offset: TreeNode.noOffset, | 45 {int offset: TreeNode.noOffset, |
| 46 bool voidContext: false, | 46 bool voidContext: false, |
| 47 Procedure interfaceTarget}) { | 47 Procedure interfaceTarget}) { |
| 48 return _finish(_makeWrite( | 48 return _finish(_makeWrite( |
| 49 builtBinary = makeBinary( | 49 builtBinary = makeBinary( |
| 50 _makeRead(), binaryOperator, interfaceTarget, value, | 50 _makeRead(), binaryOperator, interfaceTarget, value, |
| 51 offset: offset), | 51 offset: offset), |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 426 |
| 427 VariableDeclaration makeOrReuseVariable(Expression value) { | 427 VariableDeclaration makeOrReuseVariable(Expression value) { |
| 428 // TODO: Devise a way to remember if a variable declaration was reused | 428 // TODO: Devise a way to remember if a variable declaration was reused |
| 429 // or is fresh (hence needs a let binding). | 429 // or is fresh (hence needs a let binding). |
| 430 return new VariableDeclaration.forValue(value); | 430 return new VariableDeclaration.forValue(value); |
| 431 } | 431 } |
| 432 | 432 |
| 433 Expression wrapInvalid(Expression e) { | 433 Expression wrapInvalid(Expression e) { |
| 434 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 434 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
| 435 } | 435 } |
| OLD | NEW |