module Language.Clafer.Generator.Stats where
import Control.Monad.State
import Language.Clafer.Intermediate.Intclafer
data Stats = Stats {
naClafers :: Int,
nrClafers :: Int,
ncClafers :: Int,
nConstraints :: Int,
nGoals :: Int,
sglCard :: Interval
} deriving Show
statsModule :: IModule -> Stats
statsModule imodule =
execState (mapM statsElement $ _mDecls imodule) $ Stats 0 0 0 0 0 (1, 1)
statsClafer :: MonadState Stats m => IClafer -> m ()
statsClafer claf = do
if _isAbstract claf
then modify (\e -> e {naClafers = naClafers e + 1})
else
if _isOverlapping $ _super claf
then modify (\e -> e {nrClafers = nrClafers e + 1})
else modify (\e -> e {ncClafers = ncClafers e + 1})
sglCard' <- gets sglCard
modify (\e -> e {sglCard = statsCard sglCard' $ _glCard claf})
mapM_ statsElement $ _elements claf
statsCard :: Interval -> Interval -> Interval
statsCard (m1, n1) (m2, n2) = (max m1 m2, maxEx n1 n2)
where
maxEx m' n' = if m' == 1 || n' == 1 then 1 else max m' n'
statsElement :: MonadState Stats m => IElement -> m ()
statsElement x = case x of
IEClafer clafer -> statsClafer clafer
IEConstraint _ _ -> modify (\e -> e {nConstraints = nConstraints e + 1})
IEGoal _ _ -> modify (\e -> e {nGoals = nGoals e + 1})