Merge remote-tracking branch 'origin/main'

This commit is contained in:
Ahmad 2024-06-22 22:19:14 +02:00
commit 976312d5ae
55 changed files with 2696 additions and 1247 deletions

View File

@ -8,15 +8,9 @@
# Fehlende Tests für Features (positive Tests): # Fehlende Tests für Features (positive Tests):
- Mainmethod - Mainmethod
- *=
- %=
- /=
- boolean als Datentyp (public boolean test;)
- do while
- break - break
- recipient mit methode zwischen drinnen (this.methode().a - recipient mit methode zwischen drinnen (this.methode().a
- && - &&
- || - ||
- unaryOp - unaryOp
- Klammern von Expressions - Klammern von Expressions
- Multiline Comment

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

@ -1,5 +1,6 @@
import de.maishai.Compiler; import de.maishai.Compiler;
import de.maishai.ast.records.Program; import de.maishai.ast.records.Program;
import de.maishai.typedast.typedclass.TypedProgram;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import testResources.AST.ASTFeatures.*; import testResources.AST.ASTFeatures.*;
import testResources.AST.ASTMore.*; import testResources.AST.ASTMore.*;
@ -65,6 +66,13 @@ public class ScannerParserTests {
assertEquals(AbstractSyntax_ComplexClass.get(), resultAst); assertEquals(AbstractSyntax_ComplexClass.get(), resultAst);
} }
// Feature Tests // Feature Tests
@Test @Test
@ -86,6 +94,12 @@ public class ScannerParserTests {
assertEquals(AST_Comment.get(), resultAst); assertEquals(AST_Comment.get(), resultAst);
} }
@Test
public void testCompAssign() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/CompAssign.java"));
assertEquals(AST_CompAssign.get(), resultAst);
}
@Test @Test
public void testConstructor() { public void testConstructor() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Constructor.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Constructor.java"));
@ -98,6 +112,12 @@ public class ScannerParserTests {
assertEquals(AST_Continue.get(), resultAst); assertEquals(AST_Continue.get(), resultAst);
} }
@Test
public void testDataTypes() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/DataTypes.java"));
assertEquals(AST_DataTypes.get(), resultAst);
}
@Test @Test
public void testField() { public void testField() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Field.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Field.java"));
@ -116,18 +136,18 @@ public class ScannerParserTests {
assertEquals(AST_If.get(), resultAst); assertEquals(AST_If.get(), resultAst);
} }
// @Test
// public void testIncrDecr() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java"));
// assertEquals(AST_IncrDecr.get(), resultAst);
// }
@Test @Test
public void testLogicExpr() { public void testLogicExpr() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/LogicExpr.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/LogicExpr.java"));
assertEquals(AST_LogicExpr.get(), resultAst); assertEquals(AST_LogicExpr.get(), resultAst);
} }
@Test
public void testMain() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Main.java"));
assertEquals(AST_Main.get(), resultAst);
}
@Test @Test
public void testMethod() { public void testMethod() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Method.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Method.java"));
@ -140,7 +160,12 @@ public class ScannerParserTests {
assertEquals(AST_MethodCall.get(), resultAst); assertEquals(AST_MethodCall.get(), resultAst);
} }
//TODO: Multiple Classes test // @Test
// public void testMultipleClasses() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses.java"));
// assertEquals(AST_MultipleClasses.get(), resultAst);
// }
// TODO: Implement
@Test @Test
public void testOperators() { public void testOperators() {
@ -159,14 +184,12 @@ public class ScannerParserTests {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Print.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Print.java"));
assertEquals(AST_Print.get(), resultAst); assertEquals(AST_Print.get(), resultAst);
} }
//TODO: fix
// @Test @Test
// public void testReturn() { public void testReturn() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java"));
// assertEquals(AST_Return.get(), resultAst); assertEquals(AST_Return.get(), resultAst);
// } }
//TODO: fix
@Test @Test
public void testVariableDefWithDecl() { public void testVariableDefWithDecl() {

View File

@ -1,16 +1,15 @@
import de.maishai.Compiler; import de.maishai.Compiler;
import de.maishai.typedast.typedclass.TypedProgram; import de.maishai.typedast.typedclass.TypedProgram;
import jdk.jshell.spi.ExecutionControl;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import testResources.typedAST.TypedASTFeatures.*; import testResources.TypedAST.TypedASTFeatures.*;
import testResources.AST.ASTFeatures.*; import testResources.AST.ASTFeatures.*;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithConstructor; import testResources.AST.ASTMore.AbstractSyntax_ClassWithConstructor;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithField; import testResources.AST.ASTMore.AbstractSyntax_ClassWithField;
import testResources.AST.ASTMore.AbstractSyntax_ComplexClass;
import testResources.AST.ASTMore.AbstractSyntax_PublicClass; import testResources.AST.ASTMore.AbstractSyntax_PublicClass;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor; import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField; import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ComplexClass; import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_PublicClass;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_PublicClass;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -58,103 +57,117 @@ public class TypingTests {
assertEquals(TypedAST_Comment.get(), resultTypedAst); assertEquals(TypedAST_Comment.get(), resultTypedAst);
} }
@Test
public void testCompAssign() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_CompAssign.get());
assertEquals(TypedAST_CompAssign.get(), resultTypedAst);
}
@Test @Test
public void testConstructor() { public void testConstructor() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Constructor.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Constructor.get());
assertEquals(TypedAST_Constructor.get(), resultTypedAst); assertEquals(TypedAST_Constructor.get(), resultTypedAst);
} }
//
// @Test @Test
// public void testContinue() { public void testContinue() {
// 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 testDataTypes() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_DataTypes.get());
// assertEquals(TypedAST_Field.get(), resultTypedAst); assertEquals(TypedAST_DataTypes.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testFor() { public void testField() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get());
// assertEquals(TypedAST_For.get(), resultTypedAst); assertEquals(TypedAST_Field.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testIf() { public void testFor() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_For.get());
// assertEquals(TypedAST_If.get(), resultTypedAst); assertEquals(TypedAST_For.get(), resultTypedAst);
// } }
//
// @Test @Test
// public void testIncrDecr() { public void testIf() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_IncrDecr.get()); TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get());
// assertEquals(TypedAST_IncrDecr.get(), resultTypedAst); assertEquals(TypedAST_If.get(), resultTypedAst);
// } }
//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 testMain() {
// public void testMethod() { TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get());
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get()); assertEquals(TypedAST_Main.get(), resultTypedAst);
// assertEquals(TypedAST_Method.get(), resultTypedAst); try {
// } throw new ExecutionControl.NotImplementedException("Main Class not yet implemented in TypedAST");
// } catch (ExecutionControl.NotImplementedException e) {
// @Test throw new RuntimeException(e);
// public void testMethodCall() { }
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_MethodCall.get()); }
// assertEquals(TypedAST_MethodCall.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 // @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 @Test
// public void testVariableDefWithDecl() {
// @Test TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get());
// public void testVariableDefWithDecl() { assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst);
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_VariableDefWithDecl.get()); }
// assertEquals(TypedAST_VariableDefWithDecl.get(), resultTypedAst);
// } @Test
// public void testWhile() {
// @Test TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get());
// public void testWhile() { assertEquals(TypedAST_While.get(), resultTypedAst);
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_While.get()); }
// assertEquals(TypedAST_While.get(), resultTypedAst);
// }
} }

View File

@ -1,37 +1,37 @@
package testResources.typedAST.TypedASTFeatures; package testResources.AST.ASTFeatures;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import java.util.List; import java.util.List;
public class AST_CompAssign {
public class TypedAST_Operators {
public static Program get() { public static Program get() {
return new Program( return new Program(
List.of( List.of(
new Class( new Class(
"Operators", "CompAssign",
List.of(), List.of(),
List.of( List.of(
new Method( new Method(
Type.INT, Type.INT,
"add", "increase",
List.of( List.of(
new Parameter( new Parameter(
"a", "a",
Type.INT Type.INT
),
new Parameter(
"b",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Return( new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary( new Binary(
new FieldVarAccess( new FieldVarAccess(
false, false,
@ -39,11 +39,14 @@ public class TypedAST_Operators {
"a" "a"
), ),
Operator.ADD, Operator.ADD,
new FieldVarAccess( new IntLiteral(1)
false, )
null, ),
"b" new Return(
) new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -51,20 +54,21 @@ public class TypedAST_Operators {
), ),
new Method( new Method(
Type.INT, Type.INT,
"sub", "decrease",
List.of( List.of(
new Parameter( new Parameter(
"a", "a",
Type.INT Type.INT
),
new Parameter(
"b",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Return( new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary( new Binary(
new FieldVarAccess( new FieldVarAccess(
false, false,
@ -72,11 +76,14 @@ public class TypedAST_Operators {
"a" "a"
), ),
Operator.SUB, Operator.SUB,
new FieldVarAccess( new IntLiteral(1)
false, )
null, ),
"b" new Return(
) new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -84,20 +91,21 @@ public class TypedAST_Operators {
), ),
new Method( new Method(
Type.INT, Type.INT,
"mul", "multiply",
List.of( List.of(
new Parameter( new Parameter(
"a", "a",
Type.INT Type.INT
),
new Parameter(
"b",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Return( new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary( new Binary(
new FieldVarAccess( new FieldVarAccess(
false, false,
@ -105,11 +113,14 @@ public class TypedAST_Operators {
"a" "a"
), ),
Operator.MUL, Operator.MUL,
new FieldVarAccess( new IntLiteral(2)
false, )
null, ),
"b" new Return(
) new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -117,20 +128,21 @@ public class TypedAST_Operators {
), ),
new Method( new Method(
Type.INT, Type.INT,
"div", "divide",
List.of( List.of(
new Parameter( new Parameter(
"a", "a",
Type.INT Type.INT
),
new Parameter(
"b",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Return( new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary( new Binary(
new FieldVarAccess( new FieldVarAccess(
false, false,
@ -138,11 +150,14 @@ public class TypedAST_Operators {
"a" "a"
), ),
Operator.DIV, Operator.DIV,
new FieldVarAccess( new IntLiteral(2)
false, )
null, ),
"b" new Return(
) new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -150,20 +165,21 @@ public class TypedAST_Operators {
), ),
new Method( new Method(
Type.INT, Type.INT,
"mod", "modulus",
List.of( List.of(
new Parameter( new Parameter(
"a", "a",
Type.INT Type.INT
),
new Parameter(
"b",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Return( new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary( new Binary(
new FieldVarAccess( new FieldVarAccess(
false, false,
@ -171,11 +187,14 @@ public class TypedAST_Operators {
"a" "a"
), ),
Operator.MOD, Operator.MOD,
new FieldVarAccess( new IntLiteral(2)
false, )
null, ),
"b" new Return(
) new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -184,7 +203,7 @@ public class TypedAST_Operators {
), ),
List.of( List.of(
new Constructor( new Constructor(
"Operators", "CompAssign",
List.of(), List.of(),
new Block( new Block(
List.of() List.of()

View File

@ -1,143 +1,127 @@
package testResources.typedAST.TypedASTFeatures; package testResources.AST.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.Program;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import java.util.List; import java.util.List;
public class TypedAST_MethodCall { public class AST_DataTypes {
public static Program get() { public static Program get() {
return new Program( return new Program(
List.of( List.of(
new Class( new Class(
"MethodCall", "DataTypes",
List.of(), List.of(
new Declaration(
"x",
Type.INT
),
new Declaration(
"y",
Type.BOOL
),
new Declaration(
"z",
Type.CHAR
)
),
List.of( List.of(
new Method( new Method(
Type.INT, Type.INT,
"methodCall", "integer",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method"
),
List.of()
)
)
)
)
),
new Method(
Type.INT,
"methodCall1",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method1"
),
List.of(
new IntLiteral(1)
)
)
)
)
)
),
new Method(
Type.INT,
"methodCall2",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method2"
),
List.of(
new IntLiteral(1),
new IntLiteral(2)
)
)
)
)
)
),
new Method(
Type.INT,
"method",
List.of(),
new Block(
List.of(
new Return(
new IntLiteral(0)
)
)
)
),
new Method(
Type.INT,
"method1",
List.of( List.of(
new Parameter( new Parameter(
"x", "i",
Type.INT Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Declaration(
"a",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new IntLiteral(1)
),
new Return( new Return(
new FieldVarAccess( new FieldVarAccess(
false, false,
null, null,
"x" "a"
) )
) )
) )
) )
), ),
new Method( new Method(
Type.INT, Type.BOOL,
"method2", "bool",
List.of( List.of(
new Parameter( new Parameter(
"x", "b",
Type.INT Type.BOOL
),
new Parameter(
"y",
Type.INT
) )
), ),
new Block( new Block(
List.of( List.of(
new Declaration(
"a",
Type.BOOL
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new BoolLiteral(true)
),
new Return( new Return(
new Binary( new FieldVarAccess(
new FieldVarAccess( false,
false, null,
null, "a"
"x" )
), )
Operator.ADD, )
new FieldVarAccess( )
false, ),
null, new Method(
"y" Type.CHAR,
) "character",
List.of(
new Parameter(
"c",
Type.CHAR
)
),
new Block(
List.of(
new Declaration(
"a",
Type.CHAR
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new CharLiteral('a')
),
new Return(
new FieldVarAccess(
false,
null,
"a"
) )
) )
) )
@ -146,7 +130,7 @@ public class TypedAST_MethodCall {
), ),
List.of( List.of(
new Constructor( new Constructor(
"MethodCall", "DataTypes",
List.of(), List.of(),
new Block( new Block(
List.of() List.of()

View File

@ -1,86 +0,0 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_IncrDecr {
public static Program get() {
return new Program(
List.of(
new Class(
"IncrDecr",
List.of(),
List.of(
new Method(
Type.INT,
"increment",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new IntLiteral(
1
)
)
)
)
)
),
new Method(
Type.INT,
"decrement",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(
1
)
)
)
)
)
)
),
List.of(
new Constructor(
"IncrDecr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,46 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Main {
public static Program get() {
return new Program(
List.of(
new Class(
"Main",
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
)
)
),
List.of(),
List.of(),
List.of(
new Constructor(
"Main",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -63,14 +63,14 @@ public class AST_Return {
) )
), ),
new Method( new Method(
Type.REFERENCE("AST_Return"), Type.REFERENCE("Return"),
"returnClass", "returnClass",
List.of(), List.of(),
new Block( new Block(
List.of( List.of(
new Return( new Return(
new New( new New(
Type.REFERENCE("AST_Return"), Type.REFERENCE("Return"),
List.of() List.of()
) )
) )

View File

@ -66,6 +66,59 @@ public class AST_While {
) )
) )
) )
),
new Method(
Type.VOID,
"doWhileLoop",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new DoWhile(
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
)
)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
)
)
)
)
) )
), ),
List.of( List.of(

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.TypedBlock; import de.maishai.typedast.typedclass.TypedBlock;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.*;

View File

@ -1,9 +1,5 @@
package testResources.typedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Block;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.Constructor;
import de.maishai.ast.records.Program;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.TypedBlock; import de.maishai.typedast.typedclass.TypedBlock;
import de.maishai.typedast.typedclass.TypedClass; import de.maishai.typedast.typedclass.TypedClass;

View File

@ -0,0 +1,285 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_CompAssign {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"CompAssign",
List.of(),
List.of(
new TypedMethod(
"increase",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"decrease",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.SUB,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"multiply",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MUL,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"divide",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.DIV,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"modulus",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MOD,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
)
),
List.of(
new TypedConstructor(
"CompAssign",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("CompAssign")
)
),
null
);
}
}

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,127 +1,145 @@
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_Continue {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"For", "Continue",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
"continueLoop",
Type.VOID, Type.VOID,
"testFor",
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( List.of(
new Assignment( new TypedFor(
new FieldVarAccess( new TypedAssignment(
false, new TypedIntLiteral(
null, 0,
"i" Type.INT
), ),
new IntLiteral(0) new TypedFieldVarAccess(
),
new Binary(
new FieldVarAccess(
false, false,
null, null,
"i" "i",
Type.INT
),
Type.INT
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
), ),
Operator.LT, Operator.LT,
new IntLiteral(10) new TypedIntLiteral(
), 5,
new Assignment( Type.INT
new FieldVarAccess(
false,
null,
"i"
), ),
new Binary( Type.BOOL
new FieldVarAccess( ),
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
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
),
new TypedBlock(
List.of(),
List.of(
new TypedIfElse(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.EQ,
new TypedIntLiteral(
3,
Type.INT
),
Type.BOOL
),
new TypedBlock(
List.of(),
List.of(
new TypedContinue()
),
Type.VOID
),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
)
),
Type.VOID
), ),
new Block(
List.of()
)
),
new Declaration(
"j",
Type.INT Type.INT
),
new For(
new Assignment(
new FieldVarAccess(
false,
null,
"j"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"j"
),
Operator.LT,
new IntLiteral(10)
),
new Assignment(
new FieldVarAccess(
false,
null,
"j"
),
new Binary(
new FieldVarAccess(
false,
null,
"j"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of()
)
) )
) ),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"For", "Continue",
List.of(), List.of(),
new Block( new TypedBlock(
List.of( List.of(),
) List.of(),
) Type.VOID
),
Type.VOID,
// TODO: ist Konstruktor nicht immer vom Typ der Klasse?
List.of()
) )
) ),
null,
null,
Type.REFERENCE("Continue")
) )
) ),
null
); );
} }
} }

View File

@ -0,0 +1,183 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_DataTypes {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"DataTypes",
List.of(
new TypedDeclaration(
"x",
Type.INT
),
new TypedDeclaration(
"y",
Type.BOOL
),
new TypedDeclaration(
"z",
Type.CHAR
)
),
List.of(
new TypedMethod(
"integer",
Type.INT,
List.of(
new TypedParameter(
"i",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.INT
)
),
List.of(
new TypedAssignment(
new TypedIntLiteral(
1,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"bool",
Type.BOOL,
List.of(
new TypedParameter(
"b",
Type.BOOL
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.BOOL
)
),
List.of(
new TypedAssignment(
new TypedBoolLiteral(
true,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.BOOL
),
Type.BOOL
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.BOOL
),
Type.BOOL
)
),
Type.BOOL
)
),
new TypedMethod(
"character",
Type.CHAR,
List.of(
new TypedParameter(
"c",
Type.CHAR
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.CHAR
)
),
List.of(
new TypedAssignment(
new TypedCharLiteral(
'a',
Type.CHAR
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.CHAR
),
Type.CHAR
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.CHAR
),
Type.CHAR
)
),
Type.CHAR
)
)
),
List.of(
new TypedConstructor(
"DataTypes",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("DataTypes")
)
),
null
);
}
}

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

@ -0,0 +1,175 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_For {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"For",
List.of(),
List.of(
new TypedMethod(
"testFor",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"i",
Type.INT
),
new TypedLocalVariable(
"j",
Type.INT
)
),
List.of(
new TypedFor(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.LT,
new TypedIntLiteral(
10,
Type.INT
),
Type.BOOL
),
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
),
new TypedFor(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Type.INT
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Operator.LT,
new TypedIntLiteral(
10,
Type.INT
),
Type.BOOL
),
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Type.INT
),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
)
)
)
)
),
List.of(
new TypedConstructor(
"For",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("For")
)
),
null
);
}
}

View File

@ -1,84 +1,87 @@
package testResources.typedAST.TypedASTFeatures; package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class; import de.maishai.ast.records.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_If {
public static Program get() { public static TypedProgram get() {
return new Program( return new TypedProgram(
List.of( List.of(
new Class( new TypedClass(
"While", "If",
List.of(), List.of(),
List.of( List.of(
new Method( new TypedMethod(
"ifMethod",
Type.VOID, Type.VOID,
"whileLoop",
List.of(), List.of(),
new Block( List.of(),
new TypedBlock(
List.of(),
List.of( List.of(
new Declaration( new TypedIfElse(
"i", new TypedBoolLiteral(
Type.INT
),
new Assignment(
new FieldVarAccess(
false, false,
null, Type.BOOL
"i"
), ),
new IntLiteral(0) new TypedBlock(
), List.of(),
new While( List.of(),
new Binary( Type.VOID
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
), ),
new Block( new TypedBlock(
List.of(),
List.of( List.of(
new Assignment( new TypedIfElse(
new FieldVarAccess( new TypedBoolLiteral(
false, true,
null, Type.BOOL
"i"
), ),
new Binary( new TypedBlock(
new FieldVarAccess( List.of(),
false, List.of(),
null, Type.VOID
"i" ),
), new TypedBlock(
Operator.ADD, List.of(),
new IntLiteral(1) List.of(),
) Type.VOID
),
Type.VOID
) )
) ),
) Type.VOID
),
Type.VOID
) )
) ),
Type.VOID
) )
) )
), ),
List.of( List.of(
new Constructor( new TypedConstructor(
"While", "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

@ -0,0 +1,56 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.TypedBlock;
import de.maishai.typedast.typedclass.TypedClass;
import de.maishai.typedast.typedclass.TypedConstructor;
import de.maishai.typedast.typedclass.TypedProgram;
import jdk.jshell.spi.ExecutionControl;
import java.util.List;
public class TypedAST_Main {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"Main",
// new Block(
// List.of(
// new Declaration(
// "i",
// Type.INT
// ),
// new Assignment(
// new FieldVarAccess(
// false,
// null,
// "i"
// ),
// new IntLiteral(0)
// )
// )
// ),
List.of(),
List.of(),
List.of(
new TypedConstructor(
"Main",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("Main")
)
),
null
);
}
}

View File

@ -0,0 +1,49 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Method {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"Method",
List.of(),
List.of(
new TypedMethod(
"method",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
)
)
),
List.of(
new TypedConstructor(
"Method",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("Method")
)
),
null
);
}
}

View File

@ -0,0 +1,213 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_MethodCall {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"MethodCall",
List.of(),
List.of(
new TypedMethod(
"methodCall",
Type.INT,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method",
Type.INT
),
List.of(),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"methodCall1",
Type.INT,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method1",
Type.INT
),
List.of(
new TypedIntLiteral(
1,
Type.INT
)
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"methodCall2",
Type.INT,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedMethodCall(
new TypedFieldVarAccess(
false,
null,
"method2",
Type.INT
),
List.of(
new TypedIntLiteral(
1,
Type.INT
),
new TypedIntLiteral(
2,
Type.INT
)
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"method",
Type.INT,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedIntLiteral(
0,
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"method1",
Type.INT,
List.of(
new TypedParameter(
"x",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"x",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"method2",
Type.INT,
List.of(
new TypedParameter(
"x",
Type.INT
),
new TypedParameter(
"y",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"x",
Type.INT
),
Operator.ADD,
new TypedFieldVarAccess(
false,
null,
"y",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
)
),
List.of(
new TypedConstructor(
"MethodCall",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("MethodCall")
)
),
null
);
}
}

View File

@ -0,0 +1,5 @@
package testResources.TypedAST.TypedASTFeatures;
public class TypedAST_MultipleClasses {
}

View File

@ -0,0 +1,240 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Operators {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"Operators",
List.of(),
List.of(
new TypedMethod(
"add",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
),
new TypedParameter(
"b",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.ADD,
new TypedFieldVarAccess(
false,
null,
"b",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"sub",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
),
new TypedParameter(
"b",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.SUB,
new TypedFieldVarAccess(
false,
null,
"b",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"mul",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
),
new TypedParameter(
"b",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MUL,
new TypedFieldVarAccess(
false,
null,
"b",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"div",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
),
new TypedParameter(
"b",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.DIV,
new TypedFieldVarAccess(
false,
null,
"b",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"mod",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
),
new TypedParameter(
"b",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MOD,
new TypedFieldVarAccess(
false,
null,
"b",
Type.INT
),
Type.INT
),
Type.INT
)
),
Type.INT
)
)
),
List.of(
new TypedConstructor(
"Operators",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("Operators")
)
),
null
);
}
}

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

@ -0,0 +1,131 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Return {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"Return",
List.of(),
List.of(
new TypedMethod(
"returnInt",
Type.INT,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedIntLiteral(
10,
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"returnVoid",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
null,
Type.VOID
)
),
Type.VOID
)
),
new TypedMethod(
"returnBoolean",
Type.BOOL,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedBoolLiteral(
true,
Type.BOOL
),
Type.BOOL
)
),
Type.BOOL
)
),
new TypedMethod(
"returnChar",
Type.CHAR,
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedCharLiteral(
'a',
Type.CHAR
),
Type.CHAR
)
),
Type.CHAR
)
),
new TypedMethod(
"returnClass",
Type.REFERENCE("Return"),
List.of(),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedReturn(
new TypedNew(
Type.REFERENCE("Return"),
List.of()
),
Type.REFERENCE("Return")
)
),
Type.REFERENCE("Return")
)
)
),
List.of(
new TypedConstructor(
"Return",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("Return")
)
),
null
);
}
}

View File

@ -1,55 +1,75 @@
package testResources.typedAST.TypedASTFeatures; 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

@ -0,0 +1,191 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_While {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"While",
List.of(),
List.of(
new TypedMethod(
"whileLoop",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"i",
Type.INT
)
),
List.of(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
),
new TypedWhile(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.LT,
new TypedIntLiteral(
5,
Type.INT
),
Type.BOOL
),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
)
),
Type.VOID
),
Type.VOID
)
)
)
),
new TypedMethod(
"doWhileLoop",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"i",
Type.INT
)
),
List.of(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
),
new TypedDoWhile(
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
)
),
Type.VOID
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.LT,
new TypedIntLiteral(
5,
Type.INT
),
Type.BOOL
),
Type.VOID
)
)
)
)
),
List.of(
new TypedConstructor(
"While",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("While")
)
),
null
);
}
}

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructor { package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructor {
// int x; // int x;
// public classWithConstructor() { // public classWithConstructor() {
// this.x = 10; // this.x = 10;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorAndMethodCall { package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorAndMethodCall {
// int x; // int x;
// //
// public ClassWithConstructorAndMethodCall() { // public ClassWithConstructorAndMethodCall() {

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments { package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments {
// int x; // int x;
// public ClassWithConstructorWithCodeInComments() { // public ClassWithConstructorWithCodeInComments() {
// this.x = 10; // this.x = 10;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorWithParameters { package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorWithParameters {
// int x; // int x;
// public classWithConstructorWithParameters(int startValue, int repetitions) { // public classWithConstructorWithParameters(int startValue, int repetitions) {
// this.x = startValue; // this.x = startValue;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithField { package testResources.TypedAST.TypedASTMore;//public class ClassWithField {
// int x; // int x;
//} //}

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithMethod { package testResources.TypedAST.TypedASTMore;//public class ClassWithMethod {
// public boolean method() { // public boolean method() {
// return false; // return false;
// } // }

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithMethodAndField { package testResources.TypedAST.TypedASTMore;//public class ClassWithMethodAndField {
// char c; // char c;
// //
// public ClassWithMethodAndField(char character) { // public ClassWithMethodAndField(char character) {

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain { package testResources.TypedAST.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain {
// ClassWithMoreComplexMethodAndMain instance; // ClassWithMoreComplexMethodAndMain instance;
// //
// public boolean moreComplexMethod() { // public boolean moreComplexMethod() {

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ComplexClass { package testResources.TypedAST.TypedASTMore;//public class ComplexClass {
// //
// int x; // int x;
// int y; // int y;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class PublicClass { package testResources.TypedAST.TypedASTMore;//public class PublicClass {
//} //}
import de.maishai.typedast.Type; import de.maishai.typedast.Type;

View File

@ -1,103 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_Continue {
public static Program get() {
return new Program(
List.of(
new Class(
"Continue",
List.of(),
List.of(
new Method(
Type.VOID,
"continueLoop",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new For(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of(
new IfElse(
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.EQ,
new IntLiteral(3)
),
new Block(
List.of(
new Continue()
)
),
null
)
)
)
)
)
)
)
),
List.of(
new Constructor(
"Continue",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -1,61 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_If {
public static Program get() {
return new Program(
List.of(
new Class(
"If",
List.of(),
List.of(
new Method(
Type.VOID,
"ifMethod",
List.of(),
new Block(
List.of(
new IfElse(
new BoolLiteral(false),
new Block(
List.of()
),
new Block(
List.of(
new IfElse(
new BoolLiteral(true),
new Block(
List.of()
),
new Block(
List.of()
)
)
)
)
)
)
)
)
),
List.of(
new Constructor(
"If",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -1,86 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_IncrDecr {
public static Program get() {
return new Program(
List.of(
new Class(
"IncrDecr",
List.of(),
List.of(
new Method(
Type.INT,
"increment",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new IntLiteral(
1
)
)
)
)
)
),
new Method(
Type.INT,
"decrement",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(
1
)
)
)
)
)
)
),
List.of(
new Constructor(
"IncrDecr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -1,39 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_Method {
public static Program get() {
return new Program(
List.of(
new Class(
"Method",
List.of(),
List.of(
new Method(
Type.VOID,
"method",
List.of(),
new Block(
List.of()
)
)
),
List.of(
new Constructor(
"Method",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -1,5 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
public class TypedAST_MultipleClasses {
}

View File

@ -1,95 +0,0 @@
package testResources.typedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_Return {
public static Program get() {
return new Program(
List.of(
new Class(
"Return",
List.of(),
List.of(
new Method(
Type.INT,
"returnInt",
List.of(),
new Block(
List.of(
new Return(
new IntLiteral(10)
)
)
)
),
new Method(
Type.VOID,
"returnVoid",
List.of(),
new Block(
List.of(
new Return(
null
)
)
)
),
new Method(
Type.BOOL,
"returnBoolean",
List.of(),
new Block(
List.of(
new Return(
new BoolLiteral(true)
)
)
)
),
new Method(
Type.CHAR,
"returnChar",
List.of(),
new Block(
List.of(
new Return(
new CharLiteral('a')
)
)
)
),
new Method(
Type.REFERENCE("AST_Return"),
"returnClass",
List.of(),
new Block(
List.of(
new Return(
new New(
Type.REFERENCE("AST_Return"),
List.of()
)
)
)
)
)
),
List.of(
new Constructor(
"Return",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -1,3 +1,12 @@
public class Comment { public class Comment {
// This is a comment // This is a comment
// This is another comment
// With multiple lines
/* This is a comment
with multiple lines written in a block
which is closed/started with a * and a /
*/
} }

View File

@ -0,0 +1,26 @@
public class CompAssign {
public int increase(int a) {
a += 1;
return a;
}
public int decrease(int a) {
a -= 1;
return a;
}
public int multiply(int a) {
a *= 2;
return a;
}
public int divide(int a) {
a /= 2;
return a;
}
public int modulus(int a) {
a %= 2;
return a;
}
}

View File

@ -0,0 +1,20 @@
public class DataTypes {
int x;
boolean y;
char z;
public int integer(int i) {
int a = 1;
return a;
}
public boolean bool(boolean b) {
boolean a = true;
return a;
}
public char character(char c) {
char a = 'a';
return a;
}
}

View File

@ -1,9 +0,0 @@
public class IncrDecr {
public int increment(int a) {
return a += 1;
}
public int decrement(int a) {
return a -= 1;
}
}

View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
int i = 0;
}
}

View File

@ -15,7 +15,7 @@ public class Return {
return 'a'; return 'a';
} }
public AST_Return returnClass() { public Return returnClass() {
return new AST_Return(); return new Return();
} }
} }

View File

@ -5,4 +5,11 @@ public class While {
i = i + 1; i = i + 1;
} }
} }
public void doWhileLoop() {
int i = 0;
do {
i = i + 1;
} while (i < 5);
}
} }