update solve (not fixed).
This commit is contained in:
parent
7e1d6fad01
commit
25a5e79509
@ -56,6 +56,7 @@ public class Construct extends DefaultASTVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||||
|
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
|
||||||
return subTypeConstraints;
|
return subTypeConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +131,6 @@ public class Construct extends DefaultASTVisitor {
|
|||||||
TypePlaceholder x = TypePlaceholder.fresh(offset);
|
TypePlaceholder x = TypePlaceholder.fresh(offset);
|
||||||
this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm));
|
this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm));
|
||||||
this.inferredTypes.put(i, x);
|
this.inferredTypes.put(i, x);
|
||||||
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
|
|
||||||
|
|
||||||
final int modifiers = Modifier.PUBLIC;
|
final int modifiers = Modifier.PUBLIC;
|
||||||
final RefType superClass = this.createSuperClass();
|
final RefType superClass = this.createSuperClass();
|
||||||
|
@ -19,6 +19,7 @@ import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
|||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||||
@ -225,5 +226,9 @@ public class TYPEExpr extends DefaultASTVisitor {
|
|||||||
public void visit(GenericRefType genericRefType){
|
public void visit(GenericRefType genericRefType){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Literal literal) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.strucTypes.constraint;
|
package de.dhbwstuttgart.strucTypes.constraint;
|
||||||
|
|
||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
|
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,12 +36,15 @@ public class FieldConstraint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void inferTypes(InferredTypes inferredTypes) {
|
public void inferTypes(InferredTypes inferredTypes) {
|
||||||
if (inferredTypes.containsKey(classType)) {
|
// if (inferredTypes.containsKey(classType)) {
|
||||||
this.classType = inferredTypes.get(classType);
|
// this.classType = inferredTypes.get(classType);
|
||||||
}
|
// }
|
||||||
if (inferredTypes.containsKey(fieldType)) {
|
// if (inferredTypes.containsKey(fieldType)) {
|
||||||
this.fieldType = inferredTypes.get(fieldType);
|
// this.fieldType = inferredTypes.get(fieldType);
|
||||||
}
|
// }
|
||||||
|
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||||
|
classType = classType.accept(inferTypes);
|
||||||
|
fieldType = fieldType.accept(inferTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
|
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
@ -63,12 +64,15 @@ public class MethodConstraint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void inferTypes(InferredTypes inferredTypes) {
|
public void inferTypes(InferredTypes inferredTypes) {
|
||||||
if (inferredTypes.containsKey(classType)) {
|
// if (inferredTypes.containsKey(classType)) {
|
||||||
this.classType = inferredTypes.get(classType);
|
// this.classType = inferredTypes.get(classType);
|
||||||
}
|
// }
|
||||||
if (inferredTypes.containsKey(returnType)) {
|
// if (inferredTypes.containsKey(returnType)) {
|
||||||
this.returnType = inferredTypes.get(returnType);
|
// this.returnType = inferredTypes.get(returnType);
|
||||||
}
|
// }
|
||||||
|
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||||
|
classType = classType.accept(inferTypes);
|
||||||
|
returnType = returnType.accept(inferTypes);
|
||||||
arguments.forEach(c -> c.inferTypes(inferredTypes));
|
arguments.forEach(c -> c.inferTypes(inferredTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.strucTypes.constraint;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
import de.dhbwstuttgart.strucTypes.InferredTypes;
|
||||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||||
|
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
@ -33,13 +34,17 @@ public class SubTypeConstraint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void inferTypes(InferredTypes inferredTypes) {
|
public void inferTypes(InferredTypes inferredTypes) {
|
||||||
if (inferredTypes.containsKey(subtype)) {
|
// if (inferredTypes.containsKey(subtype)) {
|
||||||
this.subtype = inferredTypes.get(subtype);
|
// this.subtype = inferredTypes.get(subtype);
|
||||||
}
|
// }
|
||||||
if (inferredTypes.containsKey(supertype)) {
|
// if (inferredTypes.containsKey(supertype)) {
|
||||||
this.supertype = inferredTypes.get(supertype);
|
// this.supertype = inferredTypes.get(supertype);
|
||||||
}
|
// }
|
||||||
|
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||||
|
subtype = subtype.accept(inferTypes);
|
||||||
|
supertype = supertype.accept(inferTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean checkConstraintPossible() throws ImpossibleSubTypeException {
|
public boolean checkConstraintPossible() throws ImpossibleSubTypeException {
|
||||||
if (this.subtype instanceof RefType && this.supertype instanceof RefType) {
|
if (this.subtype instanceof RefType && this.supertype instanceof RefType) {
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.type;
|
package de.dhbwstuttgart.syntaxtree.type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
public class GenericRefType extends RefType
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public GenericRefType(String name, Token offset)
|
public GenericRefType(String name, Token offset)
|
||||||
{
|
{
|
||||||
super(offset);
|
super(new JavaClassName(name),offset);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,16 +25,17 @@ import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
|
|
||||||
public class TestPaperExample {
|
public class TestPaperExample {
|
||||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/";
|
||||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||||
|
|
||||||
@org.junit.Test
|
@org.junit.Test
|
||||||
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||||
ArrayList<File> files = new ArrayList<>();
|
ArrayList<File> files = new ArrayList<>();
|
||||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
// files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||||
trans(files);
|
// trans(files);
|
||||||
files.clear();
|
// files.clear();
|
||||||
files.add(new File(rootDirectory + "testMain.jav"));
|
// files.add(new File(rootDirectory + "constructed/A.java"));
|
||||||
|
files.add(new File(rootDirectory + "javFiles/testMain.jav"));
|
||||||
trans(files);
|
trans(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +83,7 @@ public class TestPaperExample {
|
|||||||
solvedClass.accept(syntaxtreeprinter);
|
solvedClass.accept(syntaxtreeprinter);
|
||||||
System.out.println("\nRemaining Constraints:");
|
System.out.println("\nRemaining Constraints:");
|
||||||
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
||||||
|
PrintInferredTypes.print(inferredTypesConstruct);
|
||||||
|
|
||||||
System.out.println("____________________________________________________________________________");
|
System.out.println("____________________________________________________________________________");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package strucType.constructed;
|
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 class A<Z extends L<AD, U>, M extends U, P, N extends V, V, AD extends O<P, V>, U> {
|
||||||
|
|
||||||
public A() {
|
public A() {
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,12 @@ import strucType.constructed.O;
|
|||||||
|
|
||||||
public class MyInteger implements L<MyInteger, MyInteger>, O<MyInteger, MyInteger> {
|
public class MyInteger implements L<MyInteger, MyInteger>, O<MyInteger, MyInteger> {
|
||||||
|
|
||||||
|
public Integer i;
|
||||||
|
|
||||||
public MyInteger(Integer i){
|
public MyInteger(Integer i){
|
||||||
this.i = i;
|
this.i = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer i;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MyInteger sub(MyInteger x) {
|
public MyInteger sub(MyInteger x) {
|
||||||
|
Loading…
Reference in New Issue
Block a user