forked from JavaTX/JavaCompilerCore
Finite Closure beachtet imports
This commit is contained in:
parent
36bb442bff
commit
8c00d89731
@ -1,12 +1,16 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
|
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
@ -39,12 +43,22 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference(){
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
for(SourceFile sf : sourceFiles.values()){
|
for(SourceFile sf : sourceFiles.values()){
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
}
|
}
|
||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
List<ClassOrInterface> 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<Pair> cons = new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
final ConstraintSet<Pair> cons = new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
@ -56,9 +70,9 @@ public class JavaTXCompiler {
|
|||||||
xConsSet.addAll(constraint);
|
xConsSet.addAll(constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(xConsSet);
|
//System.out.println(xConsSet);
|
||||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
System.out.println("RESULT: " + result);
|
//System.out.println("RESULT: " + result);
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
|
@ -24,13 +24,13 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
private List<Method> methods = new ArrayList<>();
|
private List<Method> methods = new ArrayList<>();
|
||||||
private GenericDeclarationList genericClassParameters;
|
private GenericDeclarationList genericClassParameters;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric superClass;
|
private RefType superClass;
|
||||||
protected boolean isInterface;
|
protected boolean isInterface;
|
||||||
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||||
RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
RefType superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
||||||
super(offset);
|
super(offset);
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -74,7 +74,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
return new RefType(name, params, offset);
|
return new RefType(name, params, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getSuperClass() {
|
public RefType getSuperClass() {
|
||||||
return superClass;
|
return superClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||||
System.out.println(eq);
|
|
||||||
/*
|
/*
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
*/
|
*/
|
||||||
@ -153,7 +152,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
||||||
.stream().map(x -> new HashSet<>(x))
|
.stream().map(x -> new HashSet<>(x))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
//System.out.println(result);
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
@ -162,14 +160,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// Flatten the cartesian product
|
// Flatten the cartesian product
|
||||||
Set<UnifyPair> eqPrime = new HashSet<>();
|
Set<UnifyPair> eqPrime = new HashSet<>();
|
||||||
setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
|
setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
|
||||||
System.out.println(eqPrime);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 5: Substitution
|
* Step 5: Substitution
|
||||||
*/
|
*/
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||||
System.out.println(eq);
|
|
||||||
System.out.println(eqPrimePrime);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
@ -450,7 +445,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
||||||
cs.add(thetaPrime);
|
cs.add(thetaPrime);
|
||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||||
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
|
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
|
||||||
|
17
test/javFiles/fc.jav
Normal file
17
test/javFiles/fc.jav
Normal file
@ -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);
|
||||||
|
}
|
@ -10,6 +10,6 @@ interface Klasse1{
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Klasse2{
|
interface Klasse2{
|
||||||
Klasse1 meth(Klasse1 p):
|
Klasse1 meth(Klasse1 p);
|
||||||
Klasse2 meth(Klasse2 p):
|
Klasse2 meth(Klasse2 p);
|
||||||
}
|
}
|
9
test/typeinference/FiniteClosureTest.java
Normal file
9
test/typeinference/FiniteClosureTest.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package typeinference;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class FiniteClosureTest extends JavaTXCompilerTest{
|
||||||
|
public FiniteClosureTest() {
|
||||||
|
this.fileToTest = new File(rootDirectory+"fc.jav");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user