From b040130569c69370ec99c2210da891495ee77f09 Mon Sep 17 00:00:00 2001 From: MisterChaos96 Date: Tue, 7 May 2024 16:36:42 +0200 Subject: [PATCH] removed unneccesary comments --- src/Typecheck.hs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Typecheck.hs b/src/Typecheck.hs index 61aa87e..7cdc3a7 100644 --- a/src/Typecheck.hs +++ b/src/Typecheck.hs @@ -9,7 +9,7 @@ typeCheckCompilationUnit classes = map (`typeCheckClass` classes) classes typeCheckClass :: Class -> [Class] -> Class typeCheckClass (Class className methods fields) classes = let - -- Create a symbol table from class fields + -- Create a symbol table from class fields and method entries classFields = [(id, dt) | VariableDeclaration dt id _ <- fields] methodEntries = [(methodName, className) | MethodDeclaration _ methodName _ _ <- methods] initalSymTab = ("this", className) : classFields ++ methodEntries @@ -21,9 +21,7 @@ typeCheckMethodDeclaration (MethodDeclaration retType name params body) classFie let -- Combine class fields with method parameters to form the initial symbol table for the method methodParams = [(identifier, dataType) | ParameterDeclaration dataType identifier <- params] - -- Ensure method parameters shadow class fields if names collide initialSymtab = classFields ++ methodParams - -- Type check the body of the method using the combined symbol table checkedBody = typeCheckStatement body initialSymtab classes bodyType = getTypeFromStmt checkedBody -- Check if the type of the body matches the declared return type @@ -211,17 +209,13 @@ typeCheckStatementExpression (ConstructorCall className args) symtab classes = TypedStatementExpression className (ConstructorCall className args') typeCheckStatementExpression (MethodCall expr methodName args) symtab classes = - -- First, evaluate the object expression to find its type let objExprTyped = typeCheckExpression expr symtab classes in case objExprTyped of TypedExpression objType _ -> - -- Look for the class of the object type to find the method case find (\(Class className _ _) -> className == objType) classes of Just (Class _ methods _) -> - -- Find the method within the class case find (\(MethodDeclaration retType name params _) -> name == methodName) methods of Just (MethodDeclaration retType _ params _) -> - -- Check arguments let args' = map (\arg -> typeCheckExpression arg symtab classes) args expectedTypes = [dataType | ParameterDeclaration dataType _ <- params] argTypes = map getTypeFromExpr args' @@ -240,7 +234,6 @@ typeCheckStatementExpression (MethodCall expr methodName args) symtab classes = Nothing -> error $ "Class for object type '" ++ objType ++ "' not found." _ -> error "Invalid object type for method call. Object must have a class type." - -- ********************************** Type Checking: Statements ********************************** typeCheckStatement :: Statement -> [(Identifier, DataType)] -> [Class] -> Statement