Ordnung fuer Variablen unterschieden, ob sie innere Typen sind oder nicht

modified:   ../../core/JavaTXCompiler.java
	modified:   UnifyTypeFactory.java
Bestimmung welche Typevariablen innere Typen sind

	modified:   ../../typeinference/unify/TypeUnifyTask.java
	modified:   ../../typeinference/unify/model/OrderingUnifyPair.java
Ordnungsfunktion geaendert

	modified:   ../../typeinference/unify/model/PlaceholderType.java
	modified:   ../../typeinference/unify/model/UnifyPair.java
This commit is contained in:
Martin Plümicke 2019-01-13 00:42:33 +01:00
parent 6de1c50542
commit faccdf5896
6 changed files with 45 additions and 21 deletions

View File

@ -16,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
@ -30,6 +31,7 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
import java.io.File; import java.io.File;
@ -283,7 +285,24 @@ public class JavaTXCompiler {
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
System.out.println(finiteClosure); System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons); ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
Function<UnifyPair, UnifyPair> distributeInnerVars =
x -> {
UnifyType lhs, rhs;
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
&& (((PlaceholderType)lhs).isInnerType()
|| ((PlaceholderType)rhs).isInnerType()))
{
((PlaceholderType)lhs).setInnerType(true);
((PlaceholderType)rhs).setInnerType(true);
}
return x;
};
logFile.write(unifyCons.toString());
unifyCons = unifyCons.map(distributeInnerVars);
logFile.write(unifyCons.toString());
TypeUnify unify = new TypeUnify(); TypeUnify unify = new TypeUnify();
//Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen //Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
logFile.write("FC:\\" + finiteClosure.toString()+"\n"); logFile.write("FC:\\" + finiteClosure.toString()+"\n");

View File

@ -120,8 +120,8 @@ public class UnifyTypeFactory {
} }
public static UnifyType convert(TypePlaceholder tph, Boolean innerType){ public static UnifyType convert(TypePlaceholder tph, Boolean innerType){
if (tph.getName().equals("AFQ")) { if (tph.getName().equals("AFR")) {
System.out.println(""); System.out.println("XXX"+innerType);
} }
PlaceholderType ntph = new PlaceholderType(tph.getName()); PlaceholderType ntph = new PlaceholderType(tph.getName());
int in = PLACEHOLDERS.indexOf(ntph); int in = PLACEHOLDERS.indexOf(ntph);
@ -132,21 +132,16 @@ public class UnifyTypeFactory {
} }
else { else {
PlaceholderType oldpht = PLACEHOLDERS.get(in); PlaceholderType oldpht = PLACEHOLDERS.get(in);
if (oldpht.isWildcardable()) { oldpht.setInnerType(oldpht.isInnerType() || innerType);
return oldpht; return oldpht;
}
else {
oldpht.setInnerType(innerType);
return oldpht;
}
} }
} }
public static UnifyType convert(GenericRefType t){ public static UnifyType convert(GenericRefType t, Boolean innerType){
return new ReferenceType(t.getParsedName()); return new ReferenceType(t.getParsedName());
} }
public static UnifyType convert(WildcardType t){ public static UnifyType convert(WildcardType t, Boolean innerType){
if(t.isExtends()) if(t.isExtends())
return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false)); return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false));
else if(t.isSuper()) else if(t.isSuper())

View File

@ -578,6 +578,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//Aufruf von computeCartesianRecursive ANFANG //Aufruf von computeCartesianRecursive ANFANG
//writeLog("topLevelSets: " + topLevelSets.toString());
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe);
} }
@ -610,9 +611,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 5: Substitution * Step 5: Substitution
*/ */
//System.out.println("vor Subst: " + eqPrime); //writeLog("vor Subst: " + eqPrime);
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime); Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
//writeLog("nach Subst: " + eqPrimePrime);
/* /*
* Step 6 a) Restart (fork) for pairs where subst was applied * Step 6 a) Restart (fork) for pairs where subst was applied
*/ */
@ -797,7 +798,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n");
elems.add(a); elems.add(a);
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
//writeLog("Vor unify2 Aufruf: " + eq.toString()); //writeLog("Vor unify2 Aufruf: " + elems.toString());
Set<Set<UnifyPair>> res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); Set<Set<UnifyPair>> res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe);
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
@ -1585,6 +1586,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12 if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12
freshTphs.add(PlaceholderType.freshPlaceholder()); freshTphs.add(PlaceholderType.freshPlaceholder());
freshTphs.forEach(x -> ((PlaceholderType)x).setInnerType(true));
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
} }
@ -1768,6 +1770,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
UnifyType freshTph = PlaceholderType.freshPlaceholder(); UnifyType freshTph = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshTph).setVariance(a.getVariance()); ((PlaceholderType)freshTph).setVariance(a.getVariance());
((PlaceholderType)freshTph).disableWildcardtable();
resultPrime = new HashSet<>(); resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
@ -1821,11 +1824,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
void writeLog(String str) { void writeLog(String str) {
if (log) { if (log) {
try { try {
logFile.write(str+"\n"); logFile.write(str+"\n\n");
logFile.flush(); logFile.flush();
} }
catch (IOException e) { } catch (IOException e) {
System.err.println("kein LogFile");
}
} }
} }
} }

View File

@ -30,7 +30,8 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
* in dem compare(Theta, Theta') aufgerufen wird. * in dem compare(Theta, Theta') aufgerufen wird.
*/ */
public int compareEq (UnifyPair left, UnifyPair right) { public int compareEq (UnifyPair left, UnifyPair right) {
if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) { //if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) {//PL 2019-01-12 ausgetauscht
if (((PlaceholderType)left.getLhsType()).isInnerType() && ((PlaceholderType)right.getLhsType()).isInnerType()) {
return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC);
} }
else { else {

View File

@ -49,7 +49,7 @@ public final class PlaceholderType extends UnifyType{
/** /**
* is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird * is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird
*/ */
private boolean innerType = true; private boolean innerType = false;
/** /**
* variance shows the variance of the pair * variance shows the variance of the pair
@ -137,6 +137,10 @@ public final class PlaceholderType extends UnifyType{
this.wildcardable = wildcardable; this.wildcardable = wildcardable;
} }
public Boolean isInnerType() {
return innerType;
}
public void setInnerType(Boolean innerType) { public void setInnerType(Boolean innerType) {
this.innerType = innerType; this.innerType = innerType;
} }

View File

@ -219,10 +219,10 @@ public class UnifyPair {
public String toString() { public String toString() {
String ret = ""; String ret = "";
if (lhs instanceof PlaceholderType) { if (lhs instanceof PlaceholderType) {
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString(); ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType();
} }
if (rhs instanceof PlaceholderType) { if (rhs instanceof PlaceholderType) {
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString(); ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType();
} }
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
} }