diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index e3dce48a..d44ac77f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -474,9 +474,9 @@ public class JavaTXCompiler { return x; }; - logFile.write(unifyCons.toString()); + logFile.write("Unify:" + unifyCons.toString()); unifyCons = unifyCons.map(distributeInnerVars); - logFile.write(unifyCons.toString()); + logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString()); TypeUnify unify = new TypeUnify(); // Set> results = new HashSet<>(); Nach vorne gezogen logFile.write("FC:\\" + finiteClosure.toString() + "\n"); diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index a945b02a..140b3432 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -35,7 +35,7 @@ public class SyntaxTreeGenerator{ Set imports = new HashSet(); private Map fields = new HashMap<>(); //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen - List fieldInitializations = new ArrayList<>(); + List fieldInitializations = new ArrayList<>(); //PL 2019-10-23: Muss für jede Klasse neu initilisiert werden public SyntaxTreeGenerator(JavaClassRegistry reg, GenericsRegistry globalGenerics){ //Die Generics müssen während des Bauens des AST erstellt werden, @@ -159,6 +159,7 @@ public class SyntaxTreeGenerator{ private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) { ClassOrInterface newClass; + fieldInitializations = new ArrayList<>(); //PL 2019-10-22: muss für jede Klasse neu initilisiert werden if(ctx.normalClassDeclaration() != null){ newClass = convertNormal(ctx.normalClassDeclaration()); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/This.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/This.java index d35e7797..cd7ef5ec 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -19,4 +19,8 @@ public class This extends Expression public void accept(StatementVisitor visitor) { visitor.visit(this); } + + public String toString() { + return "this: "+ this.getType(); + } } diff --git a/src/test/java/bytecode/mathStrucIntegerTest.java b/src/test/java/bytecode/mathStrucIntegerTest.java new file mode 100644 index 00000000..7100e4af --- /dev/null +++ b/src/test/java/bytecode/mathStrucIntegerTest.java @@ -0,0 +1,38 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class mathStrucIntegerTest { + + 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; + + + @Test + public void test() throws Exception { + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("mathStrucInteger"); + //instanceOfClass = classToTest.getDeclaredConstructor(Integer.class).newInstance("A"); + } + +} diff --git a/src/test/resources/bytecode/javFiles/mathStruc.jav b/src/test/resources/bytecode/javFiles/mathStruc.jav index 37c5d08c..171881b1 100644 --- a/src/test/resources/bytecode/javFiles/mathStruc.jav +++ b/src/test/resources/bytecode/javFiles/mathStruc.jav @@ -1,3 +1,6 @@ +import java.util.Vector; +import java.lang.Integer; + public class mathStruc { model; @@ -8,3 +11,5 @@ public class mathStruc { model =m; //innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(this.model,ms.model)); } +} + diff --git a/src/test/resources/bytecode/javFiles/mathStrucInteger.jav b/src/test/resources/bytecode/javFiles/mathStrucInteger.jav new file mode 100644 index 00000000..f1f67553 --- /dev/null +++ b/src/test/resources/bytecode/javFiles/mathStrucInteger.jav @@ -0,0 +1,23 @@ +import java.util.Vector; +import java.lang.Integer; + +public class mathStrucInteger { + model; + + innerOp = (o) -> (ms) -> new mathStrucInteger<>(o.apply(model,ms.model)); + + public mathStrucInteger(m) { + model =m; + } +} + +class mathStrucIntegerUse { + + main() { + var ms; + ms = new mathStrucInteger<>(2); + var ms2; + ms2 = ms.innerOp.apply((x,y) -> x+y).apply(ms); + return ms2; + } +} diff --git a/src/test/resources/bytecode/javFiles/mathStrucMatrixOP.jav b/src/test/resources/bytecode/javFiles/mathStrucMatrixOP.jav new file mode 100644 index 00000000..2b24f037 --- /dev/null +++ b/src/test/resources/bytecode/javFiles/mathStrucMatrixOP.jav @@ -0,0 +1,91 @@ +//PL 2019-10-24: laeuft nicht durch, zu gross +import java.util.Vector; +import java.lang.Integer; +import java.lang.Boolean; + +public class mathStrucMatrixOP { + model; + + innerOp = (o) -> (ms) -> new mathStrucMatrixOP<>(o.apply(model,ms.model)); + + public mathStrucMatrixOP(m) { + model =m; + } +} + +public class MatrixOP extends Vector> { + + MatrixOP () { + } + + MatrixOP(vv) { + Integer i; + i = 0; + while(i < vv.size()) { +// Boolean a = this.add(vv.elementAt(i)); + this.add(vv.elementAt(i)); + i=i+1; + } + } + + public mul = (m1, m2) -> { + var ret = new MatrixOP(); + var i = 0; + while(i < m1.size()) { + var v1 = m1.elementAt(i); + var v2 = new Vector(); + var j = 0; + while(j < v1.size()) { + var erg = 0; + var k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m2.elementAt(k).elementAt(j); + k++; } +// v2.addElement(new Integer(erg)); + v2.addElement(erg); + j++; } + ret.addElement(v2); + i++; + } + return ret; + }; +} + + +class mathStrucUseMatrixOP { + + main() { + Vector> vv = new Vector>(); + Vector v1 = new Vector(); + v1.addElement(2); + v1.addElement(2); + Vector v2 = new Vector(); + v2.addElement(3); + v2.addElement(3); + vv.addElement(v1); + vv.addElement(v2); + + MatrixOP m1 = new MatrixOP(vv); + + Vector> vv1 = new Vector>(); + Vector v3 = new Vector(); + v3.addElement(2); + v3.addElement(2); + Vector v4 = new Vector(); + v4.addElement(3); + v4.addElement(3); + vv1.addElement(v3); + vv1.addElement(v4); + + MatrixOP m2 = new MatrixOP(vv1); + + var mms; + mms = new mathStrucMatrixOP<>(m1); + var mms2; + mms2 = new mathStrucMatrixOP<>(m2); + var mms3; + mms3 = mms.innerOp.apply(m1.mul).apply(mms2); + return mms3; + } +}