Verbesserung der Bytecodegenerierung für FunN Typen.

Immernoch in drei Tests fehlerhaft.
This commit is contained in:
Etienne Zink 2022-03-28 10:47:49 +02:00
parent bcf56e6bdd
commit 4522aeff36
6 changed files with 36 additions and 22 deletions

View File

@ -592,12 +592,26 @@ public class BytecodeGenMethod implements StatementVisitor {
public void visit(LambdaExpression lambdaExpression) {
this.lamCounter++;
//ToDo Etienne: umbauen
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path);
//ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path); //old
//ToDo Etienne: umbauen
FunN f;
//ToDo refactor with code for FunN underneath
ASTToIntermediate converter = new ASTToIntermediate();
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(lambdaExpression.getReturnType());
List<IntermediateInnerType> arguments = lambdaExpression.params
.getFormalparalist()
.stream()
.map(FormalParameter::getType)
.map(resolver::resolve)
.map(converter::convert)
.filter(t -> t instanceof IntermediateInnerType)
.map(t -> (IntermediateInnerType) t)
.collect(Collectors.toList());//ToDo
f = new FunN(arguments, returnType);
FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path);
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
//ToDo Etienne: umbauen end
Lambda lam = new Lambda(lambdaExpression);
String lamDesc = lam.accept(new DescriptorToString(resultSet));
// Call site, which, when invoked, returns an instance of the functional
@ -819,14 +833,12 @@ public class BytecodeGenMethod implements StatementVisitor {
} else if(!helper.isInCurrPkg(clazz)){
if(clazz.contains(CONSTANTS.$$)) {
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
//helper.generateBCForFunN(mDesc); //old
//ToDo Etienne: check if it works
//helper.generateBCForFunN(mDesc);
FunN f;
ASTToIntermediate converter = new ASTToIntermediate();
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.receiver.getType()));
if(methodCall
.arglist
.getArguments().size() > 0){
//Fehler
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.getType()));
List<IntermediateInnerType> arguments = methodCall
.arglist
.getArguments()
@ -837,10 +849,7 @@ public class BytecodeGenMethod implements StatementVisitor {
.filter(t -> t instanceof IntermediateInnerType)
.map(t -> (IntermediateInnerType) t)
.collect(Collectors.toList());//ToDo
f = new FunN(arguments, returnType);
} else {
f = new FunN(returnType);
}
f = new FunN(arguments, returnType);
FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path);
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);

View File

@ -14,7 +14,10 @@ public class TypeToDescriptor implements TypeVisitor<String>{
@Override
public String visit(RefType refType) {
//ToDo Etienne: check if it works
if (refType.getName().toString().matches("Fun\\d+\\$\\$")) return new ASTToIntermediate().convert(refType).getDescriptor();
if (refType.getName().toString().matches("Fun\\d+\\$\\$")){
String descriptor = new ASTToIntermediate().convert(refType).getDescriptor();
return descriptor.substring(1, descriptor.length() - 1);
}
return refType.getName().toString().replace(".", "/");
// String t = refType.getName().toString().replace(".", "/");

View File

@ -31,7 +31,8 @@ public class TypeToSignature implements TypeVisitor<String> {
if(refType.getName().toString().equals("void"))
return "V";
//ToDo Etienne: check if it works
if (refType.getName().toString().matches("Fun\\d+\\$\\$")) return new ASTToIntermediate().convert(refType).getSignature();
if (refType.getName().toString().matches("Fun\\d+\\$\\$"))
return new ASTToIntermediate().convert(refType).getSignature();
// return refType.toString().replace(".", "/");
String params = "";

View File

@ -1,6 +1,5 @@
package de.dhbwstuttgart.intermediate.convert;
import de.dhbwstuttgart.bytecode.utilities.Resolver;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.intermediate.generation.FunN;
import de.dhbwstuttgart.intermediate.types.*;
@ -19,13 +18,13 @@ public class ASTToIntermediate {
System.out.println(originalType.getParaList().size());
if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){
if(originalType.getParaList().size() == 0) throw new RuntimeException("Incorrect FunN Type: No params are defined!");
ASTToIntermediate converter = new ASTToIntermediate();
if(originalType.getParaList().size() == 0)
throw new RuntimeException("Incorrect FunN Type: No params are defined!");
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = originalType.getParaList();
IntermediateInnerType returnType = (IntermediateInnerType) convert(parameters.get(parameters.size() - 1));
parameters.remove(parameters.size() - 1);
return new FunN(parameters
.stream()
.limit((parameters.size() - 1) > 0 ? (parameters.size() - 1) : 0)
.map(this::convert)
.filter(t -> t instanceof IntermediateInnerType)
.map(t -> (IntermediateInnerType) t)
@ -70,6 +69,7 @@ public class ASTToIntermediate {
//ToDo Etienne: check if it works
public IntermediateRefType convert(TypePlaceholder originalType){
//ToDo zu Generic nachher
return new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class)));
}

View File

@ -60,9 +60,9 @@ public final class FunN extends IntermediateRefType {
typArguments.size(),
typArguments
.stream()
.map(IntermediateType::getSignature)
.map(IntermediateInnerType::getDescriptor)
.collect(Collectors.joining()),
returnType.getSignature())
returnType.getDescriptor())
.replace('/', '$')
.replace(";", "$_$")),
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
@ -138,6 +138,7 @@ public final class FunN extends IntermediateRefType {
}
//ToDo Etienne: Auslagern in andere Klasse;
@Deprecated
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
output.write(bytecode);

View File

@ -82,7 +82,7 @@ public class IntermediateRefType extends IntermediateInnerType{
}
signature += ";";
}
signature.replace('.','/');
signature = signature.replace('.','/');
this.signature = signature;
return signature;
}