From d0b1b3d4645b273473a57f5dbc8d19f4f7c82209 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 29 Jan 2008 16:58:46 +0000 Subject: [PATCH] Changed checkPlainVarUsage and checkInitVar to apply only to plain variables --- checks/Check.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/checks/Check.hs b/checks/Check.hs index e1da961..b618f0e 100644 --- a/checks/Check.hs +++ b/checks/Check.hs @@ -51,9 +51,18 @@ usageCheckPass t = do g' <- buildFlowGraph labelFunctions t checkParAssignUsage t checkProcCallArgsUsage t mapM_ (checkInitVar (findMeta t) g) roots - -- TODO add checkInitVar here (need to find roots in the tree) return t +filterPlain :: Set.Set Var -> Set.Set Var +filterPlain = Set.filter plain + where + plain (Var (A.Variable {})) = True + plain _ = False + +filterPlain' :: ExSet Var -> ExSet Var +filterPlain' Everything = Everything +filterPlain' (NormalSet s) = NormalSet $ filterPlain s + -- | I am not sure how you could build this out of the standard functions, so I built it myself --Takes a list (let's say Y), a function that applies to a single item and a list, and then goes through applying the function --to each item in the list, with the rest of the list Y as a parameter. Perhaps the code is clearer: @@ -87,9 +96,8 @@ checkPlainVarUsage (m, p) = check p diePC (findMeta (head $ Set.elems writtenAndRead)) $ formatCode "The following variables are written-to and read-from in separate branches of a PAR: %" writtenAndRead where - writtenTwice = writtenVars item `Set.intersection` writtenVars otherVars - writtenAndRead = writtenVars item `Set.intersection` readVars otherVars - + writtenTwice = filterPlain $ writtenVars item `Set.intersection` writtenVars otherVars + writtenAndRead = filterPlain $ writtenVars item `Set.intersection` readVars otherVars otherVars = foldUnionVars rest -- | A custom Set wrapper that allows for easy representation of the "everything" set. @@ -170,7 +178,7 @@ checkInitVar m graph startNode checkInitVar' writtenMap (n,v) = let vs = fromMaybe emptySet (Map.lookup n writtenMap) in -- The read-from set should be a subset of the written-to set: - if v `isSubsetOf` vs then return () else + if filterPlain' v `isSubsetOf` filterPlain' vs then return () else do readVars <- showCodeExSet v writtenVars <- showCodeExSet vs dieP (getMeta n) $ "Variable read from is not written to before-hand, sets are read: " ++ show readVars ++ " and written: " ++ show writtenVars