Compare commits
5 Commits
3d2b935c60
...
9c2c6a3ea9
Author | SHA1 | Date | |
---|---|---|---|
|
9c2c6a3ea9 | ||
|
a7ad4fa984 | ||
|
fcda301b1e | ||
|
2aa3997f17 | ||
|
7e37497740 |
9
README.md
Normal file
9
README.md
Normal 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
|
5
pom.xml
5
pom.xml
@ -53,9 +53,8 @@ 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>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
<source>22</source>
|
||||||
<source>21</source>
|
<target>22</target>
|
||||||
<target>21</target>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -73,5 +73,5 @@ public class Constraint<A> extends HashSet<A> {
|
|||||||
public String toStringBase() {
|
public String toStringBase() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,4 +127,5 @@ public class ConstraintSet<A> {
|
|||||||
public Set<A> getUndConstraints() {
|
public Set<A> getUndConstraints() {
|
||||||
return undConstraints;
|
return undConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -136,8 +136,12 @@ public class Pair implements Serializable
|
|||||||
public boolean OperatorSmallerDot() {
|
public boolean OperatorSmallerDot() {
|
||||||
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<>();
|
||||||
constraints.map((Pair p) -> {
|
constraints.map((Pair p) -> {
|
||||||
|
@ -5,13 +5,17 @@ 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.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
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 {
|
||||||
|
|
||||||
@ -24,16 +28,80 @@ public class TYPE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet getConstraints() {
|
public ConstraintSet getConstraints() {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet<Pair> 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,6 +3,7 @@ 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;
|
||||||
@ -237,6 +238,9 @@ 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 + "Import.jav"));
|
execute(new File(rootDirectory + "OrConsTest.jav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
20
src/test/resources/javFiles/OrConsTest.jav
Normal file
20
src/test/resources/javFiles/OrConsTest.jav
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user