forked from JavaTX/JavaCompilerCore
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,14 +37,10 @@ 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;
|
||||||
@ -49,12 +63,14 @@ public class JavaTXCompiler {
|
|||||||
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
|
||||||
|
// FC
|
||||||
for (File forSourceFile : sourceFiles.keySet())
|
for (File forSourceFile : sourceFiles.keySet())
|
||||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
for (JavaClassName name : sourceFiles.get(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
|
||||||
|
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
importedClasses.add(importedClass);
|
importedClasses.add(importedClass);
|
||||||
}
|
}
|
||||||
allClasses.addAll(importedClasses);
|
allClasses.addAll(importedClasses);
|
||||||
@ -69,18 +85,43 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
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
|
||||||
|
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
importedClasses.add(importedClass);
|
importedClasses.add(importedClass);
|
||||||
allClasses.addAll(importedClasses);
|
allClasses.addAll(importedClasses);
|
||||||
}
|
}
|
||||||
return allClasses;
|
return allClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<SolvedClass> strucTypeInference()
|
||||||
|
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||||
|
List<SolvedClass> 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();
|
||||||
|
|
||||||
|
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||||
|
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||||
|
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||||
|
inferredTypes = construct.getInferredTypes();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||||
|
// FC
|
||||||
for (SourceFile sf : this.sourceFiles.values()) {
|
for (SourceFile sf : this.sourceFiles.values()) {
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
@ -105,8 +146,9 @@ public class JavaTXCompiler {
|
|||||||
System.out.println("RESULT: " + result.size());
|
System.out.println("RESULT: " + result.size());
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream()
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons)))))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||||
@ -125,7 +167,8 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
||||||
|
new GenericsRegistry(null));
|
||||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||||
return ret;
|
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();
|
||||||
cls.accept(typeExpr);
|
this.clsA.accept(typeExpr);
|
||||||
cls.getMethods().forEach(m -> m.accept(this));
|
this.clsA.getMethods().forEach(m -> m.accept(this));
|
||||||
this.evaluateTypeExpr(typeExpr);
|
this.evaluateTypeExpr(typeExpr);
|
||||||
}
|
|
||||||
return this.constraintsSet;
|
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;
|
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;
|
||||||
@ -36,7 +36,8 @@ public class TestPaperExample {
|
|||||||
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 {
|
||||||
@ -34,8 +35,9 @@ public class TestStrucType {
|
|||||||
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);
|
||||||
|
@ -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