diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 9a66543a..9f77ff89 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -1,13 +1,31 @@ package de.dhbwstuttgart.core; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import de.dhbwstuttgart.environment.CompilationEnvironment; 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.GenericsRegistry; import de.dhbwstuttgart.parser.scope.JavaClassName; -import de.dhbwstuttgart.parser.scope.JavaClassRegistry; +import de.dhbwstuttgart.strucTypes.Construct; +import de.dhbwstuttgart.strucTypes.InferredTypes; +import de.dhbwstuttgart.strucTypes.Solve; +import de.dhbwstuttgart.strucTypes.StrucTYPE; +import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; +import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; +import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; +import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException; +import de.dhbwstuttgart.strucTypes.model.SolvedClass; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; @@ -19,115 +37,140 @@ import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; - public class JavaTXCompiler { - final CompilationEnvironment environment; - public final Map sourceFiles = new HashMap<>(); + final CompilationEnvironment environment; + public final Map sourceFiles = new HashMap<>(); - public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { - this(Arrays.asList(sourceFile)); - } + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { + this(Arrays.asList(sourceFile)); + } - public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { - environment = new CompilationEnvironment(sources); - for (File s : sources) { - sourceFiles.put(s, parse(s)); - } - } + public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { + environment = new CompilationEnvironment(sources); + for (File s : sources) { + sourceFiles.put(s, parse(s)); + } + } - public ConstraintSet getConstraints() throws ClassNotFoundException { - List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); - for (SourceFile sf : sourceFiles.values()) { - allClasses.addAll(sf.getClasses()); - } - 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()) { - //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet - ClassOrInterface importedClass = ASTFactory.createClass( - ClassLoader.getSystemClassLoader().loadClass(name.toString())); - importedClasses.add(importedClass); - } - allClasses.addAll(importedClasses); + public ConstraintSet getConstraints() throws ClassNotFoundException { + List allClasses = new ArrayList<>();// environment.getAllAvailableClasses(); + for (SourceFile sf : sourceFiles.values()) { + allClasses.addAll(sf.getClasses()); + } + 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()) { + // TODO: Hier werden imports von eigenen (.jav) Klassen nicht + // beachtet + ClassOrInterface importedClass = ASTFactory + .createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())); + importedClasses.add(importedClass); + } + allClasses.addAll(importedClasses); - return new TYPE(sourceFiles.values(), allClasses).getConstraints(); - } + return new TYPE(sourceFiles.values(), allClasses).getConstraints(); + } - public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException { - List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); - for (SourceFile sf : sourceFiles.values()) { - allClasses.addAll(sf.getClasses()); - } - List importedClasses = new ArrayList<>(); - for (JavaClassName name : forSourceFile.getImports()) { - //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet - ClassOrInterface importedClass = ASTFactory.createClass( - ClassLoader.getSystemClassLoader().loadClass(name.toString())); - importedClasses.add(importedClass); - allClasses.addAll(importedClasses); - } - return allClasses; - } + public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException { + List allClasses = new ArrayList<>();// environment.getAllAvailableClasses(); + for (SourceFile sf : sourceFiles.values()) { + allClasses.addAll(sf.getClasses()); + } + List importedClasses = new ArrayList<>(); + for (JavaClassName name : forSourceFile.getImports()) { + // TODO: Hier werden imports von eigenen (.jav) Klassen nicht + // beachtet + ClassOrInterface importedClass = ASTFactory + .createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())); + importedClasses.add(importedClass); + allClasses.addAll(importedClasses); + } + return allClasses; + } - public List typeInference() throws ClassNotFoundException { - List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); - //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC - for(SourceFile sf : this.sourceFiles.values()) { - allClasses.addAll(getAvailableClasses(sf)); - allClasses.addAll(sf.getClasses()); - } + public List strucTypeInference() + throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException { + List solvedClasses = new ArrayList<>(); + for (SourceFile sourceFile : sourceFiles.values()) { + ClassOrInterface clsA = sourceFile.getClasses().get(0); + + StrucTYPE strucTYPE = new StrucTYPE(clsA); + ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints(); + InferredTypes inferredTypes = strucTYPE.getInferredTypes(); - final ConstraintSet cons = getConstraints(); + Construct construct = new Construct(strucTypeConstraints, inferredTypes); + List constructedInterfaces = construct.getConstructedInterfaces(); + Set subTypeConstraints = construct.getSubTypeConstraints(); + inferredTypes = construct.getInferredTypes(); - FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); - System.out.println(finiteClosure); - ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); + IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile)); + Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces); + SolvedClass solvedClass = solve.getSolvedClass(); + solvedClasses.add(solvedClass); + } + return solvedClasses; + } - TypeUnify unify = new TypeUnify(); - Set> results = new HashSet<>(); - for (List> xCons : unifyCons.cartesianProduct()) { - Set xConsSet = new HashSet<>(); - for (Constraint constraint : xCons) { - xConsSet.addAll(constraint); - } + public List typeInference() throws ClassNotFoundException { + List allClasses = new ArrayList<>();// environment.getAllAvailableClasses(); + // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins + // FC + for (SourceFile sf : this.sourceFiles.values()) { + allClasses.addAll(getAvailableClasses(sf)); + allClasses.addAll(sf.getClasses()); + } - System.out.println(xConsSet); - Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result.size()); - results.addAll(result); - } - return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); - } + final ConstraintSet cons = getConstraints(); - private Map generateTPHMap(ConstraintSet constraints) { - HashMap ret = new HashMap<>(); - constraints.map((Pair p) -> { - if (p.TA1 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); - } - if (p.TA2 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); - } - return null; - }); - return ret; - } + FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); + System.out.println(finiteClosure); + ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); - private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { - CompilationUnitContext tree = JavaTXParser.parse(sourceFile); - SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null)); - SourceFile ret = generator.convert(tree, environment.packageCrawler); - return ret; - } + TypeUnify unify = new TypeUnify(); + Set> results = new HashSet<>(); + for (List> xCons : unifyCons.cartesianProduct()) { + Set xConsSet = new HashSet<>(); + for (Constraint constraint : xCons) { + xConsSet.addAll(constraint); + } + + System.out.println(xConsSet); + Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result.size()); + results.addAll(result); + } + return results.stream() + .map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))) + .collect(Collectors.toList()); + } + + private Map generateTPHMap(ConstraintSet constraints) { + HashMap ret = new HashMap<>(); + constraints.map((Pair p) -> { + if (p.TA1 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); + } + if (p.TA2 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); + } + return null; + }); + return ret; + } + + private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { + CompilationUnitContext tree = JavaTXParser.parse(sourceFile); + SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), + new GenericsRegistry(null)); + SourceFile ret = generator.convert(tree, environment.packageCrawler); + return ret; + } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes/Solve.java b/src/de/dhbwstuttgart/strucTypes/Solve.java index 232b53ec..3cfbb4cb 100644 --- a/src/de/dhbwstuttgart/strucTypes/Solve.java +++ b/src/de/dhbwstuttgart/strucTypes/Solve.java @@ -10,9 +10,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException; +import de.dhbwstuttgart.strucTypes.model.SolvedClass; import de.dhbwstuttgart.strucTypes.visitor.InferTypes; import de.dhbwstuttgart.strucTypes.visitor.TypeExtract; import de.dhbwstuttgart.strucTypes.visitor.TypeVar; @@ -32,16 +32,18 @@ public class Solve { private IFiniteClosure fc; private InferredTypes inferredTypes = new InferredTypes(); private ClassOrInterface clsA; + private List generatedInterfaces = new ArrayList<>(); public Solve(Set constraints, ClassOrInterface clsA, IFiniteClosure fc, - InferredTypes inferredTypes) { + InferredTypes inferredTypes, List generatedInterfaces) { this.constraints = constraints; this.fc = fc; this.inferredTypes = inferredTypes; this.clsA = clsA; + this.generatedInterfaces = generatedInterfaces; } - public ClassOrInterfaceWithConstraints getSolvedClass() throws InconsistentConstraintsException { + public SolvedClass getSolvedClass() throws InconsistentConstraintsException { Set constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair) .collect(Collectors.toSet()); StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc); @@ -99,8 +101,8 @@ public class Solve { if (!consistent(cs)) { throw new InconsistentConstraintsException(); } - return new ClassOrInterfaceWithConstraints(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew, - this.constraints); + return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew, + this.constraints, this.generatedInterfaces); } diff --git a/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java b/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java index 0f00a25a..f45cb835 100644 --- a/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java +++ b/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java @@ -4,7 +4,6 @@ import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Method; -import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.statement.Expression; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.type.RefType; @@ -13,21 +12,19 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class StrucTYPE extends DefaultASTVisitor { - private SourceFile sourceFile; + private ClassOrInterface clsA; private ConstraintsSet constraintsSet = new ConstraintsSet(); private InferredTypes inferredTypes = new InferredTypes(); - public StrucTYPE(SourceFile sourceFile) { - this.sourceFile = sourceFile; + public StrucTYPE(ClassOrInterface clsA) { + this.clsA = clsA; } public ConstraintsSet getConstraints() { - for (ClassOrInterface cls : this.sourceFile.getClasses()) { - TYPEExpr typeExpr = new TYPEExpr(); - cls.accept(typeExpr); - cls.getMethods().forEach(m -> m.accept(this)); - this.evaluateTypeExpr(typeExpr); - } + TYPEExpr typeExpr = new TYPEExpr(); + this.clsA.accept(typeExpr); + this.clsA.getMethods().forEach(m -> m.accept(this)); + this.evaluateTypeExpr(typeExpr); return this.constraintsSet; } @@ -39,10 +36,10 @@ public class StrucTYPE extends DefaultASTVisitor { public void visit(Method method) { // Es gibt nur ein Return Statement Expression retexpr = ((Return) method.block.statements.get(0)).retexpr; - + RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType(); RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType(); - + // ordnet dem Methodentyp den Returntyp zu [sigma(Mt)] if (methodReturnType instanceof TypePlaceholder) { this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType); @@ -55,7 +52,7 @@ public class StrucTYPE extends DefaultASTVisitor { private void evaluateTypeExpr(TYPEExpr typeExpr) { this.inferredTypes.putAll(typeExpr.getInferredTypes()); this.inferredTypes.resolveTransitiveTypes(); - + ConstraintsSet constraints = typeExpr.getConstraints(); constraints.inferTypes(this.inferredTypes); this.constraintsSet.addConstraintsSet(constraints); diff --git a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraintsFactory.java b/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraintsFactory.java deleted file mode 100644 index a12c2a19..00000000 --- a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraintsFactory.java +++ /dev/null @@ -1,83 +0,0 @@ -package de.dhbwstuttgart.strucTypes.classorinterface; - -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.antlr.v4.runtime.Token; - -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.parser.scope.JavaClassName; -import de.dhbwstuttgart.strucTypes.InferredTypes; -import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.Constructor; -import de.dhbwstuttgart.syntaxtree.Field; -import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; -import de.dhbwstuttgart.syntaxtree.GenericTypeVar; -import de.dhbwstuttgart.syntaxtree.Method; -import de.dhbwstuttgart.syntaxtree.ParameterList; -import de.dhbwstuttgart.syntaxtree.statement.Block; -import de.dhbwstuttgart.syntaxtree.type.RefType; - -public class ClassOrInterfaceWithConstraintsFactory { - - public ClassOrInterfaceWithConstraintsFactory() { - } - - public static ClassOrInterfaceWithConstraints inferTypes(ClassOrInterface cls, Set constraints, InferredTypes inferredTypes) { - int modifiers = Modifier.PUBLIC; - JavaClassName name = cls.getClassName(); - List fielddecl = inferFields(cls.getFieldDecl(), inferredTypes); - List methods = inferMethods(cls.getMethods(), inferredTypes); - List constructors = inferConstructors(cls.getConstructors(), inferredTypes); - Boolean isInterface = false; - List implementedInterfaces = inferInterfaces((List) cls.getSuperInterfaces(), inferredTypes); - RefType superClass = inferSuperClass(cls.getSuperClass(), inferredTypes); - Token offset = cls.getOffset(); - GenericDeclarationList genericClassParameters = inferGenerics(cls.getGenerics(), inferredTypes); - return new ClassOrInterfaceWithConstraints(modifiers, name, fielddecl, methods, constructors, - genericClassParameters, superClass, isInterface, implementedInterfaces, offset, constraints); - } - - public static List inferFields(List fields, InferredTypes inferredTypes){ - List result = new ArrayList<>(); - for (Field field : fields) { - result.add(new Field(field.getName(), inferredTypes.infer(field.getType()), field.modifier, field.getOffset())); - } - return result; - } - - public static List inferMethods(List methods, InferredTypes inferredTypes){ - List result = new ArrayList<>(); - for (Method method : methods) { - ParameterList parameterList = null; - Block block = null; - GenericDeclarationList gtvDeclarations = null; - result.add(new Method(method.modifier, method.name, inferredTypes.infer(method.getReturnType()), parameterList, block, gtvDeclarations, method.getOffset())); - } - return result; - } - - public static List inferConstructors(List constructors, InferredTypes inferredTypes){ - List result = new ArrayList<>(); - return result; - } - - public static List inferInterfaces(List interfaces, InferredTypes inferredTypes){ - List result = new ArrayList<>(); - return result; - } - - public static RefType inferSuperClass(RefType superclass, InferredTypes inferredTypes){ - return null; - } - - public static GenericDeclarationList inferGenerics(GenericDeclarationList generics, InferredTypes inferredTypes){ - List values = new ArrayList<>(); - return new GenericDeclarationList(values, new NullToken()); - } - - -} diff --git a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceFactory.java b/src/de/dhbwstuttgart/strucTypes/model/ClassOrInterfaceFactory.java similarity index 85% rename from src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceFactory.java rename to src/de/dhbwstuttgart/strucTypes/model/ClassOrInterfaceFactory.java index 9d6bb562..be0a4a1b 100644 --- a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceFactory.java +++ b/src/de/dhbwstuttgart/strucTypes/model/ClassOrInterfaceFactory.java @@ -1,4 +1,4 @@ -package de.dhbwstuttgart.strucTypes.classorinterface; +package de.dhbwstuttgart.strucTypes.model; import java.util.Optional; @@ -13,7 +13,6 @@ public class ClassOrInterfaceFactory { try { return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()))); } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } return Optional.empty(); diff --git a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraints.java b/src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java similarity index 62% rename from src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraints.java rename to src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java index 2dfb09b6..5e3ce396 100644 --- a/src/de/dhbwstuttgart/strucTypes/classorinterface/ClassOrInterfaceWithConstraints.java +++ b/src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java @@ -1,5 +1,6 @@ -package de.dhbwstuttgart.strucTypes.classorinterface; +package de.dhbwstuttgart.strucTypes.model; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -15,36 +16,43 @@ import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.type.RefType; -public class ClassOrInterfaceWithConstraints extends ClassOrInterface { +public class SolvedClass extends ClassOrInterface { private Set constraints = new HashSet<>(); + private List generatedInterfaces = new ArrayList<>(); - public ClassOrInterfaceWithConstraints(int modifiers, JavaClassName name, List fielddecl, + public SolvedClass(int modifiers, JavaClassName name, List fielddecl, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset, - Set constraints) { + Set constraints, List generatedInterfaces) { super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); this.constraints = constraints; + this.generatedInterfaces = generatedInterfaces; } - public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, Set constraints) { + public SolvedClass(ClassOrInterface classOrInterface, Set constraints, + List generatedInterfaces) { this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(), classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(), classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(), - classOrInterface.getOffset(), constraints); + classOrInterface.getOffset(), constraints, generatedInterfaces); } - public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, GenericDeclarationList generics, - Set constraints) { + public SolvedClass(ClassOrInterface classOrInterface, GenericDeclarationList generics, + Set constraints, List generatedInterfaces) { this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(), classOrInterface.getMethods(), classOrInterface.getConstructors(), generics, classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(), - classOrInterface.getOffset(), constraints); + classOrInterface.getOffset(), constraints, generatedInterfaces); } public Set getConstraints() { return this.constraints; } + public List getGeneratedInterfaces() { + return generatedInterfaces; + } + } diff --git a/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java b/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java index fe4071d1..95783db4 100644 --- a/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java +++ b/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java @@ -10,7 +10,6 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.ArgumentList; import de.dhbwstuttgart.syntaxtree.statement.Assign; import de.dhbwstuttgart.syntaxtree.statement.AssignToField; diff --git a/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java b/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java index 03de7394..23d57730 100644 --- a/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java +++ b/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java @@ -7,8 +7,8 @@ import java.util.Optional; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.strucTypes.InferredTypes; -import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceFactory; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; +import de.dhbwstuttgart.strucTypes.model.ClassOrInterfaceFactory; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.Field; diff --git a/test/strucType/TestConstruct.java b/test/strucType/TestConstruct.java index 512805d6..c7110ab2 100644 --- a/test/strucType/TestConstruct.java +++ b/test/strucType/TestConstruct.java @@ -40,8 +40,9 @@ public class TestConstruct { SourceFile sourceFile = compiler.sourceFiles.get(f); // Print SourceFile Infos sourceFile.accept(new SyntaxTreePrinter()); + ClassOrInterface clsA = sourceFile.getClasses().get(0); - StrucTYPE strucTYPE = new StrucTYPE(sourceFile); + StrucTYPE strucTYPE = new StrucTYPE(clsA); final ConstraintsSet constraints = strucTYPE.getConstraints(); final InferredTypes inferredTypesType = strucTYPE.getInferredTypes(); diff --git a/test/strucType/TestInferTypesVisitor.java b/test/strucType/TestInferTypesVisitor.java index ff92d1d0..414b4bd4 100644 --- a/test/strucType/TestInferTypesVisitor.java +++ b/test/strucType/TestInferTypesVisitor.java @@ -70,8 +70,9 @@ public class TestInferTypesVisitor { // Print SourceFile Infos SyntaxTreePrinter syntaxTreePrinter = new SyntaxTreePrinter(); sourceFile.accept(syntaxTreePrinter); + ClassOrInterface clsA = sourceFile.getClasses().get(0); - StrucTYPE strucTYPE = new StrucTYPE(sourceFile); + StrucTYPE strucTYPE = new StrucTYPE(clsA); final ConstraintsSet constraints = strucTYPE.getConstraints(); final InferredTypes inferredTypesType = strucTYPE.getInferredTypes(); diff --git a/test/strucType/TestPaperExample.java b/test/strucType/TestPaperExample.java index e50d4d75..f8b200b2 100644 --- a/test/strucType/TestPaperExample.java +++ b/test/strucType/TestPaperExample.java @@ -11,11 +11,11 @@ import de.dhbwstuttgart.strucTypes.Construct; import de.dhbwstuttgart.strucTypes.InferredTypes; import de.dhbwstuttgart.strucTypes.Solve; import de.dhbwstuttgart.strucTypes.StrucTYPE; -import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException; +import de.dhbwstuttgart.strucTypes.model.SolvedClass; import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints; import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes; import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; @@ -32,11 +32,12 @@ public class TestPaperExample { public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException { ArrayList files = new ArrayList<>(); - files.add(new File(rootDirectory + "javFiles/testPaperExample.jav")); - trans(files); - files.clear(); -// files.add(new File(rootDirectory + "constructed/A.java")); -// files.add(new File(rootDirectory + "typedtestclasses/MyInteger.java")); + files.add(new File(rootDirectory + "javFiles/testPaperExample.jav")); + trans(files); + files.clear(); + // files.add(new File(rootDirectory + "constructed/A.java")); + // files.add(new File(rootDirectory + + // "typedtestclasses/MyInteger.java")); files.add(new File(rootDirectory + "javFiles/testMain.jav")); trans(files); } @@ -53,9 +54,10 @@ public class TestPaperExample { sourceFile.accept(syntaxtreeprinter); // List typedClasses = // compiler.sourceFiles.values().stream().flatMap(sf->sf.getClasses().stream()).collect(Collectors.toList()); + ClassOrInterface clsA = sourceFile.getClasses().get(0); System.out.println("\n--StrucTYPE--"); - StrucTYPE strucTYPE = new StrucTYPE(sourceFile); + StrucTYPE strucTYPE = new StrucTYPE(clsA); final ConstraintsSet constraints = strucTYPE.getConstraints(); final InferredTypes inferredTypesType = strucTYPE.getInferredTypes(); @@ -81,9 +83,9 @@ public class TestPaperExample { FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses); System.out.println("\nFinite Closure:"); System.out.println(finiteClosure); - Solve solve = new Solve(subTypeConstraints, sourceFile.getClasses().get(0), finiteClosure, - inferredTypesConstruct); - ClassOrInterfaceWithConstraints solvedClass = solve.getSolvedClass(); + Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct, + constructedInterfaces); + SolvedClass solvedClass = solve.getSolvedClass(); System.out.println("\nSolved Class:"); solvedClass.accept(syntaxtreeprinter); System.out.println("\nRemaining Constraints:"); diff --git a/test/strucType/TestSolve.java b/test/strucType/TestSolve.java index e59f8eb8..c90b3f80 100644 --- a/test/strucType/TestSolve.java +++ b/test/strucType/TestSolve.java @@ -11,11 +11,11 @@ import de.dhbwstuttgart.strucTypes.Construct; import de.dhbwstuttgart.strucTypes.InferredTypes; import de.dhbwstuttgart.strucTypes.Solve; import de.dhbwstuttgart.strucTypes.StrucTYPE; -import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException; +import de.dhbwstuttgart.strucTypes.model.SolvedClass; import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints; import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes; import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; @@ -48,7 +48,8 @@ public class TestSolve { sourceFile.accept(syntaxtreeprinter); System.out.println("\n--StrucTYPE--"); - StrucTYPE strucTYPE = new StrucTYPE(sourceFile); + ClassOrInterface clsA = sourceFile.getClasses().get(0); + StrucTYPE strucTYPE = new StrucTYPE(clsA); final ConstraintsSet constraints = strucTYPE.getConstraints(); final InferredTypes inferredTypesType = strucTYPE.getInferredTypes(); @@ -75,8 +76,8 @@ public class TestSolve { FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses); // System.out.println("\nFinite Closure:"); // System.out.println(finiteClosure); - Solve solve = new Solve(subTypeConstraints, sourceFile.getClasses().get(0), finiteClosure, inferredTypesConstruct); - ClassOrInterfaceWithConstraints solvedClass = solve.getSolvedClass(); + Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct, constructedInterfaces); + SolvedClass solvedClass = solve.getSolvedClass(); System.out.println("\nSolved Class:"); solvedClass.accept(syntaxtreeprinter); System.out.println("\nRemaining Constraints:"); diff --git a/test/strucType/TestStrucType.java b/test/strucType/TestStrucType.java index ae41b796..a929fa64 100644 --- a/test/strucType/TestStrucType.java +++ b/test/strucType/TestStrucType.java @@ -11,6 +11,7 @@ import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints; import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes; import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; public class TestStrucType { @@ -32,17 +33,18 @@ public class TestStrucType { String name = f.getName(); System.out.println("Filename: " + name); SourceFile sourceFile = compiler.sourceFiles.get(f); - //Print SourceFile Infos + // Print SourceFile Infos sourceFile.accept(new SyntaxTreePrinter()); - - StrucTYPE strucTYPE = new StrucTYPE(sourceFile); - + ClassOrInterface clsA = sourceFile.getClasses().get(0); + + StrucTYPE strucTYPE = new StrucTYPE(clsA); + ConstraintsSet constraints = strucTYPE.getConstraints(); printConstraints.print(constraints); - + InferredTypes inferredTypes = strucTYPE.getInferredTypes(); PrintInferredTypes.print(inferredTypes); - + System.out.println("____________________________________________________________________________"); } } diff --git a/test/strucType/constructed/CO.java b/test/strucType/constructed/CO.java deleted file mode 100644 index 974c7e9b..00000000 --- a/test/strucType/constructed/CO.java +++ /dev/null @@ -1,6 +0,0 @@ -package strucType.constructed; - -public abstract class CO { - - public OX f; -} \ No newline at end of file diff --git a/test/strucType/constructed/DE.java b/test/strucType/constructed/DE.java deleted file mode 100644 index 39db1813..00000000 --- a/test/strucType/constructed/DE.java +++ /dev/null @@ -1,7 +0,0 @@ -package strucType.constructed; - -public abstract class DE { - - public abstract NG mF(NI x, NJ y); - -} \ No newline at end of file diff --git a/test/strucType/constructed/DG.java b/test/strucType/constructed/DG.java deleted file mode 100644 index 44db0371..00000000 --- a/test/strucType/constructed/DG.java +++ /dev/null @@ -1,8 +0,0 @@ -package strucType.constructed; - -public abstract class DG { - - public NL g; - public abstract NM m2(NO x); - -} \ No newline at end of file diff --git a/test/strucType/constructed/EK.java b/test/strucType/constructed/EK.java deleted file mode 100644 index 5ed0c930..00000000 --- a/test/strucType/constructed/EK.java +++ /dev/null @@ -1,7 +0,0 @@ -package strucType.constructed; - -public abstract class EK { - - public abstract OA getA(); - -} \ No newline at end of file diff --git a/test/strucType/constructed/FF.java b/test/strucType/constructed/FF.java deleted file mode 100644 index 5b8d0062..00000000 --- a/test/strucType/constructed/FF.java +++ /dev/null @@ -1,7 +0,0 @@ -package strucType.constructed; - -public interface FF { - - public PP sub(PR x); - -} \ No newline at end of file diff --git a/test/strucType/constructed/FI.java b/test/strucType/constructed/FI.java deleted file mode 100644 index e9b8bc2a..00000000 --- a/test/strucType/constructed/FI.java +++ /dev/null @@ -1,7 +0,0 @@ -package strucType.constructed; - -public interface FI { - - public PL add(PN x); - -} \ No newline at end of file