{-# LANGUAGE CPP #-}
module GHC.SourceGen.Name
(
RdrNameStr(..)
, RawNameSpace(..)
, rdrNameStrToString
, qual
, unqual
, OccNameStr
, occNameStrToString
, occNameStrNamespace
, occNameToStr
, nameToStr
, ModuleNameStr(..)
, moduleNameStrToString
) where
#if MIN_VERSION_ghc(9,0,0)
import GHC.Data.FastString (unpackFS)
import GHC.Unit.Module (moduleNameString)
import GHC.Types.Name.Occurrence (OccName, occNameFS, occNameSpace, isVarNameSpace)
import GHC.Types.Name (Name, nameOccName)
#else
import FastString (unpackFS)
import Module (moduleNameString)
import OccName (OccName, occNameFS, occNameSpace, isVarNameSpace)
import Name (Name, nameOccName)
#endif
import GHC.SourceGen.Name.Internal
unqual :: OccNameStr -> RdrNameStr
unqual :: OccNameStr -> RdrNameStr
unqual = OccNameStr -> RdrNameStr
UnqualStr
qual :: ModuleNameStr -> OccNameStr -> RdrNameStr
qual :: ModuleNameStr -> OccNameStr -> RdrNameStr
qual = ModuleNameStr -> OccNameStr -> RdrNameStr
QualStr
moduleNameStrToString :: ModuleNameStr -> String
moduleNameStrToString :: ModuleNameStr -> String
moduleNameStrToString = ModuleName -> String
moduleNameString (ModuleName -> String)
-> (ModuleNameStr -> ModuleName) -> ModuleNameStr -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleNameStr -> ModuleName
unModuleNameStr
occNameStrToString :: OccNameStr -> String
occNameStrToString :: OccNameStr -> String
occNameStrToString (OccNameStr RawNameSpace
_ FastString
s) = FastString -> String
unpackFS FastString
s
occNameStrNamespace :: OccNameStr -> RawNameSpace
occNameStrNamespace :: OccNameStr -> RawNameSpace
occNameStrNamespace (OccNameStr RawNameSpace
n FastString
_) = RawNameSpace
n
rdrNameStrToString :: RdrNameStr -> String
rdrNameStrToString :: RdrNameStr -> String
rdrNameStrToString (UnqualStr OccNameStr
o) = OccNameStr -> String
occNameStrToString OccNameStr
o
rdrNameStrToString (QualStr ModuleNameStr
m OccNameStr
o) =
ModuleNameStr -> String
moduleNameStrToString ModuleNameStr
m String -> String -> String
forall a. [a] -> [a] -> [a]
++ Char
'.' Char -> String -> String
forall a. a -> [a] -> [a]
: OccNameStr -> String
occNameStrToString OccNameStr
o
occNameToStr :: OccName -> OccNameStr
occNameToStr :: OccName -> OccNameStr
occNameToStr OccName
o = RawNameSpace -> FastString -> OccNameStr
OccNameStr RawNameSpace
n (OccName -> FastString
occNameFS OccName
o)
where
n :: RawNameSpace
n = if NameSpace -> Bool
isVarNameSpace (NameSpace -> Bool) -> NameSpace -> Bool
forall a b. (a -> b) -> a -> b
$ OccName -> NameSpace
occNameSpace OccName
o
then RawNameSpace
Value
else RawNameSpace
Constructor
nameToStr :: Name -> OccNameStr
nameToStr :: Name -> OccNameStr
nameToStr = OccName -> OccNameStr
occNameToStr (OccName -> OccNameStr) -> (Name -> OccName) -> Name -> OccNameStr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName