renamed the static method

This commit is contained in:
ahmad 2024-05-09 18:39:44 +02:00
parent 903f9e8d4e
commit 735781a63c
12 changed files with 29 additions and 28 deletions

View File

@ -9,7 +9,7 @@ import java.util.Map;
public class TypedExpressionUtil { public class TypedExpressionUtil {
public static TypedExpression GET_KIND_OF_EXPRESSION(Map<String, Type> localVar, Map<String, TypedClass> classes, Expression expression) { public static TypedExpression getKindOfExpression(Map<String, Type> localVar, Map<String, TypedClass> classes, Expression expression) {
if (expression instanceof BoolLiteral boolLiteral) { if (expression instanceof BoolLiteral boolLiteral) {
TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral(); TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral();
typedBoolLiteral.setValue(boolLiteral.value()); typedBoolLiteral.setValue(boolLiteral.value());
@ -44,7 +44,7 @@ public class TypedExpressionUtil {
typedFieldVarAccess.setField(methodCall.recipient().field()); typedFieldVarAccess.setField(methodCall.recipient().field());
typedMethodCall.setRecipient(typedFieldVarAccess); typedMethodCall.setRecipient(typedFieldVarAccess);
for (var arg : methodCall.args()) { for (var arg : methodCall.args()) {
typedMethodCall.getArgs().add(GET_KIND_OF_EXPRESSION(localVar, classes, arg)); typedMethodCall.getArgs().add(getKindOfExpression(localVar, classes, arg));
} }
return typedMethodCall; return typedMethodCall;
} }
@ -52,14 +52,14 @@ public class TypedExpressionUtil {
TypedNew typedNew = new TypedNew(); TypedNew typedNew = new TypedNew();
typedNew.setType(newStmt.type()); typedNew.setType(newStmt.type());
for (var arg : newStmt.args()) { for (var arg : newStmt.args()) {
typedNew.getArgs().add(GET_KIND_OF_EXPRESSION(localVar, classes, arg)); typedNew.getArgs().add(getKindOfExpression(localVar, classes, arg));
} }
return typedNew; return typedNew;
} }
else if (expression instanceof Unary unary) { else if (expression instanceof Unary unary) {
TypedUnary typedUnary = new TypedUnary(); TypedUnary typedUnary = new TypedUnary();
typedUnary.setOp(unary.op()); typedUnary.setOp(unary.op());
typedUnary.setRight(GET_KIND_OF_EXPRESSION(localVar, classes, unary.right())); typedUnary.setRight(getKindOfExpression(localVar, classes, unary.right()));
return typedUnary; return typedUnary;
} else { } else {
return null; return null;

View File

@ -12,7 +12,7 @@ import org.objectweb.asm.Opcodes;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedAssignment implements TypedStatement { public class TypedAssignment implements TypedStatement {
@ -22,7 +22,7 @@ public class TypedAssignment implements TypedStatement {
public TypedAssignment convertToTypedAssignment(Map<String, Type> localVar, Map<String, TypedClass> classes, Assignment untyped) { public TypedAssignment convertToTypedAssignment(Map<String, Type> localVar, Map<String, TypedClass> classes, Assignment untyped) {
varName = untyped.location().id(); varName = untyped.location().id();
value = GET_KIND_OF_EXPRESSION(localVar, classes, untyped.value()); value = getKindOfExpression(localVar, classes, untyped.value());
return this; return this;
} }

View File

@ -3,7 +3,6 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
import de.maishai.ast.records.Binary; import de.maishai.ast.records.Binary;
import de.maishai.typedast.MethodContext; import de.maishai.typedast.MethodContext;
import de.maishai.ast.records.*;
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;
@ -12,7 +11,7 @@ import org.objectweb.asm.MethodVisitor;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedBinary implements TypedExpression { public class TypedBinary implements TypedExpression {
@ -22,8 +21,8 @@ public class TypedBinary implements TypedExpression {
private Type type; private Type type;
public TypedBinary convertToTypedBinary(Map<String, Type> localVar, Map<String, TypedClass> classes, Binary unTypedBinary) { public TypedBinary convertToTypedBinary(Map<String, Type> localVar, Map<String, TypedClass> classes, Binary unTypedBinary) {
left = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedBinary.left()); left = getKindOfExpression(localVar, classes, unTypedBinary.left());
right = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedBinary.right()); right = getKindOfExpression(localVar, classes, unTypedBinary.right());
op = unTypedBinary.op(); op = unTypedBinary.op();
return this; return this;
} }

View File

@ -52,8 +52,7 @@ public class TypedBlock implements TypedNode {
continue; continue;
} }
if (stmt instanceof For forStmt) { if (stmt instanceof For forStmt) {
TypedFor typedFor = new TypedFor() TypedFor typedFor = new TypedFor().convertToTypedFor(localVar, classes, forStmt);
.convertToTypedFor(localVar, classes, forStmt);
typedFor.typeCheck(localVar, classes); typedFor.typeCheck(localVar, classes);
typedBlock.getStmts().add(typedFor); typedBlock.getStmts().add(typedFor);
continue; continue;
@ -105,7 +104,7 @@ public class TypedBlock implements TypedNode {
} }
} }
} }
System.out.println("typedBlock: " + typedBlock.toString());
return typedBlock; return typedBlock;
} }

View File

@ -7,16 +7,18 @@ import org.objectweb.asm.MethodVisitor;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedDoWhile implements TypedStatement { public class TypedDoWhile implements TypedStatement {
private TypedBlock typedBlock; private TypedBlock typedBlock;
private TypedExpression cond; private TypedExpression cond;
public TypedDoWhile() {
}
public TypedDoWhile convertToTypedDoWhile(Map<String, Type> localVar, Map<String, TypedClass> classes, DoWhile unTypedDoWhile) { public TypedDoWhile convertToTypedDoWhile(Map<String, Type> localVar, Map<String, TypedClass> classes, DoWhile unTypedDoWhile) {
typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedDoWhile.block()); typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedDoWhile.block());
cond = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedDoWhile.cond()); cond = getKindOfExpression(localVar, classes, unTypedDoWhile.cond());
return this; return this;
} }

View File

@ -10,7 +10,7 @@ import org.objectweb.asm.MethodVisitor;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedFieldVarAccess implements TypedExpression { public class TypedFieldVarAccess implements TypedExpression {
@ -21,7 +21,7 @@ public class TypedFieldVarAccess implements TypedExpression {
public TypedFieldVarAccess convertToTypedFieldVarAccess(Map<String, Type> localVar, Map<String, TypedClass> classes, FieldVarAccess unTypedFieldVarAccess) { public TypedFieldVarAccess convertToTypedFieldVarAccess(Map<String, Type> localVar, Map<String, TypedClass> classes, FieldVarAccess unTypedFieldVarAccess) {
field = unTypedFieldVarAccess.field(); field = unTypedFieldVarAccess.field();
recursiveOwnerChain = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedFieldVarAccess.recursiveOwnerChain()); recursiveOwnerChain = getKindOfExpression(localVar, classes, unTypedFieldVarAccess.recursiveOwnerChain());
name = unTypedFieldVarAccess.id(); name = unTypedFieldVarAccess.id();
type = localVar.get(unTypedFieldVarAccess.id()); type = localVar.get(unTypedFieldVarAccess.id());
return this; return this;

View File

@ -9,7 +9,7 @@ import org.objectweb.asm.MethodVisitor;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -22,7 +22,7 @@ public class TypedFor implements TypedStatement {
public TypedFor convertToTypedFor(Map<String, Type> localVar, Map<String, TypedClass> classes, For unTypedFor) { public TypedFor convertToTypedFor(Map<String, Type> localVar, Map<String, TypedClass> classes, For unTypedFor) {
assign = new TypedAssignment().convertToTypedAssignment(localVar, classes, unTypedFor.assign()); assign = new TypedAssignment().convertToTypedAssignment(localVar, classes, unTypedFor.assign());
cond = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedFor.cond()); cond = getKindOfExpression(localVar, classes, unTypedFor.cond());
inc = new TypedAssignment().convertToTypedAssignment(localVar, classes, unTypedFor.inc()); inc = new TypedAssignment().convertToTypedAssignment(localVar, classes, unTypedFor.inc());
typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedFor.block()); typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedFor.block());
return this; return this;

View File

@ -9,7 +9,7 @@ import org.objectweb.asm.Opcodes;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedIfElse implements TypedStatement { public class TypedIfElse implements TypedStatement {
@ -20,7 +20,7 @@ public class TypedIfElse implements TypedStatement {
public TypedIfElse convertToTypedIfElse(Map<String, Type> localVar, Map<String, TypedClass> classes, IfElse unTypedIfElse) { public TypedIfElse convertToTypedIfElse(Map<String, Type> localVar, Map<String, TypedClass> classes, IfElse unTypedIfElse) {
ifTypedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedIfElse.ifBlock()); ifTypedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedIfElse.ifBlock());
elseTypedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedIfElse.elseBlock()); elseTypedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedIfElse.elseBlock());
typedCon = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedIfElse.cond()); typedCon = getKindOfExpression(localVar, classes, unTypedIfElse.cond());
return this; return this;
} }

View File

@ -18,7 +18,8 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
//TODO: Implement this //TODO: Implement this
return null; return null;
} }
@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 MethodCall //TODO: Implement typeCheck for MethodCall
return null; return null;

View File

@ -9,14 +9,14 @@ import org.objectweb.asm.Opcodes;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedReturn implements TypedStatement { public class TypedReturn implements TypedStatement {
private TypedExpression ret; private TypedExpression ret;
public TypedReturn convertToTypedReturn(Map<String, Type> localVar, Map<String, TypedClass> classes, Return unTypedReturn) { public TypedReturn convertToTypedReturn(Map<String, Type> localVar, Map<String, TypedClass> classes, Return unTypedReturn) {
ret = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedReturn.ret()); ret = getKindOfExpression(localVar, classes, unTypedReturn.ret());
return this; return this;
} }

View File

@ -12,7 +12,7 @@ import org.objectweb.asm.Opcodes;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedUnary implements TypedExpression { public class TypedUnary implements TypedExpression {
@ -22,7 +22,7 @@ public class TypedUnary implements TypedExpression {
public TypedUnary convertToTypedUnary(Map<String, Type> localVar, Map<String, TypedClass> classes, Unary unTypedUnary) { public TypedUnary convertToTypedUnary(Map<String, Type> localVar, Map<String, TypedClass> classes, Unary unTypedUnary) {
op = unTypedUnary.op(); op = unTypedUnary.op();
right = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedUnary.right()); right = getKindOfExpression(localVar, classes, unTypedUnary.right());
return this; return this;
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import org.objectweb.asm.MethodVisitor;
import java.util.Map; import java.util.Map;
import static de.maishai.typedast.Util.TypedExpressionUtil.GET_KIND_OF_EXPRESSION; import static de.maishai.typedast.Util.TypedExpressionUtil.getKindOfExpression;
@Data @Data
public class TypedWhile implements TypedStatement { public class TypedWhile implements TypedStatement {
@ -15,7 +15,7 @@ public class TypedWhile implements TypedStatement {
private TypedBlock typedBlock; private TypedBlock typedBlock;
public TypedWhile convertToTypedWhile(Map<String, Type> localVar, Map<String, TypedClass> classes, While unTypedWhile) { public TypedWhile convertToTypedWhile(Map<String, Type> localVar, Map<String, TypedClass> classes, While unTypedWhile) {
cond = GET_KIND_OF_EXPRESSION(localVar, classes, unTypedWhile.cond()); cond = getKindOfExpression(localVar, classes, unTypedWhile.cond());
typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedWhile.block()); typedBlock = new TypedBlock().blockToTypedBlock(localVar, classes, unTypedWhile.block());
return this; return this;
} }