forked from JavaTX/JavaCompilerCore
ASP Generate Gencay
This commit is contained in:
parent
3dfbddf693
commit
1f8421db27
@ -21,6 +21,7 @@ public class ASPUnify {
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/step4.lp"));
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/subst.lp"));
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/unifikation.lp"));
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/cartesian.lp"));
|
||||
}
|
||||
|
||||
public ASPUnify(List<File> inputFiles){
|
||||
@ -37,7 +38,7 @@ public class ASPUnify {
|
||||
commands.add(pathToClingo);
|
||||
//commands.add("--outf=2"); //use JSON-Output
|
||||
commands.add("--outf=1"); //use Text-Output
|
||||
commands.add("-n 0"); //Compute all models
|
||||
commands.add("-n 1"); //Compute n models
|
||||
for(File file : input){
|
||||
commands.add(file.getPath());
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
public enum ASPGencayRule {
|
||||
ASP_PAIR_EQUALS_NAME("equals"),
|
||||
ASP_PAIR_SMALLER_NAME("sub"),
|
||||
@ -7,10 +9,13 @@ public enum ASPGencayRule {
|
||||
ASP_PARAMLIST_NAME("paramEq"),
|
||||
ASP_FC_PARAMLIST_NAME("param"),
|
||||
ASP_PARAMLIST_END_POINTER("null"),
|
||||
ASP_PARAMLIST_END_RULE_EQ("endParamEq"),
|
||||
ASP_PARAMLIST_END_RULE_FC("endParam"),
|
||||
ASP_TYPE("typeEq"),
|
||||
ASP_FCTYPE("type"),
|
||||
ASP_TYPE_VAR("var"),
|
||||
ASP_GENERIC_VAR("pph"),
|
||||
ASP_WILDCARD("wildcard"),
|
||||
ASP_PARAMLIST_ORDER("paramOrder");
|
||||
|
||||
private final String text;
|
||||
|
@ -130,6 +130,11 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
stmt = makeStatement(paramname, p, type,
|
||||
ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString());
|
||||
}
|
||||
if(!it.hasNext()){ //Falls es der letzte Pointer ist
|
||||
String endRule = isFCType?ASPGencayRule.ASP_PARAMLIST_END_RULE_FC.toString():ASPGencayRule.ASP_PARAMLIST_END_RULE_EQ.toString();
|
||||
writer.add(makeStatement(endRule, p,
|
||||
ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString()));
|
||||
}
|
||||
p = nextP;
|
||||
writer.add(stmt);
|
||||
}
|
||||
@ -143,11 +148,9 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
currentFCTypePointer = pointer;
|
||||
String paramPointer = ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
if(refType.getParaList().size() == 1 ){
|
||||
if(refType.getParaList().get(0) instanceof TypePlaceholder){
|
||||
TypePlaceholder typePlaceholder = (TypePlaceholder) refType.getParaList().get(0);
|
||||
paramPointer = typePlaceholder.acceptTV(this);
|
||||
}
|
||||
if(refType.getParaList().size() == 1 && (refType.getParaList().get(0) instanceof TypePlaceholder)){
|
||||
TypePlaceholder typePlaceholder = (TypePlaceholder) refType.getParaList().get(0);
|
||||
paramPointer = typePlaceholder.acceptTV(this);
|
||||
}else{
|
||||
List<String> params = null;
|
||||
params = generateParameter(refType);
|
||||
@ -194,6 +197,8 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
ret.addAll(generateParameter((RefType) param));
|
||||
}else if(param instanceof TypePlaceholder){
|
||||
ret.add(param.acceptTV(this));
|
||||
}else if(param instanceof WildcardType){
|
||||
ret.add(param.acceptTV(this));
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
return ret;
|
||||
@ -201,7 +206,10 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
writer.add(makeStatement(ASPGencayRule.ASP_WILDCARD.toString(),
|
||||
pointer, "super", superWildcardType.getInnerType().acceptTV(this)));
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,7 +230,10 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
writer.add(makeStatement(ASPGencayRule.ASP_WILDCARD.toString(),
|
||||
pointer, "extends", extendsWildcardType.getInnerType().acceptTV(this)));
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -69,6 +69,40 @@ public class GeneratorTest extends UnifyWithoutWildcards{
|
||||
System.out.println(resultSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void example5() throws ClassNotFoundException { //Das Beispiel aus dem Paper
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
|
||||
TypePlaceholder tphA = TypePlaceholder.fresh(new NullToken());
|
||||
RefType number = new RefType(new JavaClassName(Number.class.getName()), new ArrayList<>(), new NullToken());
|
||||
ExtendsWildcardType extendsNumber = new ExtendsWildcardType(number, new NullToken());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(tphA);
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(extendsNumber);
|
||||
RefType stack = new RefType(new JavaClassName(Stack.class.getName()), list1, new NullToken());
|
||||
RefType vector = new RefType(new JavaClassName(Vector.class.getName()), list2, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(stack, vector, PairOperator.SMALLERDOT));
|
||||
|
||||
RefType integer = new RefType(new JavaClassName(Integer.class.getName()), new ArrayList<>(), new NullToken());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list3 = Arrays.asList(integer);
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list4 = Arrays.asList(tphA);
|
||||
RefType abstractList = new RefType(new JavaClassName(AbstractList.class.getName()), list3, new NullToken());
|
||||
RefType list = new RefType(new JavaClassName(List.class.getName()), list4, new NullToken());
|
||||
|
||||
testSet.addUndConstraint(new Pair(abstractList, list, PairOperator.SMALLERDOT));
|
||||
|
||||
|
||||
Set<ClassOrInterface> fc = new HashSet<>();
|
||||
fc.add(ASTFactory.createClass(Stack.class));
|
||||
fc.add(ASTFactory.createClass(Vector.class));
|
||||
fc.add(ASTFactory.createClass(AbstractList.class));
|
||||
fc.add(ASTFactory.createClass(List.class));
|
||||
fc.add(ASTFactory.createClass(Integer.class));
|
||||
fc.add(ASTFactory.createClass(Number.class));
|
||||
|
||||
String resultSet = ASPGencayFactory.generateASP(testSet, fc);
|
||||
System.out.println(resultSet);
|
||||
}
|
||||
|
||||
private Collection<ClassOrInterface> getFC() {
|
||||
Set<ClassOrInterface> ret = new HashSet<>();
|
||||
ret.add(ASTFactory.createClass(Matrix.class));
|
||||
|
@ -1,13 +1,27 @@
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.Object;
|
||||
|
||||
class MyVector{
|
||||
|
||||
id(x){
|
||||
Object i;
|
||||
x.elementAt(i);
|
||||
x.elementAt(i);
|
||||
x.elementAt(i);
|
||||
return x.elementAt(i);
|
||||
///*
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
//*/
|
||||
//TODO: Allein die Constraints aus diesem Stmt verursachen 5000 mögliche Lösungen. Warum?
|
||||
x.add(i);
|
||||
return x;
|
||||
}
|
||||
}
|
10976
test/logFiles/log
Normal file
10976
test/logFiles/log
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user