Compare commits

...

5 Commits

Author SHA1 Message Date
Andreas Stadelmeier
9c2c6a3ea9 Alter OL Test
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 48s
2024-07-01 12:36:22 +02:00
Andreas Stadelmeier
a7ad4fa984 Add OrCOnsTest 2024-06-28 11:32:32 +02:00
Andreas Stadelmeier
fcda301b1e Hack in ASP-Constraint generation for WLP2024 paper Prototype Test 2024-06-10 09:02:26 +02:00
JanUlrich
2aa3997f17 Readme 2024-06-07 14:54:27 +02:00
JanUlrich
7e37497740 Start ASP Gen after Constraint Generateion 2024-06-07 14:53:47 +02:00
9 changed files with 114 additions and 9 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
Prototype
run with:
mvn test -Dtest="TestComplete#matrixTest"
mvn test -Dtest="typeinference.JavaTXCompilerTest#importTest"
then the output is in: /tmp/output

View File

@ -53,9 +53,8 @@ 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>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
<plugin>

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,17 @@ 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.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.*;
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 +28,80 @@ 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 "_"+((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){
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);
}
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 if(p.OperatorSmaller()){
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<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(var orCon : orCons){
f.append("{\n");
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) {
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");

View File

@ -34,7 +34,7 @@ public class JavaTXCompilerTest {
@Test
public void importTest() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Import.jav"));
execute(new File(rootDirectory + "OrConsTest.jav"));
}
@Test

View File

@ -0,0 +1,20 @@
import java.lang.Integer;
import java.lang.String;
class C1{
m(){return this;}
}
class C2{
m(){return this;}
}
public class OrConsTest {
ol(var1) {
return var1.m().m().m().m().m().m().m().m().m().m().m().m();
}
}