Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin

src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	test/bytecode/javFiles/Lambda.jav
	test/typeinference/UnifyTest.java

	modified:   src/de/dhbwstuttgart/.DS_Store
	modified:   src/de/dhbwstuttgart/bytecode/BytecodeGen.java
	modified:   src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java
	modified:   src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java
	modified:   src/de/dhbwstuttgart/bytecode/signature/Signature.java
	modified:   src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java
	modified:   src/de/dhbwstuttgart/bytecode/utilities/MethodFromMethodCall.java
	modified:   src/de/dhbwstuttgart/syntaxtree/type/FunN.java
	modified:   src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java
	modified:   src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java
	modified:   src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
	modified:   target/JavaTXcompiler-0.1-jar-with-dependencies.jar
	modified:   test/bytecode/javFiles/Lambda.jav
	modified:   test/bytecode/javFiles/Matrix.jav
	modified:   test/javFiles/Lambda.jav
	modified:   test/javFiles/Matrix.jav
	modified:   test/javFiles/Vector.jav
	modified:   test/typeinference/UnifyTest.java
This commit is contained in:
Martin Plümicke 2018-07-05 00:54:40 +02:00
commit 72c2e19def
22 changed files with 383 additions and 68 deletions

Binary file not shown.

View File

@ -121,7 +121,7 @@ public class BytecodeGen implements ASTVisitor {
// Nur einmal ausführen!! // Nur einmal ausführen!!
if(!isVisited) { if(!isVisited) {
classOrInterface.accept(tphExtractor); classOrInterface.accept(tphExtractor);
getCommonTPHS(tphExtractor); getCommonTPHS(tphExtractor);
String sig = null; String sig = null;
@ -275,6 +275,11 @@ public class BytecodeGen implements ASTVisitor {
} }
private ArrayList<GenericInsertPair> simplifyPairs(String methodName, ArrayList<GenericInsertPair> allPairs) { 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<>(); ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
MethodAndTPH method; MethodAndTPH method;
@ -320,22 +325,41 @@ public class BytecodeGen implements ASTVisitor {
numOfVisitedPairs++; numOfVisitedPairs++;
} }
// TODO: 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.
// Subtype // Subtype
TypePlaceholder subTphRes = tphsInRel.get(0); TypePlaceholder subTphRes = tphsInRel.get(0);
// Die größte Supertype // Die größte Supertype
TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1); 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; int i = 2;
while(!methodTphs.contains(superTphRes) && (tphsInRel.size()-i) >0) { while(!methodTphs.contains(superTphRes) && (tphsInRel.size()-i) >0) {
superTphRes = tphsInRel.get(tphsInRel.size()-i); superTphRes = tphsInRel.get(tphsInRel.size()-i);
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.
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes); // Zweite Operand für die Fälle wie in Lambda.jav (Paramtrisierte Typen)
simplifiedPairs.add(sPair); if(methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes)) {
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes);
simplifiedPairs.add(sPair);
}
} }
return simplifiedPairs; return simplifiedPairs;
} }
@ -599,7 +623,6 @@ public class BytecodeGen implements ASTVisitor {
methodAndTph.getTphs().add(resolvedTPH); methodAndTph.getTphs().add(resolvedTPH);
allTPHS.put(resolvedTPH,inMethod); allTPHS.put(resolvedTPH,inMethod);
ResolvedType rst = resultSet.resolveType(tph);
resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{ resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{
if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) { if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) {
if(inMethod) if(inMethod)
@ -625,6 +648,7 @@ public class BytecodeGen implements ASTVisitor {
inMethod = false; inMethod = false;
ListOfMethodsAndTph.add(methodAndTph); ListOfMethodsAndTph.add(methodAndTph);
} }
} }
} }

View File

@ -639,19 +639,32 @@ public class BytecodeGenMethod implements StatementVisitor {
public void visit(MethodCall methodCall) { public void visit(MethodCall methodCall) {
//ClassLoader.getSystemClassLoader().loadClass(className).getMethod(name, parameterTypes) //ClassLoader.getSystemClassLoader().loadClass(className).getMethod(name, parameterTypes)
String receiverName = getResolvedType(methodCall.receiver.getType());
System.out.println("Methods of " + receiverName + " ");
ClassLoader cl = ClassLoader.getSystemClassLoader();
try {
java.lang.reflect.Method[] methods = cl.loadClass("java.util.Vector").getMethods();
System.out.println("Methods of " + receiverName + " ");
for(java.lang.reflect.Method m : methods) {
System.out.println(m.getName() + " " + m.toGenericString()+ " ==> ");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor())); System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
methodCall.receiver.accept(this); methodCall.receiver.accept(this);
methodCall.arglist.accept(this); methodCall.arglist.accept(this);
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(), MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
genericsAndBoundsMethod, genericsAndBounds); receiverName, genericsAndBoundsMethod, genericsAndBounds);
String mDesc = method.accept(new DescriptorToString(resultSet)); String mDesc = method.accept(new DescriptorToString(resultSet));
System.out.println("Methodcall Desc : " + mDesc); System.out.println("Methodcall Desc : " + mDesc);
// 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, getResolvedType(methodCall.receiver.getType()), methodCall.name, mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name,
mDesc, false); mDesc, true);
} else { } else {
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getResolvedType(methodCall.receiver.getType()), methodCall.name, mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getResolvedType(methodCall.receiver.getType()), methodCall.name,
mDesc, isInterface); mDesc, isInterface);

View File

@ -123,9 +123,21 @@ 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();
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";"; String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
desc += "L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + "L"+ d + ";";
}
}
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + ")"+"L"+retType+";";
} }
desc = addReturnType(desc, lambdaExpression.getReturnType(), resultSet);
return desc; return desc;
} }
@ -135,9 +147,22 @@ 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();
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor())+";"; String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
desc += "L"+Type.getInternalName(Object.class)+ ";";
}else {
desc += "L"+ d + ";";
}
}
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + ")"+"L"+retType+";";
} }
desc = desc + ")"+"L"+resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
return desc; return desc;
} }
@ -147,7 +172,7 @@ public class DescriptorToString implements DescriptorVisitor{
for(Expression e : methodFromMethodCall.getArgList().getArguments()) { for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor()); String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) { if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
desc += "L"+Type.getInternalName(Object.class)+ ";"; desc += "L"+Type.getInternalName(Object.class)+ ";";
}else { }else {
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) { if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
@ -164,7 +189,7 @@ public class DescriptorToString implements DescriptorVisitor{
System.out.println("DescriptorToString retType = " + retType); System.out.println("DescriptorToString retType = " + retType);
if(retType.equals("void")) { if(retType.equals("void")) {
desc += ")V"; desc += ")V";
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){ }else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
desc += ")L"+Type.getInternalName(Object.class)+ ";"; desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else { }else {
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) { if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {

View File

@ -9,6 +9,7 @@ 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.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.Constructor;
@ -16,9 +17,11 @@ 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.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair; 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 {
@ -106,7 +109,7 @@ public class Signature {
// 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
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()); String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
if(ret.substring(0,4).equals("TPH ")) { if(ret.substring(0,4).equals("TPH ")) {
String g = ret.substring(4)+"$"; String g = ret.substring(4,ret.length())+"$";
if(genericsAndBounds.containsKey(g)) { if(genericsAndBounds.containsKey(g)) {
genericsAndBoundsMethod.put(g, genericsAndBounds.get(g)); genericsAndBoundsMethod.put(g, genericsAndBounds.get(g));
}else { }else {
@ -117,13 +120,21 @@ public class Signature {
} }
} }
if(ret.contains("<")) {
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
if(hasTPHs(ref)) {
createSignatureForParameterizedType(ref);
}
}
// Parameters // 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 ")) {
String gP = pT.substring(4)+"$"; String gP = pT.substring(4,pT.length())+"$";
if(!genericsAndBounds.containsKey(gP) && !genericsAndBoundsMethod.containsKey(gP)) { if(!genericsAndBounds.containsKey(gP) && !genericsAndBoundsMethod.containsKey(gP)) {
sw.visitFormalTypeParameter(gP); sw.visitFormalTypeParameter(gP);
String bound = Type.getInternalName(Object.class); String bound = Type.getInternalName(Object.class);
@ -147,6 +158,12 @@ public class Signature {
} }
} }
if(pT.contains("<")) {
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
if(hasTPHs(ref))
createSignatureForParameterizedType(ref);
}
for(GenericInsertPair p:methodPairs) { for(GenericInsertPair p:methodPairs) {
String name = p.TA1.getName()+"$"; String name = p.TA1.getName()+"$";
if(!genericsAndBoundsMethod.containsKey(name)) { if(!genericsAndBoundsMethod.containsKey(name)) {
@ -191,6 +208,142 @@ public class Signature {
} }
// 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()) {
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

View File

@ -22,7 +22,12 @@ 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();
params += "L"+param.toString().replace(".", "/"); if(param instanceof TypePlaceholder) {
params += "T" + ((TypePlaceholder) param).getName() + "$";
} else {
params += "L"+param.toString().replace(".", "/");
}
if(it.hasNext())params += ";"; if(it.hasNext())params += ";";
} }
params += ";>"; params += ";>";

View File

@ -9,13 +9,16 @@ 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,
HashMap<String, String> genericsAndBoundsMethod,HashMap<String,String> genericsAndBounds) { String receiverName, HashMap<String, String> genericsAndBoundsMethod,
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;
} }
@ -28,6 +31,10 @@ 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;
} }

View File

@ -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());
} }
/** /**

View File

@ -8,32 +8,36 @@ 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<RefTypeOrTPHOrWildcardOrGeneric> funNParams) { public FunNClass(List<GenericRefType> funNParams) {
super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(), super(0, new JavaClassName("Fun"+(funNParams.size())), 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<RefTypeOrTPHOrWildcardOrGeneric> funNParams) { private static GenericDeclarationList createGenerics(List<GenericRefType> funNParams) {
//PL 2018-06-22: so geaendert, dass generierte Generics den Namen der funParams entsprechen.
List<GenericTypeVar> generics = new ArrayList<>(); List<GenericTypeVar> generics = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : funNParams){ for(GenericRefType param : funNParams){
generics.add(new GenericTypeVar(NameGenerator.makeNewName(), generics.add(new GenericTypeVar(param.getParsedName(),//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<RefTypeOrTPHOrWildcardOrGeneric> funNParams) { private static List<Method> createMethods(List<GenericRefType> funNParams) {
return null; return null;
} }
} }

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> params; List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
List<RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){ List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
super(scope); super(scope);
this.receiver = receiver; this.receiver = receiver;
this.retType = retType; this.retType = retType;
@ -38,7 +38,9 @@ public class MethodAssumption extends Assumption{
} }
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
if(retType instanceof GenericRefType)return resolver.resolve(retType); if(retType instanceof GenericRefType) {
return resolver.resolve(retType);
}
return retType; return retType;
} }

View File

@ -6,6 +6,7 @@ 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;
@ -327,7 +328,16 @@ 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
@ -451,11 +461,14 @@ 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<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>(); List<GenericRefType> 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()));
} }
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()), funNParams.get(funNParams.size()-1);
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size()-1), funNParams.subList(0, funNParams.size()-1),
new TypeScope() { new TypeScope() {
@Override @Override
public Iterable<? extends GenericTypeVar> getGenerics() { public Iterable<? extends GenericTypeVar> getGenerics() {
@ -498,7 +511,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(info.checkGTV(fp.getType())); params.add(fp.getType()); //info.checkGTV(fp.getType())); //PL 2018-06-22 GTV sollen in Argumenten erhalten bleiben
} }
return params; return params;
} }

View File

@ -933,7 +933,9 @@ 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()));
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); Set<UnifyType> fBounded = pair.getfBounded();
fBounded.add(lhsType);
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
} }
return Optional.of(result); return Optional.of(result);

View File

@ -13,6 +13,7 @@ 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;
@ -141,11 +142,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* @return The set of all principal type unifiers * @return The set of all principal type unifiers
*/ */
protected Set<Set<UnifyPair>> unify(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));
if (aas.isEmpty()) { //writeLog(nOfUnify.toString() + " AA: " + aas.toString());
System.out.println(""); //if (aas.isEmpty()) {
} // System.out.println("");
//}
/* /*
* Step 1: Repeated application of reduce, adapt, erase, swap * Step 1: Repeated application of reduce, adapt, erase, swap
*/ */
@ -470,6 +472,7 @@ 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 = 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
@ -494,7 +497,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
//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("");
@ -524,6 +528,8 @@ 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 ->
@ -1068,7 +1074,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)); resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
result.add(resultPrime); result.add(resultPrime);
//writeLog(resultPrime.toString()); //writeLog(resultPrime.toString());
@ -1098,14 +1104,34 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
break; break;
} }
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) { for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
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());
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); Set<UnifyType> fBounded = pair.getfBounded();
int i_ef = i;
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
{
ArrayList<UnifyPair> termList = new ArrayList<UnifyPair>();
termList.add(new UnifyPair(y,thetaS.getTypeParams().get(i_ef), PairOperator.EQUALSDOT));
return ((match.match(termList).isPresent()) || x);
};
//if (parai.getName().equals("java.lang.Integer")) {
// System.out.println("");
//}
BinaryOperator<Boolean> bo = (x,y) -> (x || y);
if (fBounded.stream().reduce(false,f,bo)) {
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
}
else {
fBounded.add(thetaS.getTypeParams().get(i));
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded));
}
} }
if(allGen) if(allGen)
@ -1139,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)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
result.add(resultPrime); result.add(resultPrime);
//writeLog(resultPrime.toString()); //writeLog("resultPrime: " + 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));

View File

@ -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()); return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair(), p.getfBounded());
} }
/** /**

View File

@ -50,6 +50,13 @@ public class UnifyPair {
* PL 2018-03-15 * PL 2018-03-15
*/ */
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;
@ -82,6 +89,12 @@ 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.
*/ */
@ -138,6 +151,10 @@ 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))
@ -177,7 +194,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 + ")"; return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
} }
/* /*

View File

@ -1,11 +1,16 @@
import java.lang.Integer; import java.util.Vector;
class Apply { }
public class Lambda { public class Lambda {
m () { m () {
var lam1 = (Integer x) -> { var lam1 = (x) -> {
return x; return x;
}; };
return lam1;
return lam1.apply(new Apply());
//return lam1;
//return new Vector();
} }
} }

View File

@ -8,9 +8,9 @@ public class Matrix extends Vector<Vector<Integer>> {
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()) {
@ -18,9 +18,9 @@ public class Matrix extends Vector<Vector<Integer>> {
// * m.elementAt(k).elementAt(j); // * m.elementAt(k).elementAt(j);
// k++; } // k++; }
// v2.addElement(new Integer(erg)); // v2.addElement(new Integer(erg));
j++; } // j++; }
ret.addElement(v2); // ret.addElement(v2);
i++; // i++;
} }
return ret; return ret;
} }

View File

@ -1,5 +1,4 @@
import java.lang.Integer; class Apply { }
import java.lang.Number;
public class Lambda { public class Lambda {
@ -7,7 +6,7 @@ public class Lambda {
var lam1 = (Integer x) -> { var lam1 = (Integer x) -> {
return x; return x;
}; };
return lam1.apply(1); return lam1.apply(new Apply());
} }
} }

View File

@ -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));

View File

@ -1,8 +1,23 @@
import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import java.lang.Object;
class MyVector{ class MyVector{
id(x){ id(x){
return (x.elementAt(0)); Object i;
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
x.add(i);
return x;
} }
} }

View File

@ -28,13 +28,20 @@ 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 {
@ -74,16 +81,14 @@ 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"));
//JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav"));
//compiler.generateBytecode(); //compiler.generateBytecode();
} }
*/
/* /*
@Test @Test
public void vector() throws IOException, ClassNotFoundException { public void vector() throws IOException, ClassNotFoundException {