Compare commits
10 Commits
performanc
...
8e2151bfc2
Author | SHA1 | Date | |
---|---|---|---|
|
8e2151bfc2 | ||
|
0bd6d824c3 | ||
|
7e5e63dc5f | ||
|
f75d646a73 | ||
|
ce2401f3eb | ||
|
996ef1a735 | ||
|
2bb2f1a898 | ||
|
cf8653567c | ||
|
dd62d8d6b9 | ||
|
dc803bd6b8 |
@@ -0,0 +1,11 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface IUnifyResultListener {
|
||||
|
||||
void onNewTypeResultFound(Set<Set<UnifyPair>> evt);
|
||||
|
||||
}
|
@@ -3,16 +3,12 @@ package de.dhbwstuttgart.typeinference.unify;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
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.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class TypeUnify {
|
||||
@@ -28,9 +24,10 @@ public class TypeUnify {
|
||||
* @param cons
|
||||
* @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 ret, UnifyTaskModel usedTasks) {
|
||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||
ret.setPool(pool);
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
pool.invoke(unifyTask);
|
||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||
try {
|
||||
@@ -54,9 +51,10 @@ public class TypeUnify {
|
||||
* @param ret
|
||||
* @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 ret, UnifyTaskModel usedTasks) {
|
||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||
ret.setPool(pool);
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
pool.invoke(unifyTask);
|
||||
return ret;
|
||||
}
|
||||
@@ -72,10 +70,11 @@ public class TypeUnify {
|
||||
* @param ret
|
||||
* @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 ret, UnifyTaskModel usedTasks) {
|
||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||
ret.setPool(pool);
|
||||
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, statistics);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
pool.invoke(unifyTask);
|
||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||
try {
|
||||
@@ -108,7 +107,7 @@ public class TypeUnify {
|
||||
* @param cons
|
||||
* @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 ret, UnifyTaskModel usedTasks) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
||||
unifyTask.statistics = statistics;
|
||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||
|
@@ -23,13 +23,13 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
||||
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||
Set<UnifyPair> nextSetElement,
|
||||
IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
|
||||
IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, UnifyTaskModel usedTasks,
|
||||
Set<UnifyPair> methodSignatureConstraintUebergabe, Writer statistics) {
|
||||
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe );
|
||||
|
||||
}
|
||||
|
||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
|
||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
|
||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
this.setToFlatten = setToFlatten;
|
||||
this.nextSetElement = nextSetElement;
|
||||
|
@@ -73,12 +73,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Fuer die Threads
|
||||
*/
|
||||
UnifyResultModel urm;
|
||||
protected static int noOfThread = 0;
|
||||
UnifyResultModelParallel urm;
|
||||
private static int totalnoOfThread = 0;
|
||||
int thNo;
|
||||
protected boolean one = false;
|
||||
Integer MaxNoOfThreads = 128;
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||
Writer logFile;
|
||||
@@ -152,11 +150,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
|
||||
//statistics
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Writer statistics) {
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, UnifyTaskModel usedTasks, Writer statistics) {
|
||||
this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
this.statistics = statistics;
|
||||
}
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, UnifyTaskModel usedTasks) {
|
||||
synchronized (this) {
|
||||
if(statistics==null){
|
||||
statistics = new NullWriter();
|
||||
@@ -179,8 +177,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
this.parallel = parallel;
|
||||
this.logFile = logFile;
|
||||
this.log = log;
|
||||
|
||||
noOfThread++;
|
||||
|
||||
totalnoOfThread++;
|
||||
//writeLog("thNo1 " + thNo);
|
||||
thNo = totalnoOfThread;
|
||||
@@ -269,7 +266,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
.filter(x -> x.size()>1)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>());
|
||||
noOfThread--;
|
||||
try {
|
||||
logFile.close();
|
||||
}
|
||||
@@ -2262,7 +2258,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
if (log && finalresult) {
|
||||
try {
|
||||
logFile.write("Thread no.:" + thNo + "\n");
|
||||
logFile.write("noOfThread:" + noOfThread + "\n");
|
||||
logFile.write("parallel:" + parallel + "\n");
|
||||
logFile.write(str+"\n\n");
|
||||
logFile.flush();
|
||||
|
@@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
public interface UnifyResultListener {
|
||||
|
||||
void onNewTypeResultFound(UnifyResultEvent evt);
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class UnifyResultListenerImpl implements UnifyResultListener {
|
||||
|
||||
List<ResultSet> results = new ArrayList<>();
|
||||
|
||||
public synchronized void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||
results.addAll(evt.getNewTypeResult());
|
||||
}
|
||||
|
||||
public List<ResultSet> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class UnifyResultModel {
|
||||
|
||||
ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons;
|
||||
|
||||
IFiniteClosure fc;
|
||||
|
||||
public UnifyResultModel(ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons,
|
||||
IFiniteClosure fc) {
|
||||
this.cons = cons;
|
||||
this.fc = fc;
|
||||
}
|
||||
|
||||
private List<UnifyResultListener> listeners = new ArrayList<>();
|
||||
|
||||
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
||||
listeners.add(listenerToAdd);
|
||||
}
|
||||
|
||||
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
||||
listeners.remove(listenerToRemove);
|
||||
}
|
||||
|
||||
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet) {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
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<IUnifyResultListener> 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(IUnifyResultListener listenerToAdd) {
|
||||
listeners.add(listenerToAdd);
|
||||
}
|
||||
public void removeUnifyResultListener(IUnifyResultListener 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));
|
||||
|
||||
for (IUnifyResultListener listener : listeners) {
|
||||
listener.onNewTypeResultFound(eqPrimePrimeSetRet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,13 +1,10 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
@@ -23,7 +20,7 @@ public final class PlaceholderType extends UnifyType{
|
||||
* Static list containing the names of all existing placeholders.
|
||||
* Used for generating fresh placeholders.
|
||||
*/
|
||||
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
||||
public static final Set<String> EXISTING_PLACEHOLDERS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
/**
|
||||
* Prefix of auto-generated placeholder names.
|
||||
@@ -96,7 +93,7 @@ public final class PlaceholderType extends UnifyType{
|
||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||
* @return A fresh placeholder type.
|
||||
*/
|
||||
public synchronized static PlaceholderType freshPlaceholder() {
|
||||
public static PlaceholderType freshPlaceholder() {
|
||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||
// Add random chars while the name is in use.
|
||||
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
||||
|
@@ -2,7 +2,7 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
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.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
@@ -76,10 +76,606 @@ public class UnifyTest {
|
||||
|
||||
TypeUnify unifyAlgo = new TypeUnify();
|
||||
ConstraintSet<Pair> cons = new ConstraintSet<>();
|
||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||
System.out.println(solution.size());
|
||||
//System.out.println(solution);
|
||||
}}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicMatrixTest(){
|
||||
UnifyType type1;
|
||||
UnifyType type2;
|
||||
Set<UnifyPair> undConstraints = new HashSet<>();
|
||||
|
||||
//und-constraints
|
||||
//Matrix <. ret
|
||||
type1 = new ReferenceType("Matrix");
|
||||
type2 = new PlaceholderType("ret");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//Integer <. i
|
||||
type1 = new ReferenceType("Integer");
|
||||
type2 = new PlaceholderType("i");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//Matrix <. Vector<x?>
|
||||
type1 = new ReferenceType("Matrix");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//x? <. v1
|
||||
type1 = new PlaceholderType("x");
|
||||
type2 = new PlaceholderType("v1");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//i <. Integer
|
||||
type1 = new PlaceholderType("i");
|
||||
type2 = new ReferenceType("Integer");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//Vector<Integer> <. v2
|
||||
type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("Integer")));
|
||||
type2 = new PlaceholderType("v2");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//v1 <. Vector<y?>
|
||||
type1 = new PlaceholderType("v1");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("y")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//m <. Vector<z?>
|
||||
type1 = new PlaceholderType("m");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("z")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//z? <. zr
|
||||
type1 = new PlaceholderType("z");
|
||||
type2 = new PlaceholderType("zr");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//zr <. Vector<z2?>
|
||||
type1 = new PlaceholderType("zr");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("z2")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//z2? <. z2r
|
||||
type1 = new PlaceholderType("z2");
|
||||
type2 = new PlaceholderType("z2r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//z2r <. Integer
|
||||
type1 = new PlaceholderType("z2r");
|
||||
type2 = new ReferenceType("Integer");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//v1 <. Vector<y2?>
|
||||
type1 = new PlaceholderType("v1");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("y2")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//y2? <. y2r
|
||||
type1 = new PlaceholderType("y2");
|
||||
type2 = new PlaceholderType("y2r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//y2r <. Integer
|
||||
type1 = new PlaceholderType("y2r");
|
||||
type2 = new ReferenceType("Integer");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//v2 <. Vector<x3?>
|
||||
type1 = new PlaceholderType("v2");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x3")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//x3? <. x3r
|
||||
type1 = new PlaceholderType("x3");
|
||||
type2 = new PlaceholderType("x3r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//Integer <. x3r
|
||||
type1 = new ReferenceType("Integer");
|
||||
type2 = new PlaceholderType("x3r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//ret <. Vector<x2?>
|
||||
type1 = new PlaceholderType("ret");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x2")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//x2? <. x2r
|
||||
type1 = new PlaceholderType("x2");
|
||||
type2 = new PlaceholderType("x2r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//v2 <. x2r
|
||||
type1 = new PlaceholderType("v2");
|
||||
type2 = new PlaceholderType("x2r");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
|
||||
//oder-constraints
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
||||
|
||||
//FiniteClosure
|
||||
Set<UnifyPair> constraints = new HashSet<>();
|
||||
//Matrix extends Vector<Vector<Integer>>
|
||||
type1 = new ReferenceType("Matrix");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new ReferenceType("Vector", new TypeParams(new ReferenceType("Integer")))));
|
||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Vector<X> extends Object
|
||||
type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("X")));
|
||||
type2 = new ReferenceType("Object");
|
||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Integer extends Object
|
||||
type1 = new ReferenceType("Integer");
|
||||
type2 = new ReferenceType("Object");
|
||||
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
FiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
||||
|
||||
TypeUnify unifyAlgo = new TypeUnify();
|
||||
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
||||
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||
System.out.println(solution.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalark2(){
|
||||
UnifyType type1;
|
||||
UnifyType type2;
|
||||
|
||||
//und-constraints
|
||||
Set<UnifyPair> undConstraints = new HashSet<>();
|
||||
//H =. Scalar
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new ReferenceType("Scalar");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <!=. java.lang.Number
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Number");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERNEQDOT));
|
||||
//C =. A
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new PlaceholderType("A");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//L =. Scalar
|
||||
type1 = new PlaceholderType("L");
|
||||
type2 = new ReferenceType("Scalar");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//D <. C
|
||||
type1 = new PlaceholderType("D");
|
||||
type2 = new PlaceholderType("C");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//java.lang.Boolean =. G
|
||||
type1 = new ReferenceType("java.lang.Boolean");
|
||||
type2 = new PlaceholderType("G");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//G =. java.lang.Boolean
|
||||
type1 = new PlaceholderType("G");
|
||||
type2 = new ReferenceType("java.lang.Boolean");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//V <. C
|
||||
type1 = new PlaceholderType("V");
|
||||
type2 = new PlaceholderType("C");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//F <. E
|
||||
type1 = new PlaceholderType("F");
|
||||
type2 = new PlaceholderType("E");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//X <. E
|
||||
type1 = new PlaceholderType("X");
|
||||
type2 = new PlaceholderType("E");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//J <!=. java.lang.Number
|
||||
type1 = new PlaceholderType("J");
|
||||
type2 = new ReferenceType("java.lang.Number");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERNEQDOT));
|
||||
|
||||
//oder-constraints
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
||||
Set<Constraint<UnifyPair>> constraints = new HashSet<>();
|
||||
Constraint<UnifyPair> constraint = new Constraint<>();
|
||||
|
||||
//set #1
|
||||
//D =. java.lang.Float
|
||||
type1 = new PlaceholderType("D");
|
||||
type2 = new ReferenceType("java.lang.Boolean");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//D =. java.lang.Integer
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("D");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #2
|
||||
constraints = new HashSet<>();
|
||||
//F =. java.lang.Integer
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("F");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//F =. java.lang.Float
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("F");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #3
|
||||
constraints = new HashSet<>();
|
||||
//H =. ? extends Scalar
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new ExtendsType(new ReferenceType("Scalar"));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//java.lang.Integer =. J
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("J");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//H =. Vector<AJP>
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJP")));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//java.lang.Integer =. J
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("J");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//H =. ? extends Vector<AJP>
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new ExtendsType(new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJP"))));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//java.lang.Integer =. J
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("J");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//H =. Scalar
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("H");
|
||||
type2 = new ReferenceType("Scalar");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//java.lang.Integer =. J
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("J");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #4
|
||||
constraints = new HashSet<>();
|
||||
//java.lang.Integer =. O
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("O");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//L =. Scalar
|
||||
type1 = new PlaceholderType("L");
|
||||
type2 = new ReferenceType("Scalar");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
//E <. java.lang.Integer
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//L =. ? extends Vector<AJQ>
|
||||
type1 = new PlaceholderType("L");
|
||||
type2 = new ExtendsType(new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJQ"))));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//AJQ =. O
|
||||
type1 = new PlaceholderType("AJQ");
|
||||
type2 = new PlaceholderType("O");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//java.lang.Integer =. O
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("O");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//L =. ? extends Scalar
|
||||
type1 = new PlaceholderType("L");
|
||||
type2 = new ExtendsType(new ReferenceType("Scalar"));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//L =. Vector<AJQ>
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("L");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJQ")));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//AJQ =. O
|
||||
type1 = new PlaceholderType("AJQ");
|
||||
type2 = new PlaceholderType("O");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #5
|
||||
constraints = new HashSet<>();
|
||||
//AJR =. S
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("AJR");
|
||||
type2 = new PlaceholderType("S");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//B =. Vector<AJR>
|
||||
type1 = new PlaceholderType("B");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJR")));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//java.lang.Integer =. S
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("S");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//B =. Scalar
|
||||
type1 = new PlaceholderType("B");
|
||||
type2 = new ReferenceType("Scalar");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//java.lang.Integer =. S
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("S");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//B =. ? extends Scalar
|
||||
type1 = new PlaceholderType("B");
|
||||
type2 = new ExtendsType(new ReferenceType("Scalar"));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
//AJR =. S
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("AJR");
|
||||
type2 = new PlaceholderType("S");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//B =. ? extends Vector<AJR>
|
||||
type1 = new PlaceholderType("B");
|
||||
type2 = new ExtendsType(new ReferenceType("Vector", new TypeParams(new PlaceholderType("AJR"))));
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #6
|
||||
constraints = new HashSet<>();
|
||||
//O <. java.lang.Float
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("O");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//java.lang.Float =. U
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new PlaceholderType("U");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//S <. java.lang.Float
|
||||
type1 = new PlaceholderType("S");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
//java.lang.Integer =. U
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("U");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//S <. java.lang.Integer
|
||||
type1 = new PlaceholderType("S");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//O <. java.lang.Integer
|
||||
type1 = new PlaceholderType("O");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #7
|
||||
constraints = new HashSet<>();
|
||||
//java.lang.Integer =. V
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("V");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//U <. java.lang.Integer
|
||||
type1 = new PlaceholderType("U");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//C <. java.lang.Integer
|
||||
type1 = new PlaceholderType("C");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
//java.lang.Float =. V
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new PlaceholderType("V");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//U <. java.lang.Float
|
||||
type1 = new PlaceholderType("U");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//C <. java.lang.Float
|
||||
type1 = new PlaceholderType("C");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #8
|
||||
constraints = new HashSet<>();
|
||||
//W =. java.lang.Float
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("W");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
//W =. java.lang.Integer
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("W");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
//set #9
|
||||
constraints = new HashSet<>();
|
||||
//W <. java.lang.Integer
|
||||
constraint = new Constraint<>();
|
||||
type1 = new PlaceholderType("W");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//E <. java.lang.Integer
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Integer");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//java.lang.Integer =. X
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new PlaceholderType("X");
|
||||
constraints.add(constraint);
|
||||
//java.lang.Float =. X
|
||||
constraint = new Constraint<>();
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new PlaceholderType("X");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.EQUALSDOT));
|
||||
//E <. java.lang.Float
|
||||
type1 = new PlaceholderType("E");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//W <. java.lang.Float
|
||||
type1 = new PlaceholderType("W");
|
||||
type2 = new ReferenceType("java.lang.Float");
|
||||
constraint.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
constraints.add(constraint);
|
||||
oderConstraints.add(constraints);
|
||||
|
||||
|
||||
//FiniteClosure
|
||||
Set<UnifyPair> fcConstraints = new HashSet<>();
|
||||
//java.lang.Number < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.Number");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Number < java.io.Serializable
|
||||
type1 = new ReferenceType("java.lang.Number");
|
||||
type2 = new ReferenceType("java.io.Serializable");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.lang.Number
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new ReferenceType("java.lang.Number");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.lang.Number
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.Number");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.lang.constant.Constable
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.constant.Constable");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.io.Serializable
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.io.Serializable");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.lang.constant.ConstantDesc
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.constant.ConstantDesc");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Integer < java.lang.Comparable<java.lang.Integer>
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.Comparable", new TypeParams(new ReferenceType("java.lang.Integer")));
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.lang.constant.Constable
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new ReferenceType("java.lang.constant.Constable");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.io.Serializable
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new ReferenceType("java.io.Serializable");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.lang.Comparable<java.lang.Float>
|
||||
type1 = new ReferenceType("java.lang.Integer");
|
||||
type2 = new ReferenceType("java.lang.Comparable", new TypeParams(new ReferenceType("java.lang.Float")));
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Float < java.lang.constant.ConstantDesc
|
||||
type1 = new ReferenceType("java.lang.Float");
|
||||
type2 = new ReferenceType("java.lang.constant.ConstantDesc");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Scalar<EYW> < java.lang.Object
|
||||
type1 = new ReferenceType("Scalar", new TypeParams(new PlaceholderType("EYW")));
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Scalar<EYW> < Vector<java.lang.Integer>
|
||||
type1 = new ReferenceType("Scalar", new TypeParams(new PlaceholderType("EYW")));
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new ReferenceType("java.lang.Integer")));
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Comparable<java.lang.Float> < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.Comparable", new TypeParams(new ReferenceType("java.lang.Float")));
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Vector<java.lang.Integer> < java.lang.Object
|
||||
type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("java.lang.Integer")));
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Scalar < Vector<java.lang.Integer>
|
||||
type1 = new ReferenceType("Scalar");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new ReferenceType("java.lang.Integer")));
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.constant.ConstantDesc < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.constant.ConstantDesc");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Scalar < java.lang.Object
|
||||
type1 = new ReferenceType("Scalar");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.constant.Constable < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.constant.Constable");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//Vector<EWV> < java.lang.Object
|
||||
type1 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("EWV")));
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.io.Serializable < java.lang.Object
|
||||
type1 = new ReferenceType("java.io.Serializable");
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
//java.lang.Comparable<java.lang.Integer> < java.lang.Object
|
||||
type1 = new ReferenceType("java.lang.Comparable", new TypeParams(new ReferenceType("java.lang.Integer")));
|
||||
type2 = new ReferenceType("java.lang.Object");
|
||||
fcConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||
|
||||
FiniteClosure finiteClosure = new FiniteClosure(fcConstraints, new NullWriter());
|
||||
TypeUnify unifyAlgo = new TypeUnify();
|
||||
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
||||
UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||
System.out.println(solution);
|
||||
System.out.println(solution.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user