forked from JavaTX/JavaCompilerCore
Hinzufügen der ersten Einbeziehung der API zur Generierung der spezialisierten FunN Typen, ohne Tests.
This commit is contained in:
parent
21adeb7f26
commit
dc9a54be3b
@ -13,10 +13,14 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.*;
|
import de.dhbwstuttgart.bytecode.utilities.*;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate;
|
||||||
|
import de.dhbwstuttgart.intermediate.generation.FunN;
|
||||||
|
import de.dhbwstuttgart.intermediate.types.IntermediateInnerType;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
||||||
@ -814,7 +818,21 @@ 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);
|
//ToDo Etienne: check if it works
|
||||||
|
//helper.generateBCForFunN(mDesc);
|
||||||
|
ASTToIntermediate converter = new ASTToIntermediate();
|
||||||
|
IntermediateInnerType returnType = converter.convert(methodCall.receiver.getType());
|
||||||
|
List<IntermediateInnerType> arguments = methodCall
|
||||||
|
.arglist
|
||||||
|
.getArguments()
|
||||||
|
.stream()
|
||||||
|
.map(TypableStatement::getType)
|
||||||
|
.map(converter::convert)
|
||||||
|
.collect(Collectors.toList());//ToDo
|
||||||
|
FunN f = new FunN(arguments, returnType);
|
||||||
|
FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path);
|
||||||
|
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
|
||||||
|
//ToDo Etienne End
|
||||||
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.bytecode.descriptor;
|
package de.dhbwstuttgart.bytecode.descriptor;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@ -12,6 +13,9 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
|
//ToDo Etienne: check if it works
|
||||||
|
if (refType.getName().toString().matches("Fun\\d+\\$\\$")) return new ASTToIntermediate().convert(refType).getDescriptor();
|
||||||
|
|
||||||
return refType.getName().toString().replace(".", "/");
|
return refType.getName().toString().replace(".", "/");
|
||||||
// String t = refType.getName().toString().replace(".", "/");
|
// String t = refType.getName().toString().replace(".", "/");
|
||||||
// return t.equals("Fun1")?(t+"$$"):t;
|
// return t.equals("Fun1")?(t+"$$"):t;
|
||||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
|
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@ -29,6 +30,9 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
if(refType.getName().toString().equals("void"))
|
if(refType.getName().toString().equals("void"))
|
||||||
return "V";
|
return "V";
|
||||||
|
//ToDo Etienne: check if it works
|
||||||
|
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 = "";
|
||||||
if(refType.getParaList().size()>0){
|
if(refType.getParaList().size()>0){
|
||||||
|
@ -1,14 +1,28 @@
|
|||||||
package de.dhbwstuttgart.intermediate.convert;
|
package de.dhbwstuttgart.intermediate.convert;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.intermediate.generation.FunN;
|
||||||
import de.dhbwstuttgart.intermediate.types.*;
|
import de.dhbwstuttgart.intermediate.types.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ASTToIntermediate {
|
public class ASTToIntermediate {
|
||||||
|
|
||||||
public IntermediateRefType convert(RefType originalType){
|
public IntermediateRefType convert(RefType originalType){
|
||||||
|
//ToDo Etienne: check if it works
|
||||||
|
if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){
|
||||||
|
ASTToIntermediate converter = new ASTToIntermediate();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = originalType.getParaList();
|
||||||
|
IntermediateInnerType returnType = convert(parameters.get(parameters.size() - 1));
|
||||||
|
parameters.remove(parameters.size() - 1);
|
||||||
|
return new FunN(parameters
|
||||||
|
.stream()
|
||||||
|
.map(this::convert)
|
||||||
|
.collect(Collectors.toList()), returnType);
|
||||||
|
}
|
||||||
|
|
||||||
return new IntermediateRefType(originalType.getName(),
|
return new IntermediateRefType(originalType.getName(),
|
||||||
originalType
|
originalType
|
||||||
.getParaList()
|
.getParaList()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.intermediate.generation;
|
package de.dhbwstuttgart.intermediate.generation;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
|
||||||
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
|
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
|
||||||
import de.dhbwstuttgart.intermediate.types.IntermediateInnerType;
|
import de.dhbwstuttgart.intermediate.types.IntermediateInnerType;
|
||||||
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
|
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
|
||||||
@ -9,6 +10,8 @@ import org.objectweb.asm.ClassWriter;
|
|||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -67,6 +70,8 @@ public final class FunN extends IntermediateRefType {
|
|||||||
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
|
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSuperClassName() { return superFunN.getClassName(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the bytecode for the super FunN type
|
* @return the bytecode for the super FunN type
|
||||||
*/
|
*/
|
||||||
@ -131,4 +136,16 @@ public final class FunN extends IntermediateRefType {
|
|||||||
}
|
}
|
||||||
return bytecode;
|
return bytecode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ToDo Etienne: Auslagern in andere Klasse;
|
||||||
|
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
|
||||||
|
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
|
||||||
|
output.write(bytecode);
|
||||||
|
output.flush();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user