From a3000d0ba1869054eaa4e61c4d3642c0c1d2bea9 Mon Sep 17 00:00:00 2001 From: KingJulian Date: Fri, 28 Jun 2024 11:13:22 +0200 Subject: [PATCH] Test update --- classWithMain.class | Bin 0 -> 65 bytes emptyClass.class | Bin 0 -> 62 bytes src/NichtHaskell1.iml | 12 + src/main/java/Compiler.java | 2 +- src/main/java/TestClass.java | 3 +- .../abstractSyntaxTree/Class/FieldDecl.java | 7 +- .../abstractSyntaxTree/Class/MethodDecl.java | 4 +- .../abstractSyntaxTree/Class/RefType.java | 6 +- .../Datatype/BoolDatatype.java | 7 +- .../Datatype/CharDatatype.java | 5 +- .../Datatype/IntDatatype.java | 5 +- .../Expression/BinaryExpression.java | 5 +- .../Expression/BooleanConstantExpression.java | 13 + .../Expression/CharConstantExpression.java | 12 + .../Expression/InstVarExpression.java | 5 +- .../Expression/IntConstantExpression.java | 5 +- .../Expression/LocalVarIdentifier.java | 5 +- src/main/java/abstractSyntaxTree/Program.java | 3 +- src/test/java/AST/testAll.java | 11 +- src/test/java/ASTs/fourClassesAST.java | 230 ++++++++++++++---- .../java/ByteCode/CompareByteCodeSyntax.java | 20 +- src/test/java/ByteCode/TestAll.java | 34 ++- .../resources/basicClasses/Fakultaet.class | Bin 0 -> 393 bytes .../resources/basicClasses/Fakultaet.java | 19 ++ .../resources/basicClasses/FourClasses.java | 8 +- src/test/resources/basicClasses/Test.class | Bin 0 -> 464 bytes src/test/resources/basicClasses/Test2.class | Bin 0 -> 271 bytes src/test/resources/basicClasses/Test3.class | Bin 0 -> 419 bytes .../basicClasses/classWithMain.class | Bin 0 -> 271 bytes .../resources/basicClasses/classWithMain.java | 6 + .../resources/basicClasses/emptyClass.class | Bin 0 -> 194 bytes 31 files changed, 348 insertions(+), 79 deletions(-) create mode 100644 classWithMain.class create mode 100644 emptyClass.class create mode 100644 src/test/resources/basicClasses/Fakultaet.class create mode 100644 src/test/resources/basicClasses/Fakultaet.java create mode 100644 src/test/resources/basicClasses/Test.class create mode 100644 src/test/resources/basicClasses/Test2.class create mode 100644 src/test/resources/basicClasses/Test3.class create mode 100644 src/test/resources/basicClasses/classWithMain.class create mode 100644 src/test/resources/basicClasses/classWithMain.java create mode 100644 src/test/resources/basicClasses/emptyClass.class diff --git a/classWithMain.class b/classWithMain.class new file mode 100644 index 0000000000000000000000000000000000000000..ede677c2712e12474d40bd491138cdff673c8a7e GIT binary patch literal 65 zcmX^0Z`VEs1_l!bRz?Qi + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/Compiler.java b/src/main/java/Compiler.java index fb2f6d9..28b873d 100644 --- a/src/main/java/Compiler.java +++ b/src/main/java/Compiler.java @@ -18,7 +18,7 @@ public class Compiler { public static void main(String[] args) throws Exception{ - Path filePath = Paths.get("src/main/java/Input.java"); + Path filePath = Paths.get("src/main/java/TestClass.java"); // todo remove this debug info diff --git a/src/main/java/TestClass.java b/src/main/java/TestClass.java index 9150abd..f21bd45 100644 --- a/src/main/java/TestClass.java +++ b/src/main/java/TestClass.java @@ -1,6 +1,5 @@ public class TestClass { public static void main(String[] args){ -// new Example(); -// new Example2(); + } } diff --git a/src/main/java/abstractSyntaxTree/Class/FieldDecl.java b/src/main/java/abstractSyntaxTree/Class/FieldDecl.java index 1213e5e..a79fe5d 100644 --- a/src/main/java/abstractSyntaxTree/Class/FieldDecl.java +++ b/src/main/java/abstractSyntaxTree/Class/FieldDecl.java @@ -69,7 +69,10 @@ public class FieldDecl extends AbstractType implements Node { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FieldDecl fieldDecl = (FieldDecl) o; - return ( Objects.equals(type, fieldDecl.type) - && Objects.equals(identifier, fieldDecl.identifier)); + boolean result = Objects.equals(type, fieldDecl.type) + && Objects.equals(identifier, fieldDecl.identifier); + + System.out.println("In FieldDecl: " + result); + return result; } } diff --git a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java index c59353f..c1143b8 100644 --- a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java +++ b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java @@ -173,10 +173,12 @@ public class MethodDecl implements Node { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MethodDecl methodDecl = (MethodDecl) o; - return (Objects.equals(name, methodDecl.name) + boolean result = (Objects.equals(name, methodDecl.name) && Objects.equals(parameters, methodDecl.parameters) && Objects.equals(returnType, methodDecl.returnType) && Objects.equals(codeBlock, methodDecl.codeBlock)); + System.out.println("In MethodDecl: " + result); + return result; } } diff --git a/src/main/java/abstractSyntaxTree/Class/RefType.java b/src/main/java/abstractSyntaxTree/Class/RefType.java index 218b8bd..76cc208 100644 --- a/src/main/java/abstractSyntaxTree/Class/RefType.java +++ b/src/main/java/abstractSyntaxTree/Class/RefType.java @@ -96,14 +96,16 @@ public class RefType extends AbstractType implements Node { @Override public boolean equals(Object o) { - System.out.println("Dont forget me ;)"); if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RefType refType = (RefType) o; - return ( Objects.equals(name, refType.name) + boolean result = ( Objects.equals(name, refType.name) && Objects.equals(fieldDecls, refType.fieldDecls) && Objects.equals(methodDecls, refType.methodDecls) && Objects.equals(hasMain, refType.hasMain)); + System.out.println("In RefType: " + result); + + return result; } } diff --git a/src/main/java/abstractSyntaxTree/Datatype/BoolDatatype.java b/src/main/java/abstractSyntaxTree/Datatype/BoolDatatype.java index 1ed7d5f..d5a0518 100644 --- a/src/main/java/abstractSyntaxTree/Datatype/BoolDatatype.java +++ b/src/main/java/abstractSyntaxTree/Datatype/BoolDatatype.java @@ -14,7 +14,10 @@ public class BoolDatatype extends AbstractType implements IDatatype{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BoolDatatype boolDatatype = (BoolDatatype) o; - return (Objects.equals(value, boolDatatype.value)); + boolean result = Objects.equals(value, boolDatatype.value); + System.out.println("In BoolDataType: " + result); + + return result; } @Override public TypeCheckResult typeCheck() { @@ -39,4 +42,6 @@ public class BoolDatatype extends AbstractType implements IDatatype{ public TypeCheckResult getTypeCheckResult() { return super.getTypeCheckResult(); } + + } diff --git a/src/main/java/abstractSyntaxTree/Datatype/CharDatatype.java b/src/main/java/abstractSyntaxTree/Datatype/CharDatatype.java index 92e74be..3ed8014 100644 --- a/src/main/java/abstractSyntaxTree/Datatype/CharDatatype.java +++ b/src/main/java/abstractSyntaxTree/Datatype/CharDatatype.java @@ -32,7 +32,10 @@ public class CharDatatype extends AbstractType implements IDatatype{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CharDatatype charDatatype = (CharDatatype) o; - return (Objects.equals(value, charDatatype.value)); + boolean result = Objects.equals(value, charDatatype.value); + System.out.println("In CharDataType: " + result); + + return result; } @Override diff --git a/src/main/java/abstractSyntaxTree/Datatype/IntDatatype.java b/src/main/java/abstractSyntaxTree/Datatype/IntDatatype.java index b1576aa..6d86b89 100644 --- a/src/main/java/abstractSyntaxTree/Datatype/IntDatatype.java +++ b/src/main/java/abstractSyntaxTree/Datatype/IntDatatype.java @@ -36,7 +36,10 @@ public class IntDatatype extends AbstractType implements IDatatype{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IntDatatype intDatatype = (IntDatatype) o; - return (Objects.equals(value, intDatatype.value)); + boolean result = (Objects.equals(value, intDatatype.value)); + System.out.println("In IntDataType: " + result); + + return result; } @Override diff --git a/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java b/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java index 5086324..2396975 100644 --- a/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java @@ -181,10 +181,13 @@ public class BinaryExpression extends AbstractType implements IExpression{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BinaryExpression binaryExpression = (BinaryExpression) o; - return (Objects.equals(operator, binaryExpression.operator) + boolean result = (Objects.equals(operator, binaryExpression.operator) && Objects.equals(left, binaryExpression.left) && Objects.equals(right, binaryExpression.right) ); + System.out.println("In BinaryExpression: " + result); + + return result; } @Override public TypeCheckResult getTypeCheckResult() { diff --git a/src/main/java/abstractSyntaxTree/Expression/BooleanConstantExpression.java b/src/main/java/abstractSyntaxTree/Expression/BooleanConstantExpression.java index 1400bd2..48313ec 100644 --- a/src/main/java/abstractSyntaxTree/Expression/BooleanConstantExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/BooleanConstantExpression.java @@ -3,12 +3,14 @@ package abstractSyntaxTree.Expression; import TypeCheck.AbstractType; import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckResult; +import abstractSyntaxTree.Datatype.BoolDatatype; import abstractSyntaxTree.Parameter.ParameterList; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Objects; public class BooleanConstantExpression extends AbstractType implements IExpression{ public boolean value; @@ -37,4 +39,15 @@ public class BooleanConstantExpression extends AbstractType implements IExpressi public TypeCheckResult getTypeCheckResult() { return super.getTypeCheckResult(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BooleanConstantExpression boolDatatype = (BooleanConstantExpression) o; + boolean result = Objects.equals(value, boolDatatype.value); + System.out.println("In BooleanConstantExpression: " + result); + + return result; + } } diff --git a/src/main/java/abstractSyntaxTree/Expression/CharConstantExpression.java b/src/main/java/abstractSyntaxTree/Expression/CharConstantExpression.java index 00df59e..01a733d 100644 --- a/src/main/java/abstractSyntaxTree/Expression/CharConstantExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/CharConstantExpression.java @@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Objects; public class CharConstantExpression extends AbstractType implements IExpression{ public char value; @@ -33,4 +34,15 @@ public class CharConstantExpression extends AbstractType implements IExpression{ public TypeCheckResult getTypeCheckResult() { return super.getTypeCheckResult(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CharConstantExpression boolDatatype = (CharConstantExpression) o; + boolean result = Objects.equals(value, boolDatatype.value); + System.out.println("In CharConstantExpression: " + result); + + return result; + } } diff --git a/src/main/java/abstractSyntaxTree/Expression/InstVarExpression.java b/src/main/java/abstractSyntaxTree/Expression/InstVarExpression.java index ee15a8c..dffe91a 100644 --- a/src/main/java/abstractSyntaxTree/Expression/InstVarExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/InstVarExpression.java @@ -80,9 +80,12 @@ public class InstVarExpression extends AbstractType implements IExpression{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InstVarExpression instVarExpression = (InstVarExpression) o; - return (Objects.equals(thisClass, instVarExpression.thisClass) + boolean result = (Objects.equals(thisClass, instVarExpression.thisClass) && Objects.equals(fieldName, instVarExpression.fieldName) ); + System.out.println("In InstVarExpression: " + result); + + return result; } @Override diff --git a/src/main/java/abstractSyntaxTree/Expression/IntConstantExpression.java b/src/main/java/abstractSyntaxTree/Expression/IntConstantExpression.java index e3a689b..1541d5a 100644 --- a/src/main/java/abstractSyntaxTree/Expression/IntConstantExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/IntConstantExpression.java @@ -37,8 +37,11 @@ public class IntConstantExpression extends AbstractType implements IExpression{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IntConstantExpression intConstantExpression = (IntConstantExpression) o; - return (Objects.equals(value, intConstantExpression.value) + boolean result = (Objects.equals(value, intConstantExpression.value) ); + System.out.println("In intConstantExpression: " + result); + + return result; } @Override diff --git a/src/main/java/abstractSyntaxTree/Expression/LocalVarIdentifier.java b/src/main/java/abstractSyntaxTree/Expression/LocalVarIdentifier.java index aac2115..d098002 100644 --- a/src/main/java/abstractSyntaxTree/Expression/LocalVarIdentifier.java +++ b/src/main/java/abstractSyntaxTree/Expression/LocalVarIdentifier.java @@ -93,7 +93,10 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{ if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LocalVarIdentifier localVarIdentifier = (LocalVarIdentifier) o; - return (Objects.equals(identifier, localVarIdentifier.identifier) + boolean result = (Objects.equals(identifier, localVarIdentifier.identifier) ); + System.out.println("In localVarIdentifier: " + result); + + return result; } } diff --git a/src/main/java/abstractSyntaxTree/Program.java b/src/main/java/abstractSyntaxTree/Program.java index eb2508b..2582f18 100644 --- a/src/main/java/abstractSyntaxTree/Program.java +++ b/src/main/java/abstractSyntaxTree/Program.java @@ -120,8 +120,7 @@ public class Program implements Node { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Program program = (Program) o; - System.out.println(classes); - System.out.println(program.classes); + System.out.println("In program: " + Objects.equals(classes, program.classes)); return (Objects.equals(classes, program.classes)); } } \ No newline at end of file diff --git a/src/test/java/AST/testAll.java b/src/test/java/AST/testAll.java index 7b9c41c..a775d53 100644 --- a/src/test/java/AST/testAll.java +++ b/src/test/java/AST/testAll.java @@ -8,15 +8,22 @@ public class testAll { AstComparer astComparer; public testAll() { - this.astComparer = new AstComparer("test/resources"); + this.astComparer = new AstComparer("src/test/resources"); } @Test - public void TestEmptyClass(){ + public void testEmptyClass(){ Program ast = emptyClassAST.getEmptyProgramm(); String pathToCode = "basicClasses/emptyClass.java"; testAst(ast, pathToCode); } + + @Test + public void testEmptyClassWithConstructor(){ + Program ast = emptyClassAST.getEmptyProgramm(); + String pathToCode = "basicClasses/emptyClassWithConstructor.java"; + testAst(ast, pathToCode); + } public void testAst(Program ast, String pathToCode) { diff --git a/src/test/java/ASTs/fourClassesAST.java b/src/test/java/ASTs/fourClassesAST.java index 5a2569c..26ebc86 100644 --- a/src/test/java/ASTs/fourClassesAST.java +++ b/src/test/java/ASTs/fourClassesAST.java @@ -3,21 +3,24 @@ package ASTs; import abstractSyntaxTree.Class.FieldDecl; import abstractSyntaxTree.Class.MethodDecl; import abstractSyntaxTree.Class.RefType; -import abstractSyntaxTree.Expression.IExpression; -import abstractSyntaxTree.Expression.InstVarExpression; +import abstractSyntaxTree.Expression.*; import abstractSyntaxTree.Parameter.Parameter; import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Program; import abstractSyntaxTree.Statement.BlockStatement; import abstractSyntaxTree.Statement.IStatement; +import abstractSyntaxTree.Statement.LocalVarDecl; import abstractSyntaxTree.Statement.ReturnStatement; import abstractSyntaxTree.StatementExpression.AssignStatementExpression; import abstractSyntaxTree.StatementExpression.NewStatementExpression; +import abstractSyntaxTree.StatementExpression.ReceivingMethod; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; - /* + public class fourClassesAST extends Program { public fourClassesAST() @@ -26,55 +29,174 @@ public class fourClassesAST extends Program { } private static List staticClasses() { - /////////// Classes /////////// - - ///////// Class: FourClasses ///////// - - /////// Fields /////// - List fieldDeclList = new ArrayList<>(); - - ParameterList emptyParameterList = new ParameterList(new ArrayList<>()); - - /////// Methods /////// - - // Main // - - List emptyIStatementList = new ArrayList<>(); - BlockStatement emptyBlockStatement = new BlockStatement(emptyIStatementList, "void"); - MethodDecl constructor = new MethodDecl("emptyClassWithConstructor", "null", "emptyClassWithConstructor", emptyParameterList, emptyBlockStatement); - - //IStatement - List fourClassesMainBlockIstatements = new ArrayList<>(); - - IExpression atntiLeft = new InstVarExpression("Test", "t"); - IExpression atntiRight = new NewStatementExpression(); - AssignStatementExpression atnti = new AssignStatementExpression(atntiLeft, "=", ); - - - ReturnStatement fcmbiReturn = new ReturnStatement(); - - fourClassesMainBlockIstatements.add(atnti); - //BlockStatement - BlockStatement fourClassesMainBlock = new BlockStatement(fourClassesMainBlockIstatements, "int"); - - //Parameter - Parameter intI = new Parameter("int", "i"); - List fourClassesMainParameterList = new ArrayList<>(); - - ParameterList fourClassesMainParameters = new ParameterList(fourClassesMainParameterList); - - MethodDecl fourClassesMain = new MethodDecl("fourClasses", "int", "main", fourClassesMainParameters, fourClassesMainBlock); - List MethodDeclList = new ArrayList<>(); - - RefType emptyClass = new RefType("emptyClass", fieldDeclList, MethodDeclList, false); - - - - - - - List classes = new ArrayList<>(); - classes.add(emptyClass); - return classes; + return program; } -}*/ + + public RefType Test() { + + + // Class Test + + //public int x + FieldDecl publicIntX = new FieldDecl("int","x"); + + //public int y + FieldDecl publicIntY = new FieldDecl("int", "y"); + + //public Test3 test3 + FieldDecl Test3test3 = new FieldDecl("Test3", "test3"); + + // FieldDeclList + List fieldDeclList = new ArrayList<>(); + fieldDeclList.add(publicIntX); + fieldDeclList.add(publicIntY); + fieldDeclList.add(Test3test3); + + // (int i) + List par11 = new ArrayList<>(); + Parameter inti = new Parameter("int", "i"); + par11.add(inti); + ParameterList par1 = new ParameterList(par11); + + //this.x + InstVarExpression thisX = new InstVarExpression("X"); + + // i + LocalVarIdentifier i = new LocalVarIdentifier("i"); + + //this.x = i + AssignStatementExpression thisXeqI = new AssignStatementExpression("=", thisX, i); + + //this.test3 + LocalVarIdentifier thisTest3 = new LocalVarIdentifier("test3"); + + // 2 + IntConstantExpression two = new IntConstantExpression(2); + //(i * 2) + BinaryExpression iTimes2 = new BinaryExpression("*", i, two); + + //new Test3(i*2) + List exprNewTest3 = new ArrayList<>(); + exprNewTest3.add(iTimes2); + NewStatementExpression newTest3 = new NewStatementExpression("Test3",exprNewTest3 ); + + //this.test3 = new Test3(i * 2); + AssignStatementExpression thisTesteqNewTest3 = new AssignStatementExpression("=", thisTest3, newTest3); + + // {} + List ilistTest = new ArrayList<>(); + ilistTest.add(thisTesteqNewTest3); + BlockStatement blockTest = new BlockStatement(ilistTest,"void"); + + //public Test (int i) + MethodDecl Test = new MethodDecl("Test", "void", + "Test", par1, blockTest); + + + // public Test3 getTest3() {return this.test3;} + + //this.test3 + //LocalVarIdentifier thisTest3 = new LocalVarIdentifier("test3") + + // return this.test3 + ReturnStatement returnThisTest3 = new ReturnStatement(thisTest3); + + // {return this.test3} + List getTest3Stmts = new ArrayList<>(); + getTest3Stmts.add(returnThisTest3); + BlockStatement blockReturnThisTest3 = new BlockStatement(getTest3Stmts, "Test3"); + + ParameterList emptyParamList = new ParameterList(null); + MethodDecl getTest3 = new MethodDecl("Test", "Test3", + "gettest3", emptyParamList, blockReturnThisTest3); + + + //this.x + //LocalVarIdentifier thisX = new LocalVarIdentifier("x"); + + //return this.x + ReturnStatement returnThisX = new ReturnStatement(thisX); + + // {return this.x} + List stmtsBlockReturnX = new ArrayList<>(); + stmtsBlockReturnX.add(returnThisX); + BlockStatement blockReturnX = new BlockStatement(stmtsBlockReturnX,"int"); + + //public int getX() { + // return this.x; + // } + MethodDecl getX = new MethodDecl("Test", "int", + "getX", emptyParamList, blockReturnX); + + //MethodDeclList + List methodDeclList = new ArrayList<>(); + methodDeclList.add(Test); + methodDeclList.add(getTest3); + methodDeclList.add(getX); + + // Class Test + RefType ClassTest = new RefType("Test", fieldDeclList, + methodDeclList, false); + + return ClassTest; + } + + public RefType FourClasses() { + + LocalVarDecl localVarDecl1 = () -> { + String type = Test2; + String identifier = "t2"; + NewStatementExpression expression = () -> { + String className = "Test2"; + List arguments = () -> { + InstVarExpression arg0 = () -> { + List receivers = () -> { + ArrayList subReceiverList = new ArrayList<>(); + SubReceiver subreceiver1 = new SubReceiver(); + + subReceiverList.add(subreceiver1); + + return subReceiverList; + }; + List = () -> { + ArrayList receivingMethodList = new ArrayList<>(); + ReceivingMethod receivingMethod01 = () -> { + new ReceivingMethod(); + } + return receivingMethodList + }; + + return new InstVarExpression(); + }; + }; + return new NewStatementExpression(); + }; + + return new LocalVarDecl(); + }; + + LocalVarIdentifier localVarIdentifier01 = new LocalVarIdentifier("i"); + List localargumentList01 = new ArrayList<>(); + localargumentList01.add(localVarIdentifier01); + NewStatementExpression newstmtexpr01 = new NewStatementExpression("Test", localargumentList01); + LocalVarDecl statement01 = new LocalVarDecl("Test", "t", newstmtexpr01); + List statements01 = new ArrayList<>(); + statements01.add(statement01); + BlockStatement blockStatement0 = new BlockStatement(statements01, "int"); + + Parameter parameter01 = new Parameter("int", "i"); + List parameterList0x = new ArrayList<>(); + parameterList0x.add(parameter01); + ParameterList parameterList0 = new ParameterList(parameterList0x); + MethodDecl methodDecl0 = new MethodDecl("FourClasses", "int", "main", parameterList0, blockStatement0); + + List fieldDeclsList = new ArrayList<>(); + List methodDeclList = new ArrayList<>(); + methodDeclList.add(methodDecl0); + RefType FourClassesClass = new RefType("FourClasses", fieldDeclsList, methodDeclList, true); + + return FourClassesClass; + } + +} +*/ \ No newline at end of file diff --git a/src/test/java/ByteCode/CompareByteCodeSyntax.java b/src/test/java/ByteCode/CompareByteCodeSyntax.java index cddcad6..162e9ad 100644 --- a/src/test/java/ByteCode/CompareByteCodeSyntax.java +++ b/src/test/java/ByteCode/CompareByteCodeSyntax.java @@ -4,18 +4,23 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; + public class CompareByteCodeSyntax { public static boolean haveSameBehavior(Class class1, Class class2) { + System.out.println("Comparing class signatures of " + class1.getName() + " and " + class2.getName()); if (!compareClassSignatures(class1, class2)) { return false; } + System.out.println("Comparing methods of " + class1.getName() + " and " + class2.getName()); if (!compareMethods(class1, class2)) { return false; } + System.out.println("Comparing fields of " + class1.getName() + " and " + class2.getName()); if (!compareFields(class1, class2)) { return false; } + System.out.println("Comparing annotations of " + class1.getName() + " and " + class2.getName()); if (!compareAnnotations(class1.getAnnotations(), class2.getAnnotations())) { return false; } @@ -24,9 +29,11 @@ public class CompareByteCodeSyntax { public static boolean compareClassSignatures(Class class1, Class class2) { if (!Arrays.equals(class1.getInterfaces(), class2.getInterfaces())) { + System.out.println("Interfaces do not match"); return false; } if (class1.getSuperclass() != class2.getSuperclass()) { + System.out.println("Superclasses do not match"); return false; } return true; @@ -36,6 +43,7 @@ public class CompareByteCodeSyntax { Method[] methods1 = class1.getDeclaredMethods(); Method[] methods2 = class2.getDeclaredMethods(); if (methods1.length != methods2.length) { + System.out.println("Method counts do not match"); return false; } for (Method method1 : methods1) { @@ -49,6 +57,7 @@ public class CompareByteCodeSyntax { } } if (!found) { + System.out.println("No matching method found for: " + method1.getName()); return false; } } @@ -57,15 +66,19 @@ public class CompareByteCodeSyntax { public static boolean compareMethod(Method method1, Method method2) { if (!method1.getReturnType().equals(method2.getReturnType())) { + System.out.println("Return types do not match for methods " + method1.getName() + " and " + method2.getName()); return false; } if (!Arrays.equals(method1.getParameterTypes(), method2.getParameterTypes())) { + System.out.println("Parameter types do not match for methods " + method1.getName() + " and " + method2.getName()); return false; } if (!Arrays.equals(method1.getExceptionTypes(), method2.getExceptionTypes())) { + System.out.println("Exception types do not match for methods " + method1.getName() + " and " + method2.getName()); return false; } if (!compareAnnotations(method1.getAnnotations(), method2.getAnnotations())) { + System.out.println("Annotations do not match for methods " + method1.getName() + " and " + method2.getName()); return false; } return true; @@ -75,6 +88,7 @@ public class CompareByteCodeSyntax { Field[] fields1 = class1.getDeclaredFields(); Field[] fields2 = class2.getDeclaredFields(); if (fields1.length != fields2.length) { + System.out.println("Field counts do not match"); return false; } for (Field field1 : fields1) { @@ -88,6 +102,7 @@ public class CompareByteCodeSyntax { } } if (!found) { + System.out.println("No matching field found for: " + field1.getName()); return false; } } @@ -96,9 +111,11 @@ public class CompareByteCodeSyntax { public static boolean compareField(Field field1, Field field2) { if (!field1.getType().equals(field2.getType())) { + System.out.println("Field types do not match for fields " + field1.getName() + " and " + field2.getName()); return false; } if (!compareAnnotations(field1.getAnnotations(), field2.getAnnotations())) { + System.out.println("Annotations do not match for fields " + field1.getName() + " and " + field2.getName()); return false; } return true; @@ -106,6 +123,7 @@ public class CompareByteCodeSyntax { public static boolean compareAnnotations(Annotation[] annotations1, Annotation[] annotations2) { if (annotations1.length != annotations2.length) { + System.out.println("Annotation counts do not match"); return false; } for (Annotation annotation1 : annotations1) { @@ -117,10 +135,10 @@ public class CompareByteCodeSyntax { } } if (!found) { + System.out.println("No matching annotation found for: " + annotation1.annotationType().getName()); return false; } } return true; } } - diff --git a/src/test/java/ByteCode/TestAll.java b/src/test/java/ByteCode/TestAll.java index b5a21de..5e72098 100644 --- a/src/test/java/ByteCode/TestAll.java +++ b/src/test/java/ByteCode/TestAll.java @@ -79,17 +79,19 @@ public class TestAll { abstractSyntaxTree.typeCheck(); } catch (Exception e){ System.out.println("Le Exception in le type-check"); + //fail(); } try { abstractSyntaxTree.codeGen(); } catch (Exception e){ System.out.println("Le Exception in le codegen"); + fail(); } try { ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath); - ClassFileLoader classLoader2 = new ClassFileLoader(className + ".class"); + ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class"); Class class1 = classLoader1.findClass(className); Class class2 = classLoader2.findClass(className); @@ -112,5 +114,35 @@ public class TestAll { //testByteCodeFromScratch(classPath, javacode, className); } + @Test + public void testFourClasses() { + String classPath = "src/test/resources/basicClasses/FourClasses.class"; + Program ast = emptyClassAST.getEmptyProgramm(); + String className = "emptyClass"; + String javacode = "src/test/resources/basicClasses/FourClasses.java"; + //testByteCodeFromAst(classPath, ast ,className); + testByteCodeFromScratch(classPath, javacode, className); + } + + @Test + public void testFakultaet() { + String classPath = "src/test/resources/basicClasses/Fakultaet.class"; + Program ast = emptyClassAST.getEmptyProgramm(); + String className = "Fakultät"; + String javacode = "src/test/resources/basicClasses/Fakultaet.java"; + //testByteCodeFromAst(classPath, ast ,className); + testByteCodeFromScratch(classPath, javacode, className); + } + + @Test + public void testClassWithMain() { + String classPath = "src/test/resources/basicClasses/classWithMain.class"; + Program ast = emptyClassAST.getEmptyProgramm(); + String className = "classWithMain"; + String javacode = "src/test/resources/basicClasses/classWithMain.java"; + //testByteCodeFromAst(classPath, ast ,className); + testByteCodeFromScratch(classPath, javacode, className); + } + } diff --git a/src/test/resources/basicClasses/Fakultaet.class b/src/test/resources/basicClasses/Fakultaet.class new file mode 100644 index 0000000000000000000000000000000000000000..d8f6f98cbe7ee928495d8d1b4a77d8665880dfa4 GIT binary patch literal 393 zcmZ8byG{Z@6g`(27FeEI5Dj1~!9qSjq0oec1hrU$h1D#sxI7j@7Qe>I#)ihq#KI5o zhpc>@L8FOtGxwgk=gv9z_2c;kz!5fGB%o5zIV9l-N+WY?niCTZn`izg7{mhSFpR>u zEl~AFKZUd)(=p@aBsKwAeLTAg1jSw$1*glYA1uy|KVe5*n=$Enx6u{kz1R%KCuaUb z>Zu7MLAid}`!n?7MHmea8hwH5&6bNn& zBLQ`oEp4$NiyX5Zy`X?*-KyLnsaLwC+O^6(+-mKn_3-&tU6D(yfA7%D8fk{ZNb~J7 i7pYUGUY=|Q%6W$p$r2VweVc5PT3i3$#SWC#4jW%CYd)a> literal 0 HcmV?d00001 diff --git a/src/test/resources/basicClasses/Fakultaet.java b/src/test/resources/basicClasses/Fakultaet.java new file mode 100644 index 0000000..57e5a2d --- /dev/null +++ b/src/test/resources/basicClasses/Fakultaet.java @@ -0,0 +1,19 @@ +class Fakultaet { + public int fak(int number) { + if (number < 0) { + return 1; + } + int factorial = 1; + int i = 0; + while(i < number){ + factorial = factorial * i; + } + + return factorial; + } + + public static void main(String[] args){ + + } + +} \ No newline at end of file diff --git a/src/test/resources/basicClasses/FourClasses.java b/src/test/resources/basicClasses/FourClasses.java index 625731c..cc01eb0 100644 --- a/src/test/resources/basicClasses/FourClasses.java +++ b/src/test/resources/basicClasses/FourClasses.java @@ -19,11 +19,11 @@ class Test { this.test3 = new Test3(i * 2); } - public Test3 getTest3() { + public Test3 getTest3(int not) { return this.test3; } - public int getX() { + public int getX(int not) { return this.x; } } @@ -46,11 +46,11 @@ class Test3 { this.x = i; } - public int getX() { + public int getX(int not) { return this.x; } - public int getY() { + public int getY(int not) { return this.y; } diff --git a/src/test/resources/basicClasses/Test.class b/src/test/resources/basicClasses/Test.class new file mode 100644 index 0000000000000000000000000000000000000000..b4563ae649e7443f9f1399b16f42b7d19efa090c GIT binary patch literal 464 zcmZ9HPfx-?5XIk8N@=Z9KtQeh@diD}!K225BqSt64-%utf*UMBNN6$oojhnFA<@JS z;D<84twfE7o!x!&o0&HspRex#POxVo0nI?thK`hgGxG2J=GdPMn`ixz97F=CqhJz5 z#{yctabY42(|~1T4YokCCqp9Qo~NU78#Xd3As!551$31^u;3uC25hpT-udoQv{Awq zkw_r|MmJ^;iL|EIQXta}Ch~NC+n2MR-yc&+4`mcX0%pDO%TvCL?R5mK^XYsxknKPf zIBkAfV?PXKxUV)tjUE%+T!T;>@Wnx^n|4+iI;FnNUz@HKU-6a@p1XkIIo1N}-W!}N zSHD>zw?N@J?z6*KBoD5eL>4A;?43tB?&e~5)w9f7kkY*u6rO%cQ?XcLETh7x#{Wf) N$A73xs7ft?+829lKg0k4 literal 0 HcmV?d00001 diff --git a/src/test/resources/basicClasses/Test2.class b/src/test/resources/basicClasses/Test2.class new file mode 100644 index 0000000000000000000000000000000000000000..0459f8d173709c982c8d7ab3a132f07ccdb0a4d2 GIT binary patch literal 271 zcmXYrL2JT55QX0+(XDCJXsefAO7)-~Dtc8sCcWC8;dsa(E8wrxuWCms{%KExm0qR-*?t&@=|I44H0Kfz z0?te)sS63$Og*yD_-M{^$fF=p^x&f;kTIezdntdqObqwPqs_M#C{Dsyf9}?S-p*7I zvEqJhcH5;MhX(vHVHBw((aF2H39q!bc(dT+f_ujGGtB4L`v-t?Y`M^&+b}$sumt>Jd>@BtoDIUO-ca@n0qZo$lHyE2 zuQ$357U0-$JuJc#Fgr3Y4h6&mPo$bv4>i>hj{-(LYII4h@tqW?T_l;joQ`^O(usR1 zE5<+;H|5^wC%Gl%vLLzFWW&U2YJl|k(CCXEl!Ae0eC++VW6$b?T^ zVl|*b>D=HABG`U~{ak97iB;&teHduMLCA>}tj^|k$bwxnc!B*iAF;~f0dehLY2~l< eh|=}Bo4uJEOF60hI#GWB9Mks+^&5;eY<>fcDKrTH literal 0 HcmV?d00001 diff --git a/src/test/resources/basicClasses/classWithMain.class b/src/test/resources/basicClasses/classWithMain.class new file mode 100644 index 0000000000000000000000000000000000000000..e43c75f168d6fd1d18d39eae880c48cd02ca7bb5 GIT binary patch literal 271 zcmZ8bJr4m<5S-;W=Q|3CLZU>$4)uAA#P`x`ZJULHtj{l{SDEt6FO6=3pBaPvAqWn$CT}uI_YS%-;VwpF8}6WhVzPloqOkfOvp7&bE24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2CmfHf|5$-oW$Z{Mg|t={FGEi27aH+yi~u^+@#c^ki?`Mpa@rR zerZv1s#_+A!;jFS2eN`efq@-pGYBvOG0<)x%?V`50%@>_)^-NQjbLdmAPJHNDP?5f J2GUFnJOIRxBzFJ+ literal 0 HcmV?d00001