Rain: implemented the pass for recording inferred types, and added one more test for it
This commit is contained in:
parent
3473c512a3
commit
f9a811e775
|
@ -220,6 +220,11 @@ testRecordInfNames2 = testPassWithStateCheck "testRecordInfNames2" exp (recordIn
|
|||
assertVarDef "testRecordInfNames2" state "d"
|
||||
(tag7 A.NameDef DontCare "d" "d" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced)
|
||||
|
||||
-- | checks that doing a foreach over a non-array type is barred:
|
||||
testRecordInfNames3 :: Test
|
||||
testRecordInfNames3 = testPassShouldFail "testRecordInfNames3" (recordInfNameTypes orig) (return ())
|
||||
where
|
||||
orig = A.Rep m (A.ForEach m (simpleName "c") (intLiteral 0)) skipP
|
||||
|
||||
--Returns the list of tests:
|
||||
tests :: Test
|
||||
|
@ -234,6 +239,7 @@ tests = TestList
|
|||
,testRecordInfNames0
|
||||
,testRecordInfNames1
|
||||
,testRecordInfNames2
|
||||
,testRecordInfNames3
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -6,10 +6,7 @@ import Pass
|
|||
import Data.Generics
|
||||
import Types
|
||||
import CompState
|
||||
|
||||
--TODO add passes for:
|
||||
-- Typing the variables
|
||||
|
||||
import Errors
|
||||
|
||||
rainPasses :: A.Process -> PassM A.Process
|
||||
rainPasses = runPasses passes
|
||||
|
@ -46,7 +43,22 @@ recordDeclNameTypes = everywhereM (mkM recordDeclNameTypes')
|
|||
recordDeclNameTypes' s = return s
|
||||
|
||||
recordInfNameTypes :: Data t => t -> PassM t
|
||||
recordInfNameTypes = return
|
||||
recordInfNameTypes = everywhereM (mkM recordInfNameTypes')
|
||||
where
|
||||
recordInfNameTypes' :: A.Replicator -> PassM A.Replicator
|
||||
recordInfNameTypes' input@(A.ForEach m n e)
|
||||
= do arrType <- typeOfExpression e
|
||||
innerT <- case arrType of
|
||||
A.Array (_:innerDims) t ->
|
||||
return $ case innerDims of
|
||||
[] -> t
|
||||
_ -> A.Array innerDims t
|
||||
_ -> dieP m "Cannot do a foreach loop over a non-array type (or array with zero dimensions)"
|
||||
defineName n A.NameDef {A.ndMeta = m, A.ndName = A.nameName n, A.ndOrigName = A.nameName n,
|
||||
A.ndNameType = A.VariableName, A.ndType = (A.Declaration m innerT),
|
||||
A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced}
|
||||
return input
|
||||
recordInfNameTypes' r = return r
|
||||
|
||||
|
||||
transformEach :: Data t => t -> PassM t
|
||||
|
|
Loading…
Reference in New Issue
Block a user