update the TypedMethod

This commit is contained in:
Ahmad 2024-05-09 15:56:13 +02:00
parent 85171ce95d
commit a16ee38ce8
3 changed files with 3 additions and 83 deletions

View File

@ -1,28 +0,0 @@
package de.maishai.typedast.typedclass;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.TypedStatement;
import de.maishai.typedast.Type;
import lombok.Data;
import org.objectweb.asm.MethodVisitor;
import java.util.Map;
@Data
public class TypedContinue implements TypedStatement {
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.VOID;
}
@Override
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return new TypedContinue();
}
@Override
public void codeGen(MethodVisitor mv, MethodContext ctx) {
}
}

View File

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

View File

@ -19,7 +19,7 @@ public class TypedMethod implements TypedNode {
private List<TypedParameter> typedParameters;
private TypedBlock typedBlock;
public TypedMethod unTypedMethodToTypedMethod(Method unTypedMethod) {
public TypedMethod convertToTypedMethod(Map<String, Type> localVar, Map<String, TypedClass> classes, Method unTypedMethod) {
TypedMethod typedMethod = new TypedMethod();
typedMethod.setName(unTypedMethod.methodName());
typedMethod.setTypedParameters(new ArrayList<>());
@ -35,7 +35,7 @@ public class TypedMethod implements TypedNode {
}
}
TypedBlock block = new TypedBlock();
typedMethod.setTypedBlock(block.unTypedBlockToTypedBlock(unTypedMethod.block()));
typedMethod.setTypedBlock(block.blockToTypedBlock(localVar, classes, unTypedMethod.block()));
return typedMethod;
}
@Override
@ -67,28 +67,11 @@ public class TypedMethod implements TypedNode {
}
TypedBlock typedBlock = new TypedBlock();
typedMethod.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untypedMethod.block()));
typedMethod.setTypedBlock(typedBlock.blockToTypedBlock(localVar, classes,untypedMethod.block()));
return typedMethod;
}
private TypedParameter getTypedParameter(Parameter parameter) {
TypedParameter typedParameter = new TypedParameter();
typedParameter.setParaName(parameter.name());
if(parameter.type() == Type.CHAR){
typedParameter.setType(Type.CHAR);
}
if(parameter.type() == Type.BOOL){
typedParameter.setType(Type.BOOL);
}
if(parameter.type() == Type.INT){
typedParameter.setType(Type.INT);
}
return typedParameter;
}
public void codeGen(ClassWriter cw) {
int accessModifier = Opcodes.ACC_PUBLIC; // ist laut Andi ok
MethodVisitor mv = cw.visitMethod(accessModifier, name,