From b082b603de516577f9d584e7b4fc55723db835b4 Mon Sep 17 00:00:00 2001 From: sebastian Date: Mon, 1 May 2017 21:32:30 +0200 Subject: [PATCH] Interface Constraints erhalten jetzt auch neue Typvariablen --- .idea/workspace.xml | 707 +++++++----------- src/de/dhbwstuttgart/strucTypes5/algo/TI.java | 5 +- .../strucTypes5/algo/TypeExpr.java | 14 +- .../constraints/ConstraintShouldEqual.java | 40 + .../constraints/ConstraintSubstitution.java | 39 + .../strucTypes5/solve/Rules.java | 89 +++ .../strucTypes5/typeVars/MappingAltNeu.java | 27 +- 7 files changed, 457 insertions(+), 464 deletions(-) create mode 100644 src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintShouldEqual.java create mode 100644 src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintSubstitution.java create mode 100644 src/de/dhbwstuttgart/strucTypes5/solve/Rules.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 823375c4..51549f23 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,9 @@ - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1470,14 +1210,6 @@ - - - - - - - - @@ -1494,14 +1226,6 @@ - - - - - - - - @@ -1602,16 +1326,6 @@ - - - - - - - - - - @@ -1688,16 +1402,6 @@ - - - - - - - - - - @@ -1708,14 +1412,6 @@ - - - - - - - - @@ -1727,34 +1423,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1771,17 +1439,146 @@ - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/de/dhbwstuttgart/strucTypes5/algo/TI.java b/src/de/dhbwstuttgart/strucTypes5/algo/TI.java index 9262ad9f..b0cce412 100644 --- a/src/de/dhbwstuttgart/strucTypes5/algo/TI.java +++ b/src/de/dhbwstuttgart/strucTypes5/algo/TI.java @@ -88,6 +88,7 @@ public class TI { System.out.println(newResultConstraints); + //OldConstraints newOldConstraints = new OldConstraints(newResultConstraints); @@ -110,7 +111,7 @@ public class TI { - + // Result of Solve -> @@ -119,8 +120,6 @@ public class TI { - - public void ausgabe(ClassOrInterface cl) { Class2String cs = new Class2String(); String s = cs.generateStringTPH(cl); diff --git a/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java b/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java index 80243920..6cd0f0af 100644 --- a/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java +++ b/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java @@ -155,6 +155,11 @@ public class TypeExpr { //Versuche Informationen zu laden AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString()); if (assumptionClass != null) { + + ChangeTypeVars changeTypeVars = new ChangeTypeVars(); + assumptionClass = changeTypeVars.change(assumptionClass); + assumptionMap.putClass(assumptionClass); + OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints()); result.add(oldConstraints); @@ -164,9 +169,12 @@ public class TypeExpr { System.out.println(class2String.generateStringTypeVars(assumptionClass.getCl(), assumptionClass.getTypeVarStore())); System.out.println("-----------------------"); - ChangeTypeVars changeTypeVars = new ChangeTypeVars(); - AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass); - assumptionMap.putClass(assumptionClass1); + //ChangeTypeVars changeTypeVars = new ChangeTypeVars(); + //AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass); + + // ToDO Problem mit den neuen Typvariablen da die infos nochmals geladen werden beim Method call !!! + // (Das einige logische wäre bereits davor die TypVariablen zu tauschen -> So steht es ja eigentlich auf im Skript + //assumptionMap.putClass(assumptionClass1); } diff --git a/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintShouldEqual.java b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintShouldEqual.java new file mode 100644 index 00000000..fdd13482 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintShouldEqual.java @@ -0,0 +1,40 @@ +package de.dhbwstuttgart.strucTypes5.constraints; + +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; + +/** + * Created by sebastian on 01.05.17. + */ +public class ConstraintShouldEqual extends ConstraintAbstract{ + + private TypeVarAbstract t1; + private TypeVarAbstract t2; + + public ConstraintShouldEqual(TypeVarAbstract t1, TypeVarAbstract t2) { + this.t1 = t1; + this.t2 = t2; + } + + public TypeVarAbstract getT1() { + return t1; + } + + public void setT1(TypeVarAbstract t1) { + this.t1 = t1; + } + + public TypeVarAbstract getT2() { + return t2; + } + + public void setT2(TypeVarAbstract t2) { + this.t2 = t2; + } + + @Override + public String toString() { + return String.format("ConstraintShouldEqual( %s =* %s )" , t1, t2); + } +} + diff --git a/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintSubstitution.java b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintSubstitution.java new file mode 100644 index 00000000..88b414dc --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintSubstitution.java @@ -0,0 +1,39 @@ +package de.dhbwstuttgart.strucTypes5.constraints; + +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; + +/** + * Created by sebastian on 01.05.17. + */ +public class ConstraintSubstitution extends ConstraintAbstract { + + private TypeVarAbstract t1; + private TypeVarAbstract t2; + + public ConstraintSubstitution(TypeVarAbstract t1, TypeVarAbstract t2) { + this.t1 = t1; + this.t2 = t2; + } + + public TypeVarAbstract getT1() { + return t1; + } + + public void setT1(TypeVarAbstract t1) { + this.t1 = t1; + } + + public TypeVarAbstract getT2() { + return t2; + } + + public void setT2(TypeVarAbstract t2) { + this.t2 = t2; + } + + @Override + public String toString() { + return String.format("ConstraintSubstitution[ %s --> %s]" , t1 , t2); + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java new file mode 100644 index 00000000..347b3b30 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java @@ -0,0 +1,89 @@ +package de.dhbwstuttgart.strucTypes5.solve; + + +import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes5.constraints.ConstraintShouldEqual; +import de.dhbwstuttgart.strucTypes5.constraints.ConstraintSubType; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType; + +import java.util.List; + +/** + * Created by sebastian on 01.05.17. + */ +public class Rules { + + + + + + + public void erase1(List constraints) { + for (ConstraintAbstract cs : constraints) { + if (cs instanceof ConstraintSubType) { + ConstraintSubType csst = (ConstraintSubType) cs; + if (csst.getSubtype() instanceof TypeVarRefType && csst.getSuperType() instanceof TypeVarRefType) { + if (csst.getSubtype().equals(csst.getSuperType())) { + constraints.remove(cs); + return; + } + } + } + } + } + + public void erase2(List constraints) { + for (ConstraintAbstract cs : constraints) { + if (cs instanceof ConstraintShouldEqual) { + ConstraintShouldEqual csse = (ConstraintShouldEqual) cs; + if (csse.getT1() instanceof TypeVarRefType && csse.getT2() instanceof TypeVarRefType) { + if (csse.getT1().equals(csse.getT2())) { + constraints.remove(cs); + return; + } + } + } + } + } + + + + // swap a Should Equal Constriant. if (Theta is not TypeVar) and (T is TypeVar) + public void swap(List constraints) { + for (ConstraintAbstract cs : constraints) { + if (cs instanceof ConstraintShouldEqual) { + ConstraintShouldEqual csse = (ConstraintShouldEqual) cs; + TypeVarAbstract theta = csse.getT1(); + TypeVarAbstract typeVar = csse.getT2(); + if (theta instanceof TypeVarRefType && typeVar instanceof TypeVar) { + csse.setT1(typeVar); + csse.setT2(theta); + return; + } + } + } + } + + + /* + C u { Theta =* Type } + ---------------------- + C[T -> Typ vereinigt mit T =* Theta + Wenn T eine Typvariable ist und T in C aber nicht in Theta vorkommt + */ + public void subst(List constratins) { + + } + + + + + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes5/typeVars/MappingAltNeu.java b/src/de/dhbwstuttgart/strucTypes5/typeVars/MappingAltNeu.java index e312c241..c9508908 100644 --- a/src/de/dhbwstuttgart/strucTypes5/typeVars/MappingAltNeu.java +++ b/src/de/dhbwstuttgart/strucTypes5/typeVars/MappingAltNeu.java @@ -1,6 +1,8 @@ package de.dhbwstuttgart.strucTypes5.typeVars; +import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint; + import java.util.ArrayList; import java.util.List; @@ -28,10 +30,31 @@ public class MappingAltNeu { public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) { - if (altTypeVar instanceof TypeVarInterface || altTypeVar instanceof TypeVarRefType) { + // Wenn der Typ bereits bekannt ist gebe ihn zurück + if (altTypeVar instanceof TypeVarRefType) { return altTypeVar; } + else if (altTypeVar instanceof TypeVarInterface) { + TypeVarInterface strucType = (TypeVarInterface) altTypeVar; + TypeVarAbstract name = strucType.getInterfaceForConstraint().getStrucType(); + List neueGenerics = new ArrayList<>(); + List alteGenerics = strucType.getInterfaceForConstraint().getGenerics(); + for (TypeVarAbstract tv : alteGenerics) { + neueGenerics.add(this.getNeu(tv)); + } + InterfaceForConstraint interfaceForConstraint = new InterfaceForConstraint(name,neueGenerics); + TypeVarInterface typeVarInterface = new TypeVarInterface(interfaceForConstraint); + + return typeVarInterface; + } + else if (altTypeVar instanceof TypeVar) { + return neuList.get(altList.indexOf(altTypeVar)); + } + else { + System.err.println("kein TypeVarChange möglich " + MappingAltNeu.class.getName() ); + return altTypeVar; + } // Wenn typ bereits bekannt ist //if (altTypeVar.getClass().equals(TypeVarType.class)) { @@ -43,8 +66,6 @@ public class MappingAltNeu { // return altTypeVar; //} //System.out.println(altTypeVar); - - return neuList.get(altList.indexOf(altTypeVar)); } }