Rain: implementing type checking for inputs inside alts
This commit is contained in:
parent
5c827fdacb
commit
a12d46401a
|
@ -269,12 +269,12 @@ checkConditionalTypes t = (everywhereASTM checkWhile t) >>= (everywhereASTM chec
|
||||||
then return c
|
then return c
|
||||||
else dieP m "Expression in if conditional must be of boolean type"
|
else dieP m "Expression in if conditional must be of boolean type"
|
||||||
|
|
||||||
-- | Checks the types in inputs and outputs
|
-- | Checks the types in inputs and outputs, including inputs in alts
|
||||||
checkCommTypes :: Data t => t -> PassM t
|
checkCommTypes :: Data t => t -> PassM t
|
||||||
checkCommTypes = everywhereASTM checkInputOutput
|
checkCommTypes p = (everywhereASTM checkInputOutput p) >>= (everywhereASTM checkAltInput)
|
||||||
where
|
where
|
||||||
checkInputOutput :: A.Process -> PassM A.Process
|
checkInput :: A.Variable -> A.Variable -> Meta -> a -> PassM a
|
||||||
checkInputOutput p@(A.Input m chanVar (A.InputSimple _ [A.InVariable _ destVar]))
|
checkInput chanVar destVar m p
|
||||||
= do chanType <- typeOfVariable chanVar
|
= do chanType <- typeOfVariable chanVar
|
||||||
destType <- typeOfVariable destVar
|
destType <- typeOfVariable destVar
|
||||||
case chanType of
|
case chanType of
|
||||||
|
@ -287,6 +287,10 @@ checkCommTypes = everywhereASTM checkInputOutput
|
||||||
else diePC m $ formatCode "Mis-matching types; channel: \"%\" has inner-type: % but destination variable: \"%\" has type: %"
|
else diePC m $ formatCode "Mis-matching types; channel: \"%\" has inner-type: % but destination variable: \"%\" has type: %"
|
||||||
chanVar innerType destVar destType
|
chanVar innerType destVar destType
|
||||||
_ -> dieP m $ "Tried to input from a variable that is not of type channel: " ++ show chanVar
|
_ -> dieP m $ "Tried to input from a variable that is not of type channel: " ++ show chanVar
|
||||||
|
|
||||||
|
checkInputOutput :: A.Process -> PassM A.Process
|
||||||
|
checkInputOutput p@(A.Input m chanVar (A.InputSimple _ [A.InVariable _ destVar]))
|
||||||
|
= checkInput chanVar destVar m p
|
||||||
checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp])
|
checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp])
|
||||||
= do chanType <- typeOfVariable chanVar
|
= do chanType <- typeOfVariable chanVar
|
||||||
srcType <- typeOfExpression srcExp
|
srcType <- typeOfExpression srcExp
|
||||||
|
@ -302,6 +306,11 @@ checkCommTypes = everywhereASTM checkInputOutput
|
||||||
_ -> dieP m $ "Tried to output to a variable that is not of type channel: " ++ show chanVar
|
_ -> dieP m $ "Tried to output to a variable that is not of type channel: " ++ show chanVar
|
||||||
checkInputOutput p = return p
|
checkInputOutput p = return p
|
||||||
|
|
||||||
|
checkAltInput :: A.Alternative -> PassM A.Alternative
|
||||||
|
checkAltInput a@(A.Alternative m chanVar (A.InputSimple _ [A.InVariable _ destVar]) body)
|
||||||
|
= checkInput chanVar destVar m a
|
||||||
|
checkAltInput a = return a
|
||||||
|
|
||||||
-- | Checks the types in now statements:
|
-- | Checks the types in now statements:
|
||||||
checkGetTimeTypes :: Data t => t -> PassM t
|
checkGetTimeTypes :: Data t => t -> PassM t
|
||||||
checkGetTimeTypes = everywhereASTM checkGetTime
|
checkGetTimeTypes = everywhereASTM checkGetTime
|
||||||
|
|
Loading…
Reference in New Issue
Block a user