From ac9ebb04b3aa1d6498bf8f51352a20df0cf7837e Mon Sep 17 00:00:00 2001 From: ahmad Date: Sun, 12 May 2024 23:00:14 +0200 Subject: [PATCH] Implemented the checkType of TypedMethodCall --- .../typedast/typedclass/TypedBlock.java | 2 -- .../typedast/typedclass/TypedMethodCall.java | 24 +++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java b/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java index 56de410..f234391 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java @@ -98,8 +98,6 @@ public class TypedBlock implements TypedNode { } } this.typeCheck(clas); - System.out.println("TypedBlock: " + this.toString()); - } @Override diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java index d3962af..d35a12a 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java @@ -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 args; + private List 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 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"); }