{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}

module Distribution.Types.LibraryVisibility(
    LibraryVisibility(..),
) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Parsec
import Distribution.Pretty

import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint                as Disp

-- | Multi-lib visibility
--
-- @since 3.0.0.0
--
data LibraryVisibility
      -- | Can be used as a dependency for other packages
    = LibraryVisibilityPublic
      -- | Internal library, default
    | LibraryVisibilityPrivate
    deriving (forall x. Rep LibraryVisibility x -> LibraryVisibility
forall x. LibraryVisibility -> Rep LibraryVisibility x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LibraryVisibility x -> LibraryVisibility
$cfrom :: forall x. LibraryVisibility -> Rep LibraryVisibility x
Generic, Int -> LibraryVisibility -> ShowS
[LibraryVisibility] -> ShowS
LibraryVisibility -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LibraryVisibility] -> ShowS
$cshowList :: [LibraryVisibility] -> ShowS
show :: LibraryVisibility -> String
$cshow :: LibraryVisibility -> String
showsPrec :: Int -> LibraryVisibility -> ShowS
$cshowsPrec :: Int -> LibraryVisibility -> ShowS
Show, ReadPrec [LibraryVisibility]
ReadPrec LibraryVisibility
Int -> ReadS LibraryVisibility
ReadS [LibraryVisibility]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LibraryVisibility]
$creadListPrec :: ReadPrec [LibraryVisibility]
readPrec :: ReadPrec LibraryVisibility
$creadPrec :: ReadPrec LibraryVisibility
readList :: ReadS [LibraryVisibility]
$creadList :: ReadS [LibraryVisibility]
readsPrec :: Int -> ReadS LibraryVisibility
$creadsPrec :: Int -> ReadS LibraryVisibility
Read, LibraryVisibility -> LibraryVisibility -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LibraryVisibility -> LibraryVisibility -> Bool
$c/= :: LibraryVisibility -> LibraryVisibility -> Bool
== :: LibraryVisibility -> LibraryVisibility -> Bool
$c== :: LibraryVisibility -> LibraryVisibility -> Bool
Eq, Eq LibraryVisibility
LibraryVisibility -> LibraryVisibility -> Bool
LibraryVisibility -> LibraryVisibility -> Ordering
LibraryVisibility -> LibraryVisibility -> LibraryVisibility
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
min :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
$cmin :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
max :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
$cmax :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
>= :: LibraryVisibility -> LibraryVisibility -> Bool
$c>= :: LibraryVisibility -> LibraryVisibility -> Bool
> :: LibraryVisibility -> LibraryVisibility -> Bool
$c> :: LibraryVisibility -> LibraryVisibility -> Bool
<= :: LibraryVisibility -> LibraryVisibility -> Bool
$c<= :: LibraryVisibility -> LibraryVisibility -> Bool
< :: LibraryVisibility -> LibraryVisibility -> Bool
$c< :: LibraryVisibility -> LibraryVisibility -> Bool
compare :: LibraryVisibility -> LibraryVisibility -> Ordering
$ccompare :: LibraryVisibility -> LibraryVisibility -> Ordering
Ord, Typeable, Typeable LibraryVisibility
LibraryVisibility -> DataType
LibraryVisibility -> Constr
(forall b. Data b => b -> b)
-> LibraryVisibility -> LibraryVisibility
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> LibraryVisibility -> u
forall u. (forall d. Data d => d -> u) -> LibraryVisibility -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibraryVisibility
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibraryVisibility -> c LibraryVisibility
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LibraryVisibility)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LibraryVisibility)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LibraryVisibility -> m LibraryVisibility
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LibraryVisibility -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LibraryVisibility -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryVisibility -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryVisibility -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibraryVisibility -> r
gmapT :: (forall b. Data b => b -> b)
-> LibraryVisibility -> LibraryVisibility
$cgmapT :: (forall b. Data b => b -> b)
-> LibraryVisibility -> LibraryVisibility
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LibraryVisibility)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LibraryVisibility)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LibraryVisibility)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LibraryVisibility)
dataTypeOf :: LibraryVisibility -> DataType
$cdataTypeOf :: LibraryVisibility -> DataType
toConstr :: LibraryVisibility -> Constr
$ctoConstr :: LibraryVisibility -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibraryVisibility
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibraryVisibility
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibraryVisibility -> c LibraryVisibility
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibraryVisibility -> c LibraryVisibility
Data)

instance Pretty LibraryVisibility where
    pretty :: LibraryVisibility -> Doc
pretty LibraryVisibility
LibraryVisibilityPublic  = String -> Doc
Disp.text String
"public"
    pretty LibraryVisibility
LibraryVisibilityPrivate = String -> Doc
Disp.text String
"private"

instance Parsec LibraryVisibility where
  parsec :: forall (m :: * -> *). CabalParsing m => m LibraryVisibility
parsec = do
    String
name <- forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 Char -> Bool
isAlpha
    case String
name of
      String
"public"  -> forall (m :: * -> *) a. Monad m => a -> m a
return LibraryVisibility
LibraryVisibilityPublic
      String
"private" -> forall (m :: * -> *) a. Monad m => a -> m a
return LibraryVisibility
LibraryVisibilityPrivate
      String
_         -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown visibility: " forall a. [a] -> [a] -> [a]
++ String
name

instance Binary LibraryVisibility
instance Structured LibraryVisibility
instance NFData LibraryVisibility where rnf :: LibraryVisibility -> ()
rnf = forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Semigroup LibraryVisibility where
    LibraryVisibility
LibraryVisibilityPrivate <> :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
<> LibraryVisibility
LibraryVisibilityPrivate = LibraryVisibility
LibraryVisibilityPrivate
    LibraryVisibility
_                        <> LibraryVisibility
_                        = LibraryVisibility
LibraryVisibilityPublic

instance Monoid LibraryVisibility where
    mempty :: LibraryVisibility
mempty  = LibraryVisibility
LibraryVisibilityPrivate
    mappend :: LibraryVisibility -> LibraryVisibility -> LibraryVisibility
mappend = forall a. Semigroup a => a -> a -> a
(<>)