Rain: Added to the resolving pass to make it pass all the tests

This commit is contained in:
Neil Brown 2007-08-22 15:54:34 +00:00
parent 1620528958
commit d065338efe

View File

@ -67,11 +67,32 @@ uniquifyAndResolveVars = everywhereM (mkM uniquifyAndResolveVars')
return $ A.Spec m (A.Specification m' n {A.nameName = n'} decl) scope'
--Processes:
uniquifyAndResolveVars' input@(A.Spec _ (A.Specification m' n decl@(A.Proc {})) _)
= do defineName n A.NameDef {A.ndMeta = m', A.ndName = A.nameName n, A.ndOrigName = A.nameName n,
A.ndNameType = A.ProcName, A.ndType = decl,
uniquifyAndResolveVars' (A.Spec m (A.Specification m' n (A.Proc m'' procMode params procBody)) scope)
= do (params',procBody') <- doFormals params procBody
let newProc = (A.Proc m'' procMode params' procBody')
defineName n A.NameDef {A.ndMeta = m', A.ndName = A.nameName n, A.ndOrigName = A.nameName n,
A.ndNameType = A.ProcName, A.ndType = newProc,
A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced}
return input
return $ A.Spec m (A.Specification m' n newProc) scope
where
--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,
--but this method works just as well:
doFormals :: Data t => [A.Formal] -> t -> PassM ([A.Formal],t)
doFormals [] s = return ([],s)
doFormals (f:fs) s = do (f',s') <- doFormals' f s
(fs',s'') <- doFormals fs s'
return ((f':fs'),s'')
doFormals' :: Data t => A.Formal -> t -> PassM (A.Formal,t)
doFormals' (A.Formal am t n) scope
= do n' <- makeNonce $ A.nameName n
let newName = (n {A.nameName = n'})
let m = A.nameMeta n
defineName newName A.NameDef {A.ndMeta = m, A.ndName = n', A.ndOrigName = A.nameName n,
A.ndNameType = A.VariableName, A.ndType = (A.Declaration m t),
A.ndAbbrevMode = am, A.ndPlacement = A.Unplaced}
let scope' = everywhere (mkT $ replaceNameName (A.nameName n) n') scope
return (A.Formal am t newName, scope')
--Other:
uniquifyAndResolveVars' s = return s