From 588212389ac1bab505d0f500e839a23cb5528b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 12 Apr 2019 10:28:39 +0200 Subject: [PATCH] Die Bestimmung der Constraints aus dem ResolvedType herausgenommen und im ResultSet integriert. Damit kommen immer die gleichen Constraints raus. Diese werden ohnehin in der Bytecodegenerierung nochmals ausgewertet. modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java Zugriff auf Constraints ueber ResultSet eingefuehrt modified: ../../../../main/java/de/dhbwstuttgart/bytecode/signature/Signature.java Zugriff auf Constraints ueber ResultSet eingefuehrt modified: ../../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java toString veraendert modified: ../../../../main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java Attribut genIns eingefuehrt, indem alle GenericInsertPairs gespeichert werden, die Form (TPH a <. TPH b) im Attribut results haben modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../bytecode/javFiles/Id.jav modified: ../../bytecode/javFiles/MatrixOP.jav --- src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java | 3 ++- .../de/dhbwstuttgart/bytecode/signature/Signature.java | 6 ++++-- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 5 +++-- .../typeinference/result/GenericInsertPair.java | 5 +++++ .../result/PairTPHequalRefTypeOrWildcardType.java | 5 +++++ .../typeinference/result/PairTPHsmallerTPH.java | 5 +++++ .../de/dhbwstuttgart/typeinference/result/ResultSet.java | 5 +++++ .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 7 ++++++- src/test/resources/bytecode/javFiles/Id.jav | 2 +- src/test/resources/bytecode/javFiles/MatrixOP.jav | 4 ++-- 10 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 36753138..e9f8e257 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -90,7 +90,8 @@ public class TPHExtractor extends AbstractASTWalker { // } // } - resultSet.resolveType(tph).additionalGenerics.forEach(ag -> { + //resultSet.resolveType(tph).getAdditionalGenerics().forEach(ag -> { + resultSet.genIns.forEach(ag -> { // if (ag.contains(resolvedTPH) /* && ag.TA1.equals(resolvedTPH) */ && !contains(allPairs, ag)) { if (inMethod) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java index c3891a61..94052f9c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -235,7 +235,8 @@ public class Signature { RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType; if(resolved instanceof TypePlaceholder) { - resType.additionalGenerics.forEach(ag ->{ + //resType.getAdditionalGenerics().forEach(ag ->{ + resultSet.genIns.forEach(ag ->{ TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); if(!contains(res,constr)) { res.add(constr); @@ -246,7 +247,8 @@ public class Signature { WildcardType resWC = (WildcardType) resolved; ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType()); if(resType2.resolvedType instanceof TypePlaceholder) { - resType2.additionalGenerics.forEach(ag ->{ + //resType2.getAdditionalGenerics().forEach(ag ->{ + resultSet.genIns.forEach(ag ->{ TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); if(!contains(res,constr)) { res.add(constr); diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index c8c9802b..0d13045f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -51,6 +51,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; +import org.apache.commons.io.output.NullOutputStream; //import org.apache.commons.io.output.NullOutputStream; public class JavaTXCompiler { @@ -563,8 +564,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java b/src/main/java/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java index 824d2083..f864905d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java @@ -23,4 +23,9 @@ public class GenericInsertPair { if(TA2.equals(additionalTPH))return true; return false; } + + @Override + public String toString() { + return "GenIns(" + TA1.toString() + " < " + TA2.toString() + ")"; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java index 0bc1aee0..0c0a5872 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java @@ -21,4 +21,9 @@ public class PairTPHequalRefTypeOrWildcardType extends ResultPair{ public void accept(ResultPairVisitor visitor) { visitor.visit(this); } + + @Override + public String toString() { + return "(" + left.toString() + " = " + right.toString() + ")"; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java index bc605a27..8d586f4b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java @@ -20,4 +20,9 @@ public class PairTPHsmallerTPH extends ResultPair{ public void accept(ResultPairVisitor visitor) { visitor.visit(this); } + + @Override + public String toString() { + return "(" + left.toString() + " < " + right.toString() + ")"; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java index eef72ab0..955c388b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -6,11 +6,16 @@ import de.dhbwstuttgart.syntaxtree.type.*; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; public class ResultSet { public final Set results; + public Set genIns; public ResultSet(Set results){ this.results = results; + this.genIns = results.stream().filter(a -> a instanceof PairTPHsmallerTPH) + .map(b -> new GenericInsertPair( (TypePlaceholder)(b.getLeft()), (TypePlaceholder)(b.getRight()))) + .collect(Collectors.toCollection(HashSet::new)); } public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index f1e3b7a7..e11c81bc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -19,6 +19,8 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.io.output.NullOutputStream; + import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; @@ -46,6 +48,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.Writer; import com.google.common.collect.Ordering; @@ -165,7 +168,9 @@ public class TypeUnifyTask extends RecursiveTask>> { thNo = totalnoOfThread; writeLog("thNo2 " + thNo); try { - this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + this.logFile = new OutputStreamWriter(new NullOutputStream()); + //new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + logFile.write(""); } catch (IOException e) { System.err.println("log-File nicht vorhanden"); diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index a8d85dfd..5f84acc5 100644 --- a/src/test/resources/bytecode/javFiles/Id.jav +++ b/src/test/resources/bytecode/javFiles/Id.jav @@ -1,6 +1,6 @@ public class Id { - B id(A b){ + id(b){ return b; } } diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 4de9dc6c..991db9c0 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Byte; +//import java.lang.Byte; import java.lang.Boolean; public class MatrixOP extends Vector> { @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { + mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) {