rearranged some functions,

added check for multiple definitions
changed naming of attributes in haskell
This commit is contained in:
Macocian Adrian Radu
2022-02-24 12:05:53 +01:00
parent a84f433667
commit edee037aa3
7 changed files with 58 additions and 27 deletions

View File

@@ -5,6 +5,7 @@ import Data.Either
import Data.Maybe
import Model.Type
import Semantic.TypeChecker
import Utils.Utils
-- |A declared variable or function
data Symbol = Var{
@@ -59,7 +60,9 @@ defaultMap = [
-- |Checks whether a function is valid (inputs, outputs are of valid type and all variables are defined) and adds it to the symbol table
addFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] [Symbol]
addFunction (definedTypes, definedSymbols) (MakeFunction name _ inps out _)
| null (lefts checkedInputs) && isRight checkedOutput = Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : definedSymbols
| null (lefts checkedInputs) && isRight checkedOutput = if name `elem` map funcName definedSymbols
then Left [MultipleDeclarations name]
else Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : definedSymbols
| isLeft checkedOutput = Left [fromLeftUnsafe checkedOutput]
| otherwise = Left $ lefts checkedInputs
where