modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java

modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   test/bytecode/MatrixTest.java
	src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
This commit is contained in:
Martin Plümicke 2018-07-25 00:52:28 +02:00
parent c43d9ab9f5
commit 421169a72d
3 changed files with 88 additions and 51 deletions

View File

@ -176,7 +176,7 @@ public class JavaTXCompiler {
.collect(Collectors.toCollection(HashSet::new));
varianceInheritance(xConsSet);
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure, logFile, log);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();

View File

@ -49,6 +49,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
private static int i = 0;
private boolean printtag = false;
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
private static int noOfThread = 0;
private int thNo;
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
FileWriter logFile;
@ -96,6 +98,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
this.logFile = logFile;
this.log = log;
rules = new RuleSet(logFile);
noOfThread++;
thNo = noOfThread;
//System.out.println(noOfThread);
//System.out.println(eq);
}
@ -451,9 +457,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("nextSetasList: " + nextSetasList.toString());
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
Set<UnifyPair> a = null;
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
if (variance == 1) {
a = oup.max(nextSetasList.iterator());
nextSetasList.remove(a);
//nextSetasList.remove(a);
nextSetasListRest = new ArrayList<>(nextSetasList);
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
while (nextSetasListItRest.hasNext()) {
Set<UnifyPair> a_next = nextSetasListItRest.next();
if (//a.equals(a_next) ||
(oup.compare(a, a_next) == 1)) {
nextSetasListRest.remove(a_next);
}
}
}
else if (variance == -1) {
a = oup.min(nextSetasList.iterator());
@ -491,7 +507,21 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
elems.add(a);
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
//writeLog("Vor unify2 Aufruf: " + eq.toString());
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
Set<Set<UnifyPair>> res = new HashSet<>();
if(parallel) {
Set<TypeUnifyTask> forks = new HashSet<>();
for(Set<UnifyPair> nSaL : nextSetasListRest) {
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, true, logFile, log);
forks.add(fork);
fork.fork();
}
for(TypeUnifyTask fork : forks) {
res.addAll(fork.join());
}
}
else {
res = unify2(elems, eq, fc, parallel);
}
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = res;
@ -522,6 +552,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
System.out.print("");
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
if (variance == 1) {
/* nextSetasList = nextSetasListRest; */
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
*/
System.out.println("");
while (nextSetasListIt.hasNext()) {
Set<UnifyPair> a_next = nextSetasListIt.next();
@ -530,6 +563,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
nextSetasList.remove(a_next);
}
}
}
else { if (variance == -1) {
System.out.println("");
@ -1242,6 +1276,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
void writeLog(String str) {
if (log) {
try {
logFile.write("Thread no.:" + thNo + "\n");
logFile.write(str+"\n");
logFile.flush();

View File

@ -36,55 +36,57 @@ public class MatrixTest {
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Matrix");
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
Vector<Integer> v1 = new Vector<Integer> ();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer> ();
v2.addElement(3);
v2.addElement(3);
//Matrix m1 = new Matrix();
//m1.addElement(v1);
//m1.addElement(v2);
vv.addElement(v1);
vv.addElement(v2);
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
Vector<Integer> v3 = new Vector<Integer> ();
v3.addElement(2);
v3.addElement(2);
Vector<Integer> v4 = new Vector<Integer> ();
v4.addElement(3);
v4.addElement(3);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
vv1.addElement(v3);
vv1.addElement(v4);
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
//Matrix m3 = m1.mul(vv1);
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix();
//Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
Vector<Integer> v1 = new Vector<Integer> ();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer> ();
v2.addElement(3);
v2.addElement(3);
//Method[] ms = classToTest.getSuperclass().getDeclaredMethods();
Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class);
addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1);
addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2);
//vv.addElement(v1);
//vv.addElement(v2);
//instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
Vector<Integer> v5 = new Vector<Integer> ();
v5.addElement(10);
v5.addElement(10);
Vector<Integer> v6 = new Vector<Integer> ();
v6.addElement(15);
v6.addElement(15);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
res.addElement(v5);
res.addElement(v6);
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
assertEquals(result, instanceOfClass_m3);
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
Vector<Integer> v3 = new Vector<Integer> ();
v3.addElement(2);
v3.addElement(2);
Vector<Integer> v4 = new Vector<Integer> ();
v4.addElement(3);
v4.addElement(3);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
vv1.addElement(v3);
vv1.addElement(v4);
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
//Matrix m3 = m1.mul(vv1);
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
Vector<Integer> v5 = new Vector<Integer> ();
v5.addElement(10);
v5.addElement(10);
Vector<Integer> v6 = new Vector<Integer> ();
v6.addElement(15);
v6.addElement(15);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
res.addElement(v5);
res.addElement(v6);
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
assertEquals(result, instanceOfClass_m3);
}