diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 02a07fb84..dfc63d4cf 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -820,16 +820,26 @@ public class BytecodeGenMethod implements StatementVisitor { mDesc = helper.getDescriptorOfApplyMethod(methCallType); //ToDo Etienne: check if it works //helper.generateBCForFunN(mDesc); + FunN f; ASTToIntermediate converter = new ASTToIntermediate(); - IntermediateInnerType returnType = converter.convert(methodCall.receiver.getType()); + IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(methodCall.receiver.getType()); + if(methodCall + .arglist + .getArguments().size() > 0){ List arguments = methodCall .arglist .getArguments() .stream() .map(TypableStatement::getType) .map(converter::convert) + .filter(t -> t instanceof IntermediateInnerType) + .map(t -> (IntermediateInnerType) t) .collect(Collectors.toList());//ToDo - FunN f = new FunN(arguments, returnType); + f = new FunN(arguments, returnType); + } else { + f = new FunN(returnType); + } + FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path); FunN.writeClassFile(f.getClassName(), f.getBytecode(), path); //ToDo Etienne End diff --git a/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java index 4e9ef6dce..b9cb47b59 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java @@ -3,7 +3,9 @@ package de.dhbwstuttgart.intermediate.convert; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.intermediate.generation.FunN; import de.dhbwstuttgart.intermediate.types.*; +import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.type.*; +import org.objectweb.asm.Type; import java.util.List; import java.util.stream.Collectors; @@ -12,14 +14,19 @@ public class ASTToIntermediate { public IntermediateRefType convert(RefType originalType){ //ToDo Etienne: check if it works + System.out.println(originalType.getName()); + System.out.println(originalType.getParaList().size()); + if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){ ASTToIntermediate converter = new ASTToIntermediate(); List parameters = originalType.getParaList(); - IntermediateInnerType returnType = convert(parameters.get(parameters.size() - 1)); + IntermediateInnerType returnType = (IntermediateInnerType) convert(parameters.get(parameters.size() - 1)); parameters.remove(parameters.size() - 1); return new FunN(parameters .stream() .map(this::convert) + .filter(t -> t instanceof IntermediateInnerType) + .map(t -> (IntermediateInnerType) t) .collect(Collectors.toList()), returnType); } @@ -52,13 +59,24 @@ public class ASTToIntermediate { return new IntermediateExtendsWildcard((IntermediateInnerType) innerType); } + /* public IntermediateWildcard convert(){ //thows RuntimeException because in the AST is no typ defined which represents a normal wildcard throw new NotImplementedException("There is no conversion defined for this type."); } + */ - public IntermediateRefType convert(RefTypeOrTPHOrWildcardOrGeneric originalType){ - //default implementation which shouldn't be called because of polymorphism - throw new NotImplementedException("There is no conversion defined for this type."); + //ToDo Etienne: check if it works + public IntermediateRefType convert(TypePlaceholder originalType){ + return new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class))); + } + + public IntermediateType convert(RefTypeOrTPHOrWildcardOrGeneric originalType){ + if (originalType instanceof RefType) return convert((RefType) originalType); + if (originalType instanceof GenericRefType) return convert((GenericRefType) originalType); + if (originalType instanceof SuperWildcardType) return convert((SuperWildcardType) originalType); + if (originalType instanceof ExtendsWildcardType) return convert((ExtendsWildcardType) originalType); + if (originalType instanceof TypePlaceholder) return convert((TypePlaceholder) originalType); + throw new NotImplementedException("There is no conversion defined for this type." + originalType.getClass().getName()); } }