(original) (raw)

{-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, StandaloneDeriving, MagicHash, UnboxedTuples #-} {-# OPTIONS_HADDOCK hide #-}

#include "MachDeps.h" #if SIZEOF_HSWORD == 4 #define DIGITS 9 #define BASE 1000000000 #elif SIZEOF_HSWORD == 8 #define DIGITS 18 #define BASE 1000000000000000000 #else #error Please define DIGITS and BASE

#endif

module GHC.Show ( Show(..), ShowS,

    [shows](GHC.Show.html#shows), [showChar](GHC.Show.html#showChar), [showString](GHC.Show.html#showString), [showMultiLineString](GHC.Show.html#showMultiLineString),
    [showParen](GHC.Show.html#showParen), [showList__](GHC.Show.html#showList%5F%5F), [showCommaSpace](GHC.Show.html#showCommaSpace), [showSpace](GHC.Show.html#showSpace),
    [showLitChar](GHC.Show.html#showLitChar), [showLitString](GHC.Show.html#showLitString), [protectEsc](GHC.Show.html#protectEsc),
    [intToDigit](GHC.Show.html#intToDigit), [showSignedInt](GHC.Show.html#showSignedInt),
    [appPrec](GHC.Show.html#appPrec), [appPrec1](GHC.Show.html#appPrec1),

    
    [asciiTab](GHC.Show.html#asciiTab),

) where

import GHC.Base import GHC.List ((!!), foldr1, break) import GHC.Num import GHC.Stack.Types import GHC.Types (TypeLitSort (..))

type ShowS = String -> String

class Show a where {-# MINIMAL showsPrec | show #-}

[showsPrec](GHC.Show.html#showsPrec) :: Int    
                    
                    
          -> [a](#local-6989586621679034247)      
          -> [ShowS](GHC.Show.html#ShowS)


[show](GHC.Show.html#show)      :: [a](#local-6989586621679034247)   -> [String](GHC.Base.html#String)


[showList](GHC.Show.html#showList)  :: [[a](#local-6989586621679034247)] -> [ShowS](GHC.Show.html#ShowS)

[showsPrec](GHC.Show.html#showsPrec) _ [x](#local-6989586621679034248) [s](#local-6989586621679034249) = [show](GHC.Show.html#show) [x](#local-6989586621679034248) [++](GHC.Base.html#%2B%2B) [s](#local-6989586621679034249)
[show](GHC.Show.html#show) [x](#local-6989586621679034250)          = [shows](GHC.Show.html#shows) [x](#local-6989586621679034250) ""
[showList](GHC.Show.html#showList) [ls](#local-6989586621679034251)   [s](#local-6989586621679034252) = [showList__](GHC.Show.html#showList%5F%5F) [shows](GHC.Show.html#shows) [ls](#local-6989586621679034251) [s](#local-6989586621679034252)

showList__ :: (a -> ShowS) -> [a] -> ShowS showList__ _ [] s = "[]" ++ s showList__ showx (x:xs) s = '[' : showx x (showl xs) where showl [] = ']' : s showl (y:ys) = ',' : showx y (showl ys)

appPrec, appPrec1 :: Int

appPrec = I# 10#

appPrec1 = I# 11#

deriving instance Show ()

instance Show a => Show [a] where {-# SPECIALISE instance Show [String] #-} {-# SPECIALISE instance Show [Char] #-} {-# SPECIALISE instance Show [Int] #-} showsPrec _ = showList

deriving instance Show Bool

deriving instance Show Ordering

instance Show Char where showsPrec _ ''' = showString "'\''" showsPrec _ c = showChar ''' . showLitChar c . showChar '''

[showList](GHC.Show.html#showList) [cs](#local-6989586621679034539) = [showChar](GHC.Show.html#showChar) '"' [.](GHC.Base.html#.) [showLitString](GHC.Show.html#showLitString) [cs](#local-6989586621679034539) [.](GHC.Base.html#.) [showChar](GHC.Show.html#showChar) '"'

instance Show Int where showsPrec = showSignedInt

instance Show Word where showsPrec _ (W# w) = showWord w

showWord :: Word# -> ShowS showWord w# cs | isTrue# (w# ltWord# 10##) = C# (chr# (ord# '0'# +# word2Int# w#)) : cs | otherwise = case chr# (ord# '0'# +# word2Int# (w# remWord# 10##)) of c# -> showWord (w# quotWord# 10##) (C# c# : cs)

deriving instance Show a => Show (Maybe a)

deriving instance Show a => Show (NonEmpty a)

instance Show TyCon where showsPrec p (TyCon _ _ _ tc_name _ _) = showsPrec p tc_name

instance Show TrName where showsPrec _ (TrNameS s) = showString (unpackCStringUtf8# s) showsPrec _ (TrNameD s) = showString s

instance Show Module where showsPrec _ (Module p m) = shows p . (':' :) . shows m

instance Show CallStack where showsPrec _ = shows . getCallStack

deriving instance Show SrcLoc

instance (Show a, Show b) => Show (a,b) where showsPrec _ (a,b) s = show_tuple [shows a, shows b] s

instance (Show a, Show b, Show c) => Show (a, b, c) where showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s

instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s

instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s

instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a,b,c,d,e,f,g) where showsPrec _ (a,b,c,d,e,f,g) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a,b,c,d,e,f,g,h) where showsPrec _ (a,b,c,d,e,f,g,h) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a,b,c,d,e,f,g,h,i) where showsPrec _ (a,b,c,d,e,f,g,h,i) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a,b,c,d,e,f,g,h,i,j) where showsPrec _ (a,b,c,d,e,f,g,h,i,j) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a,b,c,d,e,f,g,h,i,j,k) where showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j, shows k] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a,b,c,d,e,f,g,h,i,j,k,l) where showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j, shows k, shows l] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a,b,c,d,e,f,g,h,i,j,k,l,m) where showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j, shows k, shows l, shows m] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j, shows k, shows l, shows m, shows n] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h, shows i, shows j, shows k, shows l, shows m, shows n, shows o] s

show_tuple :: [ShowS] -> ShowS show_tuple ss = showChar '(' . foldr1 ([s](#local-6989586621679034555) r -> s . showChar ',' . r) ss . showChar ')'

shows :: (Show a) => a -> ShowS shows = showsPrec 0

showChar :: Char -> ShowS showChar = (:)

showString :: String -> ShowS showString = (++)

showParen :: Bool -> ShowS -> ShowS showParen b p = if b then showChar '(' . p . showChar ')' else p

showSpace :: ShowS showSpace = \ xs -> ' ' : xs

showCommaSpace :: ShowS showCommaSpace = showString ", "

showLitChar :: Char -> ShowS showLitChar c s | c > '\DEL' = showChar '\' (protectEsc isDec (shows (ord c)) s) showLitChar '\DEL' s = showString "\DEL" s showLitChar '\' s = showString "\\" s showLitChar c s | c >= ' ' = showChar c s showLitChar '\a' s = showString "\a" s showLitChar '\b' s = showString "\b" s showLitChar '\f' s = showString "\f" s showLitChar '\n' s = showString "\n" s showLitChar '\r' s = showString "\r" s showLitChar '\t' s = showString "\t" s showLitChar '\v' s = showString "\v" s showLitChar '\SO' s = protectEsc (== 'H') (showString "\SO") s showLitChar c s = showString ('\' : asciiTab!!ord c) s

showLitString :: String -> ShowS

showLitString [] s = s showLitString ('"' : cs) s = showString "\"" (showLitString cs s) showLitString (c : cs) s = showLitChar c (showLitString cs s)

showMultiLineString :: String -> [String]

showMultiLineString str = go '"' str where go ch s = case break (== '\n') s of (l, :s'@(:_)) -> (ch : showLitString l "\n\") : go '\' s' (l, "\n") -> [ch : showLitString l "\n""] (l, _) -> [ch : showLitString l """]

isDec :: Char -> Bool isDec c = c >= '0' && c <= '9'

protectEsc :: (Char -> Bool) -> ShowS -> ShowS protectEsc p f = f . cont where cont s@(c:_) | p c = "\&" ++ s cont s = s

asciiTab :: [String] asciiTab = ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US", "SP"]

intToDigit :: Int -> Char intToDigit (I# i) | isTrue# (i >=# 0#) && isTrue# (i <=# 9#) = unsafeChr (ord '0' + I# i) | isTrue# (i >=# 10#) && isTrue# (i <=# 15#) = unsafeChr (ord 'a' + I# i - 10) | otherwise = errorWithoutStackTrace ("Char.intToDigit: not a digit " ++ show (I# i))

showSignedInt :: Int -> Int -> ShowS showSignedInt (I# p) (I# n) r | isTrue# (n <# 0#) && isTrue# (p ># 6#) = '(' : itos n (')' : r) | otherwise = itos n r

itos :: Int# -> String -> String itos n# cs | isTrue# (n# <# 0#) = let !(I# minInt#) = minInt in if isTrue# (n# ==# minInt#)

       then '-' : (case [n#](#local-6989586621679034601) `quotRemInt#` 10# of
                   (# [q](#local-6989586621679034610), [r](#local-6989586621679034611) #) ->
                       [itos'](#local-6989586621679034603) (negateInt# [q](#local-6989586621679034610)) ([itos'](#local-6989586621679034603) (negateInt# [r](#local-6989586621679034611)) [cs](#local-6989586621679034602)))
       else '-' : [itos'](#local-6989586621679034603) (negateInt# [n#](#local-6989586621679034601)) [cs](#local-6989586621679034602)
| [otherwise](GHC.Base.html#otherwise) = [itos'](#local-6989586621679034603) [n#](#local-6989586621679034601) [cs](#local-6989586621679034602)
where
itos' :: Int# -> [String](GHC.Base.html#String) -> [String](GHC.Base.html#String)
[itos'](#local-6989586621679034603) [x#](#local-6989586621679034604) [cs'](#local-6989586621679034605)
    | isTrue# ([x#](#local-6989586621679034604) <# 10#) = C# (chr# (ord# '0'# +# [x#](#local-6989586621679034604))) : [cs'](#local-6989586621679034605)
    | [otherwise](GHC.Base.html#otherwise) = case [x#](#local-6989586621679034604) `quotRemInt#` 10# of
                  (# [q](#local-6989586621679034606), [r](#local-6989586621679034607) #) ->
                      case chr# (ord# '0'# +# [r](#local-6989586621679034607)) of
                      [c#](#local-6989586621679034608) ->
                          [itos'](#local-6989586621679034603) [q](#local-6989586621679034606) (C# [c#](#local-6989586621679034608) : [cs'](#local-6989586621679034605))

instance Show Integer where showsPrec p n r | p > 6 && n < 0 = '(' : integerToString n (')' : r)

    | [otherwise](GHC.Base.html#otherwise) = [integerToString](GHC.Show.html#integerToString) [n](#local-6989586621679034277) [r](#local-6989586621679034278)
[showList](GHC.Show.html#showList) = [showList__](GHC.Show.html#showList%5F%5F) ([showsPrec](GHC.Show.html#showsPrec) 0)

instance Show Natural where #if defined(MIN_VERSION_integer_gmp) showsPrec p (NatS# w#) = showsPrec p (W# w#) #endif showsPrec p i = showsPrec p (naturalToInteger i)

integerToString :: Integer -> String -> String integerToString n0 cs0 | n0 < 0 = '-' : integerToString' (- n0) cs0 | otherwise = integerToString' n0 cs0 where integerToString' :: Integer -> String -> String integerToString' n cs | n < BASE = jhead (fromInteger n) cs | otherwise = jprinth (jsplitf (BASE*BASE) n) cs

jsplitf :: Integer -> Integer -> [Integer]
[jsplitf](#local-6989586621679034615) [p](#local-6989586621679034625) [n](#local-6989586621679034626)
    | [p](#local-6989586621679034625) > [n](#local-6989586621679034626)     = [[n](#local-6989586621679034626)]
    | [otherwise](GHC.Base.html#otherwise) = [jsplith](#local-6989586621679034616) [p](#local-6989586621679034625) ([jsplitf](#local-6989586621679034615) ([p](#local-6989586621679034625)[*](GHC.Num.html#%2A)[p](#local-6989586621679034625)) [n](#local-6989586621679034626))

jsplith :: Integer -> [Integer] -> [Integer]
[jsplith](#local-6989586621679034616) [p](#local-6989586621679034627) ([n](#local-6989586621679034628):[ns](#local-6989586621679034629)) =
    case [n](#local-6989586621679034628) `quotRemInteger` [p](#local-6989586621679034627) of
    (# [q](#local-6989586621679034630), [r](#local-6989586621679034631) #) ->
        if [q](#local-6989586621679034630) > 0 then [q](#local-6989586621679034630) : [r](#local-6989586621679034631) : [jsplitb](#local-6989586621679034617) [p](#local-6989586621679034627) [ns](#local-6989586621679034629)
                 else     [r](#local-6989586621679034631) : [jsplitb](#local-6989586621679034617) [p](#local-6989586621679034627) [ns](#local-6989586621679034629)
jsplith _ [] = [errorWithoutStackTrace](GHC.Err.html#errorWithoutStackTrace) "jsplith: []"

jsplitb :: Integer -> [Integer] -> [Integer]
[jsplitb](#local-6989586621679034617) _ []     = []
jsplitb [p](#local-6989586621679034632) ([n](#local-6989586621679034633):[ns](#local-6989586621679034634)) = case [n](#local-6989586621679034633) `quotRemInteger` [p](#local-6989586621679034632) of
                   (# [q](#local-6989586621679034635), [r](#local-6989586621679034636) #) ->
                       [q](#local-6989586621679034635) : [r](#local-6989586621679034636) : [jsplitb](#local-6989586621679034617) [p](#local-6989586621679034632) [ns](#local-6989586621679034634)


jprinth :: [Integer] -> [String](GHC.Base.html#String) -> [String](GHC.Base.html#String)
[jprinth](#local-6989586621679034618) ([n](#local-6989586621679034637):[ns](#local-6989586621679034638)) [cs](#local-6989586621679034639) =
    case [n](#local-6989586621679034637) `quotRemInteger` BASE of
    (# [q'](#local-6989586621679034640), [r'](#local-6989586621679034641) #) ->
        let [q](#local-6989586621679034642) = [fromInteger](GHC.Num.html#fromInteger) [q'](#local-6989586621679034640)
            [r](#local-6989586621679034643) = [fromInteger](GHC.Num.html#fromInteger) [r'](#local-6989586621679034641)
        in if [q](#local-6989586621679034642) > 0 then [jhead](#local-6989586621679034620) [q](#local-6989586621679034642) [$](GHC.Base.html#%24) [jblock](#local-6989586621679034621) [r](#local-6989586621679034643) [$](GHC.Base.html#%24) [jprintb](#local-6989586621679034619) [ns](#local-6989586621679034638) [cs](#local-6989586621679034639)
                    else [jhead](#local-6989586621679034620) [r](#local-6989586621679034643) [$](GHC.Base.html#%24) [jprintb](#local-6989586621679034619) [ns](#local-6989586621679034638) [cs](#local-6989586621679034639)
jprinth [] _ = [errorWithoutStackTrace](GHC.Err.html#errorWithoutStackTrace) "jprinth []"

jprintb :: [Integer] -> [String](GHC.Base.html#String) -> [String](GHC.Base.html#String)
[jprintb](#local-6989586621679034619) []     [cs](#local-6989586621679034644) = [cs](#local-6989586621679034644)
jprintb ([n](#local-6989586621679034645):[ns](#local-6989586621679034646)) [cs](#local-6989586621679034647) = case [n](#local-6989586621679034645) `quotRemInteger` BASE of
                    (# [q'](#local-6989586621679034648), [r'](#local-6989586621679034649) #) ->
                        let [q](#local-6989586621679034650) = [fromInteger](GHC.Num.html#fromInteger) [q'](#local-6989586621679034648)
                            [r](#local-6989586621679034651) = [fromInteger](GHC.Num.html#fromInteger) [r'](#local-6989586621679034649)
                        in [jblock](#local-6989586621679034621) [q](#local-6989586621679034650) [$](GHC.Base.html#%24) [jblock](#local-6989586621679034621) [r](#local-6989586621679034651) [$](GHC.Base.html#%24) [jprintb](#local-6989586621679034619) [ns](#local-6989586621679034646) [cs](#local-6989586621679034647)


jhead :: Int -> [String](GHC.Base.html#String) -> [String](GHC.Base.html#String)
[jhead](#local-6989586621679034620) [n](#local-6989586621679034652) [cs](#local-6989586621679034653)
    | [n](#local-6989586621679034652) < 10    = case [unsafeChr](GHC.Base.html#unsafeChr) ([ord](GHC.Base.html#ord) '0' [+](GHC.Num.html#%2B) [n](#local-6989586621679034652)) of
        [c](#local-6989586621679034656)@(C# _) -> [c](#local-6989586621679034656) : [cs](#local-6989586621679034653)
    | [otherwise](GHC.Base.html#otherwise) = case [unsafeChr](GHC.Base.html#unsafeChr) ([ord](GHC.Base.html#ord) '0' [+](GHC.Num.html#%2B) [r](#local-6989586621679034655)) of
        [c](#local-6989586621679034657)@(C# _) -> [jhead](#local-6989586621679034620) [q](#local-6989586621679034654) ([c](#local-6989586621679034657) : [cs](#local-6989586621679034653))
    where
    ([q](#local-6989586621679034654), [r](#local-6989586621679034655)) = [n](#local-6989586621679034652) `[quotRemInt](GHC.Base.html#quotRemInt)` 10

[jblock](#local-6989586621679034621) = [jblock'](#local-6989586621679034622)  DIGITS

jblock' :: Int -> Int -> [String](GHC.Base.html#String) -> [String](GHC.Base.html#String)
[jblock'](#local-6989586621679034622) [d](#local-6989586621679034658) [n](#local-6989586621679034659) [cs](#local-6989586621679034660)
    | [d](#local-6989586621679034658) == 1    = case [unsafeChr](GHC.Base.html#unsafeChr) ([ord](GHC.Base.html#ord) '0' [+](GHC.Num.html#%2B) [n](#local-6989586621679034659)) of
         [c](#local-6989586621679034663)@(C# _) -> [c](#local-6989586621679034663) : [cs](#local-6989586621679034660)
    | [otherwise](GHC.Base.html#otherwise) = case [unsafeChr](GHC.Base.html#unsafeChr) ([ord](GHC.Base.html#ord) '0' [+](GHC.Num.html#%2B) [r](#local-6989586621679034662)) of
         [c](#local-6989586621679034664)@(C# _) -> [jblock'](#local-6989586621679034622) ([d](#local-6989586621679034658) - 1) [q](#local-6989586621679034661) ([c](#local-6989586621679034664) : [cs](#local-6989586621679034660))
    where
    ([q](#local-6989586621679034661), [r](#local-6989586621679034662)) = [n](#local-6989586621679034659) `[quotRemInt](GHC.Base.html#quotRemInt)` 10

instance Show KindRep where showsPrec d (KindRepVar v) = showParen (d > 10) $ showString "KindRepVar " . showsPrec 11 v showsPrec d (KindRepTyConApp p q) = showParen (d > 10) $ showString "KindRepTyConApp " . showsPrec 11 p . showString " " . showsPrec 11 q showsPrec d (KindRepApp p q) = showParen (d > 10) $ showString "KindRepApp " . showsPrec 11 p . showString " " . showsPrec 11 q showsPrec d (KindRepFun p q) = showParen (d > 10) $ showString "KindRepFun " . showsPrec 11 p . showString " " . showsPrec 11 q showsPrec d (KindRepTYPE rep) = showParen (d > 10) $ showString "KindRepTYPE " . showsPrec 11 rep showsPrec d (KindRepTypeLitS p q) = showParen (d > 10) $ showString "KindRepTypeLitS " . showsPrec 11 p . showString " " . showsPrec 11 (unpackCString# q) showsPrec d (KindRepTypeLitD p q) = showParen (d > 10) $ showString "KindRepTypeLitD " . showsPrec 11 p . showString " " . showsPrec 11 q

deriving instance Show RuntimeRep

deriving instance Show VecCount

deriving instance Show VecElem

deriving instance Show TypeLitSort