Zwischenstand ...
This commit is contained in:
parent
13330e4fd6
commit
ede8ad6d03
@ -55,7 +55,6 @@ public class JavaTXCompiler {
|
||||
}
|
||||
return new ResultSet(results);
|
||||
}
|
||||
|
||||
public void parse(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
sourceFiles.add(new JavaTXParser().parse(sourceFile));
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 08.05.17.
|
||||
*/
|
||||
public class ConvertConstraints {
|
||||
|
||||
|
||||
public static ConstraintSet<Constraint> convert(List<ConstraintAbstract> constraints) {
|
||||
|
||||
ConstraintSet<Constraint> constraintSet = new ConstraintSet<>();
|
||||
|
||||
for (ConstraintAbstract constraint : constraints) {
|
||||
if (constraint instanceof ConstraintSubType) {
|
||||
constraintSet.addUndConstraint(convertConstraintSubType((ConstraintSubType) constraint));
|
||||
}
|
||||
}
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Constraint<UnifyPair> convertConstraintSubType(ConstraintSubType css) {
|
||||
|
||||
UnifyType t1 = UnifyTypeFactory.convert(css.getSubtype());
|
||||
UnifyType t2 = UnifyTypeFactory.convert(css.getSuperType());
|
||||
|
||||
UnifyPair pair = UnifyTypeFactory.generateSmallerPair(t1,t2);
|
||||
|
||||
Constraint<UnifyPair> constraint = new Constraint<>();
|
||||
constraint.add(pair);
|
||||
|
||||
return constraint;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
25
test/strucTypes5/ConvertTest.jav
Normal file
25
test/strucTypes5/ConvertTest.jav
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
|
||||
class Main {
|
||||
main () { return new A().mt( new MyInteger(), new MyInteger() , new MyInteger() ); }
|
||||
}
|
||||
|
||||
|
||||
class A {
|
||||
mt(x,y,z) { return x.sub(y).add(z); }
|
||||
}
|
||||
|
||||
interface if1<A,B> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MyInteger {
|
||||
|
||||
}
|
||||
|
||||
class MyList {
|
||||
|
||||
}
|
||||
|
97
test/strucTypes5/ConvertTest.java
Normal file
97
test/strucTypes5/ConvertTest.java
Normal file
@ -0,0 +1,97 @@
|
||||
package strucTypes5;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
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 de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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 ConvertTest {
|
||||
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
|
||||
|
||||
@Test
|
||||
public void run() {
|
||||
|
||||
|
||||
List<String> filenames = new ArrayList<String>();
|
||||
filenames.add("ConvertTest.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);
|
||||
|
||||
|
||||
Set<ClassOrInterface> typeinfo = new HashSet<>();
|
||||
ConstraintSet<Constraint> constraints = sf.getClasses().get(0).getConstraints(new TypeInferenceInformation(typeinfo));
|
||||
ConstraintSet cs = constraints;
|
||||
|
||||
|
||||
|
||||
AssumptionMap assumptionMap = new AssumptionMap();
|
||||
|
||||
TI ti = new TI(assumptionMap, aClass);
|
||||
|
||||
//TI ti1 = new TI(ti.assresult, mainClass);
|
||||
|
||||
|
||||
System.out.println(ti.resultConstraints);
|
||||
|
||||
//Converter
|
||||
ConstraintSet<Constraint> constraintSet = ConvertConstraints.convert(ti.resultConstraints);
|
||||
|
||||
|
||||
|
||||
// Construc Interface from Templates
|
||||
|
||||
|
||||
|
||||
System.out.println(constraintSet.toString());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
assertTrue("Tests durchlaufen", filenames.size() > 0);
|
||||
}
|
||||
}
|
@ -6,13 +6,22 @@ main () { return new A().mt( new MyInteger(), new MyInteger() , new MyInteger()
|
||||
}
|
||||
|
||||
|
||||
class A{
|
||||
class A {
|
||||
mt(x,y,z) { return x.sub(y).add(z); }
|
||||
}
|
||||
|
||||
interface if1<A,B> {
|
||||
mt(a,b,c);
|
||||
}
|
||||
|
||||
|
||||
class MyInteger {
|
||||
a = new MyInteger();
|
||||
b;
|
||||
|
||||
mt(a) {
|
||||
return new MyInteger();
|
||||
}
|
||||
}
|
||||
|
||||
class MyList {
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
|
||||
class Main {
|
||||
main () { return new A().mt( new A.mt( new MyInteger() ) ); }
|
||||
main () { return new A().mt( new MyInteger() ); }
|
||||
}
|
||||
|
||||
|
||||
class A{
|
||||
mt(x) { return new A().mt(new MyInteger()); }
|
||||
mt(x) { return x.sub(); }
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,10 +17,10 @@ public class JavaTXCompilerTest {
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler();
|
||||
//compiler.parse(new File(rootDirectory+"Methods.jav"));
|
||||
compiler.parse(new File(rootDirectory+"Methods.jav"));
|
||||
//compiler.parse(new File(rootDirectory+"Generics.jav"));
|
||||
//compiler.parse(new File(rootDirectory+"MethodsEasy.jav"));
|
||||
compiler.parse(new File(rootDirectory+"Lambda.jav"));
|
||||
//compiler.parse(new File(rootDirectory+"Lambda.jav"));
|
||||
compiler.typeInference();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user