Merge branch 'typedAST' of https://gitea.hb.dhbw-stuttgart.de/MisterChaos69/MiniJavaCompiler into bytecode
This commit is contained in:
commit
3f78cdaa2d
@ -117,9 +117,14 @@ typeCheckStatementExpression (ConstructorCall className args) symtab classes =
|
|||||||
case find (\(Class name _ _) -> name == className) classes of
|
case find (\(Class name _ _) -> name == className) classes of
|
||||||
Nothing -> error $ "Class '" ++ className ++ "' not found."
|
Nothing -> error $ "Class '" ++ className ++ "' not found."
|
||||||
Just (Class _ methods fields) ->
|
Just (Class _ methods fields) ->
|
||||||
-- Constructor needs the same name as the class
|
-- Find constructor matching the class name with void return type
|
||||||
case find (\(MethodDeclaration retType name params _) -> name == "<init>" && retType == "void") methods of
|
case find (\(MethodDeclaration retType name params _) -> name == "<init>" && retType == "void") methods of
|
||||||
Nothing -> error $ "No valid constructor found for class '" ++ className ++ "'."
|
-- If no constructor is found, assume standard constructor with no parameters
|
||||||
|
Nothing ->
|
||||||
|
if null args then
|
||||||
|
TypedStatementExpression className (ConstructorCall className args)
|
||||||
|
else
|
||||||
|
error $ "No valid constructor found for class '" ++ className ++ "', but arguments were provided."
|
||||||
Just (MethodDeclaration _ _ params _) ->
|
Just (MethodDeclaration _ _ params _) ->
|
||||||
let
|
let
|
||||||
args' = map (\arg -> typeCheckExpression arg symtab classes) args
|
args' = map (\arg -> typeCheckExpression arg symtab classes) args
|
||||||
|
Loading…
Reference in New Issue
Block a user