forked from JavaTX/JavaCompilerCore
Compare commits
11 Commits
performanc
...
28969e7931
Author | SHA1 | Date | |
---|---|---|---|
|
28969e7931 | ||
|
b806fa88ff | ||
|
301e9143ec | ||
|
bb4eaaccc5 | ||
|
4dbae46765 | ||
|
c64071f235 | ||
|
94dbf1f7ad | ||
|
890f64c813 | ||
|
5aadb7545e | ||
|
0c0ac61a02 | ||
|
46192e3fd3 |
@@ -56,7 +56,6 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import org.apache.commons.io.output.NullWriter;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,9 +162,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
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, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(statistics==null){
|
|
||||||
statistics = new NullWriter();
|
|
||||||
}
|
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
this.oderConstraintsField = oderConstraints; /*.stream().map(x -> {
|
this.oderConstraintsField = oderConstraints; /*.stream().map(x -> {
|
||||||
@@ -2613,7 +2609,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
synchronized ( this ) {
|
|
||||||
if (log && finalresult) {
|
if (log && finalresult) {
|
||||||
try {
|
try {
|
||||||
logFile.write("Thread no.:" + thNo + "\n");
|
logFile.write("Thread no.:" + thNo + "\n");
|
||||||
@@ -2621,18 +2616,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
logFile.write("parallel:" + parallel + "\n");
|
logFile.write("parallel:" + parallel + "\n");
|
||||||
logFile.write(str+"\n\n");
|
logFile.write(str+"\n\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void writeStatistics(String str) {
|
void writeStatistics(String str) {
|
||||||
if (finalresult) {
|
if (finalresult) {
|
||||||
synchronized ( this ) {
|
|
||||||
try {
|
try {
|
||||||
statistics.write("Thread No. " + thNo + ": " + str + "\n");
|
statistics.write("Thread No. " + thNo + ": " + str + "\n");
|
||||||
statistics.flush();
|
statistics.flush();
|
||||||
@@ -2641,6 +2633,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("kein StatisticsFile");
|
System.err.println("kein StatisticsFile");
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
public class WriterActiveObject {
|
||||||
|
private Writer writer;
|
||||||
|
private ForkJoinPool pool = new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
|
|
||||||
|
public WriterActiveObject(Writer writer){
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(String message){
|
||||||
|
pool.execute(()->{
|
||||||
|
try {
|
||||||
|
writer.write(message);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,13 @@
|
|||||||
package typeinference;
|
package typeinference;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
@@ -34,68 +39,57 @@ public class UnifyTest {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
|
||||||
|
|
||||||
private UnifyPair genPairListOfInteger(String name){
|
|
||||||
|
|
||||||
UnifyType type1 = new PlaceholderType(name);
|
|
||||||
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer")));
|
|
||||||
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
|
||||||
|
|
||||||
return pair1;
|
|
||||||
}
|
|
||||||
private UnifyPair genPairListOfString(String name){
|
|
||||||
|
|
||||||
PlaceholderType type1 = new PlaceholderType(name);
|
|
||||||
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("String")));
|
|
||||||
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
|
||||||
|
|
||||||
return pair1;
|
|
||||||
}
|
|
||||||
@Test
|
@Test
|
||||||
public void unifyTest(){
|
public void unifyTest(){
|
||||||
UnifyType type1;
|
UnifyType type1 = new PlaceholderType("a");
|
||||||
UnifyType type2;
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("b")));
|
||||||
|
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
|
type1 = new ReferenceType("List", new TypeParams(new PlaceholderType("c")));
|
||||||
|
type2 = new PlaceholderType("a");
|
||||||
|
UnifyPair pair2 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
|
type1 = new ReferenceType("String");
|
||||||
|
type2 = new PlaceholderType("b");
|
||||||
|
UnifyPair pair3 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
|
type1 = new ReferenceType("Integer");
|
||||||
|
type2 = new PlaceholderType("c");
|
||||||
|
UnifyPair pair4 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
||||||
|
|
||||||
Set<UnifyPair> undConstraints = new HashSet<>();
|
Set<UnifyPair> undConstraints = new HashSet<>();
|
||||||
undConstraints.add(genPairListOfInteger("a"));
|
undConstraints.add(pair1);
|
||||||
undConstraints.add(genPairListOfString("a"));
|
undConstraints.add(pair2);
|
||||||
|
undConstraints.add(pair3);
|
||||||
undConstraints.add(genPairListOfInteger("b"));
|
undConstraints.add(pair4);
|
||||||
undConstraints.add(genPairListOfString("b"));
|
|
||||||
undConstraints.add(genPairListOfInteger("c"));
|
|
||||||
undConstraints.add(genPairListOfString("c"));
|
|
||||||
undConstraints.add(genPairListOfInteger("d"));
|
|
||||||
undConstraints.add(genPairListOfString("d"));
|
|
||||||
undConstraints.add(genPairListOfInteger("e"));
|
|
||||||
undConstraints.add(genPairListOfString("e"));
|
|
||||||
undConstraints.add(genPairListOfInteger("e1"));
|
|
||||||
undConstraints.add(genPairListOfString("e1"));
|
|
||||||
undConstraints.add(genPairListOfInteger("e2"));
|
|
||||||
undConstraints.add(genPairListOfString("e2"));
|
|
||||||
undConstraints.add(genPairListOfInteger("e3"));
|
|
||||||
undConstraints.add(genPairListOfString("e3"));
|
|
||||||
|
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
||||||
|
|
||||||
Set<UnifyPair> constraints = new HashSet<>();
|
Set<UnifyPair> constraints = new HashSet<>();
|
||||||
type1 = new ReferenceType("Object");
|
type1 = new ReferenceType("Object");
|
||||||
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
|
||||||
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
|
||||||
type1 = new ReferenceType("Object");
|
|
||||||
type2 = new ReferenceType("Integer");
|
|
||||||
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
|
||||||
type1 = new ReferenceType("Object");
|
|
||||||
type2 = new ReferenceType("String");
|
type2 = new ReferenceType("String");
|
||||||
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
|
type1 = new ReferenceType("Number");
|
||||||
|
type2 = new ReferenceType("Integer");
|
||||||
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
|
type1 = new ReferenceType("Object");
|
||||||
|
type2 = new ReferenceType("Number");
|
||||||
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
|
type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
||||||
|
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
||||||
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
|
type1 = new ReferenceType("Object");
|
||||||
|
type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
||||||
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
||||||
|
|
||||||
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
||||||
|
|
||||||
TypeUnify unifyAlgo = new TypeUnify();
|
TypeUnify unifyAlgo = new TypeUnify();
|
||||||
ConstraintSet<Pair> cons = new ConstraintSet<>();
|
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyTaskModel tasks = new UnifyTaskModel();
|
UnifyTaskModel tasks = new UnifyTaskModel();
|
||||||
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||||
System.out.println(solution.size());
|
System.out.println(solution.size());
|
||||||
System.out.println(solution);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user