Compare commits
9 Commits
targetByte
...
unifyOptim
Author | SHA1 | Date | |
---|---|---|---|
|
2c9f085cca | ||
|
3e4e66d60d | ||
|
883ab50f94 | ||
|
9d37e8f637 | ||
|
496842a3bf | ||
|
608d73452a | ||
|
421169a72d | ||
|
c43d9ab9f5 | ||
|
5a0e53485c |
@ -24,6 +24,7 @@ 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.RuleSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
@ -38,7 +39,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
final boolean parallel = true;
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||||
@ -117,6 +118,7 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||||
@ -175,15 +177,39 @@ public class JavaTXCompiler {
|
|||||||
return y; } )
|
return y; } )
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
varianceInheritance(xConsSet);
|
varianceInheritance(xConsSet);
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
if (parallel) {
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
System.out.println("RESULT: " + result);
|
Set<UnifyPair> eq = new HashSet<>(xConsSet);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log);
|
||||||
logFile.flush();
|
forks.add(fork);
|
||||||
results.addAll(result);
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
catch (IOException e) { }
|
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
|
System.out.println("RESULT: " + result);
|
||||||
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
results.addAll(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (TypeUnifyTask fork : forks) {
|
||||||
|
try {
|
||||||
|
Set<Set<UnifyPair>> result = fork.join();
|
||||||
|
System.out.println("RESULT: " + result);
|
||||||
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
results.addAll(result);
|
||||||
|
}
|
||||||
|
catch (ConcurrentModificationException v) {
|
||||||
|
v.printStackTrace();
|
||||||
|
while (v.getCause() instanceof ConcurrentModificationException) {
|
||||||
|
v = (ConcurrentModificationException)v.getCause();
|
||||||
|
}
|
||||||
|
System.out.println(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) { }
|
||||||
|
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
|
@ -198,7 +198,9 @@ public class UnifyTypeFactory {
|
|||||||
}else if(tr instanceof WildcardType){
|
}else if(tr instanceof WildcardType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}else throw new NotImplementedException();
|
}else {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||||
|
@ -202,7 +202,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
||||||
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
||||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
//The type of the postfix increment expression is the type of the variable
|
//The type of the postfix increment expression is the type of the variable
|
||||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
||||||
}else{
|
}else{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
@ -11,7 +12,12 @@ public class TypeUnify {
|
|||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
|
try {
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
|
}
|
||||||
|
catch (ConcurrentModificationException v) {
|
||||||
|
v.printStackTrace();
|
||||||
|
}
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
32
src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
Normal file
32
src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
public class TypeUnify2Task extends TypeUnifyTask {
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) {
|
||||||
|
super(eq, fc, parallel, logFile, log);
|
||||||
|
this.setToFlatten = setToFlatten;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
|
if (one) {
|
||||||
|
System.out.println("two");
|
||||||
|
}
|
||||||
|
one = true;
|
||||||
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel);
|
||||||
|
/*if (isUndefinedPairSetSet(res)) {
|
||||||
|
return new HashSet<>(); }
|
||||||
|
else
|
||||||
|
*/
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||||
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.typeinference.unify.model.WildcardType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -49,10 +50,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
private static int i = 0;
|
private static int i = 0;
|
||||||
private boolean printtag = false;
|
private boolean printtag = false;
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
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/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
FileWriter logFile;
|
FileWriter logFile;
|
||||||
|
|
||||||
|
protected boolean one = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The implementation of setOps that will be used during the unification
|
* The implementation of setOps that will be used during the unification
|
||||||
*/
|
*/
|
||||||
@ -96,6 +101,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
|
noOfThread++;
|
||||||
|
thNo = noOfThread;
|
||||||
|
//System.out.println(noOfThread);
|
||||||
|
//System.out.println(eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -133,6 +142,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
|
if (one) {
|
||||||
|
System.out.println("two");
|
||||||
|
}
|
||||||
|
one = true;
|
||||||
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
||||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||||
else return res;
|
else return res;
|
||||||
@ -144,7 +157,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @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(final 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));
|
||||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||||
@ -311,10 +324,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
//System.out.println("vor Subst: " + eqPrime);
|
//System.out.println("vor Subst: " + eqPrime);
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||||
|
Set<Set<UnifyPair>> unifyres1 = null;
|
||||||
|
Set<Set<UnifyPair>> unifyres2 = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
if(parallel) {
|
if(parallel) {
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||||
@ -334,7 +350,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // sequentiell (Step 6b is included)
|
else */
|
||||||
|
{ // sequentiell (Step 6b is included)
|
||||||
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||||
@ -350,12 +367,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, false);
|
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel);
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, false);
|
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, fc, parallel);
|
||||||
|
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
@ -368,17 +385,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/*
|
/*
|
||||||
* Step 6 b) Build the union over everything.
|
* Step 6 b) Build the union over everything.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
if(parallel)
|
if(parallel)
|
||||||
for(TypeUnifyTask fork : forks)
|
for(TypeUnifyTask fork : forks)
|
||||||
eqPrimePrimeSet.addAll(fork.join());
|
eqPrimePrimeSet.addAll(fork.join());
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 7: Filter empty sets;
|
* Step 7: Filter empty sets;
|
||||||
*/
|
*/
|
||||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
||||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
|
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
|
||||||
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
||||||
|
Iterator<UnifyPair> upit = eqPrimePrimeSet.iterator().next().iterator();
|
||||||
|
if (upit.next().getLhsType() instanceof WildcardType
|
||||||
|
|| upit.next().getLhsType() instanceof WildcardType) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
}
|
||||||
return eqPrimePrimeSet;
|
return eqPrimePrimeSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,9 +475,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
|
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
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) {
|
else if (variance == -1) {
|
||||||
a = oup.min(nextSetasList.iterator());
|
a = oup.min(nextSetasList.iterator());
|
||||||
@ -491,16 +525,62 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
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());
|
//writeLog("Vor unify2 Aufruf: " + eq.toString());
|
||||||
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
|
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||||
|
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
||||||
|
if(parallel && (variance == 1)) {
|
||||||
|
/*
|
||||||
|
elems.add(a);
|
||||||
|
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
||||||
|
fork.fork();
|
||||||
|
res = fork.join();
|
||||||
|
*/
|
||||||
|
|
||||||
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
|
|
||||||
|
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
||||||
|
|
||||||
|
|
||||||
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
|
newElemsOrig.add(a);
|
||||||
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, fc, parallel, logFile, log);
|
||||||
|
forks.add(forkOrig);
|
||||||
|
forkOrig.fork();
|
||||||
|
|
||||||
|
while (!nextSetasListRest.isEmpty()) {
|
||||||
|
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
|
||||||
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
|
newElems.add(nSaL);
|
||||||
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log);
|
||||||
|
forks.add(fork);
|
||||||
|
fork.fork();
|
||||||
|
}
|
||||||
|
//res = unify2(elems, eq, fc, parallel);
|
||||||
|
res = forkOrig.join();
|
||||||
|
for(TypeUnifyTask fork : forks) {
|
||||||
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
|
add_res.add(fork_res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
elems.add(a);
|
||||||
|
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
|
||||||
result = res;
|
result = res;
|
||||||
|
if (res.iterator().next() instanceof WildcardType) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||||
|| result.isEmpty()) {
|
|| result.isEmpty()) {
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
|
writeLog("RESADD:" + result.toString() + " " + res.toString());
|
||||||
result.addAll(res);
|
result.addAll(res);
|
||||||
}
|
}
|
||||||
//else {
|
//else {
|
||||||
@ -522,6 +602,30 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
|
if (parallel) {
|
||||||
|
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||||
|
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||||
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
|
result = par_res;
|
||||||
|
if (par_res.iterator().next() instanceof WildcardType) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
||||||
|
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||||
|
|| result.isEmpty()) {
|
||||||
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
|
writeLog("RESADD:" + result.toString() + " " + par_res.toString());
|
||||||
|
result.addAll(par_res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* nextSetasList = nextSetasListRest; */
|
||||||
|
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
||||||
|
*/
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
while (nextSetasListIt.hasNext()) {
|
while (nextSetasListIt.hasNext()) {
|
||||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||||
@ -530,6 +634,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasList.remove(a_next);
|
nextSetasList.remove(a_next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else { if (variance == -1) {
|
else { if (variance == -1) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
@ -1129,8 +1235,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
allGen = false;
|
allGen = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded());
|
||||||
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
Match match = new Match();
|
Match match = new Match();
|
||||||
|
|
||||||
@ -1138,7 +1244,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
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());
|
||||||
Set<UnifyType> fBounded = pair.getfBounded();
|
//Set<UnifyType> fBounded = pair.getfBounded();
|
||||||
|
|
||||||
int i_ef = i;
|
int i_ef = i;
|
||||||
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
||||||
@ -1242,6 +1348,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
if (log) {
|
if (log) {
|
||||||
try {
|
try {
|
||||||
|
logFile.write("Thread no.:" + thNo + "\n");
|
||||||
logFile.write(str+"\n");
|
logFile.write(str+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
|
44
test/bytecode/FacultyTest.java
Normal file
44
test/bytecode/FacultyTest.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class FacultyTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Faculty.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("Fac");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||||
|
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||||
|
assertEquals(result, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -36,55 +36,57 @@ public class MatrixTest {
|
|||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Matrix");
|
classToTest = loader.loadClass("Matrix");
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix();
|
||||||
Vector<Integer> v1 = new Vector<Integer> ();
|
//Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
v1.addElement(2);
|
Vector<Integer> v1 = new Vector<Integer> ();
|
||||||
v1.addElement(2);
|
v1.addElement(2);
|
||||||
Vector<Integer> v2 = new Vector<Integer> ();
|
v1.addElement(2);
|
||||||
v2.addElement(3);
|
Vector<Integer> v2 = new Vector<Integer> ();
|
||||||
v2.addElement(3);
|
v2.addElement(3);
|
||||||
//Matrix m1 = new Matrix();
|
v2.addElement(3);
|
||||||
//m1.addElement(v1);
|
//Method[] ms = classToTest.getSuperclass().getDeclaredMethods();
|
||||||
//m1.addElement(v2);
|
Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class);
|
||||||
vv.addElement(v1);
|
addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1);
|
||||||
vv.addElement(v2);
|
addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2);
|
||||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
//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<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
Vector<Integer> v3 = new Vector<Integer> ();
|
Vector<Integer> v3 = new Vector<Integer> ();
|
||||||
v3.addElement(2);
|
v3.addElement(2);
|
||||||
v3.addElement(2);
|
v3.addElement(2);
|
||||||
Vector<Integer> v4 = new Vector<Integer> ();
|
Vector<Integer> v4 = new Vector<Integer> ();
|
||||||
v4.addElement(3);
|
v4.addElement(3);
|
||||||
v4.addElement(3);
|
v4.addElement(3);
|
||||||
//Matrix m2 = new Matrix();
|
//Matrix m2 = new Matrix();
|
||||||
//m2.addElement(v3);
|
//m2.addElement(v3);
|
||||||
//m2.addElement(v4);
|
//m2.addElement(v4);
|
||||||
vv1.addElement(v3);
|
vv1.addElement(v3);
|
||||||
vv1.addElement(v4);
|
vv1.addElement(v4);
|
||||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Matrix m3 = m1.mul(vv1);
|
//Matrix m3 = m1.mul(vv1);
|
||||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
||||||
|
|
||||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||||
Vector<Integer> v5 = new Vector<Integer> ();
|
Vector<Integer> v5 = new Vector<Integer> ();
|
||||||
v5.addElement(10);
|
v5.addElement(10);
|
||||||
v5.addElement(10);
|
v5.addElement(10);
|
||||||
Vector<Integer> v6 = new Vector<Integer> ();
|
Vector<Integer> v6 = new Vector<Integer> ();
|
||||||
v6.addElement(15);
|
v6.addElement(15);
|
||||||
v6.addElement(15);
|
v6.addElement(15);
|
||||||
//Matrix m2 = new Matrix();
|
//Matrix m2 = new Matrix();
|
||||||
//m2.addElement(v3);
|
//m2.addElement(v3);
|
||||||
//m2.addElement(v4);
|
//m2.addElement(v4);
|
||||||
res.addElement(v5);
|
res.addElement(v5);
|
||||||
res.addElement(v6);
|
res.addElement(v6);
|
||||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||||
assertEquals(result, instanceOfClass_m3);
|
assertEquals(result, instanceOfClass_m3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ public class applyLambda {
|
|||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
return lam1.apply(new Apply());
|
//return lam1.apply(new Apply());
|
||||||
//return lam1;
|
return lam1;
|
||||||
//return new Vector();
|
//return new Vector();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user