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