Verbesserung der Konvertierung und der Bytecodegenerierung für FunN Typen.

Beinhaltet noch Fehler!
This commit is contained in:
Etienne Zink 2022-03-23 16:12:25 +01:00
parent dc9a54be3b
commit 15c05e5cba
2 changed files with 34 additions and 6 deletions

View File

@ -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<IntermediateInnerType> 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

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> 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());
}
}