Commit 82228f67 by Zachary Snow

typedef conversion avoids excess traversals

parent 2b9fff78
...@@ -35,14 +35,19 @@ traverseTypeOrExprM other = return other ...@@ -35,14 +35,19 @@ traverseTypeOrExprM other = return other
traverseExprM :: Expr -> Scoper Type Expr traverseExprM :: Expr -> Scoper Type Expr
traverseExprM (Cast v e) = do traverseExprM (Cast v e) = do
v' <- traverseTypeOrExprM v v' <- traverseTypeOrExprM v
return $ Cast v' e traverseExprM' $ Cast v' e
traverseExprM (DimsFn f v) = do traverseExprM (DimsFn f v) = do
v' <- traverseTypeOrExprM v v' <- traverseTypeOrExprM v
return $ DimsFn f v' traverseExprM' $ DimsFn f v'
traverseExprM (DimFn f v e) = do traverseExprM (DimFn f v e) = do
v' <- traverseTypeOrExprM v v' <- traverseTypeOrExprM v
return $ DimFn f v' e traverseExprM' $ DimFn f v' e
traverseExprM other = return other traverseExprM other = traverseExprM' other
traverseExprM' :: Expr -> Scoper Type Expr
traverseExprM' =
traverseSinglyNestedExprsM traverseExprM
>=> traverseExprTypesM traverseTypeM
traverseModuleItemM :: ModuleItem -> Scoper Type ModuleItem traverseModuleItemM :: ModuleItem -> Scoper Type ModuleItem
traverseModuleItemM (Instance m params x rs p) = do traverseModuleItemM (Instance m params x rs p) = do
...@@ -53,39 +58,42 @@ traverseModuleItemM item = traverseModuleItemM' item ...@@ -53,39 +58,42 @@ traverseModuleItemM item = traverseModuleItemM' item
traverseModuleItemM' :: ModuleItem -> Scoper Type ModuleItem traverseModuleItemM' :: ModuleItem -> Scoper Type ModuleItem
traverseModuleItemM' = traverseModuleItemM' =
traverseTypesM (traverseNestedTypesM traverseTypeM) >=> traverseNodesM traverseExprM return traverseTypeM traverseLHSM return
traverseExprsM (traverseNestedExprsM traverseExprM) where traverseLHSM = traverseLHSExprsM traverseExprM
traverseGenItemM :: GenItem -> Scoper Type GenItem traverseGenItemM :: GenItem -> Scoper Type GenItem
traverseGenItemM = traverseGenItemExprsM (traverseNestedExprsM traverseExprM) traverseGenItemM = traverseGenItemExprsM traverseExprM
traverseDeclM :: Decl -> Scoper Type Decl traverseDeclM :: Decl -> Scoper Type Decl
traverseDeclM decl = do traverseDeclM decl = do
item <- traverseModuleItemM (MIPackageItem $ Decl decl) decl' <- traverseDeclExprsM traverseExprM decl
let MIPackageItem (Decl decl') = item >>= traverseDeclTypesM traverseTypeM
case decl' of case decl' of
Variable{} -> return decl' Variable{} -> return decl'
Param{} -> return decl' Param{} -> return decl'
ParamType Localparam x t -> do ParamType Localparam x t -> do
t' <- traverseNestedTypesM traverseTypeM t traverseTypeM t >>= insertElem x
insertElem x t'
return $ CommentDecl $ "removed localparam type " ++ x return $ CommentDecl $ "removed localparam type " ++ x
ParamType{} -> return decl' ParamType{} -> return decl'
CommentDecl{} -> return decl' CommentDecl{} -> return decl'
traverseStmtM :: Stmt -> Scoper Type Stmt traverseStmtM :: Stmt -> Scoper Type Stmt
traverseStmtM = traverseStmtExprsM $ traverseNestedExprsM traverseStmtExprM traverseStmtM = traverseStmtExprsM traverseExprM
where
traverseStmtExprM :: Expr -> Scoper Type Expr
traverseStmtExprM =
traverseExprTypesM (traverseNestedTypesM traverseTypeM) >=>
traverseExprM
traverseTypeM :: Type -> Scoper Type Type traverseTypeM :: Type -> Scoper Type Type
traverseTypeM (Alias st rs1) = do traverseTypeM (Alias st rs1) = do
details <- lookupElemM st details <- lookupElemM st
rs1' <- mapM traverseRangeM rs1
return $ case details of return $ case details of
Nothing -> Alias st rs1 Nothing -> Alias st rs1'
Just (_, _, typ) -> tf $ rs1 ++ rs2 Just (_, _, typ) -> tf $ rs1' ++ rs2
where (tf, rs2) = typeRanges typ where (tf, rs2) = typeRanges typ
traverseTypeM other = return other traverseTypeM other =
traverseSinglyNestedTypesM traverseTypeM other
>>= traverseTypeExprsM traverseExprM
traverseRangeM :: Range -> Scoper Type Range
traverseRangeM (a, b) = do
a' <- traverseExprM a
b' <- traverseExprM b
return (a', b')
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