From 6b7fc09f8f79c9271633ba8330a962ccb066c8c7 Mon Sep 17 00:00:00 2001 From: i22035 Date: Thu, 9 May 2024 13:55:45 +0200 Subject: [PATCH] Changed AST Tree --- src/main/java/ast/ClassNode.java | 2 ++ src/main/java/ast/MemberNode.java | 4 ---- src/main/java/ast/{ => member}/ConstructorNode.java | 4 ++-- src/main/java/ast/{ => member}/FieldNode.java | 4 +++- src/main/java/ast/member/MemberNode.java | 6 ++++++ src/main/java/ast/{ => member}/MethodNode.java | 7 +++++-- src/main/java/ast/{ => parameter}/ParameterListNode.java | 4 +++- src/main/java/ast/{ => parameter}/ParameterNode.java | 5 ++++- .../ast/statement/VariableDeclarationStatementNode.java | 2 +- src/main/java/ast/{ => type}/TypeNode.java | 4 ++-- src/main/java/bytecode/ClassCodeGen.java | 6 +++--- src/main/java/bytecode/FieldCodeGen.java | 3 +-- src/main/java/bytecode/MethodCodeGen.java | 3 +-- src/main/java/parser/ASTBuilder.java | 6 ++++++ src/main/java/semantic/SemanticAnalyzer.java | 3 +++ 15 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/ast/MemberNode.java rename src/main/java/ast/{ => member}/ConstructorNode.java (67%) rename src/main/java/ast/{ => member}/FieldNode.java (84%) create mode 100644 src/main/java/ast/member/MemberNode.java rename src/main/java/ast/{ => member}/MethodNode.java (85%) rename src/main/java/ast/{ => parameter}/ParameterListNode.java (85%) rename src/main/java/ast/{ => parameter}/ParameterNode.java (76%) rename src/main/java/ast/{ => type}/TypeNode.java (80%) diff --git a/src/main/java/ast/ClassNode.java b/src/main/java/ast/ClassNode.java index 81dc844..2f27d08 100644 --- a/src/main/java/ast/ClassNode.java +++ b/src/main/java/ast/ClassNode.java @@ -1,5 +1,7 @@ package ast; +import ast.member.ConstructorNode; +import ast.member.MemberNode; import ast.type.AccessTypeNode; import ast.type.EnumAccessTypeNode; diff --git a/src/main/java/ast/MemberNode.java b/src/main/java/ast/MemberNode.java deleted file mode 100644 index c1086cd..0000000 --- a/src/main/java/ast/MemberNode.java +++ /dev/null @@ -1,4 +0,0 @@ -package ast; - -public class MemberNode extends ASTNode{ -} diff --git a/src/main/java/ast/ConstructorNode.java b/src/main/java/ast/member/ConstructorNode.java similarity index 67% rename from src/main/java/ast/ConstructorNode.java rename to src/main/java/ast/member/ConstructorNode.java index 94108b8..b411ff1 100644 --- a/src/main/java/ast/ConstructorNode.java +++ b/src/main/java/ast/member/ConstructorNode.java @@ -1,8 +1,8 @@ -package ast; +package ast.member; import ast.type.AccessTypeNode; -public class ConstructorNode extends MethodNode{ +public class ConstructorNode extends MethodNode { public ConstructorNode(AccessTypeNode visibility, String name) { super(visibility, name); } diff --git a/src/main/java/ast/FieldNode.java b/src/main/java/ast/member/FieldNode.java similarity index 84% rename from src/main/java/ast/FieldNode.java rename to src/main/java/ast/member/FieldNode.java index 4e316c1..53a5335 100644 --- a/src/main/java/ast/FieldNode.java +++ b/src/main/java/ast/member/FieldNode.java @@ -1,6 +1,8 @@ -package ast; +package ast.member; +import ast.IdentifierNode; import ast.type.AccessTypeNode; +import ast.type.TypeNode; public class FieldNode extends MemberNode { public AccessTypeNode accessTypeNode; diff --git a/src/main/java/ast/member/MemberNode.java b/src/main/java/ast/member/MemberNode.java new file mode 100644 index 0000000..aa823af --- /dev/null +++ b/src/main/java/ast/member/MemberNode.java @@ -0,0 +1,6 @@ +package ast.member; + +import ast.ASTNode; + +public class MemberNode extends ASTNode { +} diff --git a/src/main/java/ast/MethodNode.java b/src/main/java/ast/member/MethodNode.java similarity index 85% rename from src/main/java/ast/MethodNode.java rename to src/main/java/ast/member/MethodNode.java index 2c4e1e9..4c937cc 100644 --- a/src/main/java/ast/MethodNode.java +++ b/src/main/java/ast/member/MethodNode.java @@ -1,12 +1,15 @@ -package ast; +package ast.member; +import ast.IdentifierNode; +import ast.parameter.ParameterListNode; import ast.statement.StatementNode; import ast.type.AccessTypeNode; +import ast.type.TypeNode; import java.util.ArrayList; import java.util.List; -public class MethodNode extends MemberNode{ +public class MethodNode extends MemberNode { public IdentifierNode identifier; public AccessTypeNode visibility; public TypeNode type; diff --git a/src/main/java/ast/ParameterListNode.java b/src/main/java/ast/parameter/ParameterListNode.java similarity index 85% rename from src/main/java/ast/ParameterListNode.java rename to src/main/java/ast/parameter/ParameterListNode.java index c86014b..34c615a 100644 --- a/src/main/java/ast/ParameterListNode.java +++ b/src/main/java/ast/parameter/ParameterListNode.java @@ -1,4 +1,6 @@ -package ast; +package ast.parameter; + +import ast.ASTNode; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ast/ParameterNode.java b/src/main/java/ast/parameter/ParameterNode.java similarity index 76% rename from src/main/java/ast/ParameterNode.java rename to src/main/java/ast/parameter/ParameterNode.java index fc2d84a..739ae21 100644 --- a/src/main/java/ast/ParameterNode.java +++ b/src/main/java/ast/parameter/ParameterNode.java @@ -1,4 +1,7 @@ -package ast; +package ast.parameter; + +import ast.ASTNode; +import ast.type.TypeNode; public class ParameterNode extends ASTNode { public TypeNode type; diff --git a/src/main/java/ast/statement/VariableDeclarationStatementNode.java b/src/main/java/ast/statement/VariableDeclarationStatementNode.java index 1095fd6..e7f6e32 100644 --- a/src/main/java/ast/statement/VariableDeclarationStatementNode.java +++ b/src/main/java/ast/statement/VariableDeclarationStatementNode.java @@ -1,6 +1,6 @@ package ast.statement; -import ast.TypeNode; +import ast.type.TypeNode; import ast.expression.ExpressionNode; public class VariableDeclarationStatementNode extends StatementNode { diff --git a/src/main/java/ast/TypeNode.java b/src/main/java/ast/type/TypeNode.java similarity index 80% rename from src/main/java/ast/TypeNode.java rename to src/main/java/ast/type/TypeNode.java index 4733bc8..5b1c2a6 100644 --- a/src/main/java/ast/TypeNode.java +++ b/src/main/java/ast/type/TypeNode.java @@ -1,6 +1,6 @@ -package ast; +package ast.type; -import ast.type.EnumTypeNode; +import ast.ASTNode; public class TypeNode extends ASTNode { public EnumTypeNode enumTypeNode; diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index 203f3f3..1e931c0 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -1,9 +1,9 @@ package bytecode; import ast.ClassNode; -import ast.FieldNode; -import ast.MemberNode; -import ast.MethodNode; +import ast.member.FieldNode; +import ast.member.MemberNode; +import ast.member.MethodNode; import java.io.File; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; diff --git a/src/main/java/bytecode/FieldCodeGen.java b/src/main/java/bytecode/FieldCodeGen.java index 5e08941..76e2921 100644 --- a/src/main/java/bytecode/FieldCodeGen.java +++ b/src/main/java/bytecode/FieldCodeGen.java @@ -1,9 +1,8 @@ package bytecode; -import ast.FieldNode; +import ast.member.FieldNode; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.Opcodes; public class FieldCodeGen { diff --git a/src/main/java/bytecode/MethodCodeGen.java b/src/main/java/bytecode/MethodCodeGen.java index 6f217ac..066905f 100644 --- a/src/main/java/bytecode/MethodCodeGen.java +++ b/src/main/java/bytecode/MethodCodeGen.java @@ -1,9 +1,8 @@ package bytecode; -import ast.MethodNode; +import ast.member.MethodNode; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; public class MethodCodeGen { public void generateMethodCode(ClassWriter classWriter, MethodNode methodNode) { diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index c4f9374..b6beba4 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -5,10 +5,16 @@ import ast.expression.BinaryExpressionNode; import ast.expression.ExpressionNode; import ast.expression.IdentifierExpressionNode; import ast.expression.UnaryExpressionNode; +import ast.member.FieldNode; +import ast.member.MemberNode; +import ast.member.MethodNode; +import ast.parameter.ParameterListNode; +import ast.parameter.ParameterNode; import ast.statement.*; import ast.type.AccessTypeNode; import ast.type.EnumAccessTypeNode; import ast.type.EnumTypeNode; +import ast.type.TypeNode; import org.antlr.v4.runtime.tree.TerminalNode; import parser.generated.SimpleJavaBaseVisitor; import parser.generated.SimpleJavaParser; diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 940a0dc..3e9197f 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -2,6 +2,9 @@ package semantic; import ast.*; +import ast.member.ConstructorNode; +import ast.member.FieldNode; +import ast.member.MemberNode; import java.util.ArrayList; import java.util.List;