Commit 5161a9e7 by Zachary Snow

allow scope traversals to rename tasks and functions

parent 3834b9f1
...@@ -291,6 +291,14 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items = ...@@ -291,6 +291,14 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items =
argIdxDecl ParamType{} = Nothing argIdxDecl ParamType{} = Nothing
argIdxDecl CommentDecl{} = Nothing argIdxDecl CommentDecl{} = Nothing
redirectTFDecl :: Type -> Identifier -> ScoperT a m (Type, Identifier)
redirectTFDecl typ ident = do
res <- declMapper $ Variable Local typ ident [] Nil
case res of
Variable Local newType newName [] Nil ->
return (newType, newName)
_ -> error $ "redirected func ret traverse failed: " ++ show res
wrappedModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem wrappedModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem
wrappedModuleItemMapper item = do wrappedModuleItemMapper item = do
item' <- fullModuleItemMapper item item' <- fullModuleItemMapper item
...@@ -303,26 +311,23 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items = ...@@ -303,26 +311,23 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items =
return $ Generate $ map GenModuleItem $ injected' ++ [item'] return $ Generate $ map GenModuleItem $ injected' ++ [item']
fullModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem fullModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem
fullModuleItemMapper (MIPackageItem (Function ml t x decls stmts)) = do fullModuleItemMapper (MIPackageItem (Function ml t x decls stmts)) = do
(t', x') <- redirectTFDecl t x
enterProcedure enterProcedure
t' <- do enterScope x' ""
res <- declMapper $ Variable Local t x [] Nil
case res of
Variable Local newType _ [] Nil -> return newType
_ -> error $ "redirected func ret traverse failed: " ++ show res
enterScope x ""
decls' <- mapTFDecls decls decls' <- mapTFDecls decls
stmts' <- mapM fullStmtMapper stmts stmts' <- mapM fullStmtMapper stmts
exitScope x "" exitScope x' ""
exitProcedure exitProcedure
return $ MIPackageItem $ Function ml t' x decls' stmts' return $ MIPackageItem $ Function ml t' x' decls' stmts'
fullModuleItemMapper (MIPackageItem (Task ml x decls stmts)) = do fullModuleItemMapper (MIPackageItem (Task ml x decls stmts)) = do
(_, x') <- redirectTFDecl (Implicit Unspecified []) x
enterProcedure enterProcedure
enterScope x "" enterScope x' ""
decls' <- mapTFDecls decls decls' <- mapTFDecls decls
stmts' <- mapM fullStmtMapper stmts stmts' <- mapM fullStmtMapper stmts
exitScope x "" exitScope x' ""
exitProcedure exitProcedure
return $ MIPackageItem $ Task ml x decls' stmts' return $ MIPackageItem $ Task ml x' decls' stmts'
fullModuleItemMapper (MIPackageItem (Decl decl)) = fullModuleItemMapper (MIPackageItem (Decl decl)) =
declMapper decl >>= return . MIPackageItem . Decl declMapper decl >>= return . MIPackageItem . Decl
fullModuleItemMapper (AlwaysC kw stmt) = do fullModuleItemMapper (AlwaysC kw stmt) = do
......
...@@ -29,7 +29,7 @@ traverseDeclM decl = do ...@@ -29,7 +29,7 @@ traverseDeclM decl = do
Variable _ t x _ _ -> do Variable _ t x _ _ -> do
details <- lookupElemM x details <- lookupElemM x
if isPrefixOf "sv2v_cast_" x && details /= Nothing if isPrefixOf "sv2v_cast_" x && details /= Nothing
then return $ Variable Local DuplicateTag x [] Nil then return $ Variable Local t DuplicateTag [] Nil
else insertElem x t >> return decl else insertElem x t >> return decl
Param _ t x _ -> do Param _ t x _ -> do
inProcedure <- withinProcedureM inProcedure <- withinProcedureM
...@@ -39,11 +39,11 @@ traverseDeclM decl = do ...@@ -39,11 +39,11 @@ traverseDeclM decl = do
CommentDecl _ -> return decl CommentDecl _ -> return decl
traverseDeclExprsM traverseExprM decl' traverseDeclExprsM traverseExprM decl'
pattern DuplicateTag :: Type pattern DuplicateTag :: Identifier
pattern DuplicateTag = Alias ":duplicate_cast_to_be_removed:" [] pattern DuplicateTag = ":duplicate_cast_to_be_removed:"
dropDuplicateCaster :: ModuleItem -> ModuleItem dropDuplicateCaster :: ModuleItem -> ModuleItem
dropDuplicateCaster (MIPackageItem (Function _ DuplicateTag _ _ _)) = dropDuplicateCaster (MIPackageItem (Function _ _ DuplicateTag _ _)) =
Generate [] Generate []
dropDuplicateCaster other = other dropDuplicateCaster other = other
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment