2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
6 HsImpExp: Abstract syntax: imports, exports, interfaces
9 {-# OPTIONS -fno-warn-incomplete-patterns #-}
10 -- The above warning supression flag is a temporary kludge.
11 -- While working on this module you are encouraged to remove it and fix
12 -- any warnings in the module. See
13 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
18 import Module ( ModuleName )
19 import HsDoc ( HsDoc )
23 import SrcLoc ( Located(..) )
26 %************************************************************************
28 \subsection{Import and export declaration lists}
30 %************************************************************************
32 One per \tr{import} declaration in a module.
34 type LImportDecl name = Located (ImportDecl name)
37 = ImportDecl (Located ModuleName) -- module name
38 Bool -- True <=> {-# SOURCE #-} import
39 Bool -- True => qualified
40 (Maybe ModuleName) -- as Module
41 (Maybe (Bool, [LIE name])) -- (True => hiding, names)
45 instance (Outputable name) => Outputable (ImportDecl name) where
46 ppr (ImportDecl mod from qual as spec)
47 = hang (hsep [ptext (sLit "import"), ppr_imp from,
48 pp_qual qual, ppr mod, pp_as as])
52 pp_qual True = ptext (sLit "qualified")
55 pp_as (Just a) = ptext (sLit "as ") <+> ppr a
57 ppr_imp True = ptext (sLit "{-# SOURCE #-}")
60 pp_spec Nothing = empty
61 pp_spec (Just (False, spec))
62 = parens (interpp'SP spec)
63 pp_spec (Just (True, spec))
64 = ptext (sLit "hiding") <+> parens (interpp'SP spec)
66 ideclName :: ImportDecl name -> Located ModuleName
67 ideclName (ImportDecl mod_nm _ _ _ _) = mod_nm
70 %************************************************************************
72 \subsection{Imported and exported entities}
74 %************************************************************************
77 type LIE name = Located (IE name)
81 | IEThingAbs name -- Class/Type (can't tell)
82 | IEThingAll name -- Class/Type plus all methods/constructors
83 | IEThingWith name [name] -- Class/Type plus some methods/constructors
84 | IEModuleContents ModuleName -- (Export Only)
85 | IEGroup Int (HsDoc name) -- Doc section heading
86 | IEDoc (HsDoc name) -- Some documentation
87 | IEDocNamed String -- Reference to named doc
91 ieName :: IE name -> name
93 ieName (IEThingAbs n) = n
94 ieName (IEThingWith n _) = n
95 ieName (IEThingAll n) = n
97 ieNames :: IE a -> [a]
98 ieNames (IEVar n ) = [n]
99 ieNames (IEThingAbs n ) = [n]
100 ieNames (IEThingAll n ) = [n]
101 ieNames (IEThingWith n ns) = n:ns
102 ieNames (IEModuleContents _ ) = []
103 ieNames (IEGroup _ _ ) = []
104 ieNames (IEDoc _ ) = []
105 ieNames (IEDocNamed _ ) = []
109 instance (Outputable name) => Outputable (IE name) where
110 ppr (IEVar var) = pprHsVar var
111 ppr (IEThingAbs thing) = ppr thing
112 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
113 ppr (IEThingWith thing withs)
114 = ppr thing <> parens (fsep (punctuate comma (map pprHsVar withs)))
115 ppr (IEModuleContents mod)
116 = ptext (sLit "module") <+> ppr mod
117 ppr (IEGroup n _) = text ("<IEGroup: " ++ (show n) ++ ">")
118 ppr (IEDoc doc) = ppr doc
119 ppr (IEDocNamed string) = text ("<IEDocNamed: " ++ string ++ ">")