From 6fc4ac955031ee4c2527503c9f151d6e7d1da8b2 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 13 Nov 2008 15:37:02 +0000 Subject: [PATCH] Added a warning when we removed an unused variable --- checks/Check.hs | 5 +++-- checks/CheckFramework.hs | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/checks/Check.hs b/checks/Check.hs index 97208e7..1758a4d 100644 --- a/checks/Check.hs +++ b/checks/Check.hs @@ -278,11 +278,12 @@ checkProcCallArgsUsage = mapM_ checkArgs . listify isProcCall checkUnusedVar :: CheckOptM () checkUnusedVar = forAnyAST doSpec where - doSpec (A.Spec _ (A.Specification _ name _) scope :: A.Structured A.Process) + doSpec (A.Spec _ (A.Specification mspec name _) scope :: A.Structured A.Process) = do vars <- withChild [1] $ getCachedAnalysis' isScopeIn varsTouchedAfter liftIO $ putStrLn $ "Vars: " ++ show vars when (not $ (Var $ A.Variable emptyMeta name) `Set.member` vars) $ - substitute scope + do warnPC mspec WarnUnusedVariable $ formatCode "Unused variable: %" name + substitute scope doSpec _ = return () isScopeIn :: UsageLabel -> Bool diff --git a/checks/CheckFramework.hs b/checks/CheckFramework.hs index 98bc8b8..86823e9 100644 --- a/checks/CheckFramework.hs +++ b/checks/CheckFramework.hs @@ -117,6 +117,9 @@ instance Die CheckOptM where instance CSMR CheckOptM where getCompState = CheckOptM . lift $ getCompState +instance Warn CheckOptM where + warnReport = CheckOptM . lift . warnReport + deCheckOptM :: CheckOptM a -> StateT CheckOptData PassM a deCheckOptM (CheckOptM x) = x @@ -154,6 +157,12 @@ instance Die m => Die (ReaderT (Route t outer) m) where instance Die (CheckOptM' t) where dieReport = liftCheckOptM . dieReport +instance Warn (CheckOptM' t) where + warnReport = liftCheckOptM . warnReport + +instance CSMR (CheckOptM' t) where + getCompState = liftCheckOptM getCompState + askRoute :: CheckOptM' t (Route t A.AST) askRoute = CheckOptM' . RestartT . liftM Right $ ask