mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:08:03 +00:00
changes to AST: id is gone, Declaration is one thing, renaming. only one Type
This commit is contained in:
parent
0163f5c0b6
commit
0ac708c8ae
@ -36,7 +36,7 @@ expr : expr binaryOp expr #BinaryOperation
|
|||||||
| unaryOp expr #UnaryOperation
|
| unaryOp expr #UnaryOperation
|
||||||
| literal #Constant
|
| literal #Constant
|
||||||
| '(' expr ')' #Expression
|
| '(' expr ')' #Expression
|
||||||
| fieldId #Identifier
|
| fieldVarAccess #Identifier
|
||||||
| stmtexpr #StatementExpressionexpr
|
| stmtexpr #StatementExpressionexpr
|
||||||
| NULL #Null
|
| NULL #Null
|
||||||
;
|
;
|
||||||
@ -44,9 +44,9 @@ expr : expr binaryOp expr #BinaryOperation
|
|||||||
binaryOp : ADD | SUB | MUL | GT | LT | GE | LE | EQ | NE | AND | OR;
|
binaryOp : ADD | SUB | MUL | GT | LT | GE | LE | EQ | NE | AND | OR;
|
||||||
unaryOp : SUB | NOT;
|
unaryOp : SUB | NOT;
|
||||||
|
|
||||||
fieldId : (THIS '.')? (recipient '.')* id;
|
fieldVarAccess : (THIS '.')? (recipient '.')* id;
|
||||||
|
|
||||||
assign : fieldId assignSign expr ;
|
assign : fieldVarAccess assignSign expr ;
|
||||||
methCall : (THIS '.')? (recipient '.')* methName;
|
methCall : (THIS '.')? (recipient '.')* methName;
|
||||||
recipient : methName | id;
|
recipient : methName | id;
|
||||||
methName : id '(' args? ')';
|
methName : id '(' args? ')';
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package de.maishai;
|
package de.maishai;
|
||||||
|
|
||||||
import de.maishai.antlr.DecafParser;
|
import de.maishai.antlr.DecafParser;
|
||||||
import de.maishai.ast.ReturnType;
|
|
||||||
import de.maishai.ast.Type;
|
import de.maishai.ast.Type;
|
||||||
import de.maishai.ast.records.*;
|
import de.maishai.ast.records.*;
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
@ -13,9 +12,9 @@ public class ASTGenerator {
|
|||||||
|
|
||||||
|
|
||||||
public static Class generateAST(DecafParser.ClassContext ctx) {
|
public static Class generateAST(DecafParser.ClassContext ctx) {
|
||||||
List<Field> fields = new ArrayList<>();
|
List<Declaration> declarations = new ArrayList<>();
|
||||||
if (ctx.field() != null) {
|
if (ctx.field() != null) {
|
||||||
fields = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList();
|
declarations = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList();
|
||||||
}
|
}
|
||||||
MainMethod mainMethod = null;
|
MainMethod mainMethod = null;
|
||||||
if(ctx.mainmeth() != null){
|
if(ctx.mainmeth() != null){
|
||||||
@ -29,14 +28,12 @@ public class ASTGenerator {
|
|||||||
if (ctx.meth() != null) {
|
if (ctx.meth() != null) {
|
||||||
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
||||||
}
|
}
|
||||||
Id classId = new Id(ctx.id().getText());
|
return new Class(ctx.id().getText(), declarations, meths, mainMethod, constructors);
|
||||||
return new Class(classId, fields, meths, mainMethod, constructors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field generateFieldVariable(DecafParser.FieldContext ctx) {
|
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
|
||||||
Id id = new Id(ctx.id().getText());
|
|
||||||
Type type = ASTGenerator.getType(ctx.type());
|
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) {
|
public static Parameter generateParameter(DecafParser.ParamContext ctx) {
|
||||||
@ -49,8 +46,7 @@ public class ASTGenerator {
|
|||||||
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
||||||
}
|
}
|
||||||
Block block = new BlockGenerator().visit(ctx.block());
|
Block block = new BlockGenerator().visit(ctx.block());
|
||||||
Id methId = new Id(ctx.id().getText());
|
return new Method(getType(ctx.returntype()), ctx.id().getText(), params, block);
|
||||||
return new Method(getReturnType(ctx.returntype()), methId, params, block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Constructor generateConstructor(DecafParser.ConstructorContext ctx) {
|
public static Constructor generateConstructor(DecafParser.ConstructorContext ctx) {
|
||||||
@ -60,8 +56,7 @@ public class ASTGenerator {
|
|||||||
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
||||||
}
|
}
|
||||||
Block block = new BlockGenerator().visit(ctx.block());
|
Block block = new BlockGenerator().visit(ctx.block());
|
||||||
Id constructorId = new Id(ctx.id().getText());
|
return new Constructor(isPublic, ctx.id().getText(), params, block);
|
||||||
return new Constructor(isPublic, constructorId, params, block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainMethod generateMainMethod(DecafParser.MainmethContext ctx) {
|
public static MainMethod generateMainMethod(DecafParser.MainmethContext ctx) {
|
||||||
@ -78,27 +73,18 @@ public class ASTGenerator {
|
|||||||
return Type.CHAR;
|
return Type.CHAR;
|
||||||
if (ctx.id() != null) {
|
if (ctx.id() != null) {
|
||||||
Type type = Type.OBJECT;
|
Type type = Type.OBJECT;
|
||||||
type.setObjectType(new Id(ctx.id().getText()));
|
type.setObjectType(ctx.id().getText());
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("No type found!");
|
throw new RuntimeException("No type found!");
|
||||||
}
|
}
|
||||||
|
public static Type getType(DecafParser.ReturntypeContext ctx) {
|
||||||
public static ReturnType getReturnType(DecafParser.ReturntypeContext ctx) {
|
if (ctx.type() != null){
|
||||||
if (ctx.type().INT() != null)
|
return getType(ctx.type());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
if (ctx.type().id() != null){
|
if (ctx.VOID() != null){
|
||||||
ReturnType type = ReturnType.OBJECT;
|
return Type.VOID;
|
||||||
type.setObjectType(new Id(ctx.type().id().getText()));
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
throw new RuntimeException("No return type found!");
|
throw new RuntimeException("No type found!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,16 @@ 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.records.Declaration;
|
||||||
import de.maishai.ast.records.Statement;
|
import de.maishai.ast.records.Statement;
|
||||||
import de.maishai.ast.records.Block;
|
import de.maishai.ast.records.Block;
|
||||||
import de.maishai.ast.records.LocalVariable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockGenerator extends DecafBaseVisitor<Block> {
|
public class BlockGenerator extends DecafBaseVisitor<Block> {
|
||||||
@Override
|
@Override
|
||||||
public Block visitBlock(DecafParser.BlockContext ctx) {
|
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();
|
List<Statement> statements = ctx.stmt().stream().map(stmt -> new StatementGenerator().visit(stmt)).toList();
|
||||||
return new Block(vars, statements);
|
return new Block(vars, statements);
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
Expression recipient = null;
|
Expression recipient = null;
|
||||||
if (ctx.fieldId().recipient() != null) {
|
if (ctx.fieldId().recipient() != null) {
|
||||||
List<DecafParser.RecipientContext> recipientList = ctx.fieldId().recipient();
|
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) {
|
public static Expression generateConstant(DecafParser.LiteralContext ctx) {
|
||||||
@ -87,18 +87,17 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
@Override
|
@Override
|
||||||
public Expression visitMethodCall(DecafParser.MethodCallContext ctx) {
|
public Expression visitMethodCall(DecafParser.MethodCallContext ctx) {
|
||||||
boolean isField = ctx.methCall().THIS() != null;
|
boolean isField = ctx.methCall().THIS() != null;
|
||||||
Expression recipient = null;
|
Expression recursiveOwnerChain = null;
|
||||||
if (ctx.methCall().recipient() != null) {
|
if (ctx.methCall().recipient() != null) {
|
||||||
List<DecafParser.RecipientContext> recipientList = ctx.methCall().recipient();
|
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<>();
|
List<Expression> args = new ArrayList<>();
|
||||||
for (var expr : ctx.methCall().methName().args().expr()) {
|
for (var expr : ctx.methCall().methName().args().expr()) {
|
||||||
Expression astExpr = expr.accept(this);
|
Expression astExpr = expr.accept(this);
|
||||||
args.add(astExpr);
|
args.add(astExpr);
|
||||||
}
|
}
|
||||||
return new MethodCall(isField, recipient, id, args);
|
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,18 +111,25 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
return new New(type, args);
|
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()) {
|
if (ctxList.isEmpty()) {
|
||||||
return recipient;
|
return recipient;
|
||||||
}
|
}
|
||||||
DecafParser.RecipientContext ctx = ctxList.get(0);
|
DecafParser.RecipientContext ctx = ctxList.get(0);
|
||||||
ctxList.remove(0);
|
ctxList.remove(0);
|
||||||
Id id = new Id(ctx.methName().id().getText());
|
if (ctx.id() != null) {
|
||||||
List<Expression> args = new ArrayList<>();
|
return new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.id().getText());
|
||||||
for (var expr : ctx.methName().args().expr()) {
|
|
||||||
Expression astExpr = expr.accept(new ExpressionGenerator());
|
|
||||||
args.add(astExpr);
|
|
||||||
}
|
}
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement visitReturnVoid(DecafParser.ReturnVoidContext ctx) {
|
public Statement visitReturnVoid(DecafParser.ReturnVoidContext ctx) {
|
||||||
return new ReturnVoid();
|
return new Return(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,33 +67,32 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Assignment generateAssign(DecafParser.AssignContext ctx) {
|
private Assignment generateAssign(DecafParser.AssignContext ctx) {
|
||||||
FieldId fieldId = generateField(ctx.fieldId());
|
FieldVarAccess fieldVarAccess = generateField(ctx.fieldId());
|
||||||
Expression expr = resolveFancyAssign(ctx.assignSign(), fieldId, new ExpressionGenerator().visit(ctx.expr()));
|
Expression expr = resolveFancyAssign(ctx.assignSign(), fieldVarAccess, new ExpressionGenerator().visit(ctx.expr()));
|
||||||
return new Assignment(fieldId, expr);
|
return new Assignment(fieldVarAccess, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldId generateField(DecafParser.FieldIdContext fieldIdContext) {
|
private FieldVarAccess generateField(DecafParser.FieldIdContext fieldIdContext) {
|
||||||
return new FieldId(fieldIdContext.THIS() != null,
|
return new FieldVarAccess(fieldIdContext.THIS() != null,
|
||||||
ExpressionGenerator.generateRecipient(fieldIdContext.recipient(),
|
ExpressionGenerator.generateRecursiveOwnerChain(fieldIdContext.recipient(),
|
||||||
null), new Id(fieldIdContext.id().getText()));
|
null), fieldIdContext.id().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
//StatementExpression
|
//StatementExpression
|
||||||
@Override
|
@Override
|
||||||
public Statement visitMethodCall(DecafParser.MethodCallContext ctx) {
|
public Statement visitMethodCall(DecafParser.MethodCallContext ctx) {
|
||||||
boolean isField = ctx.methCall().THIS() != null;
|
boolean isField = ctx.methCall().THIS() != null;
|
||||||
Expression recipient = null;
|
Expression recursiveOwnerChain = null;
|
||||||
if (ctx.methCall().recipient() != null) {
|
if (ctx.methCall().recipient() != null) {
|
||||||
List<DecafParser.RecipientContext> recipientList = ctx.methCall().recipient();
|
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<>();
|
List<Expression> args = new ArrayList<>();
|
||||||
for (var expr : ctx.methCall().methName().args().expr()) {
|
for (var expr : ctx.methCall().methName().args().expr()) {
|
||||||
Expression astExpr = expr.accept(new ExpressionGenerator());
|
Expression astExpr = expr.accept(new ExpressionGenerator());
|
||||||
args.add(astExpr);
|
args.add(astExpr);
|
||||||
}
|
}
|
||||||
return new MethodCall(isField, recipient, id, args);
|
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -107,15 +106,15 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
|||||||
return new New(type, args);
|
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)
|
if (ctx.ASSIGN() != null)
|
||||||
return expression;
|
return expression;
|
||||||
if (ctx.ADD_ASSIGN() != null)
|
if (ctx.ADD_ASSIGN() != null)
|
||||||
return new Binary(fieldId, Operator.ADD, expression);
|
return new Binary(fieldVarAccess, Operator.ADD, expression);
|
||||||
if (ctx.SUB_ASSIGN() != null)
|
if (ctx.SUB_ASSIGN() != null)
|
||||||
return new Binary(fieldId, Operator.SUB, expression);
|
return new Binary(fieldVarAccess, Operator.SUB, expression);
|
||||||
if (ctx.MUL_ASSIGN() != null)
|
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!");
|
throw new RuntimeException("No assign sign found!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,13 @@ 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.Type;
|
import de.maishai.ast.Type;
|
||||||
import de.maishai.ast.records.Id;
|
import de.maishai.ast.records.Declaration;
|
||||||
import de.maishai.ast.records.LocalVariable;
|
|
||||||
|
|
||||||
public class VariableGenerator extends DecafBaseVisitor<LocalVariable> {
|
public class VariableGenerator extends DecafBaseVisitor<Declaration> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalVariable visitLocalVar(DecafParser.LocalVarContext ctx) {
|
public Declaration visitLocalVar(DecafParser.LocalVarContext ctx) {
|
||||||
Id id = new Id(ctx.id().getText());
|
|
||||||
Type type = ASTGenerator.getType(ctx.type());
|
Type type = ASTGenerator.getType(ctx.type());
|
||||||
return new LocalVariable(id, type);
|
return new Declaration(ctx.id().getText(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ stmtexpr
|
|||||||
expr
|
expr
|
||||||
binaryOp
|
binaryOp
|
||||||
unaryOp
|
unaryOp
|
||||||
fieldId
|
fieldVarAccess
|
||||||
assign
|
assign
|
||||||
methCall
|
methCall
|
||||||
recipient
|
recipient
|
||||||
|
@ -35,7 +35,7 @@ public class DecafParser extends Parser {
|
|||||||
return new String[] {
|
return new String[] {
|
||||||
"class", "field", "localVar", "assignSign", "returntype", "type", "meth",
|
"class", "field", "localVar", "assignSign", "returntype", "type", "meth",
|
||||||
"mainmeth", "constructor", "params", "param", "block", "stmt", "stmtexpr",
|
"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"
|
"methName", "args", "literal", "id"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package de.maishai.ast;
|
|
||||||
|
|
||||||
public enum AssignSign {
|
|
||||||
ASSIGN,
|
|
||||||
ADD_ASSIGN,
|
|
||||||
SUB_ASSIGN,
|
|
||||||
MUL_ASSIGN,
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +1,22 @@
|
|||||||
package de.maishai.ast;
|
package de.maishai.ast;
|
||||||
|
|
||||||
import de.maishai.ast.records.Id;
|
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
INT,
|
INT,
|
||||||
BOOL,
|
BOOL,
|
||||||
CHAR,
|
CHAR,
|
||||||
|
VOID,
|
||||||
OBJECT;
|
OBJECT;
|
||||||
|
|
||||||
Id objectType;
|
String objectType;
|
||||||
|
|
||||||
public Id getObjectType() {
|
public String getObjectType() {
|
||||||
if(this == Type.OBJECT){
|
if(this == Type.OBJECT){
|
||||||
return objectType;
|
return objectType;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObjectType(Id objectType) {
|
public void setObjectType(String objectType) {
|
||||||
if(this == Type.OBJECT){
|
if(this == Type.OBJECT){
|
||||||
this.objectType = objectType;
|
this.objectType = objectType;
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,5 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
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 {
|
||||||
}
|
}
|
||||||
|
6
src/main/java/de/maishai/ast/records/Declaration.java
Normal file
6
src/main/java/de/maishai/ast/records/Declaration.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
import de.maishai.ast.Type;
|
||||||
|
|
||||||
|
public record Declaration(String name, Type type) implements Node {
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
package de.maishai.ast.records;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
import de.maishai.ast.Type;
|
|
||||||
|
|
||||||
public record Field(Id name, Type type) implements Node {
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
public record FieldId(Boolean field, Expression recipient, Id id) implements Expression {
|
|
||||||
}
|
|
4
src/main/java/de/maishai/ast/records/FieldVarAccess.java
Normal file
4
src/main/java/de/maishai/ast/records/FieldVarAccess.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
public record FieldVarAccess(Boolean field, Expression recursiveOwnerChain, String id) implements Expression {
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
public record Id(String name) implements Expression {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
import de.maishai.ast.Type;
|
|
||||||
|
|
||||||
public record LocalVariable(Id name, Type type) implements Node {
|
|
||||||
}
|
|
@ -2,9 +2,9 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
import de.maishai.ast.ReturnType;
|
import de.maishai.ast.Type;
|
||||||
|
|
||||||
import java.util.List;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package de.maishai.ast.records;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
public record ReturnVoid() implements Statement {
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.maishai.ast.records;
|
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 {
|
||||||
}
|
}
|
||||||
|
@ -8,18 +8,7 @@ public class TypeMapper {
|
|||||||
return Type.BOOL;
|
return Type.BOOL;
|
||||||
} else if (type == de.maishai.ast.Type.INT) {
|
} else if (type == de.maishai.ast.Type.INT) {
|
||||||
return Type.INT;
|
return Type.INT;
|
||||||
}
|
} else if (type == de.maishai.ast.Type.VOID){
|
||||||
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) {
|
|
||||||
return Type.VOID;
|
return Type.VOID;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Unknown type");
|
throw new RuntimeException("Unknown type");
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
package de.maishai.typedast.typedclass;
|
||||||
|
|
||||||
import de.maishai.ast.AssignSign;
|
|
||||||
import de.maishai.ast.records.Assignment;
|
import de.maishai.ast.records.Assignment;
|
||||||
import de.maishai.typedast.MethodContext;
|
import de.maishai.typedast.MethodContext;
|
||||||
import de.maishai.typedast.TypedExpression;
|
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) {
|
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||||
Assignment untyped = (Assignment) unTypedAST;
|
Assignment untyped = (Assignment) unTypedAST;
|
||||||
TypedAssignment typedAssignment = new TypedAssignment();
|
TypedAssignment typedAssignment = new TypedAssignment();
|
||||||
typedAssignment.setVarName(untyped.loc().id().name());
|
typedAssignment.setVarName(untyped.location().id());
|
||||||
typedAssignment.setValue((TypedExpression) value.convertToTypedAST(localVar, classes, untyped.value()));
|
typedAssignment.setValue((TypedExpression) value.convertToTypedAST(localVar, classes, untyped.value()));
|
||||||
return typedAssignment;
|
return typedAssignment;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
package de.maishai.typedast.typedclass;
|
||||||
|
|
||||||
import de.maishai.ast.records.Block;
|
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.MethodContext;
|
||||||
import de.maishai.typedast.TypedNode;
|
import de.maishai.typedast.TypedNode;
|
||||||
import de.maishai.typedast.TypedStatement;
|
import de.maishai.typedast.TypedStatement;
|
||||||
@ -36,7 +36,7 @@ public class TypedBlock implements TypedNode {
|
|||||||
Block untyped = (Block) unTypedAST;
|
Block untyped = (Block) unTypedAST;
|
||||||
TypedBlock typedBlock = new TypedBlock();
|
TypedBlock typedBlock = new TypedBlock();
|
||||||
|
|
||||||
for (LocalVariable var : untyped.vars()) {
|
for (Declaration var : untyped.localVariables()) {
|
||||||
TypedLocalVariable typedVar = new TypedLocalVariable();
|
TypedLocalVariable typedVar = new TypedLocalVariable();
|
||||||
typedVar.convertToTypedAST(localVar, classes, var);
|
typedVar.convertToTypedAST(localVar, classes, var);
|
||||||
typedBlock.getVars().add(typedVar);
|
typedBlock.getVars().add(typedVar);
|
||||||
|
@ -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) {
|
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||||
Constructor untyped = (Constructor) unTypedAST;
|
Constructor untyped = (Constructor) unTypedAST;
|
||||||
TypedConstructor typedConstructor = new TypedConstructor();
|
TypedConstructor typedConstructor = new TypedConstructor();
|
||||||
typedConstructor.setName(untyped.id().name());
|
typedConstructor.setName(untyped.className());
|
||||||
|
|
||||||
if (untyped.params().isEmpty()) {
|
if (untyped.params().isEmpty()) {
|
||||||
typedConstructor.setTypedParameters(null);
|
typedConstructor.setTypedParameters(null);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
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.TypedNode;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
import de.maishai.typedast.TypeMapper;
|
import de.maishai.typedast.TypeMapper;
|
||||||
@ -30,10 +30,10 @@ public class TypedField implements TypedNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
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 typedField = new TypedField();
|
||||||
typedField.setVarName(untypedField.name().name());
|
typedField.setVarName(untypedDeclaration.name());
|
||||||
typedField.setType(TypeMapper.getType(untypedField.type()));
|
typedField.setType(TypeMapper.getType(untypedDeclaration.type()));
|
||||||
|
|
||||||
return typedField;
|
return typedField;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
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.TypedExpression;
|
||||||
import de.maishai.typedast.TypedNode;
|
import de.maishai.typedast.TypedNode;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
@ -14,7 +14,7 @@ public class TypedFieldId implements TypedExpression {
|
|||||||
private String name;
|
private String name;
|
||||||
@Override
|
@Override
|
||||||
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
|
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
|
||||||
//TODO: Implement typeCheck for FieldId
|
//TODO: Implement typeCheck for FieldVarAccess
|
||||||
if(field){
|
if(field){
|
||||||
return null;
|
return null;
|
||||||
}else{
|
}else{
|
||||||
@ -24,11 +24,11 @@ public class TypedFieldId implements TypedExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
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 typedFieldId = new TypedFieldId();
|
||||||
typedFieldId.setField(untypedFieldId.field());
|
typedFieldId.setField(untypedFieldVarAccess.field());
|
||||||
typedFieldId.setRecipient((TypedExpression) recipient.convertToTypedAST(localVar, classes, untypedFieldId.recipient()));
|
typedFieldId.setRecipient((TypedExpression) recipient.convertToTypedAST(localVar, classes, untypedFieldVarAccess.recursiveOwnerChain()));
|
||||||
typedFieldId.setName(untypedFieldId.id().name());
|
typedFieldId.setName(untypedFieldVarAccess.id());
|
||||||
|
|
||||||
return typedFieldId;
|
return typedFieldId;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
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.MethodContext;
|
||||||
import de.maishai.typedast.TypedNode;
|
import de.maishai.typedast.TypedNode;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
@ -29,10 +30,10 @@ public final class TypedLocalVariable implements TypedNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
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 typedLocalVariable = new TypedLocalVariable();
|
||||||
|
|
||||||
typedLocalVariable.setName(untypedLocalVariable.name().name());
|
typedLocalVariable.setName(untypedLocalVariable.name());
|
||||||
typedLocalVariable.setType(TypeMapper.getType(untypedLocalVariable.type()));
|
typedLocalVariable.setType(TypeMapper.getType(untypedLocalVariable.type()));
|
||||||
|
|
||||||
return typedLocalVariable;
|
return typedLocalVariable;
|
||||||
|
@ -36,8 +36,8 @@ public class TypedMethod implements TypedNode {
|
|||||||
Method untypedMethod = (Method) unTypedAST;
|
Method untypedMethod = (Method) unTypedAST;
|
||||||
TypedMethod typedMethod = new TypedMethod();
|
TypedMethod typedMethod = new TypedMethod();
|
||||||
|
|
||||||
typedMethod.setName(untypedMethod.id().name());
|
typedMethod.setName(untypedMethod.methodName());
|
||||||
typedMethod.setReturnType(TypeMapper.getReturnType(untypedMethod.type()));
|
typedMethod.setReturnType(TypeMapper.getType(untypedMethod.type()));
|
||||||
|
|
||||||
if(untypedMethod.params().isEmpty()){
|
if(untypedMethod.params().isEmpty()){
|
||||||
//TODO: Implement this
|
//TODO: Implement this
|
||||||
|
@ -20,7 +20,7 @@ public class TypedReturnVoid implements TypedStatement {
|
|||||||
@Override
|
@Override
|
||||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||||
Method untyped = (Method) 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");
|
throw new RuntimeException("Return type is not void");
|
||||||
}
|
}
|
||||||
return new TypedReturnVoid();
|
return new TypedReturnVoid();
|
||||||
|
@ -20,8 +20,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructor {
|
public class AbstractSyntax_ClassWithConstructor {
|
||||||
public static Class get() {
|
public static Class get() {
|
||||||
List<Field> fields = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("x"),
|
new Id("x"),
|
||||||
Type.INT
|
Type.INT
|
||||||
)
|
)
|
||||||
@ -30,7 +30,7 @@ public class AbstractSyntax_ClassWithConstructor {
|
|||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithConstructor"),
|
new Id("ClassWithConstructor"),
|
||||||
fields,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
null,
|
null,
|
||||||
constructors
|
constructors
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import de.maishai.ast.Operator;
|
import de.maishai.ast.Operator;
|
||||||
import de.maishai.ast.ReturnType;
|
|
||||||
import de.maishai.ast.Type;
|
import de.maishai.ast.Type;
|
||||||
import de.maishai.ast.records.*;
|
import de.maishai.ast.records.*;
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
@ -28,8 +27,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
||||||
public static Class get() {
|
public static Class get() {
|
||||||
List<Field> fieldList = List.of(
|
List<Declaration> declarationList = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("x"),
|
new Id("x"),
|
||||||
Type.INT
|
Type.INT
|
||||||
)
|
)
|
||||||
@ -38,7 +37,7 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
|||||||
List<Constructor> constructorList = getConstructors();
|
List<Constructor> constructorList = getConstructors();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithConstructorAndMethodCall"),
|
new Id("ClassWithConstructorAndMethodCall"),
|
||||||
fieldList,
|
declarationList,
|
||||||
methodList,
|
methodList,
|
||||||
null,
|
null,
|
||||||
constructorList
|
constructorList
|
||||||
|
@ -22,8 +22,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructorWithParameters {
|
public class AbstractSyntax_ClassWithConstructorWithParameters {
|
||||||
public static Class get() {
|
public static Class get() {
|
||||||
List<Field> fields = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("x"),
|
new Id("x"),
|
||||||
Type.INT
|
Type.INT
|
||||||
)
|
)
|
||||||
@ -31,7 +31,7 @@ public class AbstractSyntax_ClassWithConstructorWithParameters {
|
|||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithConstructorWithParameters"),
|
new Id("ClassWithConstructorWithParameters"),
|
||||||
fields,
|
declarations,
|
||||||
List.of(),
|
List.of(),
|
||||||
null,
|
null,
|
||||||
constructors
|
constructors
|
||||||
|
@ -5,16 +5,15 @@
|
|||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
import de.maishai.ast.Type;
|
import de.maishai.ast.Type;
|
||||||
import de.maishai.ast.records.Constructor;
|
import de.maishai.ast.records.Constructor;
|
||||||
import de.maishai.ast.records.Field;
|
import de.maishai.ast.records.Declaration;
|
||||||
import de.maishai.ast.records.Id;
|
|
||||||
import de.maishai.ast.records.Method;
|
import de.maishai.ast.records.Method;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithField {
|
public class AbstractSyntax_ClassWithField {
|
||||||
public static Class get() {
|
public static Class get() {
|
||||||
List<Field> fields = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("x"),
|
new Id("x"),
|
||||||
Type.INT
|
Type.INT
|
||||||
)
|
)
|
||||||
@ -23,7 +22,7 @@ public class AbstractSyntax_ClassWithField {
|
|||||||
List<Constructor> constructors = List.of();
|
List<Constructor> constructors = List.of();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithAssignment"),
|
new Id("ClassWithAssignment"),
|
||||||
fields,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
null,
|
null,
|
||||||
constructors
|
constructors
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
import de.maishai.ast.ReturnType;
|
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
import de.maishai.ast.records.*;
|
import de.maishai.ast.records.*;
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ import java.util.List;
|
|||||||
|
|
||||||
class AbstractSyntax_ClassWithMethodAndField {
|
class AbstractSyntax_ClassWithMethodAndField {
|
||||||
public static Class get() {
|
public static Class get() {
|
||||||
List<Field> fields = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("c"),
|
new Id("c"),
|
||||||
Type.CHAR
|
Type.CHAR
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ class AbstractSyntax_ClassWithMethodAndField {
|
|||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithMethodAndField"),
|
new Id("ClassWithMethodAndField"),
|
||||||
fields,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
null,
|
null,
|
||||||
constructors
|
constructors
|
||||||
|
@ -28,8 +28,8 @@ public class AbstractSyntax_ClassWithMoreComplexMethodAndMain {
|
|||||||
public static Class get() {
|
public static Class get() {
|
||||||
Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
|
Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
|
||||||
TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
|
TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
|
||||||
List<Field> fields = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Field(
|
new Declaration(
|
||||||
new Id("instance"),
|
new Id("instance"),
|
||||||
TypeClassWithMoreComplexMethodAndMain
|
TypeClassWithMoreComplexMethodAndMain
|
||||||
)
|
)
|
||||||
@ -38,7 +38,7 @@ public class AbstractSyntax_ClassWithMoreComplexMethodAndMain {
|
|||||||
List<Constructor> constructors = List.of();
|
List<Constructor> constructors = List.of();
|
||||||
return new Class(
|
return new Class(
|
||||||
new Id("ClassWithMoreComplexMethodAndMain"),
|
new Id("ClassWithMoreComplexMethodAndMain"),
|
||||||
fields,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
getMainMethod(),
|
getMainMethod(),
|
||||||
constructors
|
constructors
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
import de.maishai.ast.records.Id;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
import de.maishai.ast.AssignSign;
|
|
||||||
import de.maishai.ast.Operator;
|
import de.maishai.ast.Operator;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
import de.maishai.typedast.typedclass.*;
|
import de.maishai.typedast.typedclass.*;
|
||||||
|
@ -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 class TypedAbstractSyntax_ClassWithConstructorAndMethodCall {
|
||||||
// public static Class get() {
|
// public static Class get() {
|
||||||
// List<Field> fieldList = List.of(
|
// List<Declaration> fieldList = List.of(
|
||||||
// new Field(
|
// new Declaration(
|
||||||
// new Id("x"),
|
// new Id("x"),
|
||||||
// Type.INT
|
// Type.INT
|
||||||
// )
|
// )
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
import de.maishai.ast.AssignSign;
|
|
||||||
import de.maishai.ast.Operator;
|
import de.maishai.ast.Operator;
|
||||||
import de.maishai.ast.records.*;
|
import de.maishai.ast.records.*;
|
||||||
import de.maishai.ast.Type;
|
import de.maishai.ast.Type;
|
||||||
@ -23,8 +22,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TypedAbstractSyntax_ClassWithConstructorWithParameters {
|
public class TypedAbstractSyntax_ClassWithConstructorWithParameters {
|
||||||
// public static Class get() {
|
// public static Class get() {
|
||||||
// List<Field> fields = List.of(
|
// List<Declaration> fieldDeclarations = List.of(
|
||||||
// new Field(
|
// new Declaration(
|
||||||
// new Id("x"),
|
// new Id("x"),
|
||||||
// Type.INT
|
// Type.INT
|
||||||
// )
|
// )
|
||||||
@ -33,7 +32,7 @@ public class TypedAbstractSyntax_ClassWithConstructorWithParameters {
|
|||||||
// return new Class(
|
// return new Class(
|
||||||
// true,
|
// true,
|
||||||
// new Id("ClassWithConstructorWithParameters"),
|
// new Id("ClassWithConstructorWithParameters"),
|
||||||
// fields,
|
// fieldDeclarations,
|
||||||
// List.of(),
|
// List.of(),
|
||||||
// null,
|
// null,
|
||||||
// constructors
|
// constructors
|
||||||
|
@ -18,8 +18,8 @@ import java.util.List;
|
|||||||
|
|
||||||
class TypedAbstractSyntax_ClassWithMethodAndField {
|
class TypedAbstractSyntax_ClassWithMethodAndField {
|
||||||
// public static Class get() {
|
// public static Class get() {
|
||||||
// List<Field> fields = List.of(
|
// List<Declaration> fieldDeclarations = List.of(
|
||||||
// new Field(
|
// new Declaration(
|
||||||
// new Id("c"),
|
// new Id("c"),
|
||||||
// Type.CHAR
|
// Type.CHAR
|
||||||
// )
|
// )
|
||||||
@ -29,7 +29,7 @@ class TypedAbstractSyntax_ClassWithMethodAndField {
|
|||||||
// return new Class(
|
// return new Class(
|
||||||
// false,
|
// false,
|
||||||
// new Id("ClassWithMethodAndField"),
|
// new Id("ClassWithMethodAndField"),
|
||||||
// fields,
|
// fieldDeclarations,
|
||||||
// methods,
|
// methods,
|
||||||
// null,
|
// null,
|
||||||
// constructors
|
// constructors
|
||||||
|
@ -28,8 +28,8 @@ public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain {
|
|||||||
// public static Class get() {
|
// public static Class get() {
|
||||||
// Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
|
// Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;
|
||||||
// TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
|
// TypeClassWithMoreComplexMethodAndMain.setObjectType(new Id("ClassWithMoreComplexMethodAndMain"));
|
||||||
// List<Field> fields = List.of(
|
// List<Declaration> fieldDeclarations = List.of(
|
||||||
// new Field(
|
// new Declaration(
|
||||||
// new Id("instance"),
|
// new Id("instance"),
|
||||||
// TypeClassWithMoreComplexMethodAndMain
|
// TypeClassWithMoreComplexMethodAndMain
|
||||||
// )
|
// )
|
||||||
@ -39,7 +39,7 @@ public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain {
|
|||||||
// return new Class(
|
// return new Class(
|
||||||
// true,
|
// true,
|
||||||
// new Id("ClassWithMoreComplexMethodAndMain"),
|
// new Id("ClassWithMoreComplexMethodAndMain"),
|
||||||
// fields,
|
// fieldDeclarations,
|
||||||
// methods,
|
// methods,
|
||||||
// getMainMethod(),
|
// getMainMethod(),
|
||||||
// constructors
|
// constructors
|
||||||
|
Loading…
Reference in New Issue
Block a user