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); this.typeCheck(clas);
System.out.println("TypedBlock: " + this.toString());
} }
@Override @Override

View File

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