in order to avoid package stuff, moved intefaces to records

This commit is contained in:
laurenz 2024-05-02 13:39:01 +02:00
parent e14af08678
commit 24c3a26136
31 changed files with 15 additions and 85 deletions

View File

@ -2,7 +2,7 @@ package de.maishai;
import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafBaseVisitor;
import de.maishai.antlr.DecafParser; 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.Block;
import de.maishai.ast.records.Variable; import de.maishai.ast.records.Variable;

View File

@ -2,7 +2,7 @@ package de.maishai;
import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafBaseVisitor;
import de.maishai.antlr.DecafParser; 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.Operator;
import de.maishai.ast.Type; import de.maishai.ast.Type;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;

View File

@ -2,8 +2,8 @@ package de.maishai;
import de.maishai.antlr.DecafBaseVisitor; import de.maishai.antlr.DecafBaseVisitor;
import de.maishai.antlr.DecafParser; import de.maishai.antlr.DecafParser;
import de.maishai.ast.Expression; import de.maishai.ast.records.Expression;
import de.maishai.ast.Statement; import de.maishai.ast.records.Statement;
import de.maishai.ast.Type; import de.maishai.ast.Type;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -1,8 +1,5 @@
package de.maishai.ast.records; 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 { public record Assignment(Id loc, Expression value) implements Statement, Expression {
} }

View File

@ -1,7 +1,6 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
public record Binary(Expression left, Operator op, Expression right) implements Expression { public record Binary(Expression left, Operator op, Expression right) implements Expression {

View File

@ -2,9 +2,6 @@ package de.maishai.ast.records;
import de.maishai.ast.Node;
import de.maishai.ast.Statement;
import java.util.List; import java.util.List;
public record Block(List<Variable> vars, List<Statement> stmts) implements Node { public record Block(List<Variable> vars, List<Statement> stmts) implements Node {

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
public record BoolConstant(Boolean value) implements Expression { public record BoolConstant(Boolean value) implements Expression {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Statement;
public record Break() implements Statement { public record Break() implements Statement {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
public record CharConstant(char value) implements Expression { public record CharConstant(char value) implements Expression {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Node;
import java.util.List; import java.util.List;
public record Class(Id id ,List<Variable> variables, List<Method> methods) implements Node { public record Class(Id id ,List<Variable> variables, List<Method> methods) implements Node {

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Statement;
public record Continue() implements Statement { public record Continue() implements Statement {
} }

View File

@ -1,8 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Statement;
public record DoWhile(Block block, Expression cond) implements Statement { public record DoWhile(Block block, Expression cond) implements Statement {
} }

View File

@ -0,0 +1,5 @@
package de.maishai.ast.records;
public sealed interface Expression extends Node permits Assignment, Binary, BoolConstant, CharConstant, Id, IntConstant, MethodCall, New {
}

View File

@ -1,8 +1,5 @@
package de.maishai.ast.records; 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 { public record For(Expression assign, Expression cond, Expression inc, Block block) implements Statement {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
public record Id(String name) implements Expression { public record Id(String name) implements Expression {
} }

View File

@ -1,6 +1,4 @@
package de.maishai.ast.records; 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 { public record IfElse(Expression cond, Block ifBlock, Block elseBlock) implements Statement {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
public record IntConstant(Integer value) implements Expression { public record IntConstant(Integer value) implements Expression {
} }

View File

@ -1,11 +1,5 @@
package de.maishai.ast.records; 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 { public record MainMethod(Block block) implements Node {
} }

View File

@ -2,7 +2,6 @@ package de.maishai.ast.records;
import de.maishai.ast.Node;
import de.maishai.ast.ReturnType; import de.maishai.ast.ReturnType;
import java.util.List; import java.util.List;

View File

@ -2,9 +2,6 @@ package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Statement;
import java.util.List; import java.util.List;
public record MethodCall(Id id, List<Expression> args) implements Expression, Statement { public record MethodCall(Id id, List<Expression> args) implements Expression, Statement {

View File

@ -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 de.maishai.ast.Type;
import java.util.List; import java.util.List;

View File

@ -0,0 +1,4 @@
package de.maishai.ast.records;
public sealed interface Node permits Expression, Statement, Block, Class, MainMethod, Method, Parameter, Program, Variable {
}

View File

@ -1,7 +1,6 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Node;
import de.maishai.ast.Type; import de.maishai.ast.Type;
public record Parameter(String name, Type type) implements Node { public record Parameter(String name, Type type) implements Node {

View File

@ -1,8 +1,6 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Node;
import java.util.List; import java.util.List;
public record Program(List<Class> variables) implements Node { public record Program(List<Class> variables) implements Node {

View File

@ -1,8 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Statement;
public record Return(Expression ret) implements Statement { public record Return(Expression ret) implements Statement {
} }

View File

@ -1,7 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Statement;
public record ReturnVoid() implements Statement { public record ReturnVoid() implements Statement {
} }

View File

@ -1,4 +1,4 @@
package de.maishai.ast; package de.maishai.ast.records;
import de.maishai.ast.records.Break; import de.maishai.ast.records.Break;
import de.maishai.ast.records.Continue; 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.IfElse;
import de.maishai.ast.records.MethodCall; import de.maishai.ast.records.MethodCall;
import de.maishai.ast.records.New; import de.maishai.ast.records.New;
import de.maishai.ast.records.Node;
import de.maishai.ast.records.Return; import de.maishai.ast.records.Return;
import de.maishai.ast.records.ReturnVoid; import de.maishai.ast.records.ReturnVoid;
import de.maishai.ast.records.While; import de.maishai.ast.records.While;

View File

@ -1,8 +1,6 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Node;
import de.maishai.ast.Type; import de.maishai.ast.Type;
public record Variable(Id name, Type type, Expression expr) implements Node { public record Variable(Id name, Type type, Expression expr) implements Node {

View File

@ -1,8 +1,5 @@
package de.maishai.ast.records; package de.maishai.ast.records;
import de.maishai.ast.Expression;
import de.maishai.ast.Statement;
public record While(Expression cond, Block block) implements Statement { public record While(Expression cond, Block block) implements Statement {
} }