diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 6e7e6516..034ca37d 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -1,12 +1,16 @@ package de.dhbwstuttgart.core; import de.dhbwstuttgart.environment.CompilationEnvironment; +import de.dhbwstuttgart.environment.PackageCrawler; import de.dhbwstuttgart.parser.JavaTXParser; import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.constraints.Constraint; @@ -39,12 +43,22 @@ public class JavaTXCompiler { } } - public List typeInference(){ + public List typeInference() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); for(SourceFile sf : sourceFiles.values()){ allClasses.addAll(sf.getClasses()); } - FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); + List importedClasses = new ArrayList<>(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for(File forSourceFile : sourceFiles.keySet()) + for(JavaClassName name : sourceFiles.get(forSourceFile).getImports()){ + ClassOrInterface importedClass = ASTFactory.createClass( + ClassLoader.getSystemClassLoader().loadClass(name.toString())); + importedClasses.add(importedClass); + } + allClasses.addAll(importedClasses); + FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); + final ConstraintSet cons = new TYPE(sourceFiles.values(), allClasses).getConstraints(); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); @@ -56,9 +70,9 @@ public class JavaTXCompiler { xConsSet.addAll(constraint); } - System.out.println(xConsSet); + //System.out.println(xConsSet); Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); + //System.out.println("RESULT: " + result); results.addAll(result); } return results.stream().map((unifyPairs -> diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 4dd9081d..540bc993 100644 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -24,13 +24,13 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ private List fields = new ArrayList<>(); private List methods = new ArrayList<>(); private GenericDeclarationList genericClassParameters; - private RefTypeOrTPHOrWildcardOrGeneric superClass; + private RefType superClass; protected boolean isInterface; private List implementedInterfaces; private List constructors; public ClassOrInterface(int modifiers, JavaClassName name, List fielddecl, List methods, List constructors, GenericDeclarationList genericClassParameters, - RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List implementedInterfaces, Token offset){ + RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset){ super(offset); this.modifiers = modifiers; this.name = name; @@ -74,7 +74,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ return new RefType(name, params, offset); } - public RefTypeOrTPHOrWildcardOrGeneric getSuperClass() { + public RefType getSuperClass() { return superClass; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index af672837..2005a387 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -74,7 +74,6 @@ public class TypeUnifyTask extends RecursiveTask>> { * @return The set of all principal type unifiers */ protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { - System.out.println(eq); /* * Step 1: Repeated application of reduce, adapt, erase, swap */ @@ -153,7 +152,6 @@ public class TypeUnifyTask extends RecursiveTask>> { Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) .stream().map(x -> new HashSet<>(x)) .collect(Collectors.toCollection(HashSet::new)); - //System.out.println(result); Set> eqPrimePrimeSet = new HashSet<>(); @@ -162,14 +160,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Flatten the cartesian product Set eqPrime = new HashSet<>(); setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); - System.out.println(eqPrime); /* * Step 5: Substitution */ Optional> eqPrimePrime = rules.subst(eqPrime); - System.out.println(eq); - System.out.println(eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied @@ -450,7 +445,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set cs = fc.getAllTypesByName(thetaPrime.getName()); cs.add(thetaPrime); - for(UnifyType c : cs) { + for(UnifyType c : cs) { Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, //da children offensichtlich ein echtes kleiner und kein kleinergleich ist diff --git a/test/javFiles/fc.jav b/test/javFiles/fc.jav new file mode 100644 index 00000000..cb8c1799 --- /dev/null +++ b/test/javFiles/fc.jav @@ -0,0 +1,17 @@ +import java.util.*; + +class Test{ + methode(param1, param2, param3) { + return param1.meth(param2.add(param3)); + } +} + +interface Klasse1{ + Klasse1 meth(Klasse1 p); + Klasse1 meth(Klasse2 p); +} + +interface Klasse2{ + Klasse1 meth(Klasse1 p); + Klasse2 meth(Klasse2 p); +} \ No newline at end of file diff --git a/test/javFiles/test.jav b/test/javFiles/test.jav index b539c15d..303d167a 100644 --- a/test/javFiles/test.jav +++ b/test/javFiles/test.jav @@ -10,6 +10,6 @@ interface Klasse1{ } interface Klasse2{ - Klasse1 meth(Klasse1 p): - Klasse2 meth(Klasse2 p): + Klasse1 meth(Klasse1 p); + Klasse2 meth(Klasse2 p); } \ No newline at end of file diff --git a/test/typeinference/FiniteClosureTest.java b/test/typeinference/FiniteClosureTest.java new file mode 100644 index 00000000..d3e1fdb0 --- /dev/null +++ b/test/typeinference/FiniteClosureTest.java @@ -0,0 +1,9 @@ +package typeinference; + +import java.io.File; + +public class FiniteClosureTest extends JavaTXCompilerTest{ + public FiniteClosureTest() { + this.fileToTest = new File(rootDirectory+"fc.jav"); + } +} \ No newline at end of file