diff --git a/src/main/java/de/maishai/typedast/Type.java b/src/main/java/de/maishai/typedast/Type.java index 14c0752..3bfabe5 100644 --- a/src/main/java/de/maishai/typedast/Type.java +++ b/src/main/java/de/maishai/typedast/Type.java @@ -12,7 +12,7 @@ public class Type { } private final Kind kind; private final String reference; - public Type(Kind kind, String reference){ + private Type(Kind kind, String reference){ this.kind = kind; this.reference = reference; } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java index cc8992e..160df90 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java @@ -6,6 +6,7 @@ import de.maishai.typedast.MethodContext; import de.maishai.typedast.TypedExpression; import de.maishai.typedast.TypedStatement; import de.maishai.typedast.Type; +import lombok.AllArgsConstructor; import lombok.Data; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -15,6 +16,7 @@ import java.util.Map; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; @Data +@AllArgsConstructor public class TypedAssignment implements TypedStatement { private TypedExpression value; private TypedFieldVarAccess location; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java b/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java index 5839665..015ca7b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java @@ -5,6 +5,7 @@ import de.maishai.ast.records.Binary; import de.maishai.typedast.MethodContext; import de.maishai.typedast.TypedExpression; import de.maishai.typedast.Type; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.objectweb.asm.MethodVisitor; @@ -15,6 +16,7 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; @Data @NoArgsConstructor +@AllArgsConstructor public class TypedBinary implements TypedExpression { private TypedExpression left; private Operator op; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java index 621ec43..e17075b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java @@ -4,6 +4,7 @@ import de.maishai.ast.records.*; import de.maishai.typedast.MethodContext; import de.maishai.typedast.TypedExpression; import de.maishai.typedast.Type; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.objectweb.asm.MethodVisitor; @@ -14,6 +15,7 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; @Data @NoArgsConstructor +@AllArgsConstructor public class TypedFieldVarAccess implements TypedExpression { private Boolean field; private TypedExpression recursiveOwnerChain; diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java index bc1b95f..49d6816 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java @@ -20,7 +20,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithConstructor { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "x", @@ -29,11 +29,15 @@ public class AbstractSyntax_ClassWithConstructor { ); List methods = List.of(); List constructors = getConstructors(); - return new Class( - "ClassWithConstructor", - declarations, - methods, - constructors + return new Program( + List.of( + new Class( + "ClassWithConstructor", + declarations, + methods, + constructors + ) + ) ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java index 2927742..a0d9484 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java @@ -26,7 +26,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithConstructorAndMethodCall { - public static Class get() { + public static Program get() { List declarationList = List.of( new Declaration( "x", @@ -35,11 +35,15 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { ); List methodList = getMethods(); List constructorList = getConstructors(); - return new Class( - "ClassWithConstructorAndMethodCall", - declarationList, - methodList, - constructorList + return new Program( + List.of( + new Class( + "ClassWithConstructorAndMethodCall", + declarationList, + methodList, + constructorList + ) + ) ); } @@ -61,7 +65,7 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { new While( new MethodCall( new FieldVarAccess( - true, + false, null, "methodCall"), List.of() diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java index 3253a61..e13779e 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithCodeInComments.java @@ -21,7 +21,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithConstructorWithCodeInComments { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "x", @@ -30,11 +30,15 @@ public class AbstractSyntax_ClassWithConstructorWithCodeInComments { ); List methods = List.of(); List constructors = getConstructors(); - return new Class( - "ClassWithConstructorWithCodeInComments", - declarations, - methods, - constructors + return new Program( + List.of( + new Class( + "ClassWithConstructorWithCodeInComments", + declarations, + methods, + constructors + ) + ) ); } @@ -109,7 +113,7 @@ public class AbstractSyntax_ClassWithConstructorWithCodeInComments { "x") ) ) - ) + ) ) ) diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java index 6cce69c..c239284 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java @@ -13,6 +13,7 @@ // } // } //} + import de.maishai.ast.Operator; import de.maishai.ast.records.*; import de.maishai.ast.records.Class; @@ -21,7 +22,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithConstructorWithParameters { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "x", @@ -29,11 +30,15 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { ) ); List constructors = getConstructors(); - return new Class( - "ClassWithConstructorWithParameters", - declarations, - List.of(), - constructors + return new Program( + List.of( + new Class( + "ClassWithConstructorWithParameters", + declarations, + List.of(), + constructors + ) + ) ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java index 48368a6..ee7c8e6 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java @@ -9,7 +9,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithField { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "x", @@ -18,21 +18,25 @@ public class AbstractSyntax_ClassWithField { ); List methods = List.of(); List constructors = - List.of( - new Constructor( - "ClassWithField", - List.of(), - new Block( + List.of( + new Constructor( + "ClassWithField", List.of(), - List.of() + new Block( + List.of(), + List.of() + ) + ) + ); + return new Program( + List.of( + new Class( + "ClassWithField", + declarations, + methods, + constructors ) ) ); - return new Class( - "ClassWithField", - declarations, - methods, - constructors - ); } } \ No newline at end of file diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java index 9a1dd4c..6ed296b 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java @@ -11,19 +11,23 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithMethod { - public static Class get() { + public static Program get() { List methods = getMethods(); - return new Class( - "ClassWithMethod", - List.of(), - methods, + return new Program( List.of( - new Constructor( + new Class( "ClassWithMethod", List.of(), - new Block( - List.of(), - List.of() + methods, + List.of( + new Constructor( + "ClassWithMethod", + List.of(), + new Block( + List.of(), + List.of() + ) + ) ) ) ) diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java index ee8a78a..6cada7c 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java @@ -18,7 +18,7 @@ import de.maishai.typedast.Type; import java.util.List; class AbstractSyntax_ClassWithMethodAndField { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "c", @@ -27,11 +27,15 @@ class AbstractSyntax_ClassWithMethodAndField { ); List methods = getMethods(); List constructors = getConstructors(); - return new Class( - "ClassWithMethodAndField", - declarations, - methods, - constructors + return new Program( + List.of( + new Class( + "ClassWithMethodAndField", + declarations, + methods, + constructors + ) + ) ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java index e67b321..4771f19 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMultipleMethods.java @@ -26,7 +26,7 @@ import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithMultipleMethods { - public static Class get() { + public static Program get() { List declarations = List.of( new Declaration( "instance", @@ -35,11 +35,14 @@ public class AbstractSyntax_ClassWithMultipleMethods { ); List methods = getMethods(); List constructors = List.of(); - return new Class( - "ClassWithMoreComplexMethodAndMain", - declarations, - methods, - constructors + return new Program( + List.of(new Class( + "ClassWithMoreComplexMethodAndMain", + declarations, + methods, + constructors + ) + ) ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java b/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java index 8c0c341..512f105 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java @@ -4,22 +4,27 @@ import de.maishai.ast.records.Block; import de.maishai.ast.records.Class; import de.maishai.ast.records.Constructor; +import de.maishai.ast.records.Program; import java.util.List; public class AbstractSyntax_PublicClass { - public static Class get() { - return new Class( - "PublicClass", - List.of(), - List.of(), + public static Program get() { + return new Program( List.of( - new Constructor( + new Class( "PublicClass", List.of(), - new Block( - List.of(), - List.of() + List.of(), + List.of( + new Constructor( + "PublicClass", + List.of(), + new Block( + List.of(), + List.of() + ) + ) ) ) ) diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java index bc606da..7c6a76d 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java @@ -14,140 +14,230 @@ import de.maishai.ast.Operator; import de.maishai.typedast.Type; +import de.maishai.typedast.TypedStatement; import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAbstractSyntax_ClassWithConstructor { -// public static TypedClass get() { -// TypedClass typedClass = new TypedClass(); -// typedClass.setIsPublic(true); -// typedClass.setTypedId(new TypedId("ClassWithConstructor")); -// -// TypedField typedField = new TypedField(); -// typedField.setTypedId(new TypedId("x")); -// typedField.setType(Type.INT); -// -// typedClass.setTypedFields(List.of(typedField)); -// typedClass.setTypedMethods(List.of()); -// typedClass.setTypedMainMethod(null); -// typedClass.setTypedConstructors(getConstructors()); -// return typedClass; -// } -// -// private static List getConstructors() { -// return List.of(getConstructor1()); -// } -// -// private static TypedConstructor getConstructor1() { -// TypedConstructor typedConstructor = new TypedConstructor(); -// typedConstructor.setIsPublic(true); -// typedConstructor.setTypedId(new TypedId("ClassWithConstructor")); -// typedConstructor.setTypedParameters(List.of()); -// -// TypedBlock typedBlock = new TypedBlock(); -// -// TypedLocalVariable typedLocalVariable = new TypedLocalVariable(); -// typedLocalVariable.setTypedId(new TypedId("i")); -// typedLocalVariable.setType(Type.INT); -// -// typedBlock.setVars(List.of(typedLocalVariable)); -// -// TypedAssignment typedAssignment = new TypedAssignment(); -// typedAssignment.setLoc(new TypedId("x")); -//// typedAssignment.setAssignSign(AssignSign.ASSIGN); -// typedAssignment.setValue(new TypedIntLiteral(10)); -// -// TypedFor typedFor = new TypedFor(); -// -// TypedAssignment typedAssignmentFor = new TypedAssignment(); -// typedAssignmentFor.setLoc(new TypedId("i")); -//// typedAssignmentFor.setAssignSign(AssignSign.ASSIGN); -// typedAssignmentFor.setValue(new TypedIntLiteral(0)); -// -//// typedFor.setAssign(typedAssignmentFor); -// -// TypedBinary typedBinaryFor = new TypedBinary(); -// typedBinaryFor.setLeft(new TypedId("i")); -// typedBinaryFor.setOp(Operator.LT); -// typedBinaryFor.setRight(new TypedIntLiteral(6)); -// -// typedFor.setCond(typedBinaryFor); -// -// TypedBinary typedBinaryForIncr = new TypedBinary(); -// typedBinaryForIncr.setLeft(new TypedId("i")); -// typedBinaryForIncr.setOp(Operator.ADD); -// typedBinaryForIncr.setRight(new TypedIntLiteral(1)); -// -// TypedAssignment typedAssignmentForIncr = new TypedAssignment(); -// typedAssignmentForIncr.setLoc(new TypedId("i")); -//// typedAssignmentForIncr.setAssignSign(AssignSign.ASSIGN); -// typedAssignmentForIncr.setValue(typedBinaryForIncr); -// -//// typedFor.setInc(typedAssignmentForIncr); -// -// TypedBlock typedBlockFor = new TypedBlock(); -// -// TypedLocalVariable typedLocalVariableFor = new TypedLocalVariable(); -// typedLocalVariableFor.setTypedId(new TypedId("j")); -// typedLocalVariableFor.setType(Type.INT); -// -// typedBlockFor.setVars(List.of(typedLocalVariableFor)); -// -// TypedFor typedInnerFor = new TypedFor(); -// -// TypedAssignment typedAssignmentInnerFor = new TypedAssignment(); -// typedAssignmentInnerFor.setLoc(new TypedId("j")); -//// typedAssignmentInnerFor.setAssignSign(AssignSign.ASSIGN); -// typedAssignmentInnerFor.setValue(new TypedIntLiteral(0)); -// -//// typedInnerFor.setAssign(typedAssignmentInnerFor); -// -// TypedBinary typedBinaryInnerFor = new TypedBinary(); -// typedBinaryInnerFor.setLeft(new TypedId("j")); -// typedBinaryInnerFor.setOp(Operator.LT); -// typedBinaryInnerFor.setRight(new TypedId("x")); -// -// typedInnerFor.setCond(typedBinaryInnerFor); -// -// TypedAssignment typedAssignmentInnerForIncr = new TypedAssignment(); -// typedAssignmentInnerForIncr.setLoc(new TypedId("j")); -//// typedAssignmentInnerForIncr.setAssignSign(AssignSign.ADD_ASSIGN); -// typedAssignmentInnerForIncr.setValue(new TypedIntLiteral(1)); -// -//// typedInnerFor.setInc(typedAssignmentInnerForIncr); -// -// TypedBlock typedBlockInnerFor = new TypedBlock(); -// typedBlockInnerFor.setVars(List.of()); -// -// TypedAssignment typedAssignmentInnerForBlock = new TypedAssignment(); -// typedAssignmentInnerForBlock.setLoc(new TypedId("x")); -//// typedAssignmentInnerForBlock.setAssignSign(AssignSign.ASSIGN); -// -// TypedBinary typedBinaryInnerForBlock = new TypedBinary(); -// typedBinaryInnerForBlock.setLeft(new TypedId("x")); -// typedBinaryInnerForBlock.setOp(Operator.MUL); -// typedBinaryInnerForBlock.setRight(new TypedId("x")); -// -// typedAssignmentInnerForBlock.setValue(typedBinaryInnerForBlock); -// -// typedBlockInnerFor.setStmts(List.of(typedAssignmentInnerForBlock)); -// -// typedInnerFor.setTypedBlock(typedBlockInnerFor); -// -// typedBlockFor.setStmts(List.of(typedInnerFor)); -// -// typedFor.setTypedBlock(typedBlockFor); -// -// typedBlock.setStmts( -// List.of( -// typedAssignment, -// typedFor -// ) -// ); -// -// typedConstructor.setTypedBlock(typedBlock); -// -// return typedConstructor; -// } -} \ No newline at end of file + public static TypedClass get() { + return new TypedClass( + "ClassWithConstructor", + List.of( + new TypedDeclaration( + "x", + Type.INT + ) + ), + List.of(), + List.of( + new TypedConstructor( + "ClassWithConstructor", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of( + new TypedLocalVariable( + "i", + Type.INT + ) + ) + ) + ), + null, + null, + Type.REFERENCE("ClassWithField") + ); + } + + private static List getConstructors() { + return List.of(getTypedConstructor1()); + } + + private static TypedConstructor getTypedConstructor1() { + List typedParameters = List.of(); + + List typedLocalVariables = List.of( + new TypedLocalVariable( + "i", + Type.INT + ) + ); + List typedStatementList = + List.of( + new TypedAssignment( + new TypedIntLiteral( + 10, + Type.INT), + new TypedFieldVarAccess( + true, + null, + "x", + Type.INT + ), + Type.INT + ), + 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( + 6, + 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( + new TypedLocalVariable( + "j", + Type.INT + ) + ), + List.of( + 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 TypedFieldVarAccess( + true, + null, + "x", + 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( + new TypedAssignment( + new TypedBinary( + new TypedFieldVarAccess( + true, + null, + "x", + Type.INT), + Operator.MUL, + new TypedFieldVarAccess( + true, + null, + "x", + Type.INT), + Type.INT + ), + new TypedFieldVarAccess( + true, + null, + "x", + Type.INT + ), + Type.INT + ) + ), + Type.INT + ), + Type.INT + ) + ), + Type.INT + ), + Type.INT + ) + ); + TypedBlock typedBlock = new TypedBlock( + typedLocalVariables, + typedStatementList, + Type.INT + ); + + return new TypedConstructor( + "ClassWithConstructor", + typedParameters, + typedBlock, + Type.VOID, + List.of() + ); + } +} diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java index cddcf3e..284b83d 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java @@ -9,18 +9,32 @@ import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAbstractSyntax_ClassWithField { -// public static TypedClass get() { -// TypedClass typedClass = new TypedClass(); -// typedClass.setIsPublic(true); -// typedClass.setTypedId(new TypedId("ClassWithField")); -// typedClass.setTypedFields( -// List.of( -// new TypedField(new TypedId("x"), Type.INT) -// ) -// ); -// typedClass.setTypedMethods(List.of()); -// typedClass.setTypedMainMethod(null); -// typedClass.setTypedConstructors(List.of()); -// return typedClass; -// } + public static TypedClass get() { + return new TypedClass( + "ClassWithField", + List.of( + new TypedDeclaration( + "x", + Type.INT + ) + ), + List.of(), + List.of( + new TypedConstructor( + "ClassWithField", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("ClassWithField") + ); + } } \ No newline at end of file diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java index 6075b5b..cf1c85d 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java @@ -1,19 +1,33 @@ //public class PublicClass { //} +import de.maishai.typedast.Type; import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAbstractSyntax_PublicClass { -// public static TypedClass get() { -// TypedClass typedClass = new TypedClass(); -// typedClass.setIsPublic(true); -// typedClass.setTypedId(new TypedId("PublicClass")); -// typedClass.setTypedFields(List.of()); -// typedClass.setTypedMethods(List.of()); -// typedClass.setTypedMainMethod(null); -// typedClass.setTypedConstructors(List.of()); -// return typedClass; -// } + public static TypedClass get() { + return new TypedClass( + "PublicClass", + List.of(), + List.of(), + List.of( + new TypedConstructor( + "PublicClass", + List.of(), + new TypedBlock( + List.of(), + List.of(), + Type.VOID + ), + Type.VOID, + List.of() + ) + ), + null, + null, + Type.REFERENCE("PublicClass") + ); + } } \ No newline at end of file diff --git a/src/test/java/ScannerParserTests.java b/src/test/java/ScannerParserTests.java index 26e52a2..6f32feb 100644 --- a/src/test/java/ScannerParserTests.java +++ b/src/test/java/ScannerParserTests.java @@ -48,9 +48,15 @@ public class ScannerParserTests { assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst); } + @Test + public void testClassWithConstructorAndMethodCall() { + Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java"); + assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst); + } + // @Test -// public void testClassWithConstructorAndMethodCall() { -// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java"); +// public void testClassCanBeTyped() { +// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassCanBeTyped.java"); // assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst); // } } diff --git a/src/test/java/TypingTests.java b/src/test/java/TypingTests.java new file mode 100644 index 0000000..1c7d646 --- /dev/null +++ b/src/test/java/TypingTests.java @@ -0,0 +1,26 @@ +import de.maishai.Compiler; +import de.maishai.typedast.typedclass.TypedClass; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TypingTests { + + @Test + public void testPublicClass() { + TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get()); + assertEquals(TypedAbstractSyntax_PublicClass.get(), resultTypedAst); + } + + @Test + public void testClassWithField() { + TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get()); + assertEquals(TypedAbstractSyntax_ClassWithField.get(), resultTypedAst); + } + + @Test + public void testClassWithConstructor() { + TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get()); + assertEquals(TypedAbstractSyntax_ClassWithConstructor.get(), resultTypedAst); + } +}