From d8bdcf854c0251b02aae56f407289123b7502b6d Mon Sep 17 00:00:00 2001 From: Etienne Zink Date: Tue, 29 Mar 2022 08:56:38 +0200 Subject: [PATCH] Refactoring der Bytecodegenerierung und Anpassung von Kommentaren. --- .../bytecode/BytecodeGenMethod.java | 66 ++++--------------- .../bytecode/descriptor/TypeToDescriptor.java | 1 - .../bytecode/funN/FunNUtilities.java | 2 + .../bytecode/signature/TypeToSignature.java | 1 - 4 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 526eaa7a..8fcebbf0 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -592,28 +592,7 @@ public class BytecodeGenMethod implements StatementVisitor { this.lamCounter++; String typeErasure = createDescriptorWithTypeErasure(lambdaExpression); - //ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path); //old - //ToDo Etienne: umbauen - //ToDo Refactor - /* - FunN f; - ASTToIntermediate converter = new ASTToIntermediate(); - //Fehler in return Typ - IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(lambdaExpression.getReturnType())); - List 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: Double Check RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(lambdaExpression.getReturnType()); List argumentTypes = lambdaExpression .params @@ -623,12 +602,11 @@ public class BytecodeGenMethod implements StatementVisitor { .map(resolver::resolve) .collect(Collectors.toList()); FunNUtilities funNUtilities = FunNGenerator.getInstance(); - byte[] superBytecode = funNUtilities.generateSuperBytecode(argumentTypes.size()); - byte[] specializedBytecode = funNUtilities.generateSpecializedBytecode(argumentTypes, returnType); - FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), superBytecode, path); - FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), specializedBytecode, path); - //*/ - //ToDo Etienne: umbauen end + FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), + funNUtilities.generateSuperBytecode(argumentTypes.size()), path); + FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), + funNUtilities.generateSpecializedBytecode(argumentTypes, returnType), path); + Lambda lam = new Lambda(lambdaExpression); String lamDesc = lam.accept(new DescriptorToString(resultSet)); // Call site, which, when invoked, returns an instance of the functional @@ -850,26 +828,7 @@ public class BytecodeGenMethod implements StatementVisitor { } else if(!helper.isInCurrPkg(clazz)){ if(clazz.contains(CONSTANTS.$$)) { mDesc = helper.getDescriptorOfApplyMethod(methCallType); - //helper.generateBCForFunN(mDesc); //old - //ToDo Etienne: Refactor - /* - FunN f; - ASTToIntermediate converter = new ASTToIntermediate(); - IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.getType())); - List arguments = methodCall - .argTypes - .stream() - .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: Double Check RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(methodCall.getType()); List argumentTypes = methodCall .argTypes @@ -877,13 +836,10 @@ public class BytecodeGenMethod implements StatementVisitor { .map(resolver::resolve) .collect(Collectors.toList()); FunNUtilities funNUtilities = FunNGenerator.getInstance(); - byte[] superBytecode = funNUtilities.generateSuperBytecode(argumentTypes.size()); - byte[] specializedBytecode = funNUtilities.generateSpecializedBytecode(argumentTypes, returnType); - FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), superBytecode, path); - FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), specializedBytecode, path); - //*/ - //ToDo Etienne End -// mDesc = helper.generateBCForFunN(methCallType,typesOfParams); + FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), + funNUtilities.generateSuperBytecode(argumentTypes.size()), path); + FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), + funNUtilities.generateSpecializedBytecode(argumentTypes, returnType), path); }else { try { cLoader2 = new DirectoryClassLoader(path, classLoader); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java index dd4f62a2..932770ed 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java @@ -8,7 +8,6 @@ public class TypeToDescriptor implements TypeVisitor{ @Override public String visit(RefType refType) { - //ToDo Etienne: check if it works if (refType.getName().toString().matches("Fun\\d+\\$\\$") && refType.getParaList().size() > 0) { FunNUtilities funNUtilities = FunNGenerator.getInstance(); return funNUtilities.getSpecializedDescriptor(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList())); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java index d545723b..7ae4da4d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java @@ -31,4 +31,6 @@ public interface FunNUtilities { } return false; } + + } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java index 53b39b3a..c3249f03 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java @@ -31,7 +31,6 @@ public class TypeToSignature implements TypeVisitor { public String visit(RefType refType) { if(refType.getName().toString().equals("void")) return "V"; - //ToDo Etienne: check if it works if (refType.getName().toString().matches("Fun\\d+\\$\\$") && refType.getParaList().size() > 0){ FunNUtilities funNUtilities = FunNGenerator.getInstance(); return funNUtilities.getSpecializedSignature(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList()));