diff --git a/README.md b/README.md index 4f35436..587a20e 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,9 @@ # Fehlende Tests für Features (positive Tests): - Mainmethod -- *= -- %= -- /= -- boolean als Datentyp (public boolean test;) -- do while - break - recipient mit methode zwischen drinnen (this.methode().a - && - || - unaryOp -- Klammern von Expressions -- Multiline Comment \ No newline at end of file +- Klammern von Expressions \ No newline at end of file diff --git a/src/test/java/ScannerParserTests.java b/src/test/java/ScannerParserTests.java index 5412585..eba0639 100644 --- a/src/test/java/ScannerParserTests.java +++ b/src/test/java/ScannerParserTests.java @@ -1,5 +1,6 @@ import de.maishai.Compiler; import de.maishai.ast.records.Program; +import de.maishai.typedast.typedclass.TypedProgram; import org.junit.jupiter.api.Test; import testResources.AST.ASTFeatures.*; import testResources.AST.ASTMore.*; @@ -65,6 +66,13 @@ public class ScannerParserTests { assertEquals(AbstractSyntax_ComplexClass.get(), resultAst); } + + + + + + + // Feature Tests @Test @@ -86,6 +94,12 @@ public class ScannerParserTests { assertEquals(AST_Comment.get(), resultAst); } + @Test + public void testCompAssign() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/CompAssign.java")); + assertEquals(AST_CompAssign.get(), resultAst); + } + @Test public void testConstructor() { Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Constructor.java")); @@ -98,6 +112,12 @@ public class ScannerParserTests { assertEquals(AST_Continue.get(), resultAst); } + @Test + public void testDataTypes() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/DataTypes.java")); + assertEquals(AST_DataTypes.get(), resultAst); + } + @Test public void testField() { Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Field.java")); @@ -116,18 +136,18 @@ public class ScannerParserTests { assertEquals(AST_If.get(), resultAst); } -// @Test -// public void testIncrDecr() { -// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java")); -// assertEquals(AST_IncrDecr.get(), resultAst); -// } - @Test public void testLogicExpr() { Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/LogicExpr.java")); assertEquals(AST_LogicExpr.get(), resultAst); } + @Test + public void testMain() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Main.java")); + assertEquals(AST_Main.get(), resultAst); + } + @Test public void testMethod() { Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Method.java")); @@ -140,7 +160,12 @@ public class ScannerParserTests { assertEquals(AST_MethodCall.get(), resultAst); } - //TODO: Multiple Classes test +// @Test +// public void testMultipleClasses() { +// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses.java")); +// assertEquals(AST_MultipleClasses.get(), resultAst); +// } + // TODO: Implement @Test public void testOperators() { @@ -159,14 +184,12 @@ public class ScannerParserTests { Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Print.java")); assertEquals(AST_Print.get(), resultAst); } - //TODO: fix -// @Test -// public void testReturn() { -// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java")); -// assertEquals(AST_Return.get(), resultAst); -// } - //TODO: fix + @Test + public void testReturn() { + Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java")); + assertEquals(AST_Return.get(), resultAst); + } @Test public void testVariableDefWithDecl() { diff --git a/src/test/java/TypingTests.java b/src/test/java/TypingTests.java index 2c1edb7..8f89616 100644 --- a/src/test/java/TypingTests.java +++ b/src/test/java/TypingTests.java @@ -1,5 +1,6 @@ import de.maishai.Compiler; import de.maishai.typedast.typedclass.TypedProgram; +import jdk.jshell.spi.ExecutionControl; import org.junit.jupiter.api.Test; import testResources.TypedAST.TypedASTFeatures.*; import testResources.AST.ASTFeatures.*; @@ -56,6 +57,12 @@ public class TypingTests { assertEquals(TypedAST_Comment.get(), resultTypedAst); } + @Test + public void testCompAssign() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_CompAssign.get()); + assertEquals(TypedAST_CompAssign.get(), resultTypedAst); + } + @Test public void testConstructor() { TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Constructor.get()); @@ -68,6 +75,12 @@ public class TypingTests { assertEquals(TypedAST_Continue.get(), resultTypedAst); } + @Test + public void testDataTypes() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_DataTypes.get()); + assertEquals(TypedAST_DataTypes.get(), resultTypedAst); + } + @Test public void testField() { TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get()); @@ -85,13 +98,6 @@ public class TypingTests { TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get()); assertEquals(TypedAST_If.get(), resultTypedAst); } -// -// @Test -// public void testIncrDecr() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_IncrDecr.get()); -// assertEquals(TypedAST_IncrDecr.get(), resultTypedAst); -// } - //TODO: fix @Test public void testLogicExpr() { @@ -99,6 +105,17 @@ public class TypingTests { assertEquals(TypedAST_LogicExpr.get(), resultTypedAst); } + @Test + public void testMain() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get()); + assertEquals(TypedAST_Main.get(), resultTypedAst); + try { + throw new ExecutionControl.NotImplementedException("Main Class not yet implemented in TypedAST"); + } catch (ExecutionControl.NotImplementedException e) { + throw new RuntimeException(e); + } + } + @Test public void testMethod() { TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get()); @@ -136,12 +153,11 @@ public class TypingTests { assertEquals(TypedAST_Print.get(), resultTypedAst); } -// @Test -// public void testReturn() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get()); -// assertEquals(TypedAST_Return.get(), resultTypedAst); -// } - //TODO: fix + @Test + public void testReturn() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get()); + assertEquals(TypedAST_Return.get(), resultTypedAst); + } @Test public void testVariableDefWithDecl() { diff --git a/src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java b/src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java new file mode 100644 index 0000000..b514a1e --- /dev/null +++ b/src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java @@ -0,0 +1,217 @@ +package testResources.AST.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_CompAssign { + public static Program get() { + return new Program( + List.of( + new Class( + "CompAssign", + List.of(), + List.of( + new Method( + Type.INT, + "increase", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.ADD, + new IntLiteral(1) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "decrease", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.SUB, + new IntLiteral(1) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "multiply", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.MUL, + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "divide", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.DIV, + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.INT, + "modulus", + List.of( + new Parameter( + "a", + Type.INT + ) + ), + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new Binary( + new FieldVarAccess( + false, + null, + "a" + ), + Operator.MOD, + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "CompAssign", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java b/src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java new file mode 100644 index 0000000..9e432d6 --- /dev/null +++ b/src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java @@ -0,0 +1,144 @@ +package testResources.AST.ASTFeatures; + +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; +import de.maishai.ast.records.Program; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_DataTypes { + public static Program get() { + return new Program( + List.of( + new Class( + "DataTypes", + List.of( + new Declaration( + "x", + Type.INT + ), + new Declaration( + "y", + Type.BOOL + ), + new Declaration( + "z", + Type.CHAR + ) + ), + List.of( + new Method( + Type.INT, + "integer", + List.of( + new Parameter( + "i", + Type.INT + ) + ), + new Block( + List.of( + new Declaration( + "a", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new IntLiteral(1) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.BOOL, + "bool", + List.of( + new Parameter( + "b", + Type.BOOL + ) + ), + new Block( + List.of( + new Declaration( + "a", + Type.BOOL + ), + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new BoolLiteral(true) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ), + new Method( + Type.CHAR, + "character", + List.of( + new Parameter( + "c", + Type.CHAR + ) + ), + new Block( + List.of( + new Declaration( + "a", + Type.CHAR + ), + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), + new CharLiteral('a') + ), + new Return( + new FieldVarAccess( + false, + null, + "a" + ) + ) + ) + ) + ) + ), + List.of( + new Constructor( + "DataTypes", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/AST/ASTFeatures/AST_IncrDecr.java b/src/test/java/testResources/AST/ASTFeatures/AST_IncrDecr.java deleted file mode 100644 index 0817dfe..0000000 --- a/src/test/java/testResources/AST/ASTFeatures/AST_IncrDecr.java +++ /dev/null @@ -1,86 +0,0 @@ -package testResources.AST.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/test/java/testResources/AST/ASTFeatures/AST_Main.java b/src/test/java/testResources/AST/ASTFeatures/AST_Main.java new file mode 100644 index 0000000..fc12707 --- /dev/null +++ b/src/test/java/testResources/AST/ASTFeatures/AST_Main.java @@ -0,0 +1,46 @@ +package testResources.AST.ASTFeatures; + +import de.maishai.ast.records.Class; +import de.maishai.ast.records.*; +import de.maishai.typedast.Type; + +import java.util.List; + +public class AST_Main { + public static Program get() { + return new Program( + List.of( + new Class( + "Main", + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(0) + ) + ) + ), + List.of(), + List.of(), + List.of( + new Constructor( + "Main", + List.of(), + new Block( + List.of() + ) + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/AST/ASTFeatures/AST_Return.java b/src/test/java/testResources/AST/ASTFeatures/AST_Return.java index 6300382..214dff0 100644 --- a/src/test/java/testResources/AST/ASTFeatures/AST_Return.java +++ b/src/test/java/testResources/AST/ASTFeatures/AST_Return.java @@ -63,14 +63,14 @@ public class AST_Return { ) ), new Method( - Type.REFERENCE("AST_Return"), + Type.REFERENCE("Return"), "returnClass", List.of(), new Block( List.of( new Return( new New( - Type.REFERENCE("AST_Return"), + Type.REFERENCE("Return"), List.of() ) ) diff --git a/src/test/java/testResources/AST/ASTFeatures/AST_While.java b/src/test/java/testResources/AST/ASTFeatures/AST_While.java index fb42c84..39fcab2 100644 --- a/src/test/java/testResources/AST/ASTFeatures/AST_While.java +++ b/src/test/java/testResources/AST/ASTFeatures/AST_While.java @@ -66,6 +66,59 @@ public class AST_While { ) ) ) + ), + new Method( + Type.VOID, + "doWhileLoop", + List.of(), + new Block( + List.of( + new Declaration( + "i", + Type.INT + ), + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new IntLiteral(0) + ), + new DoWhile( + new Block( + List.of( + new Assignment( + new FieldVarAccess( + false, + null, + "i" + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.ADD, + new IntLiteral(1) + ) + ) + ) + ), + new Binary( + new FieldVarAccess( + false, + null, + "i" + ), + Operator.LT, + new IntLiteral(5) + ) + ) + ) + ) + ) ), List.of( diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_CompAssign.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_CompAssign.java new file mode 100644 index 0000000..3990100 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_CompAssign.java @@ -0,0 +1,285 @@ +package testResources.TypedAST.TypedASTFeatures; + +import de.maishai.ast.Operator; +import de.maishai.typedast.Type; +import de.maishai.typedast.typedclass.*; + +import java.util.List; + +public class TypedAST_CompAssign { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "CompAssign", + List.of(), + List.of( + new TypedMethod( + "increase", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.ADD, + new TypedIntLiteral( + 1, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "decrease", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.SUB, + new TypedIntLiteral( + 1, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "multiply", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.MUL, + new TypedIntLiteral( + 2, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "divide", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.DIV, + new TypedIntLiteral( + 2, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "modulus", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.MOD, + new TypedIntLiteral( + 2, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ) + ), + List.of( + new TypedConstructor( + "CompAssign", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("CompAssign") + ) + ), + null + ); + } + +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_DataTypes.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_DataTypes.java new file mode 100644 index 0000000..fa0fa01 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_DataTypes.java @@ -0,0 +1,183 @@ +package testResources.TypedAST.TypedASTFeatures; + +import de.maishai.typedast.Type; +import de.maishai.typedast.typedclass.*; + +import java.util.List; + +public class TypedAST_DataTypes { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "DataTypes", + List.of( + new TypedDeclaration( + "x", + Type.INT + ), + new TypedDeclaration( + "y", + Type.BOOL + ), + new TypedDeclaration( + "z", + Type.CHAR + ) + ), + List.of( + new TypedMethod( + "integer", + Type.INT, + List.of( + new TypedParameter( + "i", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of( + new TypedLocalVariable( + "a", + Type.INT + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 1, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "bool", + Type.BOOL, + List.of( + new TypedParameter( + "b", + Type.BOOL + ) + ), + List.of(), + new TypedBlock( + List.of( + new TypedLocalVariable( + "a", + Type.BOOL + ) + ), + List.of( + new TypedAssignment( + new TypedBoolLiteral( + true, + Type.BOOL + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.BOOL + ), + Type.BOOL + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.BOOL + ), + Type.BOOL + ) + ), + Type.BOOL + ) + ), + new TypedMethod( + "character", + Type.CHAR, + List.of( + new TypedParameter( + "c", + Type.CHAR + ) + ), + List.of(), + new TypedBlock( + List.of( + new TypedLocalVariable( + "a", + Type.CHAR + ) + ), + List.of( + new TypedAssignment( + new TypedCharLiteral( + 'a', + Type.CHAR + ), + new TypedFieldVarAccess( + false, + null, + "a", + Type.CHAR + ), + Type.CHAR + ), + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "a", + Type.CHAR + ), + Type.CHAR + ) + ), + Type.CHAR + ) + ) + ), + List.of( + new TypedConstructor( + "DataTypes", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("DataTypes") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_IncrDecr.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_IncrDecr.java deleted file mode 100644 index 38b874f..0000000 --- a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_IncrDecr.java +++ /dev/null @@ -1,86 +0,0 @@ -package testResources.TypedAST.TypedASTFeatures; - -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 TypedAST_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/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Main.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Main.java new file mode 100644 index 0000000..c0bd740 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Main.java @@ -0,0 +1,56 @@ +package testResources.TypedAST.TypedASTFeatures; +import de.maishai.typedast.Type; +import de.maishai.typedast.typedclass.TypedBlock; +import de.maishai.typedast.typedclass.TypedClass; +import de.maishai.typedast.typedclass.TypedConstructor; +import de.maishai.typedast.typedclass.TypedProgram; +import jdk.jshell.spi.ExecutionControl; + +import java.util.List; + +public class TypedAST_Main { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "Main", +// new Block( +// List.of( +// new Declaration( +// "i", +// Type.INT +// ), +// new Assignment( +// new FieldVarAccess( +// false, +// null, +// "i" +// ), +// new IntLiteral(0) +// ) +// ) +// ), + List.of(), + List.of(), + List.of( + new TypedConstructor( + "Main", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("Main") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Return.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Return.java index 2f630a3..592b74d 100644 --- a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Return.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Return.java @@ -1,95 +1,131 @@ package testResources.TypedAST.TypedASTFeatures; -import de.maishai.ast.records.Class; import de.maishai.ast.records.*; import de.maishai.typedast.Type; +import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAST_Return { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "Return", List.of(), List.of( - new Method( - Type.INT, + new TypedMethod( "returnInt", + Type.INT, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new IntLiteral(10) + new TypedReturn( + new TypedIntLiteral( + 10, + Type.INT + ), + Type.INT ) - ) + ), + Type.INT ) ), - new Method( - Type.VOID, + new TypedMethod( "returnVoid", + Type.VOID, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - null + new TypedReturn( + null, + Type.VOID ) - ) + ), + Type.VOID ) ), - new Method( - Type.BOOL, + new TypedMethod( "returnBoolean", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new BoolLiteral(true) + new TypedReturn( + new TypedBoolLiteral( + true, + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) ), - new Method( - Type.CHAR, + new TypedMethod( "returnChar", + Type.CHAR, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new CharLiteral('a') + new TypedReturn( + new TypedCharLiteral( + 'a', + Type.CHAR + ), + Type.CHAR ) - ) + ), + Type.CHAR ) ), - new Method( - Type.REFERENCE("AST_Return"), + new TypedMethod( "returnClass", + Type.REFERENCE("Return"), List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new New( - Type.REFERENCE("AST_Return"), + new TypedReturn( + new TypedNew( + Type.REFERENCE("Return"), List.of() - ) + ), + Type.REFERENCE("Return") ) - ) + ), + Type.REFERENCE("Return") ) ) ), List.of( - new Constructor( + new TypedConstructor( "Return", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - ) - + ), + null, + null, + Type.REFERENCE("Return") ) - ) + ), + null ); } } \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_While.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_While.java index 4b78232..7624e5c 100644 --- a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_While.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_While.java @@ -90,6 +90,81 @@ public class TypedAST_While { ) ) ) + ), + new TypedMethod( + "doWhileLoop", + Type.VOID, + List.of(), + List.of(), + new TypedBlock( + List.of( + new TypedLocalVariable( + "i", + Type.INT + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 0, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Type.INT + ), + new TypedDoWhile( + new TypedBlock( + List.of(), + List.of( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Operator.ADD, + new TypedIntLiteral( + 1, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Type.INT + ) + ), + Type.VOID + ), + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Operator.LT, + new TypedIntLiteral( + 5, + Type.INT + ), + Type.BOOL + ), + Type.VOID + ) + ) + ) ) ), List.of( diff --git a/src/test/testFiles/JavaTestfilesFeatures/Comment.java b/src/test/testFiles/JavaTestfilesFeatures/Comment.java index 55d3299..a8ce7f3 100644 --- a/src/test/testFiles/JavaTestfilesFeatures/Comment.java +++ b/src/test/testFiles/JavaTestfilesFeatures/Comment.java @@ -1,3 +1,12 @@ public class Comment { // This is a comment + + + // This is another comment + // With multiple lines + + /* This is a comment + with multiple lines written in a block + which is closed/started with a * and a / + */ } \ No newline at end of file diff --git a/src/test/testFiles/JavaTestfilesFeatures/CompAssign.java b/src/test/testFiles/JavaTestfilesFeatures/CompAssign.java new file mode 100644 index 0000000..e0d42c2 --- /dev/null +++ b/src/test/testFiles/JavaTestfilesFeatures/CompAssign.java @@ -0,0 +1,26 @@ +public class CompAssign { + public int increase(int a) { + a += 1; + return a; + } + + public int decrease(int a) { + a -= 1; + return a; + } + + public int multiply(int a) { + a *= 2; + return a; + } + + public int divide(int a) { + a /= 2; + return a; + } + + public int modulus(int a) { + a %= 2; + return a; + } +} \ No newline at end of file diff --git a/src/test/testFiles/JavaTestfilesFeatures/DataTypes.java b/src/test/testFiles/JavaTestfilesFeatures/DataTypes.java new file mode 100644 index 0000000..22c27a6 --- /dev/null +++ b/src/test/testFiles/JavaTestfilesFeatures/DataTypes.java @@ -0,0 +1,20 @@ +public class DataTypes { + int x; + boolean y; + char z; + + public int integer(int i) { + int a = 1; + return a; + } + + public boolean bool(boolean b) { + boolean a = true; + return a; + } + + public char character(char c) { + char a = 'a'; + return a; + } +} \ No newline at end of file diff --git a/src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java b/src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java deleted file mode 100644 index 611193f..0000000 --- a/src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java +++ /dev/null @@ -1,9 +0,0 @@ -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/test/testFiles/JavaTestfilesFeatures/Main.java b/src/test/testFiles/JavaTestfilesFeatures/Main.java new file mode 100644 index 0000000..4ca33f6 --- /dev/null +++ b/src/test/testFiles/JavaTestfilesFeatures/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + int i = 0; + } +} \ No newline at end of file diff --git a/src/test/testFiles/JavaTestfilesFeatures/Return.java b/src/test/testFiles/JavaTestfilesFeatures/Return.java index 35c1c79..491c22a 100644 --- a/src/test/testFiles/JavaTestfilesFeatures/Return.java +++ b/src/test/testFiles/JavaTestfilesFeatures/Return.java @@ -15,7 +15,7 @@ public class Return { return 'a'; } - public AST_Return returnClass() { - return new AST_Return(); + public Return returnClass() { + return new Return(); } } \ No newline at end of file diff --git a/src/test/testFiles/JavaTestfilesFeatures/While.java b/src/test/testFiles/JavaTestfilesFeatures/While.java index dbe5898..0feb697 100644 --- a/src/test/testFiles/JavaTestfilesFeatures/While.java +++ b/src/test/testFiles/JavaTestfilesFeatures/While.java @@ -5,4 +5,11 @@ public class While { i = i + 1; } } + + public void doWhileLoop() { + int i = 0; + do { + i = i + 1; + } while (i < 5); + } } \ No newline at end of file