Commit c28bb71a by Zachary Snow

more careful expr and type traversals

parent efe8de39
......@@ -55,7 +55,8 @@ convertDescription' description =
where
-- replace and collect the enum types in this description
(description', enums) = runWriter $
traverseModuleItemsM (traverseTypesM traverseType) description
traverseModuleItemsM traverseModuleItemM description
traverseModuleItemM = traverseTypesM $ traverseNestedTypesM traverseType
-- convert the collected enums into their corresponding localparams
enumItems = concatMap makeEnumItems $ Set.toList enums
......
......@@ -14,7 +14,7 @@ convert =
map $
traverseDescriptions $
traverseModuleItems $
traverseTypes convertType
traverseTypes $ traverseNestedTypes convertType
convertType :: Type -> Type
convertType (IntegerAtom kw sg) = elaborateIntegerAtom $ IntegerAtom kw sg
......
......@@ -124,7 +124,7 @@ prefixPackageItem packageName idents item =
convertLHSM other = return other
convertModuleItemM =
traverseTypesM convertTypeM >=>
traverseTypesM (traverseNestedTypesM convertTypeM) >=>
traverseExprsM (traverseNestedExprsM convertExprM) >=>
traverseLHSsM (traverseNestedLHSsM convertLHSM )
convertStmtM =
......
......@@ -243,7 +243,7 @@ isSimpleType typ =
Union _ fields _ -> all (isSimpleType . fst) fields
_ -> False
-- returns whether a type contains any dimension queries
-- returns whether a top-level type contains any dimension queries
typeHasQueries :: Type -> Bool
typeHasQueries =
not . null . execWriter . collectTypeExprsM
......@@ -257,8 +257,9 @@ typeHasQueries =
collectUnresolvedExprM _ = return ()
prepareTypeIdents :: Identifier -> Type -> (Type, IdentSet)
prepareTypeIdents prefix typ =
runWriter $ traverseTypeExprsM (traverseNestedExprsM prepareExprIdents) typ
prepareTypeIdents prefix =
runWriter . traverseNestedTypesM
(traverseTypeExprsM $ traverseNestedExprsM prepareExprIdents)
where
prepareExprIdents :: Expr -> Writer IdentSet Expr
prepareExprIdents (Ident x) = do
......
......@@ -58,7 +58,7 @@ traverseModuleItemM (Instance m p x rs l) = do
traverseExprsM traverseExprM $ Instance m p' x rs l
where
paramBindingMapper (param, Left t) = do
t' <- traverseTypeExprsM substituteExprM t
t' <- traverseNestedTypesM (traverseTypeExprsM substituteExprM) t
return (param, Left t')
paramBindingMapper (param, Right e) = return (param, Right e)
traverseModuleItemM item = traverseExprsM traverseExprM item
......
......@@ -24,7 +24,8 @@ convert = map $ traverseDescriptions convertDescription
convertDescription :: Description -> Description
convertDescription (description @ (Part _ _ Module _ _ _ _)) =
traverseModuleItems (traverseTypes' ExcludeParamTypes convertType) $
traverseModuleItems
(traverseTypes' ExcludeParamTypes $ traverseNestedTypes convertType) $
partScoper traverseDeclM traverseModuleItemM traverseGenItemM traverseStmtM
description
convertDescription other = other
......
......@@ -38,7 +38,7 @@ traverseDeclM decl = do
CommentDecl{} -> return decl'
traverseModuleItemM :: ModuleItem -> Scoper Type ModuleItem
traverseModuleItemM = traverseTypesM traverseTypeM
traverseModuleItemM = traverseTypesM $ traverseNestedTypesM traverseTypeM
traverseGenItemM :: GenItem -> Scoper Type GenItem
traverseGenItemM = traverseGenItemExprsM traverseExprM
......@@ -47,7 +47,8 @@ traverseStmtM :: Stmt -> Scoper Type Stmt
traverseStmtM = traverseStmtExprsM traverseExprM
traverseExprM :: Expr -> Scoper Type Expr
traverseExprM = traverseNestedExprsM $ traverseExprTypesM traverseTypeM
traverseExprM = traverseNestedExprsM $ traverseExprTypesM $
traverseNestedTypesM traverseTypeM
traverseTypeM :: Type -> Scoper Type Type
traverseTypeM (TypeOf expr) = typeof expr
......@@ -62,7 +63,9 @@ lookupTypeOf expr = do
Just (_, _, Implicit Unspecified []) ->
return $ IntegerVector TLogic Unspecified []
Just (_, replacements, typ) ->
return $ rewriteType typ
return $ if Map.null replacements
then typ
else rewriteType typ
where
rewriteType = traverseNestedTypes $ traverseTypeExprs $
traverseNestedExprs replace
......
......@@ -57,7 +57,7 @@ traverseModuleItemM item = traverseModuleItemM' item
traverseModuleItemM' :: ModuleItem -> Scoper Type ModuleItem
traverseModuleItemM' =
traverseTypesM traverseTypeM >=>
traverseTypesM (traverseNestedTypesM traverseTypeM) >=>
traverseExprsM (traverseNestedExprsM traverseExprM)
traverseGenItemM :: GenItem -> Scoper Type GenItem
......
......@@ -18,7 +18,7 @@ convert =
map $
traverseDescriptions $
traverseModuleItems $
traverseTypes convertType
traverseTypes $ traverseNestedTypes convertType
convertType :: Type -> Type
convertType (Implicit Unsigned rs) = Implicit Unspecified rs
......
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