From 57fb90afafd80e99dd5792b039555f115c130d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 28 May 2018 16:35:47 +0200 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 LogFile optional gemacht --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 8 +++++++- .../typeinference/unify/TypeUnify.java | 8 ++++---- .../typeinference/unify/TypeUnifyTask.java | 20 +++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 05edbaa1..8646b484 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -41,11 +41,17 @@ public class JavaTXCompiler { final CompilationEnvironment environment; public final Map sourceFiles = new HashMap<>(); + Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile)); } + public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException { + this(sourceFile); + this.log = log; + } + public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { environment = new CompilationEnvironment(sources); for (File s : sources) { @@ -169,7 +175,7 @@ public class JavaTXCompiler { return y; } ) .collect(Collectors.toCollection(HashSet::new)); varianceInheritance(xConsSet); - Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); + 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"); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 69ed93b2..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, FileWriter logFile) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile); + 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, FileWriter logFile) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile); + 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 ef2ae74c..0545fb95 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -47,6 +47,7 @@ public class TypeUnifyTask extends RecursiveTask>> { private static final long serialVersionUID = 1L; private static int i = 0; 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/"; FileWriter logFile; @@ -86,12 +87,13 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(); } - public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile) { + 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; this.logFile = logFile; + this.log = log; rules = new RuleSet(logFile); } @@ -320,13 +322,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, logFile); + 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, logFile); + TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile, log); forks.add(fork); fork.fork(); } @@ -1212,11 +1214,13 @@ public class TypeUnifyTask extends RecursiveTask>> { } void writeLog(String str) { - try { - logFile.write(str+"\n"); - logFile.flush(); + if (log) { + try { + logFile.write(str+"\n"); + logFile.flush(); - } - catch (IOException e) { } + } + catch (IOException e) { } + } } }