solve added
This commit is contained in:
parent
403430d0c4
commit
427a87598c
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
@ -17,4 +18,9 @@ public class AssignToLocal extends AssignLeftSide {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
138
src/de/dhbwstuttgart/strucTypes/ASTReturnVisitor.java
Normal file
138
src/de/dhbwstuttgart/strucTypes/ASTReturnVisitor.java
Normal file
@ -0,0 +1,138 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
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;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public interface ASTReturnVisitor {
|
||||
|
||||
// ASTVisitor
|
||||
SourceFile visit(SourceFile sourceFile);
|
||||
|
||||
GenericTypeVar visit(GenericTypeVar genericTypeVar);
|
||||
|
||||
FormalParameter visit(FormalParameter formalParameter);
|
||||
|
||||
GenericDeclarationList visit(GenericDeclarationList genericTypeVars);
|
||||
|
||||
Field visit(Field field);
|
||||
|
||||
Method visit(Method method);
|
||||
|
||||
Constructor visit(Constructor constructor);
|
||||
|
||||
ParameterList visit(ParameterList formalParameters);
|
||||
|
||||
ClassOrInterface visit(ClassOrInterface classOrInterface);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType);
|
||||
//StatementVisitor
|
||||
ArgumentList visit(ArgumentList argumentList);
|
||||
|
||||
LambdaExpression visit(LambdaExpression lambdaExpression);
|
||||
|
||||
Assign visit(Assign assign);
|
||||
|
||||
BinaryExpr visit(BinaryExpr binary);
|
||||
|
||||
Block visit(Block block);
|
||||
|
||||
CastExpr visit(CastExpr castExpr);
|
||||
|
||||
EmptyStmt visit(EmptyStmt emptyStmt);
|
||||
|
||||
FieldVar visit(FieldVar fieldVar);
|
||||
|
||||
ForStmt visit(ForStmt forStmt);
|
||||
|
||||
IfStmt visit(IfStmt ifStmt);
|
||||
|
||||
InstanceOf visit(InstanceOf instanceOf);
|
||||
|
||||
LocalVar visit(LocalVar localVar);
|
||||
|
||||
LocalVarDecl visit(LocalVarDecl localVarDecl);
|
||||
|
||||
MethodCall visit(MethodCall methodCall);
|
||||
|
||||
NewClass visit(NewClass newClass);
|
||||
|
||||
NewArray visit(NewArray newArray);
|
||||
|
||||
Return visit(Return aReturn);
|
||||
|
||||
ReturnVoid visit(ReturnVoid aReturn);
|
||||
|
||||
StaticClassName visit(StaticClassName staticClassName);
|
||||
|
||||
Super visit(Super aSuper);
|
||||
|
||||
This visit(This aThis);
|
||||
|
||||
WhileStmt visit(WhileStmt whileStmt);
|
||||
|
||||
DoStmt visit(DoStmt doStmt);
|
||||
|
||||
AssignToField visit(AssignToField assignLeftSide);
|
||||
|
||||
AssignToLocal visit(AssignToLocal assignLeftSide);
|
||||
|
||||
SuperCall visit(SuperCall superCall);
|
||||
|
||||
ExpressionReceiver visit(ExpressionReceiver expressionReceiver);
|
||||
|
||||
UnaryExpr visit(UnaryExpr unaryExpr);
|
||||
|
||||
Literal visit(Literal literal);
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
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.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
public class ClassOrInterfaceWithConstraints extends ClassOrInterface {
|
||||
|
||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
||||
|
||||
public ClassOrInterfaceWithConstraints(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) {
|
||||
super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface,
|
||||
implementedInterfaces, offset);
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, Set<SubTypeConstraint> constraints) {
|
||||
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(),
|
||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||
classOrInterface.getOffset(), constraints);
|
||||
}
|
||||
|
||||
public ClassOrInterfaceWithConstraints(ClassOrInterface classOrInterface, GenericDeclarationList generics,
|
||||
Set<SubTypeConstraint> constraints) {
|
||||
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), generics,
|
||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||
classOrInterface.getOffset(), constraints);
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
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.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());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -28,11 +27,10 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class Construct extends DefaultASTVisitor {
|
||||
|
||||
private List<SubTypeConstraint> subTypeConstraints = new ArrayList<>();
|
||||
private Set<SubTypeConstraint> subTypeConstraints = new HashSet<>();
|
||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||
private Set<RefTypeOrTPHOrWildcardOrGeneric> newInterf = new HashSet<>();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
@ -56,13 +54,13 @@ public class Construct extends DefaultASTVisitor {
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getSubTypeConstraints() {
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
|
||||
return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
|
||||
}
|
||||
// public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
|
||||
// return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
|
||||
// }
|
||||
|
||||
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
|
||||
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
|
||||
@ -75,7 +73,7 @@ public class Construct extends DefaultASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
JavaClassName name = new JavaClassName("constructedinterface." + typePlaceholder.getName());
|
||||
JavaClassName name = new JavaClassName( typePlaceholder.getName());
|
||||
this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
|
||||
}
|
||||
|
||||
@ -116,7 +114,7 @@ public class Construct extends DefaultASTVisitor {
|
||||
// Typ für argument: GenericRefType
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
GenericRefType grt = new GenericRefType(tph.getName(), offset);
|
||||
params.add(new FormalParameter(tph.getName(), grt, offset));
|
||||
params.add(new FormalParameter("arg" + tph.getName(), grt, offset));
|
||||
parameterInhTyterm.add(supertype);
|
||||
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
|
||||
});
|
||||
|
368
src/de/dhbwstuttgart/strucTypes/InferTypesVisitor.java
Normal file
368
src/de/dhbwstuttgart/strucTypes/InferTypesVisitor.java
Normal file
@ -0,0 +1,368 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class InferTypesVisitor implements ASTReturnVisitor {
|
||||
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public InferTypesVisitor(InferredTypes inferredTypes) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile visit(SourceFile sourceFile) {
|
||||
return new SourceFile(sourceFile.getPkgName(),
|
||||
sourceFile.getClasses().stream().map(c -> c.accept(this)).collect(Collectors.toList()),
|
||||
sourceFile.getImports());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor visit(Constructor constructor) {
|
||||
int modifier = constructor.modifier;
|
||||
String name = constructor.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = constructor.getReturnType().accept(this);
|
||||
ParameterList parameterList = constructor.getParameterList().accept(this);
|
||||
Block codeInsideConstructor = constructor.block.accept(this);
|
||||
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) constructor.getGenerics()).accept(this);
|
||||
Token offset = constructor.getOffset();
|
||||
List<Statement> fieldInitializations = new ArrayList<>();
|
||||
return new Constructor(modifier, name, returnType, parameterList, codeInsideConstructor, gtvDeclarations,
|
||||
offset, fieldInitializations);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericTypeVar visit(GenericTypeVar genericTypeVar) {
|
||||
return new GenericTypeVar(
|
||||
genericTypeVar.getName(), genericTypeVar.getBounds().stream()
|
||||
.map(b -> (RefTypeOrTPHOrWildcardOrGeneric) b.accept(this)).collect(Collectors.toList()),
|
||||
genericTypeVar.getOffset(), new NullToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameter visit(FormalParameter formalParameter) {
|
||||
return new FormalParameter(formalParameter.getName(), formalParameter.getType().accept(this),
|
||||
formalParameter.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericDeclarationList visit(GenericDeclarationList genericTypeVars) {
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
genericTypeVars.forEach(gtv -> values.add(gtv.accept(this)));
|
||||
return new GenericDeclarationList(values, genericTypeVars.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field visit(Field field) {
|
||||
return new Field(field.getName(), field.getType().accept(this), field.modifier, field.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method visit(Method method) {
|
||||
int modifier = method.modifier;
|
||||
String name = method.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType().accept(this);
|
||||
ParameterList parameterList = method.getParameterList().accept(this);
|
||||
Block block = method.block.accept(this);
|
||||
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) method.getGenerics()).accept(this);
|
||||
Token offset = method.getOffset();
|
||||
return new Method(modifier, name, returnType, parameterList, block, gtvDeclarations, offset);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterList visit(ParameterList formalParameters) {
|
||||
for (FormalParameter formalParameter : formalParameters) {
|
||||
formalParameter.accept(this);
|
||||
}
|
||||
return new ParameterList(
|
||||
formalParameters.getFormalparalist().stream().map(p -> p.accept(this)).collect(Collectors.toList()),
|
||||
formalParameters.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassOrInterface visit(ClassOrInterface classOrInterface) {
|
||||
int modifiers = classOrInterface.getModifiers();
|
||||
JavaClassName name = classOrInterface.getClassName();
|
||||
List<Field> fielddecl = classOrInterface.getFieldDecl().stream().map(f -> f.accept(this))
|
||||
.collect(Collectors.toList());
|
||||
List<Method> methods = classOrInterface.getMethods().stream().map(m -> m.accept(this))
|
||||
.collect(Collectors.toList());
|
||||
List<Constructor> constructors = classOrInterface.getConstructors().stream()
|
||||
.map(c -> (Constructor) c.accept(this)).collect(Collectors.toList());
|
||||
GenericDeclarationList genericClassParameters = classOrInterface.getGenerics().accept(this);
|
||||
RefType superClass = (RefType) classOrInterface.getSuperClass().accept(this);
|
||||
Boolean isInterface = classOrInterface.isInterface;
|
||||
List<RefType> implementedInterfaces = classOrInterface.getSuperInterfaces().stream()
|
||||
.map(i -> (RefType) i.accept(this)).collect(Collectors.toList());
|
||||
Token offset = classOrInterface.getOffset();
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters,
|
||||
superClass, isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefType visit(RefType refType) {
|
||||
|
||||
return refType.getParaList() == null ? refType
|
||||
: new RefType(refType.getName(), refType.getParaList().stream()
|
||||
.map(p -> (RefTypeOrTPHOrWildcardOrGeneric) p.accept(this)).collect(Collectors.toList()),
|
||||
refType.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperWildcardType visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||
return inferredTypes.infer(typePlaceholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendsWildcardType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericRefType visit(GenericRefType genericRefType) {
|
||||
return genericRefType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentList visit(ArgumentList argumentList) {
|
||||
return new ArgumentList(argumentList.getArguments().stream().map(expr -> (Expression) expr.accept(this))
|
||||
.collect(Collectors.toList()), argumentList.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaExpression visit(LambdaExpression lambdaExpression) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assign visit(Assign assign) {
|
||||
return assign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryExpr visit(BinaryExpr binary) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block visit(Block block) {
|
||||
return new Block(
|
||||
block.getStatements().stream().map(s -> (Statement) s.accept(this)).collect(Collectors.toList()),
|
||||
block.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastExpr visit(CastExpr castExpr) {
|
||||
return new CastExpr(castExpr.getType().accept(this), castExpr.expr == null ? null : castExpr.expr.accept(this),
|
||||
castExpr.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyStmt visit(EmptyStmt emptyStmt) {
|
||||
return emptyStmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVar visit(FieldVar fieldVar) {
|
||||
return new FieldVar(fieldVar.receiver == null ? null : fieldVar.receiver.accept(this), fieldVar.fieldVarName,
|
||||
fieldVar.getType().accept(this), fieldVar.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForStmt visit(ForStmt forStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfStmt visit(IfStmt ifStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceOf visit(InstanceOf instanceOf) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVar visit(LocalVar localVar) {
|
||||
return new LocalVar(localVar.name, localVar.getType().accept(this), localVar.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVarDecl visit(LocalVarDecl localVarDecl) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodCall visit(MethodCall methodCall) {
|
||||
methodCall.getType().accept(this);
|
||||
methodCall.getArgumentList().accept(this);
|
||||
return new MethodCall(methodCall.getType().accept(this),
|
||||
methodCall.receiver == null ? null : methodCall.receiver.accept(this), methodCall.name,
|
||||
methodCall.getArgumentList().accept(this), methodCall.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewClass visit(NewClass newClass) {
|
||||
return new NewClass(newClass.getType().accept(this), newClass.getArgumentList().accept(this),
|
||||
newClass.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArray visit(NewArray newArray) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Return visit(Return aReturn) {
|
||||
return new Return(aReturn.retexpr == null ? null : aReturn.retexpr.accept(this), aReturn.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnVoid visit(ReturnVoid aReturn) {
|
||||
return aReturn;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaticClassName visit(StaticClassName staticClassName) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Super visit(Super aSuper) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public This visit(This aThis) {
|
||||
return aThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhileStmt visit(WhileStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoStmt visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToField visit(AssignToField assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal visit(AssignToLocal assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperCall visit(SuperCall superCall) {
|
||||
if(superCall.getArgumentList().getArguments() == null){
|
||||
return superCall;
|
||||
}
|
||||
return new SuperCall(superCall.getArgumentList().accept(this), superCall.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionReceiver visit(ExpressionReceiver expressionReceiver) {
|
||||
return new ExpressionReceiver(expressionReceiver.expr == null ? null : expressionReceiver.expr.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnaryExpr visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal visit(Literal literal) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -84,6 +84,10 @@ public class InferredTypes implements Map<TypePlaceholder, RefTypeOrTPHOrWildcar
|
||||
public Set<java.util.Map.Entry<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric>> entrySet() {
|
||||
return inferredTypes.entrySet();
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric infer(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
return inferredTypes.get(type) != null ? inferredTypes.get(type) : type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
102
src/de/dhbwstuttgart/strucTypes/Solve.java
Normal file
102
src/de/dhbwstuttgart/strucTypes/Solve.java
Normal file
@ -0,0 +1,102 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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 java.util.stream.Stream;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class Solve {
|
||||
|
||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
||||
private IFiniteClosure fc;
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private ClassOrInterface clsA;
|
||||
|
||||
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
||||
InferredTypes inferredTypes) {
|
||||
this.constraints = constraints;
|
||||
this.fc = fc;
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.clsA = clsA;
|
||||
}
|
||||
|
||||
public ClassOrInterfaceWithConstraints getSolvedClass() throws InconsistentConstraintsException {
|
||||
Set<UnifyPair> constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair)
|
||||
.collect(Collectors.toSet());
|
||||
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
|
||||
Set<UnifyPair> subst = strucTypeUnify.unify();
|
||||
|
||||
Map<String, TypePlaceholder> tphs = this.generateTPHMap(constraints);
|
||||
InferredTypes sigma = new InferredTypes();
|
||||
sigma.putAll(inferredTypes);
|
||||
sigma.putAll(
|
||||
StrucTypeUnifyUtils.convertEqualsdot(
|
||||
subst.stream()
|
||||
.filter(p -> p.getLhsType() instanceof PlaceholderType
|
||||
&& p.getPairOp().equals(PairOperator.EQUALSDOT))
|
||||
.collect(Collectors.toSet()),
|
||||
tphs));
|
||||
|
||||
Set<SubTypeConstraint> cs = StrucTypeUnifyUtils.convertSmallerdot(
|
||||
subst.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp())).collect(Collectors.toSet()),
|
||||
tphs);
|
||||
|
||||
// TODO Tnew
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
TypeVar typeVar = new TypeVar(inferredTypes);
|
||||
clsA.accept(typeVar);
|
||||
final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
|
||||
final NullToken offset = new NullToken();
|
||||
typeVar.getTypeVars().stream().map(tph -> new GenericTypeVar(tph.getName(), bounds, offset, offset))
|
||||
.forEach(values::add);
|
||||
cs.stream().flatMap(c -> Stream.of(c.getSubtype(), c.getSupertype())).filter(t -> t instanceof TypePlaceholder)
|
||||
.map(tph -> new GenericTypeVar(((TypePlaceholder) tph).getName(), bounds, offset, offset))
|
||||
.forEach(values::add);
|
||||
//TODO typevar(superclass)
|
||||
GenericDeclarationList Tnew = new GenericDeclarationList(values, offset);
|
||||
|
||||
if (!consistent(cs)) {
|
||||
throw new InconsistentConstraintsException();
|
||||
}
|
||||
return new ClassOrInterfaceWithConstraints(this.clsA.accept(new InferTypesVisitor(inferredTypes)), Tnew,
|
||||
this.constraints);
|
||||
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(Set<SubTypeConstraint> constraints) {
|
||||
Map<String, TypePlaceholder> tphs = new HashMap<>();
|
||||
constraints.stream().forEach(c -> {
|
||||
if (c.getSubtype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder subtype = (TypePlaceholder) c.getSubtype();
|
||||
tphs.put(subtype.getName(), subtype);
|
||||
}
|
||||
if (c.getSupertype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder supertype = (TypePlaceholder) c.getSupertype();
|
||||
tphs.put(supertype.getName(), supertype);
|
||||
}
|
||||
});
|
||||
return tphs;
|
||||
}
|
||||
|
||||
private boolean consistent(Set<SubTypeConstraint> cs) {
|
||||
// TODO update inconsistencies
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,10 +3,17 @@ package de.dhbwstuttgart.strucTypes;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class StrucTypeUnifyUtils {
|
||||
@ -33,4 +40,26 @@ public class StrucTypeUnifyUtils {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static InferredTypes convertEqualsdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
InferredTypes inferredTypes = new InferredTypes();
|
||||
if (!pairs.stream().allMatch(
|
||||
p -> PairOperator.EQUALSDOT.equals(p.getPairOp()) && p.getLhsType() instanceof PlaceholderType)) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were EQUALSDOT pairs.");
|
||||
}
|
||||
for (UnifyPair pair : pairs) {
|
||||
TypePlaceholder lhs = (TypePlaceholder) UnifyTypeFactory.convert(pair.getLhsType(), tphs);
|
||||
RefTypeOrTPHOrWildcardOrGeneric rhs = UnifyTypeFactory.convert(pair.getRhsType(), tphs);
|
||||
inferredTypes.put(lhs, rhs);
|
||||
}
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public static Set<SubTypeConstraint> convertSmallerdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
if (!pairs.stream().allMatch(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were SMALLERDOT pairs.");
|
||||
}
|
||||
return pairs.stream().map(p -> new SubTypeConstraint(UnifyTypeFactory.convert(p.getLhsType(), tphs),
|
||||
UnifyTypeFactory.convert(p.getRhsType(), tphs))).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
31
src/de/dhbwstuttgart/strucTypes/TypeVar.java
Normal file
31
src/de/dhbwstuttgart/strucTypes/TypeVar.java
Normal file
@ -0,0 +1,31 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class TypeVar extends AbstractASTWalker {
|
||||
|
||||
private Set<TypePlaceholder> typeVars = new HashSet<>();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public TypeVar(InferredTypes inferredTypes) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
super.visit(typePlaceholder);
|
||||
RefTypeOrTPHOrWildcardOrGeneric inferredType = this.inferredTypes.infer(typePlaceholder);
|
||||
if (inferredType instanceof TypePlaceholder) {
|
||||
this.typeVars.add((TypePlaceholder) inferredType);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<TypePlaceholder> getTypeVars() {
|
||||
return typeVars;
|
||||
}
|
||||
}
|
@ -1,31 +1,31 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||
|
||||
public class ConstraintsSet {
|
||||
|
||||
private List<SubTypeConstraint> subTypeConstraints;
|
||||
private List<FieldConstraint> fieldConstraints;
|
||||
private List<MethodConstraint> methodConstraints;
|
||||
private Set<SubTypeConstraint> subTypeConstraints;
|
||||
private Set<FieldConstraint> fieldConstraints;
|
||||
private Set<MethodConstraint> methodConstraints;
|
||||
|
||||
public ConstraintsSet() {
|
||||
this.subTypeConstraints = new ArrayList<>();
|
||||
this.fieldConstraints = new ArrayList<>();
|
||||
this.methodConstraints = new ArrayList<>();
|
||||
this.subTypeConstraints = new HashSet<>();
|
||||
this.fieldConstraints = new HashSet<>();
|
||||
this.methodConstraints = new HashSet<>();
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getSubTypeConstraints() {
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
public List<FieldConstraint> getFieldConstraints() {
|
||||
public Set<FieldConstraint> getFieldConstraints() {
|
||||
return fieldConstraints;
|
||||
}
|
||||
|
||||
public List<MethodConstraint> getMethodConstraints() {
|
||||
public Set<MethodConstraint> getMethodConstraints() {
|
||||
return methodConstraints;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class InconsistentConstraintsException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InconsistentConstraintsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes.printutils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
@ -17,7 +16,7 @@ public class PrintConstraints {
|
||||
printMethodConstraints(constraintsSet.getMethodConstraints());
|
||||
}
|
||||
|
||||
public void printSubTypeConstraints(List<SubTypeConstraint> constraints) {
|
||||
public void printSubTypeConstraints(Set<SubTypeConstraint> constraints) {
|
||||
System.out.println("\n SubTypeConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> System.out
|
||||
@ -25,12 +24,12 @@ public class PrintConstraints {
|
||||
// c.getSupertype().toString())));
|
||||
}
|
||||
|
||||
public void printSubTypeConstraints(Set<UnifyPair> constraints){
|
||||
public void printSubTypeConstraintsAsUnifyPair(Set<UnifyPair> constraints){
|
||||
System.out.println("\n SubTypeConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public void printFieldConstraints(List<FieldConstraint> constraints) {
|
||||
public void printFieldConstraints(Set<FieldConstraint> constraints) {
|
||||
System.out.println("\n FieldConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> System.out.println(String.format("F(%s, %s,
|
||||
@ -38,7 +37,7 @@ public class PrintConstraints {
|
||||
// c.getFieldName(), c.getFieldType().toString())));
|
||||
}
|
||||
|
||||
public void printMethodConstraints(List<MethodConstraint> constraints) {
|
||||
public void printMethodConstraints(Set<MethodConstraint> constraints) {
|
||||
System.out.println("\n MethodConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> {
|
||||
|
@ -330,6 +330,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = literal.getType();
|
||||
System.out.print("literal: ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
@ -12,6 +13,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -26,7 +28,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
public boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
@ -34,6 +36,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
this.modifiers = modifiers;
|
||||
if(isInterface)this.modifiers += Modifier.INTERFACE;
|
||||
this.name = name;
|
||||
this.fields = fielddecl;
|
||||
this.genericClassParameters = genericClassParameters;
|
||||
@ -102,8 +105,13 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassOrInterface accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public Collection<RefType> getSuperInterfaces() {
|
||||
public List<RefType> getSuperInterfaces() {
|
||||
return implementedInterfaces;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
|
||||
import java.util.List;
|
||||
@ -35,4 +36,9 @@ public class Constructor extends Method {
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -40,5 +41,10 @@ public class Field extends SyntaxTreeNode implements TypeScope{
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -26,4 +27,9 @@ public class FormalParameter extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameter accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -31,4 +33,9 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericDeclarationList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -61,4 +62,9 @@ public class GenericTypeVar extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericTypeVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -69,4 +70,9 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -39,4 +41,9 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
//import sun.security.x509.X509CertInfo;
|
||||
@ -43,4 +44,9 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
//import org.antlr.v4.runtime.misc.Pair;
|
||||
@ -20,4 +21,6 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public abstract void accept(ASTVisitor visitor);
|
||||
|
||||
public abstract <T> T accept(ASTReturnVisitor visitor);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
@ -30,4 +31,9 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -26,4 +27,9 @@ public class Assign extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assign accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
|
||||
public class AssignToField extends AssignLeftSide{
|
||||
@ -13,4 +14,9 @@ public class AssignToField extends AssignLeftSide{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToField accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -11,6 +12,11 @@ public class BinaryExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public enum Operator{
|
||||
ADD, // +
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -28,6 +29,11 @@ public class Block extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -22,4 +23,9 @@ public class CastExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -15,4 +16,9 @@ public class DoStmt extends WhileStmt
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -19,4 +20,9 @@ public class EmptyStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -18,4 +19,9 @@ public class ExpressionReceiver extends Receiver
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionReceiver accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
@ -28,4 +29,9 @@ public class FieldVar extends Expression {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -26,4 +27,9 @@ public class ForStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -27,4 +28,9 @@ public class IfStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
@ -21,4 +22,9 @@ public class InstanceOf extends BinaryExpr
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceOf accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -39,4 +40,9 @@ public class LambdaExpression extends Expression implements TypeScope {
|
||||
//return type.getParaList().get(0);
|
||||
return methodBody.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaExpression accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -21,4 +22,9 @@ public class Literal extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -24,4 +25,9 @@ public class LocalVar extends Statement{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -28,4 +29,9 @@ public class LocalVarDecl extends Statement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVarDecl accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -38,4 +39,9 @@ public class MethodCall extends Statement
|
||||
public ArgumentList getArgumentList() {
|
||||
return arglist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodCall accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
|
||||
|
||||
public class NewArray extends Expression
|
||||
@ -21,4 +22,9 @@ public class NewArray extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArray accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
@ -37,4 +38,9 @@ public class NewClass extends MethodCall
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewClass accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -18,4 +19,9 @@ public class Return extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Return accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -12,4 +13,9 @@ public class ReturnVoid extends Return{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnVoid accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -17,4 +18,9 @@ public class StaticClassName extends Receiver {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaticClassName accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
|
||||
public class Super extends Expression
|
||||
{
|
||||
@ -18,4 +19,9 @@ public class Super extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Super accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
@ -25,4 +26,9 @@ public class SuperCall extends MethodCall
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperCall accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
|
||||
public class This extends Expression
|
||||
{
|
||||
@ -19,4 +20,9 @@ public class This extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public This accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
|
||||
@ -32,6 +33,11 @@ public class UnaryExpr extends JavaInternalExpression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnaryExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class WhileStmt extends Statement
|
||||
{
|
||||
public final Expression expr;
|
||||
public final Statement loopBlock;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public WhileStmt(Expression expr, Statement loopBlock, Token offset)
|
||||
{
|
||||
super(TypePlaceholder.fresh(offset), offset);
|
||||
this.expr = expr;
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
public class WhileStmt extends Statement {
|
||||
public final Expression expr;
|
||||
public final Statement loopBlock;
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
public WhileStmt(Expression expr, Statement loopBlock, Token offset) {
|
||||
super(TypePlaceholder.fresh(offset), offset);
|
||||
this.expr = expr;
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhileStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -49,4 +50,9 @@ public class ExtendsWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -32,5 +33,10 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -121,5 +122,10 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -59,4 +60,9 @@ public class SuperWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
@ -82,4 +83,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class OutputGenerator implements ASTVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
if((Modifier.INTERFACE & classOrInterface.getModifiers()) == 1){
|
||||
if(Modifier.isInterface(classOrInterface.getModifiers())){
|
||||
out.append("interface ");
|
||||
}else{
|
||||
out.append("class ");
|
||||
|
@ -11,13 +11,13 @@ import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||
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.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class TestConstruct {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
@ -53,8 +53,8 @@ public class TestConstruct {
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
// final List<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
Set<UnifyPair> subTypeConstraints = construct.getSubTypeConstraintsAsUnifyPairs();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
// Set<UnifyPair> subTypeConstraints = construct.getSubTypeConstraintsAsUnifyPairs();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
final SyntaxTreePrinter syntaxTreePrinterInferred = new SyntaxTreePrinter(inferredTypesConstruct);
|
||||
|
||||
|
102
test/strucType/TestInferTypesVisitor.java
Normal file
102
test/strucType/TestInferTypesVisitor.java
Normal file
@ -0,0 +1,102 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.InferTypesVisitor;
|
||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||
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.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 TestInferTypesVisitor {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
//Print SourceFile Infos
|
||||
sourceFile.accept(new InferTypesVisitor(new InferredTypes()));
|
||||
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() throws ClassNotFoundException, IOException, ImpossibleSubTypeException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxTreePrinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxTreePrinter);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxTreePrinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
System.out.println("\n--Inferred SysntaxTree--");
|
||||
sourceFile = sourceFile.accept(new InferTypesVisitor(inferredTypesConstruct));
|
||||
sourceFile.accept(syntaxTreePrinter);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
89
test/strucType/TestPaperExample.java
Normal file
89
test/strucType/TestPaperExample.java
Normal file
@ -0,0 +1,89 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.ClassOrInterfaceWithConstraints;
|
||||
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.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
|
||||
public class TestPaperExample {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
trans(files);
|
||||
files.clear();
|
||||
files.add(new File(rootDirectory + "testMain.jav"));
|
||||
trans(files);
|
||||
}
|
||||
|
||||
private void trans(ArrayList<File> files)
|
||||
throws IOException, ClassNotFoundException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxtreeprinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxtreeprinter);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxtreeprinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
|
||||
System.out.println("\n--Solve--");
|
||||
// Alle Klassen aus allen SourceFiles
|
||||
List<ClassOrInterface> availableClasses = compiler.getAvailableClasses(sourceFile);
|
||||
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();
|
||||
System.out.println("\nSolved Class:");
|
||||
solvedClass.accept(syntaxtreeprinter);
|
||||
System.out.println("\nRemaining Constraints:");
|
||||
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
88
test/strucType/TestSolve.java
Normal file
88
test/strucType/TestSolve.java
Normal file
@ -0,0 +1,88 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.ClassOrInterfaceWithConstraints;
|
||||
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.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
|
||||
public class TestSolve {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxtreeprinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxtreeprinter);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
// Set<UnifyPair> subTypeConstraints = construct.getSubTypeConstraintsAsUnifyPairs();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxtreeprinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
|
||||
System.out.println("\n--Solve--");
|
||||
// Alle Klassen aus allen SourceFiles
|
||||
List<ClassOrInterface> availableClasses = compiler.getAvailableClasses(sourceFile);
|
||||
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();
|
||||
System.out.println("\nSolved Class:");
|
||||
solvedClass.accept(syntaxtreeprinter);
|
||||
System.out.println("\nRemaining Constraints:");
|
||||
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
12
test/strucType/constructed/A.java
Normal file
12
test/strucType/constructed/A.java
Normal file
@ -0,0 +1,12 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public class A<Z extends L<O<P, V>, U>, M extends U, P, N extends V, V, AD extends O<P, V>, U> {
|
||||
|
||||
public A() {
|
||||
}
|
||||
|
||||
public P mt(Z x, M y, N z) {
|
||||
return x.sub(y).add(z);
|
||||
}
|
||||
|
||||
}
|
6
test/strucType/constructed/CO.java
Normal file
6
test/strucType/constructed/CO.java
Normal file
@ -0,0 +1,6 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class CO<OX> {
|
||||
|
||||
public OX f;
|
||||
}
|
7
test/strucType/constructed/DE.java
Normal file
7
test/strucType/constructed/DE.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class DE<NG, NI, NJ> {
|
||||
|
||||
public abstract NG mF(NI x, NJ y);
|
||||
|
||||
}
|
8
test/strucType/constructed/DG.java
Normal file
8
test/strucType/constructed/DG.java
Normal file
@ -0,0 +1,8 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class DG<NL, NM, NO> {
|
||||
|
||||
public NL g;
|
||||
public abstract NM m2(NO x);
|
||||
|
||||
}
|
7
test/strucType/constructed/EK.java
Normal file
7
test/strucType/constructed/EK.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public abstract class EK<OA> {
|
||||
|
||||
public abstract OA getA();
|
||||
|
||||
}
|
7
test/strucType/constructed/FF.java
Normal file
7
test/strucType/constructed/FF.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface FF<PP, PR> {
|
||||
|
||||
public PP sub(PR x);
|
||||
|
||||
}
|
7
test/strucType/constructed/FI.java
Normal file
7
test/strucType/constructed/FI.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface FI<PL, PN> {
|
||||
|
||||
public PL add(PN x);
|
||||
|
||||
}
|
7
test/strucType/constructed/L.java
Normal file
7
test/strucType/constructed/L.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface L<R, T> {
|
||||
|
||||
public R sub(T x);
|
||||
|
||||
}
|
7
test/strucType/constructed/O.java
Normal file
7
test/strucType/constructed/O.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface O<R, T> {
|
||||
|
||||
public R add(T x);
|
||||
|
||||
}
|
8
test/strucType/javFiles/testMain.jav
Normal file
8
test/strucType/javFiles/testMain.jav
Normal file
@ -0,0 +1,8 @@
|
||||
package strucType.input;
|
||||
|
||||
import strucType.typedtestclasses.MyInteger;
|
||||
import strucType.constructed.A;
|
||||
|
||||
class Main {
|
||||
main() { return new A().mt(new MyInteger(2), new MyInteger(1), new MyInteger(3)); }
|
||||
}
|
24
test/strucType/typedtestclasses/MyInteger.java
Normal file
24
test/strucType/typedtestclasses/MyInteger.java
Normal file
@ -0,0 +1,24 @@
|
||||
package strucType.typedtestclasses;
|
||||
|
||||
import strucType.constructed.L;
|
||||
import strucType.constructed.O;
|
||||
|
||||
public class MyInteger implements L<MyInteger, MyInteger>, O<MyInteger, MyInteger> {
|
||||
|
||||
public MyInteger(Integer i){
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
Integer i;
|
||||
|
||||
@Override
|
||||
public MyInteger sub(MyInteger x) {
|
||||
return new MyInteger(i - x.i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyInteger add(MyInteger x) {
|
||||
return new MyInteger(i + x.i);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user