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/kernel_shadow_ast.dart' | 8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
9 show | 9 show |
10 KernelArguments, | 10 KernelArguments, |
11 KernelComplexAssignment, | 11 KernelComplexAssignment, |
12 KernelConditionalExpression, | 12 KernelConditionalExpression, |
13 KernelMethodInvocation, | 13 KernelMethodInvocation, |
| 14 KernelNullAwarePropertyGet, |
14 KernelPropertyAssign, | 15 KernelPropertyAssign, |
15 KernelPropertyGet, | 16 KernelPropertyGet, |
16 KernelThisExpression, | 17 KernelThisExpression, |
17 KernelVariableDeclaration, | 18 KernelVariableDeclaration, |
18 KernelVariableGet; | 19 KernelVariableGet; |
19 | 20 |
20 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 21 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
21 | 22 |
22 import 'package:front_end/src/scanner/token.dart' show Token; | 23 import 'package:front_end/src/scanner/token.dart' show Token; |
23 | 24 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 Expression _makeWrite(Expression value, bool voidContext, | 339 Expression _makeWrite(Expression value, bool voidContext, |
339 KernelComplexAssignment complexAssignment) { | 340 KernelComplexAssignment complexAssignment) { |
340 var write = new PropertySet(receiverAccess(), name, value, setter) | 341 var write = new PropertySet(receiverAccess(), name, value, setter) |
341 ..fileOffset = offsetForToken(token); | 342 ..fileOffset = offsetForToken(token); |
342 complexAssignment?.write = write; | 343 complexAssignment?.write = write; |
343 return write; | 344 return write; |
344 } | 345 } |
345 | 346 |
346 Expression _finish( | 347 Expression _finish( |
347 Expression body, KernelComplexAssignment complexAssignment) { | 348 Expression body, KernelComplexAssignment complexAssignment) { |
348 var nullAwareGuard = new KernelConditionalExpression( | 349 var offset = offsetForToken(token); |
349 buildIsNull(receiverAccess(), offsetForToken(token)), | 350 var nullAwareGuard = new ConditionalExpression( |
| 351 buildIsNull(receiverAccess(), offset), |
350 new NullLiteral(), | 352 new NullLiteral(), |
351 body) | 353 body, |
352 ..fileOffset = offsetForToken(token); | 354 const DynamicType()) |
353 body = makeLet(receiver, nullAwareGuard); | 355 ..fileOffset = offset; |
354 if (complexAssignment != null) { | 356 if (complexAssignment != null) { |
| 357 body = makeLet(receiver, nullAwareGuard); |
355 KernelPropertyAssign kernelPropertyAssign = complexAssignment; | 358 KernelPropertyAssign kernelPropertyAssign = complexAssignment; |
356 kernelPropertyAssign.nullAwareGuard = nullAwareGuard; | 359 kernelPropertyAssign.nullAwareGuard = nullAwareGuard; |
357 kernelPropertyAssign.desugared = body; | 360 kernelPropertyAssign.desugared = body; |
358 return kernelPropertyAssign; | 361 return kernelPropertyAssign; |
359 } else { | 362 } else { |
360 return body; | 363 return new KernelNullAwarePropertyGet(receiver, nullAwareGuard) |
| 364 ..fileOffset = offset; |
361 } | 365 } |
362 } | 366 } |
363 } | 367 } |
364 | 368 |
365 class SuperPropertyAccessor extends Accessor { | 369 class SuperPropertyAccessor extends Accessor { |
366 Name name; | 370 Name name; |
367 Member getter, setter; | 371 Member getter, setter; |
368 | 372 |
369 SuperPropertyAccessor( | 373 SuperPropertyAccessor( |
370 BuilderHelper helper, this.name, this.getter, this.setter, Token token) | 374 BuilderHelper helper, this.name, this.getter, this.setter, Token token) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 | 726 |
723 Expression buildIsNull(Expression value, int offset) { | 727 Expression buildIsNull(Expression value, int offset) { |
724 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset); | 728 return makeBinary(value, equalsName, null, new NullLiteral(), offset: offset); |
725 } | 729 } |
726 | 730 |
727 VariableDeclaration makeOrReuseVariable(Expression value) { | 731 VariableDeclaration makeOrReuseVariable(Expression value) { |
728 // TODO: Devise a way to remember if a variable declaration was reused | 732 // TODO: Devise a way to remember if a variable declaration was reused |
729 // or is fresh (hence needs a let binding). | 733 // or is fresh (hence needs a let binding). |
730 return new VariableDeclaration.forValue(value); | 734 return new VariableDeclaration.forValue(value); |
731 } | 735 } |
OLD | NEW |