소스 검색

Replaced hardcoded IntRange class name

Reason: Some iterators use the generated USizeRange which would throw a ClassCastException
kindlich 5 년 전
부모
커밋
6ada4ffce1
No known key found for this signature in database

+ 18
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java 파일 보기

@@ -884,11 +884,17 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
884 884
 				} else {
885 885
 					argument.accept(this);
886 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 894
 					javaWriter.storeInt(tmp);
889
-					javaWriter.getField("zsynthetic/IntRange", "from", "I");
895
+					javaWriter.getField(owner, "from", "I");
890 896
 					javaWriter.loadInt(tmp);
891
-					javaWriter.getField("zsynthetic/IntRange", "to", "I");
897
+					javaWriter.getField(owner, "to", "I");
892 898
 				}
893 899
 				javaWriter.invokeVirtual(STRING_SUBSTRING);
894 900
 				break;
@@ -1007,11 +1013,17 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
1007 1013
 				} else {
1008 1014
 					argument.accept(this);
1009 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 1023
 					javaWriter.storeInt(tmp);
1012
-					javaWriter.getField("zsynthetic/IntRange", "from", "I");
1024
+					javaWriter.getField(owner, "from", "I");
1013 1025
 					javaWriter.loadInt(tmp);
1014
-					javaWriter.getField("zsynthetic/IntRange", "to", "I");
1026
+					javaWriter.getField(owner, "to", "I");
1015 1027
 				}
1016 1028
 
1017 1029
 				if (type.elementType.type instanceof BasicTypeID) {

+ 5
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java 파일 보기

@@ -4,6 +4,7 @@ import org.objectweb.asm.Label;
4 4
 import org.objectweb.asm.Type;
5 5
 import org.openzen.zenscript.codemodel.statement.Statement;
6 6
 import org.openzen.zenscript.codemodel.statement.VarStatement;
7
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
7 8
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8 9
 import org.openzen.zenscript.javashared.JavaClass;
9 10
 import org.openzen.zenscript.javashared.JavaMethod;
@@ -32,11 +33,12 @@ public class JavaForeachWriter {
32 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 38
 		javaWriter.dup();
37
-		javaWriter.getField("zsynthetic/IntRange", "to", "I");
39
+		javaWriter.getField(owner, "to", "I");
38 40
 		javaWriter.swap();
39
-		javaWriter.getField("zsynthetic/IntRange", "from", "I");
41
+		javaWriter.getField(owner, "from", "I");
40 42
 
41 43
 		final int z = javaWriter.getLocalVariable(variables[0].variable).local;
42 44
 		javaWriter.storeInt(z);

+ 3
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java 파일 보기

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

Loading…
취소
저장