Implemented the checkType of TypedMethodCall

This commit is contained in:
ahmad 2024-05-12 23:00:14 +02:00
parent 1e830ff38b
commit ac9ebb04b3
2 changed files with 11 additions and 15 deletions

View File

@ -98,8 +98,6 @@ public class TypedBlock implements TypedNode {
}
}
this.typeCheck(clas);
System.out.println("TypedBlock: " + this.toString());
}
@Override

View File

@ -5,10 +5,9 @@ import de.maishai.ast.records.MethodCall;
import de.maishai.typedast.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.objectweb.asm.MethodVisitor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@ -18,7 +17,7 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@NoArgsConstructor
public class TypedMethodCall implements TypedExpression, TypedStatement {
private TypedFieldVarAccess recipient;
private List<TypedExpression> args;
private List<TypedExpression> args = new ArrayList<>();
private Type type;
public TypedMethodCall(TypedClass clas, MethodCall unTypedMethodCall) {
@ -27,18 +26,17 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
public void convertToTypedMethodCall(TypedClass clas, MethodCall unTypedMethodCall) {
recipient = new TypedFieldVarAccess(clas, unTypedMethodCall.recipient());
for (Expression arg : unTypedMethodCall.args()) {
args.add(convertExpression(clas, arg));
}
recipient.getName();
for (Expression arg : unTypedMethodCall.args()) {
args.add(convertExpression(clas, arg));
}
}
@Override
public Type typeCheck(TypedClass clas) {
/* if (clas.isCurrentMethodPresent()) {
if (clas.isCurrentMethodPresent() || clas.isCurrentConstructorPresent()) {
List<TypedMethod> methods = clas.getTypedMethods().stream()
.filter(method -> method.getName().equals(name))
.filter(method -> method.getName().equals(recipient.getName()))
.toList();
for (TypedMethod method : methods) {
@ -51,13 +49,13 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
}
}
if (allMatch) {
return method.getReturnType();
type = method.getReturnType();
return type;
}
}
}
} */
return null;
}
throw new RuntimeException("Method not found");
}