Changed For Structure
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
i22035 2024-07-04 23:07:54 +02:00
parent 7e66b5b8e3
commit 0a9cc7655a
3 changed files with 4 additions and 49 deletions

View File

@ -332,15 +332,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
// Inkrement // Inkrement
IStatementExpressionNode crement = null; IStatementExpressionNode crement = null;
boolean isPrefix = false;
if (ctx.statementExpression(i) != null) { if (ctx.statementExpression(i) != null) {
crement = (IStatementExpressionNode) visit(ctx.statementExpression(i)); crement = (IStatementExpressionNode) visit(ctx.statementExpression(i));
if (crement instanceof IncrementNode) {
isPrefix = ((IncrementNode) crement).crementType == CrementType.PREFIX;
} else if (crement instanceof DecrementNode) {
isPrefix = ((DecrementNode) crement).crementType == CrementType.PREFIX;
}
} }
BlockNode forBlock = (BlockNode) visit(ctx.blockStatement()); BlockNode forBlock = (BlockNode) visit(ctx.blockStatement());
@ -348,18 +341,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
// While-Schleife // While-Schleife
BlockNode whileBody = new BlockNode(); BlockNode whileBody = new BlockNode();
// Prä-Inkrement: Das Inkrement kommt vor dem Block
if (crement != null && isPrefix) {
whileBody.addStatement(crement);
}
// Block Statements der For-Schleife in den While-Block kopieren // Block Statements der For-Schleife in den While-Block kopieren
for (IStatementNode statement : forBlock.statements) { for (IStatementNode statement : forBlock.statements) {
whileBody.addStatement(statement); whileBody.addStatement(statement);
} }
// Post-Inkrement: Das Inkrement kommt nach dem Block // Post-Inkrement: Das Inkrement kommt nach dem Block
if (crement != null && !isPrefix) { if (crement != null) {
whileBody.addStatement(crement); whileBody.addStatement(crement);
} }

View File

@ -308,31 +308,6 @@ class AstBuilderTest {
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
} }
@Test
@DisplayName("Null Test")
public void nullTest() {
BlockNode blockCon = new BlockNode();
MemberAccessNode memberAccess = new MemberAccessNode(true);
memberAccess.addIdentifier("a");
AssignableNode assignable = new AssignableNode(memberAccess);
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
ClassNode class1 = new ClassNode("public", "Null");
class1.addMember(new FieldNode(new AccessModifierNode("public"), new ReferenceType("Null"), "a"));
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "Null.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test @Test
@DisplayName("If Test") @DisplayName("If Test")
public void ifTest() { public void ifTest() {
@ -608,7 +583,7 @@ class AstBuilderTest {
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10")))); blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10"))));
blockCon.addStatement(whileStatement); blockCon.addStatement(whileStatement);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "While", blockCon);
ClassNode class1 = new ClassNode("public", "While"); ClassNode class1 = new ClassNode("public", "While");
class1.addMember(constructor); class1.addMember(constructor);
@ -639,7 +614,7 @@ class AstBuilderTest {
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0")))); blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0"))));
blockCon.addStatement(blockDoWhile); blockCon.addStatement(blockDoWhile);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "DoWhile", blockCon);
ClassNode class1 = new ClassNode("public", "DoWhile"); ClassNode class1 = new ClassNode("public", "DoWhile");
class1.addMember(constructor); class1.addMember(constructor);
@ -675,7 +650,7 @@ class AstBuilderTest {
BlockNode blockCon = new BlockNode(); BlockNode blockCon = new BlockNode();
blockCon.addStatement(forStatement); blockCon.addStatement(forStatement);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "For", blockCon);
ClassNode class1 = new ClassNode("public", "For"); ClassNode class1 = new ClassNode("public", "For");
class1.addMember(constructor); class1.addMember(constructor);

View File

@ -1,8 +0,0 @@
class Null{
int a;
public Null(){
this.a = 1;
}
}