Start ASP Gen after Constraint Generateion

This commit is contained in:
JanUlrich 2024-06-07 14:53:47 +02:00
parent 3d2b935c60
commit 7e37497740
5 changed files with 70 additions and 4 deletions

View File

@ -73,5 +73,5 @@ public class Constraint<A> extends HashSet<A> {
public String toStringBase() {
return super.toString();
}
}

View File

@ -127,4 +127,5 @@ public class ConstraintSet<A> {
public Set<A> getUndConstraints() {
return undConstraints;
}
}

View File

@ -136,8 +136,12 @@ public class Pair implements Serializable
public boolean OperatorSmallerDot() {
return eOperator == PairOperator.SMALLERDOT;
}
public boolean OperatorSmallerNEQDot() {
return eOperator == PairOperator.SMALLERNEQDOT;
}
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {

View File

@ -5,13 +5,20 @@ 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.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.util.BiRelation;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class TYPE {
@ -24,16 +31,66 @@ public class TYPE {
}
public ConstraintSet getConstraints() {
ConstraintSet ret = new ConstraintSet();
ConstraintSet<Pair> ret = new ConstraintSet();
for (ClassOrInterface cl : sf.KlassenVektor) {
var allClasses = new HashSet<ClassOrInterface>();
allClasses.addAll(allAvailableClasses);
allClasses.addAll(sf.availableClasses);
ret.addAll(getConstraintsClass(cl, new TypeInferenceInformation(allClasses)));
}
writeASP(ret);
System.exit(0);
return ret;
}
private String toASP(RefTypeOrTPHOrWildcardOrGeneric type){
if(type instanceof TypePlaceholder){
return "tph"+((TypePlaceholder) type).getName();
}else if(type instanceof RefType){
if(((RefType) type).getParaList().size() > 0){
return ((RefType) type).getName() + "<" +
((RefType) type).getParaList().stream().map(this::toASP).collect(Collectors.joining(", ")) +
">";
}else{
return ((RefType) type).getName().toString();
}
}else if(type instanceof ExtendsWildcardType){
//TODO
}
throw new RuntimeException("Unsupported Type: "+ type);
}
private String genASP(Set<Pair> cs){
String ret = "";
for(Pair p : cs) {
if (p.OperatorEqual()) {
ret +=(toASP(p.TA1) + "=." + toASP(p.TA2) + "\n");
} else if (p.OperatorSmallerDot()) {
ret +=(toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
} else if (p.OperatorSmallerNEQDot()) {
ret +=(toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
} else {
throw new RuntimeException("Operator unsupported: " + p.GetOperator());
}
}
return ret;
}
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());
}).toList();
for(Set<Pair> orC : orCons) {
f.append("{\n");
f.append(genASP(orC));
f.append("}\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
ConstraintSet ret = new ConstraintSet();
ConstraintSet methConstrains;

View File

@ -3,6 +3,7 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.Ignore;
import org.junit.Test;
import java.io.FileWriter;
import java.lang.reflect.*;
import java.util.AbstractList;
import java.util.Arrays;
@ -237,6 +238,9 @@ public class TestComplete {
@Test
//@Ignore("This is too complex")
public void matrixTest() throws Exception {
try(var f = new FileWriter("/tmp/output")){
f.append("hallo");
}
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
var matrix = classFiles.get("Matrix");