{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module HieDb.Types where

import Prelude hiding (mod)

import Data.IORef

import qualified Data.Text as T
import qualified Data.Text.Encoding as T

import Control.Monad.IO.Class
import Control.Monad.Reader
import Control.Exception

import Data.List.NonEmpty (NonEmpty(..))

import Data.Int

import Database.SQLite.Simple
import Database.SQLite.Simple.ToField
import Database.SQLite.Simple.FromField

import qualified Text.ParserCombinators.ReadP as R

import HieDb.Compat

newtype HieDb = HieDb { HieDb -> Connection
getConn :: Connection }

data HieDbException
  = IncompatibleSchemaVersion
  { HieDbException -> Integer
expectedVersion :: Integer, HieDbException -> Integer
gotVersion :: Integer }
  deriving (HieDbException -> HieDbException -> Bool
(HieDbException -> HieDbException -> Bool)
-> (HieDbException -> HieDbException -> Bool) -> Eq HieDbException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HieDbException -> HieDbException -> Bool
== :: HieDbException -> HieDbException -> Bool
$c/= :: HieDbException -> HieDbException -> Bool
/= :: HieDbException -> HieDbException -> Bool
Eq,Eq HieDbException
Eq HieDbException =>
(HieDbException -> HieDbException -> Ordering)
-> (HieDbException -> HieDbException -> Bool)
-> (HieDbException -> HieDbException -> Bool)
-> (HieDbException -> HieDbException -> Bool)
-> (HieDbException -> HieDbException -> Bool)
-> (HieDbException -> HieDbException -> HieDbException)
-> (HieDbException -> HieDbException -> HieDbException)
-> Ord HieDbException
HieDbException -> HieDbException -> Bool
HieDbException -> HieDbException -> Ordering
HieDbException -> HieDbException -> HieDbException
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HieDbException -> HieDbException -> Ordering
compare :: HieDbException -> HieDbException -> Ordering
$c< :: HieDbException -> HieDbException -> Bool
< :: HieDbException -> HieDbException -> Bool
$c<= :: HieDbException -> HieDbException -> Bool
<= :: HieDbException -> HieDbException -> Bool
$c> :: HieDbException -> HieDbException -> Bool
> :: HieDbException -> HieDbException -> Bool
$c>= :: HieDbException -> HieDbException -> Bool
>= :: HieDbException -> HieDbException -> Bool
$cmax :: HieDbException -> HieDbException -> HieDbException
max :: HieDbException -> HieDbException -> HieDbException
$cmin :: HieDbException -> HieDbException -> HieDbException
min :: HieDbException -> HieDbException -> HieDbException
Ord,Int -> HieDbException -> ShowS
[HieDbException] -> ShowS
HieDbException -> [Char]
(Int -> HieDbException -> ShowS)
-> (HieDbException -> [Char])
-> ([HieDbException] -> ShowS)
-> Show HieDbException
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HieDbException -> ShowS
showsPrec :: Int -> HieDbException -> ShowS
$cshow :: HieDbException -> [Char]
show :: HieDbException -> [Char]
$cshowList :: [HieDbException] -> ShowS
showList :: [HieDbException] -> ShowS
Show)

instance Exception HieDbException where

setHieTrace :: HieDb -> Maybe (T.Text -> IO ()) -> IO ()
setHieTrace :: HieDb -> Maybe (Text -> IO ()) -> IO ()
setHieTrace = Connection -> Maybe (Text -> IO ()) -> IO ()
setTrace (Connection -> Maybe (Text -> IO ()) -> IO ())
-> (HieDb -> Connection) -> HieDb -> Maybe (Text -> IO ()) -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HieDb -> Connection
getConn

-- | Encodes the original haskell source file of a module, along with whether
-- it is "real" or not
-- A file is "real" if it comes from the user project, as opposed to a
-- dependency
data SourceFile = RealFile FilePath | FakeFile (Maybe FilePath)

data ModuleInfo
  = ModuleInfo
  { ModuleInfo -> ModuleName
modInfoName :: ModuleName
  , ModuleInfo -> Unit
modInfoUnit :: Unit -- ^ Identifies the package this module is part of
  , ModuleInfo -> Bool
modInfoIsBoot :: Bool -- ^ True, when this ModuleInfo was created by indexing @.hie-boot@  file;
                          -- False when it was created from @.hie@ file
  , ModuleInfo -> Maybe [Char]
modInfoSrcFile :: Maybe FilePath -- ^ The path to the haskell source file, from which the @.hie@ file was created
  , ModuleInfo -> Bool
modInfoIsReal :: Bool -- ^ Is this a real source file? I.e. does it come from user's project (as opposed to from project's dependency)?
  , ModuleInfo -> Fingerprint
modInfoHash :: Fingerprint -- ^ The hash of the @.hie@ file from which this ModuleInfo was created
  } deriving ModuleInfo -> ModuleInfo -> Bool
(ModuleInfo -> ModuleInfo -> Bool)
-> (ModuleInfo -> ModuleInfo -> Bool) -> Eq ModuleInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModuleInfo -> ModuleInfo -> Bool
== :: ModuleInfo -> ModuleInfo -> Bool
$c/= :: ModuleInfo -> ModuleInfo -> Bool
/= :: ModuleInfo -> ModuleInfo -> Bool
Eq

instance Show ModuleInfo where
  show :: ModuleInfo -> [Char]
show = [SQLData] -> [Char]
forall a. Show a => a -> [Char]
show ([SQLData] -> [Char])
-> (ModuleInfo -> [SQLData]) -> ModuleInfo -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleInfo -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow

instance ToRow ModuleInfo where
  toRow :: ModuleInfo -> [SQLData]
toRow (ModuleInfo ModuleName
a Unit
b Bool
c Maybe [Char]
d Bool
e Fingerprint
f) = (ModuleName, Unit, Bool, Maybe [Char], Bool, Fingerprint)
-> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow (ModuleName
a,Unit
b,Bool
c,Maybe [Char]
d,Bool
e,Fingerprint
f)
instance FromRow ModuleInfo where
  fromRow :: RowParser ModuleInfo
fromRow = ModuleName
-> Unit
-> Bool
-> Maybe [Char]
-> Bool
-> Fingerprint
-> ModuleInfo
ModuleInfo (ModuleName
 -> Unit
 -> Bool
 -> Maybe [Char]
 -> Bool
 -> Fingerprint
 -> ModuleInfo)
-> RowParser ModuleName
-> RowParser
     (Unit -> Bool -> Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser ModuleName
forall a. FromField a => RowParser a
field RowParser
  (Unit -> Bool -> Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
-> RowParser Unit
-> RowParser
     (Bool -> Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Unit
forall a. FromField a => RowParser a
field RowParser
  (Bool -> Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
-> RowParser Bool
-> RowParser (Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Bool
forall a. FromField a => RowParser a
field
                       RowParser (Maybe [Char] -> Bool -> Fingerprint -> ModuleInfo)
-> RowParser (Maybe [Char])
-> RowParser (Bool -> Fingerprint -> ModuleInfo)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser (Maybe [Char])
forall a. FromField a => RowParser a
field RowParser (Bool -> Fingerprint -> ModuleInfo)
-> RowParser Bool -> RowParser (Fingerprint -> ModuleInfo)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Bool
forall a. FromField a => RowParser a
field RowParser (Fingerprint -> ModuleInfo)
-> RowParser Fingerprint -> RowParser ModuleInfo
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Fingerprint
forall a. FromField a => RowParser a
field

type Res a = a :. ModuleInfo

instance ToField ModuleName where
  toField :: ModuleName -> SQLData
toField ModuleName
mod = Text -> SQLData
SQLText (Text -> SQLData) -> Text -> SQLData
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ ModuleName -> [Char]
moduleNameString ModuleName
mod
instance FromField ModuleName where
  fromField :: FieldParser ModuleName
fromField Field
fld = [Char] -> ModuleName
mkModuleName ([Char] -> ModuleName) -> (Text -> [Char]) -> Text -> ModuleName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack (Text -> ModuleName) -> Ok Text -> Ok ModuleName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldParser Text
forall a. FromField a => FieldParser a
fromField Field
fld

instance FromRow ModuleName where
  fromRow :: RowParser ModuleName
fromRow = RowParser ModuleName
forall a. FromField a => RowParser a
field

instance ToField Unit where
  toField :: Unit -> SQLData
toField Unit
uid = Text -> SQLData
SQLText (Text -> SQLData) -> Text -> SQLData
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Unit -> [Char]
forall u. IsUnitId u => u -> [Char]
unitString Unit
uid
instance FromField Unit where
  fromField :: FieldParser Unit
fromField Field
fld = [Char] -> Unit
stringToUnit ([Char] -> Unit) -> (Text -> [Char]) -> Text -> Unit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack (Text -> Unit) -> Ok Text -> Ok Unit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldParser Text
forall a. FromField a => FieldParser a
fromField Field
fld

instance ToField Fingerprint where
  toField :: Fingerprint -> SQLData
toField Fingerprint
hash = Text -> SQLData
SQLText (Text -> SQLData) -> Text -> SQLData
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Fingerprint -> [Char]
forall a. Show a => a -> [Char]
show Fingerprint
hash
instance FromField Fingerprint where
  fromField :: FieldParser Fingerprint
fromField Field
fld = [Char] -> Fingerprint
readHexFingerprint ([Char] -> Fingerprint) -> (Text -> [Char]) -> Text -> Fingerprint
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack (Text -> Fingerprint) -> Ok Text -> Ok Fingerprint
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldParser Text
forall a. FromField a => FieldParser a
fromField Field
fld

toNsChar :: NameSpace -> String
toNsChar :: NameSpace -> [Char]
toNsChar NameSpace
ns
  | Just FastString
fld_par <- NameSpace -> Maybe FastString
fieldNameSpace_maybe NameSpace
ns
  = (Char
'f'Char -> ShowS
forall a. a -> [a] -> [a]
:FastString -> [Char]
unpackFS FastString
fld_par) [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
":"
  | NameSpace -> Bool
isVarNameSpace NameSpace
ns = [Char]
"v:"
  | NameSpace -> Bool
isDataConNameSpace NameSpace
ns = [Char]
"c:"
  | NameSpace -> Bool
isTcClsNameSpace NameSpace
ns  = [Char]
"t:"
  | NameSpace -> Bool
isTvNameSpace NameSpace
ns = [Char]
"z:"
  | Bool
otherwise = ShowS
forall a. HasCallStack => [Char] -> a
error [Char]
"namespace not recognized"

fromNsChar :: T.Text -> Maybe NameSpace
fromNsChar :: Text -> Maybe NameSpace
fromNsChar Text
ns
  | Just (Char
'f',Text
fieldNameSpace) <- Text -> Maybe (Char, Text)
T.uncons Text
ns
  = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just (FastString -> NameSpace
fieldName (FastString -> NameSpace) -> FastString -> NameSpace
forall a b. (a -> b) -> a -> b
$ ByteString -> FastString
mkFastStringByteString (ByteString -> FastString) -> ByteString -> FastString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
T.encodeUtf8 Text
fieldNameSpace)
fromNsChar Text
"v" = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just NameSpace
varName
fromNsChar Text
"c" = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just NameSpace
dataName
fromNsChar Text
"t" = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just NameSpace
tcClsName
fromNsChar Text
"z" = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just NameSpace
tvName
fromNsChar Text
_   = Maybe NameSpace
forall a. Maybe a
Nothing

instance ToField OccName where
  toField :: OccName -> SQLData
toField OccName
occ = Text -> SQLData
SQLText (Text -> SQLData) -> Text -> SQLData
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ NameSpace -> [Char]
toNsChar (OccName -> NameSpace
occNameSpace OccName
occ) [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ OccName -> [Char]
occNameString OccName
occ
instance FromField OccName where
  fromField :: FieldParser OccName
fromField Field
fld =
    case Field -> SQLData
fieldData Field
fld of
      SQLText Text
t ->
        case (Char -> Bool) -> Text -> (Text, Text)
T.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':') Text
t of
          (Text
nsText,Text
occ)
            | Just NameSpace
ns <- Text -> Maybe NameSpace
fromNsChar Text
nsText ->
              OccName -> Ok OccName
forall a. a -> Ok a
forall (m :: * -> *) a. Monad m => a -> m a
return (OccName -> Ok OccName) -> OccName -> Ok OccName
forall a b. (a -> b) -> a -> b
$ NameSpace -> [Char] -> OccName
mkOccName NameSpace
ns (Text -> [Char]
T.unpack (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ HasCallStack => Text -> Text
Text -> Text
T.tail Text
occ)
          (Text, Text)
_ -> ([Char] -> [Char] -> [Char] -> ResultError)
-> Field -> [Char] -> Ok OccName
forall a err.
(Typeable a, Exception err) =>
([Char] -> [Char] -> [Char] -> err) -> Field -> [Char] -> Ok a
returnError [Char] -> [Char] -> [Char] -> ResultError
ConversionFailed Field
fld ([Char]
"OccName encoding invalid: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
forall a. Show a => a -> [Char]
show Text
t)
      SQLData
_ -> ([Char] -> [Char] -> [Char] -> ResultError)
-> Field -> [Char] -> Ok OccName
forall a err.
(Typeable a, Exception err) =>
([Char] -> [Char] -> [Char] -> err) -> Field -> [Char] -> Ok a
returnError [Char] -> [Char] -> [Char] -> ResultError
Incompatible Field
fld [Char]
"Expected a SQL string representing an OccName"

data HieModuleRow
  = HieModuleRow
  { HieModuleRow -> [Char]
hieModuleHieFile :: FilePath -- ^ Full path to @.hie@ file based on which this row was created
  , HieModuleRow -> ModuleInfo
hieModInfo :: ModuleInfo
  } deriving HieModuleRow -> HieModuleRow -> Bool
(HieModuleRow -> HieModuleRow -> Bool)
-> (HieModuleRow -> HieModuleRow -> Bool) -> Eq HieModuleRow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HieModuleRow -> HieModuleRow -> Bool
== :: HieModuleRow -> HieModuleRow -> Bool
$c/= :: HieModuleRow -> HieModuleRow -> Bool
/= :: HieModuleRow -> HieModuleRow -> Bool
Eq

instance Show HieModuleRow where
  show :: HieModuleRow -> [Char]
show = [SQLData] -> [Char]
forall a. Show a => a -> [Char]
show ([SQLData] -> [Char])
-> (HieModuleRow -> [SQLData]) -> HieModuleRow -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HieModuleRow -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow

instance ToRow HieModuleRow where
  toRow :: HieModuleRow -> [SQLData]
toRow (HieModuleRow [Char]
a ModuleInfo
b) =
     [Char] -> SQLData
forall a. ToField a => a -> SQLData
toField [Char]
a SQLData -> [SQLData] -> [SQLData]
forall a. a -> [a] -> [a]
: ModuleInfo -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow ModuleInfo
b

instance FromRow HieModuleRow where
  fromRow :: RowParser HieModuleRow
fromRow =
    [Char] -> ModuleInfo -> HieModuleRow
HieModuleRow ([Char] -> ModuleInfo -> HieModuleRow)
-> RowParser [Char] -> RowParser (ModuleInfo -> HieModuleRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser (ModuleInfo -> HieModuleRow)
-> RowParser ModuleInfo -> RowParser HieModuleRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser ModuleInfo
forall a. FromRow a => RowParser a
fromRow

data RefRow
  = RefRow
  { RefRow -> [Char]
refSrc :: FilePath
  , RefRow -> OccName
refNameOcc :: OccName
  , RefRow -> ModuleName
refNameMod :: ModuleName
  , RefRow -> Unit
refNameUnit :: Unit
  , RefRow -> Int
refSLine :: Int
  , RefRow -> Int
refSCol :: Int
  , RefRow -> Int
refELine :: Int
  , RefRow -> Int
refECol :: Int
  }

instance ToRow RefRow where
  toRow :: RefRow -> [SQLData]
toRow (RefRow [Char]
a OccName
b ModuleName
c Unit
d Int
e Int
f Int
g Int
h) = (([Char], OccName, ModuleName) :. ((Unit, Int, Int) :. (Int, Int)))
-> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow (([Char]
a,OccName
b,ModuleName
c)([Char], OccName, ModuleName)
-> ((Unit, Int, Int) :. (Int, Int))
-> ([Char], OccName, ModuleName)
   :. ((Unit, Int, Int) :. (Int, Int))
forall h t. h -> t -> h :. t
:.(Unit
d,Int
e,Int
f)(Unit, Int, Int) -> (Int, Int) -> (Unit, Int, Int) :. (Int, Int)
forall h t. h -> t -> h :. t
:.(Int
g,Int
h))

instance FromRow RefRow where
  fromRow :: RowParser RefRow
fromRow = [Char]
-> OccName
-> ModuleName
-> Unit
-> Int
-> Int
-> Int
-> Int
-> RefRow
RefRow ([Char]
 -> OccName
 -> ModuleName
 -> Unit
 -> Int
 -> Int
 -> Int
 -> Int
 -> RefRow)
-> RowParser [Char]
-> RowParser
     (OccName
      -> ModuleName -> Unit -> Int -> Int -> Int -> Int -> RefRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser
  (OccName
   -> ModuleName -> Unit -> Int -> Int -> Int -> Int -> RefRow)
-> RowParser OccName
-> RowParser
     (ModuleName -> Unit -> Int -> Int -> Int -> Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser OccName
forall a. FromField a => RowParser a
field RowParser
  (ModuleName -> Unit -> Int -> Int -> Int -> Int -> RefRow)
-> RowParser ModuleName
-> RowParser (Unit -> Int -> Int -> Int -> Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser ModuleName
forall a. FromField a => RowParser a
field
                   RowParser (Unit -> Int -> Int -> Int -> Int -> RefRow)
-> RowParser Unit -> RowParser (Int -> Int -> Int -> Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Unit
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> RefRow)
-> RowParser Int -> RowParser (Int -> Int -> Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> RefRow)
-> RowParser Int -> RowParser (Int -> Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field
                   RowParser (Int -> Int -> RefRow)
-> RowParser Int -> RowParser (Int -> RefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> RefRow) -> RowParser Int -> RowParser RefRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field

data DeclRow
  = DeclRow
  { DeclRow -> [Char]
declSrc :: FilePath
  , DeclRow -> OccName
declNameOcc :: OccName
  , DeclRow -> Int
declSLine :: Int
  , DeclRow -> Int
declSCol :: Int
  , DeclRow -> Int
declELine :: Int
  , DeclRow -> Int
declECol :: Int
  , DeclRow -> Bool
declRoot :: Bool
  }

instance ToRow DeclRow where
  toRow :: DeclRow -> [SQLData]
toRow (DeclRow [Char]
a OccName
b Int
c Int
d Int
e Int
f Bool
g) = (([Char], OccName, Int, Int) :. (Int, Int, Bool)) -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow (([Char]
a,OccName
b,Int
c,Int
d)([Char], OccName, Int, Int)
-> (Int, Int, Bool)
-> ([Char], OccName, Int, Int) :. (Int, Int, Bool)
forall h t. h -> t -> h :. t
:.(Int
e,Int
f,Bool
g))

instance FromRow DeclRow where
  fromRow :: RowParser DeclRow
fromRow = [Char] -> OccName -> Int -> Int -> Int -> Int -> Bool -> DeclRow
DeclRow ([Char] -> OccName -> Int -> Int -> Int -> Int -> Bool -> DeclRow)
-> RowParser [Char]
-> RowParser
     (OccName -> Int -> Int -> Int -> Int -> Bool -> DeclRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser (OccName -> Int -> Int -> Int -> Int -> Bool -> DeclRow)
-> RowParser OccName
-> RowParser (Int -> Int -> Int -> Int -> Bool -> DeclRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser OccName
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> Bool -> DeclRow)
-> RowParser Int
-> RowParser (Int -> Int -> Int -> Bool -> DeclRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Bool -> DeclRow)
-> RowParser Int -> RowParser (Int -> Int -> Bool -> DeclRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field
                    RowParser (Int -> Int -> Bool -> DeclRow)
-> RowParser Int -> RowParser (Int -> Bool -> DeclRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Bool -> DeclRow)
-> RowParser Int -> RowParser (Bool -> DeclRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Bool -> DeclRow) -> RowParser Bool -> RowParser DeclRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Bool
forall a. FromField a => RowParser a
field

data ImportRow 
  = ImportRow 
    { ImportRow -> [Char]
importSrc :: FilePath
    , ImportRow -> ModuleName
importModuleName :: ModuleName
    , ImportRow -> Int
importSLine :: Int 
    , ImportRow -> Int
importSCol :: Int 
    , ImportRow -> Int
importELine :: Int 
    , ImportRow -> Int
importECol :: Int 
    }

instance FromRow ImportRow where 
  fromRow :: RowParser ImportRow
fromRow = 
    [Char] -> ModuleName -> Int -> Int -> Int -> Int -> ImportRow
ImportRow 
      ([Char] -> ModuleName -> Int -> Int -> Int -> Int -> ImportRow)
-> RowParser [Char]
-> RowParser (ModuleName -> Int -> Int -> Int -> Int -> ImportRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser (ModuleName -> Int -> Int -> Int -> Int -> ImportRow)
-> RowParser ModuleName
-> RowParser (Int -> Int -> Int -> Int -> ImportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser ModuleName
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> ImportRow)
-> RowParser Int -> RowParser (Int -> Int -> Int -> ImportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> ImportRow)
-> RowParser Int -> RowParser (Int -> Int -> ImportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field 
      RowParser (Int -> Int -> ImportRow)
-> RowParser Int -> RowParser (Int -> ImportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> ImportRow)
-> RowParser Int -> RowParser ImportRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field

instance ToRow ImportRow where 
  toRow :: ImportRow -> [SQLData]
toRow (ImportRow [Char]
a ModuleName
b Int
c Int
d Int
e Int
f) = (([Char], ModuleName, Int, Int) :. (Int, Int)) -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow (([Char]
a,ModuleName
b,Int
c,Int
d)([Char], ModuleName, Int, Int)
-> (Int, Int) -> ([Char], ModuleName, Int, Int) :. (Int, Int)
forall h t. h -> t -> h :. t
:.(Int
e,Int
f))

data TypeName = TypeName
  { TypeName -> OccName
typeName :: OccName
  , TypeName -> ModuleName
typeMod :: ModuleName
  , TypeName -> Unit
typeUnit :: Unit
  }

data TypeRef = TypeRef
  { TypeRef -> Int64
typeRefOccId :: Int64
  , TypeRef -> [Char]
typeRefHieFile :: FilePath
  , TypeRef -> Int
typeRefDepth :: Int
  , TypeRef -> Int
typeRefSLine :: Int
  , TypeRef -> Int
typeRefSCol :: Int
  , TypeRef -> Int
typeRefELine :: Int
  , TypeRef -> Int
typeRefECol :: Int
  }

instance ToRow TypeRef where
  toRow :: TypeRef -> [SQLData]
toRow (TypeRef Int64
a [Char]
b Int
c Int
d Int
e Int
f Int
g) = ((Int64, [Char], Int, Int) :. (Int, Int, Int)) -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow ((Int64
a,[Char]
b,Int
c,Int
d)(Int64, [Char], Int, Int)
-> (Int, Int, Int) -> (Int64, [Char], Int, Int) :. (Int, Int, Int)
forall h t. h -> t -> h :. t
:.(Int
e,Int
f,Int
g))

instance FromRow TypeRef where
  fromRow :: RowParser TypeRef
fromRow = Int64 -> [Char] -> Int -> Int -> Int -> Int -> Int -> TypeRef
TypeRef (Int64 -> [Char] -> Int -> Int -> Int -> Int -> Int -> TypeRef)
-> RowParser Int64
-> RowParser ([Char] -> Int -> Int -> Int -> Int -> Int -> TypeRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser Int64
forall a. FromField a => RowParser a
field RowParser ([Char] -> Int -> Int -> Int -> Int -> Int -> TypeRef)
-> RowParser [Char]
-> RowParser (Int -> Int -> Int -> Int -> Int -> TypeRef)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> Int -> TypeRef)
-> RowParser Int -> RowParser (Int -> Int -> Int -> Int -> TypeRef)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> TypeRef)
-> RowParser Int -> RowParser (Int -> Int -> Int -> TypeRef)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field
                    RowParser (Int -> Int -> Int -> TypeRef)
-> RowParser Int -> RowParser (Int -> Int -> TypeRef)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> TypeRef)
-> RowParser Int -> RowParser (Int -> TypeRef)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> TypeRef) -> RowParser Int -> RowParser TypeRef
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field

data DefRow
  = DefRow
  { DefRow -> [Char]
defSrc :: FilePath
  , DefRow -> OccName
defNameOcc :: OccName
  , DefRow -> Int
defSLine :: Int
  , DefRow -> Int
defSCol :: Int
  , DefRow -> Int
defELine :: Int
  , DefRow -> Int
defECol :: Int
  }

instance ToRow DefRow where
  toRow :: DefRow -> [SQLData]
toRow (DefRow [Char]
a OccName
b Int
c Int
d Int
e Int
f) = (([Char], OccName, Int, Int) :. (Int, Int)) -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow (([Char]
a,OccName
b,Int
c,Int
d)([Char], OccName, Int, Int)
-> (Int, Int) -> ([Char], OccName, Int, Int) :. (Int, Int)
forall h t. h -> t -> h :. t
:.(Int
e,Int
f))

instance FromRow DefRow where
  fromRow :: RowParser DefRow
fromRow = [Char] -> OccName -> Int -> Int -> Int -> Int -> DefRow
DefRow ([Char] -> OccName -> Int -> Int -> Int -> Int -> DefRow)
-> RowParser [Char]
-> RowParser (OccName -> Int -> Int -> Int -> Int -> DefRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser (OccName -> Int -> Int -> Int -> Int -> DefRow)
-> RowParser OccName
-> RowParser (Int -> Int -> Int -> Int -> DefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser OccName
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> Int -> DefRow)
-> RowParser Int -> RowParser (Int -> Int -> Int -> DefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> Int -> Int -> DefRow)
-> RowParser Int -> RowParser (Int -> Int -> DefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field
                   RowParser (Int -> Int -> DefRow)
-> RowParser Int -> RowParser (Int -> DefRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field RowParser (Int -> DefRow) -> RowParser Int -> RowParser DefRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Int
forall a. FromField a => RowParser a
field

data ExportRow = ExportRow
  { ExportRow -> [Char]
exportHieFile :: FilePath -- ^ Exporting module
  , ExportRow -> OccName
exportName :: OccName
  , ExportRow -> ModuleName
exportMod :: ModuleName -- ^ Definition module
  , ExportRow -> Unit
exportUnit :: Unit
  , ExportRow -> Maybe OccName
exportParent :: Maybe OccName
  , ExportRow -> Maybe ModuleName
exportParentMod :: Maybe ModuleName
  , ExportRow -> Maybe Unit
exportParentUnit :: Maybe Unit
  , ExportRow -> Bool
exportIsDatacon :: Bool
  }
instance ToRow ExportRow where
  toRow :: ExportRow -> [SQLData]
toRow (ExportRow [Char]
a OccName
b ModuleName
c Unit
d Maybe OccName
e Maybe ModuleName
f Maybe Unit
g Bool
h) = ([Char], OccName, ModuleName, Unit, Maybe OccName,
 Maybe ModuleName, Maybe Unit, Bool)
-> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow ([Char]
a,OccName
b,ModuleName
c,Unit
d,Maybe OccName
e,Maybe ModuleName
f,Maybe Unit
g,Bool
h)

instance FromRow ExportRow where
  fromRow :: RowParser ExportRow
fromRow = [Char]
-> OccName
-> ModuleName
-> Unit
-> Maybe OccName
-> Maybe ModuleName
-> Maybe Unit
-> Bool
-> ExportRow
ExportRow ([Char]
 -> OccName
 -> ModuleName
 -> Unit
 -> Maybe OccName
 -> Maybe ModuleName
 -> Maybe Unit
 -> Bool
 -> ExportRow)
-> RowParser [Char]
-> RowParser
     (OccName
      -> ModuleName
      -> Unit
      -> Maybe OccName
      -> Maybe ModuleName
      -> Maybe Unit
      -> Bool
      -> ExportRow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RowParser [Char]
forall a. FromField a => RowParser a
field RowParser
  (OccName
   -> ModuleName
   -> Unit
   -> Maybe OccName
   -> Maybe ModuleName
   -> Maybe Unit
   -> Bool
   -> ExportRow)
-> RowParser OccName
-> RowParser
     (ModuleName
      -> Unit
      -> Maybe OccName
      -> Maybe ModuleName
      -> Maybe Unit
      -> Bool
      -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser OccName
forall a. FromField a => RowParser a
field RowParser
  (ModuleName
   -> Unit
   -> Maybe OccName
   -> Maybe ModuleName
   -> Maybe Unit
   -> Bool
   -> ExportRow)
-> RowParser ModuleName
-> RowParser
     (Unit
      -> Maybe OccName
      -> Maybe ModuleName
      -> Maybe Unit
      -> Bool
      -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser ModuleName
forall a. FromField a => RowParser a
field RowParser
  (Unit
   -> Maybe OccName
   -> Maybe ModuleName
   -> Maybe Unit
   -> Bool
   -> ExportRow)
-> RowParser Unit
-> RowParser
     (Maybe OccName
      -> Maybe ModuleName -> Maybe Unit -> Bool -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Unit
forall a. FromField a => RowParser a
field RowParser
  (Maybe OccName
   -> Maybe ModuleName -> Maybe Unit -> Bool -> ExportRow)
-> RowParser (Maybe OccName)
-> RowParser (Maybe ModuleName -> Maybe Unit -> Bool -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser (Maybe OccName)
forall a. FromField a => RowParser a
field RowParser (Maybe ModuleName -> Maybe Unit -> Bool -> ExportRow)
-> RowParser (Maybe ModuleName)
-> RowParser (Maybe Unit -> Bool -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser (Maybe ModuleName)
forall a. FromField a => RowParser a
field RowParser (Maybe Unit -> Bool -> ExportRow)
-> RowParser (Maybe Unit) -> RowParser (Bool -> ExportRow)
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser (Maybe Unit)
forall a. FromField a => RowParser a
field RowParser (Bool -> ExportRow)
-> RowParser Bool -> RowParser ExportRow
forall a b. RowParser (a -> b) -> RowParser a -> RowParser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowParser Bool
forall a. FromField a => RowParser a
field

{-| Monad with access to 'NameCacheUpdater', which is needed to deserialize @.hie@ files -}
class Monad m => NameCacheMonad m where
  getNcUpdater :: m NameCacheUpdater

newtype DbMonadT m a = DbMonadT { forall (m :: * -> *) a.
DbMonadT m a -> ReaderT (IORef NameCache) m a
runDbMonad :: ReaderT (IORef NameCache) m a } deriving ((forall (m :: * -> *). Monad m => Monad (DbMonadT m)) =>
(forall (m :: * -> *) a. Monad m => m a -> DbMonadT m a)
-> MonadTrans DbMonadT
forall (m :: * -> *). Monad m => Monad (DbMonadT m)
forall (m :: * -> *) a. Monad m => m a -> DbMonadT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *). Monad m => Monad (t m)) =>
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
$clift :: forall (m :: * -> *) a. Monad m => m a -> DbMonadT m a
lift :: forall (m :: * -> *) a. Monad m => m a -> DbMonadT m a
MonadTrans)
deriving instance Monad m => Functor (DbMonadT m)
deriving instance Monad m => Applicative (DbMonadT m)
deriving instance Monad m => Monad (DbMonadT m)
deriving instance MonadIO m => MonadIO (DbMonadT m)

type DbMonad = DbMonadT IO

runDbM :: IORef NameCache -> DbMonad a -> IO a
runDbM :: forall a. IORef NameCache -> DbMonad a -> IO a
runDbM IORef NameCache
nc DbMonad a
x = (ReaderT (IORef NameCache) IO a -> IORef NameCache -> IO a)
-> IORef NameCache -> ReaderT (IORef NameCache) IO a -> IO a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT (IORef NameCache) IO a -> IORef NameCache -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT IORef NameCache
nc (ReaderT (IORef NameCache) IO a -> IO a)
-> ReaderT (IORef NameCache) IO a -> IO a
forall a b. (a -> b) -> a -> b
$ DbMonad a -> ReaderT (IORef NameCache) IO a
forall (m :: * -> *) a.
DbMonadT m a -> ReaderT (IORef NameCache) m a
runDbMonad DbMonad a
x

instance MonadIO m => NameCacheMonad (DbMonadT m) where
#if __GLASGOW_HASKELL__ >= 903
  getNcUpdater :: DbMonadT m NameCache
getNcUpdater = ReaderT (IORef NameCache) m NameCache -> DbMonadT m NameCache
forall (m :: * -> *) a.
ReaderT (IORef NameCache) m a -> DbMonadT m a
DbMonadT (ReaderT (IORef NameCache) m NameCache -> DbMonadT m NameCache)
-> ReaderT (IORef NameCache) m NameCache -> DbMonadT m NameCache
forall a b. (a -> b) -> a -> b
$ (IORef NameCache -> m NameCache)
-> ReaderT (IORef NameCache) m NameCache
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((IORef NameCache -> m NameCache)
 -> ReaderT (IORef NameCache) m NameCache)
-> (IORef NameCache -> m NameCache)
-> ReaderT (IORef NameCache) m NameCache
forall a b. (a -> b) -> a -> b
$ \IORef NameCache
ref -> IO NameCache -> m NameCache
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO NameCache -> m NameCache) -> IO NameCache -> m NameCache
forall a b. (a -> b) -> a -> b
$ IORef NameCache -> IO NameCache
forall a. IORef a -> IO a
readIORef IORef NameCache
ref
#else
  getNcUpdater = DbMonadT $ ReaderT $ \ref -> pure (NCU $ atomicModifyIORef' ref)
#endif


data HieDbErr
  = NotIndexed ModuleName (Maybe Unit)
  | AmbiguousUnitId (NonEmpty ModuleInfo)
  | NameNotFound OccName (Maybe ModuleName) (Maybe Unit)
  | NoNameAtPoint HieTarget (Int,Int)
  | NameUnhelpfulSpan Name String

data Symbol = Symbol
    { Symbol -> OccName
symName   :: !OccName
    , Symbol -> Module
symModule :: !Module
    } deriving (Symbol -> Symbol -> Bool
(Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool) -> Eq Symbol
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Symbol -> Symbol -> Bool
== :: Symbol -> Symbol -> Bool
$c/= :: Symbol -> Symbol -> Bool
/= :: Symbol -> Symbol -> Bool
Eq, Eq Symbol
Eq Symbol =>
(Symbol -> Symbol -> Ordering)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Symbol)
-> (Symbol -> Symbol -> Symbol)
-> Ord Symbol
Symbol -> Symbol -> Bool
Symbol -> Symbol -> Ordering
Symbol -> Symbol -> Symbol
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Symbol -> Symbol -> Ordering
compare :: Symbol -> Symbol -> Ordering
$c< :: Symbol -> Symbol -> Bool
< :: Symbol -> Symbol -> Bool
$c<= :: Symbol -> Symbol -> Bool
<= :: Symbol -> Symbol -> Bool
$c> :: Symbol -> Symbol -> Bool
> :: Symbol -> Symbol -> Bool
$c>= :: Symbol -> Symbol -> Bool
>= :: Symbol -> Symbol -> Bool
$cmax :: Symbol -> Symbol -> Symbol
max :: Symbol -> Symbol -> Symbol
$cmin :: Symbol -> Symbol -> Symbol
min :: Symbol -> Symbol -> Symbol
Ord)

instance Show Symbol where
    show :: Symbol -> [Char]
show Symbol
s =     NameSpace -> [Char]
toNsChar (OccName -> NameSpace
occNameSpace (OccName -> NameSpace) -> OccName -> NameSpace
forall a b. (a -> b) -> a -> b
$ Symbol -> OccName
symName Symbol
s)
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> OccName -> [Char]
occNameString (Symbol -> OccName
symName Symbol
s)
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
":"
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> ModuleName -> [Char]
moduleNameString (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName (Module -> ModuleName) -> Module -> ModuleName
forall a b. (a -> b) -> a -> b
$ Symbol -> Module
symModule Symbol
s)
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
":"
        --       <> unitIdString (moduleUnit $ symModule s)
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Unit -> [Char]
forall u. IsUnitId u => u -> [Char]
unitString (Module -> Unit
forall unit. GenModule unit -> unit
moduleUnit (Module -> Unit) -> Module -> Unit
forall a b. (a -> b) -> a -> b
$ Symbol -> Module
symModule Symbol
s)

instance Read Symbol where
  readsPrec :: Int -> ReadS Symbol
readsPrec = ReadS Symbol -> Int -> ReadS Symbol
forall a b. a -> b -> a
const (ReadS Symbol -> Int -> ReadS Symbol)
-> ReadS Symbol -> Int -> ReadS Symbol
forall a b. (a -> b) -> a -> b
$ ReadP Symbol -> ReadS Symbol
forall a. ReadP a -> ReadS a
R.readP_to_S ReadP Symbol
readSymbol

readNameSpace :: R.ReadP NameSpace
readNameSpace :: ReadP NameSpace
readNameSpace = do
  [Char]
c <- ReadP Char -> ReadP [Char]
forall a. ReadP a -> ReadP [a]
R.many1 ReadP Char
R.get
  ReadP NameSpace
-> (NameSpace -> ReadP NameSpace)
-> Maybe NameSpace
-> ReadP NameSpace
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ReadP NameSpace
forall a. ReadP a
R.pfail NameSpace -> ReadP NameSpace
forall a. a -> ReadP a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Maybe NameSpace
fromNsChar (Text -> Maybe NameSpace) -> Text -> Maybe NameSpace
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
c)

readColon :: R.ReadP ()
readColon :: ReadP ()
readColon = () () -> ReadP Char -> ReadP ()
forall a b. a -> ReadP b -> ReadP a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ReadP Char
R.char Char
':'

readSymbol :: R.ReadP Symbol
readSymbol :: ReadP Symbol
readSymbol = do
  NameSpace
ns <- ReadP NameSpace
readNameSpace
  ReadP ()
readColon
  [Char]
n <- ReadP Char -> ReadP [Char]
forall a. ReadP a -> ReadP [a]
R.many1 ReadP Char
R.get
  ReadP ()
readColon
  [Char]
m <- ReadP Char -> ReadP [Char]
forall a. ReadP a -> ReadP [a]
R.many1 ReadP Char
R.get
  ReadP ()
readColon
  [Char]
u <- ReadP Char -> ReadP [Char]
forall a. ReadP a -> ReadP [a]
R.many1 ReadP Char
R.get
  ReadP ()
R.eof
  let mn :: ModuleName
mn  = [Char] -> ModuleName
mkModuleName [Char]
m
      uid :: Unit
uid = [Char] -> Unit
stringToUnit [Char]
u
      sym :: Symbol
sym = Symbol
              { symName :: OccName
symName   = NameSpace -> [Char] -> OccName
mkOccName NameSpace
ns [Char]
n
              , symModule :: Module
symModule = Unit -> ModuleName -> Module
forall u. u -> ModuleName -> GenModule u
mkModule Unit
uid ModuleName
mn
              }
  Symbol -> ReadP Symbol
forall a. a -> ReadP a
forall (m :: * -> *) a. Monad m => a -> m a
return Symbol
sym

-- | GHC Library Directory. Typically you'll want to use
-- @libdir@ from <https://hackage.haskell.org/package/ghc-paths ghc-paths>
newtype LibDir = LibDir FilePath

-- | A way to specify which HieFile to operate on.
-- Either the path to @.hie@ file is given in the Left
-- Or ModuleName (with optional Unit) is given in the Right
type HieTarget = Either FilePath (ModuleName, Maybe Unit)