Skip to content

Commit

Permalink
Fix JavaMethod#genericResult not being set
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed May 17, 2024
1 parent 461d4db commit 53273e2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
private static final JavaMethod ENUM_NAME = JavaMethod.getNativeVirtual(JavaClass.ENUM, "name", "()Ljava/lang/String;");
public static final JavaMethod ENUM_ORDINAL = JavaMethod.getNativeVirtual(JavaClass.ENUM, "ordinal", "()I");
private static final JavaMethod HASHMAP_INIT = JavaMethod.getNativeConstructor(JavaClass.HASHMAP, "()V");
private static final JavaMethod MAP_GET = JavaMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaMethod MAP_PUT = JavaMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaMethod MAP_GET = JavaMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaMethod MAP_PUT = JavaMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaMethod MAP_PUT_ALL = JavaMethod.getInterface(JavaClass.MAP, "putAll", "(Ljava/util/Map;)V");
private static final JavaMethod MAP_CONTAINS_KEY = JavaMethod.getInterface(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z");
private static final JavaMethod MAP_SIZE = JavaMethod.getInterface(JavaClass.MAP, "size", "()I");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void visitIteratorIterator(Type targetType) {
javaWriter.dup();
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));
javaWriter.checkCast(targetType);
final JavaLocalVariableInfo variable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
javaWriter.store(variable.type, variable.local);
Expand Down Expand Up @@ -117,7 +117,7 @@ public void visitCustomIterator() {
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));

final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
this.downCast(0, keyVariable.type);
Expand All @@ -135,7 +135,7 @@ public void visitAssocKeyIterator() {
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));

final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
this.downCast(0, keyVariable.type);
Expand All @@ -153,19 +153,19 @@ public void visitAssocKeyValueIterator() {
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));
javaWriter.checkCast(Type.getType(Map.Entry.class));
javaWriter.dup(false);


final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
final JavaLocalVariableInfo valueVariable = javaWriter.getLocalVariable(statement.loopVariables[1].variable);

javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getKey", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getKey", "()Ljava/lang/Object;", 0, true));
this.downCast(0, keyVariable.type);
javaWriter.store(keyVariable.type, keyVariable.local);

javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getValue", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getValue", "()Ljava/lang/Object;", 0, true));
this.downCast(1, valueVariable.type);
javaWriter.store(valueVariable.type, valueVariable.local);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void fillMethod(ExpansionDefinition expansion, JavaClass javaClass, Meth
final MethodMember member = new MethodMember(CodePosition.NATIVE, expansion, headerConverter.getMethodModifiers(method) ^ Modifiers.STATIC, name, header, null);

expansion.addMember(member);
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method)));
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method), member.getHeader().getReturnType().isGeneric()));
}

private void fillStaticMethod(ExpansionDefinition expansion, JavaClass javaClass, Method method, ZenCodeType.StaticExpansionMethod annotation) {
Expand All @@ -176,7 +176,7 @@ private void fillStaticMethod(ExpansionDefinition expansion, JavaClass javaClass
final MethodMember member = new MethodMember(CodePosition.NATIVE, expansion, headerConverter.getMethodModifiers(method), name, header, null);

expansion.addMember(member);
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method)));
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method), header.getReturnType().isGeneric()));
}

private void fillOperator(ExpansionDefinition expansion, JavaClass javaClass, Method method, Class<?> classFromType, ZenCodeType.Operator operator) {
Expand All @@ -189,7 +189,7 @@ private void fillOperator(ExpansionDefinition expansion, JavaClass javaClass, Me
final OperatorMember member = new OperatorMember(CodePosition.NATIVE, expansion, headerConverter.getMethodModifiers(method) ^ Modifiers.STATIC, operatorType, header, null);

expansion.addMember(member);
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method)));
typeConversionContext.compiled.setMethodInfo(member, JavaMethod.getStatic(javaClass, method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method), headerConverter.getMethodModifiers(method), header.getReturnType().isGeneric()));
}

private OperatorType getOperatorTypeFrom(ZenCodeType.Operator operator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,35 @@ public static JavaMethod getDestructor(JavaClass cls, int modifiers) {
}

public static JavaMethod getStatic(JavaClass cls, String name, String descriptor, int modifiers) {
return new JavaMethod(cls, Kind.STATIC, name, true, descriptor, modifiers | JavaModifiers.STATIC, false);
return getStatic(cls, name, descriptor, modifiers, false);
}

public static JavaMethod getStatic(JavaClass cls, String name, String descriptor, int modifiers, boolean genericResult) {
return new JavaMethod(cls, Kind.STATIC, name, true, descriptor, modifiers | JavaModifiers.STATIC, genericResult);
}

public static JavaMethod getNativeStatic(JavaClass cls, String name, String descriptor) {
return new JavaMethod(cls, Kind.STATIC, name, false, descriptor, JavaModifiers.STATIC | JavaModifiers.PUBLIC, false);
}

public static JavaMethod getVirtual(JavaClass cls, String name, String descriptor, int modifiers) {
return new JavaMethod(cls, Kind.INSTANCE, name, true, descriptor, modifiers, false);
return getVirtual(cls, name, descriptor, modifiers, false);
}

public static JavaMethod getVirtual(JavaClass cls, String name, String descriptor, int modifiers, boolean genericResult) {
return new JavaMethod(cls, Kind.INSTANCE, name, true, descriptor, modifiers, genericResult);
}

public static JavaMethod getNativeVirtual(JavaClass cls, String name, String descriptor) {
return new JavaMethod(cls, Kind.INSTANCE, name, false, descriptor, JavaModifiers.PUBLIC, false);
}

public static JavaMethod getInterface(JavaClass cls, String name, String descriptor) {
return new JavaMethod(cls, Kind.INTERFACE, name, false, descriptor, JavaModifiers.PUBLIC, false);
return getInterface(cls, name, descriptor, false);
}

public static JavaMethod getInterface(JavaClass cls, String name, String descriptor, boolean genericResult) {
return new JavaMethod(cls, Kind.INTERFACE, name, false, descriptor, JavaModifiers.PUBLIC, genericResult);
}

public static JavaMethod getNativeExpansion(JavaClass cls, String name, String descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public JavaClass visitFunction(FunctionDefinition definition) {
return context.getJavaClass(definition);

JavaClass cls = context.getJavaClass(definition);
JavaMethod method = JavaMethod.getStatic(cls, definition.name, context.getMethodDescriptor(definition.header), JavaModifiers.getJavaModifiers(definition.modifiers));
JavaMethod method = JavaMethod.getStatic(cls, definition.name, context.getMethodDescriptor(definition.header), JavaModifiers.getJavaModifiers(definition.modifiers), definition.header.getReturnType().isGeneric());
module.setMethodInfo(definition.caller, method);
return cls;
}
Expand Down

0 comments on commit 53273e2

Please sign in to comment.