forked from JavaTX/JavaCompilerCore
Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode
resources/AllgemeinTest/Pair.jav
This commit is contained in:
commit
9d03080667
@ -12,7 +12,8 @@ class Pair<U, T> {
|
||||
ret.b = x.elementAt(1);
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
eq(a, b) {
|
||||
b = a;
|
||||
return a == b;
|
||||
@ -23,8 +24,9 @@ class Pair<U, T> {
|
||||
return eq(p.a, p.b);
|
||||
//return p.a == p.b;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
void m(Pair<?, ?> p, List<? extends Eq> b)
|
||||
{
|
||||
//this.compare(p); //1, type incorrect
|
||||
|
32
resources/bytecode/javFiles/Pair.jav
Normal file
32
resources/bytecode/javFiles/Pair.jav
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Boolean;
|
||||
import java.lang.Object;
|
||||
|
||||
class Pair<U, T> {
|
||||
U a;
|
||||
T b;
|
||||
|
||||
make(x) {
|
||||
var ret = new Pair<>();
|
||||
ret.a = x.elementAt(0);
|
||||
ret.b = x.elementAt(1);
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
eq(a, b) {
|
||||
b = a;
|
||||
return a == b;
|
||||
}
|
||||
|
||||
compare( p) {
|
||||
return eq(p.a, p.b);
|
||||
//return p.a == p.b;
|
||||
}
|
||||
|
||||
void m(Pair<?, ?> p, List<? extends Eq> b)
|
||||
{
|
||||
//this.compare(p); //1, type incorrect
|
||||
this.compare(this.make(b)); //2, OK
|
||||
}
|
||||
*/
|
||||
}
|
@ -56,11 +56,14 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.output.NullOutputStream;
|
||||
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
@ -68,7 +71,7 @@ public class JavaTXCompiler {
|
||||
final CompilationEnvironment environment;
|
||||
Boolean resultmodel = true;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/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();
|
||||
private final DirectoryClassLoader classLoader;
|
||||
|
||||
@ -552,11 +555,8 @@ public class JavaTXCompiler {
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||
// new FileWriter(new
|
||||
// File(System.getProperty("user.dir")+"/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||
+ sourceFiles.keySet().iterator().next().getName()));
|
||||
Writer logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + sourceFiles.keySet().iterator().next().getName()))
|
||||
: new OutputStreamWriter(new NullOutputStream());
|
||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
@ -445,7 +445,6 @@ public class ASTToTargetAST {
|
||||
addToPairs(result, minimalPair);
|
||||
}
|
||||
|
||||
|
||||
// All unbounded type variables (bounds not in method)
|
||||
outer:
|
||||
for (var typeVariable : typeVariables) {
|
||||
@ -482,6 +481,7 @@ public class ASTToTargetAST {
|
||||
typeVariablesOfClass.add((TypePlaceholder) pair.getLeft());
|
||||
}
|
||||
|
||||
if (!(method instanceof Constructor))
|
||||
typeVariables.addAll(findTypeVariables(method.getReturnType(), equality));
|
||||
for (var arg : method.getParameterList().getFormalparalist()) {
|
||||
typeVariables.addAll(findTypeVariables(arg.getType(), equality));
|
||||
@ -529,27 +529,29 @@ public class ASTToTargetAST {
|
||||
methodFindConstraints(owner, method, simplifiedConstraints, txTypeVariables, txTypeVariablesOfClass, txResult, txEquality);
|
||||
|
||||
{ // Java Generics
|
||||
eliminateCycles(javaResult, equality);
|
||||
eliminateInfima(javaResult, equality);
|
||||
var referenced = new HashSet<TypePlaceholder>();
|
||||
|
||||
eliminateCycles(javaResult, equality, referenced);
|
||||
eliminateInfima(javaResult, equality, referenced);
|
||||
|
||||
var usedTphs = new HashSet<TypePlaceholder>();
|
||||
// For eliminating inner type variables we need to figure out which ones are actually used
|
||||
// TODO Maybe don't do this twice?
|
||||
for (var param : method.getParameterList().getFormalparalist()) {
|
||||
usedTphs.addAll(findTypeVariables(param.getType(), equality));
|
||||
}
|
||||
usedTphs.addAll(findTypeVariables(method.getReturnType(), equality));
|
||||
var referenced = new HashSet<>(usedTphs);
|
||||
referenced.addAll(usedTphs);
|
||||
referenced.addAll(javaTypeVariablesOfClass);
|
||||
|
||||
eliminateInnerTypeVariables(referenced, javaResult);
|
||||
equalizeTypeVariables(javaResult, equality);
|
||||
usedTPHsOfMethods.put(method, usedTphs);
|
||||
}
|
||||
{ // JavaTX Generics
|
||||
eliminateInfima(txResult, txEquality);
|
||||
|
||||
{
|
||||
var referenced = new HashSet<TypePlaceholder>();
|
||||
// JavaTX Generics
|
||||
eliminateInfima(txResult, txEquality, referenced);
|
||||
|
||||
for (var param : method.getParameterList().getFormalparalist()) {
|
||||
referenced.addAll(findTypeVariables(param.getType(), txEquality));
|
||||
}
|
||||
@ -609,14 +611,16 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
{ // Java Generics
|
||||
eliminateCycles(javaResult, equality);
|
||||
eliminateInfima(javaResult, equality);
|
||||
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality);
|
||||
var referenced = new HashSet<TypePlaceholder>();
|
||||
eliminateCycles(javaResult, equality, referenced);
|
||||
eliminateInfima(javaResult, equality, referenced);
|
||||
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
||||
equalizeTypeVariables(javaResult, equality);
|
||||
}
|
||||
{ // TX Generics
|
||||
eliminateInfima(txResult, txEquality);
|
||||
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality);
|
||||
var referenced = new HashSet<TypePlaceholder>();
|
||||
eliminateInfima(txResult, txEquality, referenced);
|
||||
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, referenced);
|
||||
}
|
||||
|
||||
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult);
|
||||
@ -654,8 +658,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
}
|
||||
|
||||
void eliminateInnerTypeVariablesOfClass(ClassOrInterface classOrInterface, Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||
Set<TypePlaceholder> referenced = new HashSet<>();
|
||||
void eliminateInnerTypeVariablesOfClass(ClassOrInterface classOrInterface, Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality, Set<TypePlaceholder> referenced) {
|
||||
for (var field : classOrInterface.getFieldDecl()) {
|
||||
findTphs(field.getType(), referenced, equality);
|
||||
}
|
||||
@ -709,10 +712,11 @@ public class ASTToTargetAST {
|
||||
input.addAll(output);
|
||||
}
|
||||
|
||||
void eliminateCycles(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||
void eliminateCycles(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality, Set<TypePlaceholder> referenced) {
|
||||
var cycles = findCycles(input);
|
||||
for (var cycle : cycles) {
|
||||
var newTph = TypePlaceholder.fresh(new NullToken());
|
||||
referenced.add(newTph);
|
||||
addToPairs(input, new PairTPHequalRefTypeOrWildcardType(newTph, OBJECT));
|
||||
cycle.add(cycle.get(0)); // Make it a complete cycle
|
||||
for (var i = 0; i < cycle.size() - 1; i++) {
|
||||
@ -725,7 +729,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;
|
||||
do {
|
||||
foundInfima = false;
|
||||
@ -740,6 +744,7 @@ public class ASTToTargetAST {
|
||||
if (infima.size() > 1) {
|
||||
foundInfima = true;
|
||||
var newTph = TypePlaceholder.fresh(new NullToken());
|
||||
referenced.add(newTph);
|
||||
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
||||
input.removeAll(infima);
|
||||
for (var infimum : infima) {
|
||||
|
@ -177,9 +177,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
thNo = totalnoOfThread;
|
||||
writeLog("thNo2 " + thNo);
|
||||
try {
|
||||
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||
//new FileWriter(new File(System.getProperty("user.dir")+"/resources/logFiles/"+"Thread_"+thNo));
|
||||
new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
||||
this.logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo))
|
||||
: new OutputStreamWriter(new NullOutputStream());
|
||||
logFile.write("");
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
@ -233,6 +233,7 @@ public class TestComplete {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void matrixTest() throws Exception {
|
||||
var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader());
|
||||
var matrix = classFiles.get("Matrix");
|
||||
@ -598,4 +599,10 @@ public class TestComplete {
|
||||
var classFiles = generateClassFiles("OLFun2.jav", new ByteArrayClassLoader());
|
||||
var instance = classFiles.get("OLFun2").getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pairTest() throws Exception {
|
||||
var classFiles = generateClassFiles("Pair.jav", new ByteArrayClassLoader());
|
||||
var instance = classFiles.get("Pair").getDeclaredConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user