changes to AST: id is gone, Declaration is one thing, renaming. only one Type

This commit is contained in:
laurenz 2024-05-08 14:27:51 +02:00
parent 0163f5c0b6
commit 0ac708c8ae
49 changed files with 135 additions and 224 deletions

View File

@ -36,7 +36,7 @@ expr : expr binaryOp expr #BinaryOperation
| unaryOp expr #UnaryOperation
| literal #Constant
| '(' expr ')' #Expression
| fieldId #Identifier
| fieldVarAccess #Identifier
| stmtexpr #StatementExpressionexpr
| NULL #Null
;
@ -44,9 +44,9 @@ expr : expr binaryOp expr #BinaryOperation
binaryOp : ADD | SUB | MUL | GT | LT | GE | LE | EQ | NE | AND | OR;
unaryOp : SUB | NOT;
fieldId : (THIS '.')? (recipient '.')* id;
fieldVarAccess : (THIS '.')? (recipient '.')* id;
assign : fieldId assignSign expr ;
assign : fieldVarAccess assignSign expr ;
methCall : (THIS '.')? (recipient '.')* methName;
recipient : methName | id;
methName : id '(' args? ')';

View File

@ -1,7 +1,6 @@
package de.maishai;
import de.maishai.antlr.DecafParser;
import de.maishai.ast.ReturnType;
import de.maishai.ast.Type;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
@ -13,9 +12,9 @@ public class ASTGenerator {
public static Class generateAST(DecafParser.ClassContext ctx) {
List<Field> fields = new ArrayList<>();
List<Declaration> declarations = new ArrayList<>();
if (ctx.field() != null) {
fields = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList();
declarations = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList();
}
MainMethod mainMethod = null;
if(ctx.mainmeth() != null){
@ -29,14 +28,12 @@ public class ASTGenerator {
if (ctx.meth() != null) {
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
}
Id classId = new Id(ctx.id().getText());
return new Class(classId, fields, meths, mainMethod, constructors);
return new Class(ctx.id().getText(), declarations, meths, mainMethod, constructors);
}
public static Field generateFieldVariable(DecafParser.FieldContext ctx) {
Id id = new Id(ctx.id().getText());
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
Type type = ASTGenerator.getType(ctx.type());
return new Field(id, type);
return new Declaration(ctx.id().getText(), type);
}
public static Parameter generateParameter(DecafParser.ParamContext ctx) {
@ -49,8 +46,7 @@ public class ASTGenerator {
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
}
Block block = new BlockGenerator().visit(ctx.block());
Id methId = new Id(ctx.id().getText());
return new Method(getReturnType(ctx.returntype()), methId, params, block);
return new Method(getType(ctx.returntype()), ctx.id().getText(), params, block);
}
public static Constructor generateConstructor(DecafParser.ConstructorContext ctx) {
@ -60,8 +56,7 @@ public class ASTGenerator {
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
}
Block block = new BlockGenerator().visit(ctx.block());
Id constructorId = new Id(ctx.id().getText());
return new Constructor(isPublic, constructorId, params, block);
return new Constructor(isPublic, ctx.id().getText(), params, block);
}
public static MainMethod generateMainMethod(DecafParser.MainmethContext ctx) {
@ -78,27 +73,18 @@ public class ASTGenerator {
return Type.CHAR;
if (ctx.id() != null) {
Type type = Type.OBJECT;
type.setObjectType(new Id(ctx.id().getText()));
type.setObjectType(ctx.id().getText());
return type;
}
throw new RuntimeException("No type found!");
}
public static ReturnType getReturnType(DecafParser.ReturntypeContext ctx) {
if (ctx.type().INT() != null)
return ReturnType.INT;
if (ctx.type().BOOL() != null)
return ReturnType.BOOL;
if (ctx.type().CHAR() != null)
return ReturnType.CHAR;
if (ctx.VOID() != null) {
return ReturnType.VOID;
public static Type getType(DecafParser.ReturntypeContext ctx) {
if (ctx.type() != null){
return getType(ctx.type());
}
if (ctx.type().id() != null){
ReturnType type = ReturnType.OBJECT;
type.setObjectType(new Id(ctx.type().id().getText()));
return type;
if (ctx.VOID() != null){
return Type.VOID;
}
throw new RuntimeException("No return type found!");
throw new RuntimeException("No type found!");
}
}

View File

@ -2,16 +2,16 @@ package de.maishai;
import de.maishai.antlr.DecafBaseVisitor;
import de.maishai.antlr.DecafParser;
import de.maishai.ast.records.Declaration;
import de.maishai.ast.records.Statement;
import de.maishai.ast.records.Block;
import de.maishai.ast.records.LocalVariable;
import java.util.List;
public class BlockGenerator extends DecafBaseVisitor<Block> {
@Override
public Block visitBlock(DecafParser.BlockContext ctx) {
List<LocalVariable> vars = ctx.localVar().stream().map(var -> new VariableGenerator().visit(var)).toList();
List<Declaration> vars = ctx.localVar().stream().map(var -> new VariableGenerator().visit(var)).toList();
List<Statement> statements = ctx.stmt().stream().map(stmt -> new StatementGenerator().visit(stmt)).toList();
return new Block(vars, statements);
}

View File

@ -47,9 +47,9 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
Expression recipient = null;
if (ctx.fieldId().recipient() != null) {
List<DecafParser.RecipientContext> recipientList = ctx.fieldId().recipient();
recipient = generateRecipient(recipientList, null);
recipient = generateRecursiveOwnerChain(recipientList, null);
}
return new FieldId(isField, recipient, new Id(ctx.getText()));
return new FieldVarAccess(isField, recipient, ctx.getText());
}
public static Expression generateConstant(DecafParser.LiteralContext ctx) {
@ -87,18 +87,17 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitMethodCall(DecafParser.MethodCallContext ctx) {
boolean isField = ctx.methCall().THIS() != null;
Expression recipient = null;
Expression recursiveOwnerChain = null;
if (ctx.methCall().recipient() != null) {
List<DecafParser.RecipientContext> recipientList = ctx.methCall().recipient();
recipient = generateRecipient(recipientList, null);
recursiveOwnerChain = generateRecursiveOwnerChain(recipientList, null);
}
Id id = new Id(ctx.methCall().methName().id().getText());
List<Expression> args = new ArrayList<>();
for (var expr : ctx.methCall().methName().args().expr()) {
Expression astExpr = expr.accept(this);
args.add(astExpr);
}
return new MethodCall(isField, recipient, id, args);
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
}
@Override
@ -112,18 +111,25 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
return new New(type, args);
}
public static Expression generateRecipient(List<DecafParser.RecipientContext> ctxList, Expression recipient) {
public static Expression generateRecursiveOwnerChain(List<DecafParser.RecipientContext> ctxList, FieldVarAccess recipient) {
if (ctxList.isEmpty()) {
return recipient;
}
DecafParser.RecipientContext ctx = ctxList.get(0);
ctxList.remove(0);
Id id = new Id(ctx.methName().id().getText());
List<Expression> args = new ArrayList<>();
for (var expr : ctx.methName().args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr);
if (ctx.id() != null) {
return new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.id().getText());
}
return new MethodCall(null, generateRecipient(ctxList, recipient), id, args);
if (ctx.methName() != null) {
List<Expression> args = new ArrayList<>();
for (var expr : ctx.methName().args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr);
}
return new MethodCall(new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.methName().id().getText()), args);
}
throw new RuntimeException();
}
}

View File

@ -53,7 +53,7 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
@Override
public Statement visitReturnVoid(DecafParser.ReturnVoidContext ctx) {
return new ReturnVoid();
return new Return(null);
}
@Override
@ -67,33 +67,32 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
}
private Assignment generateAssign(DecafParser.AssignContext ctx) {
FieldId fieldId = generateField(ctx.fieldId());
Expression expr = resolveFancyAssign(ctx.assignSign(), fieldId, new ExpressionGenerator().visit(ctx.expr()));
return new Assignment(fieldId, expr);
FieldVarAccess fieldVarAccess = generateField(ctx.fieldId());
Expression expr = resolveFancyAssign(ctx.assignSign(), fieldVarAccess, new ExpressionGenerator().visit(ctx.expr()));
return new Assignment(fieldVarAccess, expr);
}
private FieldId generateField(DecafParser.FieldIdContext fieldIdContext) {
return new FieldId(fieldIdContext.THIS() != null,
ExpressionGenerator.generateRecipient(fieldIdContext.recipient(),
null), new Id(fieldIdContext.id().getText()));
private FieldVarAccess generateField(DecafParser.FieldIdContext fieldIdContext) {
return new FieldVarAccess(fieldIdContext.THIS() != null,
ExpressionGenerator.generateRecursiveOwnerChain(fieldIdContext.recipient(),
null), fieldIdContext.id().getText());
}
//StatementExpression
@Override
public Statement visitMethodCall(DecafParser.MethodCallContext ctx) {
boolean isField = ctx.methCall().THIS() != null;
Expression recipient = null;
Expression recursiveOwnerChain = null;
if (ctx.methCall().recipient() != null) {
List<DecafParser.RecipientContext> recipientList = ctx.methCall().recipient();
recipient = ExpressionGenerator.generateRecipient(recipientList, null);
recursiveOwnerChain = ExpressionGenerator.generateRecursiveOwnerChain(recipientList, null);
}
Id id = new Id(ctx.methCall().methName().id().getText());
List<Expression> args = new ArrayList<>();
for (var expr : ctx.methCall().methName().args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr);
}
return new MethodCall(isField, recipient, id, args);
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
}
@Override
@ -107,15 +106,15 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
return new New(type, args);
}
public static Expression resolveFancyAssign(DecafParser.AssignSignContext ctx, FieldId fieldId, Expression expression) {
public static Expression resolveFancyAssign(DecafParser.AssignSignContext ctx, FieldVarAccess fieldVarAccess, Expression expression) {
if (ctx.ASSIGN() != null)
return expression;
if (ctx.ADD_ASSIGN() != null)
return new Binary(fieldId, Operator.ADD, expression);
return new Binary(fieldVarAccess, Operator.ADD, expression);
if (ctx.SUB_ASSIGN() != null)
return new Binary(fieldId, Operator.SUB, expression);
return new Binary(fieldVarAccess, Operator.SUB, expression);
if (ctx.MUL_ASSIGN() != null)
return new Binary(fieldId, Operator.MUL, expression);
return new Binary(fieldVarAccess, Operator.MUL, expression);
throw new RuntimeException("No assign sign found!");
}
}

View File

@ -4,15 +4,13 @@ package de.maishai;
import de.maishai.antlr.DecafBaseVisitor;
import de.maishai.antlr.DecafParser;
import de.maishai.ast.Type;
import de.maishai.ast.records.Id;
import de.maishai.ast.records.LocalVariable;
import de.maishai.ast.records.Declaration;
public class VariableGenerator extends DecafBaseVisitor<LocalVariable> {
public class VariableGenerator extends DecafBaseVisitor<Declaration> {
@Override
public LocalVariable visitLocalVar(DecafParser.LocalVarContext ctx) {
Id id = new Id(ctx.id().getText());
public Declaration visitLocalVar(DecafParser.LocalVarContext ctx) {
Type type = ASTGenerator.getType(ctx.type());
return new LocalVariable(id, type);
return new Declaration(ctx.id().getText(), type);
}
}

View File

@ -116,7 +116,7 @@ stmtexpr
expr
binaryOp
unaryOp
fieldId
fieldVarAccess
assign
methCall
recipient

View File

@ -35,7 +35,7 @@ public class DecafParser extends Parser {
return new String[] {
"class", "field", "localVar", "assignSign", "returntype", "type", "meth",
"mainmeth", "constructor", "params", "param", "block", "stmt", "stmtexpr",
"expr", "binaryOp", "unaryOp", "fieldId", "assign", "methCall", "recipient",
"expr", "binaryOp", "unaryOp", "fieldId", "assign", "methCall", "recursiveOwnerChain",
"methName", "args", "literal", "id"
};
}

View File

@ -1,8 +0,0 @@
package de.maishai.ast;
public enum AssignSign {
ASSIGN,
ADD_ASSIGN,
SUB_ASSIGN,
MUL_ASSIGN,
}

View File

@ -1,26 +0,0 @@
package de.maishai.ast;
import de.maishai.ast.records.Id;
public enum ReturnType {
INT,
BOOL,
CHAR,
VOID,
OBJECT;
Id objectType;
public Id getObjectType() {
if(this == ReturnType.OBJECT){
return objectType;
}
return null;
}
public void setObjectType(Id objectType) {
if(this == ReturnType.OBJECT){
this.objectType = objectType;
}
}
}

View File

@ -1,23 +1,22 @@
package de.maishai.ast;
import de.maishai.ast.records.Id;
public enum Type {
INT,
BOOL,
CHAR,
VOID,
OBJECT;
Id objectType;
String objectType;
public Id getObjectType() {
public String getObjectType() {
if(this == Type.OBJECT){
return objectType;
}
return null;
}
public void setObjectType(Id objectType) {
public void setObjectType(String objectType) {
if(this == Type.OBJECT){
this.objectType = objectType;
}

View File

@ -2,5 +2,5 @@ package de.maishai.ast.records;
public record Assignment(FieldId loc, Expression value) implements Statement {
public record Assignment(FieldVarAccess location, Expression value) implements Statement {
}

View File

@ -4,5 +4,5 @@ package de.maishai.ast.records;
import java.util.List;
public record Block(List<LocalVariable> vars, List<Statement> stmts) implements Node {
public record Block(List<Declaration> localVariables, List<Statement> stmts) implements Node {
}

View File

@ -2,5 +2,5 @@ package de.maishai.ast.records;
import java.util.List;
public record Class(Id id , List<Field> fields, List<Method> methods, MainMethod mainMethod, List<Constructor> constructors) implements Node {
public record Class(String classname , List<Declaration> fieldDeclarations, List<Method> methods, MainMethod mainMethod, List<Constructor> constructors) implements Node {
}

View File

@ -2,5 +2,5 @@ package de.maishai.ast.records;
import java.util.List;
public record Constructor(Boolean isPublic, Id id, List<Parameter> params, Block block) implements Node {
public record Constructor(Boolean isPublic, String className, List<Parameter> params, Block block) implements Node {
}

View File

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

View File

@ -1,5 +1,5 @@
package de.maishai.ast.records;
public sealed interface Expression extends Node permits Binary, BoolLiteral, CharLiteral, FieldId, Id, IntLiteral, MethodCall, New, Unary {
public sealed interface Expression extends Node permits Binary, BoolLiteral, CharLiteral, FieldVarAccess, IntLiteral, MethodCall, New, Unary {
}

View File

@ -1,6 +0,0 @@
package de.maishai.ast.records;
import de.maishai.ast.Type;
public record Field(Id name, Type type) implements Node {
}

View File

@ -1,4 +0,0 @@
package de.maishai.ast.records;
public record FieldId(Boolean field, Expression recipient, Id id) implements Expression {
}

View File

@ -0,0 +1,4 @@
package de.maishai.ast.records;
public record FieldVarAccess(Boolean field, Expression recursiveOwnerChain, String id) implements Expression {
}

View File

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

View File

@ -1,7 +0,0 @@
package de.maishai.ast.records;
import de.maishai.ast.Type;
public record LocalVariable(Id name, Type type) implements Node {
}

View File

@ -2,9 +2,9 @@ package de.maishai.ast.records;
import de.maishai.ast.ReturnType;
import de.maishai.ast.Type;
import java.util.List;
public record Method(ReturnType type, Id id, List<Parameter> params, Block block) implements Node {
public record Method(Type type, String methodName, List<Parameter> params, Block block) implements Node {
}

View File

@ -2,5 +2,5 @@ package de.maishai.ast.records;
import java.util.List;
public record MethodCall(Boolean field, Expression recipient, Id id, List<Expression> args) implements Expression, Statement {
public record MethodCall(FieldVarAccess recipient, List<Expression> args) implements Expression, Statement {
}

View File

@ -1,4 +1,4 @@
package de.maishai.ast.records;
public sealed interface Node permits Block, Class, Constructor, Expression, Field, LocalVariable, MainMethod, Method, Parameter, Statement {
public sealed interface Node permits Block, Class, Constructor, Expression, Declaration, MainMethod, Method, Parameter, Statement {
}

View File

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

View File

@ -1,4 +1,4 @@
package de.maishai.ast.records;
public sealed interface Statement extends Node permits Assignment, Break, DoWhile, For, IfElse, MethodCall, New, Return, ReturnVoid, While {
public sealed interface Statement extends Node permits Assignment, Break, DoWhile, For, IfElse, MethodCall, New, Return, While {
}

View File

@ -8,18 +8,7 @@ public class TypeMapper {
return Type.BOOL;
} else if (type == de.maishai.ast.Type.INT) {
return Type.INT;
}
throw new RuntimeException("Unknown type");
}
public static Type getReturnType(de.maishai.ast.ReturnType type) {
if (type == de.maishai.ast.ReturnType.CHAR) {
return Type.CHAR;
} else if (type == de.maishai.ast.ReturnType.BOOL) {
return Type.BOOL;
} else if (type == de.maishai.ast.ReturnType.INT) {
return Type.INT;
} else if (type == de.maishai.ast.ReturnType.VOID) {
} else if (type == de.maishai.ast.Type.VOID){
return Type.VOID;
}
throw new RuntimeException("Unknown type");

View File

@ -1,6 +1,5 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.AssignSign;
import de.maishai.ast.records.Assignment;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.TypedExpression;
@ -36,7 +35,7 @@ public class TypedAssignment implements TypedStatement {
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
Assignment untyped = (Assignment) unTypedAST;
TypedAssignment typedAssignment = new TypedAssignment();
typedAssignment.setVarName(untyped.loc().id().name());
typedAssignment.setVarName(untyped.location().id());
typedAssignment.setValue((TypedExpression) value.convertToTypedAST(localVar, classes, untyped.value()));
return typedAssignment;
}

View File

@ -1,7 +1,7 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Block;
import de.maishai.ast.records.LocalVariable;
import de.maishai.ast.records.Declaration;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.TypedStatement;
@ -36,7 +36,7 @@ public class TypedBlock implements TypedNode {
Block untyped = (Block) unTypedAST;
TypedBlock typedBlock = new TypedBlock();
for (LocalVariable var : untyped.vars()) {
for (Declaration var : untyped.localVariables()) {
TypedLocalVariable typedVar = new TypedLocalVariable();
typedVar.convertToTypedAST(localVar, classes, var);
typedBlock.getVars().add(typedVar);

View File

@ -47,7 +47,7 @@ public class TypedConstructor implements TypedNode {
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
Constructor untyped = (Constructor) unTypedAST;
TypedConstructor typedConstructor = new TypedConstructor();
typedConstructor.setName(untyped.id().name());
typedConstructor.setName(untyped.className());
if (untyped.params().isEmpty()) {
typedConstructor.setTypedParameters(null);

View File

@ -1,6 +1,6 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Field;
import de.maishai.ast.records.Declaration;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypeMapper;
@ -30,10 +30,10 @@ public class TypedField implements TypedNode {
@Override
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
Field untypedField = (Field) unTypedAST;
Declaration untypedDeclaration = (Declaration) unTypedAST;
TypedField typedField = new TypedField();
typedField.setVarName(untypedField.name().name());
typedField.setType(TypeMapper.getType(untypedField.type()));
typedField.setVarName(untypedDeclaration.name());
typedField.setType(TypeMapper.getType(untypedDeclaration.type()));
return typedField;
}

View File

@ -1,6 +1,6 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.records.FieldId;
import de.maishai.ast.records.FieldVarAccess;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type;
@ -14,7 +14,7 @@ public class TypedFieldId implements TypedExpression {
private String name;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
//TODO: Implement typeCheck for FieldId
//TODO: Implement typeCheck for FieldVarAccess
if(field){
return null;
}else{
@ -24,11 +24,11 @@ public class TypedFieldId implements TypedExpression {
@Override
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
FieldId untypedFieldId = (FieldId) unTypedAST;
FieldVarAccess untypedFieldVarAccess = (FieldVarAccess) unTypedAST;
TypedFieldId typedFieldId = new TypedFieldId();
typedFieldId.setField(untypedFieldId.field());
typedFieldId.setRecipient((TypedExpression) recipient.convertToTypedAST(localVar, classes, untypedFieldId.recipient()));
typedFieldId.setName(untypedFieldId.id().name());
typedFieldId.setField(untypedFieldVarAccess.field());
typedFieldId.setRecipient((TypedExpression) recipient.convertToTypedAST(localVar, classes, untypedFieldVarAccess.recursiveOwnerChain()));
typedFieldId.setName(untypedFieldVarAccess.id());
return typedFieldId;
}

View File

@ -1,6 +1,7 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.records.LocalVariable;
import com.sun.jdi.LocalVariable;
import de.maishai.ast.records.Declaration;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type;
@ -29,10 +30,10 @@ public final class TypedLocalVariable implements TypedNode {
@Override
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
LocalVariable untypedLocalVariable = (LocalVariable) unTypedAST;
Declaration untypedLocalVariable = (Declaration) unTypedAST;
TypedLocalVariable typedLocalVariable = new TypedLocalVariable();
typedLocalVariable.setName(untypedLocalVariable.name().name());
typedLocalVariable.setName(untypedLocalVariable.name());
typedLocalVariable.setType(TypeMapper.getType(untypedLocalVariable.type()));
return typedLocalVariable;

View File

@ -36,8 +36,8 @@ public class TypedMethod implements TypedNode {
Method untypedMethod = (Method) unTypedAST;
TypedMethod typedMethod = new TypedMethod();
typedMethod.setName(untypedMethod.id().name());
typedMethod.setReturnType(TypeMapper.getReturnType(untypedMethod.type()));
typedMethod.setName(untypedMethod.methodName());
typedMethod.setReturnType(TypeMapper.getType(untypedMethod.type()));
if(untypedMethod.params().isEmpty()){
//TODO: Implement this

View File

@ -20,7 +20,7 @@ public class TypedReturnVoid implements TypedStatement {
@Override
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
Method untyped = (Method) unTypedAST;
if(untyped.type() != de.maishai.ast.ReturnType.VOID){
if(untyped.type() != de.maishai.ast.Type.VOID){
throw new RuntimeException("Return type is not void");
}
return new TypedReturnVoid();

View File

@ -20,8 +20,8 @@ import java.util.List;
public class AbstractSyntax_ClassWithConstructor {
public static Class get() {
List<Field> fields = List.of(
new Field(
List<Declaration> declarations = List.of(
new Declaration(
new Id("x"),
Type.INT
)
@ -30,7 +30,7 @@ public class AbstractSyntax_ClassWithConstructor {
List<Constructor> constructors = getConstructors();
return new Class(
new Id("ClassWithConstructor"),
fields,
declarations,
methods,
null,
constructors

View File

@ -19,7 +19,6 @@
import de.maishai.ast.Operator;
import de.maishai.ast.ReturnType;
import de.maishai.ast.Type;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
@ -28,8 +27,8 @@ import java.util.List;
public class AbstractSyntax_ClassWithConstructorAndMethodCall {
public static Class get() {
List<Field> fieldList = List.of(
new Field(
List<Declaration> declarationList = List.of(
new Declaration(
new Id("x"),
Type.INT
)
@ -38,7 +37,7 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall {
List<Constructor> constructorList = getConstructors();
return new Class(
new Id("ClassWithConstructorAndMethodCall"),
fieldList,
declarationList,
methodList,
null,
constructorList

View File

@ -22,8 +22,8 @@ import java.util.List;
public class AbstractSyntax_ClassWithConstructorWithParameters {
public static Class get() {
List<Field> fields = List.of(
new Field(
List<Declaration> declarations = List.of(
new Declaration(
new Id("x"),
Type.INT
)
@ -31,7 +31,7 @@ public class AbstractSyntax_ClassWithConstructorWithParameters {
List<Constructor> constructors = getConstructors();
return new Class(
new Id("ClassWithConstructorWithParameters"),
fields,
declarations,
List.of(),
null,
constructors

View File

@ -5,16 +5,15 @@
import de.maishai.ast.records.Class;
import de.maishai.ast.Type;
import de.maishai.ast.records.Constructor;
import de.maishai.ast.records.Field;
import de.maishai.ast.records.Id;
import de.maishai.ast.records.Declaration;
import de.maishai.ast.records.Method;
import java.util.List;
public class AbstractSyntax_ClassWithField {
public static Class get() {
List<Field> fields = List.of(
new Field(
List<Declaration> declarations = List.of(
new Declaration(
new Id("x"),
Type.INT
)
@ -23,7 +22,7 @@ public class AbstractSyntax_ClassWithField {
List<Constructor> constructors = List.of();
return new Class(
new Id("ClassWithAssignment"),
fields,
declarations,
methods,
null,
constructors

View File

@ -4,7 +4,6 @@
// }
//}
import de.maishai.ast.ReturnType;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;

View File

@ -18,8 +18,8 @@ import java.util.List;
class AbstractSyntax_ClassWithMethodAndField {
public static Class get() {
List<Field> fields = List.of(
new Field(
List<Declaration> declarations = List.of(
new Declaration(
new Id("c"),
Type.CHAR
)
@ -28,7 +28,7 @@ class AbstractSyntax_ClassWithMethodAndField {
List<Constructor> constructors = getConstructors();
return new Class(
new Id("ClassWithMethodAndField"),
fields,
declarations,
methods,
null,
constructors

View File

@ -28,8 +28,8 @@ public class AbstractSyntax_ClassWithMoreComplexMethodAndMain {
public static Class get() {
Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
List<Field> fields = List.of(
new Field(
List<Declaration> declarations = List.of(
new Declaration(
new Id("instance"),
TypeClassWithMoreComplexMethodAndMain
)
@ -38,7 +38,7 @@ public class AbstractSyntax_ClassWithMoreComplexMethodAndMain {
List<Constructor> constructors = List.of();
return new Class(
new Id("ClassWithMoreComplexMethodAndMain"),
fields,
declarations,
methods,
getMainMethod(),
constructors

View File

@ -2,7 +2,6 @@
//}
import de.maishai.ast.records.Class;
import de.maishai.ast.records.Id;
import java.util.List;

View File

@ -12,7 +12,6 @@
// }
//}
import de.maishai.ast.AssignSign;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;

View File

@ -18,19 +18,10 @@
//}
import de.maishai.ast.AssignSign;
import de.maishai.ast.Operator;
import de.maishai.ast.ReturnType;
import de.maishai.ast.Type;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import java.util.List;
public class TypedAbstractSyntax_ClassWithConstructorAndMethodCall {
// public static Class get() {
// List<Field> fieldList = List.of(
// new Field(
// List<Declaration> fieldList = List.of(
// new Declaration(
// new Id("x"),
// Type.INT
// )

View File

@ -13,7 +13,6 @@
// }
// }
//}
import de.maishai.ast.AssignSign;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.Type;
@ -23,8 +22,8 @@ import java.util.List;
public class TypedAbstractSyntax_ClassWithConstructorWithParameters {
// public static Class get() {
// List<Field> fields = List.of(
// new Field(
// List<Declaration> fieldDeclarations = List.of(
// new Declaration(
// new Id("x"),
// Type.INT
// )
@ -33,7 +32,7 @@ public class TypedAbstractSyntax_ClassWithConstructorWithParameters {
// return new Class(
// true,
// new Id("ClassWithConstructorWithParameters"),
// fields,
// fieldDeclarations,
// List.of(),
// null,
// constructors

View File

@ -18,8 +18,8 @@ import java.util.List;
class TypedAbstractSyntax_ClassWithMethodAndField {
// public static Class get() {
// List<Field> fields = List.of(
// new Field(
// List<Declaration> fieldDeclarations = List.of(
// new Declaration(
// new Id("c"),
// Type.CHAR
// )
@ -29,7 +29,7 @@ class TypedAbstractSyntax_ClassWithMethodAndField {
// return new Class(
// false,
// new Id("ClassWithMethodAndField"),
// fields,
// fieldDeclarations,
// methods,
// null,
// constructors

View File

@ -28,8 +28,8 @@ public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain {
// public static Class get() {
// Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
// TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
// List<Field> fields = List.of(
// new Field(
// List<Declaration> fieldDeclarations = List.of(
// new Declaration(
// new Id("instance"),
// TypeClassWithMoreComplexMethodAndMain
// )
@ -39,7 +39,7 @@ public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain {
// return new Class(
// true,
// new Id("ClassWithMoreComplexMethodAndMain"),
// fields,
// fieldDeclarations,
// methods,
// getMainMethod(),
// constructors