Updated convertToTypedAST of TypedConstructor

This commit is contained in:
Ahmad 2024-05-08 16:05:32 +02:00
parent cdfb914816
commit bfcbb4dc2d

View File

@ -14,6 +14,7 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -22,12 +23,10 @@ import java.util.Map;
@Data
public class TypedConstructor implements TypedNode {
private Boolean isPublic;
private String name;
private List<TypedParameter> typedParameters;
private TypedBlock typedBlock;
//constructor: PUBLIC? id '(' params? ')' block;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if (localVar.containsKey(name)) {
@ -70,20 +69,22 @@ public class TypedConstructor implements TypedNode {
Constructor untyped = (Constructor) unTypedAST;
TypedConstructor typedConstructor = new TypedConstructor();
typedConstructor.setName(untyped.className());
typedConstructor.setTypedParameters(new ArrayList<>());
if (untyped.params().isEmpty()) {
typedConstructor.setTypedParameters(null);
} else {
for (Parameter param : untyped.params()) {
TypedParameter typedParam = new TypedParameter();
typedParam.convertToTypedAST(localVar, classes, param);
typedParam.setType(param.type());
typedParam.setParaName(param.name());
typedConstructor.getTypedParameters().add(typedParam);
}
}
Block block = untyped.block();
TypedBlock typedBlock = new TypedBlock();
typedBlock.convertToTypedAST(localVar, classes, block);
typedConstructor.setTypedBlock(typedBlock);
typedConstructor.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untyped.block()));
return typedConstructor;
}