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 move super calls last in the initializer list. | 5 /// A library to help move super calls last in the initializer list. |
6 library kernel.frontend.super_calls; | 6 library kernel.frontend.super_calls; |
7 | 7 |
8 import '../ast.dart'; | 8 import '../ast.dart'; |
9 | 9 |
10 /// Mutates the initializer list of [node] so that its super initializer occurs | 10 /// Mutates the initializer list of [node] so that its super initializer occurs |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (superIndex == -1) return; | 26 if (superIndex == -1) return; |
27 SuperInitializer superCall = initializers[superIndex]; | 27 SuperInitializer superCall = initializers[superIndex]; |
28 Arguments arguments = superCall.arguments; | 28 Arguments arguments = superCall.arguments; |
29 int argumentCount = arguments.positional.length + arguments.named.length; | 29 int argumentCount = arguments.positional.length + arguments.named.length; |
30 | 30 |
31 // We move all initializers after the super call to the place where the super | 31 // We move all initializers after the super call to the place where the super |
32 // call was, but reserve [argumentCount] slots before that for | 32 // call was, but reserve [argumentCount] slots before that for |
33 // [LocalInitializer]s. | 33 // [LocalInitializer]s. |
34 initializers.length += argumentCount; | 34 initializers.length += argumentCount; |
35 initializers.setRange( | 35 initializers.setRange( |
36 superIndex + argumentCount, // desination start (inclusive) | 36 superIndex + argumentCount, // desination start (inclusive) |
37 initializers.length - 1, // desination end (exclusive) | 37 initializers.length - 1, // desination end (exclusive) |
38 initializers, // source list | 38 initializers, // source list |
39 superIndex + 1); // source start index | 39 superIndex + 1); // source start index |
40 initializers[initializers.length - 1] = superCall; | 40 initializers[initializers.length - 1] = superCall; |
41 | 41 |
42 // Fill in the [argumentCount] reserved slots with the evaluation expressions | 42 // Fill in the [argumentCount] reserved slots with the evaluation expressions |
43 // of the arguments to the super constructor call. | 43 // of the arguments to the super constructor call. |
44 int storeIndex = superIndex; | 44 int storeIndex = superIndex; |
45 for (int i = 0; i < arguments.positional.length; ++i) { | 45 for (int i = 0; i < arguments.positional.length; ++i) { |
46 var variable = new VariableDeclaration.forValue(arguments.positional[i]); | 46 var variable = new VariableDeclaration.forValue(arguments.positional[i]); |
47 arguments.positional[i] = new VariableGet(variable)..parent = arguments; | 47 arguments.positional[i] = new VariableGet(variable)..parent = arguments; |
48 initializers[storeIndex++] = new LocalInitializer(variable)..parent = node; | 48 initializers[storeIndex++] = new LocalInitializer(variable)..parent = node; |
49 } | 49 } |
50 for (int i = 0; i < arguments.named.length; ++i) { | 50 for (int i = 0; i < arguments.named.length; ++i) { |
51 NamedExpression argument = arguments.named[i]; | 51 NamedExpression argument = arguments.named[i]; |
52 var variable = new VariableDeclaration.forValue(argument.value); | 52 var variable = new VariableDeclaration.forValue(argument.value); |
53 arguments.named[i].value = new VariableGet(variable)..parent = argument; | 53 arguments.named[i].value = new VariableGet(variable)..parent = argument; |
54 initializers[storeIndex++] = new LocalInitializer(variable)..parent = node; | 54 initializers[storeIndex++] = new LocalInitializer(variable)..parent = node; |
55 } | 55 } |
56 } | 56 } |
OLD | NEW |