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>
|
||||
<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>
|
||||
|
@ -73,5 +73,5 @@ public class Constraint<A> extends HashSet<A> {
|
||||
public String toStringBase() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -127,4 +127,5 @@ public class ConstraintSet<A> {
|
||||
public Set<A> getUndConstraints() {
|
||||
return undConstraints;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) -> {
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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
|
||||
|
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