Changed the types in RainUsageCheck and RainUsageCheckTest to match the changes to FlowGraph's type

This commit is contained in:
Neil Brown 2007-11-07 13:45:43 +00:00
parent fbbe539bc0
commit 78b3c038c3
2 changed files with 17 additions and 15 deletions

View File

@ -282,16 +282,16 @@ isSubsetOf (NormalSet a) (NormalSet b) = Set.isSubsetOf a b
-- TODO have some sort of error-message return if the check fails or if the code fails
checkInitVar :: FlowGraph (Maybe Decl, Vars) -> Node -> Either String ()
checkInitVar :: forall m. Monad m => FlowGraph m (Maybe Decl, Vars) -> Node -> Either String ()
checkInitVar graph startNode
= do vwb <- varWrittenBefore
mapM_ (checkInitVar' vwb) (map readNode (labNodes graph))
where
readNode :: (Node, FNode (Maybe Decl, Vars)) -> (Node, ExSet Var)
readNode (n, Node (_,(_,Vars read _ _ _))) = (n,NormalSet read)
readNode :: (Node, FNode m (Maybe Decl, Vars)) -> (Node, ExSet Var)
readNode (n, Node (_,(_,Vars read _ _ _),_)) = (n,NormalSet read)
writeNode :: FNode (Maybe Decl, Vars) -> ExSet Var
writeNode (Node (_,(_,Vars _ _ written _))) = NormalSet written
writeNode :: FNode m (Maybe Decl, Vars) -> ExSet Var
writeNode (Node (_,(_,Vars _ _ written _),_)) = NormalSet written
-- Nothing is treated as if were the set of all possible variables (easier than building that set):
nodeFunction :: (Node, EdgeLabel) -> ExSet Var -> Maybe (ExSet Var) -> ExSet Var
@ -325,7 +325,8 @@ checkInitVar graph startNode
-- I considered having the return type be Map Var (Map Node x)) rather than Map (Var,Node) x, but the time for lookup
-- will be identical (log N + log V in the former case, log (V*N) in the latter), and having a pair seemed simpler.
findReachDef :: FlowGraph (Maybe Decl, Vars) -> Node -> Either String (Map.Map Node (Map.Map Var (Set.Set Node)))
-- TODO correct that comment!
findReachDef :: forall m. Monad m => FlowGraph m (Maybe Decl, Vars) -> Node -> Either String (Map.Map Node (Map.Map Var (Set.Set Node)))
findReachDef graph startNode
= do r <- flowAlgorithm graphFuncs (nodes graph) startNode
-- These lines remove the maps where the variable is not read in that particular node:
@ -345,18 +346,18 @@ findReachDef graph startNode
readInNode' :: Node -> Var -> a -> Bool
readInNode' n v _ = readInNode v (lab graph n)
readInNode :: Var -> Maybe (FNode (Maybe Decl, Vars)) -> Bool
readInNode v (Just (Node (_,(_,Vars read _ _ _)))) = Set.member v read
readInNode :: Var -> Maybe (FNode m (Maybe Decl, Vars)) -> Bool
readInNode v (Just (Node (_,(_,Vars read _ _ _),_))) = Set.member v read
writeNode :: FNode (Maybe Decl, Vars) -> Set.Set Var
writeNode (Node (_,(_,Vars _ _ written _))) = written
writeNode :: FNode m (Maybe Decl, Vars) -> Set.Set Var
writeNode (Node (_,(_,Vars _ _ written _),_)) = written
-- | A confusiing function used by processNode. It takes a node and node label, and uses
-- these to form a multi-map modifier function that replaces all node-sources for variables
-- written to by the given with node with a singleton set containing the given node.
-- That is, nodeLabelToMapInsert N (Node (_,Vars _ written _ _)) is a function that replaces
-- the sets for each v (v in written) with a singleton set {N}.
nodeLabelToMapInsert :: Node -> FNode (Maybe Decl, Vars) -> Map.Map Var (Set.Set Node) -> Map.Map Var (Set.Set Node)
nodeLabelToMapInsert :: Node -> FNode m (Maybe Decl, Vars) -> Map.Map Var (Set.Set Node) -> Map.Map Var (Set.Set Node)
nodeLabelToMapInsert n = foldFuncs . (map (\v -> Map.insert v (Set.singleton n) )) . Set.toList . writeNode
processNode :: (Node, EdgeLabel) -> Map.Map Var (Set.Set Node) -> Maybe (Map.Map Var (Set.Set Node)) -> Map.Map Var (Set.Set Node)

View File

@ -18,6 +18,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
module RainUsageCheckTest (tests) where
import Control.Monad.Identity
import Data.Graph.Inductive
import qualified Data.Map as Map
import qualified Data.Set as Set
@ -134,14 +135,14 @@ testParUsageCheck = TestList (map doTest tests)
--TODO add tests for initialising a variable before use.
--TODO especially test things like only initialising the variable in one part of an if
buildTestFlowGraph :: [(Int, [Var], [Var], [Var])] -> [(Int, Int, EdgeLabel)] -> Int -> Int -> String -> FlowGraph (Maybe Decl, Vars)
buildTestFlowGraph :: [(Int, [Var], [Var], [Var])] -> [(Int, Int, EdgeLabel)] -> Int -> Int -> String -> FlowGraph Identity (Maybe Decl, Vars)
buildTestFlowGraph ns es start end v
= mkGraph
([(-1,Node (emptyMeta,(Just $ ScopeIn v, emptyVars))),(-2,Node (emptyMeta,(Just $ ScopeOut v,emptyVars)))] ++ (map transNode ns))
([(-1,Node (emptyMeta,(Just $ ScopeIn v, emptyVars), undefined)),(-2,Node (emptyMeta,(Just $ ScopeOut v,emptyVars), undefined))] ++ (map transNode ns))
([(-1,start,ESeq),(end,-2,ESeq)] ++ es)
where
transNode :: (Int, [Var], [Var], [Var]) -> (Int, FNode (Maybe Decl, Vars))
transNode (n,mr,mw,dw) = (n,Node (emptyMeta, (Nothing,vars mr mw dw [])))
transNode :: (Int, [Var], [Var], [Var]) -> (Int, FNode Identity (Maybe Decl, Vars))
transNode (n,mr,mw,dw) = (n,Node (emptyMeta, (Nothing,vars mr mw dw []), undefined))
testInitVar :: Test
testInitVar = TestList