Browse Source

Replaced hardcoded IntRange class name

Reason: Some iterators use the generated USizeRange which would throw a ClassCastException
kindlich 5 years ago
parent
commit
6ada4ffce1
No known key found for this signature in database

+ 18
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

884
 				} else {
884
 				} else {
885
 					argument.accept(this);
885
 					argument.accept(this);
886
 					javaWriter.dup();
886
 					javaWriter.dup();
887
-					int tmp = javaWriter.local(Type.getType("zsynthetic/IntRange"));
887
+					final String owner;
888
+					if (argument.type.type instanceof RangeTypeID) {
889
+						owner = context.getInternalName(argument.type);
890
+					} else {
891
+						owner = "zsynthetic/IntRange";
892
+					}
893
+					int tmp = javaWriter.local(Type.getType(owner));
888
 					javaWriter.storeInt(tmp);
894
 					javaWriter.storeInt(tmp);
889
-					javaWriter.getField("zsynthetic/IntRange", "from", "I");
895
+					javaWriter.getField(owner, "from", "I");
890
 					javaWriter.loadInt(tmp);
896
 					javaWriter.loadInt(tmp);
891
-					javaWriter.getField("zsynthetic/IntRange", "to", "I");
897
+					javaWriter.getField(owner, "to", "I");
892
 				}
898
 				}
893
 				javaWriter.invokeVirtual(STRING_SUBSTRING);
899
 				javaWriter.invokeVirtual(STRING_SUBSTRING);
894
 				break;
900
 				break;
1007
 				} else {
1013
 				} else {
1008
 					argument.accept(this);
1014
 					argument.accept(this);
1009
 					javaWriter.dup();
1015
 					javaWriter.dup();
1010
-					int tmp = javaWriter.local(Type.getType("zsynthetic/IntRange"));
1016
+					final String owner;
1017
+					if (argument.type.type instanceof RangeTypeID) {
1018
+						owner = context.getInternalName(argument.type);
1019
+					} else {
1020
+						owner = "zsynthetic/IntRange";
1021
+					}
1022
+					int tmp = javaWriter.local(Type.getType(owner));
1011
 					javaWriter.storeInt(tmp);
1023
 					javaWriter.storeInt(tmp);
1012
-					javaWriter.getField("zsynthetic/IntRange", "from", "I");
1024
+					javaWriter.getField(owner, "from", "I");
1013
 					javaWriter.loadInt(tmp);
1025
 					javaWriter.loadInt(tmp);
1014
-					javaWriter.getField("zsynthetic/IntRange", "to", "I");
1026
+					javaWriter.getField(owner, "to", "I");
1015
 				}
1027
 				}
1016
 
1028
 
1017
 				if (type.elementType.type instanceof BasicTypeID) {
1029
 				if (type.elementType.type instanceof BasicTypeID) {

+ 5
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java View File

4
 import org.objectweb.asm.Type;
4
 import org.objectweb.asm.Type;
5
 import org.openzen.zenscript.codemodel.statement.Statement;
5
 import org.openzen.zenscript.codemodel.statement.Statement;
6
 import org.openzen.zenscript.codemodel.statement.VarStatement;
6
 import org.openzen.zenscript.codemodel.statement.VarStatement;
7
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
7
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8
 import org.openzen.zenscript.javashared.JavaClass;
9
 import org.openzen.zenscript.javashared.JavaClass;
9
 import org.openzen.zenscript.javashared.JavaMethod;
10
 import org.openzen.zenscript.javashared.JavaMethod;
32
         this.unboxingTypeVisitor = new JavaUnboxingTypeVisitor(this.javaWriter);
33
         this.unboxingTypeVisitor = new JavaUnboxingTypeVisitor(this.javaWriter);
33
     }
34
     }
34
 
35
 
35
-	public void visitIntRange() {
36
+	public void visitIntRange(RangeTypeID type) {
37
+		final String owner = statementVisitor.context.getInternalName(type);
36
 		javaWriter.dup();
38
 		javaWriter.dup();
37
-		javaWriter.getField("zsynthetic/IntRange", "to", "I");
39
+		javaWriter.getField(owner, "to", "I");
38
 		javaWriter.swap();
40
 		javaWriter.swap();
39
-		javaWriter.getField("zsynthetic/IntRange", "from", "I");
41
+		javaWriter.getField(owner, "from", "I");
40
 
42
 
41
 		final int z = javaWriter.getLocalVariable(variables[0].variable).local;
43
 		final int z = javaWriter.getLocalVariable(variables[0].variable).local;
42
 		javaWriter.storeInt(z);
44
 		javaWriter.storeInt(z);

+ 3
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java View File

3
 import org.objectweb.asm.Label;
3
 import org.objectweb.asm.Label;
4
 import org.objectweb.asm.Type;
4
 import org.objectweb.asm.Type;
5
 import org.openzen.zenscript.codemodel.statement.*;
5
 import org.openzen.zenscript.codemodel.statement.*;
6
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
6
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
7
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
7
 
8
 
8
 import java.util.Arrays;
9
 import java.util.Arrays;
14
 
15
 
15
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
16
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
16
     private final JavaWriter javaWriter;
17
     private final JavaWriter javaWriter;
17
-	private final JavaBytecodeContext context;
18
+	final JavaBytecodeContext context;
18
     public JavaExpressionVisitor expressionVisitor;
19
     public JavaExpressionVisitor expressionVisitor;
19
 	public JavaNonPushingExpressionVisitor nonPushingExpressionVisitor;
20
 	public JavaNonPushingExpressionVisitor nonPushingExpressionVisitor;
20
 
21
 
124
 		} else {
125
 		} else {
125
 			switch (statement.iterator.target.getBuiltin()) {
126
 			switch (statement.iterator.target.getBuiltin()) {
126
 				case ITERATOR_INT_RANGE:
127
 				case ITERATOR_INT_RANGE:
127
-					iteratorWriter.visitIntRange();
128
+					iteratorWriter.visitIntRange(((RangeTypeID) statement.iterator.getOwnerType().type));
128
 					break;
129
 					break;
129
 				case ITERATOR_ARRAY_VALUES:
130
 				case ITERATOR_ARRAY_VALUES:
130
 					iteratorWriter.visitArrayValueIterator();
131
 					iteratorWriter.visitArrayValueIterator();

Loading…
Cancel
Save