diff --git a/src/main/java/de/maishai/BlockGenerator.java b/src/main/java/de/maishai/BlockGenerator.java index 7d9e616..c2b3a49 100644 --- a/src/main/java/de/maishai/BlockGenerator.java +++ b/src/main/java/de/maishai/BlockGenerator.java @@ -2,7 +2,7 @@ package de.maishai; import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafParser; -import de.maishai.ast.Statement; +import de.maishai.ast.records.Statement; import de.maishai.ast.records.Block; import de.maishai.ast.records.Variable; diff --git a/src/main/java/de/maishai/ExpressionGenerator.java b/src/main/java/de/maishai/ExpressionGenerator.java index 2743b4a..d9e1698 100644 --- a/src/main/java/de/maishai/ExpressionGenerator.java +++ b/src/main/java/de/maishai/ExpressionGenerator.java @@ -2,7 +2,7 @@ package de.maishai; import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafParser; -import de.maishai.ast.Expression; +import de.maishai.ast.records.Expression; import de.maishai.ast.Operator; import de.maishai.ast.Type; import de.maishai.ast.records.*; diff --git a/src/main/java/de/maishai/StatementGenerator.java b/src/main/java/de/maishai/StatementGenerator.java index 07b66f6..4ba4c62 100644 --- a/src/main/java/de/maishai/StatementGenerator.java +++ b/src/main/java/de/maishai/StatementGenerator.java @@ -2,8 +2,8 @@ package de.maishai; import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafParser; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; +import de.maishai.ast.records.Expression; +import de.maishai.ast.records.Statement; import de.maishai.ast.Type; import de.maishai.ast.records.*; diff --git a/src/main/java/de/maishai/ast/Expression.java b/src/main/java/de/maishai/ast/Expression.java deleted file mode 100644 index a113f28..0000000 --- a/src/main/java/de/maishai/ast/Expression.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.maishai.ast; - - -import de.maishai.ast.records.Assignment; -import de.maishai.ast.records.Binary; -import de.maishai.ast.records.BoolConstant; -import de.maishai.ast.records.CharConstant; -import de.maishai.ast.records.Id; -import de.maishai.ast.records.IntConstant; -import de.maishai.ast.records.MethodCall; -import de.maishai.ast.records.New; - -public sealed interface Expression extends Node permits Assignment, Binary, BoolConstant, CharConstant, Id, IntConstant, MethodCall, New { -} diff --git a/src/main/java/de/maishai/ast/Node.java b/src/main/java/de/maishai/ast/Node.java deleted file mode 100644 index 0c68bd6..0000000 --- a/src/main/java/de/maishai/ast/Node.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.maishai.ast; - -import de.maishai.ast.records.Block; -import de.maishai.ast.records.Class; -import de.maishai.ast.records.MainMethod; -import de.maishai.ast.records.Method; -import de.maishai.ast.records.Parameter; -import de.maishai.ast.records.Program; -import de.maishai.ast.records.Variable; - -public sealed interface Node permits Expression, Statement, Block, Class, MainMethod, Method, Parameter, Program, Variable { -} diff --git a/src/main/java/de/maishai/ast/records/Assignment.java b/src/main/java/de/maishai/ast/records/Assignment.java index a5c596b..3af8b5e 100644 --- a/src/main/java/de/maishai/ast/records/Assignment.java +++ b/src/main/java/de/maishai/ast/records/Assignment.java @@ -1,8 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - public record Assignment(Id loc, Expression value) implements Statement, Expression { } diff --git a/src/main/java/de/maishai/ast/records/Binary.java b/src/main/java/de/maishai/ast/records/Binary.java index 40070e3..c110395 100644 --- a/src/main/java/de/maishai/ast/records/Binary.java +++ b/src/main/java/de/maishai/ast/records/Binary.java @@ -1,7 +1,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; import de.maishai.ast.Operator; public record Binary(Expression left, Operator op, Expression right) implements Expression { diff --git a/src/main/java/de/maishai/ast/records/Block.java b/src/main/java/de/maishai/ast/records/Block.java index e36affe..2068433 100644 --- a/src/main/java/de/maishai/ast/records/Block.java +++ b/src/main/java/de/maishai/ast/records/Block.java @@ -2,9 +2,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Node; -import de.maishai.ast.Statement; - import java.util.List; public record Block(List vars, List stmts) implements Node { diff --git a/src/main/java/de/maishai/ast/records/BoolConstant.java b/src/main/java/de/maishai/ast/records/BoolConstant.java index 3b6e0a9..1e4e7a3 100644 --- a/src/main/java/de/maishai/ast/records/BoolConstant.java +++ b/src/main/java/de/maishai/ast/records/BoolConstant.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; - public record BoolConstant(Boolean value) implements Expression { } diff --git a/src/main/java/de/maishai/ast/records/Break.java b/src/main/java/de/maishai/ast/records/Break.java index 9e9dc87..119a35d 100644 --- a/src/main/java/de/maishai/ast/records/Break.java +++ b/src/main/java/de/maishai/ast/records/Break.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Statement; - public record Break() implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/CharConstant.java b/src/main/java/de/maishai/ast/records/CharConstant.java index fdf4ec6..ad2c671 100644 --- a/src/main/java/de/maishai/ast/records/CharConstant.java +++ b/src/main/java/de/maishai/ast/records/CharConstant.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; - public record CharConstant(char value) implements Expression { } diff --git a/src/main/java/de/maishai/ast/records/Class.java b/src/main/java/de/maishai/ast/records/Class.java index 203a48e..cefdba0 100644 --- a/src/main/java/de/maishai/ast/records/Class.java +++ b/src/main/java/de/maishai/ast/records/Class.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Node; - import java.util.List; public record Class(Id id ,List variables, List methods) implements Node { diff --git a/src/main/java/de/maishai/ast/records/Continue.java b/src/main/java/de/maishai/ast/records/Continue.java index 29b7382..f7de37b 100644 --- a/src/main/java/de/maishai/ast/records/Continue.java +++ b/src/main/java/de/maishai/ast/records/Continue.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Statement; - public record Continue() implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/DoWhile.java b/src/main/java/de/maishai/ast/records/DoWhile.java index 73dbf26..32ba194 100644 --- a/src/main/java/de/maishai/ast/records/DoWhile.java +++ b/src/main/java/de/maishai/ast/records/DoWhile.java @@ -1,8 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - public record DoWhile(Block block, Expression cond) implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/Expression.java b/src/main/java/de/maishai/ast/records/Expression.java new file mode 100644 index 0000000..815e7f9 --- /dev/null +++ b/src/main/java/de/maishai/ast/records/Expression.java @@ -0,0 +1,5 @@ +package de.maishai.ast.records; + + +public sealed interface Expression extends Node permits Assignment, Binary, BoolConstant, CharConstant, Id, IntConstant, MethodCall, New { +} diff --git a/src/main/java/de/maishai/ast/records/For.java b/src/main/java/de/maishai/ast/records/For.java index 2440947..1e51e77 100644 --- a/src/main/java/de/maishai/ast/records/For.java +++ b/src/main/java/de/maishai/ast/records/For.java @@ -1,8 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - public record For(Expression assign, Expression cond, Expression inc, Block block) implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/Id.java b/src/main/java/de/maishai/ast/records/Id.java index 5e5f3ea..cc3e8cf 100644 --- a/src/main/java/de/maishai/ast/records/Id.java +++ b/src/main/java/de/maishai/ast/records/Id.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; - public record Id(String name) implements Expression { } diff --git a/src/main/java/de/maishai/ast/records/IfElse.java b/src/main/java/de/maishai/ast/records/IfElse.java index 50c355b..ef48126 100644 --- a/src/main/java/de/maishai/ast/records/IfElse.java +++ b/src/main/java/de/maishai/ast/records/IfElse.java @@ -1,6 +1,4 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; public record IfElse(Expression cond, Block ifBlock, Block elseBlock) implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/IntConstant.java b/src/main/java/de/maishai/ast/records/IntConstant.java index 79c1ea7..2724a49 100644 --- a/src/main/java/de/maishai/ast/records/IntConstant.java +++ b/src/main/java/de/maishai/ast/records/IntConstant.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; - public record IntConstant(Integer value) implements Expression { } diff --git a/src/main/java/de/maishai/ast/records/MainMethod.java b/src/main/java/de/maishai/ast/records/MainMethod.java index 3873d02..fdeedb1 100644 --- a/src/main/java/de/maishai/ast/records/MainMethod.java +++ b/src/main/java/de/maishai/ast/records/MainMethod.java @@ -1,11 +1,5 @@ package de.maishai.ast.records; - -import de.maishai.ast.Node; -import de.maishai.ast.ReturnType; - -import java.util.List; - public record MainMethod(Block block) implements Node { } diff --git a/src/main/java/de/maishai/ast/records/Method.java b/src/main/java/de/maishai/ast/records/Method.java index 742bb54..a11e9bc 100644 --- a/src/main/java/de/maishai/ast/records/Method.java +++ b/src/main/java/de/maishai/ast/records/Method.java @@ -2,7 +2,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Node; import de.maishai.ast.ReturnType; import java.util.List; diff --git a/src/main/java/de/maishai/ast/records/MethodCall.java b/src/main/java/de/maishai/ast/records/MethodCall.java index d5a5d31..755e224 100644 --- a/src/main/java/de/maishai/ast/records/MethodCall.java +++ b/src/main/java/de/maishai/ast/records/MethodCall.java @@ -2,9 +2,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - import java.util.List; public record MethodCall(Id id, List args) implements Expression, Statement { diff --git a/src/main/java/de/maishai/ast/records/New.java b/src/main/java/de/maishai/ast/records/New.java index 347fb7d..5a9ec9e 100644 --- a/src/main/java/de/maishai/ast/records/New.java +++ b/src/main/java/de/maishai/ast/records/New.java @@ -2,8 +2,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; import de.maishai.ast.Type; import java.util.List; diff --git a/src/main/java/de/maishai/ast/records/Node.java b/src/main/java/de/maishai/ast/records/Node.java new file mode 100644 index 0000000..e088d11 --- /dev/null +++ b/src/main/java/de/maishai/ast/records/Node.java @@ -0,0 +1,4 @@ +package de.maishai.ast.records; + +public sealed interface Node permits Expression, Statement, Block, Class, MainMethod, Method, Parameter, Program, Variable { +} diff --git a/src/main/java/de/maishai/ast/records/Parameter.java b/src/main/java/de/maishai/ast/records/Parameter.java index 508ef1e..5cbe5a1 100644 --- a/src/main/java/de/maishai/ast/records/Parameter.java +++ b/src/main/java/de/maishai/ast/records/Parameter.java @@ -1,7 +1,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Node; import de.maishai.ast.Type; public record Parameter(String name, Type type) implements Node { diff --git a/src/main/java/de/maishai/ast/records/Program.java b/src/main/java/de/maishai/ast/records/Program.java index ec638c0..588d4a4 100644 --- a/src/main/java/de/maishai/ast/records/Program.java +++ b/src/main/java/de/maishai/ast/records/Program.java @@ -1,8 +1,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Node; - import java.util.List; public record Program(List variables) implements Node { diff --git a/src/main/java/de/maishai/ast/records/Return.java b/src/main/java/de/maishai/ast/records/Return.java index 5e3e0bd..c330e72 100644 --- a/src/main/java/de/maishai/ast/records/Return.java +++ b/src/main/java/de/maishai/ast/records/Return.java @@ -1,8 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - public record Return(Expression ret) implements Statement { } diff --git a/src/main/java/de/maishai/ast/records/ReturnVoid.java b/src/main/java/de/maishai/ast/records/ReturnVoid.java index 7100004..b3d1f08 100644 --- a/src/main/java/de/maishai/ast/records/ReturnVoid.java +++ b/src/main/java/de/maishai/ast/records/ReturnVoid.java @@ -1,7 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Statement; - public record ReturnVoid() implements Statement { } diff --git a/src/main/java/de/maishai/ast/Statement.java b/src/main/java/de/maishai/ast/records/Statement.java similarity index 88% rename from src/main/java/de/maishai/ast/Statement.java rename to src/main/java/de/maishai/ast/records/Statement.java index 191bea6..9351511 100644 --- a/src/main/java/de/maishai/ast/Statement.java +++ b/src/main/java/de/maishai/ast/records/Statement.java @@ -1,4 +1,4 @@ -package de.maishai.ast; +package de.maishai.ast.records; import de.maishai.ast.records.Break; import de.maishai.ast.records.Continue; @@ -7,6 +7,7 @@ import de.maishai.ast.records.For; import de.maishai.ast.records.IfElse; import de.maishai.ast.records.MethodCall; import de.maishai.ast.records.New; +import de.maishai.ast.records.Node; import de.maishai.ast.records.Return; import de.maishai.ast.records.ReturnVoid; import de.maishai.ast.records.While; diff --git a/src/main/java/de/maishai/ast/records/Variable.java b/src/main/java/de/maishai/ast/records/Variable.java index adab4ea..58457ba 100644 --- a/src/main/java/de/maishai/ast/records/Variable.java +++ b/src/main/java/de/maishai/ast/records/Variable.java @@ -1,8 +1,6 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Node; import de.maishai.ast.Type; public record Variable(Id name, Type type, Expression expr) implements Node { diff --git a/src/main/java/de/maishai/ast/records/While.java b/src/main/java/de/maishai/ast/records/While.java index 47b7548..331a7f2 100644 --- a/src/main/java/de/maishai/ast/records/While.java +++ b/src/main/java/de/maishai/ast/records/While.java @@ -1,8 +1,5 @@ package de.maishai.ast.records; -import de.maishai.ast.Expression; -import de.maishai.ast.Statement; - public record While(Expression cond, Block block) implements Statement { }