add default constructor if none are present
This commit is contained in:
parent
d0bf34d331
commit
b5efc76c17
@ -10,10 +10,14 @@ typeCheckCompilationUnit classes = map (`typeCheckClass` classes) classes
|
|||||||
typeCheckClass :: Class -> [Class] -> Class
|
typeCheckClass :: Class -> [Class] -> Class
|
||||||
typeCheckClass (Class className constructors methods fields) classes =
|
typeCheckClass (Class className constructors methods fields) classes =
|
||||||
let
|
let
|
||||||
|
-- Add a default constructor if none are present
|
||||||
|
defaultConstructor = ConstructorDeclaration className [] (Block [])
|
||||||
|
constructorsWithDefault = if null constructors then [defaultConstructor] else constructors
|
||||||
|
|
||||||
-- Fields and methods dont need to be added to the symtab because they are looked upon automatically under "this"
|
-- Fields and methods dont need to be added to the symtab because they are looked upon automatically under "this"
|
||||||
-- if its not a declared local variable. Also shadowing wouldnt be possible then.
|
-- if its not a declared local variable. Also shadowing wouldnt be possible then.
|
||||||
initalSymTab = [("this", className)]
|
initalSymTab = [("this", className)]
|
||||||
checkedConstructors = map (\constructor -> typeCheckConstructorDeclaration constructor initalSymTab classes) constructors
|
checkedConstructors = map (\constructor -> typeCheckConstructorDeclaration constructor initalSymTab classes) constructorsWithDefault
|
||||||
checkedMethods = map (\method -> typeCheckMethodDeclaration method initalSymTab classes) methods
|
checkedMethods = map (\method -> typeCheckMethodDeclaration method initalSymTab classes) methods
|
||||||
checkedFields = map (\field -> typeCheckVariableDeclaration field initalSymTab classes) fields
|
checkedFields = map (\field -> typeCheckVariableDeclaration field initalSymTab classes) fields
|
||||||
in Class className checkedConstructors checkedMethods checkedFields
|
in Class className checkedConstructors checkedMethods checkedFields
|
||||||
|
Loading…
Reference in New Issue
Block a user