diff --git a/.idea/workspace.xml b/.idea/workspace.xml index aa6286c3..17ca699a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,12 @@ - + + - - - + - - - - - - - - - - @@ -1189,9 +1343,6 @@ - - - @@ -1199,9 +1350,6 @@ - - - @@ -1231,7 +1379,6 @@ - @@ -1239,7 +1386,6 @@ - @@ -1247,9 +1393,6 @@ - - - @@ -1275,23 +1418,10 @@ - - - - - - - - - - - - - @@ -1389,7 +1519,6 @@ - @@ -1422,9 +1551,6 @@ - - - @@ -1455,14 +1581,6 @@ - - - - - - - - @@ -1479,16 +1597,6 @@ - - - - - - - - - - @@ -1512,7 +1620,11 @@ - + + + + + @@ -1526,25 +1638,21 @@ - + - - - - - - - - - + + + + + - + @@ -1553,18 +1661,69 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -1572,18 +1731,16 @@ - + - + - - - - - + + + diff --git a/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java b/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java index 1810296d..4af96f6b 100644 --- a/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java +++ b/src/de/dhbwstuttgart/strucTypes5/algo/TypeExpr.java @@ -69,6 +69,7 @@ public class TypeExpr { LocalVar localVar = (LocalVar) expression; // Erstellung keines Constriants // Lediglich eintrag in TypeVarStore + RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression()); typeVarStore.addTuple(typeVar,localVar.getType()); List result = new ArrayList<>(); diff --git a/src/de/dhbwstuttgart/strucTypes5/solve/Ruler.java b/src/de/dhbwstuttgart/strucTypes5/solve/Ruler.java index 2bd24d98..420fbc80 100644 --- a/src/de/dhbwstuttgart/strucTypes5/solve/Ruler.java +++ b/src/de/dhbwstuttgart/strucTypes5/solve/Ruler.java @@ -46,7 +46,7 @@ public class Ruler { public void rule() { //System.out.println("StartConstraints: " + constraintList); Help.print("StartConstraints" , constraintList); - substitutionList = ruleAll(constraintList,substitutionList); + substitutionList = ruleAll(constraintList,substitutionList); Help.print("Aktuelle Substitutionen: " ,substitutionList); Help.print("Aktuelle Constriants: " , constraintList); diff --git a/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java index dbc72cc4..c9300000 100644 --- a/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java +++ b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java @@ -145,9 +145,6 @@ public class Rules { - - - // ToDo Not implemented public void reduce(List constraints) { for (ConstraintAbstract cs : constraints) { @@ -359,15 +356,17 @@ public class Rules { } - + /** + * Sucht aus den geladen Interfaces das benötigte herraus. + * + * + * @param tvSub Subtype des Constraints + * @param tvSuper Gesuchtes Interface aus dem Constraint mit dem Objekt "Interface for Constraint". + * @return gibt den Constraint für den das gefundene Interface zurück. + */ private ConstraintInterface sucheInterface( RefTypeOrTPHOrWildcardOrGeneric tvSub , RefTypeOrTPHOrWildcardOrGeneric tvSuper ) { for (ConstraintInterface cs : constraintInterfaces) { - // if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) { - //if ( cs.getSubType().equals(tvSub) && cs.getSuperType().equals(tvSuper) ) { - // if (true) { - // return cs; - String nameStart = null; String nameStartIF = null; @@ -389,25 +388,16 @@ public class Rules { nameVglIf = ((TypeVarInterface) cs.getSuperType()).getInterfaceForConstraint().getStrucType().toString(); } - if (nameStart.equals(nameVglStart) && nameStartIF.equals(nameVglIf)) { - return cs; + + if (nameStart != null && nameStartIF != null && nameVglStart != null && nameVglStart != null ) { + if (nameStart.equals(nameVglStart) && nameStartIF.equals(nameVglIf)) { + return cs; + } } - - - //System.out.println(String.format("Vergleiche: %s ==? %s und %s ==? %s " , nameStart, nameVglStart , nameStartIF , nameVglIf)); - - - - - } - - - - return null; } diff --git a/test/strucTypes5/SolveTest.jav b/test/strucTypes5/SolveTest.jav index 7bba0374..e113d202 100644 --- a/test/strucTypes5/SolveTest.jav +++ b/test/strucTypes5/SolveTest.jav @@ -2,7 +2,7 @@ class Main { -main () { return new A().mt( new MyInteger() , new MyInteger() , new MyInteger() ); } +main () { return new A().mt( new MyInteger(), new MyInteger() , new MyInteger() ); } } diff --git a/test/strucTypes5/SolveTest.java b/test/strucTypes5/SolveTest.java index f00b03f3..639e3aac 100644 --- a/test/strucTypes5/SolveTest.java +++ b/test/strucTypes5/SolveTest.java @@ -94,33 +94,6 @@ public class SolveTest { System.out.println("Manuell Test"); - /* - Rules rules = new Rules(); - rules.setConstraintInterfaces(interfaces); - - - - System.out.println(ti1.resultConstraints); - - rules.adapt2(ti1.resultConstraints); - System.out.println(ti1.resultConstraints); - - rules.swap(ti1.resultConstraints); - System.out.println(ti1.resultConstraints); - - rules.swap(ti1.resultConstraints); - System.out.println(ti1.resultConstraints); - - rules.subst(ti1.resultConstraints); - System.out.println(ti1.resultConstraints); - - rules.subst(ti1.resultConstraints); - System.out.println(ti1.resultConstraints); - - - System.out.println(rules.substitutions); - - */ List substitutions = new ArrayList<>(); @@ -132,15 +105,9 @@ public class SolveTest { while (ti1.resultConstraints.size() > 0) { ruler.rule(); } - - - - } - - } catch (Exception exc) { exc.printStackTrace(); fail(); @@ -148,6 +115,9 @@ public class SolveTest { assertTrue("Tests durchlaufen", filenames.size() > 0); } + + + // Erstellt RefType für das Inteface das Implementiert werden soll private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List constraints , String name) { for (ConstraintAbstract cs : constraints) { if (cs instanceof ConstraintSubType) { diff --git a/test/strucTypes5/SolveTestRek.jav b/test/strucTypes5/SolveTestRek.jav new file mode 100644 index 00000000..b02a47e0 --- /dev/null +++ b/test/strucTypes5/SolveTestRek.jav @@ -0,0 +1,21 @@ + + + +class Main { +main () { return new A().mt( new MyInteger() ); } +} + + +class A{ +mt(x) { return x; } +} + + +class MyInteger { + +} + +class MyList { + +} + diff --git a/test/strucTypes5/SolveTest_Rek.java b/test/strucTypes5/SolveTest_Rek.java new file mode 100644 index 00000000..a79bf8dc --- /dev/null +++ b/test/strucTypes5/SolveTest_Rek.java @@ -0,0 +1,141 @@ +package strucTypes5; + +import de.dhbwstuttgart.parser.JavaTXParser; +import de.dhbwstuttgart.strucTypes5.algo.TI; +import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap; +import de.dhbwstuttgart.strucTypes5.constraints.*; +import de.dhbwstuttgart.strucTypes5.solve.Ruler; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface; +import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der + * dabei erstellte Syntaxbaum wird nicht kontrolliert. + * + * @author janulrich + * + */ +public class SolveTest_Rek { + private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/"; + + @Test + public void run() { + + + List filenames = new ArrayList(); + filenames.add("SolveTestRek.jav"); + + JavaTXParser parser = new JavaTXParser(); + try { + for (String filename : filenames) { + + System.out.println("Teste: " + filename); + + SourceFile sf = parser.parse(new File(rootDirectory + filename)); + + SourceFile sfdebug = sf; + + ClassOrInterface mainClass = sf.getClasses().get(0); + ClassOrInterface aClass = sf.getClasses().get(1); + + + AssumptionMap assumptionMap = new AssumptionMap(); + + TI ti = new TI(assumptionMap, aClass); + + TI ti1 = new TI(ti.assresult, mainClass); + + // Take The Generatet Constraints from ti: + // Try To Solve + + System.out.println("\n \n \n \n Starte einfach Unifikation "); + System.out.println("Gegegeben Constraints: " + ti1.resultConstraints); + + // Generate Interfaces Give + TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger"); + RefTypeOrTPHOrWildcardOrGeneric v2 = getTypeVar(ti1.resultConstraints , "TVar_2"); + RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5"); + System.out.println(myInteger.toString()); + System.out.println(v2.toString()); + System.out.println(v5.toString()); + + // Generiere Interface 1 + List generics = new ArrayList<>(); + generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); + generics.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); + InterfaceForConstraint if1 = new InterfaceForConstraint(v2, generics); + ConstraintInterface constraintInterface = new ConstraintInterface(TypeVarFactory.makeTypeVar(myInteger.getRefType()) , TypeVarFactory.makeTypeVar(if1) ); + List interfaces = new ArrayList<>(); + interfaces.add(constraintInterface); + + + // Generiere Interface 2 + List generics2 = new ArrayList<>(); + generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); + generics2.add(TypeVarFactory.makeTypeVar(myInteger.getRefType())); + InterfaceForConstraint if2 = new InterfaceForConstraint(v5, generics); + ConstraintInterface constraintInterface2 = new ConstraintInterface(TypeVarFactory.makeTypeVar(myInteger.getRefType()) , TypeVarFactory.makeTypeVar(if2) ); + interfaces.add(constraintInterface2); + + System.out.println(interfaces); + + + System.out.println("Manuell Test"); + + + + List substitutions = new ArrayList<>(); + Ruler ruler = new Ruler(interfaces,substitutions,ti1.resultConstraints); + + System.out.println("start ..."); + + + while (ti1.resultConstraints.size() > 0) { + ruler.rule(); + } + } + + + } catch (Exception exc) { + exc.printStackTrace(); + fail(); + } + assertTrue("Tests durchlaufen", filenames.size() > 0); + } + + + + // Erstellt RefType für das Inteface das Implementiert werden soll + private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List constraints , String name) { + for (ConstraintAbstract cs : constraints) { + if (cs instanceof ConstraintSubType) { + ConstraintSubType css = (ConstraintSubType) cs; + if (css.getSubtype().toString().equals(name)) { + return css.getSubtype(); + } + else if (css.getSuperType().toString().equals(name)) { + return css.getSuperType(); + } + else if (css.getSuperType() instanceof TypeVarInterface) { + TypeVarInterface tcv = (TypeVarInterface) css.getSuperType(); + if (tcv.getInterfaceForConstraint().getStrucType().toString().equals(name)) { + return tcv.getInterfaceForConstraint().getStrucType(); + } + } + } + } + return null; + } +}