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/main/java/de/maishai/typedast/typedclass/TypedPrint.java b/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java index 6e7deba..8cee74b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedPrint.java @@ -2,12 +2,14 @@ package de.maishai.typedast.typedclass; import de.maishai.ast.records.Print; import de.maishai.typedast.*; +import lombok.AllArgsConstructor; import org.objectweb.asm.Opcodes; import java.util.List; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; +@AllArgsConstructor public class TypedPrint implements TypedStatement { private TypedExpression value; private Type type; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java b/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java index 8119725..427c6ce 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java @@ -2,6 +2,7 @@ package de.maishai.typedast.typedclass; import de.maishai.ast.records.*; import de.maishai.typedast.*; +import lombok.AllArgsConstructor; import lombok.Data; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; @@ -10,6 +11,7 @@ import org.objectweb.asm.Opcodes; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; @Data +@AllArgsConstructor public class TypedWhile implements TypedStatement { private TypedExpression cond; private TypedBlock typedBlock; 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 70eaadd..8f89616 100644 --- a/src/test/java/TypingTests.java +++ b/src/test/java/TypingTests.java @@ -1,16 +1,15 @@ 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.TypedAST.TypedASTFeatures.*; import testResources.AST.ASTFeatures.*; import testResources.AST.ASTMore.AbstractSyntax_ClassWithConstructor; import testResources.AST.ASTMore.AbstractSyntax_ClassWithField; -import testResources.AST.ASTMore.AbstractSyntax_ComplexClass; import testResources.AST.ASTMore.AbstractSyntax_PublicClass; -import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor; -import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField; -import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ComplexClass; -import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_PublicClass; +import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor; +import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField; +import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_PublicClass; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -58,103 +57,117 @@ 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()); assertEquals(TypedAST_Constructor.get(), resultTypedAst); } -// -// @Test -// public void testContinue() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get()); -// assertEquals(TypedAST_Continue.get(), resultTypedAst); -// } -// -// @Test -// public void testField() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get()); -// assertEquals(TypedAST_Field.get(), resultTypedAst); -// } -// -// @Test -// public void testFor() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get()); -// assertEquals(TypedAST_For.get(), resultTypedAst); -// } -// -// @Test -// public void testIf() { -// 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() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get()); -// assertEquals(TypedAST_LogicExpr.get(), resultTypedAst); -// } -// -// @Test -// public void testMethod() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get()); -// assertEquals(TypedAST_Method.get(), resultTypedAst); -// } -// -// @Test -// public void testMethodCall() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MethodCall.get()); -// assertEquals(TypedAST_MethodCall.get(), resultTypedAst); -// } -// + + @Test + public void testContinue() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get()); + 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()); + assertEquals(TypedAST_Field.get(), resultTypedAst); + } + + @Test + public void testFor() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get()); + assertEquals(TypedAST_For.get(), resultTypedAst); + } + + @Test + public void testIf() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get()); + assertEquals(TypedAST_If.get(), resultTypedAst); + } + + @Test + public void testLogicExpr() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get()); + 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()); + assertEquals(TypedAST_Method.get(), resultTypedAst); + } + + @Test + public void testMethodCall() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MethodCall.get()); + assertEquals(TypedAST_MethodCall.get(), resultTypedAst); + } + // @Test // public void testMultipleClasses() { // TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MultipleClasses.get()); // assertEquals(TypedAST_MultipleClasses.get(), resultTypedAst); // } -// // TODO: Implement -// -// @Test -// public void testOperators() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Operators.get()); -// assertEquals(TypedAST_Operators.get(), resultTypedAst); -// } -// -// @Test -// public void testOverloaded() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Overloaded.get()); -// assertEquals(TypedAST_Overloaded.get(), resultTypedAst); -// } -// -// @Test -// public void testPrint() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Print.get()); -// assertEquals(TypedAST_Print.get(), resultTypedAst); -// } - //TODO: fix -// -// @Test -// public void testReturn() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get()); -// assertEquals(TypedAST_Return.get(), resultTypedAst); -// } - //TODO: fix -// -// @Test -// public void testVariableDefWithDecl() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get()); -// assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst); -// } -// -// @Test -// public void testWhile() { -// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get()); -// assertEquals(TypedAST_While.get(), resultTypedAst); -// } + // TODO: Implement + + @Test + public void testOperators() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Operators.get()); + assertEquals(TypedAST_Operators.get(), resultTypedAst); + } + + @Test + public void testOverloaded() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Overloaded.get()); + assertEquals(TypedAST_Overloaded.get(), resultTypedAst); + } + + @Test + public void testPrint() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Print.get()); + assertEquals(TypedAST_Print.get(), resultTypedAst); + } + + @Test + public void testReturn() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get()); + assertEquals(TypedAST_Return.get(), resultTypedAst); + } + + @Test + public void testVariableDefWithDecl() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get()); + assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst); + } + + @Test + public void testWhile() { + TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get()); + assertEquals(TypedAST_While.get(), resultTypedAst); + } } diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Operators.java b/src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java similarity index 75% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Operators.java rename to src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java index 1739a73..b514a1e 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Operators.java +++ b/src/test/java/testResources/AST/ASTFeatures/AST_CompAssign.java @@ -1,37 +1,37 @@ -package testResources.typedAST.TypedASTFeatures; +package testResources.AST.ASTFeatures; import de.maishai.ast.Operator; -import de.maishai.ast.records.Class; import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; import de.maishai.typedast.Type; import java.util.List; - -public class TypedAST_Operators { +public class AST_CompAssign { public static Program get() { return new Program( List.of( new Class( - "Operators", + "CompAssign", List.of(), List.of( new Method( Type.INT, - "add", + "increase", List.of( new Parameter( "a", Type.INT - ), - new Parameter( - "b", - Type.INT ) ), new Block( List.of( - new Return( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), new Binary( new FieldVarAccess( false, @@ -39,11 +39,14 @@ public class TypedAST_Operators { "a" ), Operator.ADD, - new FieldVarAccess( - false, - null, - "b" - ) + new IntLiteral(1) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" ) ) ) @@ -51,20 +54,21 @@ public class TypedAST_Operators { ), new Method( Type.INT, - "sub", + "decrease", List.of( new Parameter( "a", Type.INT - ), - new Parameter( - "b", - Type.INT ) ), new Block( List.of( - new Return( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), new Binary( new FieldVarAccess( false, @@ -72,11 +76,14 @@ public class TypedAST_Operators { "a" ), Operator.SUB, - new FieldVarAccess( - false, - null, - "b" - ) + new IntLiteral(1) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" ) ) ) @@ -84,20 +91,21 @@ public class TypedAST_Operators { ), new Method( Type.INT, - "mul", + "multiply", List.of( new Parameter( "a", Type.INT - ), - new Parameter( - "b", - Type.INT ) ), new Block( List.of( - new Return( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), new Binary( new FieldVarAccess( false, @@ -105,11 +113,14 @@ public class TypedAST_Operators { "a" ), Operator.MUL, - new FieldVarAccess( - false, - null, - "b" - ) + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" ) ) ) @@ -117,20 +128,21 @@ public class TypedAST_Operators { ), new Method( Type.INT, - "div", + "divide", List.of( new Parameter( "a", Type.INT - ), - new Parameter( - "b", - Type.INT ) ), new Block( List.of( - new Return( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), new Binary( new FieldVarAccess( false, @@ -138,11 +150,14 @@ public class TypedAST_Operators { "a" ), Operator.DIV, - new FieldVarAccess( - false, - null, - "b" - ) + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" ) ) ) @@ -150,20 +165,21 @@ public class TypedAST_Operators { ), new Method( Type.INT, - "mod", + "modulus", List.of( new Parameter( "a", Type.INT - ), - new Parameter( - "b", - Type.INT ) ), new Block( List.of( - new Return( + new Assignment( + new FieldVarAccess( + false, + null, + "a" + ), new Binary( new FieldVarAccess( false, @@ -171,11 +187,14 @@ public class TypedAST_Operators { "a" ), Operator.MOD, - new FieldVarAccess( - false, - null, - "b" - ) + new IntLiteral(2) + ) + ), + new Return( + new FieldVarAccess( + false, + null, + "a" ) ) ) @@ -184,7 +203,7 @@ public class TypedAST_Operators { ), List.of( new Constructor( - "Operators", + "CompAssign", List.of(), new Block( List.of() diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MethodCall.java b/src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java similarity index 65% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MethodCall.java rename to src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java index 48891b5..9e432d6 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MethodCall.java +++ b/src/test/java/testResources/AST/ASTFeatures/AST_DataTypes.java @@ -1,143 +1,127 @@ -package testResources.typedAST.TypedASTFeatures; +package testResources.AST.ASTFeatures; -import de.maishai.ast.Operator; -import de.maishai.ast.records.Class; 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 TypedAST_MethodCall { +public class AST_DataTypes { public static Program get() { return new Program( List.of( new Class( - "MethodCall", - List.of(), + "DataTypes", + List.of( + new Declaration( + "x", + Type.INT + ), + new Declaration( + "y", + Type.BOOL + ), + new Declaration( + "z", + Type.CHAR + ) + ), 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", + "integer", List.of( new Parameter( - "x", + "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, - "x" + "a" ) ) ) ) ), new Method( - Type.INT, - "method2", + Type.BOOL, + "bool", List.of( new Parameter( - "x", - Type.INT - ), - new Parameter( - "y", - Type.INT + "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 Binary( - new FieldVarAccess( - false, - null, - "x" - ), - Operator.ADD, - new FieldVarAccess( - false, - null, - "y" - ) + 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" ) ) ) @@ -146,7 +130,7 @@ public class TypedAST_MethodCall { ), List.of( new Constructor( - "MethodCall", + "DataTypes", List.of(), new Block( List.of() 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_Class.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Class.java similarity index 96% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Class.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Class.java index c9a7699..00c3211 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Class.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Class.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTFeatures; +package testResources.TypedAST.TypedASTFeatures; import de.maishai.typedast.Type; import de.maishai.typedast.typedclass.TypedBlock; diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_ClassObjects.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_ClassObjects.java similarity index 99% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_ClassObjects.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_ClassObjects.java index 3943970..d4f5972 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_ClassObjects.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_ClassObjects.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTFeatures; +package testResources.TypedAST.TypedASTFeatures; import de.maishai.typedast.Type; import de.maishai.typedast.typedclass.*; diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Comment.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Comment.java similarity index 88% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Comment.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Comment.java index d56d3a4..95a050e 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Comment.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Comment.java @@ -1,9 +1,5 @@ -package testResources.typedAST.TypedASTFeatures; +package testResources.TypedAST.TypedASTFeatures; -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 de.maishai.typedast.Type; import de.maishai.typedast.typedclass.TypedBlock; import de.maishai.typedast.typedclass.TypedClass; 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_Constructor.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Constructor.java similarity index 98% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Constructor.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Constructor.java index 8eb080d..d17943e 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Constructor.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Constructor.java @@ -1,8 +1,6 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_For.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Continue.java similarity index 59% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_For.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Continue.java index bc22fb7..efe4e02 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_For.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Continue.java @@ -1,127 +1,145 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; import java.util.List; -public class TypedAST_For { - public static Program get() { - return new Program( +public class TypedAST_Continue { + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( - "For", + new TypedClass( + "Continue", List.of(), List.of( - new Method( + new TypedMethod( + "continueLoop", Type.VOID, - "testFor", List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "i", Type.INT - ), - new For( - new Assignment( - new FieldVarAccess( - false, - null, - "i" + )), + List.of( + new TypedFor( + new TypedAssignment( + new TypedIntLiteral( + 0, + Type.INT ), - new IntLiteral(0) - ), - new Binary( - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "i" + "i", + Type.INT + ), + Type.INT + ), + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT ), Operator.LT, - new IntLiteral(10) - ), - new Assignment( - new FieldVarAccess( - false, - null, - "i" + new TypedIntLiteral( + 5, + Type.INT ), - new Binary( - new FieldVarAccess( + Type.BOOL + ), + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "i" + "i", + Type.INT ), Operator.ADD, - new IntLiteral(1) - ) + new TypedIntLiteral( + 1, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Type.INT + ), + new TypedBlock( + List.of(), + List.of( + new TypedIfElse( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Operator.EQ, + new TypedIntLiteral( + 3, + Type.INT + ), + Type.BOOL + ), + new TypedBlock( + List.of(), + List.of( + new TypedContinue() + ), + Type.VOID + + ), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID + ) + ), + Type.VOID ), - 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() - ) ) - ) + ), + Type.VOID ) ) ), List.of( - new Constructor( - "For", + new TypedConstructor( + "Continue", List.of(), - new Block( - List.of( - ) - ) - + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + // TODO: ist Konstruktor nicht immer vom Typ der Klasse? + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("Continue") ) - ) + ), + 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_Field.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Field.java similarity index 50% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Field.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Field.java index 1bab774..c6a182a 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Field.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Field.java @@ -1,66 +1,85 @@ -package testResources.typedAST.TypedASTFeatures; +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_Field { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "Field", List.of( - new Declaration( + new TypedDeclaration( "x", Type.INT ), - new Declaration( + new TypedDeclaration( "c", Type.CHAR ) ), List.of( - new Method( - Type.VOID, + new TypedMethod( "fieldAccess", + Type.VOID, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Assignment( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 0, + Type.INT + ), + new TypedFieldVarAccess( true, null, - "x" + "x", + Type.INT ), - new IntLiteral(0) + Type.INT ), - new Assignment( - new FieldVarAccess( + new TypedAssignment( + new TypedCharLiteral( + 'a', + Type.CHAR + ), + new TypedFieldVarAccess( true, null, - "c" + "c", + Type.CHAR ), - new CharLiteral('a') + Type.CHAR ) - ) + ), + Type.VOID ) ) ), List.of( - new Constructor( + new TypedConstructor( "Field", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - - ) + ), + null, + null, + Type.REFERENCE("Field") ) - ) + ), + null ); } } \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_For.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_For.java new file mode 100644 index 0000000..ba72415 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_For.java @@ -0,0 +1,175 @@ +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_For { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "For", + List.of(), + List.of( + new TypedMethod( + "testFor", + Type.VOID, + List.of(), + List.of(), + new TypedBlock( + List.of( + new TypedLocalVariable( + "i", + Type.INT + ), + new TypedLocalVariable( + "j", + Type.INT + ) + ), + List.of( + new TypedFor( + new TypedAssignment( + new TypedIntLiteral( + 0, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Type.INT + ), + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Operator.LT, + new TypedIntLiteral( + 10, + Type.INT + ), + Type.BOOL + ), + 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 + ), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID + ), + new TypedFor( + new TypedAssignment( + new TypedIntLiteral( + 0, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "j", + Type.INT + ), + Type.INT + ), + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "j", + Type.INT + ), + Operator.LT, + new TypedIntLiteral( + 10, + Type.INT + ), + Type.BOOL + ), + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "j", + Type.INT + ), + Operator.ADD, + new TypedIntLiteral( + 1, + Type.INT + ), + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "j", + Type.INT + ), + Type.INT + ), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID + ) + ) + ) + ) + ), + List.of( + new TypedConstructor( + "For", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("For") + ) + ), + 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_If.java similarity index 57% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_While.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_If.java index 1ef1d74..6ae9eaf 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_While.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_If.java @@ -1,84 +1,87 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; import java.util.List; -public class TypedAST_While { - public static Program get() { - return new Program( +public class TypedAST_If { + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( - "While", + new TypedClass( + "If", List.of(), List.of( - new Method( + new TypedMethod( + "ifMethod", Type.VOID, - "whileLoop", List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Declaration( - "i", - Type.INT - ), - new Assignment( - new FieldVarAccess( + new TypedIfElse( + new TypedBoolLiteral( false, - null, - "i" + Type.BOOL ), - new IntLiteral(0) - ), - new While( - new Binary( - new FieldVarAccess( - false, - null, - "i" - ), - Operator.LT, - new IntLiteral(5) + new TypedBlock( + List.of(), + List.of(), + Type.VOID ), - new Block( + new TypedBlock( + List.of(), List.of( - new Assignment( - new FieldVarAccess( - false, - null, - "i" + new TypedIfElse( + new TypedBoolLiteral( + true, + Type.BOOL ), - new Binary( - new FieldVarAccess( - false, - null, - "i" - ), - Operator.ADD, - new IntLiteral(1) - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID ) - ) - ) + ), + Type.VOID + ), + Type.VOID ) - ) + ), + Type.VOID ) ) ), List.of( - new Constructor( - "While", + new TypedConstructor( + "If", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("If") ) - ) + ), + null ); } } \ No newline at end of file diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_LogicExpr.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_LogicExpr.java similarity index 59% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_LogicExpr.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_LogicExpr.java index a2526f6..36da8b1 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_LogicExpr.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_LogicExpr.java @@ -1,332 +1,435 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAST_LogicExpr { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "LogicExpr", List.of(), List.of( - new Method( - Type.BOOL, + new TypedMethod( "test", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.LT, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ), - new Method( - Type.BOOL, + new TypedMethod( "test2", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.GT, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ), - new Method( - Type.BOOL, + new TypedMethod( "test3", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.EQ, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ), - new Method( - Type.BOOL, + new TypedMethod( "test4", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.NE, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ), - new Method( - Type.BOOL, + new TypedMethod( "test5", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.LE, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ), - new Method( - Type.BOOL, + new TypedMethod( "test6", + Type.BOOL, List.of(), - new Block( + List.of(), + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "x", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "x" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "y", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "y" + "x", + Type.INT ), - new IntLiteral(20) + Type.INT ), - new Return( - new Binary( - new FieldVarAccess( + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.GE, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) - + "y", + Type.INT + ), + Type.BOOL + ), + Type.BOOL ) - ) + ), + Type.BOOL ) - ) ), List.of( - new Constructor( + new TypedConstructor( "LogicExpr", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("LogicExpr") ) - ) + ), + null ); } } \ 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_Method.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Method.java new file mode 100644 index 0000000..46b5f61 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Method.java @@ -0,0 +1,49 @@ +package testResources.TypedAST.TypedASTFeatures; + +import de.maishai.typedast.Type; +import de.maishai.typedast.typedclass.*; + +import java.util.List; + +public class TypedAST_Method { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "Method", + List.of(), + List.of( + new TypedMethod( + "method", + Type.VOID, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ) + ) + ), + List.of( + new TypedConstructor( + "Method", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("Method") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MethodCall.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MethodCall.java new file mode 100644 index 0000000..02805d5 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MethodCall.java @@ -0,0 +1,213 @@ +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_MethodCall { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "MethodCall", + List.of(), + List.of( + new TypedMethod( + "methodCall", + Type.INT, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedMethodCall( + new TypedFieldVarAccess( + false, + null, + "method", + Type.INT + ), + List.of(), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "methodCall1", + Type.INT, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedMethodCall( + new TypedFieldVarAccess( + false, + null, + "method1", + Type.INT + ), + List.of( + new TypedIntLiteral( + 1, + Type.INT + ) + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "methodCall2", + Type.INT, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedMethodCall( + new TypedFieldVarAccess( + false, + null, + "method2", + Type.INT + ), + List.of( + new TypedIntLiteral( + 1, + Type.INT + ), + new TypedIntLiteral( + 2, + Type.INT + ) + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "method", + Type.INT, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedIntLiteral( + 0, + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "method1", + Type.INT, + List.of( + new TypedParameter( + "x", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedFieldVarAccess( + false, + null, + "x", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "method2", + Type.INT, + List.of( + new TypedParameter( + "x", + Type.INT + ), + new TypedParameter( + "y", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "x", + Type.INT + ), + Operator.ADD, + new TypedFieldVarAccess( + false, + null, + "y", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ) + ), + List.of( + new TypedConstructor( + "MethodCall", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("MethodCall") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MultipleClasses.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MultipleClasses.java new file mode 100644 index 0000000..f6e6b79 --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_MultipleClasses.java @@ -0,0 +1,5 @@ +package testResources.TypedAST.TypedASTFeatures; + +public class TypedAST_MultipleClasses { + +} \ No newline at end of file diff --git a/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Operators.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Operators.java new file mode 100644 index 0000000..3b7b30f --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Operators.java @@ -0,0 +1,240 @@ +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_Operators { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "Operators", + List.of(), + List.of( + new TypedMethod( + "add", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ), + new TypedParameter( + "b", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.ADD, + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "sub", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ), + new TypedParameter( + "b", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.SUB, + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "mul", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ), + new TypedParameter( + "b", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.MUL, + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "div", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ), + new TypedParameter( + "b", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.DIV, + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "mod", + Type.INT, + List.of( + new TypedParameter( + "a", + Type.INT + ), + new TypedParameter( + "b", + Type.INT + ) + ), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "a", + Type.INT + ), + Operator.MOD, + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ) + ), + List.of( + new TypedConstructor( + "Operators", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("Operators") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Overloaded.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Overloaded.java similarity index 55% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Overloaded.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Overloaded.java index 905f16a..c66fb78 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Overloaded.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Overloaded.java @@ -1,98 +1,124 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAST_Overloaded { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "Overloaded", List.of(), List.of( - new Method( - Type.INT, + new TypedMethod( "overloadedMethod", + Type.INT, List.of(), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new IntLiteral(0) + new TypedReturn( + new TypedIntLiteral( + 0, + Type.INT + ), + Type.INT ) - ) + ), + Type.INT ) ), - new Method( - Type.INT, + new TypedMethod( "overloadedMethod", + Type.INT, List.of( - new Parameter( + new TypedParameter( "x", Type.INT ) ), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new FieldVarAccess( + new TypedReturn( + new TypedFieldVarAccess( false, null, - "x" - ) + "x", + Type.INT + ), + Type.INT ) - ) + ), + Type.INT ) ), - new Method( - Type.INT, + new TypedMethod( "overloadedMethod", + Type.INT, List.of( - new Parameter( + new TypedParameter( "x", Type.INT ), - new Parameter( + new TypedParameter( "y", Type.INT ) ), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Return( - new Binary( - new FieldVarAccess( + new TypedReturn( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.ADD, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) + "y", + Type.INT + ), + Type.INT + ), + Type.INT ) - ) + ), + Type.INT ) ) ), List.of( - new Constructor( + new TypedConstructor( "Overloaded", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("Overloaded") ) - ) + ), + null ); } } \ No newline at end of file diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Print.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Print.java similarity index 56% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Print.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Print.java index b4c7ab4..718f0a0 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Print.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Print.java @@ -1,86 +1,105 @@ -package testResources.typedAST.TypedASTFeatures; +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 de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAST_Print { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "Print", List.of(), List.of( - new Method( + new TypedMethod( + "printIt", Type.VOID, - "print", List.of( - new Parameter( + new TypedParameter( "c", Type.CHAR ) ), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Print( - new FieldVarAccess( + new TypedPrint( + new TypedFieldVarAccess( false, null, - "c" - ) + "c", + Type.CHAR + ), + Type.VOID ) - ) + ), + Type.VOID ) ), - new Method( - Type.VOID, + new TypedMethod( "printMoreComplex", + Type.VOID, List.of( - new Parameter( + new TypedParameter( "x", Type.INT ), - new Parameter( + new TypedParameter( "y", Type.INT ) ), - new Block( + List.of(), + new TypedBlock( + List.of(), List.of( - new Print( - new Binary( - new FieldVarAccess( + new TypedPrint( + new TypedBinary( + new TypedFieldVarAccess( false, null, - "x" + "x", + Type.INT ), Operator.LT, - new FieldVarAccess( + new TypedFieldVarAccess( false, null, - "y" - ) - ) + "y", + Type.INT + ), + Type.BOOL + ), + Type.VOID ) - ) + ), + Type.VOID ) ) ), List.of( - new Constructor( + new TypedConstructor( "Print", List.of(), - new Block( - List.of() - ) + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("Print") ) - ) + ), + 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 new file mode 100644 index 0000000..592b74d --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_Return.java @@ -0,0 +1,131 @@ +package testResources.TypedAST.TypedASTFeatures; + +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 TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "Return", + List.of(), + List.of( + new TypedMethod( + "returnInt", + Type.INT, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedIntLiteral( + 10, + Type.INT + ), + Type.INT + ) + ), + Type.INT + ) + ), + new TypedMethod( + "returnVoid", + Type.VOID, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + null, + Type.VOID + ) + ), + Type.VOID + ) + ), + new TypedMethod( + "returnBoolean", + Type.BOOL, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedBoolLiteral( + true, + Type.BOOL + ), + Type.BOOL + ) + ), + Type.BOOL + ) + ), + new TypedMethod( + "returnChar", + Type.CHAR, + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedCharLiteral( + 'a', + Type.CHAR + ), + Type.CHAR + ) + ), + Type.CHAR + ) + ), + new TypedMethod( + "returnClass", + Type.REFERENCE("Return"), + List.of(), + List.of(), + new TypedBlock( + List.of(), + List.of( + new TypedReturn( + new TypedNew( + Type.REFERENCE("Return"), + List.of() + ), + Type.REFERENCE("Return") + ) + ), + Type.REFERENCE("Return") + ) + ) + ), + List.of( + new TypedConstructor( + "Return", + 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_VariableDefWithDecl.java b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_VariableDefWithDecl.java similarity index 53% rename from src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_VariableDefWithDecl.java rename to src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_VariableDefWithDecl.java index 3c8ca54..a2e33fe 100644 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_VariableDefWithDecl.java +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_VariableDefWithDecl.java @@ -1,55 +1,75 @@ -package testResources.typedAST.TypedASTFeatures; +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_VariableDefWithDecl { - public static Program get() { - return new Program( + public static TypedProgram get() { + return new TypedProgram( List.of( - new Class( + new TypedClass( "VariableDefWithDecl", List.of(), List.of(), List.of( - new Constructor( + new TypedConstructor( "VariableDefWithDecl", List.of(), - new Block( + new TypedBlock( List.of( - new Declaration( + new TypedLocalVariable( "a", Type.INT ), - new Assignment( - new FieldVarAccess( - false, - null, - "a" - ), - new IntLiteral(10) - ), - new Declaration( + new TypedLocalVariable( "b", Type.INT - ), - new Assignment( - new FieldVarAccess( + ) + ), + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT + ), + new TypedFieldVarAccess( false, null, - "b" + "a", + Type.INT ), - new IntLiteral(20) + Type.INT + ), + new TypedAssignment( + new TypedIntLiteral( + 20, + Type.INT + ), + new TypedFieldVarAccess( + false, + null, + "b", + Type.INT + ), + Type.INT ) - ) - ) + ), + Type.VOID + ), + Type.VOID, + List.of() ) - ) + ), + null, + null, + Type.REFERENCE("VariableDefWithDecl") ) - ) + ), + 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 new file mode 100644 index 0000000..7624e5c --- /dev/null +++ b/src/test/java/testResources/TypedAST/TypedASTFeatures/TypedAST_While.java @@ -0,0 +1,191 @@ +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 de.maishai.typedast.typedclass.*; + +import java.util.List; + +public class TypedAST_While { + public static TypedProgram get() { + return new TypedProgram( + List.of( + new TypedClass( + "While", + List.of(), + List.of( + new TypedMethod( + "whileLoop", + 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 TypedWhile( + new TypedBinary( + new TypedFieldVarAccess( + false, + null, + "i", + Type.INT + ), + Operator.LT, + new TypedIntLiteral( + 5, + Type.INT + ), + Type.BOOL + ), + 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 + ), + Type.VOID + ) + ) + ) + ), + 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( + new TypedConstructor( + "While", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("While") + ) + ), + null + ); + } +} \ No newline at end of file diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java similarity index 99% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java index 040111f..b8236de 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructor.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithConstructor { +package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructor { // int x; // public classWithConstructor() { // this.x = 10; diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java similarity index 98% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java index 26e9017..94c5d25 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorAndMethodCall.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorAndMethodCall { +package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorAndMethodCall { // int x; // // public ClassWithConstructorAndMethodCall() { diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java similarity index 98% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java index db47095..b7b7d63 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithCodeInComments.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments { +package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments { // int x; // public ClassWithConstructorWithCodeInComments() { // this.x = 10; diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java similarity index 98% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java index 84e8607..19dc89c 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithConstructorWithParameters.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorWithParameters { +package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorWithParameters { // int x; // public classWithConstructorWithParameters(int startValue, int repetitions) { // this.x = startValue; diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java similarity index 96% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java index 7dabe49..9a95d6b 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithField.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithField { +package testResources.TypedAST.TypedASTMore;//public class ClassWithField { // int x; //} diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java similarity index 95% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java index 1364084..03ad682 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethod.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithMethod { +package testResources.TypedAST.TypedASTMore;//public class ClassWithMethod { // public boolean method() { // return false; // } diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java similarity index 97% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java index e6dd3e2..3ec5cf2 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMethodAndField.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithMethodAndField { +package testResources.TypedAST.TypedASTMore;//public class ClassWithMethodAndField { // char c; // // public ClassWithMethodAndField(char character) { diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java similarity index 98% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java index 08bbe3a..f9c405f 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain { +package testResources.TypedAST.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain { // ClassWithMoreComplexMethodAndMain instance; // // public boolean moreComplexMethod() { diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java similarity index 99% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java index 3d3129e..40fb554 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_ComplexClass.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class ComplexClass { +package testResources.TypedAST.TypedASTMore;//public class ComplexClass { // // int x; // int y; diff --git a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java similarity index 95% rename from src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java rename to src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java index 33c3ad3..31b5d85 100644 --- a/src/test/java/testResources/typedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java +++ b/src/test/java/testResources/TypedAST/TypedASTMore/TypedAbstractSyntax_PublicClass.java @@ -1,4 +1,4 @@ -package testResources.typedAST.TypedASTMore;//public class PublicClass { +package testResources.TypedAST.TypedASTMore;//public class PublicClass { //} import de.maishai.typedast.Type; diff --git a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Continue.java b/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Continue.java deleted file mode 100644 index a6cdcb8..0000000 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Continue.java +++ /dev/null @@ -1,103 +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_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/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_If.java b/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_If.java deleted file mode 100644 index 1bc4729..0000000 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_If.java +++ /dev/null @@ -1,61 +0,0 @@ -package testResources.typedAST.TypedASTFeatures; - -import de.maishai.ast.records.Class; -import de.maishai.ast.records.*; -import de.maishai.typedast.Type; - -import java.util.List; - -public class TypedAST_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/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_IncrDecr.java b/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_IncrDecr.java deleted file mode 100644 index a403e5d..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_Method.java b/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Method.java deleted file mode 100644 index 6a501fe..0000000 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Method.java +++ /dev/null @@ -1,39 +0,0 @@ -package testResources.typedAST.TypedASTFeatures; - -import de.maishai.ast.records.Class; -import de.maishai.ast.records.*; -import de.maishai.typedast.Type; - -import java.util.List; - -public class TypedAST_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/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MultipleClasses.java b/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MultipleClasses.java deleted file mode 100644 index 2c6aa85..0000000 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_MultipleClasses.java +++ /dev/null @@ -1,5 +0,0 @@ -package testResources.typedAST.TypedASTFeatures; - -public class TypedAST_MultipleClasses { - -} \ 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 deleted file mode 100644 index c7b966a..0000000 --- a/src/test/java/testResources/typedAST/TypedASTFeatures/TypedAST_Return.java +++ /dev/null @@ -1,95 +0,0 @@ -package testResources.typedAST.TypedASTFeatures; - -import de.maishai.ast.records.Class; -import de.maishai.ast.records.*; -import de.maishai.typedast.Type; - -import java.util.List; - -public class TypedAST_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/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