Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for generic traversals across Futhark syntax trees. The motivation for this module came from dissatisfaction with rewriting the same trivial tree recursions for every module. A possible alternative would be to use normal "Scrap your boilerplate"-techniques, but these are rejected for two reasons:
- They are too slow.
- More importantly, they do not tell you whether you have missed some cases.
Instead, this module defines various traversals of the Futhark syntax tree. The implementation is rather tedious, but the interface is easy to use.
A traversal of the Futhark syntax tree is expressed as a tuple of functions expressing the operations to be performed on the various types of nodes.
The Futhark.Transform.Rename is a simple example of how to use this facility.
Synopsis
- data Mapper flore tlore m = Mapper {
- mapOnSubExp :: SubExp -> m SubExp
- mapOnBody :: Scope tlore -> Body flore -> m (Body tlore)
- mapOnVName :: VName -> m VName
- mapOnCertificates :: Certificates -> m Certificates
- mapOnRetType :: RetType flore -> m (RetType tlore)
- mapOnBranchType :: BranchType flore -> m (BranchType tlore)
- mapOnFParam :: FParam flore -> m (FParam tlore)
- mapOnLParam :: LParam flore -> m (LParam tlore)
- mapOnOp :: Op flore -> m (Op tlore)
- identityMapper :: Monad m => Mapper lore lore m
- mapBody :: (Stm lore -> Stm lore) -> Body lore -> Body lore
- mapExpM :: (Applicative m, Monad m) => Mapper flore tlore m -> Exp flore -> m (Exp tlore)
- mapExp :: Mapper flore tlore Identity -> Exp flore -> Exp tlore
- mapOnType :: Monad m => (SubExp -> m SubExp) -> Type -> m Type
- mapOnLoopForm :: Monad m => Mapper flore tlore m -> LoopForm flore -> m (LoopForm tlore)
- mapOnExtType :: Monad m => Mapper flore tlore m -> TypeBase ExtShape u -> m (TypeBase ExtShape u)
- data Walker lore m = Walker {
- walkOnSubExp :: SubExp -> m ()
- walkOnBody :: Body lore -> m ()
- walkOnVName :: VName -> m ()
- walkOnCertificates :: Certificates -> m ()
- walkOnRetType :: RetType lore -> m ()
- walkOnBranchType :: BranchType lore -> m ()
- walkOnFParam :: FParam lore -> m ()
- walkOnLParam :: LParam lore -> m ()
- walkOnOp :: Op lore -> m ()
- identityWalker :: Monad m => Walker lore m
- walkExpM :: Monad m => Walker lore m -> Exp lore -> m ()
- walkExp :: Walker lore Identity -> Exp lore -> ()
Mapping
data Mapper flore tlore m Source #
Express a monad mapping operation on a syntax node. Each element of this structure expresses the operation to be performed on a given child.
Mapper | |
|
identityMapper :: Monad m => Mapper lore lore m Source #
A mapper that simply returns the tree verbatim.
mapBody :: (Stm lore -> Stm lore) -> Body lore -> Body lore Source #
Map across the bindings of a BodyT
.
mapExpM :: (Applicative m, Monad m) => Mapper flore tlore m -> Exp flore -> m (Exp tlore) Source #
Map a monadic action across the immediate children of an
expression. Importantly, the mapOnExp
action is not invoked for
the expression itself, and the mapping does not descend recursively
into subexpressions. The mapping is done left-to-right.
mapOnExtType :: Monad m => Mapper flore tlore m -> TypeBase ExtShape u -> m (TypeBase ExtShape u) Source #
Walking
Express a monad expression on a syntax node. Each element of this structure expresses the action to be performed on a given child.
Walker | |
|
identityWalker :: Monad m => Walker lore m Source #
A no-op traversal.