X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FdeSugar%2FCoverage.lhs;h=f888d0589459d2fc5a4107d2c48a228c819bf9ef;hb=ab5b8aa357c685a7c702262903bce04c66f79156;hp=36b04041ba8c574a17e0b2114a0865715c57aa4f;hpb=ec3c7841346821c2d5342d0d9c3ff1ae4558aeb6;p=ghc-hetmet.git diff --git a/compiler/deSugar/Coverage.lhs b/compiler/deSugar/Coverage.lhs index 36b0404..f888d05 100644 --- a/compiler/deSugar/Coverage.lhs +++ b/compiler/deSugar/Coverage.lhs @@ -58,11 +58,23 @@ import System.Directory ( createDirectoryIfMissing ) \begin{code} addCoverageTicksToBinds dflags mod mod_loc binds = do + { let orig_file = + case ml_hs_file mod_loc of + Just file -> file + Nothing -> error "can not find the original file during hpc trans" + + ; if "boot" `isSuffixOf` orig_file then return (binds, 0) + else addCoverageTicksToBinds2 dflags mod orig_file binds + } + +addCoverageTicksToBinds2 dflags mod orig_file binds = do let main_mod = mainModIs dflags main_is = case mainFunIs dflags of Nothing -> "main" Just main -> main + modTime <- getModificationTime' orig_file + let mod_name = moduleNameString (moduleName mod) let (binds1,st) @@ -78,12 +90,6 @@ addCoverageTicksToBinds dflags mod mod_loc binds = do -- write the mix entries for this module let tabStop = 1 -- counts as a normal char in GHC's location ranges. - let orig_file = case ml_hs_file mod_loc of - Just file -> file - Nothing -> error "can not find the original file during hpc trans" - - modTime <- getModificationTime' orig_file - createDirectoryIfMissing True hpc_dir mixCreate hpc_dir mod_name (Mix orig_file modTime tabStop $ reverse $ mixEntries st) @@ -122,7 +128,7 @@ addTickLHsBind (L pos (funBind@(FunBind { fun_id = (L _ id) }))) = do let arg_count = matchGroupArity mg let (tys,res_ty) = splitFunTysN arg_count ty - return $ L pos $ funBind { fun_matches = MatchGroup ({-L pos fn_entry:-}matches') ty + return $ L pos $ funBind { fun_matches = MatchGroup matches' ty , fun_tick = tick_no } @@ -289,7 +295,7 @@ addTickHsExpr (HsBinTick _ _ _) = error "addTickhsExpr: HsBinTick _ _ _" addTickHsExpr (HsTick _ _) = error "addTickhsExpr: HsTick _ _" addTickMatchGroup (MatchGroup matches ty) = do - let isOneOfMany = True -- AJG: for now + let isOneOfMany = matchesOneOfMany matches matches' <- mapM (liftL (addTickMatch isOneOfMany)) matches return $ MatchGroup matches' ty @@ -514,6 +520,14 @@ hpcLoc = L hpcSrcSpan \begin{code} +matchesOneOfMany :: [LMatch Id] -> Bool +matchesOneOfMany lmatches = sum (map matchCount lmatches) > 1 + where + matchCount (L _ (Match _pats _ty (GRHSs grhss _binds))) = length grhss +\end{code} + + +\begin{code} --------------------------------------------------------------- -- Datatypes and file-access routines for the per-module (.mix) -- indexes used by Hpc. @@ -553,11 +567,6 @@ mixCreate :: String -> String -> Mix -> IO () mixCreate dirName modName mix = writeFile (mixName dirName modName) (show mix) -readMix :: FilePath -> String -> IO Mix -readMix dirName modName = do - contents <- readFile (mixName dirName modName) - return (read contents) - mixName :: FilePath -> String -> String mixName dirName name = dirName ++ "/" ++ name ++ ".mix" @@ -572,21 +581,6 @@ data Tix = Tix [PixEntry] -- The number of tickboxes in each module type TixEntry = Integer --- always read and write Tix from the current working directory. - -readTix :: String -> IO (Maybe Tix) -readTix pname = - catch (do contents <- readFile $ tixName pname - return $ Just $ read contents) - (\ _ -> return $ Nothing) - -writeTix :: String -> Tix -> IO () -writeTix pname tix = - writeFile (tixName pname) (show tix) - -tixName :: String -> String -tixName name = name ++ ".tix" - -- a program index records module names and numbers of tick-boxes -- introduced in each module that has been transformed for coverage @@ -596,40 +590,6 @@ type PixEntry = ( String -- module name , Int -- number of boxes ) -pixUpdate :: FilePath -> String -> String -> Int -> IO () -pixUpdate dirName progName modName boxCount = do - fileUpdate (pixName dirName progName) pixAssign (Pix []) - where - pixAssign :: Pix -> Pix - pixAssign (Pix pes) = - Pix ((modName,boxCount) : filter ((/=) modName . fst) pes) - -readPix :: FilePath -> String -> IO Pix -readPix dirName pname = do - contents <- readFile (pixName dirName pname) - return (read contents) - -tickCount :: Pix -> Int -tickCount (Pix mp) = sum $ map snd mp - -pixName :: FilePath -> String -> String -pixName dirName name = dirName ++ "/" ++ name ++ ".pix" - --- updating a value stored in a file via read and show -fileUpdate :: (Read a, Show a) => String -> (a->a) -> a -> IO() -fileUpdate fname update init = - catch - (do - valueText <- readFile fname - ( case finite valueText of - True -> - writeFile fname (show (update (read valueText))) )) - (const (writeFile fname (show (update init)))) - -finite :: [a] -> Bool -finite [] = True -finite (x:xs) = finite xs - data HpcPos = P !Int !Int !Int !Int deriving (Eq) fromHpcPos :: HpcPos -> (Int,Int,Int,Int)