Compare commits
9 Commits
targetByte
...
unifyOptim
Author | SHA1 | Date | |
---|---|---|---|
|
2c9f085cca | ||
|
3e4e66d60d | ||
|
883ab50f94 | ||
|
9d37e8f637 | ||
|
496842a3bf | ||
|
608d73452a | ||
|
421169a72d | ||
|
c43d9ab9f5 | ||
|
5a0e53485c |
@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
@ -38,7 +39,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
final boolean parallel = true;
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||
@ -117,6 +118,7 @@ public class JavaTXCompiler {
|
||||
logFile.write(ASTTypePrinter.print(sf));
|
||||
}
|
||||
logFile.flush();
|
||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
@ -175,15 +177,39 @@ public class JavaTXCompiler {
|
||||
return y; } )
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
varianceInheritance(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
logFile.write("RES: " + result.toString()+"\n");
|
||||
logFile.flush();
|
||||
results.addAll(result);
|
||||
}
|
||||
}
|
||||
catch (IOException e) { }
|
||||
if (parallel) {
|
||||
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||
Set<UnifyPair> eq = new HashSet<>(xConsSet);
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
else {
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||
System.out.println("RESULT: " + result);
|
||||
logFile.write("RES: " + result.toString()+"\n");
|
||||
logFile.flush();
|
||||
results.addAll(result);
|
||||
}
|
||||
}
|
||||
for (TypeUnifyTask fork : forks) {
|
||||
try {
|
||||
Set<Set<UnifyPair>> result = fork.join();
|
||||
System.out.println("RESULT: " + result);
|
||||
logFile.write("RES: " + result.toString()+"\n");
|
||||
logFile.flush();
|
||||
results.addAll(result);
|
||||
}
|
||||
catch (ConcurrentModificationException v) {
|
||||
v.printStackTrace();
|
||||
while (v.getCause() instanceof ConcurrentModificationException) {
|
||||
v = (ConcurrentModificationException)v.getCause();
|
||||
}
|
||||
System.out.println(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) { }
|
||||
|
||||
return results.stream().map((unifyPairs ->
|
||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
|
@ -198,7 +198,9 @@ public class UnifyTypeFactory {
|
||||
}else if(tr instanceof WildcardType){
|
||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
||||
}else throw new NotImplementedException();
|
||||
}else throw new NotImplementedException();
|
||||
}else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||
|
@ -202,7 +202,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
||||
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||
//The type of the postfix increment expression is the type of the variable
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
||||
}else{
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
@ -11,7 +12,12 @@ public class TypeUnify {
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
try {
|
||||
pool.invoke(unifyTask);
|
||||
}
|
||||
catch (ConcurrentModificationException v) {
|
||||
v.printStackTrace();
|
||||
}
|
||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||
return res;
|
||||
}
|
||||
|
32
src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
Normal file
32
src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
Normal file
@ -0,0 +1,32 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class TypeUnify2Task extends TypeUnifyTask {
|
||||
|
||||
Set<Set<UnifyPair>> setToFlatten;
|
||||
|
||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) {
|
||||
super(eq, fc, parallel, logFile, log);
|
||||
this.setToFlatten = setToFlatten;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Set<UnifyPair>> compute() {
|
||||
if (one) {
|
||||
System.out.println("two");
|
||||
}
|
||||
one = true;
|
||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel);
|
||||
/*if (isUndefinedPairSetSet(res)) {
|
||||
return new HashSet<>(); }
|
||||
else
|
||||
*/
|
||||
return res;
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||
|
||||
import java.io.File;
|
||||
@ -49,10 +50,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
private static int i = 0;
|
||||
private boolean printtag = false;
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||
private static int noOfThread = 0;
|
||||
private int thNo;
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||
FileWriter logFile;
|
||||
|
||||
protected boolean one = false;
|
||||
|
||||
/**
|
||||
* The implementation of setOps that will be used during the unification
|
||||
*/
|
||||
@ -96,6 +101,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
this.logFile = logFile;
|
||||
this.log = log;
|
||||
rules = new RuleSet(logFile);
|
||||
noOfThread++;
|
||||
thNo = noOfThread;
|
||||
//System.out.println(noOfThread);
|
||||
//System.out.println(eq);
|
||||
}
|
||||
|
||||
|
||||
@ -133,6 +142,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
@Override
|
||||
protected Set<Set<UnifyPair>> compute() {
|
||||
if (one) {
|
||||
System.out.println("two");
|
||||
}
|
||||
one = true;
|
||||
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||
else return res;
|
||||
@ -144,7 +157,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* @param fc The finite closure
|
||||
* @return The set of all principal type unifiers
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||
// ).collect(Collectors.toCollection(HashSet::new));
|
||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||
@ -311,10 +324,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
//System.out.println("vor Subst: " + eqPrime);
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
Set<Set<UnifyPair>> unifyres1 = null;
|
||||
Set<Set<UnifyPair>> unifyres2 = null;
|
||||
|
||||
/*
|
||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||
*/
|
||||
/*
|
||||
if(parallel) {
|
||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||
@ -334,7 +350,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
fork.fork();
|
||||
}
|
||||
}
|
||||
else { // sequentiell (Step 6b is included)
|
||||
else */
|
||||
{ // sequentiell (Step 6b is included)
|
||||
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||
@ -350,12 +367,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
}
|
||||
else if(eqPrimePrime.isPresent()) {
|
||||
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, false);
|
||||
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel);
|
||||
|
||||
eqPrimePrimeSet.addAll(unifyres);
|
||||
}
|
||||
else {
|
||||
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, false);
|
||||
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, fc, parallel);
|
||||
|
||||
|
||||
eqPrimePrimeSet.addAll(unifyres);
|
||||
@ -368,17 +385,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/*
|
||||
* Step 6 b) Build the union over everything.
|
||||
*/
|
||||
|
||||
/*
|
||||
if(parallel)
|
||||
for(TypeUnifyTask fork : forks)
|
||||
eqPrimePrimeSet.addAll(fork.join());
|
||||
*/
|
||||
|
||||
/*
|
||||
* Step 7: Filter empty sets;
|
||||
*/
|
||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
|
||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
|
||||
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
||||
Iterator<UnifyPair> upit = eqPrimePrimeSet.iterator().next().iterator();
|
||||
if (upit.next().getLhsType() instanceof WildcardType
|
||||
|| upit.next().getLhsType() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
return eqPrimePrimeSet;
|
||||
}
|
||||
|
||||
@ -451,9 +475,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a = null;
|
||||
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
nextSetasList.remove(a);
|
||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
||||
if (//a.equals(a_next) ||
|
||||
(oup.compare(a, a_next) == 1)) {
|
||||
nextSetasListRest.remove(a_next);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a = oup.min(nextSetasList.iterator());
|
||||
@ -491,16 +525,62 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
elems.add(a);
|
||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
||||
//writeLog("Vor unify2 Aufruf: " + eq.toString());
|
||||
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
|
||||
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
||||
if(parallel && (variance == 1)) {
|
||||
/*
|
||||
elems.add(a);
|
||||
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
||||
fork.fork();
|
||||
res = fork.join();
|
||||
*/
|
||||
|
||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||
|
||||
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
||||
|
||||
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
newElemsOrig.add(a);
|
||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, fc, parallel, logFile, log);
|
||||
forks.add(forkOrig);
|
||||
forkOrig.fork();
|
||||
|
||||
while (!nextSetasListRest.isEmpty()) {
|
||||
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
newElems.add(nSaL);
|
||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
//res = unify2(elems, eq, fc, parallel);
|
||||
res = forkOrig.join();
|
||||
for(TypeUnifyTask fork : forks) {
|
||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||
add_res.add(fork_res);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
elems.add(a);
|
||||
res = unify2(elems, eq, fc, parallel);
|
||||
}
|
||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = res;
|
||||
if (res.iterator().next() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
writeLog("RESADD:" + result.toString() + " " + res.toString());
|
||||
result.addAll(res);
|
||||
}
|
||||
//else {
|
||||
@ -522,6 +602,30 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
System.out.print("");
|
||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||
if (variance == 1) {
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = par_res;
|
||||
if (par_res.iterator().next() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
writeLog("RESADD:" + result.toString() + " " + par_res.toString());
|
||||
result.addAll(par_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* nextSetasList = nextSetasListRest; */
|
||||
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
||||
*/
|
||||
System.out.println("");
|
||||
while (nextSetasListIt.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||
@ -530,6 +634,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
nextSetasList.remove(a_next);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else { if (variance == -1) {
|
||||
System.out.println("");
|
||||
@ -1129,8 +1235,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
allGen = false;
|
||||
break;
|
||||
}
|
||||
|
||||
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
||||
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded());
|
||||
for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
Match match = new Match();
|
||||
|
||||
@ -1138,7 +1244,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
||||
Set<UnifyType> fBounded = pair.getfBounded();
|
||||
//Set<UnifyType> fBounded = pair.getfBounded();
|
||||
|
||||
int i_ef = i;
|
||||
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
||||
@ -1242,6 +1348,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
void writeLog(String str) {
|
||||
if (log) {
|
||||
try {
|
||||
logFile.write("Thread no.:" + thNo + "\n");
|
||||
logFile.write(str+"\n");
|
||||
logFile.flush();
|
||||
|
||||
|
44
test/bytecode/FacultyTest.java
Normal file
44
test/bytecode/FacultyTest.java
Normal file
@ -0,0 +1,44 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class FacultyTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Faculty.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Fac");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||
assertEquals(result, 6);
|
||||
}
|
||||
|
||||
}
|
@ -36,55 +36,57 @@ public class MatrixTest {
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Matrix");
|
||||
|
||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v1 = new Vector<Integer> ();
|
||||
v1.addElement(2);
|
||||
v1.addElement(2);
|
||||
Vector<Integer> v2 = new Vector<Integer> ();
|
||||
v2.addElement(3);
|
||||
v2.addElement(3);
|
||||
//Matrix m1 = new Matrix();
|
||||
//m1.addElement(v1);
|
||||
//m1.addElement(v2);
|
||||
vv.addElement(v1);
|
||||
vv.addElement(v2);
|
||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix();
|
||||
//Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v1 = new Vector<Integer> ();
|
||||
v1.addElement(2);
|
||||
v1.addElement(2);
|
||||
Vector<Integer> v2 = new Vector<Integer> ();
|
||||
v2.addElement(3);
|
||||
v2.addElement(3);
|
||||
//Method[] ms = classToTest.getSuperclass().getDeclaredMethods();
|
||||
Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class);
|
||||
addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1);
|
||||
addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2);
|
||||
//vv.addElement(v1);
|
||||
//vv.addElement(v2);
|
||||
//instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||
|
||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v3 = new Vector<Integer> ();
|
||||
v3.addElement(2);
|
||||
v3.addElement(2);
|
||||
Vector<Integer> v4 = new Vector<Integer> ();
|
||||
v4.addElement(3);
|
||||
v4.addElement(3);
|
||||
//Matrix m2 = new Matrix();
|
||||
//m2.addElement(v3);
|
||||
//m2.addElement(v4);
|
||||
vv1.addElement(v3);
|
||||
vv1.addElement(v4);
|
||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v3 = new Vector<Integer> ();
|
||||
v3.addElement(2);
|
||||
v3.addElement(2);
|
||||
Vector<Integer> v4 = new Vector<Integer> ();
|
||||
v4.addElement(3);
|
||||
v4.addElement(3);
|
||||
//Matrix m2 = new Matrix();
|
||||
//m2.addElement(v3);
|
||||
//m2.addElement(v4);
|
||||
vv1.addElement(v3);
|
||||
vv1.addElement(v4);
|
||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||
|
||||
|
||||
|
||||
//Matrix m3 = m1.mul(vv1);
|
||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
||||
//Matrix m3 = m1.mul(vv1);
|
||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
||||
|
||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v5 = new Vector<Integer> ();
|
||||
v5.addElement(10);
|
||||
v5.addElement(10);
|
||||
Vector<Integer> v6 = new Vector<Integer> ();
|
||||
v6.addElement(15);
|
||||
v6.addElement(15);
|
||||
//Matrix m2 = new Matrix();
|
||||
//m2.addElement(v3);
|
||||
//m2.addElement(v4);
|
||||
res.addElement(v5);
|
||||
res.addElement(v6);
|
||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||
assertEquals(result, instanceOfClass_m3);
|
||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v5 = new Vector<Integer> ();
|
||||
v5.addElement(10);
|
||||
v5.addElement(10);
|
||||
Vector<Integer> v6 = new Vector<Integer> ();
|
||||
v6.addElement(15);
|
||||
v6.addElement(15);
|
||||
//Matrix m2 = new Matrix();
|
||||
//m2.addElement(v3);
|
||||
//m2.addElement(v4);
|
||||
res.addElement(v5);
|
||||
res.addElement(v6);
|
||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||
assertEquals(result, instanceOfClass_m3);
|
||||
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ public class applyLambda {
|
||||
return x;
|
||||
};
|
||||
|
||||
return lam1.apply(new Apply());
|
||||
//return lam1;
|
||||
//return lam1.apply(new Apply());
|
||||
return lam1;
|
||||
//return new Vector();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user