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

    module Distribution.Types.IncludeRenaming (
        IncludeRenaming(..),
        defaultIncludeRenaming,
        isDefaultIncludeRenaming,
    ) where

    import Distribution.Compat.Prelude
    import Prelude ()

    import Distribution.Types.ModuleRenaming

    import qualified Distribution.Compat.CharParsing as P
    import           Distribution.Parsec
    import           Distribution.Pretty
    import           Text.PrettyPrint           (text)
    import qualified Text.PrettyPrint           as Disp

    -- ---------------------------------------------------------------------------
    -- Module renaming

    -- | A renaming on an include: (provides renaming, requires renaming)
    data IncludeRenaming
        = IncludeRenaming {
            IncludeRenaming -> ModuleRenaming
    includeProvidesRn :: ModuleRenaming,
            IncludeRenaming -> ModuleRenaming
    includeRequiresRn :: ModuleRenaming
        }
        deriving (Int -> IncludeRenaming -> ShowS
    [IncludeRenaming] -> ShowS
    IncludeRenaming -> String
    (Int -> IncludeRenaming -> ShowS)
    -> (IncludeRenaming -> String)
    -> ([IncludeRenaming] -> ShowS)
    -> Show IncludeRenaming
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> IncludeRenaming -> ShowS
    showsPrec :: Int -> IncludeRenaming -> ShowS
    $cshow :: IncludeRenaming -> String
    show :: IncludeRenaming -> String
    $cshowList :: [IncludeRenaming] -> ShowS
    showList :: [IncludeRenaming] -> ShowS
    Show, ReadPrec [IncludeRenaming]
    ReadPrec IncludeRenaming
    Int -> ReadS IncludeRenaming
    ReadS [IncludeRenaming]
    (Int -> ReadS IncludeRenaming)
    -> ReadS [IncludeRenaming]
    -> ReadPrec IncludeRenaming
    -> ReadPrec [IncludeRenaming]
    -> Read IncludeRenaming
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS IncludeRenaming
    readsPrec :: Int -> ReadS IncludeRenaming
    $creadList :: ReadS [IncludeRenaming]
    readList :: ReadS [IncludeRenaming]
    $creadPrec :: ReadPrec IncludeRenaming
    readPrec :: ReadPrec IncludeRenaming
    $creadListPrec :: ReadPrec [IncludeRenaming]
    readListPrec :: ReadPrec [IncludeRenaming]
    Read, IncludeRenaming -> IncludeRenaming -> Bool
    (IncludeRenaming -> IncludeRenaming -> Bool)
    -> (IncludeRenaming -> IncludeRenaming -> Bool)
    -> Eq IncludeRenaming
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: IncludeRenaming -> IncludeRenaming -> Bool
    == :: IncludeRenaming -> IncludeRenaming -> Bool
    $c/= :: IncludeRenaming -> IncludeRenaming -> Bool
    /= :: IncludeRenaming -> IncludeRenaming -> Bool
    Eq, Eq IncludeRenaming
    Eq IncludeRenaming
    -> (IncludeRenaming -> IncludeRenaming -> Ordering)
    -> (IncludeRenaming -> IncludeRenaming -> Bool)
    -> (IncludeRenaming -> IncludeRenaming -> Bool)
    -> (IncludeRenaming -> IncludeRenaming -> Bool)
    -> (IncludeRenaming -> IncludeRenaming -> Bool)
    -> (IncludeRenaming -> IncludeRenaming -> IncludeRenaming)
    -> (IncludeRenaming -> IncludeRenaming -> IncludeRenaming)
    -> Ord IncludeRenaming
    IncludeRenaming -> IncludeRenaming -> Bool
    IncludeRenaming -> IncludeRenaming -> Ordering
    IncludeRenaming -> IncludeRenaming -> IncludeRenaming
    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 :: IncludeRenaming -> IncludeRenaming -> Ordering
    compare :: IncludeRenaming -> IncludeRenaming -> Ordering
    $c< :: IncludeRenaming -> IncludeRenaming -> Bool
    < :: IncludeRenaming -> IncludeRenaming -> Bool
    $c<= :: IncludeRenaming -> IncludeRenaming -> Bool
    <= :: IncludeRenaming -> IncludeRenaming -> Bool
    $c> :: IncludeRenaming -> IncludeRenaming -> Bool
    > :: IncludeRenaming -> IncludeRenaming -> Bool
    $c>= :: IncludeRenaming -> IncludeRenaming -> Bool
    >= :: IncludeRenaming -> IncludeRenaming -> Bool
    $cmax :: IncludeRenaming -> IncludeRenaming -> IncludeRenaming
    max :: IncludeRenaming -> IncludeRenaming -> IncludeRenaming
    $cmin :: IncludeRenaming -> IncludeRenaming -> IncludeRenaming
    min :: IncludeRenaming -> IncludeRenaming -> IncludeRenaming
    Ord, Typeable, Typeable IncludeRenaming
    Typeable IncludeRenaming
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> IncludeRenaming -> c IncludeRenaming)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c IncludeRenaming)
    -> (IncludeRenaming -> Constr)
    -> (IncludeRenaming -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c IncludeRenaming))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c IncludeRenaming))
    -> ((forall b. Data b => b -> b)
        -> IncludeRenaming -> IncludeRenaming)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r)
    -> (forall u.
        (forall d. Data d => d -> u) -> IncludeRenaming -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> IncludeRenaming -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d)
        -> IncludeRenaming -> m IncludeRenaming)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d)
        -> IncludeRenaming -> m IncludeRenaming)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d)
        -> IncludeRenaming -> m IncludeRenaming)
    -> Data IncludeRenaming
    IncludeRenaming -> Constr
    IncludeRenaming -> DataType
    (forall b. Data b => b -> b) -> IncludeRenaming -> IncludeRenaming
    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) -> IncludeRenaming -> u
    forall u. (forall d. Data d => d -> u) -> IncludeRenaming -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IncludeRenaming
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IncludeRenaming -> c IncludeRenaming
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IncludeRenaming)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c IncludeRenaming)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IncludeRenaming -> c IncludeRenaming
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IncludeRenaming -> c IncludeRenaming
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IncludeRenaming
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IncludeRenaming
    $ctoConstr :: IncludeRenaming -> Constr
    toConstr :: IncludeRenaming -> Constr
    $cdataTypeOf :: IncludeRenaming -> DataType
    dataTypeOf :: IncludeRenaming -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IncludeRenaming)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IncludeRenaming)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c IncludeRenaming)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c IncludeRenaming)
    $cgmapT :: (forall b. Data b => b -> b) -> IncludeRenaming -> IncludeRenaming
    gmapT :: (forall b. Data b => b -> b) -> IncludeRenaming -> IncludeRenaming
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IncludeRenaming -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> IncludeRenaming -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> IncludeRenaming -> [u]
    $cgmapQi :: forall u.
    Int -> (forall d. Data d => d -> u) -> IncludeRenaming -> u
    gmapQi :: forall u.
    Int -> (forall d. Data d => d -> u) -> IncludeRenaming -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IncludeRenaming -> m IncludeRenaming
    Data, (forall x. IncludeRenaming -> Rep IncludeRenaming x)
    -> (forall x. Rep IncludeRenaming x -> IncludeRenaming)
    -> Generic IncludeRenaming
    forall x. Rep IncludeRenaming x -> IncludeRenaming
    forall x. IncludeRenaming -> Rep IncludeRenaming x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. IncludeRenaming -> Rep IncludeRenaming x
    from :: forall x. IncludeRenaming -> Rep IncludeRenaming x
    $cto :: forall x. Rep IncludeRenaming x -> IncludeRenaming
    to :: forall x. Rep IncludeRenaming x -> IncludeRenaming
    Generic)

    instance Binary IncludeRenaming
    instance Structured IncludeRenaming

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

    -- | The 'defaultIncludeRenaming' applied when you only @build-depends@
    -- on a package.
    defaultIncludeRenaming :: IncludeRenaming
    defaultIncludeRenaming :: IncludeRenaming
    defaultIncludeRenaming = ModuleRenaming -> ModuleRenaming -> IncludeRenaming
    IncludeRenaming ModuleRenaming
    defaultRenaming ModuleRenaming
    defaultRenaming

    -- | Is an 'IncludeRenaming' the default one?
    isDefaultIncludeRenaming :: IncludeRenaming -> Bool
    isDefaultIncludeRenaming :: IncludeRenaming -> Bool
    isDefaultIncludeRenaming (IncludeRenaming ModuleRenaming
    p ModuleRenaming
    r) = ModuleRenaming -> Bool
    isDefaultRenaming ModuleRenaming
    p Bool -> Bool -> Bool
    && ModuleRenaming -> Bool
    isDefaultRenaming ModuleRenaming
    r

    instance Pretty IncludeRenaming where
        pretty :: IncludeRenaming -> Doc
    pretty (IncludeRenaming ModuleRenaming
    prov_rn ModuleRenaming
    req_rn) =
            ModuleRenaming -> Doc
    forall a. Pretty a => a -> Doc
    pretty ModuleRenaming
    prov_rn
              Doc -> Doc -> Doc
    <+> (if ModuleRenaming -> Bool
    isDefaultRenaming ModuleRenaming
    req_rn
                    then Doc
    Disp.empty
                    else String -> Doc
    text String
    "requires" Doc -> Doc -> Doc
    <+> ModuleRenaming -> Doc
    forall a. Pretty a => a -> Doc
    pretty ModuleRenaming
    req_rn)

    instance Parsec IncludeRenaming where
        parsec :: forall (m :: * -> *). CabalParsing m => m IncludeRenaming
    parsec = do
            ModuleRenaming
    prov_rn <- m ModuleRenaming
    forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
    forall (m :: * -> *). CabalParsing m => m ModuleRenaming
    parsec
            ModuleRenaming
    req_rn <- ModuleRenaming -> m ModuleRenaming -> m ModuleRenaming
    forall (m :: * -> *) a. Alternative m => a -> m a -> m a
    P.option ModuleRenaming
    defaultRenaming (m ModuleRenaming -> m ModuleRenaming)
    -> m ModuleRenaming -> m ModuleRenaming
    forall a b. (a -> b) -> a -> b
    $ m ModuleRenaming -> m ModuleRenaming
    forall a. m a -> m a
    forall (m :: * -> *) a. Parsing m => m a -> m a
    P.try (m ModuleRenaming -> m ModuleRenaming)
    -> m ModuleRenaming -> m ModuleRenaming
    forall a b. (a -> b) -> a -> b
    $ do
                m ()
    forall (m :: * -> *). CharParsing m => m ()
    P.spaces -- no need to be space
                String
    _ <- String -> m String
    forall (m :: * -> *). CharParsing m => String -> m String
    P.string String
    "requires"
                m ()
    forall (m :: * -> *). CharParsing m => m ()
    P.spaces
                m ModuleRenaming
    forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
    forall (m :: * -> *). CabalParsing m => m ModuleRenaming
    parsec
            -- Requirements don't really care if they're mentioned
            -- or not (since you can't thin a requirement.)  But
            -- we have a little hack in Configure to combine
            -- the provisions and requirements together before passing
            -- them to GHC, and so the most neutral choice for a requirement
            -- is for the "with" field to be False, so we correctly
            -- thin provisions.
            IncludeRenaming -> m IncludeRenaming
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ModuleRenaming -> ModuleRenaming -> IncludeRenaming
    IncludeRenaming ModuleRenaming
    prov_rn ModuleRenaming
    req_rn)