Hack in ASP-Constraint generation for WLP2024 paper Prototype Test

This commit is contained in:
Andreas Stadelmeier 2024-06-10 09:02:26 +02:00
parent 2aa3997f17
commit fcda301b1e
2 changed files with 24 additions and 14 deletions

View File

@ -53,7 +53,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
<source>21</source>
<target>21</target>
</configuration>

View File

@ -5,10 +5,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
@ -45,7 +42,7 @@ public class TYPE {
private String toASP(RefTypeOrTPHOrWildcardOrGeneric type){
if(type instanceof TypePlaceholder){
return "tph"+((TypePlaceholder) type).getName();
return "_"+((TypePlaceholder) type).getName();
}else if(type instanceof RefType){
if(((RefType) type).getParaList().size() > 0){
return ((RefType) type).getName() + "<" +
@ -55,7 +52,11 @@ public class TYPE {
return ((RefType) type).getName().toString();
}
}else if(type instanceof ExtendsWildcardType){
//TODO
return toASP(((ExtendsWildcardType) type).getInnerType());
} else if(type instanceof SuperWildcardType) {
return toASP(((SuperWildcardType) type).getInnerType());
} else if(type instanceof GenericRefType){
return "G"+((GenericRefType) type).getParsedName();
}
throw new RuntimeException("Unsupported Type: "+ type);
}
@ -67,7 +68,9 @@ public class TYPE {
} else if (p.OperatorSmallerDot()) {
ret +=(toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
} else if (p.OperatorSmallerNEQDot()) {
ret +=(toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
ret += (toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
}else if(p.OperatorSmaller()){
ret += toASP(p.TA1) +"<"+toASP(p.TA2)+ "\n";
} else {
throw new RuntimeException("Operator unsupported: " + p.GetOperator());
}
@ -77,14 +80,22 @@ public class TYPE {
private void writeASP(ConstraintSet<Pair> cs){
try(var f = new FileWriter("/tmp/output")){
f.append(genASP(cs.getUndConstraints()));
List<Set<Pair>> orCons = cs.getOderConstraints().stream().map(css -> {
return css.stream().flatMap(cp -> {
return cp.stream();
}).collect(Collectors.toSet());
List<List<Set<Pair>>> orCons = cs.getOderConstraints().stream().map(css -> {
return css.stream().map(cp -> {
return cp.stream().collect(Collectors.toSet());
}).collect(Collectors.toList());
}).toList();
for(Set<Pair> orC : orCons) {
for(var orCon : orCons){
f.append("{\n");
f.append(genASP(orC));
var it = orCon.iterator();
while(it.hasNext()) {
var orC = it.next();
f.append("{\n");
f.append(genASP(orC));
f.append("}\n");
if(it.hasNext())f.append("|");
}
f.append("}\n");
}
} catch (IOException e) {