File: Ppr.hs

package info (click to toggle)
haskell-ghc-lib-parser 9.6.6.20240701-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,280 kB
  • sloc: haskell: 109,582; yacc: 3,744; ansic: 2,480; makefile: 12
file content (36 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- | Unit identifier pretty-printing
module GHC.Unit.Ppr
   ( UnitPprInfo (..)
   )
where

import GHC.Prelude
import GHC.Data.FastString
import GHC.Utils.Outputable
import Data.Version

-- | Subset of UnitInfo: just enough to pretty-print a unit-id
--
-- Instead of printing the unit-id which may contain a hash, we print:
--    package-version:componentname
--
data UnitPprInfo = UnitPprInfo
   { unitPprId             :: FastString   -- ^ Identifier
   , unitPprPackageName    :: String       -- ^ Source package name
   , unitPprPackageVersion :: Version      -- ^ Source package version
   , unitPprComponentName  :: Maybe String -- ^ Component name
   }

instance Outputable UnitPprInfo where
  ppr pprinfo = getPprDebug $ \debug ->
    if debug
       then ftext (unitPprId pprinfo)
       else text $ mconcat
         [ unitPprPackageName pprinfo
         , case unitPprPackageVersion pprinfo of
            Version [] [] -> ""
            version       -> "-" ++ showVersion version
         , case unitPprComponentName pprinfo of
            Nothing    -> ""
            Just cname -> ":" ++ cname
         ]