updated project structure. Implemented trans.
This commit is contained in:
parent
f44f08b895
commit
24f93f0bcb
@ -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<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> 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<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
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()) {
|
||||
//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<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
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()) {
|
||||
// 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<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> 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<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> 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<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> 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<SolvedClass> strucTypeInference()
|
||||
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||
List<SolvedClass> solvedClasses = new ArrayList<>();
|
||||
for (SourceFile sourceFile : sourceFiles.values()) {
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
|
||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
inferredTypes = construct.getInferredTypes();
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> 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());
|
||||
}
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> 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());
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> 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;
|
||||
}
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
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;
|
||||
}
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> 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<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||
|
||||
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
||||
InferredTypes inferredTypes) {
|
||||
InferredTypes inferredTypes, List<ClassOrInterface> 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<UnifyPair> 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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<SubTypeConstraint> constraints, InferredTypes inferredTypes) {
|
||||
int modifiers = Modifier.PUBLIC;
|
||||
JavaClassName name = cls.getClassName();
|
||||
List<Field> fielddecl = inferFields(cls.getFieldDecl(), inferredTypes);
|
||||
List<Method> methods = inferMethods(cls.getMethods(), inferredTypes);
|
||||
List<Constructor> constructors = inferConstructors(cls.getConstructors(), inferredTypes);
|
||||
Boolean isInterface = false;
|
||||
List<RefType> implementedInterfaces = inferInterfaces((List<RefType>) 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<Field> inferFields(List<Field> fields, InferredTypes inferredTypes){
|
||||
List<Field> 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<Method> inferMethods(List<Method> methods, InferredTypes inferredTypes){
|
||||
List<Method> 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<Constructor> inferConstructors(List<Constructor> constructors, InferredTypes inferredTypes){
|
||||
List<Constructor> result = new ArrayList<>();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<RefType> inferInterfaces(List<RefType> interfaces, InferredTypes inferredTypes){
|
||||
List<RefType> result = new ArrayList<>();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static RefType inferSuperClass(RefType superclass, InferredTypes inferredTypes){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GenericDeclarationList inferGenerics(GenericDeclarationList generics, InferredTypes inferredTypes){
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
return new GenericDeclarationList(values, new NullToken());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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();
|
@ -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<SubTypeConstraint> constraints = new HashSet<>();
|
||||
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||
|
||||
public ClassOrInterfaceWithConstraints(int modifiers, JavaClassName name, List<Field> fielddecl,
|
||||
public SolvedClass(int modifiers, JavaClassName name, List<Field> fielddecl,
|
||||
List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset,
|
||||
Set<SubTypeConstraint> constraints) {
|
||||
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
|
||||
super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface,
|
||||
implementedInterfaces, offset);
|
||||
this.constraints = constraints;
|
||||
this.generatedInterfaces = generatedInterfaces;
|
||||
}
|
||||
|
||||
public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, Set<SubTypeConstraint> constraints) {
|
||||
public SolvedClass(ClassOrInterface classOrInterface, Set<SubTypeConstraint> constraints,
|
||||
List<ClassOrInterface> 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<SubTypeConstraint> constraints) {
|
||||
public SolvedClass(ClassOrInterface classOrInterface, GenericDeclarationList generics,
|
||||
Set<SubTypeConstraint> constraints, List<ClassOrInterface> 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<SubTypeConstraint> getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getGeneratedInterfaces() {
|
||||
return generatedInterfaces;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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<File> 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<ClassOrInterface> 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:");
|
||||
|
@ -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:");
|
||||
|
@ -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,10 +33,11 @@ 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());
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
printConstraints.print(constraints);
|
||||
|
@ -1,6 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class CO<OX> {
|
||||
|
||||
public OX f;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class DE<NG, NI, NJ> {
|
||||
|
||||
public abstract NG mF(NI x, NJ y);
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class DG<NL, NM, NO> {
|
||||
|
||||
public NL g;
|
||||
public abstract NM m2(NO x);
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class EK<OA> {
|
||||
|
||||
public abstract OA getA();
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface FF<PP, PR> {
|
||||
|
||||
public PP sub(PR x);
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface FI<PL, PN> {
|
||||
|
||||
public PL add(PN x);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user