diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java index 5a56c7a7d..77ea36f3e 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java @@ -12,11 +12,18 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import java.sql.Ref; import java.util.*; -public class ASPGencayFactory implements TypeVisitor { +public class ASPGencayFactory implements TypeVisitor { + /* TODO: + * Alle TPHs müssen als var(tph) definiert sein + * Wenn es eine Variable ist, dann direkt in die type-Regel schreiben: type(p, type, tph) + * Für die FCTypen eindeutige Namen für die pph-Regeln + * (ergibt sich von selbst, weil man einfach den Namen der TPH in der FC verwenden kann) + * paramOrder wird benötigt! + * + */ ASPWriter writer = new ASPWriter(); boolean isFCType = false; @@ -45,15 +52,14 @@ public class ASPGencayFactory implements TypeVisitor { } private void generateTheta(RefType t){ - String statement = "theta"+t.getParaList().size() + "("; - statement += ASPStringConverter.toConstant(t.getName()); - statement+=")"; - writer.add(new ASPStatement(statement)); + String rule = "theta"+t.getParaList().size() ; + String name = ASPStringConverter.toConstant(t.getName()); + writer.add(makeStatement(rule, name)); } private void convertPair(Pair p){ - String ls = p.TA1.acceptTV(this); - String rs = p.TA2.acceptTV(this); + String ls = generateFCType((RefType) p.TA1); + String rs = generateFCType((RefType) p.TA2); ASPStatement pairStmt = null; if(p.GetOperator().equals(PairOperator.SMALLERDOT)){ pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_SMALLER_DOT_NAME.toString(), ls, rs); @@ -65,6 +71,24 @@ public class ASPGencayFactory implements TypeVisitor { writer.add(pairStmt); } + private String generateFCType(RefType refType){ + String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); + String paramPointer = ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString(); + if(refType.getParaList().size() > 1)throw new NotImplementedException(); + if(refType.getParaList().size() > 0){ + TypePlaceholder typePlaceholder = (TypePlaceholder) refType.getParaList().get(0); + String pphName = ASPStringConverter.toConstant(typePlaceholder.getName()); + ASPStatement paramStmt = makeStatement(ASPGencayRule.ASP_GENERIC_VAR.toString(), + pointer, pphName); + writer.add(paramStmt); + } + String typeName = ASPStringConverter.toConstant(refType.getName()); + String ruleName = isFCType? ASPGencayRule.ASP_FCTYPE.toString(): ASPGencayRule.ASP_TYPE.toString(); + ASPStatement stmt = makeStatement(ruleName, pointer, typeName, paramPointer); + writer.add(stmt); + return pointer; + } + private ASPStatement makeStatement(String rule, String... params){ String stmt = rule + "("; for(String param : params){ @@ -76,7 +100,7 @@ public class ASPGencayFactory implements TypeVisitor { } private String convertParameterlist(List pointers){ - if(pointers.size()==1)return pointers.get(0); + //if(pointers.size()==1)return pointers.get(0); String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); Iterator it = pointers.iterator(); String p = pointer; @@ -104,7 +128,7 @@ public class ASPGencayFactory implements TypeVisitor { @Override public String visit(RefType refType) { String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); - List params = new ArrayList<>(); + List params = null; params = generateParameter(refType); params.remove(0); //Das erste ist der eigentliche Typ kein parameter String typeName = ASPStringConverter.toConstant(refType.getName()); @@ -138,7 +162,14 @@ public class ASPGencayFactory implements TypeVisitor { @Override public String visit(TypePlaceholder typePlaceholder) { String name = ASPStringConverter.toConstant(typePlaceholder.getName()); - ASPStatement stmt = makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(), name); + + ASPStatement stmt = null; + if(isFCType){ + stmt = makeStatement(ASPGencayRule.ASP_GENERIC_VAR.toString(), name); + } else { + stmt = makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(), name); + } + writer.add(stmt); return name; } diff --git a/test/asp/gencay/GeneratorTest.java b/test/asp/gencay/GeneratorTest.java index d7e457b26..2c9fc46f3 100644 --- a/test/asp/gencay/GeneratorTest.java +++ b/test/asp/gencay/GeneratorTest.java @@ -27,7 +27,20 @@ import java.util.concurrent.ArrayBlockingQueue; public class GeneratorTest extends UnifyWithoutWildcards{ @Test - public void matrix() throws InterruptedException, IOException, ClassNotFoundException { + public void simple() throws ClassNotFoundException { + ConstraintSet testSet = new ConstraintSet<>(); + List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); + List list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); + RefType t1 = new RefType(new JavaClassName("java.util.List"), list1, new NullToken()); + RefType t2 = new RefType(new JavaClassName("java.util.List"), list2, new NullToken()); + testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); + String resultSet = ASPGencayFactory.generateASP(testSet, + new HashSet<>(Arrays.asList(ASTFactory.createClass(List.class)))); + System.out.println(resultSet); + } + + @Test + public void matrix() throws ClassNotFoundException { ConstraintSet testSet = new ConstraintSet<>(); List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); List list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));