{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE Trustworthy #-}
module Language.Haskell.TH.Syntax
  ( module GHC.Internal.TH.Syntax
  , makeRelativeToProject
  , module GHC.Internal.TH.Lift
  , addrToByteArrayName
  , addrToByteArray
  )
where

import GHC.Internal.TH.Syntax
import GHC.Internal.TH.Lift
import System.FilePath
import Data.Array.Byte
import GHC.Exts
import GHC.ST

-- This module completely re-exports 'GHC.Internal.TH.Syntax',
-- and exports additionally functions that depend on filepath.

-- | The input is a filepath, which if relative is offset by the package root.
makeRelativeToProject :: FilePath -> Q FilePath
makeRelativeToProject :: FilePath -> Q FilePath
makeRelativeToProject FilePath
fp | FilePath -> Bool
isRelative FilePath
fp = do
  root <- Q FilePath
getPackageRoot
  return (root </> fp)
makeRelativeToProject FilePath
fp = FilePath -> Q FilePath
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fp

-- The following two defintions are copied from 'Data.Byte.Array'
-- in order to preserve the old export list of 'TH.Syntax'.
-- They will soon be removed as part of #24782.

addrToByteArrayName :: Name
addrToByteArrayName :: Name
addrToByteArrayName = 'addrToByteArray

addrToByteArray :: Int -> Addr# -> ByteArray
addrToByteArray :: Int -> Addr# -> ByteArray
addrToByteArray (I# Int#
len) Addr#
addr = (forall s. ST s ByteArray) -> ByteArray
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s ByteArray) -> ByteArray)
-> (forall s. ST s ByteArray) -> ByteArray
forall a b. (a -> b) -> a -> b
$ STRep s ByteArray -> ST s ByteArray
forall s a. STRep s a -> ST s a
ST (STRep s ByteArray -> ST s ByteArray)
-> STRep s ByteArray -> ST s ByteArray
forall a b. (a -> b) -> a -> b
$
  \State# s
s -> case Int# -> State# s -> (# State# s, MutableByteArray# s #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
len State# s
s of
    (# State# s
s', MutableByteArray# s
mb #) -> case Addr#
-> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
Addr#
-> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
copyAddrToByteArray# Addr#
addr MutableByteArray# s
mb Int#
0# Int#
len State# s
s' of
      State# s
s'' -> case MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# s
mb State# s
s'' of
        (# State# s
s''', ByteArray#
ret #) -> (# State# s
s''', ByteArray# -> ByteArray
ByteArray ByteArray#
ret #)