From 6d34ae89ae4edd195ab0ceb5440615b126647648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 7 Aug 2018 17:38:40 +0200 Subject: [PATCH] =?UTF-8?q?=09modified:=20=20=20src/de/dhbwstuttgart/core/?= =?UTF-8?q?JavaTXCompiler.java=20=09modified:=20=20=20src/de/dhbwstuttgart?= =?UTF-8?q?/typeinference/unify/RuleSet.java=20=09modified:=20=20=20src/de?= =?UTF-8?q?/dhbwstuttgart/typeinference/unify/TypeUnify.java=20=09modified?= =?UTF-8?q?:=20=20=20src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTas?= =?UTF-8?q?k.java=20logging=20f=C3=BCr=20TypeUnify=20aus=20commit=20d63640?= =?UTF-8?q?40=20wiederhergestellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 15 ++++++- .../typeinference/unify/RuleSet.java | 5 +++ .../typeinference/unify/TypeUnify.java | 8 ++-- .../typeinference/unify/TypeUnifyTask.java | 42 +++++++++++++++---- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 6c9763a2..ffa8d54d 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -110,6 +110,13 @@ public class JavaTXCompiler { TypeUnify unify = new TypeUnify(); Set> results = new HashSet<>(); + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } + logFile.flush(); Set>> cardProd = unifyCons.cartesianProduct(); for (List> xCons : cardProd ){ Set xConsSet = new HashSet<>(); @@ -168,11 +175,15 @@ public class JavaTXCompiler { return y; } ) .collect(Collectors.toCollection(HashSet::new)); varianceInheritance(xConsSet); - Set> result = unify.unifySequential(xConsSet, finiteClosure); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); //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()); diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index f54b1eb1..6c3cfaad 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -36,10 +36,15 @@ import java.io.IOException; */ public class RuleSet implements IRuleSet{ + FileWriter logFile; + RuleSet() { super(); } + RuleSet(FileWriter logFile) { + this.logFile = logFile; + } @Override public Optional reduceUp(UnifyPair pair) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 5f0126aa..fa190cb7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -8,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, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log); 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, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); 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 3ee49cdb..e38e1443 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -50,7 +50,8 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? - //public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; + public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; + FileWriter logFile; /** * The implementation of setOps that will be used during the unification @@ -87,12 +88,14 @@ 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, Boolean log) { this.eq = eq; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; - rules = new RuleSet(); + this.logFile = logFile; + this.log = log; + rules = new RuleSet(logFile); } @@ -152,6 +155,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 1: Repeated application of reduce, adapt, erase, swap */ nOfUnify++; + writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -227,6 +231,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { noUndefPair++; + for (UnifyPair up : undefinedPairs) { + writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); + writeLog("BasePair; " + up.getBasePair()); + } Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); @@ -315,13 +323,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, log); 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, log); forks.add(fork); fork.fork(); } @@ -332,7 +340,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. - + try { + if (isSolvedForm(eqPrime)) { + logFile.write(eqPrime.toString()+"\n"); + logFile.flush(); + } + } + catch (IOException e) { } eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { @@ -363,6 +377,8 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); + if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) + writeLog("Result1 " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; } @@ -382,6 +398,7 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } Set> nextSet = remainingSets.remove(0); + writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); try { //List> @@ -431,6 +448,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); + writeLog("nextSetasList: " + nextSetasList.toString()); while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a = null; if (variance == 1) { @@ -551,8 +569,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //} return (!x.containsAll(durchschnitt)); }).collect(Collectors.toCollection(ArrayList::new)); + writeLog("abhSubst: " + abhSubst.toString()); + writeLog("a: " + a.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); + writeLog("nextSet: " + nextSet.toString()); + writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); + writeLog("Number erased Elements (undef): " + noAllErasedElements.toString()); noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { @@ -1212,7 +1238,7 @@ public class TypeUnifyTask extends RecursiveTask>> { permuteParams(candidates, idx+1, result, current); } } -/* + void writeLog(String str) { if (log) { try { @@ -1223,6 +1249,4 @@ public class TypeUnifyTask extends RecursiveTask>> { catch (IOException e) { } } } - */ } -