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.typedast.*;
import lombok.AllArgsConstructor;
import org.objectweb.asm.Opcodes;
import java.util.List;
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@AllArgsConstructor
public class TypedPrint implements TypedStatement {
private TypedExpression value;
private Type type;

View File

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

View File

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

View File

@ -1,8 +1,6 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;

View File

@ -1,66 +1,85 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Field {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Field",
List.of(
new Declaration(
new TypedDeclaration(
"x",
Type.INT
),
new Declaration(
new TypedDeclaration(
"c",
Type.CHAR
)
),
List.of(
new Method(
Type.VOID,
new TypedMethod(
"fieldAccess",
Type.VOID,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Assignment(
new FieldVarAccess(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
true,
null,
"x"
"x",
Type.INT
),
new IntLiteral(0)
Type.INT
),
new Assignment(
new FieldVarAccess(
new TypedAssignment(
new TypedCharLiteral(
'a',
Type.CHAR
),
new TypedFieldVarAccess(
true,
null,
"c"
"c",
Type.CHAR
),
new CharLiteral('a')
Type.CHAR
)
)
),
Type.VOID
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Field",
List.of(),
new Block(
List.of()
)
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
)
),
null,
null,
Type.REFERENCE("Field")
)
)
),
null
);
}
}

View File

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

View File

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

View File

@ -1,39 +1,49 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Method {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Method",
List.of(),
List.of(
new Method(
Type.VOID,
new TypedMethod(
"method",
Type.VOID,
List.of(),
new Block(
List.of()
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Method",
List.of(),
new Block(
List.of()
)
new TypedBlock(
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;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_MethodCall {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"MethodCall",
List.of(),
List.of(
new Method(
Type.INT,
new TypedMethod(
"methodCall",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method"
"method",
Type.INT
),
List.of()
)
List.of(),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"methodCall1",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method1"
"method1",
Type.INT
),
List.of(
new IntLiteral(1)
)
)
new TypedIntLiteral(
1,
Type.INT
)
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"methodCall2",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method2"
"method2",
Type.INT
),
List.of(
new IntLiteral(1),
new IntLiteral(2)
)
)
new TypedIntLiteral(
1,
Type.INT
),
new TypedIntLiteral(
2,
Type.INT
)
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"method",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new IntLiteral(0)
new TypedReturn(
new TypedIntLiteral(
0,
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"method1",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"x",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new FieldVarAccess(
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"x"
)
"x",
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"method2",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"x",
Type.INT
),
new Parameter(
new TypedParameter(
"y",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"x"
"x",
Type.INT
),
Operator.ADD,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"y"
)
)
"y",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"MethodCall",
List.of(),
new Block(
List.of()
)
new TypedBlock(
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;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Operators {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Operators",
List.of(),
List.of(
new Method(
Type.INT,
new TypedMethod(
"add",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"a",
Type.INT
),
new Parameter(
new TypedParameter(
"b",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a"
"a",
Type.INT
),
Operator.ADD,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"b"
)
)
"b",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"sub",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"a",
Type.INT
),
new Parameter(
new TypedParameter(
"b",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a"
"a",
Type.INT
),
Operator.SUB,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"b"
)
)
"b",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"mul",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"a",
Type.INT
),
new Parameter(
new TypedParameter(
"b",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a"
"a",
Type.INT
),
Operator.MUL,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"b"
)
)
"b",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"div",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"a",
Type.INT
),
new Parameter(
new TypedParameter(
"b",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a"
"a",
Type.INT
),
Operator.DIV,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"b"
)
)
"b",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"mod",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"a",
Type.INT
),
new Parameter(
new TypedParameter(
"b",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a"
"a",
Type.INT
),
Operator.MOD,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"b"
)
)
"b",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Operators",
List.of(),
new Block(
List.of()
)
new TypedBlock(
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;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Overloaded {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Overloaded",
List.of(),
List.of(
new Method(
Type.INT,
new TypedMethod(
"overloadedMethod",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new IntLiteral(0)
new TypedReturn(
new TypedIntLiteral(
0,
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"overloadedMethod",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"x",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new FieldVarAccess(
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"x"
)
"x",
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.INT,
new TypedMethod(
"overloadedMethod",
Type.INT,
List.of(
new Parameter(
new TypedParameter(
"x",
Type.INT
),
new Parameter(
new TypedParameter(
"y",
Type.INT
)
),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new Binary(
new FieldVarAccess(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"x"
"x",
Type.INT
),
Operator.ADD,
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"y"
)
)
"y",
Type.INT
),
Type.INT
),
Type.INT
)
)
),
Type.INT
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Overloaded",
List.of(),
new Block(
List.of()
)
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
)
),
null,
null,
Type.REFERENCE("Overloaded")
)
)
),
null
);
}
}

View File

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

View File

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

View File

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