module Trace.Hpc.Codecov.Lix where
import Data.List
import Data.Ord
import Prelude hiding (getLine)
import Trace.Hpc.Codecov.Types
import Trace.Hpc.Codecov.Util
import Trace.Hpc.Mix
import Trace.Hpc.Util
toHit :: [Bool] -> Hit
toHit [] = Irrelevant
toHit [x] = if x then Full else None
toHit xs
| and xs = Full
| or xs = Partial
| otherwise = None
getLine :: MixEntry -> Int
getLine = fffst . fromHpcPos . fst
where fffst (x, _, _, _) = x
toLineHit :: CoverageEntry -> (Int, Bool)
toLineHit (entry, cnt, _source) = (getLine entry 1, cnt > 0)
adjust :: CoverageEntry -> CoverageEntry
adjust coverageEntry@(mixEntry, _, source) = case (snd mixEntry, source) of
(BinBox GuardBinBox False, ["otherwise"]) -> (mixEntry, 1, source)
_ -> coverageEntry
toLix :: Int
-> [CoverageEntry]
-> Lix
toLix lineCount entries = map toHit (groupByIndex lineCount sortedLineHits)
where sortedLineHits = sortBy (comparing fst) lineHits
lineHits = map (toLineHit . adjust) entries