From ede0b389878d222a19968de7dbf643bb28678928 Mon Sep 17 00:00:00 2001 From: ahmad Date: Sun, 12 May 2024 15:46:14 +0200 Subject: [PATCH] Add the list of TypedLocalVariable to TypedMethod and implemented the typeCheck --- .../maishai/typedast/typedclass/TypedMethod.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java index e9c4f38..26fcf00 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java @@ -20,8 +20,8 @@ public class TypedMethod implements TypedNode { private String name; private Type returnType; private List typedParameters = new ArrayList<>(); - private TypedBlock typedBlock; private List localVariables = new ArrayList<>(); + private TypedBlock typedBlock; public TypedMethod(TypedClass clas, Method unTypedMethod) { convertToTypedMethod(clas, unTypedMethod); @@ -40,12 +40,11 @@ public class TypedMethod implements TypedNode { throw new RuntimeException("Method " + name + " already exists"); }, () -> { }); - - //localVar.put(name, returnType); } public void convertToTypedBlock(TypedClass clas, Method unTypedMethod) { typedBlock = new TypedBlock(clas, unTypedMethod.block()); + typeCheck(clas); } public boolean isLocalVariablePresent(String localVarName) { @@ -67,13 +66,11 @@ public class TypedMethod implements TypedNode { @Override public Type typeCheck(TypedClass clas) { - /* if (localVar.containsKey(name)) { - throw new RuntimeException("Method " + name + " already exists"); + if(returnType != Type.VOID){ + if(typedBlock.typeCheck(clas) != returnType){ + throw new RuntimeException("Method " + name + " must return " + returnType); + } } - localVar.put(name, returnType); - for (TypedParameter typedParameter : typedParameters) { - typedParameter.typeCheck( clas); - }*/ return returnType; }