From c92af101ef7a3bfc976af17e424ccc4b8a8397d7 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 27 May 2009 13:42:46 +0000 Subject: [PATCH] Added a function for joining together two GraphFuncs for flow analysis --- flow/FlowAlgorithms.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flow/FlowAlgorithms.hs b/flow/FlowAlgorithms.hs index 807b97e..8430900 100644 --- a/flow/FlowAlgorithms.hs +++ b/flow/FlowAlgorithms.hs @@ -48,6 +48,24 @@ data GraphFuncs n e result = GF { ,userErrLabel :: n -> String } +-- Joins together two sets of GraphFuncs into one. For nodesToProcess, nodesToReAdd +-- and userErrLabel it takes the functions from the first argument. The first +-- two should be identical to that for the second argument. This is only common +-- sense; if you try to combine a forward flow algorithm with a backwards flow +-- algorithm, it's not going to work! +joinGraphFuncs :: GraphFuncs n e resultA -> GraphFuncs n e resultB -> GraphFuncs + n e (resultA, resultB) +joinGraphFuncs gfA gfB + = GF { nodeFunc = \ne (rA, rB) mrAB -> + (nodeFunc gfA ne rA (fmap fst mrAB) + ,nodeFunc gfB ne rB (fmap snd mrAB) + ) + , nodesToProcess = nodesToProcess gfA + , nodesToReAdd = nodesToReAdd gfB + , defVal = (defVal gfA, defVal gfB) + , userErrLabel = userErrLabel gfA + } + -- | Given the graph functions, a list of nodes and an entry node, performs -- an iterative data-flow analysis. All the nodes in the list should be connected to -- the starting node, and there should be no nodes without nodes to process