From 0315a1f144137025fbf462ac7d45dcaf1e626197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 10 Mar 2018 01:04:19 +0100 Subject: [PATCH] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java compare(Matrix, Vector, ? extends Vector> <.? gen_ab funktioniert nicht --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 35 ++++++++++++------- .../typeinference/unify/TypeUnify.java | 9 ++--- .../typeinference/unify/TypeUnifyTask.java | 20 +++++------ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 88743c25..a04f3c4c 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -18,11 +18,13 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; +import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -94,21 +96,28 @@ public class JavaTXCompiler { TypeUnify unify = new TypeUnify(); Set> results = new HashSet<>(); - for (List> xCons : unifyCons.cartesianProduct()) { - Set xConsSet = new HashSet<>(); - for (Constraint constraint : xCons) { - xConsSet.addAll(constraint); - } + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); + for (List> xCons : unifyCons.cartesianProduct()) { + Set xConsSet = new HashSet<>(); + for (Constraint constraint : xCons) { + xConsSet.addAll(constraint); + } - System.out.println(xConsSet); - Set> result = unify.unifySequential(xConsSet, finiteClosure); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - results.addAll(result); + System.out.println(xConsSet); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); + //Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); + } + } + catch (IOException e) { } + + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); - } private Map generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index f457fbb8..69ed93b2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify; +import java.io.FileWriter; import java.util.Set; import java.util.concurrent.ForkJoinPool; @@ -7,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true); + public Set> unify(Set eq, IFiniteClosure fc, FileWriter logFile) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } - public Set> unifySequential(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false); + public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile); Set> res = unifyTask.compute(); return res; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4f422d12..713ee9aa 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -75,18 +75,13 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(); } - public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel) { + public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile) { this.eq = eq; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; - try { - logFile = new FileWriter(new File(rootDirectory+"log")); - logFile.write("xxx"); - logFile.flush(); - rules = new RuleSet(logFile); - } - catch (IOException e) { } + this.logFile = logFile; + rules = new RuleSet(logFile); } @Override @@ -105,6 +100,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 1: Repeated application of reduce, adapt, erase, swap */ writeLog("Unifikation: " + eq.toString()); + eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -245,13 +241,13 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); else if(eqPrimePrime.isPresent()) { //System.out.println("nextStep: " + eqPrimePrime.get()); - TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true); + TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile); forks.add(fork); fork.fork(); } else { //System.out.println("nextStep: " + eqPrime); - TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true); + TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile); forks.add(fork); fork.fork(); } @@ -314,6 +310,8 @@ public class TypeUnifyTask extends RecursiveTask>> { int i = 0; byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); Set a_next = null; + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("A")) + System.out.print(""); if (nextSetasList.size()>1) { if (variance == 1) { a_next = oup.max(nextSetasList.iterator()); @@ -373,6 +371,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + if (a.iterator().next().getLhsType().getName().equals("A")) + System.out.print(""); if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { System.out.print(""); break;