translated most of test ASTs into TypedASTs

This commit is contained in:
JonathanFleischmann 2024-06-22 19:36:39 +02:00
parent 57c603c498
commit 59d0c97be3
15 changed files with 1098 additions and 699 deletions

View File

@ -2,12 +2,14 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Print; import de.maishai.ast.records.Print;
import de.maishai.typedast.*; import de.maishai.typedast.*;
import lombok.AllArgsConstructor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import java.util.List; import java.util.List;
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@AllArgsConstructor
public class TypedPrint implements TypedStatement { public class TypedPrint implements TypedStatement {
private TypedExpression value; private TypedExpression value;
private Type type; private Type type;

View File

@ -2,6 +2,7 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.typedast.*; import de.maishai.typedast.*;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
@ -10,6 +11,7 @@ import org.objectweb.asm.Opcodes;
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@Data @Data
@AllArgsConstructor
public class TypedWhile implements TypedStatement { public class TypedWhile implements TypedStatement {
private TypedExpression cond; private TypedExpression cond;
private TypedBlock typedBlock; private TypedBlock typedBlock;

View File

@ -67,24 +67,24 @@ public class TypingTests {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get());
assertEquals(TypedAST_Continue.get(), resultTypedAst); assertEquals(TypedAST_Continue.get(), resultTypedAst);
} }
//
// @Test @Test
// public void testField() { public void testField() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get());
// assertEquals(TypedAST_Field.get(), resultTypedAst); assertEquals(TypedAST_Field.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testFor() { public void testFor() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get());
// assertEquals(TypedAST_For.get(), resultTypedAst); assertEquals(TypedAST_For.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testIf() { public void testIf() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get());
// assertEquals(TypedAST_If.get(), resultTypedAst); assertEquals(TypedAST_If.get(), resultTypedAst);
// } }
// //
// @Test // @Test
// public void testIncrDecr() { // public void testIncrDecr() {
@ -92,67 +92,66 @@ public class TypingTests {
// assertEquals(TypedAST_IncrDecr.get(), resultTypedAst); // assertEquals(TypedAST_IncrDecr.get(), resultTypedAst);
// } // }
//TODO: fix //TODO: fix
//
// @Test @Test
// public void testLogicExpr() { public void testLogicExpr() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get());
// assertEquals(TypedAST_LogicExpr.get(), resultTypedAst); assertEquals(TypedAST_LogicExpr.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testMethod() { public void testMethod() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get());
// assertEquals(TypedAST_Method.get(), resultTypedAst); assertEquals(TypedAST_Method.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testMethodCall() { public void testMethodCall() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MethodCall.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MethodCall.get());
// assertEquals(TypedAST_MethodCall.get(), resultTypedAst); assertEquals(TypedAST_MethodCall.get(), resultTypedAst);
// } }
//
// @Test // @Test
// public void testMultipleClasses() { // public void testMultipleClasses() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MultipleClasses.get()); // TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MultipleClasses.get());
// assertEquals(TypedAST_MultipleClasses.get(), resultTypedAst); // assertEquals(TypedAST_MultipleClasses.get(), resultTypedAst);
// } // }
// // TODO: Implement // TODO: Implement
//
// @Test @Test
// public void testOperators() { public void testOperators() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Operators.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Operators.get());
// assertEquals(TypedAST_Operators.get(), resultTypedAst); assertEquals(TypedAST_Operators.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testOverloaded() { public void testOverloaded() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Overloaded.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Overloaded.get());
// assertEquals(TypedAST_Overloaded.get(), resultTypedAst); assertEquals(TypedAST_Overloaded.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testPrint() { public void testPrint() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Print.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Print.get());
// assertEquals(TypedAST_Print.get(), resultTypedAst); assertEquals(TypedAST_Print.get(), resultTypedAst);
// } }
//TODO: fix
//
// @Test // @Test
// public void testReturn() { // public void testReturn() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get()); // TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get());
// assertEquals(TypedAST_Return.get(), resultTypedAst); // assertEquals(TypedAST_Return.get(), resultTypedAst);
// } // }
//TODO: fix //TODO: fix
//
// @Test @Test
// public void testVariableDefWithDecl() { public void testVariableDefWithDecl() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get());
// assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst); assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testWhile() { public void testWhile() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get());
// assertEquals(TypedAST_While.get(), resultTypedAst); assertEquals(TypedAST_While.get(), resultTypedAst);
// } }
} }

View File

@ -1,8 +1,6 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.*;

View File

@ -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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_Field { public class TypedAST_Field {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"Field", "Field",
List.of( List.of(
new Declaration( new TypedDeclaration(
"x", "x",
Type.INT Type.INT
), ),
new Declaration( new TypedDeclaration(
"c", "c",
Type.CHAR Type.CHAR
) )
), ),
List.of( List.of(
new Method( new TypedMethod(
Type.VOID,
"fieldAccess", "fieldAccess",
Type.VOID,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Assignment( new TypedAssignment(
new FieldVarAccess( new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
true, true,
null, null,
"x" "x",
Type.INT
), ),
new IntLiteral(0) Type.INT
), ),
new Assignment( new TypedAssignment(
new FieldVarAccess( new TypedCharLiteral(
'a',
Type.CHAR
),
new TypedFieldVarAccess(
true, true,
null, null,
"c" "c",
Type.CHAR
), ),
new CharLiteral('a') Type.CHAR
) )
) ),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"Field", "Field",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
),
) null,
null,
Type.REFERENCE("Field")
) )
) ),
null
); );
} }
} }

View File

@ -1,127 +1,175 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_For { public class TypedAST_For {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"For", "For",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.VOID,
"testFor", "testFor",
Type.VOID,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"i", "i",
Type.INT Type.INT
), ),
new For( new TypedLocalVariable(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(10)
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of()
)
),
new Declaration(
"j", "j",
Type.INT Type.INT
), )
new For( ),
new Assignment( List.of(
new FieldVarAccess( new TypedFor(
false, new TypedAssignment(
null, new TypedIntLiteral(
"j" 0,
Type.INT
), ),
new IntLiteral(0) new TypedFieldVarAccess(
),
new Binary(
new FieldVarAccess(
false, false,
null, null,
"j" "i",
Type.INT
),
Type.INT
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
), ),
Operator.LT, Operator.LT,
new IntLiteral(10) new TypedIntLiteral(
), 10,
new Assignment( Type.INT
new FieldVarAccess(
false,
null,
"j"
), ),
new Binary( Type.BOOL
new FieldVarAccess( ),
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"j" "i",
Type.INT
), ),
Operator.ADD, Operator.ADD,
new IntLiteral(1) new TypedIntLiteral(
) 1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
), ),
new Block( new TypedBlock(
List.of() 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( List.of(
new Constructor( new TypedConstructor(
"For", "For",
List.of(), List.of(),
new Block( new TypedBlock(
List.of( List.of(),
) List.of(),
) Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("For")
) )
) ),
null
); );
} }
} }

View File

@ -3,59 +3,85 @@ package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class; import de.maishai.ast.records.Class;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_If { public class TypedAST_If {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"If", "If",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.VOID,
"ifMethod", "ifMethod",
Type.VOID,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new IfElse( new TypedIfElse(
new BoolLiteral(false), new TypedBoolLiteral(
new Block( false,
List.of() Type.BOOL
), ),
new Block( new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
new TypedBlock(
List.of(),
List.of( List.of(
new IfElse( new TypedIfElse(
new BoolLiteral(true), new TypedBoolLiteral(
new Block( true,
List.of() Type.BOOL
), ),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
) )
) ),
) Type.VOID
),
Type.VOID
) )
) ),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"If", "If",
List.of(), List.of(),
new Block( new TypedBlock(
List.of( List.of(),
) List.of(),
) Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("If")
) )
) ),
null
); );
} }
} }

View File

@ -1,332 +1,435 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_LogicExpr { public class TypedAST_LogicExpr {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"LogicExpr", "LogicExpr",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.BOOL,
"test", "test",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.LT, Operator.LT,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
), ),
new Method( new TypedMethod(
Type.BOOL,
"test2", "test2",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.GT, Operator.GT,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
), ),
new Method( new TypedMethod(
Type.BOOL,
"test3", "test3",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.EQ, Operator.EQ,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
), ),
new Method( new TypedMethod(
Type.BOOL,
"test4", "test4",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.NE, Operator.NE,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
), ),
new Method( new TypedMethod(
Type.BOOL,
"test5", "test5",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.LE, Operator.LE,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
), ),
new Method( new TypedMethod(
Type.BOOL,
"test6", "test6",
Type.BOOL,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"x", "x",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y", "y",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"y" "x",
Type.INT
), ),
new IntLiteral(20) Type.INT
), ),
new Return( new TypedAssignment(
new Binary( new TypedIntLiteral(
new FieldVarAccess( 20,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.GE, Operator.GE,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.BOOL
) )
) ),
Type.BOOL
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"LogicExpr", "LogicExpr",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("LogicExpr")
) )
) ),
null
); );
} }
} }

View File

@ -1,39 +1,49 @@
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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_Method { public class TypedAST_Method {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"Method", "Method",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.VOID,
"method", "method",
Type.VOID,
List.of(), List.of(),
new Block( List.of(),
List.of() new TypedBlock(
List.of(),
List.of(),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"Method", "Method",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("Method")
) )
) ),
null
); );
} }
} }

View File

@ -1,160 +1,213 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_MethodCall { public class TypedAST_MethodCall {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"MethodCall", "MethodCall",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.INT,
"methodCall", "methodCall",
Type.INT,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new MethodCall( new TypedMethodCall(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"method" "method",
Type.INT
), ),
List.of() List.of(),
) Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"methodCall1", "methodCall1",
Type.INT,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new MethodCall( new TypedMethodCall(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"method1" "method1",
Type.INT
), ),
List.of( List.of(
new IntLiteral(1) new TypedIntLiteral(
) 1,
) Type.INT
)
),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"methodCall2", "methodCall2",
Type.INT,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new MethodCall( new TypedMethodCall(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"method2" "method2",
Type.INT
), ),
List.of( List.of(
new IntLiteral(1), new TypedIntLiteral(
new IntLiteral(2) 1,
) Type.INT
) ),
new TypedIntLiteral(
2,
Type.INT
)
),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"method", "method",
Type.INT,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new IntLiteral(0) new TypedIntLiteral(
0,
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"method1", "method1",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"x", "x",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
) Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"method2", "method2",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"x", "x",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"y", "y",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.ADD, Operator.ADD,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"MethodCall", "MethodCall",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("MethodCall")
) )
) ),
null
); );
} }
} }

View File

@ -1,198 +1,240 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_Operators { public class TypedAST_Operators {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"Operators", "Operators",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.INT,
"add", "add",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"a", "a",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"b", "b",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"a" "a",
Type.INT
), ),
Operator.ADD, Operator.ADD,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"b" "b",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"sub", "sub",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"a", "a",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"b", "b",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"a" "a",
Type.INT
), ),
Operator.SUB, Operator.SUB,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"b" "b",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"mul", "mul",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"a", "a",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"b", "b",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"a" "a",
Type.INT
), ),
Operator.MUL, Operator.MUL,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"b" "b",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"div", "div",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"a", "a",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"b", "b",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"a" "a",
Type.INT
), ),
Operator.DIV, Operator.DIV,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"b" "b",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"mod", "mod",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"a", "a",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"b", "b",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"a" "a",
Type.INT
), ),
Operator.MOD, Operator.MOD,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"b" "b",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"Operators", "Operators",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("Operators")
) )
) ),
null
); );
} }
} }

View File

@ -1,98 +1,124 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_Overloaded { public class TypedAST_Overloaded {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"Overloaded", "Overloaded",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.INT,
"overloadedMethod", "overloadedMethod",
Type.INT,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new IntLiteral(0) new TypedIntLiteral(
0,
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"overloadedMethod", "overloadedMethod",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"x", "x",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
) Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
), ),
new Method( new TypedMethod(
Type.INT,
"overloadedMethod", "overloadedMethod",
Type.INT,
List.of( List.of(
new Parameter( new TypedParameter(
"x", "x",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"y", "y",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Return( new TypedReturn(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.ADD, Operator.ADD,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.INT
),
Type.INT
) )
) ),
Type.INT
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"Overloaded", "Overloaded",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("Overloaded")
) )
) ),
null
); );
} }
} }

View File

@ -1,86 +1,105 @@
package testResources.TypedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator; 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.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_Print { public class TypedAST_Print {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"Print", "Print",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
"printIt",
Type.VOID, Type.VOID,
"print",
List.of( List.of(
new Parameter( new TypedParameter(
"c", "c",
Type.CHAR Type.CHAR
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Print( new TypedPrint(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"c" "c",
) Type.CHAR
),
Type.VOID
) )
) ),
Type.VOID
) )
), ),
new Method( new TypedMethod(
Type.VOID,
"printMoreComplex", "printMoreComplex",
Type.VOID,
List.of( List.of(
new Parameter( new TypedParameter(
"x", "x",
Type.INT Type.INT
), ),
new Parameter( new TypedParameter(
"y", "y",
Type.INT Type.INT
) )
), ),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Print( new TypedPrint(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"x" "x",
Type.INT
), ),
Operator.LT, Operator.LT,
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"y" "y",
) Type.INT
) ),
Type.BOOL
),
Type.VOID
) )
) ),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"Print", "Print",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("Print")
) )
) ),
null
); );
} }
} }

View File

@ -3,53 +3,73 @@ package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class; import de.maishai.ast.records.Class;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_VariableDefWithDecl { public class TypedAST_VariableDefWithDecl {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"VariableDefWithDecl", "VariableDefWithDecl",
List.of(), List.of(),
List.of(), List.of(),
List.of( List.of(
new Constructor( new TypedConstructor(
"VariableDefWithDecl", "VariableDefWithDecl",
List.of(), List.of(),
new Block( new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"a", "a",
Type.INT Type.INT
), ),
new Assignment( new TypedLocalVariable(
new FieldVarAccess(
false,
null,
"a"
),
new IntLiteral(10)
),
new Declaration(
"b", "b",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
10,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, 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
); );
} }
} }

View File

@ -4,81 +4,113 @@ import de.maishai.ast.Operator;
import de.maishai.ast.records.Class; import de.maishai.ast.records.Class;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List; import java.util.List;
public class TypedAST_While { public class TypedAST_While {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"While", "While",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
Type.VOID,
"whileLoop", "whileLoop",
Type.VOID,
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of( List.of(
new Declaration( new TypedLocalVariable(
"i", "i",
Type.INT Type.INT
), )
new Assignment( ),
new FieldVarAccess( List.of(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false, false,
null, null,
"i" "i",
Type.INT
), ),
new IntLiteral(0) Type.INT
), ),
new While( new TypedWhile(
new Binary( new TypedBinary(
new FieldVarAccess( new TypedFieldVarAccess(
false, false,
null, null,
"i" "i",
Type.INT
), ),
Operator.LT, Operator.LT,
new IntLiteral(5) new TypedIntLiteral(
5,
Type.INT
),
Type.BOOL
), ),
new Block( new TypedBlock(
List.of(),
List.of( List.of(
new Assignment( new TypedAssignment(
new FieldVarAccess( new TypedBinary(
false, new TypedFieldVarAccess(
null,
"i"
),
new Binary(
new FieldVarAccess(
false, false,
null, null,
"i" "i",
Type.INT
), ),
Operator.ADD, Operator.ADD,
new IntLiteral(1) new TypedIntLiteral(
) 1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
) )
) ),
) Type.VOID
),
Type.VOID
) )
) )
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"While", "While",
List.of(), List.of(),
new Block( new TypedBlock(
List.of() List.of(),
) List.of(),
Type.VOID
),
Type.VOID,
List.of()
) )
) ),
null,
null,
Type.REFERENCE("While")
) )
) ),
null
); );
} }
} }