forked from JavaTX/JavaCompilerCore
Compare commits
19 Commits
performanc
...
unif23NoOp
Author | SHA1 | Date | |
---|---|---|---|
|
588036ea46 | ||
|
70b28bbfb0 | ||
|
701962b0e7 | ||
|
e91a9370df | ||
|
d71e67cfdd | ||
|
c2c2d6f445 | ||
|
7296e3de44 | ||
|
c1aebaf1f5 | ||
|
2871586c71 | ||
|
fa1f3a0507 | ||
|
f66edd4c4b | ||
|
598fe8ebe9 | ||
|
41d97dfa80 | ||
|
0f18cedf90 | ||
f43d1f4f4f | |||
2a44773403 | |||
|
a6ca31d509 | ||
|
b13f2b357b | ||
|
45fa0ff0b9 |
@ -37,20 +37,13 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
import de.dhbwstuttgart.typeinference.unify.*;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.util.BiRelation;
|
import de.dhbwstuttgart.util.BiRelation;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -73,7 +66,7 @@ public class JavaTXCompiler {
|
|||||||
Boolean resultmodel = true;
|
Boolean resultmodel = true;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
public UnifyTaskModelParallel usedTasks = new UnifyTaskModelParallel();
|
||||||
private final DirectoryClassLoader classLoader;
|
private final DirectoryClassLoader classLoader;
|
||||||
static Writer statistics;
|
static Writer statistics;
|
||||||
|
|
||||||
@ -376,7 +369,7 @@ public class JavaTXCompiler {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
public UnifyResultModelParallel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
||||||
throws ClassNotFoundException, IOException {
|
throws ClassNotFoundException, IOException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
@ -389,7 +382,7 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
UnifyResultModel urm = null;
|
UnifyResultModelParallel urm = null;
|
||||||
// urm.addUnifyResultListener(resultListener);
|
// urm.addUnifyResultListener(resultListener);
|
||||||
try {
|
try {
|
||||||
logFile = logFile == null
|
logFile = logFile == null
|
||||||
@ -397,7 +390,7 @@ public class JavaTXCompiler {
|
|||||||
: logFile;
|
: logFile;
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||||
urm.addUnifyResultListener(resultListener);
|
urm.addUnifyResultListener(resultListener);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
@ -727,7 +720,7 @@ public class JavaTXCompiler {
|
|||||||
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||||
@ -745,7 +738,7 @@ public class JavaTXCompiler {
|
|||||||
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
||||||
// finiteClosure));
|
// finiteClosure));
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
|
||||||
finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
finiteClosure, logFile, log, new UnifyResultModelParallel(cons, finiteClosure), usedTasks);
|
||||||
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();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -20,21 +19,15 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) {
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool);
|
taskModel.setPool(pool);
|
||||||
|
resultModel.setPool(pool);
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, resultModel, pool);
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
try {
|
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("no log-File");
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,15 +38,15 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @param ret
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModelParallel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) {
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool);
|
taskModel.setPool(pool);
|
||||||
|
resultModel.setPool(pool);
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, resultModel, pool);
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
return ret;
|
return resultModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,27 +56,19 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @param ret
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModelParallel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) {
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
|
taskModel.setPool(pool);
|
||||||
|
resultModel.setPool(pool);
|
||||||
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool, statistics);
|
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, resultModel, pool, statistics);
|
||||||
|
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
unifyTask.join();
|
||||||
try {
|
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
return resultModel;
|
||||||
logFile.flush();
|
|
||||||
unifyTask.statisticsFile.write("Backtracking: " + unifyTask.noBacktracking);
|
|
||||||
unifyTask.statisticsFile.write("\nLoops: " + unifyTask.noLoop);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("no log-File");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -101,20 +86,13 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, usedTasks, ForkJoinPool.commonPool());
|
resultModel.setPool(ForkJoinPool.commonPool());
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, resultModel, ForkJoinPool.commonPool());
|
||||||
unifyTask.statisticsFile = statistics;
|
unifyTask.statisticsFile = statistics;
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("no log-File");
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
@ -24,14 +18,14 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
Set<UnifyPair> nextSetElement,
|
Set<UnifyPair> nextSetElement,
|
||||||
IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
|
IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, UnifyResultModelParallel urm,
|
||||||
Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool, Writer statistics) {
|
Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool, Writer statistics) {
|
||||||
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe, pool );
|
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, urm, methodSignatureConstraintUebergabe, pool );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, UnifyResultModelParallel urm, Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, pool);
|
super(eq, oderConstraints, fc, parallel, logFile, log, urm, pool);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe;
|
this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe;
|
||||||
@ -43,25 +37,14 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, methodSignatureConstraintUebergabe);
|
||||||
System.out.println("two");
|
|
||||||
}
|
|
||||||
one = true;
|
|
||||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe);
|
|
||||||
/*if (isUndefinedPairSetSet(res)) {
|
/*if (isUndefinedPairSetSet(res)) {
|
||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
//writeLog("xxx");
|
//writeLog("xxx");
|
||||||
//noOfThread--;
|
//noOfThread--;
|
||||||
synchronized (usedTasks) {
|
return res;
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeLogFile() {
|
public void closeLogFile() {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,57 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class UnifyResultModelParallel {
|
||||||
|
private ForkJoinPool pool;
|
||||||
|
private ConstraintSet<Pair> cons;
|
||||||
|
private IFiniteClosure fc;
|
||||||
|
private List<UnifyResultListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public UnifyResultModelParallel(ConstraintSet<Pair> cons, IFiniteClosure fc){
|
||||||
|
this.cons = cons;
|
||||||
|
this.fc = fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPool(ForkJoinPool pool){
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
||||||
|
listeners.add(listenerToAdd);
|
||||||
|
}
|
||||||
|
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
||||||
|
listeners.remove(listenerToRemove);
|
||||||
|
}
|
||||||
|
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet){
|
||||||
|
pool.execute(()->{
|
||||||
|
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||||
|
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||||
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||||
|
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc);
|
||||||
|
}
|
||||||
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
List<ResultSet> newResult = eqPrimePrimeSetRet.stream().map(unifyPairs ->
|
||||||
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
||||||
|
|
||||||
|
for (UnifyResultListener listener : listeners) {
|
||||||
|
listener.onNewTypeResultFound(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class UnifyTaskModel {
|
|
||||||
|
|
||||||
ArrayList<TypeUnifyTask> usedTasks = new ArrayList<>();
|
|
||||||
|
|
||||||
public synchronized void add(TypeUnifyTask t) {
|
|
||||||
usedTasks.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void cancel() {
|
|
||||||
for(TypeUnifyTask t : usedTasks) {
|
|
||||||
t.myCancel(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
public class UnifyTaskModelParallel {
|
||||||
|
private ForkJoinPool pool;
|
||||||
|
|
||||||
|
public void setPool(ForkJoinPool pool){
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel(){
|
||||||
|
if(this.pool != null) {
|
||||||
|
this.pool.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,8 @@
|
|||||||
package typeinference;
|
package typeinference;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
@ -17,8 +12,8 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultModelParallel;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModelParallel;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||||
import org.apache.commons.io.output.NullWriter;
|
import org.apache.commons.io.output.NullWriter;
|
||||||
@ -40,7 +35,7 @@ public class UnifyTest {
|
|||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unifyTest(){
|
public void smallUnifyTest(){
|
||||||
UnifyType type1 = new PlaceholderType("a");
|
UnifyType type1 = new PlaceholderType("a");
|
||||||
UnifyType type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("b")));
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("b")));
|
||||||
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
||||||
@ -68,61 +63,95 @@ public class UnifyTest {
|
|||||||
Set<UnifyPair> constraints = new HashSet<>();
|
Set<UnifyPair> constraints = new HashSet<>();
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("String");
|
type2 = new ReferenceType("String");
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
type1 = new ReferenceType("Number");
|
type1 = new ReferenceType("Number");
|
||||||
type2 = new ReferenceType("Integer");
|
type2 = new ReferenceType("Integer");
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("Number");
|
type2 = new ReferenceType("Number");
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
/* type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
/* type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
||||||
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));*/
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));*/
|
||||||
type1 = new ReferenceType("AbstractList");
|
type1 = new ReferenceType("AbstractList", new PlaceholderType("X"));
|
||||||
type2 = new ReferenceType("List");
|
type2 = new ReferenceType("List", new PlaceholderType("X"));
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("AbstractList");
|
type2 = new ReferenceType("AbstractList", new PlaceholderType("X"));
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
|
|
||||||
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
||||||
|
|
||||||
TypeUnify unifyAlgo = new TypeUnify();
|
TypeUnify unifyAlgo = new TypeUnify();
|
||||||
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
UnifyTaskModelParallel tasks = new UnifyTaskModelParallel();
|
||||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||||
System.out.println(solution.size());
|
System.out.println(solution.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private UnifyPair genPairListOfInteger(String name){
|
||||||
public void smallUnifyTest(){
|
|
||||||
UnifyType type1 = new PlaceholderType("a");
|
UnifyType type1 = new PlaceholderType(name);
|
||||||
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer")));
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer")));
|
||||||
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
|
return pair1;
|
||||||
|
}
|
||||||
|
private UnifyPair genPairListOfString(String name){
|
||||||
|
|
||||||
|
PlaceholderType type1 = new PlaceholderType(name);
|
||||||
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("String")));
|
||||||
|
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
|
return pair1;
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void unifyTest(){
|
||||||
|
UnifyType type1;
|
||||||
|
UnifyType type2;
|
||||||
|
|
||||||
Set<UnifyPair> undConstraints = new HashSet<>();
|
Set<UnifyPair> undConstraints = new HashSet<>();
|
||||||
undConstraints.add(pair1);
|
undConstraints.add(genPairListOfInteger("a"));
|
||||||
|
undConstraints.add(genPairListOfString("a"));
|
||||||
|
|
||||||
|
undConstraints.add(genPairListOfInteger("b"));
|
||||||
|
undConstraints.add(genPairListOfString("b"));
|
||||||
|
undConstraints.add(genPairListOfInteger("c"));
|
||||||
|
undConstraints.add(genPairListOfString("c"));
|
||||||
|
undConstraints.add(genPairListOfInteger("d"));
|
||||||
|
undConstraints.add(genPairListOfString("d"));
|
||||||
|
undConstraints.add(genPairListOfInteger("e"));
|
||||||
|
undConstraints.add(genPairListOfString("e"));
|
||||||
|
undConstraints.add(genPairListOfInteger("e1"));
|
||||||
|
undConstraints.add(genPairListOfString("e1"));
|
||||||
|
undConstraints.add(genPairListOfInteger("e2"));
|
||||||
|
undConstraints.add(genPairListOfString("e2"));
|
||||||
|
undConstraints.add(genPairListOfInteger("e3"));
|
||||||
|
undConstraints.add(genPairListOfString("e3"));
|
||||||
|
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
||||||
|
|
||||||
Set<UnifyPair> constraints = new HashSet<>();
|
Set<UnifyPair> constraints = new HashSet<>();
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("List");
|
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("Integer");
|
type2 = new ReferenceType("Integer");
|
||||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
|
type1 = new ReferenceType("Object");
|
||||||
|
type2 = new ReferenceType("String");
|
||||||
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
||||||
|
|
||||||
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
||||||
|
|
||||||
TypeUnify unifyAlgo = new TypeUnify();
|
TypeUnify unifyAlgo = new TypeUnify();
|
||||||
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
UnifyTaskModelParallel tasks = new UnifyTaskModelParallel();
|
||||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||||
System.out.println(solution.size());
|
System.out.println(solution.size());
|
||||||
System.out.println(solution);
|
System.out.println(solution);
|
||||||
|
Loading…
Reference in New Issue
Block a user