Compare commits
No commits in common. "9c2c6a3ea969ab5e7fd8edf2d57f1ae3822ec27a" and "3d2b935c60717e41a326df966619ad08bf3c04a7" have entirely different histories.
9c2c6a3ea9
...
3d2b935c60
@ -1,9 +0,0 @@
|
|||||||
Prototype
|
|
||||||
|
|
||||||
run with:
|
|
||||||
|
|
||||||
mvn test -Dtest="TestComplete#matrixTest"
|
|
||||||
|
|
||||||
mvn test -Dtest="typeinference.JavaTXCompilerTest#importTest"
|
|
||||||
|
|
||||||
then the output is in: /tmp/output
|
|
5
pom.xml
5
pom.xml
@ -53,8 +53,9 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>22</source>
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
<target>22</target>
|
<source>21</source>
|
||||||
|
<target>21</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -127,5 +127,4 @@ public class ConstraintSet<A> {
|
|||||||
public Set<A> getUndConstraints() {
|
public Set<A> getUndConstraints() {
|
||||||
return undConstraints;
|
return undConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -137,10 +137,6 @@ public class Pair implements Serializable
|
|||||||
return eOperator == PairOperator.SMALLERDOT;
|
return eOperator == PairOperator.SMALLERDOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean OperatorSmallerNEQDot() {
|
|
||||||
return eOperator == PairOperator.SMALLERNEQDOT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||||
|
@ -5,17 +5,13 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
|
||||||
import de.dhbwstuttgart.util.BiRelation;
|
import de.dhbwstuttgart.util.BiRelation;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class TYPE {
|
public class TYPE {
|
||||||
|
|
||||||
@ -28,80 +24,16 @@ public class TYPE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet getConstraints() {
|
public ConstraintSet getConstraints() {
|
||||||
ConstraintSet<Pair> ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
for (ClassOrInterface cl : sf.KlassenVektor) {
|
for (ClassOrInterface cl : sf.KlassenVektor) {
|
||||||
var allClasses = new HashSet<ClassOrInterface>();
|
var allClasses = new HashSet<ClassOrInterface>();
|
||||||
allClasses.addAll(allAvailableClasses);
|
allClasses.addAll(allAvailableClasses);
|
||||||
allClasses.addAll(sf.availableClasses);
|
allClasses.addAll(sf.availableClasses);
|
||||||
ret.addAll(getConstraintsClass(cl, new TypeInferenceInformation(allClasses)));
|
ret.addAll(getConstraintsClass(cl, new TypeInferenceInformation(allClasses)));
|
||||||
}
|
}
|
||||||
writeASP(ret);
|
|
||||||
//System.exit(0);
|
|
||||||
return ret;
|
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) {
|
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
ConstraintSet methConstrains;
|
ConstraintSet methConstrains;
|
||||||
|
@ -3,7 +3,6 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -238,9 +237,6 @@ public class TestComplete {
|
|||||||
@Test
|
@Test
|
||||||
//@Ignore("This is too complex")
|
//@Ignore("This is too complex")
|
||||||
public void matrixTest() throws Exception {
|
public void matrixTest() throws Exception {
|
||||||
try(var f = new FileWriter("/tmp/output")){
|
|
||||||
f.append("hallo");
|
|
||||||
}
|
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
|
||||||
var matrix = classFiles.get("Matrix");
|
var matrix = classFiles.get("Matrix");
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class JavaTXCompilerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void importTest() throws IOException, ClassNotFoundException {
|
public void importTest() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory + "OrConsTest.jav"));
|
execute(new File(rootDirectory + "Import.jav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user