Compare commits
No commits in common. "2c9f085cca10f3b9a4e566d97890d6f11df72e26" and "5a0e53485cff364cd5006859bab9ca11f97028bd" have entirely different histories.
2c9f085cca
...
5a0e53485c
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
Binary file not shown.
@ -1,255 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
|
||||||
|
|
||||||
public class ArgumentVisitor implements StatementVisitor {
|
|
||||||
private List<Boolean> argListMethCall;
|
|
||||||
private BytecodeGenMethod bytecodeGenMethod;
|
|
||||||
|
|
||||||
public ArgumentVisitor(List<Boolean> argListMethCall, BytecodeGenMethod bytecodeGenMethod) {
|
|
||||||
this.argListMethCall = argListMethCall;
|
|
||||||
this.bytecodeGenMethod = bytecodeGenMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ArgumentList argumentList) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
|
||||||
lambdaExpression.accept(bytecodeGenMethod);
|
|
||||||
// Zieltype des Lambas ist Funktionale Interface
|
|
||||||
// kann nie primitiv sein => un-/boxing wird hier nicht gebraucht
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Assign assign) {
|
|
||||||
assign.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(assign.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(BinaryExpr binary) {
|
|
||||||
binary.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Block block) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(CastExpr castExpr) {
|
|
||||||
castExpr.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(castExpr.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(EmptyStmt emptyStmt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(FieldVar fieldVar) {
|
|
||||||
fieldVar.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(fieldVar.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ForStmt forStmt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(IfStmt ifStmt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(InstanceOf instanceOf) {
|
|
||||||
instanceOf.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(instanceOf.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LocalVar localVar) {
|
|
||||||
localVar.accept(bytecodeGenMethod);
|
|
||||||
if(!bytecodeGenMethod.isBinaryExp) {
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(localVar.getType()));
|
|
||||||
}
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(MethodCall methodCall) {
|
|
||||||
methodCall.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(NewClass methodCall) {
|
|
||||||
methodCall.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(NewArray newArray) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Return aReturn) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ReturnVoid aReturn) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(StaticClassName staticClassName) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Super aSuper) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(This aThis) {
|
|
||||||
aThis.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(aThis.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(WhileStmt whileStmt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(DoStmt whileStmt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(AssignToField assignLeftSide) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(AssignToLocal assignLeftSide) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(SuperCall superCall) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ExpressionReceiver expressionReceiver) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(UnaryExpr unaryExpr) {
|
|
||||||
unaryExpr.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(unaryExpr.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Literal literal) {
|
|
||||||
literal.accept(bytecodeGenMethod);
|
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(literal.getType()));
|
|
||||||
argListMethCall.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -16,9 +16,7 @@ import org.objectweb.asm.Type;
|
|||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
@ -30,8 +28,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
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.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
@ -45,13 +41,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private List<ResultSet> listOfResultSets;
|
private List<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private SourceFile sf;
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
private int indexOfFirstParam = 0;
|
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,...
|
// 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<>();
|
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
// stores generics and their bounds of class
|
// stores generics and their bounds of class
|
||||||
@ -59,27 +50,22 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
// stores generics and their bounds of method
|
// stores generics and their bounds of method
|
||||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
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<>();
|
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||||
byte[] bytecode;
|
byte[] bytecode;
|
||||||
HashMap<String,byte[]> classFiles;
|
HashMap<String,byte[]> classFiles;
|
||||||
|
|
||||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.sf = sf;
|
|
||||||
this.path = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(SourceFile sourceFile) {
|
public void visit(SourceFile sourceFile) {
|
||||||
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
@ -104,7 +90,6 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
|
||||||
className = classOrInterface.getClassName().toString();
|
className = classOrInterface.getClassName().toString();
|
||||||
|
|
||||||
cw.visitSource(className +".jav", null);
|
cw.visitSource(className +".jav", null);
|
||||||
@ -112,41 +97,26 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||||
|
|
||||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||||
|
|
||||||
|
|
||||||
// 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;
|
String sig = null;
|
||||||
/* if class has generics then creates signature
|
/* if class has generics then creates signature
|
||||||
* Signature looks like:
|
* Signature looks like:
|
||||||
* <E:Ljava/...>Superclass
|
* <E:Ljava/...>Superclass
|
||||||
*/
|
*/
|
||||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
if(classOrInterface.getGenerics().iterator().hasNext()) {
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")) {
|
Signature signature = new Signature(classOrInterface, genericsAndBounds);
|
||||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs);
|
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
System.out.println("Signature: => " + sig);
|
|
||||||
}
|
}
|
||||||
|
// needs implemented Interfaces?
|
||||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||||
|
|
||||||
isVisited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Field f : classOrInterface.getFieldDecl()) {
|
for(Field f : classOrInterface.getFieldDecl()) {
|
||||||
f.accept(this);
|
f.accept(this);
|
||||||
}
|
}
|
||||||
|
// resultSet = listOfResultSets.get(0);
|
||||||
|
boolean isConsWithNoParamsVisited = false;
|
||||||
|
for(ResultSet rs : listOfResultSets) {
|
||||||
|
resultSet = rs;
|
||||||
|
|
||||||
for(Constructor c : classOrInterface.getConstructors()) {
|
for(Constructor c : classOrInterface.getConstructors()) {
|
||||||
if(!isConsWithNoParamsVisited)
|
if(!isConsWithNoParamsVisited)
|
||||||
@ -163,16 +133,6 @@ 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
|
@Override
|
||||||
public void visit(Constructor field) {
|
public void visit(Constructor field) {
|
||||||
field.getParameterList().accept(this);
|
field.getParameterList().accept(this);
|
||||||
@ -181,25 +141,23 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
boolean hasGen = false;
|
boolean hasGen = false;
|
||||||
|
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.substring(0, 4).equals("TPH ")
|
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||||
|| typeOfParam.contains("<")) {
|
|
||||||
hasGen = true;
|
hasGen = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
if(hasGen) {
|
if(hasGen) {
|
||||||
ArrayList<GenericInsertPair> pairs = simplifyPairs(field.name,tphExtractor.allPairs);
|
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes);
|
||||||
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes,resultSet,pairs);
|
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
}
|
}
|
||||||
NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen);
|
NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen);
|
||||||
desc = constructor.accept(new DescriptorToString(resultSet));
|
desc = constructor.accept(new DescriptorToString(resultSet));
|
||||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw,
|
||||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path);
|
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||||
if(!field.getParameterList().iterator().hasNext()) {
|
if(!field.getParameterList().iterator().hasNext()) {
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
}
|
}
|
||||||
@ -233,15 +191,13 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println(acc);
|
System.out.println(acc);
|
||||||
|
|
||||||
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ") ||
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ");
|
||||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).contains("<");
|
|
||||||
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
||||||
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
||||||
if(!hasGenInParameterList) {
|
if(!hasGenInParameterList) {
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) {
|
||||||
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) {
|
|
||||||
hasGenInParameterList = true;
|
hasGenInParameterList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -255,16 +211,15 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
/* method.getGenerics: <....> RT method(..)
|
/* method.getGenerics: <....> RT method(..)
|
||||||
* */
|
* */
|
||||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
|
|
||||||
/* if method has generics or return type is TPH, create signature */
|
/* if method has generics or return type is TPH, create signature */
|
||||||
// zwite operand muss weggelassen werden
|
// zwite operand muss weggelassen werden
|
||||||
if(hasGen||resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString()).equals("TPH")) {
|
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
||||||
ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs);
|
// resultset hier zum testen
|
||||||
System.out.println(method.name + " => Simplified Pairs: ");
|
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||||
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();
|
sig = signature.toString();
|
||||||
}
|
}
|
||||||
System.out.println(method.getName()+" ==> "+sig);
|
// System.out.println(sig);
|
||||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||||
|
|
||||||
@ -272,103 +227,13 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
|
||||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path);
|
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||||
|
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
mv.visitEnd();
|
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
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
paramsAndLocals = new HashMap<>();
|
paramsAndLocals = new HashMap<>();
|
||||||
@ -611,49 +476,4 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
throw new NotImplementedException();
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,9 @@ import java.lang.invoke.CallSite;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.Parameter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
@ -34,21 +29,15 @@ import org.objectweb.asm.signature.SignatureWriter;
|
|||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class BytecodeGenMethod implements StatementVisitor {
|
public class BytecodeGenMethod implements StatementVisitor {
|
||||||
@ -61,15 +50,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private ClassWriter cw;
|
private ClassWriter cw;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private HashMap<String, String> genericsAndBoundsMethod;
|
HashMap<String, String> genericsAndBoundsMethod;
|
||||||
private HashMap<String, String> genericsAndBounds;
|
private HashMap<String, String> genericsAndBounds;
|
||||||
public boolean isBinaryExp = false;
|
private boolean isBinaryExp = false;
|
||||||
private String superClass;
|
|
||||||
private String path;
|
|
||||||
private SourceFile sf;
|
|
||||||
private IStatement statement = null;
|
|
||||||
|
|
||||||
// private int numMethodCalls = 0;
|
private IStatement statement = null;
|
||||||
|
|
||||||
// for tests **
|
// for tests **
|
||||||
private String fieldName;
|
private String fieldName;
|
||||||
@ -82,12 +67,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||||
|
|
||||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(String className, ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles, SourceFile sf,String path) {
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.m = m;
|
this.m = m;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
@ -97,8 +81,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.isInterface = isInterface;
|
this.isInterface = isInterface;
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.sf = sf;
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
if (!isInterface)
|
if (!isInterface)
|
||||||
this.m.block.accept(this);
|
this.m.block.accept(this);
|
||||||
@ -106,13 +88,12 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||||
|
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.isInterface = isInterface;
|
this.isInterface = isInterface;
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
int i = indexOfFirstParamLam;
|
int i = indexOfFirstParamLam;
|
||||||
@ -124,11 +105,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
lambdaExpression.methodBody.accept(this);
|
lambdaExpression.methodBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void isBinary(boolean isBinary) {
|
private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
this.isBinaryExp =isBinary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
|
||||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,11 +113,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(Block block) {
|
public void visit(Block block) {
|
||||||
for (Statement stmt : block.getStatements()) {
|
for (Statement stmt : block.getStatements()) {
|
||||||
stmt.accept(this);
|
stmt.accept(this);
|
||||||
if(stmt instanceof MethodCall) {
|
|
||||||
String ret = getResolvedType(((MethodCall) stmt).getType());
|
|
||||||
if(!ret.equals("void"))
|
|
||||||
mv.visitInsn(Opcodes.POP);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +120,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(SuperCall superCall) {
|
public void visit(SuperCall superCall) {
|
||||||
superCall.receiver.accept(this);
|
superCall.receiver.accept(this);
|
||||||
superCall.arglist.accept(this);
|
superCall.arglist.accept(this);
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.superClass, superCall.name, "()V",
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), superCall.name, "()V",
|
||||||
isInterface);
|
isInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +129,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(LocalVar localVar) {
|
public void visit(LocalVar localVar) {
|
||||||
// wenn String + String zuerst wird ein StringBuilder initialisiert dann
|
// wenn String + String zuerst wird ein StringBuilder initialisiert dann
|
||||||
// wird die lokale Var geladen. Sonst wird zuerst die lokale Var geladen.
|
// wird die lokale Var geladen. Sonst wird zuerst die lokale Var geladen.
|
||||||
System.out.println(localVar.name);
|
|
||||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
||||||
|
|
||||||
if (isBinaryExp) {
|
if (isBinaryExp) {
|
||||||
@ -195,11 +167,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
doBoxing(binaryType);
|
doBoxing(binaryType);
|
||||||
isBinaryExp = false;
|
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);
|
assign.lefSide.accept(this);
|
||||||
|
|
||||||
statement = null;
|
statement = null;
|
||||||
@ -553,7 +520,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodName, arg3.toString(), null, null);
|
methodName, arg3.toString(), null, null);
|
||||||
|
|
||||||
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles,this.path);
|
classFiles);
|
||||||
|
|
||||||
mvLambdaBody.visitMaxs(0, 0);
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
mvLambdaBody.visitEnd();
|
mvLambdaBody.visitEnd();
|
||||||
@ -581,7 +548,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// ")"+lam.getReturn.getBounds
|
// ")"+lam.getReturn.getBounds
|
||||||
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
String name = "Fun" + numberOfParams + "$$";
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
Type.getInternalName(Object.class), null);
|
Type.getInternalName(Object.class), null);
|
||||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
methSig.toString(), null);
|
methSig.toString(), null);
|
||||||
@ -594,7 +561,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
try {
|
try {
|
||||||
System.out.println("generating " + name + ".class file...");
|
System.out.println("generating " + name + ".class file...");
|
||||||
output = new FileOutputStream(
|
output = new FileOutputStream(
|
||||||
new File(path + name + ".class"));
|
new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" + name + ".class"));
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
System.out.println(name + ".class file generated");
|
System.out.println(name + ".class file generated");
|
||||||
@ -608,6 +575,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CastExpr castExpr) {
|
public void visit(CastExpr castExpr) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,6 +587,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(FieldVar fieldVar) {
|
public void visit(FieldVar fieldVar) {
|
||||||
|
|
||||||
fieldName = fieldVar.fieldVarName;
|
fieldName = fieldVar.fieldVarName;
|
||||||
fieldDesc = "L" + getResolvedType(fieldVar.getType()) + ";";
|
fieldDesc = "L" + getResolvedType(fieldVar.getType()) + ";";
|
||||||
|
|
||||||
@ -646,157 +615,32 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(InstanceOf instanceOf) {
|
public void visit(InstanceOf instanceOf) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
System.out.println("In MethodCall = " + methodCall.name);
|
|
||||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
|
||||||
java.lang.reflect.Method methodRefl = null;
|
|
||||||
String clazz = receiverName.replace("/", ".");
|
|
||||||
try {
|
|
||||||
if(receiverName.contains("<")) {
|
|
||||||
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
|
||||||
}
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
|
||||||
for(java.lang.reflect.Method m : methods) {
|
|
||||||
if(methodCall.name.equals(m.getName())) {
|
|
||||||
methodRefl = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
String superClass = "";
|
|
||||||
// TODO: Test SubMatrix.jav
|
|
||||||
while(true) {
|
|
||||||
for(ClassOrInterface cl : sf.getClasses()) {
|
|
||||||
if(receiverName.equals(cl.getClassName().toString())) {
|
|
||||||
superClass = cl.getSuperClass().getName().toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(superClass);
|
|
||||||
|
|
||||||
if(superClass.equals(""))
|
|
||||||
break;
|
|
||||||
|
|
||||||
try {
|
|
||||||
String superClazz = superClass.replace("/", ".");
|
|
||||||
if(superClass.contains("<")) {
|
|
||||||
superClazz = superClazz.substring(0, superClass.indexOf("<"));
|
|
||||||
}
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
|
||||||
System.out.println("Methods of " + superClass + " ");
|
|
||||||
|
|
||||||
for(java.lang.reflect.Method m : methods) {
|
|
||||||
if(methodCall.name.equals(m.getName())) {
|
|
||||||
methodRefl = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
} catch (Exception e2) {
|
|
||||||
receiverName = superClass;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
|
||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
|
||||||
String mDesc = "";
|
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
|
||||||
if(methodRefl == null) {
|
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
} else {
|
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
|
||||||
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
|
||||||
argListMethCall.add(p.getType().isPrimitive());
|
|
||||||
}
|
|
||||||
mDesc = getMethodDesc(methodRefl);
|
|
||||||
for (Expression al : methodCall.arglist.getArguments()) {
|
|
||||||
statement = new ArgumentExpr(al);
|
|
||||||
ArgumentVisitor argV = new ArgumentVisitor(argListMethCall,this);
|
|
||||||
al.accept(argV);
|
|
||||||
statement = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Methodcall Desc : " + mDesc);
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
|
genericsAndBoundsMethod, genericsAndBounds);
|
||||||
|
String mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
// methodCall.arglist.accept(this);
|
|
||||||
|
|
||||||
// is methodCall.receiver functional Interface)?
|
// is methodCall.receiver functional Interface)?
|
||||||
if (varsFunInterface.contains(methodCall.receiver.getType())) {
|
if (varsFunInterface.contains(methodCall.receiver.getType())) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, clazz.replace(".", "/"), methodCall.name,
|
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name,
|
||||||
mDesc, true);
|
mDesc, false);
|
||||||
} else {
|
} else {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazz.replace(".", "/"), methodCall.name,
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getResolvedType(methodCall.receiver.getType()), methodCall.name,
|
||||||
mDesc, isInterface);
|
mDesc, isInterface);
|
||||||
}
|
}
|
||||||
|
// test
|
||||||
if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) {
|
// if(!methodCall.getType().toString().equals("V")) {
|
||||||
if(methodRefl.getReturnType().equals(Object.class)) {
|
// mv.visitInsn(Opcodes.POP);
|
||||||
String checkCast = getResolvedType(methodCall.getType());
|
// }
|
||||||
int pos = checkCast.length();
|
|
||||||
if(checkCast.contains("<"))
|
|
||||||
pos = checkCast.indexOf("<");
|
|
||||||
mv.visitTypeInsn(Opcodes.CHECKCAST,checkCast.substring(0,pos));
|
|
||||||
}
|
|
||||||
if(isBinaryExp)
|
|
||||||
doUnboxing(getResolvedType(methodCall.getType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMethodDesc(java.lang.reflect.Method methodRefl) {
|
|
||||||
StringBuilder sb = new StringBuilder("(");
|
|
||||||
|
|
||||||
for(final Class c:(methodRefl.getParameterTypes()))
|
|
||||||
sb= sb.append(getDescriptorForClass(c));
|
|
||||||
|
|
||||||
sb.append(')');
|
|
||||||
sb.append(getDescriptorForClass(methodRefl.getReturnType()));
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDescriptorForClass(final Class c) {
|
|
||||||
if(c.isPrimitive())
|
|
||||||
{
|
|
||||||
if(c==byte.class)
|
|
||||||
return "B";
|
|
||||||
if(c==char.class)
|
|
||||||
return "C";
|
|
||||||
if(c==double.class)
|
|
||||||
return "D";
|
|
||||||
if(c==float.class)
|
|
||||||
return "F";
|
|
||||||
if(c==int.class)
|
|
||||||
return "I";
|
|
||||||
if(c==long.class)
|
|
||||||
return "J";
|
|
||||||
if(c==short.class)
|
|
||||||
return "S";
|
|
||||||
if(c==boolean.class)
|
|
||||||
return "Z";
|
|
||||||
if(c==void.class)
|
|
||||||
return "V";
|
|
||||||
|
|
||||||
}
|
|
||||||
if(c.isArray())
|
|
||||||
return c.getName().replace('.', '/');
|
|
||||||
|
|
||||||
return ('L'+c.getName()+';').replace('.', '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -828,7 +672,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(UnaryExpr unaryExpr) {
|
public void visit(UnaryExpr unaryExpr) {
|
||||||
|
|
||||||
unaryExpr.expr.accept(this);
|
unaryExpr.expr.accept(this);
|
||||||
Operation op = unaryExpr.operation;
|
Operation op = unaryExpr.operation;
|
||||||
|
|
||||||
@ -956,7 +799,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock);
|
statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock);
|
||||||
isBinaryExp = statement.isExprBinary();
|
isBinaryExp = statement.isExprBinary();
|
||||||
whileStmt.expr.accept(this);
|
whileStmt.expr.accept(this);
|
||||||
// isBinaryExp = false;
|
isBinaryExp = false;
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -976,7 +819,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unboxing: RefType -> prim
|
// Unboxing: RefType -> prim
|
||||||
public void doUnboxing(String type) {
|
private void doUnboxing(String type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "java/lang/String":
|
case "java/lang/String":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
||||||
@ -1197,9 +1040,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
String var = assignLeftSide.localVar.name;
|
String var = assignLeftSide.localVar.name;
|
||||||
if (!paramsAndLocals.containsKey(var)) {
|
if (!paramsAndLocals.containsKey(var)) {
|
||||||
paramsAndLocals.put(var, index + 1);
|
paramsAndLocals.put(var, index + 1);
|
||||||
|
} else {
|
||||||
|
paramsAndLocals.put(var, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.get(var));
|
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size());
|
||||||
|
// Debug:::
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ public class LoopStmt extends AStatement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||||
bytecodeGenMethod.isBinary(false);
|
|
||||||
this.loopBlock.accept(bytecodeGenMethod);
|
this.loopBlock.accept(bytecodeGenMethod);
|
||||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||||
mv.visitLabel(branchLabel);
|
mv.visitLabel(branchLabel);
|
||||||
|
@ -2,8 +2,6 @@ package de.dhbwstuttgart.bytecode.descriptor;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||||
@ -51,8 +49,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
String resType = 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 ")) {
|
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||||
// Bound ist immer Object
|
desc += "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
|
||||||
} else {
|
} else {
|
||||||
desc += "L"+resType+ ";";
|
desc += "L"+resType+ ";";
|
||||||
}
|
}
|
||||||
@ -79,8 +76,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}else {
|
}else {
|
||||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
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 {
|
} else {
|
||||||
desc += ")" + "L"+resType+ ";";
|
desc += ")" + "L"+resType+ ";";
|
||||||
}
|
}
|
||||||
@ -123,21 +119,9 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
|
||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
FormalParameter fp = itr.next();
|
FormalParameter fp = itr.next();
|
||||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
desc = desc + "L"+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;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,22 +131,9 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
|
||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
desc = desc + "L"+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;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,11 +141,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
public String visit(MethodFromMethodCall methodFromMethodCall) {
|
public String visit(MethodFromMethodCall methodFromMethodCall) {
|
||||||
String desc = "(";
|
String desc = "(";
|
||||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = e.getType().acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
|
||||||
}else {
|
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||||
@ -184,20 +151,16 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
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";
|
desc += ")V";
|
||||||
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
String ret = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(retType)+ ";";
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(ret)) {
|
||||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(retType)){
|
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(ret)+ ";";
|
||||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(retType)+ ";";
|
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(ret)){
|
||||||
|
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(ret)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc += ")" + "L"+retType+ ";";
|
desc += ")" + "L"+resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
|
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
|
||||||
|
@ -19,9 +19,7 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
throw new NotImplementedException();
|
||||||
return superWildcardType.getInnerType().toString().replace(".", "/");
|
|
||||||
//throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,7 +29,6 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
|
||||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.bytecode.signature;
|
package de.dhbwstuttgart.bytecode.signature;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@ -9,19 +8,13 @@ import org.objectweb.asm.signature.SignatureVisitor;
|
|||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
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;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class Signature {
|
public class Signature {
|
||||||
@ -33,36 +26,28 @@ public class Signature {
|
|||||||
private Method method;
|
private Method method;
|
||||||
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private ArrayList<GenericInsertPair> commonPairs;
|
|
||||||
private ArrayList<GenericInsertPair> methodPairs;
|
|
||||||
|
|
||||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,ArrayList<GenericInsertPair> commonPairs) {
|
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds) {
|
||||||
this.classOrInterface = classOrInterface;
|
this.classOrInterface = classOrInterface;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.commonPairs = commonPairs;
|
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForClassOrInterface();
|
createSignatureForClassOrInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds,
|
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds, HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes) {
|
||||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes,ResultSet resultSet,ArrayList<GenericInsertPair> methodPairs) {
|
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||||
this.resultSet = resultSet;
|
|
||||||
this.methodPairs = methodPairs;
|
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForConsOrMethod(this.constructor,true);
|
createSignatureForConsOrMethod(this.constructor,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,HashMap<String, String> genericsAndBounds,
|
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet, ArrayList<GenericInsertPair> methodPairs) {
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
|
||||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.methodPairs = methodPairs;
|
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForConsOrMethod(this.method,false);
|
createSignatureForConsOrMethod(this.method,false);
|
||||||
}
|
}
|
||||||
@ -107,102 +92,28 @@ public class Signature {
|
|||||||
GenericTypeVar g = itr.next();
|
GenericTypeVar g = itr.next();
|
||||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
// 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
|
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||||
if(!isConstructor) {
|
|
||||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
System.out.println("RET:::: " + ret);
|
if(ret.substring(0,4).equals("TPH ")) {
|
||||||
if(!ret.equals("V")) {
|
String g = ret.substring(4)+"$";
|
||||||
// TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich
|
sw.visitFormalTypeParameter(g);
|
||||||
// T... braucht und L ...
|
|
||||||
if(ret.contains("$") && !ret.contains("$$")) {
|
|
||||||
// String g = ret.substring(4,ret.length())+"$";
|
|
||||||
if(genericsAndBounds.containsKey(ret)) {
|
|
||||||
genericsAndBoundsMethod.put(ret.substring(1), genericsAndBounds.get(ret.substring(1)));
|
|
||||||
}else {
|
|
||||||
sw.visitFormalTypeParameter(ret.substring(1));
|
|
||||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||||
genericsAndBoundsMethod.put(ret.substring(1), Type.getInternalName(Object.class));
|
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||||
sw.visitClassBound().visitEnd();
|
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()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||||
String pT = t.acceptTV(new TypeToSignature());
|
String pT = t.acceptTV(new TypeToSignature());
|
||||||
// S.o
|
// S.o
|
||||||
// if(pT.substring(0,4).equals("TPH ")) {
|
if(pT.substring(0,4).equals("TPH ") && !genericsAndBoundsMethod.containsKey(pT)) {
|
||||||
if(t instanceof TypePlaceholder) {
|
String gP = pT.substring(4)+"$";
|
||||||
// String gP = pT.substring(4,pT.length())+"$";
|
sw.visitFormalTypeParameter(gP);
|
||||||
String gP = t.acceptTV(new TypeToSignature());
|
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||||
if(!genericsAndBounds.containsKey(gP.substring(1)) && !genericsAndBoundsMethod.containsKey(gP.substring(1))) {
|
genericsAndBoundsMethod.put(gP, Type.getInternalName(Object.class));
|
||||||
sw.visitFormalTypeParameter(gP.substring(1));
|
|
||||||
String bound = Type.getInternalName(Object.class);
|
|
||||||
boolean isTypeVar = false;
|
|
||||||
for(GenericInsertPair pair : methodPairs) {
|
|
||||||
if(pT.substring(1,pT.length()-1).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();
|
sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
genericsAndBoundsMethod.put(gP.substring(1), 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// visit each method-parameter to create the signature
|
// visit each method-parameter to create the signature
|
||||||
@ -211,156 +122,24 @@ public class Signature {
|
|||||||
// parameter type deswegen ist true
|
// parameter type deswegen ist true
|
||||||
doVisitParamsOrReturn(t,true);
|
doVisitParamsOrReturn(t,true);
|
||||||
}
|
}
|
||||||
if(isConstructor ||
|
if(isConstructor) {
|
||||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).equals("V")) {
|
|
||||||
sw.visitReturnType().visitBaseType('V');
|
sw.visitReturnType().visitBaseType('V');
|
||||||
}else {
|
}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();
|
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||||
// return type deswegen ist false
|
// return type deswegen ist false
|
||||||
doVisitParamsOrReturn(returnType, false);
|
doVisitParamsOrReturn(returnType, false);
|
||||||
}
|
}
|
||||||
// sw.visitEnd();
|
// 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()) {
|
|
||||||
System.out.println(p.acceptTV(new TypeToString()));
|
|
||||||
if(p.acceptTV(new TypeToString()).contains("WC")){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(resultSet.resolveType(p).resolvedType instanceof TypePlaceholder)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||||
* the method signature
|
* the method signature
|
||||||
@ -378,34 +157,24 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "RT":
|
case "RT":
|
||||||
String sig = t.acceptTV(new TypeToSignature());
|
sv.visitClassType(t.acceptTV(new TypeToSignature()));
|
||||||
sv.visitClassType(sig.substring(1, sig.length()));
|
|
||||||
break;
|
break;
|
||||||
case "GRT":
|
case "GRT":
|
||||||
GenericRefType g = (GenericRefType) t;
|
GenericRefType g = (GenericRefType) t;
|
||||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||||
break;
|
break;
|
||||||
case "TPH":
|
case "TPH":
|
||||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||||
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
|
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
|
||||||
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
|
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
|
||||||
// Interface oder eine Klasse ist.
|
// Interface oder eine Klasse ist.
|
||||||
|
if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) {
|
||||||
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
|
||||||
//
|
|
||||||
// if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) {
|
|
||||||
String sig2 = r.acceptTV(new TypeToSignature());
|
|
||||||
if(!(r instanceof TypePlaceholder)) {
|
|
||||||
|
|
||||||
// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
|
// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
|
||||||
// sv.visitClassType(r.acceptTV(new TypeToSignature()));
|
sv.visitClassType(r.acceptTV(new TypeToSignature()));
|
||||||
sv.visitClassType(sig2.substring(1, sig2.length()));
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
||||||
// sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$");
|
sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$");
|
||||||
sv.visitTypeVariable(sig2.substring(1, sig2.length()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(!isParameterType)
|
if(!isParameterType)
|
||||||
@ -425,36 +194,8 @@ public class Signature {
|
|||||||
GenericTypeVar g = itr.next();
|
GenericTypeVar g = itr.next();
|
||||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||||
}
|
}
|
||||||
if(!commonPairs.isEmpty()) {
|
|
||||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
|
||||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
|
||||||
|
|
||||||
for(GenericInsertPair p : commonPairs) {
|
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String sClass = classOrInterface.getSuperClass().acceptTV(new TypeToSignature());
|
|
||||||
sw.visitSuperclass().visitClassType(sClass.substring(1, sClass.length()-1));
|
|
||||||
sw.visitEnd();
|
sw.visitEnd();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -15,8 +15,6 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
if(refType.getName().toString().equals("void"))
|
|
||||||
return "V";
|
|
||||||
// return refType.toString().replace(".", "/");
|
// return refType.toString().replace(".", "/");
|
||||||
String params = "";
|
String params = "";
|
||||||
if(refType.getParaList().size()>0){
|
if(refType.getParaList().size()>0){
|
||||||
@ -24,41 +22,29 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||||
// if(param instanceof TypePlaceholder) {
|
params += "L"+param.toString().replace(".", "/");
|
||||||
// params += "T" + ((TypePlaceholder) param).getName() + "$";
|
if(it.hasNext())params += ";";
|
||||||
// } else if(param instanceof ExtendsWildcardType) {
|
|
||||||
// params += "+" + ((ExtendsWildcardType) param).getInnerType().acceptTV(new TypeToSignature());
|
|
||||||
// } else if(param instanceof SuperWildcardType) {
|
|
||||||
// params += "-" + ((SuperWildcardType) param).getInnerType().acceptTV(new TypeToSignature());
|
|
||||||
// } else {
|
|
||||||
// params += "L"+param.toString().replace(".", "/");
|
|
||||||
// }
|
|
||||||
params += param.acceptTV(new TypeToSignature());
|
|
||||||
// if(it.hasNext())params += ";";
|
|
||||||
}
|
}
|
||||||
params += ">";
|
params += ";>";
|
||||||
}
|
}
|
||||||
// String t = refType.getName().toString().replace(".", "/");
|
// String t = refType.getName().toString().replace(".", "/");
|
||||||
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
|
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
|
||||||
return "L"+refType.getName().toString().replace(".", "/") + params+";";
|
return refType.getName().toString().replace(".", "/") + params+";";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
// throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
return "-" + superWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(TypePlaceholder typePlaceholder) {
|
public String visit(TypePlaceholder typePlaceholder) {
|
||||||
// return typePlaceholder.toString().replace(".", "/");
|
return typePlaceholder.toString().replace(".", "/");
|
||||||
return "T" + typePlaceholder.getName() + "$";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
// throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
return "+" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,7 +17,7 @@ public class TypeToString implements TypeVisitor<String>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
return "SWC";
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,7 +27,7 @@ public class TypeToString implements TypeVisitor<String>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
return "EWC";
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,16 +9,13 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
public class MethodFromMethodCall {
|
public class MethodFromMethodCall {
|
||||||
private ArgumentList argList;
|
private ArgumentList argList;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric returnType;
|
private RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
private String receiverName;
|
|
||||||
private HashMap<String, String> genericsAndBoundsMethod;
|
private HashMap<String, String> genericsAndBoundsMethod;
|
||||||
private HashMap<String,String> genericsAndBounds;
|
private HashMap<String,String> genericsAndBounds;
|
||||||
|
|
||||||
public MethodFromMethodCall(ArgumentList argList,RefTypeOrTPHOrWildcardOrGeneric returnType,
|
public MethodFromMethodCall(ArgumentList argList,RefTypeOrTPHOrWildcardOrGeneric returnType,
|
||||||
String receiverName, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, String> genericsAndBoundsMethod,HashMap<String,String> genericsAndBounds) {
|
||||||
HashMap<String,String> genericsAndBounds) {
|
|
||||||
this.argList = argList;
|
this.argList = argList;
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
this.receiverName = receiverName;
|
|
||||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
}
|
}
|
||||||
@ -31,10 +28,6 @@ public class MethodFromMethodCall {
|
|||||||
return returnType;
|
return returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReceiverName() {
|
|
||||||
return receiverName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, String> getGenericsAndBoundsMethod(){
|
public HashMap<String, String> getGenericsAndBoundsMethod(){
|
||||||
return genericsAndBoundsMethod;
|
return genericsAndBoundsMethod;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
@ -39,7 +38,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
final boolean parallel = true;
|
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||||
@ -118,7 +117,6 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
|
||||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||||
@ -177,38 +175,14 @@ public class JavaTXCompiler {
|
|||||||
return y; } )
|
return y; } )
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
varianceInheritance(xConsSet);
|
varianceInheritance(xConsSet);
|
||||||
if (parallel) {
|
|
||||||
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
|
||||||
Set<UnifyPair> eq = new HashSet<>(xConsSet);
|
|
||||||
TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log);
|
|
||||||
forks.add(fork);
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (TypeUnifyTask fork : forks) {
|
|
||||||
try {
|
|
||||||
Set<Set<UnifyPair>> result = fork.join();
|
|
||||||
System.out.println("RESULT: " + result);
|
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
|
||||||
logFile.flush();
|
|
||||||
results.addAll(result);
|
|
||||||
}
|
|
||||||
catch (ConcurrentModificationException v) {
|
|
||||||
v.printStackTrace();
|
|
||||||
while (v.getCause() instanceof ConcurrentModificationException) {
|
|
||||||
v = (ConcurrentModificationException)v.getCause();
|
|
||||||
}
|
|
||||||
System.out.println(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) { }
|
catch (IOException e) { }
|
||||||
|
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
@ -266,26 +240,25 @@ public class JavaTXCompiler {
|
|||||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// um pfad erweitern
|
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
public void generateBytecode() throws ClassNotFoundException, IOException {
|
||||||
for(File f : sourceFiles.keySet()) {
|
for(File f : sourceFiles.keySet()) {
|
||||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult);
|
||||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
this.writeClassFile(bytecodeGen.getClassFiles());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeClassFile(HashMap<String, byte[]> classFiles, String path) throws IOException {
|
private void writeClassFile(HashMap<String, byte[]> classFiles) throws IOException {
|
||||||
FileOutputStream output;
|
FileOutputStream output;
|
||||||
for(String name : classFiles.keySet()) {
|
for(String name : classFiles.keySet()) {
|
||||||
byte[] bytecode = classFiles.get(name);
|
byte[] bytecode = classFiles.get(name);
|
||||||
System.out.println("generating "+name+ ".class file ...");
|
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.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
System.out.println(name+".class file generated");
|
System.out.println(name+".class file generated");
|
||||||
|
@ -198,9 +198,7 @@ public class UnifyTypeFactory {
|
|||||||
}else if(tr instanceof WildcardType){
|
}else if(tr instanceof WildcardType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}else {
|
}else throw new NotImplementedException();
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||||
@ -210,7 +208,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class FunN extends RefType {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
|
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
|
||||||
super(new JavaClassName("Fun"+(params.size())), params, new NullToken());
|
super(new JavaClassName("Fun"+params.size()), params, new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,36 +8,32 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FunNClass extends ClassOrInterface {
|
public class FunNClass extends ClassOrInterface {
|
||||||
public FunNClass(List<GenericRefType> funNParams) {
|
public FunNClass(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||||
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(),
|
super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(),
|
||||||
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
||||||
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GenericDeclarationList createGenerics(List<GenericRefType> funNParams) {
|
private static GenericDeclarationList createGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||||
//PL 2018-06-22: so geaendert, dass generierte Generics den Namen der funParams entsprechen.
|
|
||||||
List<GenericTypeVar> generics = new ArrayList<>();
|
List<GenericTypeVar> generics = new ArrayList<>();
|
||||||
for(GenericRefType param : funNParams){
|
for(RefTypeOrTPHOrWildcardOrGeneric param : funNParams){
|
||||||
generics.add(new GenericTypeVar(param.getParsedName(),//NameGenerator.makeNewName(),
|
generics.add(new GenericTypeVar(NameGenerator.makeNewName(),
|
||||||
new ArrayList<>(), new NullToken(), new NullToken()));
|
new ArrayList<>(), new NullToken(), new NullToken()));
|
||||||
}
|
}
|
||||||
return new GenericDeclarationList(generics, new NullToken());
|
return new GenericDeclarationList(generics, new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Method> createMethods(List<GenericRefType> funNParams) {
|
private static List<Method> createMethods(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ import java.util.List;
|
|||||||
public class MethodAssumption extends Assumption{
|
public class MethodAssumption extends Assumption{
|
||||||
private ClassOrInterface receiver;
|
private ClassOrInterface receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
List<RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||||
|
|
||||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
List<RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
||||||
super(scope);
|
super(scope);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.retType = retType;
|
this.retType = retType;
|
||||||
@ -38,9 +38,7 @@ public class MethodAssumption extends Assumption{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
||||||
if(retType instanceof GenericRefType) {
|
if(retType instanceof GenericRefType)return resolver.resolve(retType);
|
||||||
return resolver.resolve(retType);
|
|
||||||
}
|
|
||||||
return retType;
|
return retType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import de.dhbwstuttgart.parser.NullToken;
|
|||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||||
@ -223,76 +222,51 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
|
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
|
||||||
//see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
|
//see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
|
||||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||||
Constraint<Pair> numeric;
|
Constraint<Pair> numeric = new Constraint<>();
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(bytee.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(shortt.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(integer.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(longg.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(floatt.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
//PL eingefuegt 2018-07-17
|
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(doublee.getName())) {
|
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
|
||||||
/* PL auskommentiert Anfang 2018-07-17
|
|
||||||
/*
|
/*
|
||||||
In Java passiert bei den binären Operatoren eine sogenannte Type Promotion:
|
In Java passiert bei den binären Operatoren eine sogenannte Type Promotion:
|
||||||
https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2
|
https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2
|
||||||
Das bedeutet, dass Java die Typen je nach belieben castet, so lange sie nur von Number erben
|
Das bedeutet, dass Java die Typen je nach belieben castet, so lange sie nur von Number erben
|
||||||
|
*/
|
||||||
numeric = new Constraint<>();
|
|
||||||
numeric.add(new Pair(binary.getType(), number, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), number, PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
* PL auskommentiert Ende 2018-07-17 */
|
|
||||||
|
|
||||||
if(binary.operation.equals(BinaryExpr.Operator.ADD)) {
|
if(binary.operation.equals(BinaryExpr.Operator.ADD)) {
|
||||||
//Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2)
|
//Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2)
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(string.getName())) {
|
|
||||||
Constraint<Pair> stringConcat = new Constraint<>();
|
Constraint<Pair> stringConcat = new Constraint<>();
|
||||||
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
||||||
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
||||||
@ -354,15 +328,6 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Literal literal) {
|
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
|
@Override
|
||||||
@ -486,14 +451,11 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
List<MethodAssumption> ret = new ArrayList<>();
|
List<MethodAssumption> ret = new ArrayList<>();
|
||||||
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
||||||
if(name.equals("apply")){
|
if(name.equals("apply")){
|
||||||
List<GenericRefType> funNParams = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||||
for(int i = 0; i< numArgs + 1 ; i++){
|
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()));
|
|
||||||
}
|
}
|
||||||
funNParams.get(funNParams.size()-1);
|
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()),
|
||||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size()-1), funNParams.subList(0, funNParams.size()-1),
|
|
||||||
new TypeScope() {
|
new TypeScope() {
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||||
@ -536,7 +498,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
*/
|
*/
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
for(FormalParameter fp : parameterList.getFormalparalist()){
|
for(FormalParameter fp : parameterList.getFormalparalist()){
|
||||||
params.add(fp.getType()); //info.checkGTV(fp.getType())); //PL 2018-06-22 GTV sollen in Argumenten erhalten bleiben
|
params.add(info.checkGTV(fp.getType()));
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -938,9 +938,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
else {
|
else {
|
||||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||||
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||||
Set<UnifyType> fBounded = pair.getfBounded();
|
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||||
fBounded.add(lhsType);
|
|
||||||
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(result);
|
return Optional.of(result);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.util.ConcurrentModificationException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
@ -12,12 +11,7 @@ public class TypeUnify {
|
|||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
try {
|
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
}
|
|
||||||
catch (ConcurrentModificationException v) {
|
|
||||||
v.printStackTrace();
|
|
||||||
}
|
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
|
||||||
|
|
||||||
public class TypeUnify2Task extends TypeUnifyTask {
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) {
|
|
||||||
super(eq, fc, parallel, logFile, log);
|
|
||||||
this.setToFlatten = setToFlatten;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
|
||||||
if (one) {
|
|
||||||
System.out.println("two");
|
|
||||||
}
|
|
||||||
one = true;
|
|
||||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel);
|
|
||||||
/*if (isUndefinedPairSetSet(res)) {
|
|
||||||
return new HashSet<>(); }
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.RecursiveTask;
|
import java.util.concurrent.RecursiveTask;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -30,7 +29,6 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -50,14 +48,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
private static int i = 0;
|
private static int i = 0;
|
||||||
private boolean printtag = false;
|
private boolean printtag = false;
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||||
private static int noOfThread = 0;
|
|
||||||
private int thNo;
|
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
FileWriter logFile;
|
FileWriter logFile;
|
||||||
|
|
||||||
protected boolean one = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The implementation of setOps that will be used during the unification
|
* The implementation of setOps that will be used during the unification
|
||||||
*/
|
*/
|
||||||
@ -101,10 +95,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
noOfThread++;
|
|
||||||
thNo = noOfThread;
|
|
||||||
//System.out.println(noOfThread);
|
|
||||||
//System.out.println(eq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -142,10 +132,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
|
||||||
System.out.println("two");
|
|
||||||
}
|
|
||||||
one = true;
|
|
||||||
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
||||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||||
else return res;
|
else return res;
|
||||||
@ -157,13 +143,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
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)
|
Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||||
// ).collect(Collectors.toCollection(HashSet::new));
|
).collect(Collectors.toCollection(HashSet::new));
|
||||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||||
//if (aas.isEmpty()) {
|
if (aas.isEmpty()) {
|
||||||
// System.out.println("");
|
System.out.println("");
|
||||||
//}
|
}
|
||||||
/*
|
/*
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
*/
|
*/
|
||||||
@ -324,13 +310,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
//System.out.println("vor Subst: " + eqPrime);
|
//System.out.println("vor Subst: " + eqPrime);
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||||
Set<Set<UnifyPair>> unifyres1 = null;
|
|
||||||
Set<Set<UnifyPair>> unifyres2 = null;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
if(parallel) {
|
if(parallel) {
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||||
@ -350,8 +333,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else */
|
else { // sequentiell (Step 6b is included)
|
||||||
{ // sequentiell (Step 6b is included)
|
|
||||||
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||||
@ -367,12 +349,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel);
|
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, false);
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, fc, parallel);
|
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, false);
|
||||||
|
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
@ -385,24 +367,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/*
|
/*
|
||||||
* Step 6 b) Build the union over everything.
|
* Step 6 b) Build the union over everything.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
if(parallel)
|
if(parallel)
|
||||||
for(TypeUnifyTask fork : forks)
|
for(TypeUnifyTask fork : forks)
|
||||||
eqPrimePrimeSet.addAll(fork.join());
|
eqPrimePrimeSet.addAll(fork.join());
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 7: Filter empty sets;
|
* Step 7: Filter empty sets;
|
||||||
*/
|
*/
|
||||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
||||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
|
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
|
||||||
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
||||||
Iterator<UnifyPair> upit = eqPrimePrimeSet.iterator().next().iterator();
|
|
||||||
if (upit.next().getLhsType() instanceof WildcardType
|
|
||||||
|| upit.next().getLhsType() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return eqPrimePrimeSet;
|
return eqPrimePrimeSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,22 +447,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
|
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
a = oup.max(nextSetasList.iterator());
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
|
||||||
while (nextSetasListItRest.hasNext()) {
|
|
||||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
|
||||||
if (//a.equals(a_next) ||
|
|
||||||
(oup.compare(a, a_next) == 1)) {
|
|
||||||
nextSetasListRest.remove(a_next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (variance == -1) {
|
else if (variance == -1) {
|
||||||
a = oup.min(nextSetasList.iterator());
|
a = oup.min(nextSetasList.iterator());
|
||||||
@ -524,63 +488,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||||
elems.add(a);
|
elems.add(a);
|
||||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
//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);
|
||||||
Set<Set<UnifyPair>> res = new HashSet<>();
|
|
||||||
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
|
||||||
if(parallel && (variance == 1)) {
|
|
||||||
/*
|
|
||||||
elems.add(a);
|
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
|
||||||
fork.fork();
|
|
||||||
res = fork.join();
|
|
||||||
*/
|
|
||||||
|
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
|
||||||
|
|
||||||
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
|
||||||
|
|
||||||
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
|
||||||
newElemsOrig.add(a);
|
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, fc, parallel, logFile, log);
|
|
||||||
forks.add(forkOrig);
|
|
||||||
forkOrig.fork();
|
|
||||||
|
|
||||||
while (!nextSetasListRest.isEmpty()) {
|
|
||||||
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
|
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
|
||||||
newElems.add(nSaL);
|
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log);
|
|
||||||
forks.add(fork);
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
//res = unify2(elems, eq, fc, parallel);
|
|
||||||
res = forkOrig.join();
|
|
||||||
for(TypeUnifyTask fork : forks) {
|
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
|
||||||
add_res.add(fork_res);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
elems.add(a);
|
|
||||||
res = unify2(elems, eq, fc, parallel);
|
|
||||||
}
|
|
||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
result = res;
|
result = res;
|
||||||
if (res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||||
|| result.isEmpty()) {
|
|| result.isEmpty()) {
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
writeLog("RESADD:" + result.toString() + " " + res.toString());
|
|
||||||
result.addAll(res);
|
result.addAll(res);
|
||||||
}
|
}
|
||||||
//else {
|
//else {
|
||||||
@ -596,36 +513,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
|
|
||||||
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
|
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)
|
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
if (parallel) {
|
|
||||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
|
||||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
|
||||||
result = par_res;
|
|
||||||
if (par_res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
|
||||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
|
||||||
|| result.isEmpty()) {
|
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
|
||||||
writeLog("RESADD:" + result.toString() + " " + par_res.toString());
|
|
||||||
result.addAll(par_res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* nextSetasList = nextSetasListRest; */
|
|
||||||
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
|
||||||
*/
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
while (nextSetasListIt.hasNext()) {
|
while (nextSetasListIt.hasNext()) {
|
||||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||||
@ -634,8 +526,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasList.remove(a_next);
|
nextSetasList.remove(a_next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else { if (variance == -1) {
|
else { if (variance == -1) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
@ -652,8 +542,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
|
||||||
|
|
||||||
if (isUndefinedPairSetSet(res)) {
|
if (isUndefinedPairSetSet(res)) {
|
||||||
Set<UnifyPair> abhSubst = res.stream()
|
Set<UnifyPair> abhSubst = res.stream()
|
||||||
.map(b ->
|
.map(b ->
|
||||||
@ -1206,7 +1094,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
UnifyType supAPrime = new SuperType(aPrime);
|
UnifyType supAPrime = new SuperType(aPrime);
|
||||||
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
|
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
|
||||||
result.add(resultPrime);
|
result.add(resultPrime);
|
||||||
//writeLog(resultPrime.toString());
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
@ -1235,35 +1123,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
allGen = false;
|
allGen = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded());
|
|
||||||
for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) {
|
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
Match match = new Match();
|
|
||||||
|
|
||||||
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||||
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
||||||
//Set<UnifyType> fBounded = pair.getfBounded();
|
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
|
||||||
|
|
||||||
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)
|
if(allGen)
|
||||||
@ -1297,9 +1165,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
((PlaceholderType)freshTph).setVariance(a.getVariance());
|
((PlaceholderType)freshTph).setVariance(a.getVariance());
|
||||||
resultPrime = new HashSet<>();
|
resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||||
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
|
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
|
||||||
result.add(resultPrime);
|
result.add(resultPrime);
|
||||||
//writeLog("resultPrime: " + resultPrime.toString());
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
resultPrime = new HashSet<>();
|
resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||||
@ -1348,7 +1216,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
if (log) {
|
if (log) {
|
||||||
try {
|
try {
|
||||||
logFile.write("Thread no.:" + thNo + "\n");
|
|
||||||
logFile.write(str+"\n");
|
logFile.write(str+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
|
@ -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(), suniUnifyPair, p);
|
||||||
}
|
}
|
||||||
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair(), p.getfBounded());
|
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,13 +51,6 @@ public class UnifyPair {
|
|||||||
*/
|
*/
|
||||||
private UnifyPair basePair;
|
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;
|
private final int hashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,12 +82,6 @@ public class UnifyPair {
|
|||||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
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.
|
* Returns the type on the left hand side of the pair.
|
||||||
*/
|
*/
|
||||||
@ -151,10 +138,6 @@ public class UnifyPair {
|
|||||||
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UnifyType> getfBounded() {
|
|
||||||
return this.fBounded;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(!(obj instanceof UnifyPair))
|
if(!(obj instanceof UnifyPair))
|
||||||
@ -194,7 +177,7 @@ public class UnifyPair {
|
|||||||
if (rhs instanceof PlaceholderType) {
|
if (rhs instanceof PlaceholderType) {
|
||||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
||||||
}
|
}
|
||||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
|
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,8 +25,8 @@ public class BinaryTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/BinaryInMeth.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/BinaryInMeth.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("BinaryInMeth");
|
classToTest = loader.loadClass("BinaryInMeth");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -27,8 +27,8 @@ public class FacTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Fac.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Fac.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Fac");
|
classToTest = loader.loadClass("Fac");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
@ -37,8 +37,8 @@ public class FacTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||||
Double result = (Double) getFac.invoke(instanceOfClass,3);
|
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||||
assertEquals(result, 6.0);
|
assertEquals(result, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class FacultyTest {
|
|
||||||
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/Faculty.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("Fac");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -26,8 +26,8 @@ public class GenTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Gen.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Gen.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Gen");
|
classToTest = loader.loadClass("Gen");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -28,8 +28,8 @@ public class GreaterEqualTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterEqual.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterEqual.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("GreaterEqual");
|
classToTest = loader.loadClass("GreaterEqual");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -28,8 +28,8 @@ public class GreaterThanTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterThan.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterThan.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("GreaterThan");
|
classToTest = loader.loadClass("GreaterThan");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
package bytecode;
|
package bytecode;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -16,31 +10,13 @@ public class LambdaTest {
|
|||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
|
||||||
private static Class<?> classToTest;
|
|
||||||
private static String pathToClassFile;
|
|
||||||
private static Object instanceOfClass;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateBC() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("Lambda");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
|
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
|
||||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
|
||||||
Method apply = lambda.getMethod("apply", Object.class);
|
|
||||||
apply.setAccessible(true);
|
|
||||||
|
|
||||||
Integer i = 77;
|
|
||||||
// result = 77*77 = 5929
|
|
||||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
|
||||||
assertEquals(5929, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ public class LessEqualTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessEqual.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessEqual.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("LessEqual");
|
classToTest = loader.loadClass("LessEqual");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -28,8 +28,8 @@ public class LessThanTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessThan.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessThan.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("LessThan");
|
classToTest = loader.loadClass("LessThan");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -3,12 +3,8 @@ package bytecode;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -22,72 +18,23 @@ public class MatrixTest {
|
|||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static String pathToClassFile;
|
private static String pathToClassFile;
|
||||||
private static Object instanceOfClass_m1;
|
private static Object instanceOfClass;
|
||||||
private static Object instanceOfClass_m2;
|
|
||||||
private static Object instanceOfClass_m3;
|
|
||||||
|
|
||||||
@Test
|
@BeforeClass
|
||||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Matrix");
|
classToTest = loader.loadClass("Matrix");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix();
|
@Test
|
||||||
//Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
public void test() {
|
||||||
Vector<Integer> v1 = new Vector<Integer> ();
|
fail("Not yet implemented");
|
||||||
v1.addElement(2);
|
|
||||||
v1.addElement(2);
|
|
||||||
Vector<Integer> v2 = new Vector<Integer> ();
|
|
||||||
v2.addElement(3);
|
|
||||||
v2.addElement(3);
|
|
||||||
//Method[] ms = classToTest.getSuperclass().getDeclaredMethods();
|
|
||||||
Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class);
|
|
||||||
addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1);
|
|
||||||
addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2);
|
|
||||||
//vv.addElement(v1);
|
|
||||||
//vv.addElement(v2);
|
|
||||||
//instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
|
||||||
Vector<Integer> v3 = new Vector<Integer> ();
|
|
||||||
v3.addElement(2);
|
|
||||||
v3.addElement(2);
|
|
||||||
Vector<Integer> v4 = new Vector<Integer> ();
|
|
||||||
v4.addElement(3);
|
|
||||||
v4.addElement(3);
|
|
||||||
//Matrix m2 = new Matrix();
|
|
||||||
//m2.addElement(v3);
|
|
||||||
//m2.addElement(v4);
|
|
||||||
vv1.addElement(v3);
|
|
||||||
vv1.addElement(v4);
|
|
||||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Matrix m3 = m1.mul(vv1);
|
|
||||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
|
||||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
|
||||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
|
||||||
|
|
||||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
|
||||||
Vector<Integer> v5 = new Vector<Integer> ();
|
|
||||||
v5.addElement(10);
|
|
||||||
v5.addElement(10);
|
|
||||||
Vector<Integer> v6 = new Vector<Integer> ();
|
|
||||||
v6.addElement(15);
|
|
||||||
v6.addElement(15);
|
|
||||||
//Matrix m2 = new Matrix();
|
|
||||||
//m2.addElement(v3);
|
|
||||||
//m2.addElement(v4);
|
|
||||||
res.addElement(v5);
|
|
||||||
res.addElement(v6);
|
|
||||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
|
||||||
assertEquals(result, instanceOfClass_m3);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package bytecode;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
@ -19,74 +17,23 @@ public class OLTest {
|
|||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Class<?> classToTest1;
|
|
||||||
private static String pathToClassFile;
|
private static String pathToClassFile;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static Object instanceOfClass1;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/OL.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/OL.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("OL");
|
classToTest = loader.loadClass("OL");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
classToTest1 = loader.loadClass("OLMain");
|
}
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
@Test
|
||||||
|
public void test() {
|
||||||
|
fail("Not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOLClassName() {
|
|
||||||
assertEquals("OL", classToTest.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
|
||||||
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
|
||||||
assertEquals(10, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
|
||||||
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
|
||||||
assertEquals(10.0, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", String.class);
|
|
||||||
String result = (String) m.invoke(instanceOfClass, "xxx");
|
|
||||||
assertEquals("xxxxxx", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOLMainClassName() {
|
|
||||||
assertEquals("OLMain", classToTest1.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
|
||||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
|
||||||
assertEquals(10, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
|
||||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
|
||||||
assertEquals(10.0, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
Method main = classToTest1.getDeclaredMethod("main", String.class);
|
|
||||||
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
|
||||||
assertEquals("xxxxxx", result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ public class OpTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Op.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Op.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Op");
|
classToTest = loader.loadClass("Op");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -30,8 +30,8 @@ public class OverloadingTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Overloading.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Overloading.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Overloading");
|
classToTest = loader.loadClass("Overloading");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -27,8 +27,9 @@ public class PlusTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Plus.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Plus.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Plus");
|
classToTest = loader.loadClass("Plus");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -27,8 +27,8 @@ public class PostIncTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PostIncDec.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PostIncDec.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("PostIncDec");
|
classToTest = loader.loadClass("PostIncDec");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -27,8 +27,8 @@ public class PreIncTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PreInc.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/PreInc.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
||||||
classToTest = loader.loadClass("PreInc");
|
classToTest = loader.loadClass("PreInc");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -27,8 +27,8 @@ public class RelOpsTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/RelOps.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/RelOps.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("RelOps");
|
classToTest = loader.loadClass("RelOps");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -26,8 +26,8 @@ public class StaticTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/StaticM.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/StaticM.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
|
||||||
classToTest = loader.loadClass("StaticM");
|
classToTest = loader.loadClass("StaticM");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class SubMatTest {
|
|
||||||
private static String path;
|
|
||||||
private static File fileToTest;
|
|
||||||
private static JavaTXCompiler compiler;
|
|
||||||
private static String pathToClassFile;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() throws ClassNotFoundException, IOException {
|
|
||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/SubMatrix.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
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 test1() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
|
||||||
|
|
||||||
assertEquals(1,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test2() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, "sss",2);
|
|
||||||
|
|
||||||
assertEquals("sss",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test3() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
|
||||||
|
|
||||||
assertEquals(2,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test4() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,"xxx");
|
|
||||||
|
|
||||||
assertEquals("xxx",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class Tph3Test {
|
|
||||||
|
|
||||||
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/Tph3.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 test1() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
|
||||||
|
|
||||||
assertEquals(1,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test2() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, "sss",2);
|
|
||||||
|
|
||||||
assertEquals("sss",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test3() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
|
||||||
|
|
||||||
assertEquals(2,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test4() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,"xxx");
|
|
||||||
|
|
||||||
assertEquals("xxx",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
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 test1() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
|
||||||
|
|
||||||
assertEquals(2,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test2() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 1, "sss");
|
|
||||||
|
|
||||||
assertEquals("sss",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test3() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass, 2);
|
|
||||||
|
|
||||||
assertEquals(2,result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test4() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m2", Object.class);
|
|
||||||
Object result = m.invoke(instanceOfClass,"xxx");
|
|
||||||
|
|
||||||
assertEquals("xxx",result);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -27,8 +27,8 @@ public class WhileTest {
|
|||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/While.jav";
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/While.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode();
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("While");
|
classToTest = loader.loadClass("While");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class applyLambdaTest {
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void generateBC() throws Exception {
|
|
||||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/applyLambda.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("applyLambda");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
|
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
|
||||||
Object result = m.invoke(instanceOfClass);
|
|
||||||
|
|
||||||
assertEquals(result.getClass(), loader.loadClass("Apply"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,15 +2,14 @@ import java.lang.Integer;
|
|||||||
|
|
||||||
class Faculty {
|
class Faculty {
|
||||||
|
|
||||||
|
Integer mul(Integer x, Integer y) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
m () {
|
m () {
|
||||||
|
|
||||||
var fact = (Integer x) -> {
|
var fact = (Integer x) -> {
|
||||||
if (x == 1) {
|
return mul(x, x);
|
||||||
return x;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return x * fact.apply(x-1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return fact;
|
return fact;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import java.lang.Integer;
|
|
||||||
import java.lang.Boolean;
|
|
||||||
|
|
||||||
public class IfTest{
|
public class IfTest{
|
||||||
Integer m1(Boolean b) {
|
Integer m1(Boolean b) {
|
||||||
Integer i;
|
Integer i;
|
||||||
|
@ -4,7 +4,7 @@ public class Lambda {
|
|||||||
|
|
||||||
m () {
|
m () {
|
||||||
var lam1 = (Integer x) -> {
|
var lam1 = (Integer x) -> {
|
||||||
return x * x;
|
return x;
|
||||||
};
|
};
|
||||||
return lam1;
|
return lam1;
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,25 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
//import java.lang.Byte;
|
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class Matrix extends Vector<Vector<Integer>> {
|
class Matrix extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
Matrix () {
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix(vv) {
|
|
||||||
Integer i;
|
|
||||||
i = 0;
|
|
||||||
while(i < vv.size()) {
|
|
||||||
// Boolean a = this.add(vv.elementAt(i));
|
|
||||||
this.add(vv.elementAt(i));
|
|
||||||
i=i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mul(m) {
|
mul(m) {
|
||||||
var ret = new Matrix();
|
var ret = new Matrix();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
var v1 = this.elementAt(i);
|
// var v1 = this.elementAt(i);
|
||||||
var v2 = new Vector<Integer>();
|
// var v2 = new Vector<Integer>();
|
||||||
var j = 0;
|
// var j = 0;
|
||||||
while(j < v1.size()) {
|
// while(j < v1.size()) {
|
||||||
var erg = 0;
|
// var erg = 0;
|
||||||
var k = 0;
|
// var k = 0;
|
||||||
while(k < v1.size()) {
|
// while(k < v1.size()) {
|
||||||
erg = erg + v1.elementAt(k)
|
// erg = erg + v1.elementAt(k)
|
||||||
* m.elementAt(k).elementAt(j);
|
// * m.elementAt(k).elementAt(j);
|
||||||
k++; }
|
// k++; }
|
||||||
// v2.addElement(new Integer(erg));
|
// v2.addElement(new Integer(erg));
|
||||||
v2.addElement(erg);
|
// j++; }
|
||||||
j++; }
|
// ret.addElement(v2);
|
||||||
ret.addElement(v2);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import java.lang.String;
|
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Double;
|
import java.lang.Double;
|
||||||
|
|
||||||
|
|
||||||
public class OL {
|
class OL {
|
||||||
|
|
||||||
m(x) { return x + x; }
|
m(java.lang.Double x) { return x + x; }
|
||||||
|
|
||||||
//m(x) { return x || x; }
|
//m(x) { return x || x; }
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ public class OL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class OLMain {
|
class Main {
|
||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
var ol;
|
var ol;
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import java.util.Vector;
|
|
||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
public class Matrix2 extends Vector<Integer> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SubMatrix extends Matrix2 {
|
|
||||||
m(){
|
|
||||||
Vector<Integer> v = new Vector<Integer>();
|
|
||||||
v.add(1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
public class Tph {
|
|
||||||
|
|
||||||
m(a,b){
|
|
||||||
var c = m2(b);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
m2(b){
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
public class Tph2 {
|
|
||||||
m(a,b){
|
|
||||||
var c = m2(a,b);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
m2(a,b){
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
public class Tph3 {
|
|
||||||
m(a,b){
|
|
||||||
var c = m2(a,b);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
m2(a,b){
|
|
||||||
return m(a,b);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import java.util.Vector;
|
|
||||||
class Apply { }
|
|
||||||
|
|
||||||
public class applyLambda {
|
|
||||||
|
|
||||||
m () {
|
|
||||||
var lam1 = (x) -> {
|
|
||||||
return x;
|
|
||||||
};
|
|
||||||
|
|
||||||
//return lam1.apply(new Apply());
|
|
||||||
return lam1;
|
|
||||||
//return new Vector();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
class Apply { }
|
import java.lang.Integer;
|
||||||
|
import java.lang.Number;
|
||||||
|
|
||||||
public class Lambda {
|
public class Lambda {
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ public class Lambda {
|
|||||||
var lam1 = (x) -> {
|
var lam1 = (x) -> {
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
return lam1.apply(new Apply());
|
return lam1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class Matrix extends Vector<Vector<Integer>> {
|
|||||||
var k = 0;
|
var k = 0;
|
||||||
while(k < v1.size()) {
|
while(k < v1.size()) {
|
||||||
erg = erg + 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),
|
// erg = add1(erg, mul1(v1.elementAt(k),
|
||||||
// m.elementAt(k).elementAt(j)));
|
// m.elementAt(k).elementAt(j)));
|
||||||
k++; }
|
k++; }
|
||||||
v2.addElement(new Integer(erg));
|
v2.addElement(new Integer(erg));
|
||||||
|
@ -1,23 +1,8 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Object;
|
|
||||||
|
|
||||||
class MyVector{
|
class MyVector{
|
||||||
|
|
||||||
id(x){
|
id(x){
|
||||||
Object i;
|
return (x.elementAt(0));
|
||||||
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,20 +28,13 @@ public class UnifyTest {
|
|||||||
public void finiteClosure() throws IOException, ClassNotFoundException {
|
public void finiteClosure() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"fc.jav"));
|
execute(new File(rootDirectory+"fc.jav"));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void lambda() throws IOException, ClassNotFoundException {
|
public void lambda() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Lambda.jav"));
|
execute(new File(rootDirectory+"Lambda.jav"));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
*/
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void vector() throws IOException, ClassNotFoundException {
|
|
||||||
execute(new File(rootDirectory+"Vector.jav"));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void lambda2() throws IOException, ClassNotFoundException {
|
public void lambda2() throws IOException, ClassNotFoundException {
|
||||||
@ -82,7 +75,6 @@ public class UnifyTest {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matrix() throws IOException, ClassNotFoundException {
|
public void matrix() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Matrix.jav"));
|
execute(new File(rootDirectory+"Matrix.jav"));
|
||||||
@ -90,7 +82,6 @@ public class UnifyTest {
|
|||||||
//compiler.generateBytecode();
|
//compiler.generateBytecode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void vector() throws IOException, ClassNotFoundException {
|
public void vector() throws IOException, ClassNotFoundException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user