From 48e0ebf521f0cc16303a28c473b8c04a4121d5ce Mon Sep 17 00:00:00 2001 From: JonathanFleischmann Date: Wed, 8 May 2024 15:34:50 +0200 Subject: [PATCH] adapted abstract syntax test files to new ast --- .../AbstractSyntax_ClassWithConstructor.java | 82 +++--- ...tax_ClassWithConstructorAndMethodCall.java | 43 +-- ...ax_ClassWithConstructorWithParameters.java | 77 +++-- .../AbstractSyntax_ClassWithField.java | 6 +- .../AbstractSyntax_ClassWithMethod.java | 8 +- ...bstractSyntax_ClassWithMethodAndField.java | 22 +- ...tax_ClassWithMoreComplexMethodAndMain.java | 107 ++++--- .../AbstractSyntax_OnlyClass.java | 3 +- .../AbstractSyntax_PublicClass.java | 3 +- .../ClassWithMoreComplexMethodAndMain.java | 4 +- ...edAbstractSyntax_ClassWithConstructor.java | 262 +++++++++--------- .../TypedAbstractSyntax_ClassWithField.java | 28 +- .../TypedAbstractSyntax_ClassWithMethod.java | 66 ++--- .../TypedAbstractSyntax_OnlyClass.java | 20 +- .../TypedAbstractSyntax_PublicClass.java | 20 +- 15 files changed, 409 insertions(+), 342 deletions(-) diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java index a27eded..a717132 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructor.java @@ -15,6 +15,7 @@ import de.maishai.ast.*; import de.maishai.ast.records.*; import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; import java.util.List; @@ -22,17 +23,16 @@ public class AbstractSyntax_ClassWithConstructor { public static Class get() { List declarations = List.of( new Declaration( - new Id("x"), + "x", Type.INT ) ); List methods = List.of(); List constructors = getConstructors(); return new Class( - new Id("ClassWithConstructor"), + "ClassWithConstructor", declarations, methods, - null, constructors ); } @@ -44,78 +44,87 @@ public class AbstractSyntax_ClassWithConstructor { private static Constructor getConstructor1() { List parameters = List.of(); - List localVariables = List.of( - new LocalVariable( - new Id("i"), + List localVariables = List.of( + new Declaration( + "i", Type.INT ) ); List statementList = List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), + "x"), new IntLiteral(10) ), new For( new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("i")), + "i"), new IntLiteral(0) ), new Binary( - new FieldId( + new FieldVarAccess( false, null, - new Id("i")), + "i"), Operator.LT, new IntLiteral(6) ), new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("i")), + "i"), new Binary( - new Id("i"), + new FieldVarAccess( + false, + null, + "i"), Operator.ADD, new IntLiteral(1) ) ), new Block( List.of( - new LocalVariable( - new Id("j"), + new Declaration( + "j", Type.INT ) ), List.of( new For( new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("j")), + "j"), new IntLiteral(0) ), new Binary( - new Id("j"), - Operator.LT, - new Id("x") - ), - new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("j")), + "j"), + Operator.LT, + new FieldVarAccess( + false, + null, + "x") + ), + new Assignment( + new FieldVarAccess( + false, + null, + "j"), new Binary( - new FieldId( + new FieldVarAccess( false, null, - new Id("j")), + "j"), Operator.ADD, new IntLiteral(1) ) @@ -124,14 +133,20 @@ public class AbstractSyntax_ClassWithConstructor { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), + "x"), new Binary( - new Id("x"), + new FieldVarAccess( + true, + null, + "x"), Operator.MUL, - new Id("x") + new FieldVarAccess( + true, + null, + "x") ) ) ) @@ -148,8 +163,7 @@ public class AbstractSyntax_ClassWithConstructor { ); return new Constructor( - true, - new Id("ClassWithConstructor"), + "ClassWithConstructor", parameters, block ); diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java index 6393665..2927742 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorAndMethodCall.java @@ -21,6 +21,7 @@ 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; @@ -28,17 +29,16 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { public static Class get() { List declarationList = List.of( new Declaration( - new Id("x"), + "x", Type.INT ) ); List methodList = getMethods(); List constructorList = getConstructors(); return new Class( - new Id("ClassWithConstructorAndMethodCall"), + "ClassWithConstructorAndMethodCall", declarationList, methodList, - null, constructorList ); } @@ -52,31 +52,38 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), + "x"), new IntLiteral(10) ), new While( new MethodCall( - false, - null, - new Id("methodCall"), + new FieldVarAccess( + true, + null, + "methodCall"), List.of() ), new Block( List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), + "x"), new Binary( - new Id("x"), + new FieldVarAccess( + true, + null, + "x"), Operator.MUL, - new Id("x") + new FieldVarAccess( + true, + null, + "x") ) ) ) @@ -85,8 +92,7 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { ) ); return new Constructor( - true, - new Id("ClassWithConstructorAndMethodCall"), + "ClassWithConstructorAndMethodCall", List.of(), block ); @@ -98,15 +104,18 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall { private static Method getMethod1() { return new Method( - ReturnType.BOOL, - new Id("methodCall"), + Type.BOOL, + "methodCall", List.of(), new Block( List.of(), List.of( new IfElse( new Binary( - new Id("x"), + new FieldVarAccess( + true, + null, + "x"), Operator.GT, new IntLiteral(100) ), diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java index dc41211..155a6bd 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithConstructorWithParameters.java @@ -16,6 +16,7 @@ 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; @@ -23,16 +24,15 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { public static Class get() { List declarations = List.of( new Declaration( - new Id("x"), + "x", Type.INT ) ); List constructors = getConstructors(); return new Class( - new Id("ClassWithConstructorWithParameters"), + "ClassWithConstructorWithParameters", declarations, List.of(), - null, constructors ); } @@ -56,36 +56,48 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), - new Id("startValue") + "x"), + new FieldVarAccess( + false, + null, + "startValue") ), new While( new Binary( - new Id("repetitions"), + new FieldVarAccess( + false, + null, + "repetitions"), Operator.GT, new IntLiteral(0) ), new Block( List.of( - new LocalVariable( - new Id("innerRepetitions"), + new Declaration( + "innerRepetitions", Type.INT ) ), List.of( new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("innerRepetitions")), - new Id("x") + "innerRepetitions"), + new FieldVarAccess( + true, + null, + "x") ), new While( new Binary( - new Id("innerRepetitions"), + new FieldVarAccess( + false, + null, + "innerRepetitions"), Operator.GT, new IntLiteral(0) ), @@ -93,22 +105,32 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("x")), + "x"), new Binary( - new Id("x"), + new FieldVarAccess( + true, + null, + "x"), Operator.MUL, - new Id("x") + new FieldVarAccess( + true, + null, + "x") ) ), new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("innerRepetitions")), - new Binary(new Id("innerRepetitions"), + "innerRepetitions"), + new Binary( + new FieldVarAccess( + false, + null, + "innerRepetitions"), Operator.SUB, new IntLiteral(1)) @@ -117,13 +139,17 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { ) ), new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("repetitions")), - new Binary(new Id("repetitions"), + "repetitions"), + new Binary( + new FieldVarAccess( + false, + null, + "repetitions"), Operator.SUB, - new IntLiteral(1) + new IntLiteral(1) ) ) ) @@ -132,8 +158,7 @@ public class AbstractSyntax_ClassWithConstructorWithParameters { ) ); return new Constructor( - true, - new Id("classWithConstructorWithParameters"), + "classWithConstructorWithParameters", parameters, block ); diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java index 6d2be52..c166836 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithField.java @@ -6,6 +6,7 @@ import de.maishai.ast.records.Class; import de.maishai.ast.records.Constructor; import de.maishai.ast.records.Declaration; import de.maishai.ast.records.Method; +import de.maishai.typedast.Type; import java.util.List; @@ -13,17 +14,16 @@ public class AbstractSyntax_ClassWithField { public static Class get() { List declarations = List.of( new Declaration( - new Id("x"), + "x", Type.INT ) ); List methods = List.of(); List constructors = List.of(); return new Class( - new Id("ClassWithAssignment"), + "ClassWithAssignment", declarations, methods, - null, constructors ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java index 07e76b5..e61e742 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethod.java @@ -6,6 +6,7 @@ import de.maishai.ast.records.Class; import de.maishai.ast.records.*; +import de.maishai.typedast.Type; import java.util.List; @@ -13,10 +14,9 @@ public class AbstractSyntax_ClassWithMethod { public static Class get() { List methods = getMethods(); return new Class( - new Id("ClassWithMethod"), + "ClassWithMethod", List.of(), methods, - null, List.of() ); } @@ -27,8 +27,8 @@ public class AbstractSyntax_ClassWithMethod { private static Method getMethod1() { return new Method( - ReturnType.BOOL, - new Id("method"), + Type.BOOL, + "method", List.of(), new Block( List.of(), diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java index 58c966f..ee8a78a 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMethodAndField.java @@ -13,6 +13,7 @@ import de.maishai.ast.*; import de.maishai.ast.records.*; import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; import java.util.List; @@ -20,17 +21,16 @@ class AbstractSyntax_ClassWithMethodAndField { public static Class get() { List declarations = List.of( new Declaration( - new Id("c"), + "c", Type.CHAR ) ); List methods = getMethods(); List constructors = getConstructors(); return new Class( - new Id("ClassWithMethodAndField"), + "ClassWithMethodAndField", declarations, methods, - null, constructors ); } @@ -41,8 +41,7 @@ class AbstractSyntax_ClassWithMethodAndField { private static Constructor getConstructor1() { return new Constructor( - true, - new Id("ClassWithMethodAndField"), + "ClassWithMethodAndField", List.of( new Parameter( "character", @@ -53,11 +52,14 @@ class AbstractSyntax_ClassWithMethodAndField { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("c")), - new Id("character") + "c"), + new FieldVarAccess( + false, + null, + "character") ) ) ) @@ -70,8 +72,8 @@ class AbstractSyntax_ClassWithMethodAndField { private static Method getMethod1() { return new Method( - ReturnType.BOOL, - new Id("method"), + Type.BOOL, + "method", List.of(), new Block( List.of(), diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMoreComplexMethodAndMain.java b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMoreComplexMethodAndMain.java index 4bb480c..d96a105 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMoreComplexMethodAndMain.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_ClassWithMoreComplexMethodAndMain.java @@ -13,72 +13,73 @@ // return returnValue; // } // -// public static void main(String[] args) { -// instance = new ClassWithMoreComplexMethodAndMain() +// public void setInstance(ClassWithMoreComplexMethodAndMain setInstance) { +// this.instance = setInstance; // } //} import de.maishai.ast.*; import de.maishai.ast.records.*; import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; import java.util.List; public class AbstractSyntax_ClassWithMoreComplexMethodAndMain { public static Class get() { - Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT; - TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain")); List declarations = List.of( new Declaration( - new Id("instance"), - TypeClassWithMoreComplexMethodAndMain + "instance", + Type.REFERENCE("ClassWithMoreComplexMethodAndMain") ) ); List methods = getMethods(); List constructors = List.of(); return new Class( - new Id("ClassWithMoreComplexMethodAndMain"), + "ClassWithMoreComplexMethodAndMain", declarations, methods, - getMainMethod(), constructors ); } private static List getMethods() { - return List.of(getMethod1()); + return List.of(getMethod1(), getMethod2()); } private static Method getMethod1() { Block block = new Block( List.of( - new LocalVariable( - new Id("i"), + new Declaration( + "i", Type.INT ), - new LocalVariable( - new Id("returnValue"), + new Declaration( + "returnValue", Type.BOOL ) ), List.of( new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("i")), + "i"), new IntLiteral(11) ), new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("returnValue")), + "returnValue"), new BoolLiteral(false) ), new While( new Binary( - new Id("i"), + new FieldVarAccess( + false, + null, + "i"), Operator.GT, new IntLiteral(0) ), @@ -86,62 +87,80 @@ public class AbstractSyntax_ClassWithMoreComplexMethodAndMain { List.of(), List.of( new Assignment( - new FieldId( + new FieldVarAccess( true, null, - new Id("i")), - new Binary(new Id("i"), + "i"), + new Binary( + new FieldVarAccess( + false, + null, + "i"), Operator.SUB, new IntLiteral(1)) ), new Assignment( - new FieldId( + new FieldVarAccess( false, null, - new Id("returnValue")), + "returnValue" + ), new Unary( UnaryOperator.NOT, - new Id("returnValue") + new FieldVarAccess( + false, + null, + "returnValue") ) ) ) ) ), new Return( - new Id("returnValue") + new FieldVarAccess( + false, + null, + "returnValue") ) ) ); return new Method( - ReturnType.BOOL, - new Id("moreComplexMethod"), + Type.BOOL, + "moreComplexMethod", List.of(), block ); } - private static MainMethod getMainMethod() { - Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT; - TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain")); - List statementList = List.of( - new Assignment( - new FieldId( - true, - null, - new Id("instance")), - new New( - TypeClassWithMoreComplexMethodAndMain, - List.of() + private static Method getMethod2() { + List parameters = List.of( + new Parameter( + "setInstance", + Type.REFERENCE("ClassWithMoreComplexMethodAndMain") + ) + ); + + Block block = new Block( + List.of(), + List.of( + new Assignment( + new FieldVarAccess( + true, + null, + "instance"), + new FieldVarAccess( + true, + null, + "setInstance") ) ) ); - Block block = new Block( - List.of(), - statementList - ); - return new MainMethod( + return new Method( + Type.VOID, + "setInstance", + parameters, block ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_OnlyClass.java b/src/main/resources/AbstractSyntax/AbstractSyntax_OnlyClass.java index 2af596b..88dc316 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_OnlyClass.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_OnlyClass.java @@ -9,10 +9,9 @@ import java.util.List; public class AbstractSyntax_OnlyClass { public static Class get() { return new Class( - new Id("OnlyClass"), + "OnlyClass", List.of(), List.of(), - null, List.of() ); } diff --git a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java b/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java index 5b725d8..d12d24e 100644 --- a/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java +++ b/src/main/resources/AbstractSyntax/AbstractSyntax_PublicClass.java @@ -8,10 +8,9 @@ import java.util.List; public class AbstractSyntax_PublicClass { public static Class get() { return new Class( - new Id("PublicClass"), + "PublicClass", List.of(), List.of(), - null, List.of() ); } diff --git a/src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java b/src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java index 09a9150..19caa7f 100644 --- a/src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java +++ b/src/main/resources/JavaTestfiles/ClassWithMoreComplexMethodAndMain.java @@ -13,7 +13,7 @@ public class ClassWithMoreComplexMethodAndMain { return returnValue; } - public static void main(String[] args) { - instance = new ClassWithMoreComplexMethodAndMain() + public void setInstance(ClassWithMoreComplexMethodAndMain setInstance) { + this.instance = setInstance; } } \ No newline at end of file diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java index 1030c88..bc606da 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithConstructor.java @@ -19,135 +19,135 @@ 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; - } +// 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 diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java index 30cffbf..cddcf3e 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithField.java @@ -9,18 +9,18 @@ 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() { +// 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; +// } } \ No newline at end of file diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java index 9129647..6bcda41 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_ClassWithMethod.java @@ -10,37 +10,37 @@ import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAbstractSyntax_ClassWithMethod { - public static TypedClass get() { - TypedClass typedClass = new TypedClass(); - typedClass.setIsPublic(true); - typedClass.setTypedId(new TypedId("ClassWithMethod")); - typedClass.setTypedFields(List.of()); - typedClass.setTypedMethods(getMethods()); - return typedClass; - } - - private static List getMethods() { - return List.of(getMethod1()); - } - - private static TypedMethod getMethod1() { - TypedMethod typedMethod = new TypedMethod(); - typedMethod.setIsPublic(true); - typedMethod.setTypedId(new TypedId("method")); - typedMethod.setReturnType(Type.BOOL); - typedMethod.setTypedParameters(List.of()); - - TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral(); - typedBoolLiteral.setValue(false); - - TypedReturn typedReturn = new TypedReturn(); - typedReturn.setRet(typedBoolLiteral); - - TypedBlock typedBlock = new TypedBlock(); - typedBlock.setVars(List.of()); - typedBlock.setStmts(List.of(typedReturn)); - - typedMethod.setTypedBlock(typedBlock); - return typedMethod; - } +// public static TypedClass get() { +// TypedClass typedClass = new TypedClass(); +// typedClass.setIsPublic(true); +// typedClass.setTypedId(new TypedId("ClassWithMethod")); +// typedClass.setTypedFields(List.of()); +// typedClass.setTypedMethods(getMethods()); +// return typedClass; +// } +// +// private static List getMethods() { +// return List.of(getMethod1()); +// } +// +// private static TypedMethod getMethod1() { +// TypedMethod typedMethod = new TypedMethod(); +// typedMethod.setIsPublic(true); +// typedMethod.setTypedId(new TypedId("method")); +// typedMethod.setReturnType(Type.BOOL); +// typedMethod.setTypedParameters(List.of()); +// +// TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral(); +// typedBoolLiteral.setValue(false); +// +// TypedReturn typedReturn = new TypedReturn(); +// typedReturn.setRet(typedBoolLiteral); +// +// TypedBlock typedBlock = new TypedBlock(); +// typedBlock.setVars(List.of()); +// typedBlock.setStmts(List.of(typedReturn)); +// +// typedMethod.setTypedBlock(typedBlock); +// return typedMethod; +// } } \ No newline at end of file diff --git a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_OnlyClass.java b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_OnlyClass.java index 4ff1212..0a61694 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_OnlyClass.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_OnlyClass.java @@ -6,14 +6,14 @@ import de.maishai.typedast.typedclass.*; import java.util.List; public class TypedAbstractSyntax_OnlyClass { - public static TypedClass get() { - TypedClass typedClass = new TypedClass(); - typedClass.setIsPublic(false); - typedClass.setTypedId(new TypedId("OnlyClass")); - typedClass.setTypedFields(List.of()); - typedClass.setTypedMethods(List.of()); - typedClass.setTypedMainMethod(null); - typedClass.setTypedConstructors(List.of()); - return typedClass; - } +// public static TypedClass get() { +// TypedClass typedClass = new TypedClass(); +// typedClass.setIsPublic(false); +// typedClass.setTypedId(new TypedId("OnlyClass")); +// typedClass.setTypedFields(List.of()); +// typedClass.setTypedMethods(List.of()); +// typedClass.setTypedMainMethod(null); +// typedClass.setTypedConstructors(List.of()); +// return typedClass; +// } } \ 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 80eaac0..6075b5b 100644 --- a/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java +++ b/src/main/resources/TypedAbstractSyntax/TypedAbstractSyntax_PublicClass.java @@ -6,14 +6,14 @@ 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() { +// 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; +// } } \ No newline at end of file