2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[HsImpExp]{Abstract syntax: imports, exports, interfaces}
9 #include "HsVersions.h"
11 import Name ( isLexSym )
12 import Module ( ModuleName, WhereFrom )
14 import SrcLoc ( SrcLoc )
17 %************************************************************************
19 \subsection{Import and export declaration lists}
21 %************************************************************************
23 One per \tr{import} declaration in a module.
26 = ImportDecl ModuleName -- module name
28 Bool -- True => qualified
29 (Maybe ModuleName) -- as Module
30 (Maybe (Bool, [IE name])) -- (True => hiding, names)
35 instance (Outputable name) => Outputable (ImportDecl name) where
36 ppr (ImportDecl mod from qual as spec _)
37 = hang (hsep [ptext SLIT("import"), ppr from,
38 pp_qual qual, ppr mod, pp_as as])
42 pp_qual True = ptext SLIT("qualified")
45 pp_as (Just a) = ptext SLIT("as ") <+> ppr a
47 pp_spec Nothing = empty
48 pp_spec (Just (False, spec))
49 = parens (interpp'SP spec)
50 pp_spec (Just (True, spec))
51 = ptext SLIT("hiding") <+> parens (interpp'SP spec)
53 ideclName (ImportDecl mod_nm _ _ _ _ _) = mod_nm
56 %************************************************************************
58 \subsection{Imported and exported entities}
60 %************************************************************************
65 | IEThingAbs name -- Class/Type (can't tell)
66 | IEThingAll name -- Class/Type plus all methods/constructors
67 | IEThingWith name [name] -- Class/Type plus some methods/constructors
68 | IEModuleContents ModuleName -- (Export Only)
72 ieName :: IE name -> name
74 ieName (IEThingAbs n) = n
75 ieName (IEThingWith n _) = n
76 ieName (IEThingAll n) = n
78 ieNames :: IE a -> [a]
79 ieNames (IEVar n ) = [n]
80 ieNames (IEThingAbs n ) = [n]
81 ieNames (IEThingAll n ) = [n]
82 ieNames (IEThingWith n ns) = n:ns
83 ieNames (IEModuleContents _ ) = []
87 instance (Outputable name) => Outputable (IE name) where
88 ppr (IEVar var) = ppr_var var
89 ppr (IEThingAbs thing) = ppr thing
90 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
91 ppr (IEThingWith thing withs)
92 = ppr thing <> parens (fsep (punctuate comma (map ppr_var withs)))
93 ppr (IEModuleContents mod)
94 = ptext SLIT("module") <+> ppr mod
96 ppr_var v | isOperator v = parens (ppr v)
101 isOperator :: Outputable a => a -> Bool
102 isOperator v = isLexSym (_PK_ (showSDocUnqual (ppr v)))
103 -- We use (showSDoc (ppr v)), rather than isSymOcc (getOccName v) simply so
104 -- that we don't need NamedThing in the context of all these functions.
105 -- Gruesome, but simple.