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 (Maybe FastString) -- package qualifier
39 Bool -- True <=> {-# SOURCE #-} import
40 Bool -- True => qualified
41 (Maybe ModuleName) -- as Module
42 (Maybe (Bool, [LIE name])) -- (True => hiding, names)
46 instance (Outputable name) => Outputable (ImportDecl name) where
47 ppr (ImportDecl mod pkg from qual as spec)
48 = hang (hsep [ptext (sLit "import"), ppr_imp from,
49 pp_qual qual, pp_pkg pkg, ppr mod, pp_as as])
52 pp_pkg Nothing = empty
53 pp_pkg (Just p) = doubleQuotes (ftext p)
56 pp_qual True = ptext (sLit "qualified")
59 pp_as (Just a) = ptext (sLit "as ") <+> ppr a
61 ppr_imp True = ptext (sLit "{-# SOURCE #-}")
64 pp_spec Nothing = empty
65 pp_spec (Just (False, spec))
66 = parens (interpp'SP spec)
67 pp_spec (Just (True, spec))
68 = ptext (sLit "hiding") <+> parens (interpp'SP spec)
70 ideclName :: ImportDecl name -> Located ModuleName
71 ideclName (ImportDecl mod_nm _ _ _ _ _) = mod_nm
74 %************************************************************************
76 \subsection{Imported and exported entities}
78 %************************************************************************
81 type LIE name = Located (IE name)
85 | IEThingAbs name -- Class/Type (can't tell)
86 | IEThingAll name -- Class/Type plus all methods/constructors
87 | IEThingWith name [name] -- Class/Type plus some methods/constructors
88 | IEModuleContents ModuleName -- (Export Only)
89 | IEGroup Int (HsDoc name) -- Doc section heading
90 | IEDoc (HsDoc name) -- Some documentation
91 | IEDocNamed String -- Reference to named doc
95 ieName :: IE name -> name
97 ieName (IEThingAbs n) = n
98 ieName (IEThingWith n _) = n
99 ieName (IEThingAll n) = n
101 ieNames :: IE a -> [a]
102 ieNames (IEVar n ) = [n]
103 ieNames (IEThingAbs n ) = [n]
104 ieNames (IEThingAll n ) = [n]
105 ieNames (IEThingWith n ns) = n:ns
106 ieNames (IEModuleContents _ ) = []
107 ieNames (IEGroup _ _ ) = []
108 ieNames (IEDoc _ ) = []
109 ieNames (IEDocNamed _ ) = []
113 instance (Outputable name) => Outputable (IE name) where
114 ppr (IEVar var) = pprHsVar var
115 ppr (IEThingAbs thing) = ppr thing
116 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
117 ppr (IEThingWith thing withs)
118 = ppr thing <> parens (fsep (punctuate comma (map pprHsVar withs)))
119 ppr (IEModuleContents mod)
120 = ptext (sLit "module") <+> ppr mod
121 ppr (IEGroup n _) = text ("<IEGroup: " ++ (show n) ++ ">")
122 ppr (IEDoc doc) = ppr doc
123 ppr (IEDocNamed string) = text ("<IEDocNamed: " ++ string ++ ">")