{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module GHC.Unit.Module.Location
( ModLocation(..)
, addBootSuffix
, addBootSuffixLocn
, addBootSuffixLocnOut
, removeBootSuffix
, mkFileSrcSpan
, ml_hs_file
, ml_hi_file
, ml_dyn_hi_file
, ml_obj_file
, ml_dyn_obj_file
, ml_hie_file
, ml_bytecode_file
)
where
import GHC.Prelude
import GHC.Data.OsPath
import GHC.Types.SrcLoc
import GHC.Utils.Outputable
import GHC.Data.FastString (mkFastString)
import qualified System.OsString as OsString
data ModLocation
= OsPathModLocation {
ModLocation -> Maybe OsPath
ml_hs_file_ospath :: Maybe OsPath,
ModLocation -> OsPath
ml_hi_file_ospath :: OsPath,
ModLocation -> OsPath
ml_dyn_hi_file_ospath :: OsPath,
ModLocation -> OsPath
ml_obj_file_ospath :: OsPath,
ModLocation -> OsPath
ml_dyn_obj_file_ospath :: OsPath,
ModLocation -> OsPath
ml_hie_file_ospath :: OsPath,
ModLocation -> OsPath
ml_bytecode_file_ospath :: OsPath
} deriving Int -> ModLocation -> ShowS
[ModLocation] -> ShowS
ModLocation -> String
(Int -> ModLocation -> ShowS)
-> (ModLocation -> String)
-> ([ModLocation] -> ShowS)
-> Show ModLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModLocation -> ShowS
showsPrec :: Int -> ModLocation -> ShowS
$cshow :: ModLocation -> String
show :: ModLocation -> String
$cshowList :: [ModLocation] -> ShowS
showList :: [ModLocation] -> ShowS
Show
instance Outputable ModLocation where
ppr :: ModLocation -> SDoc
ppr = String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> (ModLocation -> String) -> ModLocation -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> String
forall a. Show a => a -> String
show
addBootSuffix :: OsPath -> OsPath
addBootSuffix :: OsPath -> OsPath
addBootSuffix OsPath
path = OsPath
path OsPath -> OsPath -> OsPath
forall a. Monoid a => a -> a -> a
`mappend` String -> OsPath
os String
"-boot"
removeBootSuffix :: OsPath -> OsPath
removeBootSuffix :: OsPath -> OsPath
removeBootSuffix OsPath
pathWithBootSuffix =
case OsPath -> OsPath -> Maybe OsPath
OsString.stripSuffix (String -> OsPath
os String
"-boot") OsPath
pathWithBootSuffix of
Just OsPath
path -> OsPath
path
Maybe OsPath
Nothing -> String -> OsPath
forall a. HasCallStack => String -> a
error String
"removeBootSuffix: no -boot suffix"
addBootSuffixLocn :: ModLocation -> ModLocation
addBootSuffixLocn :: ModLocation -> ModLocation
addBootSuffixLocn ModLocation
locn
= ModLocation -> ModLocation
addBootSuffixLocnOut ModLocation
locn { ml_hs_file_ospath = fmap addBootSuffix (ml_hs_file_ospath locn) }
addBootSuffixLocnOut :: ModLocation -> ModLocation
addBootSuffixLocnOut :: ModLocation -> ModLocation
addBootSuffixLocnOut ModLocation
locn
= ModLocation
locn { ml_hi_file_ospath = addBootSuffix (ml_hi_file_ospath locn)
, ml_dyn_hi_file_ospath = addBootSuffix (ml_dyn_hi_file_ospath locn)
, ml_obj_file_ospath = addBootSuffix (ml_obj_file_ospath locn)
, ml_dyn_obj_file_ospath = addBootSuffix (ml_dyn_obj_file_ospath locn)
, ml_hie_file_ospath = addBootSuffix (ml_hie_file_ospath locn)
}
mkFileSrcSpan :: ModLocation -> SrcSpan
mkFileSrcSpan :: ModLocation -> SrcSpan
mkFileSrcSpan ModLocation
mod_loc
= case ModLocation -> Maybe String
ml_hs_file ModLocation
mod_loc of
Just String
file_path -> FastString -> SrcSpan
mkGeneralSrcSpan (String -> FastString
mkFastString String
file_path)
Maybe String
Nothing -> SrcSpan
interactiveSrcSpan
ml_hs_file :: ModLocation -> Maybe FilePath
{-# INLINE ml_hs_file #-}
ml_hs_file :: ModLocation -> Maybe String
ml_hs_file = (OsPath -> String) -> Maybe OsPath -> Maybe String
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (Maybe OsPath -> Maybe String)
-> (ModLocation -> Maybe OsPath) -> ModLocation -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> Maybe OsPath
ml_hs_file_ospath
ml_hi_file :: ModLocation -> FilePath
{-# INLINE ml_hi_file #-}
ml_hi_file :: ModLocation -> String
ml_hi_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_hi_file_ospath
ml_dyn_hi_file :: ModLocation -> FilePath
{-# INLINE ml_dyn_hi_file #-}
ml_dyn_hi_file :: ModLocation -> String
ml_dyn_hi_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_dyn_hi_file_ospath
ml_obj_file :: ModLocation -> FilePath
{-# INLINE ml_obj_file #-}
ml_obj_file :: ModLocation -> String
ml_obj_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_obj_file_ospath
ml_dyn_obj_file :: ModLocation -> FilePath
{-# INLINE ml_dyn_obj_file #-}
ml_dyn_obj_file :: ModLocation -> String
ml_dyn_obj_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_dyn_obj_file_ospath
ml_hie_file :: ModLocation -> FilePath
{-# INLINE ml_hie_file #-}
ml_hie_file :: ModLocation -> String
ml_hie_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_hie_file_ospath
ml_bytecode_file :: ModLocation -> FilePath
{-# INLINE ml_bytecode_file #-}
ml_bytecode_file :: ModLocation -> String
ml_bytecode_file = HasCallStack => OsPath -> String
OsPath -> String
unsafeDecodeUtf (OsPath -> String)
-> (ModLocation -> OsPath) -> ModLocation -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> OsPath
ml_bytecode_file_ospath