|
@@ -5,9 +5,9 @@ import org.objectweb.asm.Label;
|
5
|
5
|
import org.objectweb.asm.Type;
|
6
|
6
|
|
7
|
7
|
public class ArrayInitializerHelper {
|
8
|
|
- public static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, int originArrayLocation, Type originArrayType, int functionLocation, Type functionType, Type currentArrayType) {
|
|
8
|
+ public static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int dim, int originArrayLocation, Type originArrayType, int functionLocation, Type functionType, Type currentArrayType) {
|
9
|
9
|
|
10
|
|
- visitMultiDimArray(javaWriter, sizeLocations, counterLocations, dim, currentArrayType, (elementType1, counterLocations1, sizeLocations1) -> {
|
|
10
|
+ visitMultiDimArray(javaWriter, sizeLocations, dim, currentArrayType, (elementType, counterLocations) -> {
|
11
|
11
|
//Load origin array
|
12
|
12
|
javaWriter.loadObject(originArrayLocation);
|
13
|
13
|
|
|
@@ -29,11 +29,15 @@ public class ArrayInitializerHelper {
|
29
|
29
|
|
30
|
30
|
|
31
|
31
|
public static void visitMultiDimArrayWithDefaultValue(JavaWriter javaWriter, int dim, int defaultLocation, Type currentArrayType, int[] sizeLocations) {
|
32
|
|
- visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, (elementType, counterLocations, sizeLocations1) -> javaWriter.load(elementType, defaultLocation));
|
|
32
|
+ visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, (elementType, counterLocations) -> javaWriter.load(elementType, defaultLocation));
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ public static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction){
|
|
36
|
+ visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, innermostFunction);
|
33
|
37
|
}
|
34
|
38
|
|
35
|
39
|
|
36
|
|
- public static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
|
|
40
|
+ private static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
|
37
|
41
|
final Label begin = new Label();
|
38
|
42
|
final Label end = new Label();
|
39
|
43
|
javaWriter.label(begin);
|
|
@@ -63,7 +67,7 @@ public class ArrayInitializerHelper {
|
63
|
67
|
javaWriter.dup();
|
64
|
68
|
javaWriter.loadInt(forLoopCounter);
|
65
|
69
|
if (dim == 1) {
|
66
|
|
- innermostFunction.apply(elementType, counterLocations, sizeLocations);
|
|
70
|
+ innermostFunction.apply(elementType, counterLocations);
|
67
|
71
|
} else {
|
68
|
72
|
visitMultiDimArray(javaWriter, sizeLocations, counterLocations, dim - 1, elementType, innermostFunction);
|
69
|
73
|
}
|
|
@@ -79,11 +83,15 @@ public class ArrayInitializerHelper {
|
79
|
83
|
javaWriter.nameVariable(forLoopCounter, "i" + dim, loopStart, loopEnd, Type.getType(int.class));
|
80
|
84
|
|
81
|
85
|
javaWriter.label(end);
|
|
86
|
+
|
|
87
|
+ for (int i = 0; i < sizeLocations.length; i++) {
|
|
88
|
+ javaWriter.nameVariable(sizeLocations[i], "size" + (sizeLocations.length - i), begin, end, Type.getType(int.class));
|
|
89
|
+ }
|
82
|
90
|
}
|
83
|
91
|
|
84
|
92
|
@FunctionalInterface
|
85
|
93
|
public interface InnermostFunction {
|
86
|
|
- void apply(Type elementType, int[] counterLocations, int[] sizeLocations);
|
|
94
|
+ void apply(Type elementType, int[] counterLocations);
|
87
|
95
|
}
|
88
|
96
|
}
|
89
|
97
|
|