modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java

new file:   ../../../java/bytecode/PutTest.java
	new file:   ../../bytecode/javFiles/Put.jav
This commit is contained in:
pl@gohorb.ba-horb.de 2020-05-05 18:06:05 +02:00
parent fd3d4e97a1
commit 3de735ebe3
3 changed files with 180 additions and 2 deletions

View File

@ -708,7 +708,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("nextSet: " + nextSet.toString());
writeLog("nextSetasList: " + nextSetasList.toString());
if (variance == 1) {
Set<UnifyPair> a_final = a = oup.max(nextSetasList.iterator());
a = oup.max(nextSetasList.iterator());
nextSetasList.remove(a);
if (oderConstraint) {
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
@ -793,7 +793,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
nextSetasList.remove(a);
}
else {
a = nextSetasList.remove(0);
if (oderConstraint) {
a = oup.max(nextSetasList.iterator());
nextSetasList.remove(a);
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
}
else {
a = nextSetasList.remove(0);
}
}
}
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
@ -1471,9 +1478,31 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
break;
}
else {
nextSetasList.removeAll(nextSetasListOderConstraints);
nextSetasListOderConstraints = new ArrayList<>();
writeLog("Removed: " + nextSetasListOderConstraints);
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a, nextSetasList);
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
.collect(Collectors.toCollection(ArrayList::new));
List<Set<UnifyPair>> notErased = new ArrayList<>();
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
erased.removeAll(notErased);
nextSetasList.removeAll(erased);
writeLog("Removed: " + erased);
writeLog("Not Removed: " + nextSetasList);
/* zu loeschen PL 2020-05-05
nextSetasList = nextSetasList.stream()
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
.collect(Collectors.toCollection(ArrayList::new));
*/
/*
//TODO: Hier muessen alle kleineren und größeren Elemente von a geloescht werden
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());

View File

@ -0,0 +1,130 @@
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 java.util.List;
import java.util.Stack;
import java.util.Vector;
import org.junit.BeforeClass;
import org.junit.Test;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class PutTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static ClassLoader loader;
private static Class<?> classToTest;
private static Class<?> classToTest1;
private static String pathToClassFile;
private static Object instanceOfClass;
private static Object instanceOfClass1;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Put.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
List<ResultSet> typeinferenceResult = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Put");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classToTest1 = loader.loadClass("OLMain");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
}
@Test
public void testPutClassName() {
assertEquals("Put", classToTest.getName());
}
@Test
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
Vector<Integer> v_invoke = new Vector<>();
m.invoke(instanceOfClass, 5, v_invoke);
Vector<Integer> v = new Vector<>();
v.add(5);
assertEquals(v, v_invoke);
}
@Test
public void testPutElementStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
Stack<Integer> s_invoke = new Stack<>();
m.invoke(instanceOfClass, 5, s_invoke);
assertEquals(new Integer(5), s_invoke.pop());
}
@Test
public void testMainVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
Vector<Integer> v_invoke = new Vector<>();
m.invoke(instanceOfClass, 6, v_invoke);
Vector<Integer> v = new Vector<>();
v.add(6);
assertEquals(v, v_invoke);
}
@Test
public void testMainStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
Stack<Integer> s_invoke = new Stack<>();
m.invoke(instanceOfClass, 6, s_invoke);
assertEquals(new Integer(6), s_invoke.pop());
}
/*
@Test
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", Double.class);
Double result = (Double) m.invoke(instanceOfClass, 5.0);
assertEquals(new Double(10.0), result);
}
@Test
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", String.class);
String result = (String) m.invoke(instanceOfClass, "xxx");
assertEquals("xxxxxx", result);
}
@Test
public void testOLMainClassName() {
assertEquals("OLMain", classToTest1.getName());
}
@Test
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
assertEquals(new Integer(10), result);
}
@Test
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", Double.class);
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
assertEquals(new Double(10.0), result);
}
@Test
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", String.class);
String result = (String) main.invoke(instanceOfClass1, "xxx");
assertEquals("xxxxxx", result);
}
*/
}

View File

@ -0,0 +1,19 @@
import java.util.Vector;
import java.util.Stack;
public class Put {
putElement(ele, v) {
v.addElement(ele);
}
putElement(ele, s) {
s.push(ele);
}
main(ele, x) {
putElement(ele, x);
}
}