modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java

cardProd als Variable eingfuegt
	modified:   ../../src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java
toString() eingfuegt
	modified:   ../../src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
toString() eingfuegt
	modified:   ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
BinaryOp <. statt =.
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Bei nicht importierten (result []) undefinPair gesetzt
	modified:   ../javFiles/Matrix.jav
falsche importe rausgenommen
This commit is contained in:
Martin Plümicke 2018-05-22 17:10:07 +02:00
parent 06a0cb8eaf
commit c597b0430a
6 changed files with 63 additions and 34 deletions

View File

@ -111,7 +111,8 @@ public class JavaTXCompiler {
logFile.write(ASTTypePrinter.print(sf));
}
logFile.flush();
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
for (List<Constraint<UnifyPair>> xCons : cardProd ){
Set<UnifyPair> xConsSet = new HashSet<>();
for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);

View File

@ -106,4 +106,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
public Collection<RefType> getSuperInterfaces() {
return implementedInterfaces;
}
public String toString() {
return this.name.toString() + this.genericClassParameters.toString();
}
}

View File

@ -31,4 +31,8 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
public String toString() {
return this.gtvs.toString();
}
}

View File

@ -223,34 +223,34 @@ public class TYPEStmt implements StatementVisitor{
//see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
Constraint<Pair> numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), longg, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), floatt, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
numeric = new Constraint<>();
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.getType(), doublee, PairOperator.EQUALSDOT));
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
/*
In Java passiert bei den binären Operatoren eine sogenannte Type Promotion:

View File

@ -142,6 +142,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* @return The set of all principal type unifiers
*/
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
).collect(Collectors.toCollection(HashSet::new));
writeLog(nOfUnify.toString() + " AA: " + aas.toString());
if (aas.isEmpty()) {
System.out.println("");
}
/*
* Step 1: Repeated application of reduce, adapt, erase, swap
*/
@ -789,6 +795,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> x1 = unifyCase1(pair, fc);
//System.out.println(x1);
result.get(0).add(x1);
if (x1.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC => Abbruch
}
}
else {
Set<UnifyPair> s1 = new HashSet<>();
@ -802,7 +811,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 2: (a <.? ? ext Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
if (first) { //writeLog(pair.toString()+"\n");
result.get(1).add(unifyCase2(pair, fc));
Set<Set<UnifyPair>> x1 = unifyCase2(pair, fc);
result.get(1).add(x1);
if (x1.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC
}
}
else {
Set<UnifyPair> s1 = new HashSet<>();
@ -815,7 +828,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 3: (a <.? ? sup Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
if (first) { //writeLog(pair.toString()+"\n");
result.get(2).add(unifyCase3(pair, fc));
Set<Set<UnifyPair>> x1 = unifyCase3(pair, fc);
result.get(2).add(x1);
if (x1.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC
}
}
else {
Set<UnifyPair> s1 = new HashSet<>();
@ -833,9 +850,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 5: (Theta <. a)
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
if (first) { //writeLog(pair.toString()+"\n");
if (rhsType.getName().equals("A"))
System.out.println();
result.get(4).add(unifyCase5(pair, fc));
Set<Set<UnifyPair>> x1 = unifyCase5(pair, fc);
result.get(4).add(x1);
if (x1.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC
}
}
else {
Set<UnifyPair> s1 = new HashSet<>();
@ -858,8 +877,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 8: (Theta <.? a)
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
if (first) { //writeLog(pair.toString()+"\n");
result.get(7).add(
unifyCase8(pair, fc));
Set<Set<UnifyPair>> x1 = unifyCase8(pair, fc);
result.get(7).add(x1);
if (x1.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC
}
}
else {
Set<UnifyPair> s1 = new HashSet<>();
@ -892,9 +914,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
PlaceholderType a = (PlaceholderType)pair.getLhsType();
UnifyType thetaPrime = pair.getRhsType();
byte variance = pair.getVariance();
if (a.getName().equals("D")) {
System.out.print("");
}
Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = thetaPrime.getTypeParams().size() > 0;
@ -906,6 +926,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector<NP>, java.util.Vector<java.util.Vector<java.lang.Integer>>, ????java.util.Vector<gen_hv>???]
//PL 18-02-06 entfernt, kommt durch unify wieder rein
//cs.add(thetaPrime);
//PL 18-02-06 entfernt

View File

@ -1,7 +1,5 @@
import java.util.Vector;
import java.lang.Integer;
import java.lang.Boolean;
import java.lang.String;
class Matrix extends Vector<Vector<Integer>> {
Integer mul1(Integer x, Integer y) { return x;}
@ -17,9 +15,9 @@ class Matrix extends Vector<Vector<Integer>> {
var erg = 0;
var k = 0;
while(k < v1.size()) {
//erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
erg = add1(erg, mul1(v1.elementAt(k),
m.elementAt(k).elementAt(j)));
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
//erg = add1(erg, mul1(v1.elementAt(k),
// m.elementAt(k).elementAt(j)));
k++; }
v2.addElement(new Integer(erg));
j++; }