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 )
15 import SrcLoc ( SrcLoc )
18 %************************************************************************
20 \subsection{Import and export declaration lists}
22 %************************************************************************
24 One per \tr{import} declaration in a module.
27 = ImportDecl ModuleName -- module name
29 Bool -- True => qualified
30 (Maybe ModuleName) -- as Module
31 (Maybe (Bool, [IE name])) -- (True => hiding, names)
36 instance (Outputable name) => Outputable (ImportDecl name) where
37 ppr (ImportDecl mod from qual as spec _)
38 = hang (hsep [ptext SLIT("import"), ppr from,
39 pp_qual qual, ppr mod, pp_as as])
43 pp_qual True = ptext SLIT("qualified")
46 pp_as (Just a) = ptext SLIT("as ") <+> ppr a
48 pp_spec Nothing = empty
49 pp_spec (Just (False, spec))
50 = parens (interpp'SP spec)
51 pp_spec (Just (True, spec))
52 = ptext SLIT("hiding") <+> parens (interpp'SP spec)
54 ideclName (ImportDecl mod_nm _ _ _ _ _) = mod_nm
57 %************************************************************************
59 \subsection{Imported and exported entities}
61 %************************************************************************
66 | IEThingAbs name -- Class/Type (can't tell)
67 | IEThingAll name -- Class/Type plus all methods/constructors
68 | IEThingWith name [name] -- Class/Type plus some methods/constructors
69 | IEModuleContents ModuleName -- (Export Only)
73 ieName :: IE name -> name
75 ieName (IEThingAbs n) = n
76 ieName (IEThingWith n _) = n
77 ieName (IEThingAll n) = n
79 ieNames :: IE a -> [a]
80 ieNames (IEVar n ) = [n]
81 ieNames (IEThingAbs n ) = [n]
82 ieNames (IEThingAll n ) = [n]
83 ieNames (IEThingWith n ns) = n:ns
84 ieNames (IEModuleContents _ ) = []
88 instance (Outputable name) => Outputable (IE name) where
89 ppr (IEVar var) = ppr_var var
90 ppr (IEThingAbs thing) = ppr thing
91 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
92 ppr (IEThingWith thing withs)
93 = ppr thing <> parens (fsep (punctuate comma (map ppr_var withs)))
94 ppr (IEModuleContents mod)
95 = ptext SLIT("module") <+> ppr mod
97 ppr_var v | isOperator v = parens (ppr v)
102 isOperator :: Outputable a => a -> Bool
103 isOperator v = isLexSym (mkFastString (showSDocUnqual (ppr v)))
104 -- We use (showSDoc (ppr v)), rather than isSymOcc (getOccName v) simply so
105 -- that we don't need NamedThing in the context of all these functions.
106 -- Gruesome, but simple.