Merge remote-tracking branch 'origin/bigRefactoring' into bigRefactoring
# Conflicts: # src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java
This commit is contained in:
commit
e48f2b2fd5
File diff suppressed because it is too large
Load Diff
@ -33,12 +33,14 @@ import org.objectweb.asm.Type;
|
|||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
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.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.MethodCallHelper;
|
||||||
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;
|
||||||
@ -52,6 +54,7 @@ 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.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import javassist.NotFoundException;
|
||||||
|
|
||||||
public class BytecodeGenMethod implements StatementVisitor {
|
public class BytecodeGenMethod implements StatementVisitor {
|
||||||
|
|
||||||
@ -675,7 +678,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
methSig.visitReturnType().visitTypeVariable("R");
|
||||||
// ")"+lam.getReturn.getBounds
|
// ")"+lam.getReturn.getBounds
|
||||||
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
Signature sig = new Signature(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_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
Type.getInternalName(Object.class), null);
|
Type.getInternalName(Object.class), null);
|
||||||
@ -763,7 +766,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(InstanceOf instanceOf) {
|
public void visit(InstanceOf instanceOf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
boolean parentBinary = isParentBinary;
|
boolean parentBinary = isParentBinary;
|
||||||
@ -772,100 +775,102 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
java.lang.reflect.Method methodRefl = null;
|
java.lang.reflect.Method methodRefl = null;
|
||||||
String clazz = receiverName.replace("/", ".");
|
String clazz = receiverName.replace("/", ".");
|
||||||
// if(!receiverName.equals(className)) {
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
String mDesc = "";
|
||||||
// This will be used if the class is not standard class (not in API)
|
|
||||||
ClassLoader cLoader2;
|
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
||||||
|
|
||||||
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
boolean toCreate = false;
|
||||||
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
|
||||||
try {
|
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||||
if(receiverName.contains("<")) {
|
// This will be used if the class is not standard class (not in API)
|
||||||
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
ClassLoader cLoader2;
|
||||||
}
|
|
||||||
|
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
try {
|
||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
if (receiverName.contains("<")) {
|
||||||
|
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
||||||
|
}
|
||||||
|
|
||||||
|
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
||||||
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// try {
|
|
||||||
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
|
||||||
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
|
||||||
// System.out.println("Methods of " + receiverName + " ");
|
|
||||||
// for(int i = 0; i<methods.length; i++) {
|
|
||||||
// System.out.println(methods[i]);
|
|
||||||
// }
|
|
||||||
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
|
||||||
// }catch (Exception e2) {
|
|
||||||
String superClass = "";
|
String superClass = "";
|
||||||
// TODO: Test SubMatrix.jav
|
|
||||||
while(true) {
|
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 {
|
try {
|
||||||
String superClazz = superClass.replace("/", ".");
|
superClass = helper.getSuperClass(receiverName);
|
||||||
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) {
|
try {
|
||||||
if(methodCall.name.equals(m.getName())) {
|
String superClazz = superClass.replace("/", ".");
|
||||||
methodRefl = m;
|
if(superClass.contains("<")) {
|
||||||
break;
|
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 e3) {
|
||||||
|
receiverName = superClass;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (NotInCurrentPackageException e2) {
|
||||||
break;
|
break;
|
||||||
} catch (Exception e3) {
|
|
||||||
receiverName = superClass;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
try {
|
toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
if(toCreate) {
|
||||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
try {
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
mDesc = helper.getDesc(clazz);
|
||||||
for(int i = 0; i<methods.length; i++) {
|
} catch (NotInCurrentPackageException | NotFoundException e) {
|
||||||
System.out.println(methods[i]);
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
|
if(clazz.contains("$$")) {
|
||||||
|
mDesc = helper.generateBCForFunN();
|
||||||
|
}else {
|
||||||
|
try {
|
||||||
|
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
|
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
|
for(int i = 0; i<methods.length; i++) {
|
||||||
|
System.out.println(methods[i]);
|
||||||
|
}
|
||||||
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
|
}
|
||||||
|
catch (Exception e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
|
||||||
}
|
|
||||||
catch (Exception e2) {
|
|
||||||
System.out.println("");
|
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
|
||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
String mDesc = "";
|
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
List<Boolean> argListMethCall = new LinkedList<>();
|
||||||
String receiverRefl="";
|
String receiverRefl="";
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null && receiverName.equals(className)) {
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
} else {
|
} else if(methodRefl != null) {
|
||||||
System.out.println(methodCall.name + " -> Refl != null");
|
System.out.println(methodCall.name + " -> Refl != null");
|
||||||
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
for(Parameter p:methodRefl.getParameters()) {
|
||||||
@ -880,6 +885,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
al.accept(argV);
|
al.accept(argV);
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
||||||
@ -917,6 +924,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDescForMethInCurrPkg(String name) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInCurrPkg(String superClass) {
|
||||||
|
for(ClassOrInterface cl : sf.KlassenVektor) {
|
||||||
|
if(superClass.equals(cl.getClassName().toString()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private String[] getTypes(List<Expression> arguments) {
|
private String[] getTypes(List<Expression> arguments) {
|
||||||
String[] types = new String[arguments.size()];
|
String[] types = new String[arguments.size()];
|
||||||
for(int i = 0; i<arguments.size(); ++i) {
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
@ -1252,10 +1272,16 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitBooleanLiteral((Boolean) value);
|
visitBooleanLiteral((Boolean) value);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case "java/lang/Byte":
|
||||||
visitByteLiteral(((Double) value).byteValue(), false);
|
if(value instanceof Double)
|
||||||
|
visitByteLiteral(((Double) value).byteValue(), false);
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitByteLiteral(((Integer) value).byteValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case "java/lang/Short":
|
||||||
visitShortLiteral(((Double) value).shortValue(), false);
|
if(value instanceof Double)
|
||||||
|
visitShortLiteral(((Double) value).shortValue(), false);
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitShortLiteral(((Integer) value).shortValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case "java/lang/Integer":
|
||||||
// zweite Argument isLong
|
// zweite Argument isLong
|
||||||
@ -1266,10 +1292,16 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitIntegerLiteral(((Integer) value).intValue(), false);
|
visitIntegerLiteral(((Integer) value).intValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case "java/lang/Long":
|
||||||
visitLongLiteral(((Integer) value).longValue(), true);
|
if(value instanceof Double)
|
||||||
|
visitLongLiteral(((Double) value).longValue(), true);
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitLongLiteral(((Integer) value).longValue(), true);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case "java/lang/Float":
|
||||||
visitFloatLiteral(((Double) value).floatValue());
|
if(value instanceof Double)
|
||||||
|
visitFloatLiteral(((Double) value).floatValue());
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitFloatLiteral(((Integer) value).floatValue());
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case "java/lang/Double":
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BytecodeGeneratorError extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public BytecodeGeneratorError(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NotFoundException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public NotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NotInCurrentPackageException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public NotInCurrentPackageException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -5,7 +5,11 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
@ -13,13 +17,18 @@ import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,14 +38,14 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
public class TPHExtractor extends AbstractASTWalker {
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
final HashMap<TypePlaceholder, Boolean> allTPHS = new HashMap<>();
|
final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
boolean inLocalOrParam = false;
|
boolean inLocalOrParam = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
@ -58,19 +67,80 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
allTPHS.put(resolvedTPH, inMethod);
|
allTPHS.put(resolvedTPH.getName(), inMethod);
|
||||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
// final List<TPHConstraint> cons = new ArrayList<>();
|
||||||
if (ag.contains(resolvedTPH) && ag.TA1.equals(resolvedTPH) && !contains(allPairs, ag)) {
|
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||||
|
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
|
// cons.add(con);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// Map<TPHConstraint, Boolean> visitMap = new HashMap<>();
|
||||||
|
// for(TPHConstraint cc : cons) {
|
||||||
|
// visitMap.put(cc, false);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// String left = resolvedTPH.getName();
|
||||||
|
// for (TPHConstraint cc : visitMap.keySet()) {
|
||||||
|
//
|
||||||
|
// if(visitMap.get(cc))
|
||||||
|
// continue;
|
||||||
|
//
|
||||||
|
// if (cc.getLeft().equals(left)) {
|
||||||
|
// allCons.add(cc);
|
||||||
|
// List<TPHConstraint> toVisit = getToVisitCons(cons,cc.getRight(), visitMap);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
//resultSet.resolveType(tph).getAdditionalGenerics().forEach(ag -> {
|
||||||
|
resultSet.genIns.forEach(ag -> {
|
||||||
|
|
||||||
|
// if (ag.contains(resolvedTPH) /* && ag.TA1.equals(resolvedTPH) */ && !contains(allPairs, ag)) {
|
||||||
if (inMethod)
|
if (inMethod)
|
||||||
methodAndTph.getPairs().add(ag);
|
methodAndTph.getPairs().add(ag);
|
||||||
allPairs.add(ag);
|
allPairs.add(ag);
|
||||||
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
allCons.add(con);
|
if(!containsConstraint(allCons,con))
|
||||||
}
|
allCons.add(con);
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
|
} else if (resultSet.resolveType(tph).resolvedType instanceof RefType) {
|
||||||
|
RefType rt = (RefType) resultSet.resolveType(tph).resolvedType;
|
||||||
|
rt.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
||||||
|
for(TPHConstraint con:allCons) {
|
||||||
|
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TPHConstraint> getToVisitCons(List<TPHConstraint> cons, String right, Map<TPHConstraint, Boolean> visitMap) {
|
||||||
|
List<TPHConstraint> res = new ArrayList<>();
|
||||||
|
for(TPHConstraint cc : cons) {
|
||||||
|
if(cc.getLeft().equals(right)) {
|
||||||
|
res.add(cc);
|
||||||
|
if(visitMap.get(cc))
|
||||||
|
visitMap.replace(cc, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(GenericRefType genericRefType) {
|
||||||
|
String name = genericRefType.getParsedName();
|
||||||
|
if (inMethod) {
|
||||||
|
methodAndTph.getLocalTphs().add(name);
|
||||||
|
if (inLocalOrParam)
|
||||||
|
methodAndTph.getLocalTphs().add(name);
|
||||||
|
}
|
||||||
|
allTPHS.put(name, inMethod);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||||
for (int i = 0; i < pairs.size(); ++i) {
|
for (int i = 0; i < pairs.size(); ++i) {
|
||||||
GenericInsertPair p = pairs.get(i);
|
GenericInsertPair p = pairs.get(i);
|
||||||
|
@ -41,11 +41,11 @@ public class Signature {
|
|||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private ArrayList<GenericInsertPair> commonPairs;
|
private ArrayList<GenericInsertPair> commonPairs;
|
||||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
||||||
private ArrayList<TypePlaceholder> tphsClass;
|
private ArrayList<String> tphsClass;
|
||||||
private ArrayList<TPHConstraint> consClass;
|
private ArrayList<TPHConstraint> consClass;
|
||||||
|
|
||||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<TypePlaceholder> tphsClass, ArrayList<TPHConstraint> consClass) {
|
ArrayList<GenericInsertPair> commonPairs, ArrayList<String> tphsClass, ArrayList<TPHConstraint> consClass) {
|
||||||
this.classOrInterface = classOrInterface;
|
this.classOrInterface = classOrInterface;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.commonPairs = commonPairs;
|
this.commonPairs = commonPairs;
|
||||||
@ -80,12 +80,12 @@ public class Signature {
|
|||||||
createSignatureForConsOrMethod(this.method,false);
|
createSignatureForConsOrMethod(this.method,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
|
public Signature(int numberOfParams) {
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForFunN(lambdaExpression, numberOfParams);
|
createSignatureForFunN(numberOfParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
private void createSignatureForFunN(int numberOfParams) {
|
||||||
|
|
||||||
// sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
for(int i = 0;i<numberOfParams;i++) {
|
for(int i = 0;i<numberOfParams;i++) {
|
||||||
@ -235,8 +235,9 @@ public class Signature {
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
||||||
if(resolved instanceof TypePlaceholder) {
|
if(resolved instanceof TypePlaceholder) {
|
||||||
resType.additionalGenerics.forEach(ag ->{
|
//resType.getAdditionalGenerics().forEach(ag ->{
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
resultSet.genIns.forEach(ag ->{
|
||||||
|
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
@ -246,8 +247,9 @@ public class Signature {
|
|||||||
WildcardType resWC = (WildcardType) resolved;
|
WildcardType resWC = (WildcardType) resolved;
|
||||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
||||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
if(resType2.resolvedType instanceof TypePlaceholder) {
|
||||||
resType2.additionalGenerics.forEach(ag ->{
|
//resType2.getAdditionalGenerics().forEach(ag ->{
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
resultSet.genIns.forEach(ag ->{
|
||||||
|
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,17 @@ package de.dhbwstuttgart.bytecode.utilities;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
public class MethodAndTPH {
|
public class MethodAndTPH {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private final ArrayList<String> tphs = new ArrayList<>();
|
private final ArrayList<String> tphs = new ArrayList<>();
|
||||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||||
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||||
// tphs of local variables and parameters
|
// tphs of local variables and parameters
|
||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
|
|
||||||
@ -21,7 +24,10 @@ public class MethodAndTPH {
|
|||||||
return tphs;
|
return tphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GenericInsertPair> getPairs(){
|
// public ArrayList<GenericInsertPair> getPairs(){
|
||||||
|
// return pairs;
|
||||||
|
// }
|
||||||
|
public ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> getPairs(){
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,255 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import javassist.NotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MethodCallHelper {
|
||||||
|
private MethodCall methCall;
|
||||||
|
private SourceFile sourceFile;
|
||||||
|
private ResultSet resultSet;
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param methCall
|
||||||
|
* @param sourceFile
|
||||||
|
* @param resultSet
|
||||||
|
* @param path TODO
|
||||||
|
*/
|
||||||
|
public MethodCallHelper(MethodCall methCall, SourceFile sourceFile, ResultSet resultSet, String path) {
|
||||||
|
this.methCall = methCall;
|
||||||
|
this.sourceFile = sourceFile;
|
||||||
|
this.resultSet = resultSet;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInCurrPkg(String className) {
|
||||||
|
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
||||||
|
if (className.equals(cl.getClassName().toString()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuperClass(String className) throws NotInCurrentPackageException {
|
||||||
|
|
||||||
|
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
|
if (className.equals(cl.getClassName().toString())) {
|
||||||
|
return cl.getSuperClass().getName().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotInCurrentPackageException("Class " + className + " is not in the current package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassOrInterface getClassFromCurrPkg(String className) throws NotInCurrentPackageException {
|
||||||
|
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
||||||
|
if (className.equals(cl.getClassName().toString()))
|
||||||
|
return cl;
|
||||||
|
}
|
||||||
|
throw new NotInCurrentPackageException("Class of " + className + " is not in the current package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc(String className) throws NotInCurrentPackageException, NotFoundException {
|
||||||
|
String name = methCall.name;
|
||||||
|
ClassOrInterface clazz = getClassFromCurrPkg(className);
|
||||||
|
|
||||||
|
Map<String, String> genAndBoundsClass = getGenericsAndBounds(clazz.getGenerics());
|
||||||
|
modifyGenAndBounds(genAndBoundsClass);
|
||||||
|
for (Method m : clazz.getMethods()) {
|
||||||
|
if (name.equals(m.getName())) {
|
||||||
|
Map<String, String> genAndBoundsMethod = getGenericsAndBoundsMethod(m.getGenerics());
|
||||||
|
modifyGenAndBounds(genAndBoundsMethod);
|
||||||
|
boolean hasGen = hasGen(m, genAndBoundsClass);
|
||||||
|
NormalMethod nm = new NormalMethod(m, (HashMap<String, String>) genAndBoundsClass,
|
||||||
|
(HashMap<String, String>) genAndBoundsMethod, hasGen);
|
||||||
|
return nm.accept(new DescriptorToString(resultSet));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotFoundException("Method " + name + " is not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasGen(Method m, Map<String, String> genericsAndBounds) {
|
||||||
|
String retType = resultSet.resolveType(m.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
|
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||||
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ") || retType.contains("<");
|
||||||
|
|
||||||
|
Map<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||||
|
Iterator<FormalParameter> itr = m.getParameterList().iterator();
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
|
||||||
|
}
|
||||||
|
/*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*/
|
||||||
|
if(!hasGenInParameterList) {
|
||||||
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
|
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
|
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.contains("TPH ")||sigOfParam.contains("<")) {
|
||||||
|
hasGenInParameterList = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getGenericsAndBoundsMethod(Iterable<? extends GenericTypeVar> generics) {
|
||||||
|
Map<String, String> genAndBounds = new HashMap<>();
|
||||||
|
Iterator<? extends GenericTypeVar> itr = generics.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
GenericTypeVar gtv = itr.next();
|
||||||
|
getBoundsOfTypeVar(gtv, genAndBounds);
|
||||||
|
}
|
||||||
|
return genAndBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyGenAndBounds(Map<String, String> genAndBoundsClass) {
|
||||||
|
List<String> visited = new ArrayList<>(genAndBoundsClass.size());
|
||||||
|
Map<String, String> toReplace = new HashMap<>();
|
||||||
|
for (String tv : genAndBoundsClass.keySet()) {
|
||||||
|
|
||||||
|
if (visited.contains(tv))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<String> types = new LinkedList<>();
|
||||||
|
String bound = genAndBoundsClass.get(tv);
|
||||||
|
types.add(tv);
|
||||||
|
visited.add(tv);
|
||||||
|
boolean doReplace = false;
|
||||||
|
while (genAndBoundsClass.keySet().contains(bound)) {
|
||||||
|
doReplace = true;
|
||||||
|
types.add(bound);
|
||||||
|
visited.add(bound);
|
||||||
|
bound = genAndBoundsClass.get(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doReplace) {
|
||||||
|
for (String tt : types) {
|
||||||
|
toReplace.put(tt, bound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String key : toReplace.keySet()) {
|
||||||
|
genAndBoundsClass.replace(key, toReplace.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getGenericsAndBounds(GenericDeclarationList generics) {
|
||||||
|
Map<String, String> genAndBounds = new HashMap<>();
|
||||||
|
Iterator<GenericTypeVar> itr = generics.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
GenericTypeVar gtv = itr.next();
|
||||||
|
getBoundsOfTypeVar(gtv, genAndBounds);
|
||||||
|
}
|
||||||
|
return genAndBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBoundsOfTypeVar(GenericTypeVar g, Map<String, String> genAndBounds) {
|
||||||
|
|
||||||
|
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||||
|
while (bItr.hasNext()) {
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric b = bItr.next();
|
||||||
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateBCForFunN() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
|
|
||||||
|
int numberOfParams = 0;
|
||||||
|
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||||
|
Iterator<Expression> itr1 = methCall.arglist.getArguments().iterator();
|
||||||
|
String methDesc = "(";
|
||||||
|
while(itr1.hasNext()) {
|
||||||
|
numberOfParams++;
|
||||||
|
// getBounds
|
||||||
|
paramVisitor.visitTypeVariable("T" + numberOfParams);
|
||||||
|
methDesc += "L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
itr1.next();
|
||||||
|
}
|
||||||
|
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
|
||||||
|
methSig.visitReturnType().visitTypeVariable("R");
|
||||||
|
// ")"+lam.getReturn.getBounds
|
||||||
|
Signature sig = new Signature(numberOfParams);
|
||||||
|
String name = "Fun" + numberOfParams + "$$";
|
||||||
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
|
Type.getInternalName(Object.class), null);
|
||||||
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
|
methSig.toString(), null);
|
||||||
|
mvApply.visitEnd();
|
||||||
|
writeClassFile(classWriter.toByteArray(), name);
|
||||||
|
return methDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeClassFile(byte[] bytecode, String name) {
|
||||||
|
FileOutputStream output;
|
||||||
|
try {
|
||||||
|
System.out.println("generating " + name + ".class file...");
|
||||||
|
output = new FileOutputStream(
|
||||||
|
new File(path + name + ".class"));
|
||||||
|
output.write(bytecode);
|
||||||
|
output.close();
|
||||||
|
System.out.println(name + ".class file generated");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,6 +23,7 @@ public class MethodFromMethodCall {
|
|||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArgumentList getArgList() {
|
public ArgumentList getArgList() {
|
||||||
return argList;
|
return argList;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
public class Simplify {
|
public class Simplify {
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
||||||
ArrayList<TypePlaceholder> tphsClass) {
|
ArrayList<String> tphsClass) {
|
||||||
// 1. check if there are any simple cycles like L<R and R<L:
|
// 1. check if there are any simple cycles like L<R and R<L:
|
||||||
// a) yes => set L=R and:
|
// a) yes => set L=R and:
|
||||||
// * remove both constraints
|
// * remove both constraints
|
||||||
@ -38,8 +38,10 @@ public class Simplify {
|
|||||||
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
|
|
||||||
for(TPHConstraint c : tphExtractor.allCons) {
|
for(TPHConstraint c : tphExtractor.allCons) {
|
||||||
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
if(!containsConstraint(allCons,c)) {
|
||||||
allCons.add(nc);
|
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
||||||
|
allCons.add(nc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
|
|
||||||
@ -382,7 +384,7 @@ public class Simplify {
|
|||||||
|
|
||||||
if (!containTPH(methodTphs, superTphRes)) {
|
if (!containTPH(methodTphs, superTphRes)) {
|
||||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
||||||
if (classTPHSContainsTPH(tphsClass, superTphRes)) {
|
if (tphsClass.contains(superTphRes)/*classTPHSContainsTPH(tphsClass, superTphRes)*/) {
|
||||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||||
} else {
|
} else {
|
||||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
||||||
@ -450,6 +452,15 @@ public class Simplify {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
||||||
|
for(TPHConstraint con:allCons) {
|
||||||
|
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
||||||
List<String> oldNames = replRes.values().iterator().next();
|
List<String> oldNames = replRes.values().iterator().next();
|
||||||
String newName = replRes.keySet().iterator().next();
|
String newName = replRes.keySet().iterator().next();
|
||||||
@ -463,7 +474,7 @@ public class Simplify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
||||||
ArrayList<TypePlaceholder> tphsClass) {
|
ArrayList<String> tphsClass) {
|
||||||
// all constraints that will be simplified
|
// all constraints that will be simplified
|
||||||
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
@ -627,7 +638,9 @@ public class Simplify {
|
|||||||
if (isTPHInConstraint(result, sub))
|
if (isTPHInConstraint(result, sub))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!classTPHSContainsTPH(tphsClass, sub))
|
// if (!classTPHSContainsTPH(tphsClass, sub))
|
||||||
|
// continue;
|
||||||
|
if (!tphsClass.contains(sub))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (numOfVisitedPairs >= size)
|
if (numOfVisitedPairs >= size)
|
||||||
@ -656,7 +669,7 @@ public class Simplify {
|
|||||||
// add X at the beginning of the list.
|
// add X at the beginning of the list.
|
||||||
while (subAndSuper.containsValue(subTphRes)) {
|
while (subAndSuper.containsValue(subTphRes)) {
|
||||||
for (String tph : subAndSuper.keySet()) {
|
for (String tph : subAndSuper.keySet()) {
|
||||||
if (classTPHSContainsTPH(tphsClass, tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
if (/*classTPHSContainsTPH(tphsClass, tph)*/tphsClass.contains(tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
||||||
subTphRes = tph;
|
subTphRes = tph;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
*/
|
*/
|
||||||
public class SimplifyResult {
|
public class SimplifyResult {
|
||||||
private final ArrayList<TPHConstraint> classConstraints;
|
private final ArrayList<TPHConstraint> classConstraints;
|
||||||
private final ArrayList<TypePlaceholder> tphsClass;
|
private final ArrayList<String> tphsClass;
|
||||||
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
||||||
|
|
||||||
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<TypePlaceholder> tphsClass,
|
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<String> tphsClass,
|
||||||
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
||||||
super();
|
super();
|
||||||
this.classConstraints = classConstraints;
|
this.classConstraints = classConstraints;
|
||||||
@ -35,7 +35,7 @@ public class SimplifyResult {
|
|||||||
return methodsConstraints;
|
return methodsConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<TypePlaceholder> getTphsClass() {
|
public ArrayList<String> getTphsClass() {
|
||||||
return tphsClass;
|
return tphsClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
@ -51,6 +52,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
//import org.apache.commons.io.output.NullOutputStream;
|
//import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
@ -563,8 +565,8 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
//Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, 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();
|
||||||
@ -650,7 +652,7 @@ public class JavaTXCompiler {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// um pfad erweitern
|
// um pfad erweitern
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
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);
|
||||||
|
@ -23,4 +23,9 @@ public class GenericInsertPair {
|
|||||||
if(TA2.equals(additionalTPH))return true;
|
if(TA2.equals(additionalTPH))return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GenIns(" + TA1.toString() + " < " + TA2.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,9 @@ public class PairTPHequalRefTypeOrWildcardType extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "(" + left.toString() + " = " + right.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,9 @@ public class PairTPHsmallerTPH extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "(" + left.toString() + " < " + right.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ResolvedType{
|
public class ResolvedType{
|
||||||
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
||||||
public final Set<GenericInsertPair> additionalGenerics;
|
//public final Set<GenericInsertPair> additionalGenerics;
|
||||||
|
|
||||||
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
||||||
this.resolvedType = resolvedType;
|
this.resolvedType = resolvedType;
|
||||||
this.additionalGenerics = additionalGenerics;
|
//this.additionalGenerics = additionalGenerics;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.result;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
@ -15,9 +16,14 @@ import static de.dhbwstuttgart.typeinference.result.ResultPairMap.RESULT_PAIRS;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ResultSet {
|
public class ResultSet {
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public ResultSet(Set<ResultPair> set){
|
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||||
|
|
||||||
|
public ResultSet(Set<ResultPair> set){
|
||||||
this.results = set;
|
this.results = set;
|
||||||
|
this.genIns = new HashSet<>();
|
||||||
|
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(ResultPair toCheck) {
|
public boolean contains(ResultPair toCheck) {
|
||||||
|
@ -19,6 +19,8 @@ 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;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
@ -46,6 +48,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@ -165,7 +168,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
thNo = totalnoOfThread;
|
thNo = totalnoOfThread;
|
||||||
writeLog("thNo2 " + thNo);
|
writeLog("thNo2 " + thNo);
|
||||||
try {
|
try {
|
||||||
this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo));
|
this.logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
|
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo));
|
||||||
|
logFile.write("");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("log-File nicht vorhanden");
|
System.err.println("log-File nicht vorhanden");
|
||||||
|
37
src/test/java/bytecode/ClassGenLamTest.java
Normal file
37
src/test/java/bytecode/ClassGenLamTest.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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 ClassGenLamTest {
|
||||||
|
|
||||||
|
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")+"/src/test/resources/bytecode/javFiles/ClassGenLam.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("ClassGenLam");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
src/test/resources/bytecode/javFiles/ClassGenLam.jav
Normal file
8
src/test/resources/bytecode/javFiles/ClassGenLam.jav
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class ClassGenLam {
|
||||||
|
lam = x-> x;
|
||||||
|
// public ClassGenLam() {
|
||||||
|
// lam = x->x;
|
||||||
|
// }
|
||||||
|
}
|
@ -1,22 +1,25 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.Long;
|
||||||
|
import java.lang.Short;
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty {
|
||||||
public fact;
|
public fact;
|
||||||
Faculty() {
|
Faculty() {
|
||||||
fact = (x) -> {
|
fact = (x) -> {
|
||||||
if (x == 1) {
|
if (x == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return x * (fact.apply(x-1));
|
return x * (fact.apply(x-1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public getFact(x) {
|
public getFact(x) {
|
||||||
return fact.apply(x);
|
return fact.apply(x);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// m (x) {
|
// m (x) {
|
||||||
//
|
//
|
||||||
//// var fact = (x) -> {
|
//// var fact = (x) -> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
public class Id {
|
public class Id {
|
||||||
|
|
||||||
<A extends B, B> B id(A b){
|
id(b){
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ public class Lambda {
|
|||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
return lam1;
|
return lam1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class Matrix extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mul(java.util.Vector<? extends Vector<? extends java.lang.Integer>> m) {
|
mul(m) {
|
||||||
var ret = new Matrix();
|
var ret = new Matrix();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
|
@ -18,7 +18,7 @@ public class MatrixOP extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Fun2$$<java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, MatrixOP> mul = (m1, m2) -> {
|
public mul = (m1, m2) -> {
|
||||||
var ret = new MatrixOP();
|
var ret = new MatrixOP();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < m1.size()) {
|
while(i < m1.size()) {
|
||||||
|
@ -10,8 +10,6 @@ public class OL {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OLMain {
|
public class OLMain {
|
||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
public class TypedID/*<L extends K,K> */ {
|
public class TypedID/*<L extends K,K> */ {
|
||||||
|
|
||||||
<K> id(K b){
|
lam = x-> x;
|
||||||
|
|
||||||
|
id(b){
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m(){
|
||||||
|
return lam;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user