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 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 _finish(Expression body) => makeLet( | 216 _finish(Expression body) => makeLet( |
217 receiver, | 217 receiver, |
218 new ConditionalExpression( | 218 new ConditionalExpression( |
219 buildIsNull(receiverAccess()), new NullLiteral(), body, type)); | 219 buildIsNull(receiverAccess()), new NullLiteral(), body, type)); |
220 } | 220 } |
221 | 221 |
222 class SuperPropertyAccessor extends Accessor { | 222 class SuperPropertyAccessor extends Accessor { |
223 Name name; | 223 Name name; |
224 Member getter, setter; | 224 Member getter, setter; |
225 final int charOffset; | |
226 | 225 |
227 SuperPropertyAccessor(this.name, this.getter, this.setter, this.charOffset); | 226 SuperPropertyAccessor(this.name, this.getter, this.setter); |
228 | 227 |
229 _makeRead() { | 228 _makeRead() { |
230 if (getter == null) return makeInvalidRead(); | 229 if (getter == null) return makeInvalidRead(); |
231 // TODO(ahe): Use [DirectPropertyGet] when possible. | 230 // TODO(ahe): Use [DirectPropertyGet] when possible. |
232 Expression result = new DirectPropertyGet(new ThisExpression(), getter) | 231 Expression result = new DirectPropertyGet(new ThisExpression(), getter); |
233 ..fileOffset = charOffset; | 232 result = new SuperPropertyGet(name, getter); |
234 result = new SuperPropertyGet(name, getter)..fileOffset = charOffset; | |
235 return result; | 233 return result; |
236 } | 234 } |
237 | 235 |
238 _makeWrite(Expression value, bool voidContext) { | 236 _makeWrite(Expression value, bool voidContext) { |
239 if (setter == null) return makeInvalidWrite(value); | 237 if (setter == null) return makeInvalidWrite(value); |
240 // TODO(ahe): Use [DirectPropertySet] when possible. | 238 // TODO(ahe): Use [DirectPropertySet] when possible. |
241 Expression result = new DirectPropertySet( | 239 Expression result = |
242 new ThisExpression(), setter, value)..fileOffset = charOffset; | 240 new DirectPropertySet(new ThisExpression(), setter, value); |
243 result = new SuperPropertySet(name, value, setter)..fileOffset = charOffset; | 241 result = new SuperPropertySet(name, value, setter); |
244 return result; | 242 return result; |
245 } | 243 } |
246 } | 244 } |
247 | 245 |
248 final Name _indexGet = new Name('[]'); | 246 final Name _indexGet = new Name('[]'); |
249 final Name _indexSet = new Name('[]='); | 247 final Name _indexSet = new Name('[]='); |
250 | 248 |
251 class IndexAccessor extends Accessor { | 249 class IndexAccessor extends Accessor { |
252 Expression receiver; | 250 Expression receiver; |
253 Expression index; | 251 Expression index; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 478 |
481 VariableDeclaration makeOrReuseVariable(Expression value) { | 479 VariableDeclaration makeOrReuseVariable(Expression value) { |
482 // TODO: Devise a way to remember if a variable declaration was reused | 480 // TODO: Devise a way to remember if a variable declaration was reused |
483 // or is fresh (hence needs a let binding). | 481 // or is fresh (hence needs a let binding). |
484 return new VariableDeclaration.forValue(value); | 482 return new VariableDeclaration.forValue(value); |
485 } | 483 } |
486 | 484 |
487 Expression wrapInvalid(Expression e) { | 485 Expression wrapInvalid(Expression e) { |
488 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 486 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
489 } | 487 } |
OLD | NEW |