diff --git a/classWithMain.class b/classWithMain.class
new file mode 100644
index 0000000..ede677c
Binary files /dev/null and b/classWithMain.class differ
diff --git a/emptyClass.class b/emptyClass.class
new file mode 100644
index 0000000..f25c19b
Binary files /dev/null and b/emptyClass.class differ
diff --git a/src/NichtHaskell1.iml b/src/NichtHaskell1.iml
index 2336fe3..ccf5ff5 100644
--- a/src/NichtHaskell1.iml
+++ b/src/NichtHaskell1.iml
@@ -8,5 +8,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ 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 0ccb21b..6b775f6 100644
--- a/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java
+++ b/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java
@@ -182,10 +182,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 0000000..d8f6f98
Binary files /dev/null and b/src/test/resources/basicClasses/Fakultaet.class differ
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 0000000..b4563ae
Binary files /dev/null and b/src/test/resources/basicClasses/Test.class differ
diff --git a/src/test/resources/basicClasses/Test2.class b/src/test/resources/basicClasses/Test2.class
new file mode 100644
index 0000000..0459f8d
Binary files /dev/null and b/src/test/resources/basicClasses/Test2.class differ
diff --git a/src/test/resources/basicClasses/Test3.class b/src/test/resources/basicClasses/Test3.class
new file mode 100644
index 0000000..cb9f466
Binary files /dev/null and b/src/test/resources/basicClasses/Test3.class differ
diff --git a/src/test/resources/basicClasses/classWithMain.class b/src/test/resources/basicClasses/classWithMain.class
new file mode 100644
index 0000000..e43c75f
Binary files /dev/null and b/src/test/resources/basicClasses/classWithMain.class differ
diff --git a/src/test/resources/basicClasses/classWithMain.java b/src/test/resources/basicClasses/classWithMain.java
new file mode 100644
index 0000000..a67d71e
--- /dev/null
+++ b/src/test/resources/basicClasses/classWithMain.java
@@ -0,0 +1,6 @@
+class classWithMain {
+ public static void main(String[] args){
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/basicClasses/emptyClass.class b/src/test/resources/basicClasses/emptyClass.class
new file mode 100644
index 0000000..833e0b7
Binary files /dev/null and b/src/test/resources/basicClasses/emptyClass.class differ