Added support for uniquifying function arguments to the Rain passes

This commit is contained in:
Neil Brown 2008-03-22 18:34:07 +00:00
parent 81c342156d
commit ae142a94e1

View File

@ -121,7 +121,25 @@ uniquifyAndResolveVars = everywhereM (mk1M uniquifyAndResolveVars')
A.ndNameType = A.ProcName, A.ndType = newProc, A.ndNameType = A.ProcName, A.ndType = newProc,
A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced} A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced}
return $ A.Spec m (A.Specification m' n newProc) scope return $ A.Spec m (A.Specification m' n newProc) scope
where -- Functions:
uniquifyAndResolveVars' (A.Spec m (A.Specification m' n
(A.Function m'' funcMode retTypes params funcBody)) scope)
= do (params', funcBody') <- doFormals params funcBody
let newFunc = (A.Function m'' funcMode retTypes params' funcBody')
defineName n A.NameDef {A.ndMeta = m', A.ndName = A.nameName n, A.ndOrigName = A.nameName n,
A.ndNameType = A.FunctionName, A.ndType = newFunc,
A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced}
return $ A.Spec m (A.Specification m' n newFunc) scope
-- replicator names have their types recorded later, but are
-- uniquified and resolved here
uniquifyAndResolveVars' (A.Rep m (A.ForEach m' n e) scope)
= do n' <- makeNonce $ A.nameName n
let scope' = everywhere (mkT $ replaceNameName (A.nameName n) n') scope
return $ A.Rep m (A.ForEach m' (n {A.nameName = n'}) e) scope'
--Other:
uniquifyAndResolveVars' s = return s
--This function is like applying mapM to doFormals', but we need to let each doFormals' call in turn --This function is like applying mapM to doFormals', but we need to let each doFormals' call in turn
--transform the scope of the formals. This could possibly be done by using a StateT monad with the scope, --transform the scope of the formals. This could possibly be done by using a StateT monad with the scope,
--but this method works just as well: --but this method works just as well:
@ -141,15 +159,6 @@ uniquifyAndResolveVars = everywhereM (mk1M uniquifyAndResolveVars')
let scope' = everywhere (mkT $ replaceNameName (A.nameName n) n') scope let scope' = everywhere (mkT $ replaceNameName (A.nameName n) n') scope
return (A.Formal am t newName, scope') return (A.Formal am t newName, scope')
-- replicator names have their types recorded later, but are
-- uniquified and resolved here
uniquifyAndResolveVars' (A.Rep m (A.ForEach m' n e) scope)
= do n' <- makeNonce $ A.nameName n
let scope' = everywhere (mkT $ replaceNameName (A.nameName n) n') scope
return $ A.Rep m (A.ForEach m' (n {A.nameName = n'}) e) scope'
--Other:
uniquifyAndResolveVars' s = return s
-- | Helper function for a few of the passes. Replaces 'A.nameName' of a 'A.Name' if it matches a given 'String'. -- | Helper function for a few of the passes. Replaces 'A.nameName' of a 'A.Name' if it matches a given 'String'.
replaceNameName :: replaceNameName ::
String -- ^ The variable name to be replaced. String -- ^ The variable name to be replaced.