Compare commits
22 Commits
strucTypes
...
UnifyDepen
Author | SHA1 | Date | |
---|---|---|---|
1a2454e00b | |||
bc1a796e28 | |||
b8e229cf3f | |||
e0c5afcd6d | |||
9123e222f4 | |||
29bd9a3f4f | |||
7926c25c7d | |||
b4c604e2b1 | |||
d8bb4d6188 | |||
0ecaf36648 | |||
2eb7a63480 | |||
11649b39d3 | |||
303cfa5409 | |||
660ef68f7e | |||
23eab0c9a4 | |||
162ca3eb27 | |||
6d70464a1c | |||
04d3ac84e7 | |||
2db5ecc260 | |||
b325e205a1 | |||
ff2bca5ce5 | |||
66078360da |
src/de/dhbwstuttgart
.DS_Store
bytecode
core
syntaxtree
typeinference
assumptions
typeAlgo
unify
test
bytecode
BinaryTest.javaFacTest.javaGenTest.javaGreaterEqualTest.javaGreaterThanTest.javaLambdaTest.javaLessEqualTest.javaLessThanTest.javaMatrixTest.javaOLTest.javaOpTest.javaOverloadingTest.javaPlusTest.javaPostIncTest.javaPreIncTest.javaRelOpsTest.javaStaticTest.javaTph2Test.javaTphTest.javaWhileTest.java
javFiles
javFiles
typeinference
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
Binary file not shown.
@ -17,6 +17,7 @@ import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
@ -28,6 +29,8 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
@ -41,8 +44,13 @@ public class BytecodeGen implements ASTVisitor {
|
||||
private boolean isInterface;
|
||||
private List<ResultSet> listOfResultSets;
|
||||
private ResultSet resultSet;
|
||||
|
||||
private String path;
|
||||
|
||||
private int indexOfFirstParam = 0;
|
||||
|
||||
private String superClass;
|
||||
|
||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
// stores generics and their bounds of class
|
||||
@ -50,22 +58,26 @@ public class BytecodeGen implements ASTVisitor {
|
||||
// stores generics and their bounds of method
|
||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||
|
||||
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||
private final ArrayList<GenericInsertPair> commonPairs = new ArrayList<>();
|
||||
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||
byte[] bytecode;
|
||||
HashMap<String,byte[]> classFiles;
|
||||
|
||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets, String path) {
|
||||
this.classFiles = classFiles;
|
||||
this.listOfResultSets = listOfResultSets;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SourceFile sourceFile) {
|
||||
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||
System.out.println("in Class: " + cl.getClassName().toString());
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets,path);
|
||||
cl.accept(classGen);
|
||||
classGen.writeClass(cl.getClassName().toString());
|
||||
}
|
||||
@ -90,6 +102,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
|
||||
className = classOrInterface.getClassName().toString();
|
||||
|
||||
cw.visitSource(className +".jav", null);
|
||||
@ -97,27 +110,41 @@ public class BytecodeGen implements ASTVisitor {
|
||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||
|
||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds);
|
||||
sig = signature.toString();
|
||||
}
|
||||
// needs implemented Interfaces?
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
// resultSet = listOfResultSets.get(0);
|
||||
boolean isConsWithNoParamsVisited = false;
|
||||
boolean isVisited = false;
|
||||
for(ResultSet rs : listOfResultSets) {
|
||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||
resultSet = rs;
|
||||
// Nur einmal ausführen!!
|
||||
if(!isVisited) {
|
||||
classOrInterface.accept(tphExtractor);
|
||||
|
||||
getCommonTPHS(tphExtractor);
|
||||
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs);
|
||||
sig = signature.toString();
|
||||
System.out.println("Signature: => " + sig);
|
||||
}
|
||||
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
isVisited = true;
|
||||
}
|
||||
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
for(Constructor c : classOrInterface.getConstructors()) {
|
||||
if(!isConsWithNoParamsVisited)
|
||||
c.accept(this);
|
||||
@ -133,6 +160,16 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
}
|
||||
|
||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||
// Gemeinsame TPHs
|
||||
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
||||
// Alle TPHs der Felder speichern
|
||||
for(TypePlaceholder tph : tphExtractor.allTPHS.keySet()) {
|
||||
if(!tphExtractor.allTPHS.get(tph))
|
||||
cTPHs.add(tph);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
field.getParameterList().accept(this);
|
||||
@ -156,8 +193,8 @@ public class BytecodeGen implements ASTVisitor {
|
||||
desc = constructor.accept(new DescriptorToString(resultSet));
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path);
|
||||
if(!field.getParameterList().iterator().hasNext()) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
@ -215,11 +252,14 @@ public class BytecodeGen implements ASTVisitor {
|
||||
/* if method has generics or return type is TPH, create signature */
|
||||
// zwite operand muss weggelassen werden
|
||||
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
||||
// resultset hier zum testen
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||
|
||||
ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs);
|
||||
System.out.println(method.name + " => Simplified Pairs: ");
|
||||
pairs.forEach(p->System.out.println(p.TA1.getName() + " -> "+p.TA2.getName()));
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet, pairs);
|
||||
sig = signature.toString();
|
||||
}
|
||||
// System.out.println(sig);
|
||||
System.out.println(method.getName()+" ==> "+sig);
|
||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||
|
||||
@ -227,13 +267,103 @@ public class BytecodeGen implements ASTVisitor {
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
||||
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path);
|
||||
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> simplifyPairs(String methodName, ArrayList<GenericInsertPair> allPairs) {
|
||||
allPairs.forEach(p->System.out.print(p.TA1 + " < "+ p.TA2+ " ; "));
|
||||
|
||||
if(allPairs.size() < 2)
|
||||
return allPairs;
|
||||
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
|
||||
|
||||
MethodAndTPH method;
|
||||
ArrayList<TypePlaceholder> methodTphs = new ArrayList<>();
|
||||
ArrayList<GenericInsertPair> methodPairs = new ArrayList<>();
|
||||
for(MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
||||
if(m.getName().equals(methodName)) {
|
||||
methodTphs = m.getTphs();
|
||||
methodPairs = m.getPairs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||
for(GenericInsertPair p : allPairs) {
|
||||
// Tph2.jav
|
||||
if(subAndSuperTph.containsKey(p.TA1)) {
|
||||
if(methodTphs.contains(subAndSuperTph.get(p.TA1)))
|
||||
continue;
|
||||
}
|
||||
subAndSuperTph.put(p.TA1, p.TA2);
|
||||
}
|
||||
int numOfVisitedPairs = 0;
|
||||
for(TypePlaceholder subTph: subAndSuperTph.keySet()) {
|
||||
|
||||
if(numOfVisitedPairs>=subAndSuperTph.size())
|
||||
break;
|
||||
|
||||
if(!methodTphs.contains(subTph))
|
||||
continue;
|
||||
|
||||
HashMap<Integer, TypePlaceholder> tphsInRel= new HashMap<>();
|
||||
|
||||
tphsInRel.put(tphsInRel.size(), subTph);
|
||||
TypePlaceholder superTph = subAndSuperTph.get(subTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
|
||||
numOfVisitedPairs++;
|
||||
|
||||
while(subAndSuperTph.containsKey(superTph)) {
|
||||
superTph = subAndSuperTph.get(superTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
TypePlaceholder subTphRes = tphsInRel.get(0);
|
||||
// Die größte Supertype
|
||||
TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1);
|
||||
|
||||
while(subAndSuperTph.containsValue(subTphRes)) {
|
||||
for(TypePlaceholder tph : subAndSuperTph.keySet()) {
|
||||
if(methodTphs.contains(tph) && subAndSuperTph.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(subTphRes.equals(tphsInRel.get(0))) {
|
||||
break;
|
||||
}
|
||||
tphsInRel.put(0, subTphRes);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphsInRel.get(0);
|
||||
|
||||
int i = 2;
|
||||
while(!methodTphs.contains(superTphRes) && (tphsInRel.size()-i) >0) {
|
||||
superTphRes = tphsInRel.get(tphsInRel.size()-i);
|
||||
i++;
|
||||
}
|
||||
// teste noch den Fall X < Y und Y nicht in TPHS der Methode
|
||||
// Dann hat man nach der While-Schleife X < Y
|
||||
// Y muss durch Object ersetzt.
|
||||
|
||||
// Zweite Operand für die Fälle wie in Lambda.jav (Paramtrisierte Typen)
|
||||
if(methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes)) {
|
||||
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes);
|
||||
simplifiedPairs.add(sPair);
|
||||
}
|
||||
}
|
||||
return simplifiedPairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
paramsAndLocals = new HashMap<>();
|
||||
@ -475,5 +605,50 @@ public class BytecodeGen implements ASTVisitor {
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private class TPHExtractor extends AbstractASTWalker{
|
||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||
final HashMap<TypePlaceholder,Boolean> allTPHS = new HashMap<>();
|
||||
MethodAndTPH methodAndTph;
|
||||
Boolean inMethod = false;
|
||||
final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
if(resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||
if(inMethod)
|
||||
methodAndTph.getTphs().add(resolvedTPH);
|
||||
|
||||
allTPHS.put(resolvedTPH,inMethod);
|
||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{
|
||||
if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) {
|
||||
if(inMethod)
|
||||
methodAndTph.getPairs().add(ag);
|
||||
allPairs.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||
for(int i=0; i<pairs.size();++i) {
|
||||
GenericInsertPair p = pairs.get(i);
|
||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
methodAndTph = new MethodAndTPH(method.name);
|
||||
super.visit(method);
|
||||
inMethod = false;
|
||||
ListOfMethodsAndTph.add(methodAndTph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,15 +29,18 @@ import org.objectweb.asm.signature.SignatureWriter;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class BytecodeGenMethod implements StatementVisitor {
|
||||
@ -50,10 +53,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
private ClassWriter cw;
|
||||
private ResultSet resultSet;
|
||||
private boolean isInterface;
|
||||
HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String, String> genericsAndBounds;
|
||||
private boolean isBinaryExp = false;
|
||||
|
||||
private String superClass;
|
||||
private String path;
|
||||
private IStatement statement = null;
|
||||
|
||||
// for tests **
|
||||
@ -67,11 +71,12 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||
|
||||
public BytecodeGenMethod(String className, ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||
|
||||
this.className = className;
|
||||
this.superClass = superClass;
|
||||
this.resultSet = resultSet;
|
||||
this.m = m;
|
||||
this.mv = mv;
|
||||
@ -81,19 +86,21 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
|
||||
this.path = path;
|
||||
|
||||
if (!isInterface)
|
||||
this.m.block.accept(this);
|
||||
|
||||
}
|
||||
|
||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||
|
||||
this.resultSet = resultSet;
|
||||
this.mv = mv;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
this.path = path;
|
||||
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
int i = indexOfFirstParamLam;
|
||||
@ -104,7 +111,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
}
|
||||
|
||||
|
||||
public void isBinary(boolean isBinary) {
|
||||
this.isBinaryExp =isBinary;
|
||||
}
|
||||
|
||||
private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
@ -120,7 +131,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
public void visit(SuperCall superCall) {
|
||||
superCall.receiver.accept(this);
|
||||
superCall.arglist.accept(this);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), superCall.name, "()V",
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.superClass, superCall.name, "()V",
|
||||
isInterface);
|
||||
}
|
||||
|
||||
@ -167,6 +178,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
doBoxing(binaryType);
|
||||
isBinaryExp = false;
|
||||
}
|
||||
System.out.println("ASSIGN TYPE R: " + getResolvedType(assign.rightSide.getType()));
|
||||
String typeOfRightSide = getResolvedType(assign.rightSide.getType());
|
||||
if(typeOfRightSide.contains("<")) {
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, typeOfRightSide.substring(0, typeOfRightSide.indexOf('<')));
|
||||
}
|
||||
assign.lefSide.accept(this);
|
||||
|
||||
statement = null;
|
||||
@ -520,7 +536,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
methodName, arg3.toString(), null, null);
|
||||
|
||||
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||
classFiles);
|
||||
classFiles,this.path);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
@ -561,7 +577,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
try {
|
||||
System.out.println("generating " + name + ".class file...");
|
||||
output = new FileOutputStream(
|
||||
new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" + name + ".class"));
|
||||
new File(path + name + ".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name + ".class file generated");
|
||||
@ -621,14 +637,30 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
|
||||
|
||||
//ClassLoader.getSystemClassLoader().loadClass(className).getMethod(name, parameterTypes)
|
||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
try {
|
||||
java.lang.reflect.Method[] methods = cl.loadClass("java.util.Vector").getMethods();
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
for(java.lang.reflect.Method m : methods) {
|
||||
System.out.println(m.getName() + " " + m.toGenericString()+ " ==> ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.arglist.accept(this);
|
||||
|
||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||
genericsAndBoundsMethod, genericsAndBounds);
|
||||
String mDesc = method.accept(new DescriptorToString(resultSet));
|
||||
|
||||
System.out.println("Methodcall Desc : " + mDesc);
|
||||
// is methodCall.receiver functional Interface)?
|
||||
if (varsFunInterface.contains(methodCall.receiver.getType())) {
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name,
|
||||
@ -641,6 +673,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// if(!methodCall.getType().toString().equals("V")) {
|
||||
// mv.visitInsn(Opcodes.POP);
|
||||
// }
|
||||
if(isBinaryExp) {
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -799,7 +834,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock);
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
whileStmt.expr.accept(this);
|
||||
isBinaryExp = false;
|
||||
// isBinaryExp = false;
|
||||
statement = null;
|
||||
}
|
||||
|
||||
@ -1040,13 +1075,18 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
String var = assignLeftSide.localVar.name;
|
||||
if (!paramsAndLocals.containsKey(var)) {
|
||||
paramsAndLocals.put(var, index + 1);
|
||||
} else {
|
||||
paramsAndLocals.put(var, index);
|
||||
}
|
||||
|
||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.get(var));
|
||||
}
|
||||
|
||||
private class TPHEx extends AbstractASTWalker{
|
||||
// Liste enthält alle tph der Methode
|
||||
ArrayList<TypePlaceholder> allTPHS = new ArrayList<>();
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
allTPHS.add(tph);
|
||||
}
|
||||
|
||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size());
|
||||
// Debug:::
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class LoopStmt extends AStatement {
|
||||
|
||||
@Override
|
||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||
bytecodeGenMethod.isBinary(false);
|
||||
this.loopBlock.accept(bytecodeGenMethod);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||
@ -49,7 +51,8 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
desc += "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
}
|
||||
@ -76,7 +79,8 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
}else {
|
||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += ")" + "L"+resType+ ";";
|
||||
}
|
||||
@ -119,9 +123,21 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
|
||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + "L"+ d + ";";
|
||||
}
|
||||
}
|
||||
|
||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = addReturnType(desc, lambdaExpression.getReturnType(), resultSet);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -131,9 +147,22 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
|
||||
while(itr.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+ d + ";";
|
||||
|
||||
}
|
||||
}
|
||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = desc + ")"+"L"+resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -141,26 +170,34 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
public String visit(MethodFromMethodCall methodFromMethodCall) {
|
||||
String desc = "(";
|
||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||
String d = e.getType().acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.toString().equals("void")) {
|
||||
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
System.out.println("DescriptorToString retType = " + retType);
|
||||
if(retType.equals("void")) {
|
||||
desc += ")V";
|
||||
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
String ret = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(ret)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(ret)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(ret)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(ret)+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(retType)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(retType)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(retType)+ ";";
|
||||
}else {
|
||||
desc += ")" + "L"+resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
desc += ")" + "L"+retType+ ";";
|
||||
}
|
||||
}
|
||||
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
|
||||
|
@ -19,7 +19,9 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return superWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,6 +31,7 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -8,13 +9,19 @@ import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class Signature {
|
||||
@ -26,10 +33,13 @@ public class Signature {
|
||||
private Method method;
|
||||
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||
private ResultSet resultSet;
|
||||
private ArrayList<GenericInsertPair> commonPairs;
|
||||
private ArrayList<GenericInsertPair> methodPairs;
|
||||
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds) {
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,ArrayList<GenericInsertPair> commonPairs) {
|
||||
this.classOrInterface = classOrInterface;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.commonPairs = commonPairs;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForClassOrInterface();
|
||||
}
|
||||
@ -42,12 +52,14 @@ public class Signature {
|
||||
createSignatureForConsOrMethod(this.constructor,true);
|
||||
}
|
||||
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet) {
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,HashMap<String, String> genericsAndBounds,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet, ArrayList<GenericInsertPair> methodPairs) {
|
||||
this.method = method;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
this.resultSet = resultSet;
|
||||
this.methodPairs = methodPairs;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.method,false);
|
||||
}
|
||||
@ -92,27 +104,92 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
|
||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
if(ret.substring(0,4).equals("TPH ")) {
|
||||
String g = ret.substring(4)+"$";
|
||||
sw.visitFormalTypeParameter(g);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
String g = ret.substring(4,ret.length())+"$";
|
||||
if(genericsAndBounds.containsKey(g)) {
|
||||
genericsAndBoundsMethod.put(g, genericsAndBounds.get(g));
|
||||
}else {
|
||||
sw.visitFormalTypeParameter(g);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.contains("<")) {
|
||||
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
||||
if(hasTPHs(ref)) {
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Parameters
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||
String pT = t.acceptTV(new TypeToSignature());
|
||||
// S.o
|
||||
if(pT.substring(0,4).equals("TPH ") && !genericsAndBoundsMethod.containsKey(pT)) {
|
||||
String gP = pT.substring(4)+"$";
|
||||
sw.visitFormalTypeParameter(gP);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
genericsAndBoundsMethod.put(gP, Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
if(pT.substring(0,4).equals("TPH ")) {
|
||||
String gP = pT.substring(4,pT.length())+"$";
|
||||
if(!genericsAndBounds.containsKey(gP) && !genericsAndBoundsMethod.containsKey(gP)) {
|
||||
sw.visitFormalTypeParameter(gP);
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
boolean isTypeVar = false;
|
||||
for(GenericInsertPair pair : methodPairs) {
|
||||
if(pT.substring(4).equals(pair.TA1.getName())) {
|
||||
bound = pair.TA2.getName()+"$";
|
||||
isTypeVar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(isTypeVar) {
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
}else {
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
||||
genericsAndBoundsMethod.put(gP, bound);
|
||||
}
|
||||
}
|
||||
|
||||
if(pT.contains("<")) {
|
||||
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||
if(hasTPHs(ref))
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p:methodPairs) {
|
||||
String name = p.TA1.getName()+"$";
|
||||
if(!genericsAndBoundsMethod.containsKey(name)) {
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitTypeVariable(p.TA2.getName()+"$");
|
||||
genericsAndBoundsMethod.put(name, p.TA2.getName()+"$");
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
for(GenericInsertPair p : methodPairs) {
|
||||
types.add(p.TA1);
|
||||
superTypes.add(p.TA2);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : methodPairs) {
|
||||
String name = p.TA2.getName()+"$";
|
||||
if(!types.contains(p.TA2) && !genericsAndBoundsMethod.containsKey(name)) {
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBoundsMethod.put(name, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,21 +202,148 @@ public class Signature {
|
||||
if(isConstructor) {
|
||||
sw.visitReturnType().visitBaseType('V');
|
||||
}else {
|
||||
// String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
// if(ret.substring(0,4).equals("TPH ")) {
|
||||
// String g = ret.substring(4);
|
||||
// if(!genericsAndBoundsMethod.containsKey(g)) {
|
||||
// genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||
// } else {
|
||||
// genericsAndBoundsMethod.put(g+"_", Type.getInternalName(Object.class));
|
||||
// }
|
||||
// }
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
// return type deswegen ist false
|
||||
doVisitParamsOrReturn(returnType, false);
|
||||
}
|
||||
// sw.visitEnd();
|
||||
}
|
||||
|
||||
private void createSignatureForParameterizedType(RefType ref) {
|
||||
ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||
allPairs.addAll(methodPairs);
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||
|
||||
HashMap<String, String> names = new HashMap<>();
|
||||
|
||||
for(GenericInsertPair pair : simplifiedPairs) {
|
||||
if(ref.getParaList().contains(pair.TA1)) {
|
||||
String sub = pair.TA1.getName()+"$";
|
||||
String superT = pair.TA2.getName()+"$";
|
||||
names.put(sub, superT);
|
||||
}
|
||||
}
|
||||
|
||||
for(String sub : names.keySet()) {
|
||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
sw.visitFormalTypeParameter(sub);
|
||||
String bound = names.get(sub);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBoundsMethod.put(sub, bound);
|
||||
}
|
||||
}
|
||||
|
||||
for(String superT : names.values()) {
|
||||
if(!names.containsKey(superT)) {
|
||||
if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||
sw.visitFormalTypeParameter(superT);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) {
|
||||
if(p instanceof TypePlaceholder) {
|
||||
String name = ((TypePlaceholder) p).getName() + "$";
|
||||
if(!genericsAndBoundsMethod.containsKey(name) && !genericsAndBounds.containsKey(name)) {
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(name, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> getAllPairs(RefType ref) {
|
||||
final ArrayList<GenericInsertPair> res = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resultSet.resolveType(p).resolvedType;
|
||||
if(resolved instanceof TypePlaceholder) {
|
||||
resultSet.resolveType(p).additionalGenerics.forEach(ag ->{
|
||||
if(!contains(res,ag)) {
|
||||
res.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||
for(int i=0; i<pairs.size();++i) {
|
||||
GenericInsertPair p = pairs.get(i);
|
||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> simplifyPairs(ArrayList<GenericInsertPair> allPairs) {
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
|
||||
|
||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||
for(GenericInsertPair p : allPairs) {
|
||||
subAndSuperTph.put(p.TA1, p.TA2);
|
||||
}
|
||||
|
||||
subAndSuperTph.forEach((k,v)->System.out.println(k.getName() + " || " + v.getName()));
|
||||
|
||||
int numOfVisitedPairs = 0;
|
||||
for(TypePlaceholder subTph: subAndSuperTph.keySet()) {
|
||||
|
||||
if(numOfVisitedPairs>=subAndSuperTph.size())
|
||||
break;
|
||||
|
||||
HashMap<Integer, TypePlaceholder> tphsInRel= new HashMap<>();
|
||||
|
||||
tphsInRel.put(tphsInRel.size(), subTph);
|
||||
TypePlaceholder superTph = subAndSuperTph.get(subTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
|
||||
numOfVisitedPairs++;
|
||||
|
||||
while(subAndSuperTph.containsKey(superTph)) {
|
||||
superTph = subAndSuperTph.get(superTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
TypePlaceholder subTphRes = tphsInRel.get(0);
|
||||
// Die größte Supertype
|
||||
TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1);
|
||||
|
||||
|
||||
while(subAndSuperTph.containsValue(subTphRes)) {
|
||||
for(TypePlaceholder tph : subAndSuperTph.keySet()) {
|
||||
if(subAndSuperTph.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tphsInRel.put(0, subTphRes);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphsInRel.get(0);
|
||||
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes);
|
||||
simplifiedPairs.add(sPair);
|
||||
}
|
||||
return simplifiedPairs;
|
||||
}
|
||||
|
||||
private boolean hasTPHs(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
if(resultSet.resolveType(p).resolvedType instanceof TypePlaceholder)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||
* the method signature
|
||||
@ -194,7 +398,34 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||
}
|
||||
|
||||
if(!commonPairs.isEmpty()) {
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
types.add(p.TA1);
|
||||
superTypes.add(p.TA2);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
String t = p.TA1.getName()+"$";
|
||||
String bound = p.TA2.getName()+"$";
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
if(!types.contains(p.TA2)) {
|
||||
String t = p.TA2.getName()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));;
|
||||
sw.visitEnd();
|
||||
}
|
||||
|
@ -22,7 +22,12 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||
while(it.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
if(param instanceof TypePlaceholder) {
|
||||
params += "T" + ((TypePlaceholder) param).getName() + "$";
|
||||
} else {
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
}
|
||||
|
||||
if(it.hasNext())params += ";";
|
||||
}
|
||||
params += ";>";
|
||||
|
29
src/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
Normal file
29
src/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
Normal file
@ -0,0 +1,29 @@
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
|
||||
public class MethodAndTPH {
|
||||
|
||||
private String name;
|
||||
private final ArrayList<TypePlaceholder> tphs = new ArrayList<>();
|
||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||
|
||||
public MethodAndTPH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<TypePlaceholder> getTphs() {
|
||||
return tphs;
|
||||
}
|
||||
|
||||
public ArrayList<GenericInsertPair> getPairs(){
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -240,25 +240,26 @@ public class JavaTXCompiler {
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void generateBytecode() throws ClassNotFoundException, IOException {
|
||||
// um pfad erweitern
|
||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
||||
for(File f : sourceFiles.keySet()) {
|
||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult);
|
||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,path);
|
||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||
bytecodeGen.visit(sf);
|
||||
this.writeClassFile(bytecodeGen.getClassFiles());
|
||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeClassFile(HashMap<String, byte[]> classFiles) throws IOException {
|
||||
private void writeClassFile(HashMap<String, byte[]> classFiles, String path) throws IOException {
|
||||
FileOutputStream output;
|
||||
for(String name : classFiles.keySet()) {
|
||||
byte[] bytecode = classFiles.get(name);
|
||||
System.out.println("generating "+name+ ".class file ...");
|
||||
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
|
||||
//output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
|
||||
output = new FileOutputStream(new File(path +name+".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name+".class file generated");
|
||||
|
@ -208,7 +208,7 @@ public class UnifyTypeFactory {
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
|
||||
RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken());
|
||||
RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class FunN extends RefType {
|
||||
* @return
|
||||
*/
|
||||
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
|
||||
super(new JavaClassName("Fun"+params.size()), params, new NullToken());
|
||||
super(new JavaClassName("Fun"+(params.size())), params, new NullToken());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,32 +8,36 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FunNClass extends ClassOrInterface {
|
||||
public FunNClass(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||
super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(),
|
||||
public FunNClass(List<GenericRefType> funNParams) {
|
||||
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(),
|
||||
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
||||
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static GenericDeclarationList createGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||
private static GenericDeclarationList createGenerics(List<GenericRefType> funNParams) {
|
||||
//PL 2018-06-22: so geaendert, dass generierte Generics den Namen der funParams entsprechen.
|
||||
List<GenericTypeVar> generics = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : funNParams){
|
||||
generics.add(new GenericTypeVar(NameGenerator.makeNewName(),
|
||||
for(GenericRefType param : funNParams){
|
||||
generics.add(new GenericTypeVar(param.getParsedName(),//NameGenerator.makeNewName(),
|
||||
new ArrayList<>(), new NullToken(), new NullToken()));
|
||||
}
|
||||
return new GenericDeclarationList(generics, new NullToken());
|
||||
}
|
||||
|
||||
private static List<Method> createMethods(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||
private static List<Method> createMethods(List<GenericRefType> funNParams) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ import java.util.List;
|
||||
public class MethodAssumption extends Assumption{
|
||||
private ClassOrInterface receiver;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||
|
||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
||||
super(scope);
|
||||
this.receiver = receiver;
|
||||
this.retType = retType;
|
||||
@ -38,7 +38,9 @@ public class MethodAssumption extends Assumption{
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
||||
if(retType instanceof GenericRefType)return resolver.resolve(retType);
|
||||
if(retType instanceof GenericRefType) {
|
||||
return resolver.resolve(retType);
|
||||
}
|
||||
return retType;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
@ -327,7 +328,16 @@ public class TYPEStmt implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
//Nothing to do here. Literale erzeugen keine Constraints
|
||||
//Nothing to do here. Literale erzeugen keine Constraints
|
||||
//PL 2018-06-23 Sie haben einen Typ. Der muesste hier eingefuegt werden
|
||||
//wie hier fuer double gezeigt. Im Momment auskommentiert, weil zu wenige Literaltypen
|
||||
//funktionieren
|
||||
//if (literal.value instanceof Double) {
|
||||
// constraintsSet.addUndConstraint(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
//else {
|
||||
// throw new NotImplementedException();
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -451,11 +461,14 @@ public class TYPEStmt implements StatementVisitor{
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
||||
if(name.equals("apply")){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
List<GenericRefType> funNParams = new ArrayList<>();
|
||||
for(int i = 0; i< numArgs + 1 ; i++){
|
||||
funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||
//funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||
funNParams.add(new GenericRefType(NameGenerator.makeNewName(),
|
||||
new NullToken()));
|
||||
}
|
||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()),
|
||||
funNParams.get(funNParams.size()-1);
|
||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size()-1), funNParams.subList(0, funNParams.size()-1),
|
||||
new TypeScope() {
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
@ -498,7 +511,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
*/
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(FormalParameter fp : parameterList.getFormalparalist()){
|
||||
params.add(info.checkGTV(fp.getType()));
|
||||
params.add(fp.getType()); //info.checkGTV(fp.getType())); //PL 2018-06-22 GTV sollen in Argumenten erhalten bleiben
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
@ -938,7 +938,9 @@ public class RuleSet implements IRuleSet{
|
||||
else {
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
Set<UnifyType> fBounded = pair.getfBounded();
|
||||
fBounded.add(lhsType);
|
||||
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
|
@ -13,6 +13,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -144,12 +145,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* @return The set of all principal type unifiers
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||
).collect(Collectors.toCollection(HashSet::new));
|
||||
writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||
if (aas.isEmpty()) {
|
||||
System.out.println("");
|
||||
}
|
||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||
// ).collect(Collectors.toCollection(HashSet::new));
|
||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||
//if (aas.isEmpty()) {
|
||||
// System.out.println("");
|
||||
//}
|
||||
/*
|
||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||
*/
|
||||
@ -447,6 +448,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
System.out.print("");
|
||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||
System.out.print("");
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a = null;
|
||||
if (variance == 1) {
|
||||
@ -488,6 +490,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||
elems.add(a);
|
||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
||||
//writeLog("Vor unify2 Aufruf: " + eq.toString());
|
||||
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
|
||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
@ -512,7 +515,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
|
||||
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||
//}
|
||||
|
||||
|
||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
|
||||
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
|
||||
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||
System.out.print("");
|
||||
@ -542,6 +546,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
||||
|
||||
if (isUndefinedPairSetSet(res)) {
|
||||
Set<UnifyPair> abhSubst = res.stream()
|
||||
.map(b ->
|
||||
@ -1094,7 +1100,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
UnifyType supAPrime = new SuperType(aPrime);
|
||||
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
|
||||
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
|
||||
@ -1124,14 +1130,34 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
break;
|
||||
}
|
||||
|
||||
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
|
||||
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
Match match = new Match();
|
||||
|
||||
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
||||
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
|
||||
Set<UnifyType> fBounded = pair.getfBounded();
|
||||
|
||||
int i_ef = i;
|
||||
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
||||
{
|
||||
ArrayList<UnifyPair> termList = new ArrayList<UnifyPair>();
|
||||
termList.add(new UnifyPair(y,thetaS.getTypeParams().get(i_ef), PairOperator.EQUALSDOT));
|
||||
return ((match.match(termList).isPresent()) || x);
|
||||
};
|
||||
//if (parai.getName().equals("java.lang.Integer")) {
|
||||
// System.out.println("");
|
||||
//}
|
||||
BinaryOperator<Boolean> bo = (x,y) -> (x || y);
|
||||
if (fBounded.stream().reduce(false,f,bo)) {
|
||||
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
}
|
||||
else {
|
||||
fBounded.add(thetaS.getTypeParams().get(i));
|
||||
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded));
|
||||
}
|
||||
}
|
||||
|
||||
if(allGen)
|
||||
@ -1165,9 +1191,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
((PlaceholderType)freshTph).setVariance(a.getVariance());
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
|
||||
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
//writeLog("resultPrime: " + resultPrime.toString());
|
||||
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
|
@ -102,7 +102,7 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
|
||||
}
|
||||
return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p);
|
||||
}
|
||||
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair());
|
||||
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair(), p.getfBounded());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,13 @@ public class UnifyPair {
|
||||
* PL 2018-03-15
|
||||
*/
|
||||
private UnifyPair basePair;
|
||||
|
||||
/**
|
||||
* For pairs a <. Theta generated in the rule reduceTphSup
|
||||
* to store the f-Bouned Elements to avoid endless recursion
|
||||
* PL 2018-03-15
|
||||
*/
|
||||
private Set<UnifyType> fBounded = new HashSet<>();
|
||||
|
||||
private final int hashCode;
|
||||
|
||||
@ -82,6 +89,12 @@ public class UnifyPair {
|
||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||
}
|
||||
|
||||
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<UnifyPair> uni, UnifyPair base, Set<UnifyType> fBounded) {
|
||||
this(lhs, rhs, op, uni, base);
|
||||
|
||||
this.fBounded = fBounded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type on the left hand side of the pair.
|
||||
*/
|
||||
@ -138,6 +151,10 @@ public class UnifyPair {
|
||||
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
||||
}
|
||||
|
||||
public Set<UnifyType> getfBounded() {
|
||||
return this.fBounded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof UnifyPair))
|
||||
@ -177,7 +194,7 @@ public class UnifyPair {
|
||||
if (rhs instanceof PlaceholderType) {
|
||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
||||
}
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")";
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -25,8 +25,8 @@ public class BinaryTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/BinaryInMeth.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("BinaryInMeth");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -27,8 +27,8 @@ public class FacTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Fac.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Fac");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
@ -37,8 +37,8 @@ public class FacTest {
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||
assertEquals(result, 6);
|
||||
Double result = (Double) getFac.invoke(instanceOfClass,3);
|
||||
assertEquals(result, 6.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ public class GenTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Gen.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Gen");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -28,8 +28,8 @@ public class GreaterEqualTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterEqual.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("GreaterEqual");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -28,8 +28,8 @@ public class GreaterThanTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterThan.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("GreaterThan");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -16,7 +16,7 @@ public class LambdaTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ public class LessEqualTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessEqual.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("LessEqual");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -28,8 +28,8 @@ public class LessThanTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessThan.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("LessThan");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -25,8 +25,8 @@ public class MatrixTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Matrix");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -25,8 +25,8 @@ public class OLTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/OL.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("OL");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -28,8 +28,8 @@ public class OpTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Op.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Op");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -30,8 +30,8 @@ public class OverloadingTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Overloading.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Overloading");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -27,9 +27,8 @@ public class PlusTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Plus.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Plus");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -27,8 +27,8 @@ public class PostIncTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PostIncDec.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("PostIncDec");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -27,8 +27,8 @@ public class PreIncTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PreInc.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
||||
classToTest = loader.loadClass("PreInc");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -27,8 +27,8 @@ public class RelOpsTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/RelOps.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("RelOps");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -26,8 +26,8 @@ public class StaticTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/StaticM.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
||||
classToTest = loader.loadClass("StaticM");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
41
test/bytecode/Tph2Test.java
Normal file
41
test/bytecode/Tph2Test.java
Normal file
@ -0,0 +1,41 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class Tph2Test {
|
||||
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Tph2.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Tph2");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
40
test/bytecode/TphTest.java
Normal file
40
test/bytecode/TphTest.java
Normal file
@ -0,0 +1,40 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class TphTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Tph.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Tph");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
@ -27,8 +27,8 @@ public class WhileTest {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/While.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("While");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -4,7 +4,7 @@ import java.lang.Double;
|
||||
|
||||
public class Fac {
|
||||
|
||||
java.lang.Long getFac(n){
|
||||
getFac(n){
|
||||
var res = 1;
|
||||
var i = 1;
|
||||
while(i<=n) {
|
||||
|
@ -2,14 +2,15 @@ import java.lang.Integer;
|
||||
|
||||
class Faculty {
|
||||
|
||||
Integer mul(Integer x, Integer y) {
|
||||
return x;
|
||||
}
|
||||
|
||||
m () {
|
||||
|
||||
var fact = (Integer x) -> {
|
||||
return mul(x, x);
|
||||
if (x == 1) {
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
return x * fact.apply(x-1);
|
||||
}
|
||||
};
|
||||
return fact;
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Boolean;
|
||||
|
||||
public class IfTest{
|
||||
Integer m1(Boolean b) {
|
||||
Integer i;
|
||||
|
@ -1,11 +1,15 @@
|
||||
import java.lang.Integer;
|
||||
import java.util.Vector;
|
||||
class Apply { }
|
||||
|
||||
public class Lambda {
|
||||
|
||||
m () {
|
||||
var lam1 = (Integer x) -> {
|
||||
var lam1 = (x) -> {
|
||||
return x;
|
||||
};
|
||||
return lam1;
|
||||
return lam1.apply(new Apply());
|
||||
//return lam1;
|
||||
// return new Vector();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,25 +2,25 @@ import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Boolean;
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {
|
||||
public class Matrix extends Vector<Vector<Integer>> {
|
||||
mul(m) {
|
||||
var ret = new Matrix();
|
||||
var i = 0;
|
||||
while(i < size()) {
|
||||
// var v1 = this.elementAt(i);
|
||||
var v1 = this.elementAt(i);
|
||||
// var v2 = new Vector<Integer>();
|
||||
// var j = 0;
|
||||
// while(j < v1.size()) {
|
||||
// var erg = 0;
|
||||
// var k = 0;
|
||||
// while(k < v1.size()) {
|
||||
// var k = 0;
|
||||
// while(k < v1.size()) {
|
||||
// erg = erg + v1.elementAt(k)
|
||||
// * m.elementAt(k).elementAt(j);
|
||||
// k++; }
|
||||
// v2.addElement(new Integer(erg));
|
||||
// * m.elementAt(k).elementAt(j);
|
||||
// k++; }
|
||||
// v2.addElement(new Integer(erg));
|
||||
// j++; }
|
||||
// ret.addElement(v2);
|
||||
i++;
|
||||
// i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
11
test/bytecode/javFiles/Tph.jav
Normal file
11
test/bytecode/javFiles/Tph.jav
Normal file
@ -0,0 +1,11 @@
|
||||
public class Tph {
|
||||
|
||||
m(a,b){
|
||||
var c = m2(b);
|
||||
return a;
|
||||
}
|
||||
|
||||
m2(b){
|
||||
return b;
|
||||
}
|
||||
}
|
10
test/bytecode/javFiles/Tph2.jav
Normal file
10
test/bytecode/javFiles/Tph2.jav
Normal file
@ -0,0 +1,10 @@
|
||||
public class Tph2 {
|
||||
m(a,b){
|
||||
var c = m2(a,b);
|
||||
return a;
|
||||
}
|
||||
|
||||
m2(a,b){
|
||||
return b;
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Number;
|
||||
class Apply { }
|
||||
|
||||
public class Lambda {
|
||||
|
||||
@ -7,7 +6,7 @@ public class Lambda {
|
||||
var lam1 = (x) -> {
|
||||
return x;
|
||||
};
|
||||
return lam1;
|
||||
return lam1.apply(new Apply());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,9 @@ class Matrix extends Vector<Vector<Integer>> {
|
||||
var erg = 0;
|
||||
var k = 0;
|
||||
while(k < v1.size()) {
|
||||
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
||||
// erg = add1(erg, mul1(v1.elementAt(k),
|
||||
// m.elementAt(k).elementAt(j)));
|
||||
//erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
||||
erg = add1(erg, mul1(v1.elementAt(k),
|
||||
m.elementAt(k).elementAt(j)));
|
||||
k++; }
|
||||
v2.addElement(new Integer(erg));
|
||||
j++; }
|
||||
|
@ -1,8 +1,23 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
import java.lang.Object;
|
||||
|
||||
class MyVector{
|
||||
|
||||
id(x){
|
||||
return (x.elementAt(0));
|
||||
Object i;
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
return x;
|
||||
}
|
||||
}
|
@ -28,13 +28,20 @@ public class UnifyTest {
|
||||
public void finiteClosure() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"fc.jav"));
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
@Test
|
||||
public void lambda() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"Lambda.jav"));
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void vector() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"Vector.jav"));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void lambda2() throws IOException, ClassNotFoundException {
|
||||
@ -74,6 +81,7 @@ public class UnifyTest {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void matrix() throws IOException, ClassNotFoundException {
|
||||
@ -81,6 +89,7 @@ public class UnifyTest {
|
||||
//JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav"));
|
||||
//compiler.generateBytecode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user