forked from JavaTX/JavaCompilerCore
Verbesserung der Bytecodegenerierung für FunN Typen.
Immernoch in drei Tests fehlerhaft.
This commit is contained in:
parent
bcf56e6bdd
commit
4522aeff36
@ -592,12 +592,26 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
this.lamCounter++;
|
this.lamCounter++;
|
||||||
|
|
||||||
//ToDo Etienne: umbauen
|
|
||||||
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
||||||
|
//ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path); //old
|
||||||
ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path);
|
|
||||||
|
|
||||||
//ToDo Etienne: umbauen
|
//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);
|
Lambda lam = new Lambda(lambdaExpression);
|
||||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||||
// Call site, which, when invoked, returns an instance of the functional
|
// 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)){
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
if(clazz.contains(CONSTANTS.$$)) {
|
if(clazz.contains(CONSTANTS.$$)) {
|
||||||
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||||
|
//helper.generateBCForFunN(mDesc); //old
|
||||||
//ToDo Etienne: check if it works
|
//ToDo Etienne: check if it works
|
||||||
//helper.generateBCForFunN(mDesc);
|
|
||||||
FunN f;
|
FunN f;
|
||||||
ASTToIntermediate converter = new ASTToIntermediate();
|
ASTToIntermediate converter = new ASTToIntermediate();
|
||||||
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.receiver.getType()));
|
//Fehler
|
||||||
if(methodCall
|
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.getType()));
|
||||||
.arglist
|
|
||||||
.getArguments().size() > 0){
|
|
||||||
List<IntermediateInnerType> arguments = methodCall
|
List<IntermediateInnerType> arguments = methodCall
|
||||||
.arglist
|
.arglist
|
||||||
.getArguments()
|
.getArguments()
|
||||||
@ -838,9 +850,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
.map(t -> (IntermediateInnerType) t)
|
.map(t -> (IntermediateInnerType) t)
|
||||||
.collect(Collectors.toList());//ToDo
|
.collect(Collectors.toList());//ToDo
|
||||||
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.getSuperClassName(), f.getSuperBytecode(), path);
|
||||||
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
|
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
|
||||||
|
@ -14,7 +14,10 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
//ToDo Etienne: check if it works
|
//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(".", "/");
|
return refType.getName().toString().replace(".", "/");
|
||||||
// String t = refType.getName().toString().replace(".", "/");
|
// String t = refType.getName().toString().replace(".", "/");
|
||||||
|
@ -31,7 +31,8 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
if(refType.getName().toString().equals("void"))
|
if(refType.getName().toString().equals("void"))
|
||||||
return "V";
|
return "V";
|
||||||
//ToDo Etienne: check if it works
|
//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(".", "/");
|
// return refType.toString().replace(".", "/");
|
||||||
String params = "";
|
String params = "";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.intermediate.convert;
|
package de.dhbwstuttgart.intermediate.convert;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.intermediate.generation.FunN;
|
import de.dhbwstuttgart.intermediate.generation.FunN;
|
||||||
import de.dhbwstuttgart.intermediate.types.*;
|
import de.dhbwstuttgart.intermediate.types.*;
|
||||||
@ -19,13 +18,13 @@ public class ASTToIntermediate {
|
|||||||
System.out.println(originalType.getParaList().size());
|
System.out.println(originalType.getParaList().size());
|
||||||
|
|
||||||
if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){
|
if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){
|
||||||
if(originalType.getParaList().size() == 0) throw new RuntimeException("Incorrect FunN Type: No params are defined!");
|
if(originalType.getParaList().size() == 0)
|
||||||
ASTToIntermediate converter = new ASTToIntermediate();
|
throw new RuntimeException("Incorrect FunN Type: No params are defined!");
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = originalType.getParaList();
|
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = originalType.getParaList();
|
||||||
IntermediateInnerType returnType = (IntermediateInnerType) convert(parameters.get(parameters.size() - 1));
|
IntermediateInnerType returnType = (IntermediateInnerType) convert(parameters.get(parameters.size() - 1));
|
||||||
parameters.remove(parameters.size() - 1);
|
|
||||||
return new FunN(parameters
|
return new FunN(parameters
|
||||||
.stream()
|
.stream()
|
||||||
|
.limit((parameters.size() - 1) > 0 ? (parameters.size() - 1) : 0)
|
||||||
.map(this::convert)
|
.map(this::convert)
|
||||||
.filter(t -> t instanceof IntermediateInnerType)
|
.filter(t -> t instanceof IntermediateInnerType)
|
||||||
.map(t -> (IntermediateInnerType) t)
|
.map(t -> (IntermediateInnerType) t)
|
||||||
@ -70,6 +69,7 @@ public class ASTToIntermediate {
|
|||||||
|
|
||||||
//ToDo Etienne: check if it works
|
//ToDo Etienne: check if it works
|
||||||
public IntermediateRefType convert(TypePlaceholder originalType){
|
public IntermediateRefType convert(TypePlaceholder originalType){
|
||||||
|
//ToDo zu Generic nachher
|
||||||
return new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class)));
|
return new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +60,9 @@ public final class FunN extends IntermediateRefType {
|
|||||||
typArguments.size(),
|
typArguments.size(),
|
||||||
typArguments
|
typArguments
|
||||||
.stream()
|
.stream()
|
||||||
.map(IntermediateType::getSignature)
|
.map(IntermediateInnerType::getDescriptor)
|
||||||
.collect(Collectors.joining()),
|
.collect(Collectors.joining()),
|
||||||
returnType.getSignature())
|
returnType.getDescriptor())
|
||||||
.replace('/', '$')
|
.replace('/', '$')
|
||||||
.replace(";", "$_$")),
|
.replace(";", "$_$")),
|
||||||
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
|
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;
|
//ToDo Etienne: Auslagern in andere Klasse;
|
||||||
|
@Deprecated
|
||||||
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
|
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
|
||||||
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
|
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
|
@ -82,7 +82,7 @@ public class IntermediateRefType extends IntermediateInnerType{
|
|||||||
}
|
}
|
||||||
signature += ";";
|
signature += ";";
|
||||||
}
|
}
|
||||||
signature.replace('.','/');
|
signature = signature.replace('.','/');
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user