updated project structure. Implemented trans.
This commit is contained in:
parent
f44f08b895
commit
24f93f0bcb
@ -1,13 +1,31 @@
|
|||||||
package de.dhbwstuttgart.core;
|
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.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
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.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
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.result.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
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.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
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 {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||||
environment = new CompilationEnvironment(sources);
|
environment = new CompilationEnvironment(sources);
|
||||||
for (File s : sources) {
|
for (File s : sources) {
|
||||||
sourceFiles.put(s, parse(s));
|
sourceFiles.put(s, parse(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
public ConstraintSet<Pair> getConstraints() 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());
|
||||||
}
|
}
|
||||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||||
for (File forSourceFile : sourceFiles.keySet())
|
// FC
|
||||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
for (File forSourceFile : sourceFiles.keySet())
|
||||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
// beachtet
|
||||||
importedClasses.add(importedClass);
|
ClassOrInterface importedClass = ASTFactory
|
||||||
}
|
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
allClasses.addAll(importedClasses);
|
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 {
|
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) 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());
|
||||||
}
|
}
|
||||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||||
for (JavaClassName name : forSourceFile.getImports()) {
|
for (JavaClassName name : forSourceFile.getImports()) {
|
||||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
// beachtet
|
||||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
ClassOrInterface importedClass = ASTFactory
|
||||||
importedClasses.add(importedClass);
|
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
allClasses.addAll(importedClasses);
|
importedClasses.add(importedClass);
|
||||||
}
|
allClasses.addAll(importedClasses);
|
||||||
return allClasses;
|
}
|
||||||
}
|
return allClasses;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
public List<SolvedClass> strucTypeInference()
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
List<SolvedClass> solvedClasses = new ArrayList<>();
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
for (SourceFile sourceFile : sourceFiles.values()) {
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
}
|
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||||
|
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
|
||||||
|
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||||
|
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||||
|
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||||
|
inferredTypes = construct.getInferredTypes();
|
||||||
|
|
||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile));
|
||||||
System.out.println(finiteClosure);
|
Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
SolvedClass solvedClass = solve.getSolvedClass();
|
||||||
|
solvedClasses.add(solvedClass);
|
||||||
|
}
|
||||||
|
return solvedClasses;
|
||||||
|
}
|
||||||
|
|
||||||
TypeUnify unify = new TypeUnify();
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
// FC
|
||||||
for (Constraint<UnifyPair> constraint : xCons) {
|
for (SourceFile sf : this.sourceFiles.values()) {
|
||||||
xConsSet.addAll(constraint);
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
}
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println(xConsSet);
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
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) {
|
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
System.out.println(finiteClosure);
|
||||||
constraints.map((Pair p) -> {
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
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 {
|
TypeUnify unify = new TypeUnify();
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||||
return ret;
|
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 java.util.stream.Stream;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints;
|
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||||
|
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
|
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
|
||||||
import de.dhbwstuttgart.strucTypes.visitor.TypeVar;
|
import de.dhbwstuttgart.strucTypes.visitor.TypeVar;
|
||||||
@ -32,16 +32,18 @@ public class Solve {
|
|||||||
private IFiniteClosure fc;
|
private IFiniteClosure fc;
|
||||||
private InferredTypes inferredTypes = new InferredTypes();
|
private InferredTypes inferredTypes = new InferredTypes();
|
||||||
private ClassOrInterface clsA;
|
private ClassOrInterface clsA;
|
||||||
|
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||||
|
|
||||||
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
||||||
InferredTypes inferredTypes) {
|
InferredTypes inferredTypes, List<ClassOrInterface> generatedInterfaces) {
|
||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
this.fc = fc;
|
this.fc = fc;
|
||||||
this.inferredTypes = inferredTypes;
|
this.inferredTypes = inferredTypes;
|
||||||
this.clsA = clsA;
|
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)
|
Set<UnifyPair> constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
|
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
|
||||||
@ -99,8 +101,8 @@ public class Solve {
|
|||||||
if (!consistent(cs)) {
|
if (!consistent(cs)) {
|
||||||
throw new InconsistentConstraintsException();
|
throw new InconsistentConstraintsException();
|
||||||
}
|
}
|
||||||
return new ClassOrInterfaceWithConstraints(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
|
return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
|
||||||
this.constraints);
|
this.constraints, this.generatedInterfaces);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
|||||||
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@ -13,21 +12,19 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
|
|
||||||
public class StrucTYPE extends DefaultASTVisitor {
|
public class StrucTYPE extends DefaultASTVisitor {
|
||||||
|
|
||||||
private SourceFile sourceFile;
|
private ClassOrInterface clsA;
|
||||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||||
private InferredTypes inferredTypes = new InferredTypes();
|
private InferredTypes inferredTypes = new InferredTypes();
|
||||||
|
|
||||||
public StrucTYPE(SourceFile sourceFile) {
|
public StrucTYPE(ClassOrInterface clsA) {
|
||||||
this.sourceFile = sourceFile;
|
this.clsA = clsA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintsSet getConstraints() {
|
public ConstraintsSet getConstraints() {
|
||||||
for (ClassOrInterface cls : this.sourceFile.getClasses()) {
|
TYPEExpr typeExpr = new TYPEExpr();
|
||||||
TYPEExpr typeExpr = new TYPEExpr();
|
this.clsA.accept(typeExpr);
|
||||||
cls.accept(typeExpr);
|
this.clsA.getMethods().forEach(m -> m.accept(this));
|
||||||
cls.getMethods().forEach(m -> m.accept(this));
|
this.evaluateTypeExpr(typeExpr);
|
||||||
this.evaluateTypeExpr(typeExpr);
|
|
||||||
}
|
|
||||||
return this.constraintsSet;
|
return this.constraintsSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +36,10 @@ public class StrucTYPE extends DefaultASTVisitor {
|
|||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
// Es gibt nur ein Return Statement
|
// Es gibt nur ein Return Statement
|
||||||
Expression retexpr = ((Return) method.block.statements.get(0)).retexpr;
|
Expression retexpr = ((Return) method.block.statements.get(0)).retexpr;
|
||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType();
|
RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType();
|
RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType();
|
||||||
|
|
||||||
// ordnet dem Methodentyp den Returntyp zu [sigma(Mt)]
|
// ordnet dem Methodentyp den Returntyp zu [sigma(Mt)]
|
||||||
if (methodReturnType instanceof TypePlaceholder) {
|
if (methodReturnType instanceof TypePlaceholder) {
|
||||||
this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType);
|
this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType);
|
||||||
@ -55,7 +52,7 @@ public class StrucTYPE extends DefaultASTVisitor {
|
|||||||
private void evaluateTypeExpr(TYPEExpr typeExpr) {
|
private void evaluateTypeExpr(TYPEExpr typeExpr) {
|
||||||
this.inferredTypes.putAll(typeExpr.getInferredTypes());
|
this.inferredTypes.putAll(typeExpr.getInferredTypes());
|
||||||
this.inferredTypes.resolveTransitiveTypes();
|
this.inferredTypes.resolveTransitiveTypes();
|
||||||
|
|
||||||
ConstraintsSet constraints = typeExpr.getConstraints();
|
ConstraintsSet constraints = typeExpr.getConstraints();
|
||||||
constraints.inferTypes(this.inferredTypes);
|
constraints.inferTypes(this.inferredTypes);
|
||||||
this.constraintsSet.addConstraintsSet(constraints);
|
this.constraintsSet.addConstraintsSet(constraints);
|
||||||
|
@ -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;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -13,7 +13,6 @@ public class ClassOrInterfaceFactory {
|
|||||||
try {
|
try {
|
||||||
return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())));
|
return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -15,36 +16,43 @@ import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
|
||||||
public class ClassOrInterfaceWithConstraints extends ClassOrInterface {
|
public class SolvedClass extends ClassOrInterface {
|
||||||
|
|
||||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
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,
|
List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset,
|
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,
|
super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface,
|
||||||
implementedInterfaces, offset);
|
implementedInterfaces, offset);
|
||||||
this.constraints = constraints;
|
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(),
|
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(),
|
classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(),
|
||||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||||
classOrInterface.getOffset(), constraints);
|
classOrInterface.getOffset(), constraints, generatedInterfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, GenericDeclarationList generics,
|
public SolvedClass(ClassOrInterface classOrInterface, GenericDeclarationList generics,
|
||||||
Set<SubTypeConstraint> constraints) {
|
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
|
||||||
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), generics,
|
classOrInterface.getMethods(), classOrInterface.getConstructors(), generics,
|
||||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||||
classOrInterface.getOffset(), constraints);
|
classOrInterface.getOffset(), constraints, generatedInterfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SubTypeConstraint> getConstraints() {
|
public Set<SubTypeConstraint> getConstraints() {
|
||||||
return this.constraints;
|
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.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||||
|
@ -7,8 +7,8 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceFactory;
|
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||||
|
import de.dhbwstuttgart.strucTypes.model.ClassOrInterfaceFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
@ -40,8 +40,9 @@ public class TestConstruct {
|
|||||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||||
// Print SourceFile Infos
|
// Print SourceFile Infos
|
||||||
sourceFile.accept(new SyntaxTreePrinter());
|
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 ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||||
|
@ -70,8 +70,9 @@ public class TestInferTypesVisitor {
|
|||||||
// Print SourceFile Infos
|
// Print SourceFile Infos
|
||||||
SyntaxTreePrinter syntaxTreePrinter = new SyntaxTreePrinter();
|
SyntaxTreePrinter syntaxTreePrinter = new SyntaxTreePrinter();
|
||||||
sourceFile.accept(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 ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||||
|
@ -11,11 +11,11 @@ import de.dhbwstuttgart.strucTypes.Construct;
|
|||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.Solve;
|
import de.dhbwstuttgart.strucTypes.Solve;
|
||||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||||
import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints;
|
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||||
|
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||||
@ -32,11 +32,12 @@ public class TestPaperExample {
|
|||||||
public void test()
|
public void test()
|
||||||
throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||||
ArrayList<File> files = new ArrayList<>();
|
ArrayList<File> files = new ArrayList<>();
|
||||||
files.add(new File(rootDirectory + "javFiles/testPaperExample.jav"));
|
files.add(new File(rootDirectory + "javFiles/testPaperExample.jav"));
|
||||||
trans(files);
|
trans(files);
|
||||||
files.clear();
|
files.clear();
|
||||||
// files.add(new File(rootDirectory + "constructed/A.java"));
|
// files.add(new File(rootDirectory + "constructed/A.java"));
|
||||||
// files.add(new File(rootDirectory + "typedtestclasses/MyInteger.java"));
|
// files.add(new File(rootDirectory +
|
||||||
|
// "typedtestclasses/MyInteger.java"));
|
||||||
files.add(new File(rootDirectory + "javFiles/testMain.jav"));
|
files.add(new File(rootDirectory + "javFiles/testMain.jav"));
|
||||||
trans(files);
|
trans(files);
|
||||||
}
|
}
|
||||||
@ -53,9 +54,10 @@ public class TestPaperExample {
|
|||||||
sourceFile.accept(syntaxtreeprinter);
|
sourceFile.accept(syntaxtreeprinter);
|
||||||
// List<ClassOrInterface> typedClasses =
|
// List<ClassOrInterface> typedClasses =
|
||||||
// compiler.sourceFiles.values().stream().flatMap(sf->sf.getClasses().stream()).collect(Collectors.toList());
|
// compiler.sourceFiles.values().stream().flatMap(sf->sf.getClasses().stream()).collect(Collectors.toList());
|
||||||
|
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||||
|
|
||||||
System.out.println("\n--StrucTYPE--");
|
System.out.println("\n--StrucTYPE--");
|
||||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||||
|
|
||||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||||
@ -81,9 +83,9 @@ public class TestPaperExample {
|
|||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
||||||
System.out.println("\nFinite Closure:");
|
System.out.println("\nFinite Closure:");
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
Solve solve = new Solve(subTypeConstraints, sourceFile.getClasses().get(0), finiteClosure,
|
Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct,
|
||||||
inferredTypesConstruct);
|
constructedInterfaces);
|
||||||
ClassOrInterfaceWithConstraints solvedClass = solve.getSolvedClass();
|
SolvedClass solvedClass = solve.getSolvedClass();
|
||||||
System.out.println("\nSolved Class:");
|
System.out.println("\nSolved Class:");
|
||||||
solvedClass.accept(syntaxtreeprinter);
|
solvedClass.accept(syntaxtreeprinter);
|
||||||
System.out.println("\nRemaining Constraints:");
|
System.out.println("\nRemaining Constraints:");
|
||||||
|
@ -11,11 +11,11 @@ import de.dhbwstuttgart.strucTypes.Construct;
|
|||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.Solve;
|
import de.dhbwstuttgart.strucTypes.Solve;
|
||||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||||
import de.dhbwstuttgart.strucTypes.classorinterface.ClassOrInterfaceWithConstraints;
|
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||||
|
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||||
@ -48,7 +48,8 @@ public class TestSolve {
|
|||||||
sourceFile.accept(syntaxtreeprinter);
|
sourceFile.accept(syntaxtreeprinter);
|
||||||
|
|
||||||
System.out.println("\n--StrucTYPE--");
|
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 ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||||
@ -75,8 +76,8 @@ public class TestSolve {
|
|||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
||||||
// System.out.println("\nFinite Closure:");
|
// System.out.println("\nFinite Closure:");
|
||||||
// System.out.println(finiteClosure);
|
// System.out.println(finiteClosure);
|
||||||
Solve solve = new Solve(subTypeConstraints, sourceFile.getClasses().get(0), finiteClosure, inferredTypesConstruct);
|
Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct, constructedInterfaces);
|
||||||
ClassOrInterfaceWithConstraints solvedClass = solve.getSolvedClass();
|
SolvedClass solvedClass = solve.getSolvedClass();
|
||||||
System.out.println("\nSolved Class:");
|
System.out.println("\nSolved Class:");
|
||||||
solvedClass.accept(syntaxtreeprinter);
|
solvedClass.accept(syntaxtreeprinter);
|
||||||
System.out.println("\nRemaining Constraints:");
|
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.PrintConstraints;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
|
||||||
public class TestStrucType {
|
public class TestStrucType {
|
||||||
@ -32,17 +33,18 @@ public class TestStrucType {
|
|||||||
String name = f.getName();
|
String name = f.getName();
|
||||||
System.out.println("Filename: " + name);
|
System.out.println("Filename: " + name);
|
||||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||||
//Print SourceFile Infos
|
// Print SourceFile Infos
|
||||||
sourceFile.accept(new SyntaxTreePrinter());
|
sourceFile.accept(new SyntaxTreePrinter());
|
||||||
|
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
|
||||||
|
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||||
|
|
||||||
ConstraintsSet constraints = strucTYPE.getConstraints();
|
ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||||
printConstraints.print(constraints);
|
printConstraints.print(constraints);
|
||||||
|
|
||||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||||
PrintInferredTypes.print(inferredTypes);
|
PrintInferredTypes.print(inferredTypes);
|
||||||
|
|
||||||
System.out.println("____________________________________________________________________________");
|
System.out.println("____________________________________________________________________________");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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