forked from JavaTX/JavaCompilerCore
Compare commits
21 Commits
parseSigna
...
unif23
Author | SHA1 | Date | |
---|---|---|---|
|
d6a79ea3a1 | ||
|
1f909f13ee | ||
|
be6f4bd578 | ||
|
478efd5649 | ||
|
c73e57cf2b | ||
|
ce29f4bcf1 | ||
|
42821f3215 | ||
|
f68afc88a6 | ||
|
82061474b2 | ||
|
d849bc127f | ||
|
6815d8fc0a | ||
|
317f8b1aad | ||
|
79335449d0 | ||
|
14606a846e | ||
2b67230a15 | |||
|
29b05b56cc | ||
|
08b9fc0ea3 | ||
|
070dd16999 | ||
|
9d7e46925d | ||
|
d780d322f0 | ||
|
867f3d39e8 |
11
Makefile
Normal file
11
Makefile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
full:
|
||||||
|
mvn -DskipTests package
|
||||||
|
cp target/JavaTXcompiler-0.1-jar-with-dependencies.jar target/JavaTXcompiler-0.1-jar-with-dependencies_full.jar
|
||||||
|
|
||||||
|
NoMinMax:
|
||||||
|
mvn -DskipTests package
|
||||||
|
cp target/JavaTXcompiler-0.1-jar-with-dependencies.jar target/JavaTXcompiler-0.1-jar-with-dependencies_NoMinMax.jar
|
||||||
|
|
||||||
|
NoOpt:
|
||||||
|
mvn -DskipTests package
|
||||||
|
cp target/JavaTXcompiler-0.1-jar-with-dependencies.jar target/JavaTXcompiler-0.1-jar-with-dependencies_NoOpt.jar
|
@@ -1,4 +1,4 @@
|
|||||||
import java.util.Vector;
|
//import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Float;
|
import java.lang.Float;
|
||||||
//import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
@@ -6,21 +6,11 @@ import java.lang.Float;
|
|||||||
|
|
||||||
public class Scalar extends Vector<Integer> {
|
public class Scalar extends Vector<Integer> {
|
||||||
|
|
||||||
Scalar(v) {
|
|
||||||
Integer i;
|
|
||||||
i = 0;
|
|
||||||
while(i < v.size()) {
|
|
||||||
this.add(v.elementAt(i));
|
|
||||||
i=i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mul(v) {
|
mul(v) {
|
||||||
var ret = 0;
|
var ret = 0;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
ret = ret + this.elementAt(i) * v.elementAt(i);
|
ret = ret + this.elementAt(i) * v.elementAt(i);
|
||||||
i = i+1;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
import java.lang.String;
|
|
||||||
|
|
||||||
class TXGenerics {
|
|
||||||
a;
|
|
||||||
b;
|
|
||||||
|
|
||||||
test() {
|
|
||||||
var c = new Cycle();
|
|
||||||
c.m(a, b);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -5,7 +5,7 @@ public class TestContraVariant {
|
|||||||
x = y;
|
x = y;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
return m(x);
|
return m(x);
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
public class TestTwoCalls {
|
public class TestTwoCalls {
|
||||||
|
|
||||||
// <O> O -> O
|
|
||||||
id(b) {
|
id(b) {
|
||||||
var c = b;
|
var c = b;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <T, S> (S, T) -> T
|
|
||||||
main(x,y) {
|
main(x,y) {
|
||||||
id(x);
|
id(x);
|
||||||
return id(y);
|
return id(y);
|
||||||
|
@@ -1000,7 +1000,7 @@ public class Codegen {
|
|||||||
private void generateConstructor(TargetConstructor constructor) {
|
private void generateConstructor(TargetConstructor constructor) {
|
||||||
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||||
if (constructor.txGenerics() != null)
|
if (constructor.txGenerics() != null)
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(constructor.getTXSignature())));
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(null, mv, 1);
|
var state = new State(null, mv, 1);
|
||||||
@@ -1027,7 +1027,7 @@ public class Codegen {
|
|||||||
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
||||||
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
||||||
if (method.txSignature() != null) {
|
if (method.txSignature() != null) {
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(method.getTXSignature())));
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(method.getDescriptor());
|
System.out.println(method.getDescriptor());
|
||||||
@@ -1044,14 +1044,11 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String generateSignature(TargetClass clazz, Set<TargetGeneric> generics) {
|
private static String generateSignature(TargetClass clazz, Set<TargetGeneric> generics) {
|
||||||
String ret = "";
|
String ret = "<";
|
||||||
if (generics.size() > 0) {
|
for (var generic : generics) {
|
||||||
ret += "<";
|
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
||||||
for (var generic : generics) {
|
|
||||||
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
|
||||||
}
|
|
||||||
ret += ">";
|
|
||||||
}
|
}
|
||||||
|
ret += ">";
|
||||||
ret += clazz.superType().toDescriptor();
|
ret += clazz.superType().toDescriptor();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -1063,7 +1060,7 @@ public class Codegen {
|
|||||||
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
||||||
);
|
);
|
||||||
if (clazz.txGenerics() != null)
|
if (clazz.txGenerics() != null)
|
||||||
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));
|
cw.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(generateSignature(clazz, clazz.txGenerics()))));
|
||||||
|
|
||||||
clazz.fields().forEach(this::generateField);
|
clazz.fields().forEach(this::generateField);
|
||||||
clazz.constructors().forEach(this::generateConstructor);
|
clazz.constructors().forEach(this::generateConstructor);
|
||||||
|
@@ -3,13 +3,10 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
|
|
||||||
public class JavaTXSignatureAttribute extends Attribute {
|
public class JavaTXSignatureAttribute extends Attribute {
|
||||||
public String signature;
|
final int signature;
|
||||||
|
|
||||||
public JavaTXSignatureAttribute() {
|
protected JavaTXSignatureAttribute(int signature) {
|
||||||
super("JavaTXSignature");
|
super("JavaTXSignature");
|
||||||
}
|
|
||||||
protected JavaTXSignatureAttribute(String signature) {
|
|
||||||
this();
|
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,14 +14,13 @@ public class JavaTXSignatureAttribute extends Attribute {
|
|||||||
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
||||||
var data = new byte[length];
|
var data = new byte[length];
|
||||||
System.arraycopy(classReader.b, offset, data, 0, length);
|
System.arraycopy(classReader.b, offset, data, 0, length);
|
||||||
var constantPoolOffset = data[0] << 8 | data[1];
|
return new JavaTXSignatureAttribute(data[0] << 8 | data[1]);
|
||||||
return new JavaTXSignatureAttribute((String) classReader.readConst(constantPoolOffset, charBuffer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
||||||
var data = new ByteVector();
|
var data = new ByteVector();
|
||||||
data.putShort(classWriter.newConst(this.signature));
|
data.putShort(this.signature);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -58,6 +58,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -74,6 +75,7 @@ public class JavaTXCompiler {
|
|||||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||||
private final DirectoryClassLoader classLoader;
|
private final DirectoryClassLoader classLoader;
|
||||||
|
static Writer statistics;
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile), null);
|
this(Arrays.asList(sourceFile), null);
|
||||||
@@ -86,6 +88,8 @@ public class JavaTXCompiler {
|
|||||||
this(sourceFiles, null);
|
this(sourceFiles, null);
|
||||||
}
|
}
|
||||||
public JavaTXCompiler(List<File> sources, List<File> contextPath) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(List<File> sources, List<File> contextPath) throws IOException, ClassNotFoundException {
|
||||||
|
statistics = new FileWriter(new File(System.getProperty("user.dir") + "/" + sources.get(0).getName() + "_"+ new Timestamp(System.currentTimeMillis())));
|
||||||
|
statistics.write("test");
|
||||||
if(contextPath == null || contextPath.isEmpty()){
|
if(contextPath == null || contextPath.isEmpty()){
|
||||||
//When no contextPaths are given, the working directory is the sources root
|
//When no contextPaths are given, the working directory is the sources root
|
||||||
contextPath = Lists.newArrayList(new File(System.getProperty("user.dir")));
|
contextPath = Lists.newArrayList(new File(System.getProperty("user.dir")));
|
||||||
@@ -578,6 +582,7 @@ public class JavaTXCompiler {
|
|||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
||||||
TypeUnify unify = new TypeUnify();
|
TypeUnify unify = new TypeUnify();
|
||||||
|
unify.statistics = statistics;
|
||||||
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
||||||
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
||||||
for (SourceFile sf : this.sourceFiles.values()) {
|
for (SourceFile sf : this.sourceFiles.values()) {
|
||||||
@@ -730,6 +735,7 @@ public class JavaTXCompiler {
|
|||||||
System.out.println("Constraints for Generated Generics: " + " ???");
|
System.out.println("Constraints for Generated Generics: " + " ???");
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
statistics.close();
|
||||||
return li.getResults();
|
return li.getResults();
|
||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
@@ -765,6 +771,7 @@ public class JavaTXCompiler {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
}
|
}
|
||||||
|
statistics.close();
|
||||||
return results.stream()
|
return results.stream()
|
||||||
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons)))))
|
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons)))))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@@ -49,17 +49,4 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return this.gtvs.toString();
|
return this.gtvs.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
GenericDeclarationList that = (GenericDeclarationList) o;
|
|
||||||
return gtvs.equals(that.gtvs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(gtvs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entspricht einem GenericTypeVar, jedoch mit Bounds
|
* Entspricht einem GenericTypeVar, jedoch mit Bounds
|
||||||
@@ -46,7 +45,7 @@ public class GenericTypeVar extends SyntaxTreeNode
|
|||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "BoGTV " + this.name + " " + this.bounds;
|
return "BoGTV " + this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
@@ -62,17 +61,4 @@ public class GenericTypeVar extends SyntaxTreeNode
|
|||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
GenericTypeVar that = (GenericTypeVar) o;
|
|
||||||
return bounds.equals(that.bounds) && name.equals(that.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(bounds, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,19 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.factory;
|
package de.dhbwstuttgart.syntaxtree.factory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Type;
|
import java.util.ArrayList;
|
||||||
import java.nio.file.Files;
|
import java.util.Arrays;
|
||||||
import java.nio.file.Path;
|
import java.util.HashSet;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.JavaTXSignatureAttribute;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
@@ -19,14 +22,7 @@ import de.dhbwstuttgart.syntaxtree.*;
|
|||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
|
||||||
import de.dhbwstuttgart.util.Pair;
|
|
||||||
import javassist.bytecode.SignatureAttribute;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.objectweb.asm.*;
|
|
||||||
import org.objectweb.asm.signature.SignatureReader;
|
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anmerkung:
|
* Anmerkung:
|
||||||
@@ -36,76 +32,21 @@ import org.objectweb.asm.signature.SignatureVisitor;
|
|||||||
public class ASTFactory {
|
public class ASTFactory {
|
||||||
|
|
||||||
public static ClassOrInterface createClass(java.lang.Class jreClass){
|
public static ClassOrInterface createClass(java.lang.Class jreClass){
|
||||||
|
|
||||||
// TODO Inner classes
|
|
||||||
|
|
||||||
var methodSignatures = new HashMap<Pair<String, String>, String>();
|
|
||||||
String classSignature = null;
|
|
||||||
|
|
||||||
// Load class with asm to figure out if there's a JavaTX signature
|
|
||||||
try {
|
|
||||||
var path = jreClass.getName().replace('.', '/') + ".class";
|
|
||||||
var classLoader = jreClass.getClassLoader();
|
|
||||||
if (classLoader != null) {
|
|
||||||
var bytes = IOUtils.toByteArray(Objects.requireNonNull(classLoader.getResourceAsStream(path)));
|
|
||||||
var classReader = new ClassReader(bytes);
|
|
||||||
var classVisitor = new ClassVisitor(Opcodes.ASM7) {
|
|
||||||
String classSignature;
|
|
||||||
@Override
|
|
||||||
public void visitAttribute(Attribute attribute) {
|
|
||||||
if (attribute.type.equals("JavaTXSignature")) {
|
|
||||||
classSignature = ((JavaTXSignatureAttribute) attribute).signature;
|
|
||||||
}
|
|
||||||
super.visitAttribute(attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
|
||||||
classSignature = signature;
|
|
||||||
super.visit(version, access, name, signature, superName, interfaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
|
||||||
|
|
||||||
methodSignatures.put(new Pair<>(name, descriptor), signature);
|
|
||||||
return new MethodVisitor(Opcodes.ASM7) {
|
|
||||||
@Override
|
|
||||||
public void visitAttribute(Attribute attribute) {
|
|
||||||
if (attribute.type.equals("JavaTXSignature")) {
|
|
||||||
methodSignatures.put(new Pair<>(name, descriptor), ((JavaTXSignatureAttribute) attribute).signature);
|
|
||||||
}
|
|
||||||
super.visitAttribute(attribute);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
classReader.accept(classVisitor, new Attribute[]{new JavaTXSignatureAttribute()}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
|
||||||
classSignature = classVisitor.classSignature;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Skip
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaClassName name = new JavaClassName(jreClass.getName());
|
JavaClassName name = new JavaClassName(jreClass.getName());
|
||||||
List<Method> methoden = new ArrayList<>();
|
List<Method> methoden = new ArrayList<>();
|
||||||
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
||||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
for(java.lang.reflect.Constructor constructor : jreClass.getDeclaredConstructors()){
|
||||||
var signature = methodSignatures.get(new Pair<>(constructor.getName(), org.objectweb.asm.Type.getConstructorDescriptor(constructor)));
|
createConstructor(constructor, jreClass).map(c -> konstruktoren.add(c));
|
||||||
createConstructor(constructor, signature, jreClass).map(c -> konstruktoren.add(c));
|
|
||||||
}
|
}
|
||||||
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||||
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||||
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
||||||
allInheritedMethods.removeAll(allDeclaredMethods);
|
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||||
for(java.lang.reflect.Method method : allDeclaredMethods){
|
for(java.lang.reflect.Method method : allDeclaredMethods){
|
||||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
methoden.add(createMethod(method, jreClass, false));
|
||||||
methoden.add(createMethod(method, signature, jreClass, false));
|
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method method : allInheritedMethods){
|
for(java.lang.reflect.Method method : allInheritedMethods){
|
||||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
methoden.add(createMethod(method, jreClass, true));
|
||||||
methoden.add(createMethod(method, signature, jreClass, true));
|
|
||||||
}
|
}
|
||||||
List<Field> felder = new ArrayList<>();
|
List<Field> felder = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||||
@@ -131,8 +72,7 @@ public class ASTFactory {
|
|||||||
for(Type jreInterface : jreClass.getGenericInterfaces()){
|
for(Type jreInterface : jreClass.getGenericInterfaces()){
|
||||||
implementedInterfaces.add((RefType) createType(jreInterface));
|
implementedInterfaces.add((RefType) createType(jreInterface));
|
||||||
}
|
}
|
||||||
|
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
||||||
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null, classSignature);
|
|
||||||
|
|
||||||
Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
||||||
|
|
||||||
@@ -147,7 +87,7 @@ public class ASTFactory {
|
|||||||
// return createClass(classType).getType();
|
// return createClass(classType).getType();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, String signature, Class inClass) {
|
private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, Class inClass) {
|
||||||
String name = constructor.getName();
|
String name = constructor.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
||||||
Parameter[] jreParams = constructor.getParameters();
|
Parameter[] jreParams = constructor.getParameters();
|
||||||
@@ -161,7 +101,7 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||||
GenericDeclarationList gtvDeclarations = createGenerics(constructor.getTypeParameters(), inClass, constructor.getName(), signature);
|
GenericDeclarationList gtvDeclarations = createGenerics(constructor.getTypeParameters(), inClass, constructor.getName());
|
||||||
Token offset = new NullToken();
|
Token offset = new NullToken();
|
||||||
int modifier = constructor.getModifiers();
|
int modifier = constructor.getModifiers();
|
||||||
|
|
||||||
@@ -172,7 +112,7 @@ public class ASTFactory {
|
|||||||
return Optional.of(new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */));
|
return Optional.of(new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Method createMethod(java.lang.reflect.Method jreMethod, String signature, java.lang.Class inClass, Boolean isInherited){
|
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||||
String name = jreMethod.getName();
|
String name = jreMethod.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
Type jreRetType;
|
Type jreRetType;
|
||||||
@@ -193,142 +133,19 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName(), signature);
|
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
||||||
Token offset = new NullToken();
|
Token offset = new NullToken();
|
||||||
|
|
||||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName, String signature) {
|
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
||||||
if (signature == null) {
|
List<de.dhbwstuttgart.syntaxtree.GenericTypeVar> gtvs = new ArrayList<>();
|
||||||
List<de.dhbwstuttgart.syntaxtree.GenericTypeVar> gtvs = new ArrayList<>();
|
for(TypeVariable jreTV : typeParameters){
|
||||||
for(TypeVariable jreTV : typeParameters){
|
de.dhbwstuttgart.syntaxtree.GenericTypeVar gtv = createGeneric(jreTV, jreTV.getName(), context, methodName);
|
||||||
de.dhbwstuttgart.syntaxtree.GenericTypeVar gtv = createGeneric(jreTV, jreTV.getName(), context, methodName);
|
gtvs.add(gtv);
|
||||||
gtvs.add(gtv);
|
|
||||||
}
|
|
||||||
return new GenericDeclarationList(gtvs, new NullToken());
|
|
||||||
} else {
|
|
||||||
var res = createGenerics(signature);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
return new GenericDeclarationList(gtvs,new NullToken());
|
||||||
|
|
||||||
public static GenericDeclarationList createGenerics(String signature) {
|
|
||||||
if (signature == null) return new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
|
||||||
|
|
||||||
var gtvs = new ArrayList<GenericTypeVar>();
|
|
||||||
var signatureVisitor = new SignatureVisitor(Opcodes.ASM7) {
|
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
|
|
||||||
final Stack<RefTypeOrTPHOrWildcardOrGeneric> bound = new Stack<>();
|
|
||||||
final Stack<RefType> classTypes = new Stack<>();
|
|
||||||
|
|
||||||
// All hail the mighty visitor pattern
|
|
||||||
final SignatureVisitor doNothing = new SignatureVisitor(Opcodes.ASM7) {};
|
|
||||||
|
|
||||||
char wildcard = '=';
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignatureVisitor visitSuperclass() {
|
|
||||||
return doNothing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignatureVisitor visitParameterType() {
|
|
||||||
return doNothing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignatureVisitor visitReturnType() {
|
|
||||||
return doNothing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignatureVisitor visitExceptionType() {
|
|
||||||
return doNothing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitFormalTypeParameter(String name) {
|
|
||||||
bounds = new ArrayList<>();
|
|
||||||
gtvs.add(new GenericTypeVar(name, bounds, new NullToken(), new NullToken()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitTypeVariable(String name) {
|
|
||||||
var refType = new GenericRefType(name, new NullToken());
|
|
||||||
if (classTypes.isEmpty()) {
|
|
||||||
((List<RefTypeOrTPHOrWildcardOrGeneric>) gtvs.get(gtvs.size() - 1).getBounds()).add(refType);
|
|
||||||
} else {
|
|
||||||
pushType(refType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitClassType(String name) {
|
|
||||||
var refType = new RefType(new JavaClassName(name.replaceAll("/", ".")), new ArrayList<>(), new NullToken());
|
|
||||||
classTypes.push(refType);
|
|
||||||
pushType(refType);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pushType(RefTypeOrTPHOrWildcardOrGeneric refType) {
|
|
||||||
if (wildcard == SignatureVisitor.SUPER) {
|
|
||||||
bound.push(new SuperWildcardType(refType, new NullToken()));
|
|
||||||
} else if (wildcard == SignatureVisitor.EXTENDS) {
|
|
||||||
bound.push(new ExtendsWildcardType(refType, new NullToken()));
|
|
||||||
} else {
|
|
||||||
bound.push(refType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignatureVisitor visitTypeArgument(char wildcard) {
|
|
||||||
this.wildcard = wildcard;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean equals(RefTypeOrTPHOrWildcardOrGeneric a, RefTypeOrTPHOrWildcardOrGeneric b) {
|
|
||||||
if (b instanceof SuperWildcardType wc)
|
|
||||||
return equals(a, wc.getInnerType());
|
|
||||||
else if (b instanceof ExtendsWildcardType wc)
|
|
||||||
return equals(a, wc.getInnerType());
|
|
||||||
return a == b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitEnd() {
|
|
||||||
wildcard = '=';
|
|
||||||
var classType = (RefType) classTypes.pop();
|
|
||||||
if (!classTypes.isEmpty()) {
|
|
||||||
var next = classTypes.peek();
|
|
||||||
var par = bound.pop();
|
|
||||||
var toAdd = new ArrayList<RefTypeOrTPHOrWildcardOrGeneric>();
|
|
||||||
while (!equals(next, par)) {
|
|
||||||
toAdd.add(par);
|
|
||||||
par = bound.pop();
|
|
||||||
}
|
|
||||||
var element = par;
|
|
||||||
if (par instanceof WildcardType wc) {
|
|
||||||
element = wc.getInnerType();
|
|
||||||
}
|
|
||||||
Collections.reverse(toAdd);
|
|
||||||
((RefType) element).getParaList().addAll(toAdd);
|
|
||||||
|
|
||||||
bound.push(par);
|
|
||||||
} else {
|
|
||||||
if (bound.peek() != classType) {
|
|
||||||
classType.getParaList().add(bound.pop());
|
|
||||||
bounds.add(classType);
|
|
||||||
} else {
|
|
||||||
bounds.add(bound.pop());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var sr = new SignatureReader(signature);
|
|
||||||
sr.accept(signatureVisitor);
|
|
||||||
|
|
||||||
return new GenericDeclarationList(gtvs, new NullToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type){
|
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type){
|
||||||
|
@@ -5,8 +5,6 @@ import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt eine Wildcard mit oberer Grenze dar.
|
* Stellt eine Wildcard mit oberer Grenze dar.
|
||||||
* z.B. void test(? extends Number var){..}
|
* z.B. void test(? extends Number var){..}
|
||||||
@@ -56,16 +54,9 @@ public class ExtendsWildcardType extends WildcardType{
|
|||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(this.innerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
// TODO Auto-generated method stub
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return false;
|
||||||
ExtendsWildcardType that = (ExtendsWildcardType) o;
|
|
||||||
return that.innerType.equals(this.innerType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,6 @@ import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
@@ -35,20 +33,14 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
// TODO Auto-generated method stub
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return false;
|
||||||
GenericRefType that = (GenericRefType) o;
|
}
|
||||||
return name.equals(that.name);
|
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "GTV " + this.name;
|
return "GTV " + this.name;
|
||||||
|
@@ -2,12 +2,9 @@ package de.dhbwstuttgart.syntaxtree.type;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt eine Wildcard mit unterer Grenze dar.
|
* Stellt eine Wildcard mit unterer Grenze dar.
|
||||||
* z.B. void test(? super Integer var){..}
|
* z.B. void test(? super Integer var){..}
|
||||||
@@ -68,16 +65,9 @@ public class SuperWildcardType extends WildcardType{
|
|||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(this.innerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
// TODO Auto-generated method stub
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return false;
|
||||||
SuperWildcardType that = (SuperWildcardType) o;
|
|
||||||
return that.innerType.equals(this.innerType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,10 +16,8 @@ import de.dhbwstuttgart.target.tree.expression.TargetExpression;
|
|||||||
import de.dhbwstuttgart.target.tree.type.*;
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
import org.objectweb.asm.Attribute;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CyclicBarrier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -172,6 +170,7 @@ public class ASTToTargetAST {
|
|||||||
for (var pair : simplifiedConstraints) {
|
for (var pair : simplifiedConstraints) {
|
||||||
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
||||||
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
||||||
|
typeVariables.add(pair.right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +196,7 @@ public class ASTToTargetAST {
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric T2 = superType;
|
RefTypeOrTPHOrWildcardOrGeneric T2 = superType;
|
||||||
if (T2 instanceof TypePlaceholder tph) T2 = equality.getOrDefault(tph, tph);
|
if (T2 instanceof TypePlaceholder tph) T2 = equality.getOrDefault(tph, tph);
|
||||||
|
|
||||||
System.out.println("T1s: " + T1s + " T2: " + T2);
|
System.out.println("T1s: " + T1s + "\nT2: " + T2);
|
||||||
//Ende
|
//Ende
|
||||||
|
|
||||||
superType = methodCall.receiverType;
|
superType = methodCall.receiverType;
|
||||||
@@ -212,7 +211,7 @@ public class ASTToTargetAST {
|
|||||||
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
|
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
|
||||||
if (optMethod.isEmpty()) return;
|
if (optMethod.isEmpty()) return;
|
||||||
var method = optMethod.get();
|
var method = optMethod.get();
|
||||||
var generics = generics(owner, method).txGenerics();
|
var generics = generics(owner, method).javaGenerics();
|
||||||
|
|
||||||
// transitive and
|
// transitive and
|
||||||
var all = transitiveClosure(generics);
|
var all = transitiveClosure(generics);
|
||||||
@@ -227,24 +226,24 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
// Loop from hell
|
// Loop from hell
|
||||||
outer:
|
outer:
|
||||||
for (var R1 : typeVariables) {
|
for (var tph : typeVariables) {
|
||||||
if (typeVariablesOfClass.contains(R1)) continue;
|
if (typeVariablesOfClass.contains(tph)) continue;
|
||||||
for (var generic : all) {
|
for (var generic : all) {
|
||||||
if (!(generic.getRight() instanceof TypePlaceholder type))
|
if (!(generic.getRight() instanceof TypePlaceholder type))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (var pair : simplifiedConstraints) {
|
for (var pair : simplifiedConstraints) {
|
||||||
if (!(pair.left.equals(R1) && pair.right.equals(generic.getLeft())))
|
if (!(pair.left.equals(tph) && pair.right.equals(generic.getLeft())))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (var R2 : typeVariables) {
|
for (var tph2 : typeVariables) {
|
||||||
for (var pair2 : simplifiedConstraints) {
|
for (var pair2 : simplifiedConstraints) {
|
||||||
if (!(pair2.right.equals(R2) && pair2.left.equals(type)))
|
if (!(pair2.right.equals(tph2) && pair2.left.equals(type)))
|
||||||
continue;
|
continue;
|
||||||
if (R1.equals(R2)) continue;
|
if (tph.equals(tph2)) continue;
|
||||||
if (!T1s.contains(R1) || !R2.equals(T2)) continue;
|
if (!T1s.contains(tph) || !tph2.equals(T2)) continue;
|
||||||
|
|
||||||
var newPair = new PairTPHsmallerTPH(R1, R2);
|
var newPair = new PairTPHsmallerTPH(tph, tph2);
|
||||||
newPairs.add(newPair);
|
newPairs.add(newPair);
|
||||||
|
|
||||||
if (!containsRelation(result, newPair))
|
if (!containsRelation(result, newPair))
|
||||||
@@ -269,7 +268,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Assign assign) {
|
public void visit(Assign assign) {
|
||||||
superType = assign.rightSide.getType();
|
superType = assign.lefSide.getType();
|
||||||
assign.rightSide.accept(this);
|
assign.rightSide.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,6 +521,9 @@ public class ASTToTargetAST {
|
|||||||
super.visit(methodCall);
|
super.visit(methodCall);
|
||||||
typeVariables.addAll(findTypeVariables(methodCall.getType(), equality));
|
typeVariables.addAll(findTypeVariables(methodCall.getType(), equality));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Assign assign) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,11 +554,10 @@ public class ASTToTargetAST {
|
|||||||
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, classGenerics.userDefinedGenerics, txTypeVariablesOfClass, txResult, txEquality);
|
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, classGenerics.userDefinedGenerics, txTypeVariablesOfClass, txResult, txEquality);
|
||||||
|
|
||||||
{ // Java Generics
|
{ // Java Generics
|
||||||
eliminateTransitives(javaResult);
|
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
|
|
||||||
eliminateCycles(javaResult, equality, referenced);
|
eliminateCycles(javaResult, equality, referenced);
|
||||||
eliminateInfima(javaResult, equality);
|
eliminateInfima(javaResult, equality, referenced);
|
||||||
|
|
||||||
var usedTphs = new HashSet<TypePlaceholder>();
|
var usedTphs = new HashSet<TypePlaceholder>();
|
||||||
// For eliminating inner type variables we need to figure out which ones are actually used
|
// For eliminating inner type variables we need to figure out which ones are actually used
|
||||||
@@ -570,13 +571,11 @@ public class ASTToTargetAST {
|
|||||||
eliminateInnerTypeVariables(referenced, javaResult);
|
eliminateInnerTypeVariables(referenced, javaResult);
|
||||||
equalizeTypeVariables(javaResult, equality);
|
equalizeTypeVariables(javaResult, equality);
|
||||||
usedTPHsOfMethods.put(method, usedTphs);
|
usedTPHsOfMethods.put(method, usedTphs);
|
||||||
addMissingObjectBounds(javaResult, genericsOfClass);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
// JavaTX Generics
|
// JavaTX Generics
|
||||||
eliminateTransitives(txResult);
|
eliminateInfima(txResult, txEquality, referenced);
|
||||||
eliminateInfima(txResult, txEquality);
|
|
||||||
|
|
||||||
for (var param : method.getParameterList().getFormalparalist()) {
|
for (var param : method.getParameterList().getFormalparalist()) {
|
||||||
referenced.addAll(findTypeVariables(param.getType(), txEquality));
|
referenced.addAll(findTypeVariables(param.getType(), txEquality));
|
||||||
@@ -585,36 +584,12 @@ public class ASTToTargetAST {
|
|||||||
referenced.addAll(txTypeVariablesOfClass);
|
referenced.addAll(txTypeVariablesOfClass);
|
||||||
|
|
||||||
eliminateInnerTypeVariables(referenced, txResult);
|
eliminateInnerTypeVariables(referenced, txResult);
|
||||||
addMissingObjectBounds(txResult, txGenericsOfClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void eliminateChain(Set<ResultPair<?, ?>> result, List<TypePlaceholder> chain) {
|
|
||||||
for (var pair : new HashSet<>(result)) {
|
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph && chain.get(chain.size() - 1).equals(ptph.left)) {
|
|
||||||
if (chain.contains(ptph.right)) return;
|
|
||||||
var copy = new ArrayList<>(chain);
|
|
||||||
copy.add(ptph.right);
|
|
||||||
if (copy.size() > 2)
|
|
||||||
result.remove(new PairTPHsmallerTPH(chain.get(0), ptph.right));
|
|
||||||
eliminateChain(result, copy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void eliminateTransitives(Set<ResultPair<?,?>> result) {
|
|
||||||
for (var pair : new HashSet<>(result)) if (pair instanceof PairTPHsmallerTPH ptph) {
|
|
||||||
var first = ptph.left;
|
|
||||||
var chain = new ArrayList<TypePlaceholder>();
|
|
||||||
chain.add(ptph.left);
|
|
||||||
chain.add(ptph.right);
|
|
||||||
eliminateChain(result, chain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void findAllBounds(RefTypeOrTPHOrWildcardOrGeneric type, Set<ResultPair<?, ?>> generics, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void findAllBounds(RefTypeOrTPHOrWildcardOrGeneric type, Set<ResultPair<?, ?>> generics, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
if (type instanceof TypePlaceholder tph) {
|
if (type instanceof TypePlaceholder tph) {
|
||||||
tph = equality.getOrDefault(tph, tph);
|
tph = equality.getOrDefault(tph, tph);
|
||||||
@@ -659,86 +634,34 @@ public class ASTToTargetAST {
|
|||||||
findAllBounds(field.getType(), txResult, txEquality);
|
findAllBounds(field.getType(), txResult, txEquality);
|
||||||
}
|
}
|
||||||
|
|
||||||
eliminateTransitives(javaResult);
|
|
||||||
eliminateTransitives(txResult);
|
|
||||||
System.out.println(javaResult);
|
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
eliminateCycles(javaResult, equality, referenced);
|
eliminateCycles(javaResult, equality, referenced);
|
||||||
eliminateInfima(javaResult, equality);
|
eliminateInfima(javaResult, equality, referenced);
|
||||||
var txReferenced = new HashSet<TypePlaceholder>();
|
var txReferenced = new HashSet<TypePlaceholder>();
|
||||||
eliminateInfima(txResult, txEquality);
|
eliminateInfima(txResult, txEquality, txReferenced);
|
||||||
|
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
||||||
equalizeTypeVariables(javaResult, equality);
|
equalizeTypeVariables(javaResult, equality);
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, txReferenced);
|
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, txReferenced);
|
||||||
|
|
||||||
addMissingObjectBounds(javaResult, null);
|
|
||||||
addMissingObjectBounds(txResult, null);
|
|
||||||
|
|
||||||
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult + ", " + javaResult);
|
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult + ", " + javaResult);
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMissingObjectBounds(Set<ResultPair<?,?>> result, Set<ResultPair<?, ?>> filter) {
|
|
||||||
outer: for (var p1 : new HashSet<>(result)) {
|
|
||||||
if (p1 instanceof PairTPHsmallerTPH ptph) {
|
|
||||||
for (var p2 : new HashSet<>(result)) {
|
|
||||||
if (ptph.right.equals(p2.getLeft()))
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
if (filter == null || filter.stream().noneMatch((pair) -> pair.getLeft().equals(ptph.right)))
|
|
||||||
result.add(new PairTPHequalRefTypeOrWildcardType(ptph.right, OBJECT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
|
System.out.println(input);
|
||||||
for (var pair : new HashSet<>(input)) {
|
for (var pair : new HashSet<>(input)) {
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph) {
|
if (pair instanceof PairTPHsmallerTPH ptph) {
|
||||||
var chain = new ArrayList<TypePlaceholder>();
|
System.out.println(pair + " " + ptph.left.getVariance() + " " + ptph.right.getVariance());
|
||||||
chain.add(ptph.left);
|
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
||||||
chain.add(ptph.right);
|
addToEquality(equality, ptph.left, ptph.right);
|
||||||
|
input.remove(ptph);
|
||||||
outer: while (true) {
|
for (var pair2 : new HashSet<>(simplifiedConstraints)) {
|
||||||
var added = false;
|
if (pair2.right.equals(ptph.left)) {
|
||||||
for (var pair2 : input) {
|
simplifiedConstraints.remove(pair2);
|
||||||
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.left.equals(chain.get(chain.size() - 1))) {
|
simplifiedConstraints.add(new PairTPHsmallerTPH(pair2.left, ptph.right));
|
||||||
if (chain.contains(ptph2.right)) break outer;
|
|
||||||
chain.add(ptph2.right);
|
|
||||||
added = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!added) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var variance = chain.get(0).getVariance();
|
|
||||||
if (variance != 1) continue;
|
|
||||||
var index = 0;
|
|
||||||
for (var tph : chain) {
|
|
||||||
if (variance == 1 && tph.getVariance() == -1) {
|
|
||||||
variance = -1;
|
|
||||||
}
|
|
||||||
if (variance == -1 && tph.getVariance() == 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (variance == 1) continue;
|
|
||||||
|
|
||||||
var start = chain.get(0);
|
|
||||||
var prev = start;
|
|
||||||
for (var i = 1; i < index; i++) {
|
|
||||||
var cur = chain.get(i);
|
|
||||||
addToEquality(equality, cur, start);
|
|
||||||
input.remove(new PairTPHsmallerTPH(prev, chain.get(i)));
|
|
||||||
for (var pair2 : new HashSet<>(input)) {
|
|
||||||
// TODO Maybe this would be unnecessary if we were to add the = constraints later on
|
|
||||||
if (pair2 instanceof PairTPHequalRefTypeOrWildcardType && pair2.getLeft().equals(cur)) {
|
|
||||||
input.remove(pair2);
|
|
||||||
input.add(new PairTPHequalRefTypeOrWildcardType(start, pair2.getRight()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prev = chain.get(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -816,15 +739,6 @@ public class ASTToTargetAST {
|
|||||||
var cycles = findCycles(input);
|
var cycles = findCycles(input);
|
||||||
for (var cycle : cycles) {
|
for (var cycle : cycles) {
|
||||||
var newTph = TypePlaceholder.fresh(new NullToken());
|
var newTph = TypePlaceholder.fresh(new NullToken());
|
||||||
var variance = cycle.get(0).getVariance();
|
|
||||||
for (var tph : cycle) {
|
|
||||||
if (tph.getVariance() != variance) {
|
|
||||||
variance = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newTph.setVariance(variance);
|
|
||||||
|
|
||||||
referenced.add(newTph);
|
referenced.add(newTph);
|
||||||
addToPairs(input, new PairTPHequalRefTypeOrWildcardType(newTph, OBJECT));
|
addToPairs(input, new PairTPHequalRefTypeOrWildcardType(newTph, OBJECT));
|
||||||
cycle.add(cycle.get(0)); // Make it a complete cycle
|
cycle.add(cycle.get(0)); // Make it a complete cycle
|
||||||
@@ -838,7 +752,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eliminateInfima(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void eliminateInfima(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality, Set<TypePlaceholder> referenced) {
|
||||||
var foundInfima = false;
|
var foundInfima = false;
|
||||||
do {
|
do {
|
||||||
foundInfima = false;
|
foundInfima = false;
|
||||||
@@ -853,16 +767,7 @@ public class ASTToTargetAST {
|
|||||||
if (infima.size() > 1) {
|
if (infima.size() > 1) {
|
||||||
foundInfima = true;
|
foundInfima = true;
|
||||||
var newTph = TypePlaceholder.fresh(new NullToken());
|
var newTph = TypePlaceholder.fresh(new NullToken());
|
||||||
var variance = infima.stream().findFirst().get().right.getVariance();
|
referenced.add(newTph);
|
||||||
for (var pair : infima) {
|
|
||||||
if (pair.right.getVariance() != variance) {
|
|
||||||
variance = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newTph.setVariance(variance);
|
|
||||||
|
|
||||||
//referenced.add(newTph);
|
|
||||||
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
||||||
input.removeAll(infima);
|
input.removeAll(infima);
|
||||||
for (var infimum : infima) {
|
for (var infimum : infima) {
|
||||||
|
@@ -22,15 +22,11 @@ public record TargetMethod(int access, String name, TargetBlock block, Signature
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getSignature(Set<TargetGeneric> generics, List<MethodParameter> parameters, TargetType returnType) {
|
public static String getSignature(Set<TargetGeneric> generics, List<MethodParameter> parameters, TargetType returnType) {
|
||||||
String ret = "";
|
String ret = "<";
|
||||||
if (generics.size() > 0) {
|
for (var generic : generics) {
|
||||||
ret += "<";
|
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
||||||
for (var generic : generics) {
|
|
||||||
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
|
||||||
}
|
|
||||||
ret += ">";
|
|
||||||
}
|
}
|
||||||
ret += "(";
|
ret += ">(";
|
||||||
for (var param : parameters) {
|
for (var param : parameters) {
|
||||||
ret += param.type().toDescriptor();
|
ret += param.type().toDescriptor();
|
||||||
}
|
}
|
||||||
|
@@ -495,7 +495,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return returnExpr) {
|
public void visit(Return returnExpr) {
|
||||||
returnExpr.retexpr.accept(this);
|
returnExpr.retexpr.accept(this);
|
||||||
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -610,8 +610,8 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
|
|
||||||
|
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT));
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
||||||
extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT));
|
extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
//methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
//methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
||||||
//extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
//extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
||||||
|
@@ -13,6 +13,7 @@ import java.util.function.Function;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
@@ -390,26 +391,51 @@ public class RuleSet implements IRuleSet{
|
|||||||
if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT))
|
if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) {
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType lhs = pair.getLhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
UnifyType rhs = pair.getRhsType();
|
|
||||||
if (lhs instanceof WildcardType) {
|
/*
|
||||||
lhs = ((WildcardType)lhs).getWildcardedType();
|
* ty <. ? extends ty' is wrong
|
||||||
}
|
*/
|
||||||
if (rhs instanceof WildcardType) {
|
if (rhsType instanceof ExtendsType) {
|
||||||
rhs = ((WildcardType)rhs).getWildcardedType();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lhs.equals(rhs)){
|
/*
|
||||||
return false;
|
* ? super ty <. ty' is wrong
|
||||||
}
|
* except Ty' = Object or ty' = ? super Object
|
||||||
|
*/
|
||||||
|
if ((lhsType instanceof SuperType) &&
|
||||||
|
(!(rhsType.equals(new ReferenceType("java.lang.Object", false)))) &&
|
||||||
|
!(rhsType.equals(new SuperType (new ReferenceType("java.lang.Object", false))))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ? extends ty <. ty' is equivalent to ty < ty'
|
||||||
|
*/
|
||||||
|
if (lhsType instanceof ExtendsType) {
|
||||||
|
lhsType = ((WildcardType)lhsType).getWildcardedType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ty <. ? super ty' ist equivalent to ty <. ty'
|
||||||
|
*/
|
||||||
|
if (rhsType instanceof SuperType) {
|
||||||
|
rhsType = ((WildcardType)rhsType).getWildcardedType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SMALLERNEQDOT => type must not be equal
|
||||||
|
*/
|
||||||
|
if (pair.getPairOp() == PairOperator.SMALLERNEQDOT && lhsType.equals(rhsType)){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
|
||||||
if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
|
if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
UnifyType rhsType = pair.getRhsType();
|
|
||||||
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
|
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
|||||||
|
|
||||||
public class TypeUnify {
|
public class TypeUnify {
|
||||||
|
|
||||||
|
public static Writer statistics;
|
||||||
/**
|
/**
|
||||||
* unify parallel ohne result modell
|
* unify parallel ohne result modell
|
||||||
* @param undConstrains
|
* @param undConstrains
|
||||||
@@ -73,7 +74,8 @@ public class TypeUnify {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
|
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, statistics);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@@ -107,6 +109,7 @@ public class TypeUnify {
|
|||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
||||||
|
unifyTask.statistics = statistics;
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
||||||
|
@@ -19,6 +19,16 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
Set<UnifyPair> methodSignatureConstraintUebergabe;
|
Set<UnifyPair> methodSignatureConstraintUebergabe;
|
||||||
|
|
||||||
|
//statistics
|
||||||
|
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
||||||
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
|
Set<UnifyPair> nextSetElement,
|
||||||
|
IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
|
||||||
|
Set<UnifyPair> methodSignatureConstraintUebergabe, Writer statistics) {
|
||||||
|
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
|
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
@@ -46,6 +47,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||||
import de.dhbwstuttgart.util.Pair;
|
import de.dhbwstuttgart.util.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@@ -125,12 +127,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
static int noBacktracking;
|
static int noBacktracking;
|
||||||
|
|
||||||
|
static int noLoop;
|
||||||
|
|
||||||
static Integer noShortendElements = 0;
|
static Integer noShortendElements = 0;
|
||||||
|
|
||||||
Boolean myIsCanceled = false;
|
Boolean myIsCanceled = false;
|
||||||
|
|
||||||
volatile UnifyTaskModel usedTasks;
|
volatile UnifyTaskModel usedTasks;
|
||||||
|
|
||||||
|
static Writer statistics;
|
||||||
|
|
||||||
public TypeUnifyTask() {
|
public TypeUnifyTask() {
|
||||||
rules = new RuleSet();
|
rules = new RuleSet();
|
||||||
}
|
}
|
||||||
@@ -149,7 +155,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//statistics
|
||||||
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Writer statistics) {
|
||||||
|
this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
|
this.statistics = statistics;
|
||||||
|
}
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
@@ -592,6 +602,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
|
|
||||||
urm.notify(eqPrimePrimeSet);
|
urm.notify(eqPrimePrimeSet);
|
||||||
|
writeStatistics("Result: " + eqPrimePrimeSet.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
@@ -646,6 +657,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//oneElems: Alle 1-elementigen Mengen, die nur ein Paar
|
//oneElems: Alle 1-elementigen Mengen, die nur ein Paar
|
||||||
//a <. theta, theta <. a oder a =. theta enthalten
|
//a <. theta, theta <. a oder a =. theta enthalten
|
||||||
|
|
||||||
|
//statistics
|
||||||
|
writeStatistics("\nNumber of Constraints (" + rekTiefe + "): " + topLevelSets.size());
|
||||||
|
|
||||||
Set<Set<UnifyPair>> oneElems = new HashSet<>();
|
Set<Set<UnifyPair>> oneElems = new HashSet<>();
|
||||||
oneElems.addAll(topLevelSets.stream()
|
oneElems.addAll(topLevelSets.stream()
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
@@ -663,6 +678,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<? extends Set<UnifyPair>> nextSet = optNextSet.get();
|
Set<? extends Set<UnifyPair>> nextSet = optNextSet.get();
|
||||||
//writeLog("nextSet: " + nextSet.toString());
|
//writeLog("nextSet: " + nextSet.toString());
|
||||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||||
|
|
||||||
|
writeStatistics(" Start Number of elements ( " /* + nextSetasList.get(0).stream().findFirst().get().getBasePair()*/ +"): (" + rekTiefe + "): " + nextSetasList.size());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
try {
|
try {
|
||||||
//List<Set<UnifyPair>>
|
//List<Set<UnifyPair>>
|
||||||
@@ -774,8 +792,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
/* sameEqSet-Bestimmung Ende */
|
/* sameEqSet-Bestimmung Ende */
|
||||||
|
|
||||||
|
int hilf = 0;
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
while (nextSetasList.size() > 0) {
|
while (nextSetasList.size() > 0) {
|
||||||
|
|
||||||
|
//statistics
|
||||||
|
writeStatistics(" Actual Number of elements( " + nextSetasList.get(0).stream().findFirst().get().getBasePair() +"): (" + rekTiefe + "): " + nextSetasList.size());
|
||||||
Set<UnifyPair> a_last = a;
|
Set<UnifyPair> a_last = a;
|
||||||
|
|
||||||
/* Liste der Faelle für die parallele Verarbeitung
|
/* Liste der Faelle für die parallele Verarbeitung
|
||||||
@@ -794,6 +816,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
|
|
||||||
|
/* staistics Nextvar an Hand Varianzbestimmung auskommentieren Anfang
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
a = oup.max(nextSetasList.iterator());
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
@@ -865,7 +889,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Nextvar an Hand Varianzbestimmung auskommentieren Ende */
|
||||||
|
a = nextSetasList.remove(0); //statisticsList
|
||||||
|
|
||||||
|
writeStatistics(a.toString());
|
||||||
if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen
|
if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen
|
||||||
methodSignatureConstraint.addAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
|
methodSignatureConstraint.addAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
|
||||||
//System.out.println("ERSTELLUNG: " +methodSignatureConstraint);
|
//System.out.println("ERSTELLUNG: " +methodSignatureConstraint);
|
||||||
@@ -887,11 +914,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird
|
/* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird
|
||||||
* a verworfen und zu nächstem Element von nextSetasList gegangen
|
* a verworfen und zu nächstem Element von nextSetasList gegangen
|
||||||
*/
|
*/
|
||||||
|
/* statistics sameEq wird nicht betrachtet ANGFANG
|
||||||
if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) {
|
if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) {
|
||||||
a = null;
|
a = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
statistics sameEq wird nicht betrachtet ENDE */
|
||||||
|
|
||||||
/* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread
|
/* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread
|
||||||
* gestartet, der parallel weiterarbeitet.
|
* gestartet, der parallel weiterarbeitet.
|
||||||
@@ -925,12 +954,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
|
|
||||||
|
/* statistics sameEq wird nicht betrachtet ANGFANG
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
statistics sameEq wird nicht betrachtet ENDE */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
@@ -1024,12 +1056,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
|
/* statistics sameEq wird nicht betrachtet ANGFANG
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
statistics sameEq wird nicht betrachtet ENDE */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
@@ -1179,6 +1213,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}}}
|
}}}
|
||||||
|
|
||||||
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
|
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
|
||||||
|
if (hilf == 1)
|
||||||
|
System.out.println();
|
||||||
|
writeStatistics("Zusammengeführt(" + rekTiefe + "): " + nextSetasList.size());
|
||||||
if (oderConstraint) {//Wenn weiteres Element nextSetasList genommen wird, muss die vorherige methodsignatur geloescht werden
|
if (oderConstraint) {//Wenn weiteres Element nextSetasList genommen wird, muss die vorherige methodsignatur geloescht werden
|
||||||
methodSignatureConstraint.removeAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
|
methodSignatureConstraint.removeAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
|
||||||
//System.out.println("REMOVE: " +methodSignatureConstraint);
|
//System.out.println("REMOVE: " +methodSignatureConstraint);
|
||||||
@@ -1192,6 +1229,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||||
|| result.isEmpty()) {
|
|| result.isEmpty()) {
|
||||||
|
|
||||||
|
/* auskommentiert damit alle Lösungen reinkommen ANFANG
|
||||||
if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints
|
if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints
|
||||||
&& (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren
|
&& (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren
|
||||||
{
|
{
|
||||||
@@ -1213,7 +1251,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
||||||
//System.out.println(a_last);
|
//System.out.println(a_last);
|
||||||
|
if (a_last != null) {
|
||||||
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
||||||
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
||||||
List<PlaceholderType> varsLast_a =
|
List<PlaceholderType> varsLast_a =
|
||||||
@@ -1265,9 +1303,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
catch (NullPointerException e) {
|
catch (NullPointerException e) {
|
||||||
writeLog("NullPointerException: " + a_last.toString());
|
writeLog("NullPointerException: " + a_last.toString());
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
auskommentiert damit alle Lösungen reinkommen ANFANG */
|
||||||
|
{
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
writeLog("RES Fst: result: " + result.toString() + " res: " + res.toString());
|
writeLog("RES Fst: result: " + result.toString() + " res: " + res.toString());
|
||||||
result.addAll(res);
|
result.addAll(res);
|
||||||
@@ -1303,7 +1343,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
|
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG
|
||||||
if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) {
|
if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) {
|
||||||
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
@@ -1411,6 +1451,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
else { if (variance == 0) {
|
else { if (variance == 0) {
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
|
writeStatistics("break");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1439,7 +1480,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
||||||
|
|
||||||
if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) {
|
if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) {
|
||||||
int nofstred= 0;
|
int nofstred= 0;
|
||||||
@@ -1474,6 +1515,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (res.size() > 1) {
|
if (res.size() > 1) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
/* statistics no erase
|
||||||
writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList);
|
writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList);
|
||||||
if (!oderConstraint) {//PL 2023-02-08 eingefuegt: Bei oderconstraints sind Subststitutionen nicht als Substitutionen in idesem Sinne zu sehen
|
if (!oderConstraint) {//PL 2023-02-08 eingefuegt: Bei oderconstraints sind Subststitutionen nicht als Substitutionen in idesem Sinne zu sehen
|
||||||
nextSetasList = nextSetasList.stream().filter(x -> {
|
nextSetasList = nextSetasList.stream().filter(x -> {
|
||||||
@@ -1486,6 +1528,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
}
|
}
|
||||||
writeLog("nextSetasList nach filter-Aufruf: " + nextSetasList);
|
writeLog("nextSetasList nach filter-Aufruf: " + nextSetasList);
|
||||||
|
*/
|
||||||
nofstred = nextSetasList.size();
|
nofstred = nextSetasList.size();
|
||||||
//NOCH NICHT korrekt PL 2018-10-12
|
//NOCH NICHT korrekt PL 2018-10-12
|
||||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||||
@@ -1503,8 +1546,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
||||||
noBacktracking++;
|
noBacktracking++;
|
||||||
writeLog("Number of Backtracking: " + noBacktracking);
|
writeLog("Number of Backtracking: " + noBacktracking);
|
||||||
|
writeStatistics("Number of erased elements: " + (len - nextSetasList.size()));
|
||||||
|
writeStatistics("Number of Backtracking: " + noBacktracking);
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
|
else writeStatistics("res: " + res.toString());
|
||||||
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
|
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
|
||||||
// return result;
|
// return result;
|
||||||
//}
|
//}
|
||||||
@@ -1513,6 +1559,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//}
|
//}
|
||||||
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
||||||
writeLog("res: " + res.toString());
|
writeLog("res: " + res.toString());
|
||||||
|
writeStatistics(" End Number of Elements (" + rekTiefe + "): " + nextSetasList.size());
|
||||||
|
noLoop++;
|
||||||
|
writeStatistics("Number of Loops: " + noLoop);
|
||||||
}
|
}
|
||||||
//2020-02-02: if (variance ==2) Hier Aufruf von filterOverriding einfuegen
|
//2020-02-02: if (variance ==2) Hier Aufruf von filterOverriding einfuegen
|
||||||
writeLog("Return computeCR: " + result.toString());
|
writeLog("Return computeCR: " + result.toString());
|
||||||
@@ -2576,4 +2625,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeStatistics(String str) {
|
||||||
|
if (finalresult) {
|
||||||
|
synchronized ( this ) {
|
||||||
|
try {
|
||||||
|
statistics.write(str + "\n");
|
||||||
|
statistics.flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("kein StatisticsFile");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.util;
|
package de.dhbwstuttgart.util;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class Pair<T, T1> {
|
public class Pair<T, T1> {
|
||||||
@@ -23,17 +22,4 @@ public class Pair<T, T1> {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + key.toString() + "," + value.toString() + ")\n";
|
return "(" + key.toString() + "," + value.toString() + ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Pair<?, ?> pair = (Pair<?, ?>) o;
|
|
||||||
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,105 +0,0 @@
|
|||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class GenericsParserTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodNoGenerics() {
|
|
||||||
var signature = "()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
assertEquals(generics, new GenericDeclarationList(List.of(), new NullToken()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodSimpleGenerics() {
|
|
||||||
var signature = "<T:Ljava/lang/Object;>()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
assertEquals(generics, new GenericDeclarationList(
|
|
||||||
List.of(new GenericTypeVar("T", List.of(ASTToTargetAST.OBJECT), new NullToken(), new NullToken())), new NullToken())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodExtends() {
|
|
||||||
var signature = "<T:Ljava/lang/Class<TT;>;>()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
assertEquals(generics, new GenericDeclarationList(
|
|
||||||
List.of(new GenericTypeVar("T", List.of(
|
|
||||||
new RefType(new JavaClassName("java.lang.Class"), List.of(new GenericRefType("T", new NullToken())), new NullToken())),
|
|
||||||
new NullToken(), new NullToken())), new NullToken()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodVariance() {
|
|
||||||
var signature = "<T:Ljava/lang/Class<+TT;>;>()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
|
|
||||||
assertEquals(generics, new GenericDeclarationList(
|
|
||||||
List.of(new GenericTypeVar("T", List.of(
|
|
||||||
new RefType(new JavaClassName("java.lang.Class"), List.of(
|
|
||||||
new ExtendsWildcardType(new GenericRefType("T", new NullToken()), new NullToken())
|
|
||||||
), new NullToken())),
|
|
||||||
new NullToken(), new NullToken())),
|
|
||||||
new NullToken())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodTypeVars() {
|
|
||||||
var signature = "<A:TB;B:LClassA;C:LClassB<TA;>;D:TB;>()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
assertEquals(generics, new GenericDeclarationList(
|
|
||||||
List.of(
|
|
||||||
new GenericTypeVar("A", List.of(new GenericRefType("B", new NullToken())), new NullToken(), new NullToken()),
|
|
||||||
new GenericTypeVar("B", List.of(new RefType(new JavaClassName("ClassA"), new NullToken())), new NullToken(), new NullToken()),
|
|
||||||
new GenericTypeVar("C", List.of(new RefType(new JavaClassName("ClassB"),
|
|
||||||
List.of(new GenericRefType("A", new NullToken())),
|
|
||||||
new NullToken())), new NullToken(), new NullToken()
|
|
||||||
),
|
|
||||||
new GenericTypeVar("D", List.of(new GenericRefType("B", new NullToken())), new NullToken(), new NullToken())
|
|
||||||
),
|
|
||||||
new NullToken()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMethodComplex() {
|
|
||||||
var signature = "<T:LClassA<+TT;LClassB<+LClassA;-LClassC<LClassA;>;>;>;U:LClassC<LClassC;>;>()V";
|
|
||||||
var generics = ASTFactory.createGenerics(signature);
|
|
||||||
|
|
||||||
assertEquals(generics, new GenericDeclarationList(
|
|
||||||
List.of(new GenericTypeVar("T", List.of(
|
|
||||||
new RefType(new JavaClassName("ClassA"), List.of(
|
|
||||||
new ExtendsWildcardType(new GenericRefType("T", new NullToken()), new NullToken()),
|
|
||||||
new RefType(new JavaClassName("ClassB"), List.of(
|
|
||||||
new ExtendsWildcardType(new RefType(new JavaClassName("ClassA"), new NullToken()), new NullToken()),
|
|
||||||
new SuperWildcardType(
|
|
||||||
new RefType(new JavaClassName("ClassC"), List.of(
|
|
||||||
new RefType(new JavaClassName("ClassA"), new NullToken())
|
|
||||||
), new NullToken()), new NullToken())
|
|
||||||
), new NullToken())
|
|
||||||
), new NullToken())
|
|
||||||
), new NullToken(), new NullToken()),
|
|
||||||
new GenericTypeVar("U", List.of(
|
|
||||||
new RefType(new JavaClassName("ClassC"), List.of(
|
|
||||||
new RefType(new JavaClassName("ClassC"), new NullToken())
|
|
||||||
), new NullToken())
|
|
||||||
), new NullToken(), new NullToken())),
|
|
||||||
new NullToken()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -281,6 +281,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scalarTest() throws Exception {
|
public void scalarTest() throws Exception {
|
||||||
|
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Scalar.jav");
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Scalar.jav");
|
||||||
var scalar = classFiles.get("Scalar");
|
var scalar = classFiles.get("Scalar");
|
||||||
|
|
||||||
@@ -575,11 +576,6 @@ public class TestComplete {
|
|||||||
assertEquals(fstArgm2, m2.getGenericReturnType());
|
assertEquals(fstArgm2, m2.getGenericReturnType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTXGenerics() throws Exception {
|
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "TXGenerics.jav");
|
|
||||||
var instance = classFiles.get("TXGenerics").getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typedIdTest() throws Exception {
|
public void typedIdTest() throws Exception {
|
||||||
|
@@ -90,15 +90,16 @@ public class TestGenerics {
|
|||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
assertEquals(0, generics.get(result.clazz).size());
|
assertEquals(0, generics.get(result.clazz).size());
|
||||||
assertEquals(1, generics.get(m).size());
|
assertEquals(2, generics.get(m).size());
|
||||||
assertEquals(2, generics.get(main).size());
|
assertEquals(2, generics.get(main).size());
|
||||||
|
|
||||||
var N = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
var N = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||||
var N2 = generics.getBounds(m.getReturnType(), result.clazz, m);
|
|
||||||
|
|
||||||
var NChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
var NChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
||||||
assertEquals(N, N2);
|
assertEquals(N, NChain);
|
||||||
assertEquals(N2, NChain);
|
|
||||||
|
var Q = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||||
|
var QChain = new BoundsList(new Bound(true, TypePlaceholder.of("N")), new Bound(true, ASTToTargetAST.OBJECT));
|
||||||
|
assertEquals(Q, QChain);
|
||||||
|
|
||||||
var R = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
var R = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||||
assertEquals(R, NChain);
|
assertEquals(R, NChain);
|
||||||
@@ -303,18 +304,17 @@ public class TestGenerics {
|
|||||||
var main = result.findMethod("main");
|
var main = result.findMethod("main");
|
||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
var Q = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||||
var O2 = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
var N = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
assertEquals(O, O2);
|
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(O2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(N, new BoundsList(new Bound(true, TypePlaceholder.of("Q")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
// TODO Maybe test in other ways if the parameter generics equals the return generics
|
var Q2 = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||||
var S = generics.getBounds(main.getReturnType(), result.clazz, main);
|
var R = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||||
var S2 = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
var S = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||||
var T = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
assertEquals(Q2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(S, S2);
|
assertEquals(R, new BoundsList(new Bound(true, TypePlaceholder.of("Q")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(S2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("Q")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(T, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user