Make HsRecordBinds a data type instead of a synonym.
[ghc-hetmet.git] / compiler / deSugar / Coverage.lhs
index af9f002..603d721 100644 (file)
@@ -39,6 +39,7 @@ import MkId
 import PrimOp
 import BasicTypes      ( RecFlag(..), Activation(NeverActive), Boxity(..) )
 import Data.List        ( isSuffixOf )
+import FastString       ( unpackFS )
 
 import System.Time (ClockTime(..))
 import System.Directory (getModificationTime)
@@ -258,6 +259,11 @@ addTickHsExpr (ArithSeq     ty arith_seq) =
        liftM2 ArithSeq 
                (return ty)
                (addTickArithSeqInfo arith_seq)
+addTickHsExpr (HsTickPragma (file,(l1,c1),(l2,c2)) (L pos e0)) = do
+    e1 <- addTickHsExpr e0
+    fn <- allocTickBox (ExternalBox (unpackFS file) (P l1 c1 l2 c2)) pos
+    let (L _ e2) = fn $ L pos e1
+    return $ e2
 addTickHsExpr (PArrSeq  {}) = error "addTickHsExpr: PArrSeq    "
 addTickHsExpr (HsSCC    {}) = error "addTickHsExpr: HsSCC      "
 addTickHsExpr (HsCoreAnn   {}) = error "addTickHsExpr: HsCoreAnn  "
@@ -404,7 +410,7 @@ addTickDictBinds :: DictBinds Id -> TM (DictBinds Id)
 addTickDictBinds x = addTickLHsBinds x
 
 addTickHsRecordBinds :: HsRecordBinds Id -> TM (HsRecordBinds Id)
-addTickHsRecordBinds pairs = mapM process pairs
+addTickHsRecordBinds (HsRecordBinds pairs) = liftM HsRecordBinds (mapM process pairs)
     where
        process (ids,expr) = 
                liftM2 (,) 
@@ -555,23 +561,19 @@ data BoxLabel = ExpBox
               | AltBox
               | TopLevelBox [String]
               | LocalBox [String]
-           -- | UserBox (Maybe String)
               | GuardBinBox Bool
               | CondBinBox Bool
               | QualBinBox Bool
-           -- | PreludeBinBox String Bool
-           -- | UserBinBox (Maybe String) Bool
+             | ExternalBox String HpcPos
+                  -- ^The position was generated from the named file/module,
+                  -- with the stated position (inside the named file/module).
+                  -- The HpcPos inside this MixEntry refers to the generated Haskell location.
               deriving (Read, Show)
                          
 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"
 
@@ -586,21 +588,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 
 
@@ -610,40 +597,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)