    {-# OPTIONS_GHC -fno-warn-orphans #-}

    -- | Compatibility shims for mainland-pretty; the prettyprinting
    -- library used by language-c-quote.
    module Futhark.CodeGen.Backends.GenericC.Pretty
      ( expText,
        definitionsText,
        typeText,
        idText,
        funcText,
        funcsText,
      )
    where

    import Data.Text qualified as T
    import Language.C.Pretty ()
    import Language.C.Syntax qualified as C
    import Text.PrettyPrint.Mainland qualified as MPP
    import Text.PrettyPrint.Mainland.Class qualified as MPP

    render :: MPP.Doc -> String
    render :: Doc -> String
    render = Int -> Doc -> String
    MPP.pretty Int
    8000

    -- | Prettyprint a C expression.
    expText :: C.Exp -> T.Text
    expText :: Exp -> Text
    expText = String -> Text
    T.pack (String -> Text) -> (Exp -> String) -> Exp -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc -> String
    render (Doc -> String) -> (Exp -> Doc) -> Exp -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Exp -> Doc
    forall a. Pretty a => a -> Doc
    MPP.ppr

    -- | Prettyprint a list of C definitions.
    definitionsText :: [C.Definition] -> T.Text
    definitionsText :: [Definition] -> Text
    definitionsText = [Text] -> Text
    T.unlines ([Text] -> Text)
    -> ([Definition] -> [Text]) -> [Definition] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Definition -> Text) -> [Definition] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map (String -> Text
    T.pack (String -> Text) -> (Definition -> String) -> Definition -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc -> String
    render (Doc -> String) -> (Definition -> Doc) -> Definition -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Definition -> Doc
    forall a. Pretty a => a -> Doc
    MPP.ppr)

    -- | Prettyprint a single C type.
    typeText :: C.Type -> T.Text
    typeText :: Type -> Text
    typeText = String -> Text
    T.pack (String -> Text) -> (Type -> String) -> Type -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc -> String
    render (Doc -> String) -> (Type -> Doc) -> Type -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Type -> Doc
    forall a. Pretty a => a -> Doc
    MPP.ppr

    -- | Prettyprint a single identifier.
    idText :: C.Id -> T.Text
    idText :: Id -> Text
    idText = String -> Text
    T.pack (String -> Text) -> (Id -> String) -> Id -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc -> String
    render (Doc -> String) -> (Id -> Doc) -> Id -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Id -> Doc
    forall a. Pretty a => a -> Doc
    MPP.ppr

    -- | Prettyprint a single function.
    funcText :: C.Func -> T.Text
    funcText :: Func -> Text
    funcText = String -> Text
    T.pack (String -> Text) -> (Func -> String) -> Func -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc -> String
    render (Doc -> String) -> (Func -> Doc) -> Func -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Func -> Doc
    forall a. Pretty a => a -> Doc
    MPP.ppr

    -- | Prettyprint a list of functions.
    funcsText :: [C.Func] -> T.Text
    funcsText :: [Func] -> Text
    funcsText = [Text] -> Text
    T.unlines ([Text] -> Text) -> ([Func] -> [Text]) -> [Func] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Func -> Text) -> [Func] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Func -> Text
    funcText