| 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 | 7 |
| 8 import 'package:front_end/src/fasta/kernel/fasta_accessors.dart' | 8 import 'package:front_end/src/fasta/kernel/fasta_accessors.dart' |
| 9 show BuilderHelper; | 9 show BuilderHelper; |
| 10 | 10 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 /// At runtime, an exception will be thrown. | 134 /// At runtime, an exception will be thrown. |
| 135 makeInvalidRead() => new InvalidExpression(); | 135 makeInvalidRead() => new InvalidExpression(); |
| 136 | 136 |
| 137 /// Returns an [Expression] representing a compile-time error wrapping | 137 /// Returns an [Expression] representing a compile-time error wrapping |
| 138 /// [value]. | 138 /// [value]. |
| 139 /// | 139 /// |
| 140 /// At runtime, [value] will be evaluated before throwing an exception. | 140 /// At runtime, [value] will be evaluated before throwing an exception. |
| 141 makeInvalidWrite(Expression value) => wrapInvalid(value); | 141 makeInvalidWrite(Expression value) => wrapInvalid(value); |
| 142 } | 142 } |
| 143 | 143 |
| 144 class VariableAccessor extends Accessor { | 144 abstract class VariableAccessor extends Accessor { |
| 145 VariableDeclaration variable; | 145 VariableDeclaration variable; |
| 146 DartType promotedType; | 146 DartType promotedType; |
| 147 | 147 |
| 148 BuilderHelper get helper; |
| 149 |
| 148 VariableAccessor(this.variable, this.promotedType, int offset) | 150 VariableAccessor(this.variable, this.promotedType, int offset) |
| 149 : super(offset); | 151 : super(offset); |
| 150 | 152 |
| 151 Expression _makeRead() => | 153 Expression _makeRead() { |
| 152 new VariableGet(variable, promotedType)..fileOffset = offset; | 154 var fact = helper.typePromoter |
| 155 .getFactForAccess(variable, helper.functionNestingLevel); |
| 156 var scope = helper.typePromoter.currentScope; |
| 157 return helper.astFactory.variableGet(variable, fact, scope, offset); |
| 158 } |
| 153 | 159 |
| 154 Expression _makeWrite(Expression value, bool voidContext) { | 160 Expression _makeWrite(Expression value, bool voidContext) { |
| 161 helper.typePromoter.mutateVariable(variable, helper.functionNestingLevel); |
| 155 return variable.isFinal || variable.isConst | 162 return variable.isFinal || variable.isConst |
| 156 ? makeInvalidWrite(value) | 163 ? makeInvalidWrite(value) |
| 157 : new VariableSet(variable, value) | 164 : new VariableSet(variable, value) |
| 158 ..fileOffset = offset; | 165 ..fileOffset = offset; |
| 159 } | 166 } |
| 160 } | 167 } |
| 161 | 168 |
| 162 class PropertyAccessor extends Accessor { | 169 class PropertyAccessor extends Accessor { |
| 163 VariableDeclaration _receiverVariable; | 170 VariableDeclaration _receiverVariable; |
| 164 Expression receiver; | 171 Expression receiver; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 518 |
| 512 VariableDeclaration makeOrReuseVariable(Expression value) { | 519 VariableDeclaration makeOrReuseVariable(Expression value) { |
| 513 // TODO: Devise a way to remember if a variable declaration was reused | 520 // TODO: Devise a way to remember if a variable declaration was reused |
| 514 // or is fresh (hence needs a let binding). | 521 // or is fresh (hence needs a let binding). |
| 515 return new VariableDeclaration.forValue(value); | 522 return new VariableDeclaration.forValue(value); |
| 516 } | 523 } |
| 517 | 524 |
| 518 Expression wrapInvalid(Expression e) { | 525 Expression wrapInvalid(Expression e) { |
| 519 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 526 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
| 520 } | 527 } |
| OLD | NEW |