added testcase for Continue in TypedAST

This commit is contained in:
JonathanFleischmann 2024-06-22 17:53:47 +02:00
parent 032e965495
commit 67963b61b2
31 changed files with 139 additions and 103 deletions

View File

@ -1,16 +1,14 @@
import de.maishai.Compiler;
import de.maishai.typedast.typedclass.TypedProgram;
import org.junit.jupiter.api.Test;
import testResources.typedAST.TypedASTFeatures.*;
import testResources.TypedAST.TypedASTFeatures.*;
import testResources.AST.ASTFeatures.*;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithConstructor;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithField;
import testResources.AST.ASTMore.AbstractSyntax_ComplexClass;
import testResources.AST.ASTMore.AbstractSyntax_PublicClass;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_ComplexClass;
import testResources.typedAST.TypedASTMore.TypedAbstractSyntax_PublicClass;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_PublicClass;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -63,12 +61,12 @@ public class TypingTests {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Constructor.get());
assertEquals(TypedAST_Constructor.get(), resultTypedAst);
}
//
// @Test
// public void testContinue() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get());
// assertEquals(TypedAST_Continue.get(), resultTypedAst);
// }
@Test
public void testContinue() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Continue.get());
assertEquals(TypedAST_Continue.get(), resultTypedAst);
}
//
// @Test
// public void testField() {

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
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.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.typedclass.TypedBlock;
import de.maishai.typedast.typedclass.TypedClass;

View File

@ -1,8 +1,6 @@
package testResources.typedAST.TypedASTFeatures;
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,103 +1,147 @@
package testResources.typedAST.TypedASTFeatures;
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_Continue {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Continue",
List.of(),
List.of(
new Method(
Type.VOID,
new TypedMethod(
"continueLoop",
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"
)),
List.of(
new TypedFor(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
new TypedFieldVarAccess(
false,
null,
"i"
"i",
Type.INT
),
Type.INT
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.LT,
new IntLiteral(5)
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
new TypedIntLiteral(
5,
Type.INT
),
new Binary(
new FieldVarAccess(
Type.BOOL
),
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
),
new Block(
new TypedBlock(
List.of(),
List.of(
new IfElse(
new Binary(
new FieldVarAccess(
new TypedIfElse(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i"
"i",
Type.INT
),
Operator.EQ,
new IntLiteral(3)
new TypedIntLiteral(
3,
Type.INT
),
Type.BOOL
),
new Block(
new TypedBlock(
List.of(),
List.of(
new Continue()
)
new TypedContinue()
),
Type.VOID
),
null
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
)
)
)
),
Type.VOID
),
Type.INT
)
)
),
Type.VOID
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Continue",
List.of(),
new Block(
List.of(
)
)
new TypedBlock(
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

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

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

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTFeatures;
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructor {
package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructor {
// int x;
// public classWithConstructor() {
// 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;
//
// public ClassWithConstructorAndMethodCall() {

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments {
package testResources.TypedAST.TypedASTMore;//public class ClassWithConstructorWithCodeInComments {
// int x;
// public ClassWithConstructorWithCodeInComments() {
// 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;
// public classWithConstructorWithParameters(int startValue, int repetitions) {
// 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;
//}

View File

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

View File

@ -1,4 +1,4 @@
package testResources.typedAST.TypedASTMore;//public class ClassWithMethodAndField {
package testResources.TypedAST.TypedASTMore;//public class ClassWithMethodAndField {
// char c;
//
// 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;
//
// 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 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;

View File

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