forked from JavaTX/JavaCompilerCore
Merge branch 'strucTypes_dev_PL' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypes_dev_PL
This commit is contained in:
commit
f6da15751f
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,3 +10,7 @@ bin
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
|
||||
# Git Ignore für Idea Workspace
|
||||
/.idea
|
710
.idea/workspace.xml
generated
710
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@ -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<ConstraintAbstract> result = new ArrayList<>();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -145,9 +145,6 @@ public class Rules {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ToDo Not implemented
|
||||
public void reduce(List<ConstraintAbstract> 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 ) {
|
||||
|
||||
for (ConstraintInterface cs : constraintInterfaces) {
|
||||
if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) {
|
||||
return cs;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
//System.out.println(String.format("Vergleiche: %s ==? %s und %s ==? %s " , nameStart, nameVglStart , nameStartIF , nameVglIf));
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -37,4 +37,8 @@ public class TypeVarFactory {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ public class TypeVarRefType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
|
@ -65,6 +65,7 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
* Author: Jrg Buerle<br/>
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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() ); }
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ import de.dhbwstuttgart.strucTypes5.solve.Rules;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.*;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@ -93,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<ConstraintSubstitution> substitutions = new ArrayList<>();
|
||||
@ -131,15 +105,9 @@ public class SolveTest {
|
||||
while (ti1.resultConstraints.size() > 0) {
|
||||
ruler.rule();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail();
|
||||
@ -147,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<ConstraintAbstract> constraints , String name) {
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
if (cs instanceof ConstraintSubType) {
|
||||
|
@ -5,12 +5,12 @@ 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.TypeVarAbstract;
|
||||
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;
|
||||
@ -70,7 +70,7 @@ public class SolveTestMyList {
|
||||
RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5");
|
||||
System.out.println(myInteger.toString());
|
||||
System.out.println(myList.toString());
|
||||
System.out.println(v2.toString());
|
||||
System.out.println(v2);
|
||||
// System.out.println(v5.toString());
|
||||
|
||||
// Generiere Interface 1
|
||||
@ -111,10 +111,6 @@ public class SolveTestMyList {
|
||||
ruler.rule();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
21
test/strucTypes5/SolveTestRek.jav
Normal file
21
test/strucTypes5/SolveTestRek.jav
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
|
||||
class Main {
|
||||
main () { return new A().mt( new MyInteger() ); }
|
||||
}
|
||||
|
||||
|
||||
class A{
|
||||
mt(x) { return x; }
|
||||
}
|
||||
|
||||
|
||||
class MyInteger {
|
||||
|
||||
}
|
||||
|
||||
class MyList {
|
||||
|
||||
}
|
||||
|
141
test/strucTypes5/SolveTest_Rek.java
Normal file
141
test/strucTypes5/SolveTest_Rek.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user