mirror of https://github.com/zachjs/sv2v.git
allow scope traversals to rename tasks and functions
This commit is contained in:
parent
3834b9f109
commit
5161a9e71b
|
|
@ -291,6 +291,14 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items =
|
|||
argIdxDecl ParamType{} = 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 item = do
|
||||
item' <- fullModuleItemMapper item
|
||||
|
|
@ -303,26 +311,23 @@ evalScoperT declMapper moduleItemMapper genItemMapper stmtMapper topName items =
|
|||
return $ Generate $ map GenModuleItem $ injected' ++ [item']
|
||||
fullModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem
|
||||
fullModuleItemMapper (MIPackageItem (Function ml t x decls stmts)) = do
|
||||
(t', x') <- redirectTFDecl t x
|
||||
enterProcedure
|
||||
t' <- do
|
||||
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 ""
|
||||
enterScope x' ""
|
||||
decls' <- mapTFDecls decls
|
||||
stmts' <- mapM fullStmtMapper stmts
|
||||
exitScope x ""
|
||||
exitScope x' ""
|
||||
exitProcedure
|
||||
return $ MIPackageItem $ Function ml t' x decls' stmts'
|
||||
fullModuleItemMapper (MIPackageItem (Task ml x decls stmts)) = do
|
||||
return $ MIPackageItem $ Function ml t' x' decls' stmts'
|
||||
fullModuleItemMapper (MIPackageItem (Task ml x decls stmts)) = do
|
||||
(_, x') <- redirectTFDecl (Implicit Unspecified []) x
|
||||
enterProcedure
|
||||
enterScope x ""
|
||||
enterScope x' ""
|
||||
decls' <- mapTFDecls decls
|
||||
stmts' <- mapM fullStmtMapper stmts
|
||||
exitScope x ""
|
||||
exitScope x' ""
|
||||
exitProcedure
|
||||
return $ MIPackageItem $ Task ml x decls' stmts'
|
||||
return $ MIPackageItem $ Task ml x' decls' stmts'
|
||||
fullModuleItemMapper (MIPackageItem (Decl decl)) =
|
||||
declMapper decl >>= return . MIPackageItem . Decl
|
||||
fullModuleItemMapper (AlwaysC kw stmt) = do
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ traverseDeclM decl = do
|
|||
Variable _ t x _ _ -> do
|
||||
details <- lookupElemM x
|
||||
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
|
||||
Param _ t x _ -> do
|
||||
inProcedure <- withinProcedureM
|
||||
|
|
@ -39,11 +39,11 @@ traverseDeclM decl = do
|
|||
CommentDecl _ -> return decl
|
||||
traverseDeclExprsM traverseExprM decl'
|
||||
|
||||
pattern DuplicateTag :: Type
|
||||
pattern DuplicateTag = Alias ":duplicate_cast_to_be_removed:" []
|
||||
pattern DuplicateTag :: Identifier
|
||||
pattern DuplicateTag = ":duplicate_cast_to_be_removed:"
|
||||
|
||||
dropDuplicateCaster :: ModuleItem -> ModuleItem
|
||||
dropDuplicateCaster (MIPackageItem (Function _ DuplicateTag _ _ _)) =
|
||||
dropDuplicateCaster (MIPackageItem (Function _ _ DuplicateTag _ _)) =
|
||||
Generate []
|
||||
dropDuplicateCaster other = other
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue