Merge branch 'strucTypes_dev_PL' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypes_dev_PL

This commit is contained in:
Pluemicke Martin 2017-05-05 14:36:12 +02:00
commit f6da15751f
13 changed files with 609 additions and 388 deletions

4
.gitignore vendored
View File

@ -10,3 +10,7 @@ bin
*.jar *.jar
*.war *.war
*.ear *.ear
# Git Ignore für Idea Workspace
/.idea

710
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,7 @@ public class TypeExpr {
LocalVar localVar = (LocalVar) expression; LocalVar localVar = (LocalVar) expression;
// Erstellung keines Constriants // Erstellung keines Constriants
// Lediglich eintrag in TypeVarStore // Lediglich eintrag in TypeVarStore
RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression()); RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
typeVarStore.addTuple(typeVar,localVar.getType()); typeVarStore.addTuple(typeVar,localVar.getType());
List<ConstraintAbstract> result = new ArrayList<>(); List<ConstraintAbstract> result = new ArrayList<>();

View File

@ -145,9 +145,6 @@ public class Rules {
// ToDo Not implemented // ToDo Not implemented
public void reduce(List<ConstraintAbstract> constraints) { public void reduce(List<ConstraintAbstract> constraints) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
@ -359,13 +356,48 @@ 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 ) { private ConstraintInterface sucheInterface( RefTypeOrTPHOrWildcardOrGeneric tvSub , RefTypeOrTPHOrWildcardOrGeneric tvSuper ) {
for (ConstraintInterface cs : constraintInterfaces) { for (ConstraintInterface cs : constraintInterfaces) {
if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) {
String nameStart = null;
String nameStartIF = null;
String nameVglStart = null;
String nameVglIf = null;
nameStart = tvSub.toString();
if (tvSuper instanceof TypeVarInterface) {
nameStartIF = ((TypeVarInterface) tvSuper).getInterfaceForConstraint().getStrucType().toString();
}
nameVglStart = cs.getSubType().toString();
if (cs.getSuperType() instanceof TypeVarInterface) {
nameVglIf = ((TypeVarInterface) cs.getSuperType()).getInterfaceForConstraint().getStrucType().toString();
}
if (nameStart != null && nameStartIF != null && nameVglStart != null && nameVglStart != null ) {
if (nameStart.equals(nameVglStart) && nameStartIF.equals(nameVglIf)) {
return cs; return cs;
} }
} }
//System.out.println(String.format("Vergleiche: %s ==? %s und %s ==? %s " , nameStart, nameVglStart , nameStartIF , nameVglIf));
}
return null; return null;
} }

View File

@ -37,4 +37,8 @@ public class TypeVarFactory {
} }

View File

@ -42,7 +42,8 @@ public class TypeVarRefType extends RefTypeOrTPHOrWildcardOrGeneric {
TypeVarRefType that = (TypeVarRefType) o; TypeVarRefType that = (TypeVarRefType) o;
if (that.toString().equals(this.toString())) { if (that.getRefType().getName().toString().equals(this.getRefType().getName().toString())) {
System.out.println(that.getRefType().getName().toString() + " ==? " + this.getRefType().getName().toString());
return true; return true;
} }
else { else {

View File

@ -65,6 +65,7 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
* Author: Jrg Buerle<br/> * Author: Jrg Buerle<br/>
* @return * @return
*/ */
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if(obj instanceof RefType){ if(obj instanceof RefType){
@ -100,5 +101,24 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
} }
/* Methode zur Fehlersuche
public boolean equals(Object o) {
if (o instanceof RefType) {
RefType r = (RefType) o;
if (r.getName().equals(this.getName())) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
*/
} }

View File

@ -10,6 +10,7 @@ import de.dhbwstuttgart.strucTypes5.solve.Rules;
import de.dhbwstuttgart.strucTypes5.typeVars.*; import de.dhbwstuttgart.strucTypes5.typeVars.*;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -93,33 +94,6 @@ public class SolveTest {
System.out.println("Manuell Test"); 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<ConstraintSubstitution> substitutions = new ArrayList<>(); List<ConstraintSubstitution> substitutions = new ArrayList<>();
@ -131,15 +105,9 @@ public class SolveTest {
while (ti1.resultConstraints.size() > 0) { while (ti1.resultConstraints.size() > 0) {
ruler.rule(); ruler.rule();
} }
} }
} catch (Exception exc) { } catch (Exception exc) {
exc.printStackTrace(); exc.printStackTrace();
fail(); fail();
@ -147,6 +115,9 @@ public class SolveTest {
assertTrue("Tests durchlaufen", filenames.size() > 0); assertTrue("Tests durchlaufen", filenames.size() > 0);
} }
// Erstellt RefType für das Inteface das Implementiert werden soll
private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List<ConstraintAbstract> constraints , String name) { private RefTypeOrTPHOrWildcardOrGeneric getTypeVar(List<ConstraintAbstract> constraints , String name) {
for (ConstraintAbstract cs : constraints) { for (ConstraintAbstract cs : constraints) {
if (cs instanceof ConstraintSubType) { if (cs instanceof ConstraintSubType) {

View File

@ -5,12 +5,12 @@ import de.dhbwstuttgart.strucTypes5.algo.TI;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap; import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.constraints.*; import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.solve.Ruler; import de.dhbwstuttgart.strucTypes5.solve.Ruler;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType; import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -70,7 +70,7 @@ public class SolveTestMyList {
RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5"); RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5");
System.out.println(myInteger.toString()); System.out.println(myInteger.toString());
System.out.println(myList.toString()); System.out.println(myList.toString());
System.out.println(v2.toString()); System.out.println(v2);
// System.out.println(v5.toString()); // System.out.println(v5.toString());
// Generiere Interface 1 // Generiere Interface 1
@ -111,10 +111,6 @@ public class SolveTestMyList {
ruler.rule(); ruler.rule();
} }
} }

View File

@ -0,0 +1,21 @@
class Main {
main () { return new A().mt( new MyInteger() ); }
}
class A{
mt(x) { return x; }
}
class MyInteger {
}
class MyList {
}

View File

@ -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<String> filenames = new ArrayList<String>();
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<RefTypeOrTPHOrWildcardOrGeneric> 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<ConstraintInterface> interfaces = new ArrayList<>();
interfaces.add(constraintInterface);
// Generiere Interface 2
List<RefTypeOrTPHOrWildcardOrGeneric> 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<ConstraintSubstitution> 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<ConstraintAbstract> 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;
}
}