diff --git a/src/main/java/testfiles/ASTFeatures/AST_Class.java b/src/main/java/testfiles/ASTFeatures/AST_Class.java new file mode 100644 index 0000000..0ea4beb --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Class.java @@ -0,0 +1,32 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.Block; +import de.maishai.ast.records.Constructor; +import de.maishai.ast.records.Program; +import de.maishai.ast.records.Class; + +import java.util.List; + +public class AST_Class { + public static Program get() { + return new Program( + List.of( + new Class( + "Class", + List.of(), + List.of(), + List.of( + new Constructor( + "Class", + List.of(), + new Block( + List.of( + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_ClassObjects.java b/src/main/java/testfiles/ASTFeatures/AST_ClassObjects.java new file mode 100644 index 0000000..9f22ec5 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_ClassObjects.java @@ -0,0 +1,140 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_ClassObjects { + public static Program get() { + return new Program( + List.of( + new Class( + "ClassObjects", + List.of( + new Declaration( + "c", + Type.CHAR + ) + ), + getMethods(), + getConstructors() + ) + ) + ); + } + + private static List getMethods() { + return List.of(getMethod1()); + } + + private static Method getMethod1() { + return new Method( + Type.VOID, + "objectsMethod", + List.of(), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + true, + null, + "b"), + new New( + Type.REFERENCE("ClassObjects"), + List.of() + ) + ), + new Declaration( + "c", + Type.REFERENCE("ClassObjects") + ), + new Assignment( + new FieldVarAccess( + false, + null, + "c"), + new New( + Type.REFERENCE("ClassObjects"), + List.of( + new IntLiteral(2) + ) + ) + ), + new Declaration( + "d", + Type.REFERENCE("ClassObjects") + ), + new Assignment( + new FieldVarAccess( + false, + null, + "c"), + new FieldVarAccess( + true, + new FieldVarAccess( + true, + new FieldVarAccess( + true, + new FieldVarAccess( + false, + null, + "d"), + "b"), + "b"), + "b") + ), + new MethodCall( + new FieldVarAccess( + false, + new FieldVarAccess( + true, + new FieldVarAccess( + true, + new FieldVarAccess( + false, + null, + "c"), + "b"), + "b"), + "objectsMethod"), + List.of() + ) + ) + ) + + ); + } + + private static List getConstructors() { + return List.of(getConstructor1(), getConstructor2()); + } + + private static Constructor getConstructor1() { + return new Constructor( + "ClassObjects", + List.of(), + new Block( + List.of( + ) + ) + ); + } + + private static Constructor getConstructor2() { + return new Constructor( + "ClassObjects", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Comment.java b/src/main/java/testfiles/ASTFeatures/AST_Comment.java new file mode 100644 index 0000000..d5e7e3b --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Comment.java @@ -0,0 +1,32 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.Block; +import de.maishai.ast.records.Class; +import de.maishai.ast.records.Constructor; +import de.maishai.ast.records.Program; + +import java.util.List; + +public class AST_Comment { + public static Program get() { + return new Program( + List.of( + new Class( + "Comment", + List.of(), + List.of(), + List.of( + new Constructor( + "Comment", + List.of(), + new Block( + List.of( + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Constructor.java b/src/main/java/testfiles/ASTFeatures/AST_Constructor.java new file mode 100644 index 0000000..d949c42 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Constructor.java @@ -0,0 +1,115 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + + +import java.util.List; + +public class AST_Constructor { + public static Program get() { + return new Program( + List.of( + new Class( + "Constructor", + List.of(), + List.of(), + List.of( + new Constructor( + "Constructor", + List.of(), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(1) + ) + ) + ) + ), + new Constructor( + "Constructor", + List.of( + new Parameter( + "x", + Type.INT + ) + ), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new FieldVarAccess( + false, + null, + "x" + ) + ) + ) + ) + ), + new Constructor( + "Constructor", + List.of( + new Parameter( + "x", + Type.INT + ), + new Parameter( + "y", + Type.INT + ) + ), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.ADD, + new FieldVarAccess( + false, + null, + "y" + ) + ) + ) + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Continue.java b/src/main/java/testfiles/ASTFeatures/AST_Continue.java new file mode 100644 index 0000000..eefa238 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Continue.java @@ -0,0 +1,103 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Continue { + public static Program get() { + return new Program( + List.of( + new Class( + "Continue", + List.of(), + List.of( + new Method( + Type.VOID, + "continueLoop", + List.of(), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new For( + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(0) + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.LT, + new IntLiteral(5) + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.ADD, + new IntLiteral(1) + ) + + ), + new Block( + List.of( + new IfElse( + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.EQ, + new IntLiteral(3) + ), + new Block( + List.of( + new Continue() + ) + ), + null + ) + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Continue", + List.of(), + new Block( + List.of( + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Field.java b/src/main/java/testfiles/ASTFeatures/AST_Field.java new file mode 100644 index 0000000..9235936 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Field.java @@ -0,0 +1,66 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Field { + public static Program get() { + return new Program( + List.of( + new Class( + "Field", + List.of( + new Declaration( + "x", + Type.INT + ), + new Declaration( + "c", + Type.CHAR + ) + ), + List.of( + new Method( + Type.VOID, + "fieldAccess", + List.of(), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + true, + null, + "x" + ), + new IntLiteral(0) + ), + new Assignment( + new FieldVarAccess( + true, + null, + "c" + ), + new CharLiteral('a') + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Field", + List.of(), + new Block( + List.of() + ) + ) + + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_For.java b/src/main/java/testfiles/ASTFeatures/AST_For.java new file mode 100644 index 0000000..9efb2ce --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_For.java @@ -0,0 +1,127 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_For { + public static Program get() { + return new Program( + List.of( + new Class( + "For", + List.of(), + List.of( + new Method( + Type.VOID, + "testFor", + List.of(), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new For( + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(0) + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.LT, + new IntLiteral(10) + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.ADD, + new IntLiteral(1) + ) + ), + new Block( + List.of() + ) + ), + new Declaration( + "j", + Type.INT + ), + new For( + new Assignment( + new FieldVarAccess( + false, + null, + "j" + ), + new IntLiteral(0) + ), + new Binary( + new FieldVarAccess( + false, + null, + "j" + ), + Operator.LT, + new IntLiteral(10) + ), + new Assignment( + new FieldVarAccess( + false, + null, + "j" + ), + new Binary( + new FieldVarAccess( + false, + null, + "j" + ), + Operator.ADD, + new IntLiteral(1) + ) + ), + new Block( + List.of() + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "For", + List.of(), + new Block( + List.of( + ) + ) + + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_If.java b/src/main/java/testfiles/ASTFeatures/AST_If.java new file mode 100644 index 0000000..be14121 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_If.java @@ -0,0 +1,61 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_If { + public static Program get() { + return new Program( + List.of( + new Class( + "If", + List.of(), + List.of( + new Method( + Type.VOID, + "ifMethod", + List.of(), + new Block( + List.of( + new IfElse( + new BoolLiteral(false), + new Block( + List.of() + ), + new Block( + List.of( + new IfElse( + new BoolLiteral(true), + new Block( + List.of() + ), + new Block( + List.of() + ) + ) + ) + ) + + ) + ) + ) + ) + ), + List.of( + new Constructor( + "If", + List.of(), + new Block( + List.of( + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_IncrDecr.java b/src/main/java/testfiles/ASTFeatures/AST_IncrDecr.java new file mode 100644 index 0000000..5601dc7 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_IncrDecr.java @@ -0,0 +1,86 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_IncrDecr { + public static Program get() { + return new Program( + List.of( + new Class( + "IncrDecr", + List.of(), + List.of( + new Method( + Type.INT, + "increment", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.ADD, + new IntLiteral( + 1 + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "decrement", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.SUB, + new IntLiteral( + 1 + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "IncrDecr", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_LogicExpr.java b/src/main/java/testfiles/ASTFeatures/AST_LogicExpr.java new file mode 100644 index 0000000..d66c800 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_LogicExpr.java @@ -0,0 +1,332 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_LogicExpr { + public static Program get() { + return new Program( + List.of( + new Class( + "LogicExpr", + List.of(), + List.of( + new Method( + Type.BOOL, + "test", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.LT, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ), + new Method( + Type.BOOL, + "test2", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.GT, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ), + new Method( + Type.BOOL, + "test3", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.EQ, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ), + new Method( + Type.BOOL, + "test4", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.NE, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ), + new Method( + Type.BOOL, + "test5", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.LE, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ), + new Method( + Type.BOOL, + "test6", + List.of(), + new Block( + List.of( + new Declaration( + "x", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "x" + ), + new IntLiteral(10) + ), + new Declaration( + "y", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "y" + ), + new IntLiteral(20) + ), + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.GE, + new FieldVarAccess( + false, + null, + "y" + ) + ) + + ) + ) + ) + + ) + ), + List.of( + new Constructor( + "LogicExpr", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Method.java b/src/main/java/testfiles/ASTFeatures/AST_Method.java new file mode 100644 index 0000000..e1627e1 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Method.java @@ -0,0 +1,39 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Method { + public static Program get() { + return new Program( + List.of( + new Class( + "Method", + List.of(), + List.of( + new Method( + Type.VOID, + "method", + List.of(), + new Block( + List.of() + ) + ) + ), + List.of( + new Constructor( + "Method", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_MethodCall.java b/src/main/java/testfiles/ASTFeatures/AST_MethodCall.java new file mode 100644 index 0000000..44b83db --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_MethodCall.java @@ -0,0 +1,160 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_MethodCall { + public static Program get() { + return new Program( + List.of( + new Class( + "MethodCall", + List.of(), + List.of( + new Method( + Type.INT, + "methodCall", + List.of(), + new Block( + List.of( + new Return( + new MethodCall( + new FieldVarAccess( + false, + null, + "method" + ), + List.of() + ) + ) + ) + ) + ), + new Method( + Type.INT, + "methodCall1", + List.of(), + new Block( + List.of( + new Return( + new MethodCall( + new FieldVarAccess( + false, + null, + "method1" + ), + List.of( + new IntLiteral(1) + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "methodCall2", + List.of(), + new Block( + List.of( + new Return( + new MethodCall( + new FieldVarAccess( + false, + null, + "method2" + ), + List.of( + new IntLiteral(1), + new IntLiteral(2) + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "method", + List.of(), + new Block( + List.of( + new Return( + new IntLiteral(0) + ) + ) + ) + ), + new Method( + Type.INT, + "method1", + List.of( + new Parameter( + "x", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new FieldVarAccess( + false, + null, + "x" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "method2", + List.of( + new Parameter( + "x", + Type.INT + ), + new Parameter( + "y", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.ADD, + new FieldVarAccess( + false, + null, + "y" + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "MethodCall", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_MultipleClasses.java b/src/main/java/testfiles/ASTFeatures/AST_MultipleClasses.java new file mode 100644 index 0000000..2cbacb1 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_MultipleClasses.java @@ -0,0 +1,5 @@ +package testfiles.ASTFeatures; + +public class AST_MultipleClasses { + +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Operators.java b/src/main/java/testfiles/ASTFeatures/AST_Operators.java new file mode 100644 index 0000000..949c112 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Operators.java @@ -0,0 +1,198 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + + +public class AST_Operators { + public static Program get() { + return new Program( + List.of( + new Class( + "Operators", + List.of(), + List.of( + new Method( + Type.INT, + "add", + List.of( + new Parameter( + "a", + Type.INT + ), + new Parameter( + "b", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.ADD, + new FieldVarAccess( + false, + null, + "b" + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "sub", + List.of( + new Parameter( + "a", + Type.INT + ), + new Parameter( + "b", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.SUB, + new FieldVarAccess( + false, + null, + "b" + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "mul", + List.of( + new Parameter( + "a", + Type.INT + ), + new Parameter( + "b", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.MUL, + new FieldVarAccess( + false, + null, + "b" + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "div", + List.of( + new Parameter( + "a", + Type.INT + ), + new Parameter( + "b", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.DIV, + new FieldVarAccess( + false, + null, + "b" + ) + ) + ) + ) + ) + ), + new Method( + Type.INT, + "mod", + List.of( + new Parameter( + "a", + Type.INT + ), + new Parameter( + "b", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.MOD, + new FieldVarAccess( + false, + null, + "b" + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Operators", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Overloaded.java b/src/main/java/testfiles/ASTFeatures/AST_Overloaded.java new file mode 100644 index 0000000..022de6a --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Overloaded.java @@ -0,0 +1,98 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Overloaded { + public static Program get() { + return new Program( + List.of( + new Class( + "Overloaded", + List.of(), + List.of( + new Method( + Type.INT, + "overloadedMethod", + List.of(), + new Block( + List.of( + new Return( + new IntLiteral(0) + ) + ) + ) + ), + new Method( + Type.INT, + "overloadedMethod", + List.of( + new Parameter( + "x", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new FieldVarAccess( + false, + null, + "x" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "overloadedMethod", + List.of( + new Parameter( + "x", + Type.INT + ), + new Parameter( + "y", + Type.INT + ) + ), + new Block( + List.of( + new Return( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.ADD, + new FieldVarAccess( + false, + null, + "y" + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Overloaded", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Print.java b/src/main/java/testfiles/ASTFeatures/AST_Print.java new file mode 100644 index 0000000..c114029 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Print.java @@ -0,0 +1,86 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Print { + public static Program get() { + return new Program( + List.of( + new Class( + "Print", + List.of(), + List.of( + new Method( + Type.VOID, + "print", + List.of( + new Parameter( + "c", + Type.CHAR + ) + ), + new Block( + List.of( + new Print( + new FieldVarAccess( + false, + null, + "c" + ) + ) + ) + ) + ), + new Method( + Type.VOID, + "printMoreComplex", + List.of( + new Parameter( + "x", + Type.INT + ), + new Parameter( + "y", + Type.INT + ) + ), + new Block( + List.of( + new Print( + new Binary( + new FieldVarAccess( + false, + null, + "x" + ), + Operator.LT, + new FieldVarAccess( + false, + null, + "y" + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Print", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_Return.java b/src/main/java/testfiles/ASTFeatures/AST_Return.java new file mode 100644 index 0000000..007ce6a --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_Return.java @@ -0,0 +1,95 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Return { + public static Program get() { + return new Program( + List.of( + new Class( + "Return", + List.of(), + List.of( + new Method( + Type.INT, + "returnInt", + List.of(), + new Block( + List.of( + new Return( + new IntLiteral(10) + ) + ) + ) + ), + new Method( + Type.VOID, + "returnVoid", + List.of(), + new Block( + List.of( + new Return( + null + ) + ) + ) + ), + new Method( + Type.BOOL, + "returnBoolean", + List.of(), + new Block( + List.of( + new Return( + new BoolLiteral(true) + ) + ) + ) + ), + new Method( + Type.CHAR, + "returnChar", + List.of(), + new Block( + List.of( + new Return( + new CharLiteral('a') + ) + ) + ) + ), + new Method( + Type.REFERENCE("AST_Return"), + "returnClass", + List.of(), + new Block( + List.of( + new Return( + new New( + Type.REFERENCE("AST_Return"), + List.of() + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "Return", + List.of(), + new Block( + List.of() + ) + ) + ) + + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_VariableDefWithDecl.java b/src/main/java/testfiles/ASTFeatures/AST_VariableDefWithDecl.java new file mode 100644 index 0000000..f374d7c --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_VariableDefWithDecl.java @@ -0,0 +1,55 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_VariableDefWithDecl { + public static Program get() { + return new Program( + List.of( + new Class( + "VariableDefWithDecl", + List.of(), + List.of(), + List.of( + new Constructor( + "VariableDefWithDecl", + List.of(), + new Block( + List.of( + new Declaration( + "a", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new IntLiteral(10) + ), + new Declaration( + "b", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "b" + ), + new IntLiteral(20) + ) + ) + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/testfiles/ASTFeatures/AST_While.java b/src/main/java/testfiles/ASTFeatures/AST_While.java new file mode 100644 index 0000000..b248828 --- /dev/null +++ b/src/main/java/testfiles/ASTFeatures/AST_While.java @@ -0,0 +1,84 @@ +package testfiles.ASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_While { + public static Program get() { + return new Program( + List.of( + new Class( + "While", + List.of(), + List.of( + new Method( + Type.VOID, + "whileLoop", + List.of(), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(0) + ), + new While( + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.LT, + new IntLiteral(5) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.ADD, + new IntLiteral(1) + ) + ) + ) + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "While", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructor.java similarity index 99% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructor.java index 6dfa3d8..f65281d 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructor.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructor { +package testfiles.ASTMore;//public class ClassWithConstructor { // int x; // public classWithConstructor() { // this.x = 10; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorAndMethodCall.java similarity index 98% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorAndMethodCall.java index 6d8b403..dd3e013 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorAndMethodCall.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorAndMethodCall { +package testfiles.ASTMore;//public class ClassWithConstructorAndMethodCall { // int x; // // public ClassWithConstructorAndMethodCall() { diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithCodeInComments.java similarity index 98% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithCodeInComments.java index cb840d7..6816a59 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithCodeInComments.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorWithCodeInComments { +package testfiles.ASTMore;//public class ClassWithConstructorWithCodeInComments { // int x; // public ClassWithConstructorWithCodeInComments() { // this.x = 10; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithParameters.java similarity index 99% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithParameters.java index 15e7d10..332dda0 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithConstructorWithParameters.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorWithParameters { +package testfiles.ASTMore;//public class ClassWithConstructorWithParameters { // int x; // public ClassWithConstructorWithParameters(int startValue, int repetitions) { // this.x = startValue; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithField.java similarity index 95% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithField.java index 4d8ebfe..6c12c0d 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithField.java @@ -1,4 +1,4 @@ -//public class ClassWithField { +package testfiles.ASTMore;//public class ClassWithField { // int x; //} diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethod.java similarity index 96% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethod.java index 5e6bb53..dd1a6c2 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethod.java @@ -1,4 +1,4 @@ -//public class ClassWithMethod { +package testfiles.ASTMore;//public class ClassWithMethod { // public boolean method() { // return false; // } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethodAndField.java similarity index 97% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethodAndField.java index c634341..4ed490b 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMethodAndField.java @@ -1,4 +1,4 @@ -//public class ClassWithMethodAndField { +package testfiles.ASTMore;//public class ClassWithMethodAndField { // char c; // // public ClassWithMethodAndField(char character) { @@ -10,7 +10,6 @@ // } //} -import de.maishai.ast.*; import de.maishai.ast.records.*; import de.maishai.ast.records.Class; import de.maishai.typedast.Type; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMultipleMethods.java similarity index 98% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMultipleMethods.java index 525d98b..cd1310a 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ClassWithMultipleMethods.java @@ -1,4 +1,4 @@ -//public class ClassWithMoreComplexMethodAndMain { +package testfiles.ASTMore;//public class ClassWithMoreComplexMethodAndMain { // ClassWithMoreComplexMethodAndMain instance; // // public boolean moreComplexMethod() { diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ComplexClass.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_ComplexClass.java similarity index 99% rename from src/main/resources/AbstractSyntax/AbstractSyntax_ComplexClass.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_ComplexClass.java index 4f235aa..eea629d 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ComplexClass.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_ComplexClass.java @@ -1,4 +1,4 @@ -//public class ComplexClass { +package testfiles.ASTMore;//public class ComplexClass { // // int x; // int y; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java b/src/main/java/testfiles/ASTMore/AbstractSyntax_PublicClass.java similarity index 94% rename from src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java rename to src/main/java/testfiles/ASTMore/AbstractSyntax_PublicClass.java index 925fc98..915cfe0 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java +++ b/src/main/java/testfiles/ASTMore/AbstractSyntax_PublicClass.java @@ -1,4 +1,4 @@ -//public class PublicClass { +package testfiles.ASTMore;//public class PublicClass { //} import de.maishai.ast.records.Block; diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java similarity index 99% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java index 111e0b2..bbe06f1 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructor { +package testfiles.TypedASTMore;//public class ClassWithConstructor { // int x; // public classWithConstructor() { // this.x = 10; diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java similarity index 98% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java index 89cf824..42ae47c 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorAndMethodCall { +package testfiles.TypedASTMore;//public class ClassWithConstructorAndMethodCall { // int x; // // public ClassWithConstructorAndMethodCall() { diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java similarity index 95% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java index 9cb6e25..bdc72fd 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorWithCodeInComments { +package testfiles.TypedASTMore;//public class ClassWithConstructorWithCodeInComments { // int x; // public ClassWithConstructorWithCodeInComments() { // this.x = 10; @@ -13,13 +13,6 @@ // } //} -import de.maishai.ast.Operator; -import de.maishai.ast.records.Class; -import de.maishai.ast.records.*; -import de.maishai.typedast.Type; - -import java.util.List; - public class TypedAbstractSyntax_ClassWithConstructorWithCodeInComments { // public static Class get() { // List declarations = List.of( diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithParameters.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java similarity index 98% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithParameters.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java index 706463f..c756b33 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructorWithParameters.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java @@ -1,4 +1,4 @@ -//public class ClassWithConstructorWithParameters { +package testfiles.TypedASTMore;//public class ClassWithConstructorWithParameters { // int x; // public classWithConstructorWithParameters(int startValue, int repetitions) { // this.x = startValue; diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithField.java similarity index 96% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithField.java index 4abf824..226ac2e 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithField.java @@ -1,4 +1,4 @@ -//public class ClassWithField { +package testfiles.TypedASTMore;//public class ClassWithField { // int x; //} diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java similarity index 90% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java index 6bcda41..ee39309 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java @@ -1,14 +1,9 @@ -//public class ClassWithMethod { +package testfiles.TypedASTMore;//public class ClassWithMethod { // public boolean method() { // return false; // } //} -import de.maishai.typedast.Type; -import de.maishai.typedast.typedclass.*; - -import java.util.List; - public class TypedAbstractSyntax_ClassWithMethod { // public static TypedClass get() { // TypedClass typedClass = new TypedClass(); diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethodAndField.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java similarity index 93% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethodAndField.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java index 97bf34b..02bfcdc 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethodAndField.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java @@ -1,4 +1,4 @@ -//public class ClassWithMethodAndField { +package testfiles.TypedASTMore;//public class ClassWithMethodAndField { // char c; // // public ClassWithMethodAndField(char character) { @@ -10,12 +10,6 @@ // } //} -import de.maishai.ast.*; -import de.maishai.ast.records.*; -import de.maishai.ast.records.Class; - -import java.util.List; - class TypedAbstractSyntax_ClassWithMethodAndField { // public static Class get() { // List fieldDeclarations = List.of( diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java similarity index 96% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java index 3c41ad9..33ed656 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java @@ -1,4 +1,4 @@ -//public class ClassWithMoreComplexMethodAndMain { +package testfiles.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain { // ClassWithMoreComplexMethodAndMain instance; // // public boolean moreComplexMethod() { @@ -18,12 +18,6 @@ // } //} -import de.maishai.ast.*; -import de.maishai.ast.records.*; -import de.maishai.ast.records.Class; - -import java.util.List; - public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain { // public static Class get() { // Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT; diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ComplexClass.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ComplexClass.java similarity index 99% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ComplexClass.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ComplexClass.java index 129a00a..3006d55 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ComplexClass.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_ComplexClass.java @@ -1,4 +1,4 @@ -//public class ComplexClass { +package testfiles.TypedASTMore;//public class ComplexClass { // // int x; // int y; diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_PublicClass.java similarity index 95% rename from src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java rename to src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_PublicClass.java index 79541a2..b291026 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java +++ b/src/main/java/testfiles/TypedASTMore/TypedAbstractSyntax_PublicClass.java @@ -1,4 +1,4 @@ -//public class PublicClass { +package testfiles.TypedASTMore;//public class PublicClass { //} import de.maishai.typedast.Type; diff --git a/src/main/resources/JavaTestfilesFeatures/Class.java b/src/main/resources/JavaTestfilesFeatures/Class.java new file mode 100644 index 0000000..366f84e --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Class.java @@ -0,0 +1,2 @@ +public class Class { +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/ClassObjects.java b/src/main/resources/JavaTestfilesFeatures/ClassObjects.java new file mode 100644 index 0000000..8f1e3e5 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/ClassObjects.java @@ -0,0 +1,18 @@ +public class ClassObjects { + + ClassObjects b; + + public ClassObjects() { + } + + public ClassObjects(int a) { + } + + public void objectsMethod() { + this.b = new ClassObjects(); + ClassObjects c = new ClassObjects(2); + ClassObjects d = new ClassObjects(); + c = d.b.b.b; + c.b.b.objectsMethod(); + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Comment.java b/src/main/resources/JavaTestfilesFeatures/Comment.java new file mode 100644 index 0000000..55d3299 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Comment.java @@ -0,0 +1,3 @@ +public class Comment { + // This is a comment +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Constructor.java b/src/main/resources/JavaTestfilesFeatures/Constructor.java new file mode 100644 index 0000000..db73b05 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Constructor.java @@ -0,0 +1,16 @@ +public class Constructor { + public Constructor() { + int i; + i = 1; + } + + public Constructor(int x) { + int i; + i= x; + } + + public Constructor(int x, int y) { + int i; + i= x + y; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Continue.java b/src/main/resources/JavaTestfilesFeatures/Continue.java new file mode 100644 index 0000000..3f2ee8b --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Continue.java @@ -0,0 +1,9 @@ +public class Continue { + public void continueLoop() { + for (int i = 0; i < 5; i+=1) { + if (i == 3) { + continue; + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Field.java b/src/main/resources/JavaTestfilesFeatures/Field.java new file mode 100644 index 0000000..bdfb81e --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Field.java @@ -0,0 +1,9 @@ +public class Field { + int x; + public char c; + + public void fieldAccess() { + this.x = 0; + this.c = 'a'; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/For.java b/src/main/resources/JavaTestfilesFeatures/For.java new file mode 100644 index 0000000..1af04a6 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/For.java @@ -0,0 +1,9 @@ +public class For { + public void testFor() { + for (int i = 0; i < 10; i = i+1) { + } + int j; + for (j = 0; j < 10; j = j+1) { + } + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/If.java b/src/main/resources/JavaTestfilesFeatures/If.java new file mode 100644 index 0000000..dab7280 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/If.java @@ -0,0 +1,8 @@ +public class If { + public void ifMethod() { + if (false) { + } else if (true) { + } else { + } + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/IncrDecr.java b/src/main/resources/JavaTestfilesFeatures/IncrDecr.java new file mode 100644 index 0000000..611193f --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/IncrDecr.java @@ -0,0 +1,9 @@ +public class IncrDecr { + public int increment(int a) { + return a += 1; + } + + public int decrement(int a) { + return a -= 1; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/LogicExpr.java b/src/main/resources/JavaTestfilesFeatures/LogicExpr.java new file mode 100644 index 0000000..17207ab --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/LogicExpr.java @@ -0,0 +1,49 @@ +public class LogicExpr { + public boolean test() { + int x; + x = 10; + int y; + y = 20; + return x < y; + } + + public boolean test2() { + int x; + x = 10; + int y; + y = 20; + return x > y; + } + + public boolean test3() { + int x; + x = 10; + int y; + y = 20; + return x == y; + } + + public boolean test4() { + int x; + x = 10; + int y; + y = 20; + return x != y; + } + + public boolean test5() { + int x; + x = 10; + int y; + y = 20; + return x <= y; + } + + public boolean test6() { + int x; + x = 10; + int y; + y = 20; + return x >= y; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Method.java b/src/main/resources/JavaTestfilesFeatures/Method.java new file mode 100644 index 0000000..ab59bf5 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Method.java @@ -0,0 +1,4 @@ +public class Method { + public void method() { + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/MethodCall.java b/src/main/resources/JavaTestfilesFeatures/MethodCall.java new file mode 100644 index 0000000..3bc0840 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/MethodCall.java @@ -0,0 +1,26 @@ +public class MethodCall { + + public int methodCall() { + return method(); + } + + public int methodCall1() { + return method1(1); + } + + public int methodCall2() { + return method2(1, 2); + } + + public int method() { + return 0; + } + + public int method1(int x) { + return x; + } + + public int method2(int x, int y) { + return x + y; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/MultipleClasses.java b/src/main/resources/JavaTestfilesFeatures/MultipleClasses.java new file mode 100644 index 0000000..934312d --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/MultipleClasses.java @@ -0,0 +1,15 @@ +public class MultipleClasses { + AnotherClass anotherClass; + + public MultipleClasses() { + anotherClass = new AnotherClass(); + } +} + +public class AnotherClass { + MultipleClasses multipleClasses; + + public AnotherClass() { + multipleClasses = new MultipleClasses(); + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Operators.java b/src/main/resources/JavaTestfilesFeatures/Operators.java new file mode 100644 index 0000000..0d0e0b1 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Operators.java @@ -0,0 +1,21 @@ +public class Operators { + public int add(int a, int b) { + return a + b; + } + + public int sub(int a, int b) { + return a - b; + } + + public int mul(int a, int b) { + return a * b; + } + + public int div(int a, int b) { + return a / b; + } + + public int mod(int a, int b) { + return a % b; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Overloaded.java b/src/main/resources/JavaTestfilesFeatures/Overloaded.java new file mode 100644 index 0000000..bcb688c --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Overloaded.java @@ -0,0 +1,13 @@ +public class Overloaded { + public int overloadedMethod() { + return 0; + } + + public int overloadedMethod(int x) { + return x; + } + + public int overloadedMethod(int x, int y) { + return x + y; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Print.java b/src/main/resources/JavaTestfilesFeatures/Print.java new file mode 100644 index 0000000..3cbb99d --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Print.java @@ -0,0 +1,9 @@ +public class Print { + public void print(char c) { + print(c); + } + + public void printMoreComplex(x, y) { + print(x < y); + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/Return.java b/src/main/resources/JavaTestfilesFeatures/Return.java new file mode 100644 index 0000000..35c1c79 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/Return.java @@ -0,0 +1,21 @@ +public class Return { + public int returnInt() { + return 10; + } + + public void returnVoid() { + return; + } + + public boolean returnBoolean() { + return true; + } + + public char returnChar() { + return 'a'; + } + + public AST_Return returnClass() { + return new AST_Return(); + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/VariableDefWithDecl.java b/src/main/resources/JavaTestfilesFeatures/VariableDefWithDecl.java new file mode 100644 index 0000000..20c3c9b --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/VariableDefWithDecl.java @@ -0,0 +1,7 @@ +public class VariableDefWithDecl { + public VariableDefWithDecl() { + int a = 10; + int b; + b = 20; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfilesFeatures/While.java b/src/main/resources/JavaTestfilesFeatures/While.java new file mode 100644 index 0000000..dbe5898 --- /dev/null +++ b/src/main/resources/JavaTestfilesFeatures/While.java @@ -0,0 +1,8 @@ +public class While { + public void whileLoop() { + int i = 0; + while (i < 5) { + i = i + 1; + } + } +} \ No newline at end of file diff --git a/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java b/src/main/resources/JavaTestfilesMore/ClassCanBeBytecoded.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java rename to src/main/resources/JavaTestfilesMore/ClassCanBeBytecoded.java diff --git a/src/main/resources/JavaTestfiles/ClassCanBeTyped.java b/src/main/resources/JavaTestfilesMore/ClassCanBeTyped.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassCanBeTyped.java rename to src/main/resources/JavaTestfilesMore/ClassCanBeTyped.java diff --git a/src/main/resources/JavaTestfiles/ClassWithConstructor.java b/src/main/resources/JavaTestfilesMore/ClassWithConstructor.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithConstructor.java rename to src/main/resources/JavaTestfilesMore/ClassWithConstructor.java diff --git a/src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java b/src/main/resources/JavaTestfilesMore/ClassWithConstructorAndMethodCall.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java rename to src/main/resources/JavaTestfilesMore/ClassWithConstructorAndMethodCall.java diff --git a/src/main/resources/JavaTestfiles/ClassWithConstructorWithCodeInComments.java b/src/main/resources/JavaTestfilesMore/ClassWithConstructorWithCodeInComments.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithConstructorWithCodeInComments.java rename to src/main/resources/JavaTestfilesMore/ClassWithConstructorWithCodeInComments.java diff --git a/src/main/resources/JavaTestfiles/ClassWithConstructorWithParameters.java b/src/main/resources/JavaTestfilesMore/ClassWithConstructorWithParameters.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithConstructorWithParameters.java rename to src/main/resources/JavaTestfilesMore/ClassWithConstructorWithParameters.java diff --git a/src/main/resources/JavaTestfiles/ClassWithField.java b/src/main/resources/JavaTestfilesMore/ClassWithField.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithField.java rename to src/main/resources/JavaTestfilesMore/ClassWithField.java diff --git a/src/main/resources/JavaTestfiles/ClassWithMethod.java b/src/main/resources/JavaTestfilesMore/ClassWithMethod.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithMethod.java rename to src/main/resources/JavaTestfilesMore/ClassWithMethod.java diff --git a/src/main/resources/JavaTestfiles/ClassWithMethodAndField.java b/src/main/resources/JavaTestfilesMore/ClassWithMethodAndField.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithMethodAndField.java rename to src/main/resources/JavaTestfilesMore/ClassWithMethodAndField.java diff --git a/src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java b/src/main/resources/JavaTestfilesMore/ClassWithMoreComplexMethodAndMain.java similarity index 100% rename from src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java rename to src/main/resources/JavaTestfilesMore/ClassWithMoreComplexMethodAndMain.java diff --git a/src/main/resources/JavaTestfiles/ComplexClass.java b/src/main/resources/JavaTestfilesMore/ComplexClass.java similarity index 100% rename from src/main/resources/JavaTestfiles/ComplexClass.java rename to src/main/resources/JavaTestfilesMore/ComplexClass.java diff --git a/src/main/resources/JavaTestfiles/PublicClass.java b/src/main/resources/JavaTestfilesMore/PublicClass.java similarity index 100% rename from src/main/resources/JavaTestfiles/PublicClass.java rename to src/main/resources/JavaTestfilesMore/PublicClass.java diff --git a/src/test/java/ScannerParserTests.java b/src/test/java/ScannerParserTests.java index 20dfd7a..81fae52 100644 --- a/src/test/java/ScannerParserTests.java +++ b/src/test/java/ScannerParserTests.java @@ -1,6 +1,8 @@ import de.maishai.Compiler; import de.maishai.ast.records.Program; import org.junit.jupiter.api.Test; +import testfiles.ASTFeatures.*; +import testfiles.ASTMore.*; import java.util.List; @@ -44,11 +46,12 @@ public class ScannerParserTests { assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst); } - @Test - public void testClassWithMethodAndField() { - Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java")); - assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst); - } +// @Test +// public void testClassWithMethodAndField() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java")); +// assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst); +// } + //TODO: fix @Test public void testClassWithConstructorAndMethodCall() { @@ -61,4 +64,119 @@ public class ScannerParserTests { Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java")); assertEquals(AbstractSyntax_ComplexClass.get(), resultAst); } + + // Feature Tests + + @Test + public void testClass() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Class.java")); + assertEquals(AST_Class.get(), resultAst); + } + +// @Test +// public void testClassObjects() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/ClassObjects.java")); +// assertEquals(AST_ClassObjects.get(), resultAst); +// } + //TODO: fix + + @Test + public void testComment() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Comment.java")); + assertEquals(AST_Comment.get(), resultAst); + } + + @Test + public void testConstructor() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Constructor.java")); + assertEquals(AST_Constructor.get(), resultAst); + } + + @Test + public void testContinue() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Continue.java")); + assertEquals(AST_Continue.get(), resultAst); + } + + @Test + public void testField() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Field.java")); + assertEquals(AST_Field.get(), resultAst); + } + + @Test + public void testFor() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/For.java")); + assertEquals(AST_For.get(), resultAst); + } + + @Test + public void testIf() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/If.java")); + assertEquals(AST_If.get(), resultAst); + } + +// @Test +// public void testIncrDecr() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/IncrDecr.java")); +// assertEquals(AST_IncrDecr.get(), resultAst); +// } + + @Test + public void testLogicExpr() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/LogicExpr.java")); + assertEquals(AST_LogicExpr.get(), resultAst); + } + + @Test + public void testMethod() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Method.java")); + assertEquals(AST_Method.get(), resultAst); + } + + @Test + public void testMethodCall() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/MethodCall.java")); + assertEquals(AST_MethodCall.get(), resultAst); + } + + //TODO: Multiple Classes test + + @Test + public void testOperators() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Operators.java")); + assertEquals(AST_Operators.get(), resultAst); + } + + @Test + public void testOverloaded() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Overloaded.java")); + assertEquals(AST_Overloaded.get(), resultAst); + } + +// @Test +// public void testPrint() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Print.java")); +// assertEquals(AST_Print.get(), resultAst); +// } + //TODO: fix + +// @Test +// public void testReturn() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Return.java")); +// assertEquals(AST_Return.get(), resultAst); +// } + //TODO: fix + + @Test + public void testVariableDefWithDecl() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/VariableDefWithDecl.java")); + assertEquals(AST_VariableDefWithDecl.get(), resultAst); + } + + @Test + public void testWhile() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/While.java")); + assertEquals(AST_While.get(), resultAst); + } } diff --git a/src/test/java/TypingTests.java b/src/test/java/TypingTests.java index 6c2cda3..867ced3 100644 --- a/src/test/java/TypingTests.java +++ b/src/test/java/TypingTests.java @@ -1,6 +1,9 @@ import de.maishai.Compiler; import de.maishai.typedast.typedclass.TypedProgram; import org.junit.jupiter.api.Test; +import testfiles.ASTFeatures.*; +import testfiles.ASTMore.*; +import testfiles.TypedASTMore.*; import static org.junit.jupiter.api.Assertions.assertEquals;