2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[HsImpExp]{Abstract syntax: imports, exports, interfaces}
7 #include "HsVersions.h"
12 import HsDecls ( FixityDecl, TyDecl, ClassDecl, InstDecl )
13 import HsBinds ( Sig )
14 import HsPat ( ProtoNamePat(..), RenamedPat(..), InPat )
19 import ProtoName ( ProtoName(..) ) -- .. for pragmas only
20 import SrcLoc ( SrcLoc )
21 import Unique ( Unique )
22 import Util -- pragmas only
25 %************************************************************************
27 \subsection[AbsSyn-ImpExpDecls]{Import and export declaration lists}
29 %************************************************************************
31 One per \tr{import} declaration in a module.
33 data ImportedInterface name pat
34 = ImportAll (Interface name pat) -- the contents of the interface
38 | ImportSome (Interface name pat)
39 [IE] -- the only things being imported
42 | ImportButHide (Interface name pat)
43 [IE] -- import everything "but hide" these entities
49 type ProtoNameImportedInterface = ImportedInterface ProtoName ProtoNamePat
50 type RenamedImportedInterface = ImportedInterface Name RenamedPat
54 instance (NamedThing name, Outputable name,
55 NamedThing pat, Outputable pat)
56 => Outputable (ImportedInterface name pat) where
58 ppr sty (ImportAll iface renamings)
59 = ppAbove (ppCat [ppStr "import", ppr sty iface])
60 (pprRenamings sty renamings)
62 ppr sty (ImportSome iface imports renamings)
63 = ppAboves [ppCat [ppStr "import", ppr sty iface],
64 ppNest 8 (ppBesides [ppStr " (", interpp'SP sty imports, ppStr ") "]),
65 pprRenamings sty renamings]
67 ppr sty (ImportButHide iface imports renamings)
68 = ppAboves [ppCat [ppStr "import", ppr sty iface],
69 ppNest 8 (ppBesides [ppStr "hiding (", interpp'SP sty imports, ppStr ") "]),
70 pprRenamings sty renamings]
73 %************************************************************************
75 \subsection[AbsSyn-entities]{Imported and exported entities}
77 %************************************************************************
81 | IEThingAbs FAST_STRING -- Constructor/Type/Class (can't tell)
82 | IEThingAll FAST_STRING -- Class/Type plus all methods/constructors
83 | IEConWithCons FAST_STRING -- import tycon w/ some cons
85 | IEClsWithOps FAST_STRING -- import tycls w/ some methods
87 | IEModuleContents FAST_STRING -- (Export Only)
91 instance Outputable IE where
92 ppr sty (IEVar var) = ppPStr var
93 ppr sty (IEThingAbs thing) = ppPStr thing
94 ppr sty (IEThingAll thing) = ppBesides [ppPStr thing, ppStr "(..)"]
95 ppr sty (IEConWithCons tycon datacons)
96 = ppBesides [ppPStr tycon, ppLparen, ppInterleave ppComma (map ppPStr datacons), ppRparen]
97 ppr sty (IEClsWithOps cls methods)
98 = ppBesides [ppPStr cls, ppLparen, ppInterleave ppComma (map ppPStr methods), ppRparen]
99 ppr sty (IEModuleContents mod) = ppBesides [ppPStr mod, ppStr ".."]
102 We want to know what names are exported (the first list of the result)
103 and what modules are exported (the second list of the result).
105 type ImExportListInfo
106 = ( FiniteMap FAST_STRING ExportFlag,
107 -- Assoc list of im/exported things &
108 -- their "export" flags (im/exported
109 -- abstractly, concretely, etc.)
110 -- Hmm... slight misnomer there (WDP 95/02)
111 FiniteSet FAST_STRING )
112 -- List of modules to be exported
113 -- entirely; NB: *not* everything with
114 -- original names in these modules;
115 -- but: everything that these modules'
116 -- interfaces told us about.
117 -- Note: This latter component can
118 -- only arise on export lists.
120 getIEStrings :: [IE] -> ImExportListInfo
121 getRawIEStrings :: [IE] -> ([(FAST_STRING, ExportFlag)], [FAST_STRING])
122 -- "Raw" gives the raw lists of things; we need this for
123 -- checking for duplicates.
126 = case (getRawIEStrings exps) of { (pairs, mods) ->
127 (listToFM pairs, mkSet mods) }
130 = foldr do_one ([],[]) exps
132 do_one (IEVar n) (prs, mods)
133 = ((n, ExportAll):prs, mods)
134 do_one (IEThingAbs n) (prs, mods)
135 = ((n, ExportAbs):prs, mods)
136 do_one (IEThingAll n) (prs, mods)
137 = ((n, ExportAll):prs, mods)
138 do_one (IEConWithCons n ns) (prs, mods) -- needn't do anything
139 = ((n, ExportAll):prs, mods) -- with the indiv cons/ops
140 do_one (IEClsWithOps n ns) (prs, mods)
141 = ((n, ExportAll):prs, mods)
142 do_one (IEModuleContents n) (prs, mods)
146 %************************************************************************
148 \subsection[AbsSyn-Renaming]{Renamings}
150 %************************************************************************
153 data Renaming = MkRenaming FAST_STRING FAST_STRING
157 pprRenamings :: PprStyle -> [Renaming] -> Pretty
158 pprRenamings sty [] = ppNil
159 pprRenamings sty rs = ppBesides [ppStr "renaming (", interpp'SP sty rs, ppStr ")"]
163 instance Outputable Renaming where
164 ppr sty (MkRenaming from too) = ppCat [ppPStr from, ppStr "to", ppPStr too]
167 %************************************************************************
169 \subsection[AbsSyn-Interface]{Interfaces}
171 %************************************************************************
174 data Interface name pat
175 = MkInterface FAST_STRING -- module name
177 [FixityDecl name] -- none yet (ToDo)
178 [TyDecl name] -- data decls may have no constructors
179 [ClassDecl name pat] -- Without default methods
180 [InstDecl name pat] -- Without method defns
186 type ProtoNameInterface = Interface ProtoName ProtoNamePat
187 type RenamedInterface = Interface Name RenamedPat
191 instance (NamedThing name, Outputable name,
192 NamedThing pat, Outputable pat)
193 => Outputable (Interface name pat) where
195 ppr PprForUser (MkInterface name _ _ _ _ _ _ _) = ppPStr name
197 ppr sty (MkInterface name iimpdecls fixities tydecls classdecls instdecls sigs anns)
198 = ppHang (ppBeside (ppPStr name) (ppStr " {-"))
200 ifPprShowAll sty (ppr sty anns),
201 ppCat [ppStr "interface", ppPStr name, ppStr "where"],
203 ppr sty iimpdecls, ppr sty fixities,
204 ppr sty tydecls, ppr sty classdecls,
205 ppr sty instdecls, ppr sty sigs]),
211 = IfaceImportDecl FAST_STRING -- module we're being told about
212 [IE] -- things we're being told about
213 [Renaming] -- AAYYYYEEEEEEEEEE!!! (help)
218 instance Outputable IfaceImportDecl where
220 ppr sty (IfaceImportDecl mod names renamings src_loc)
221 = ppHang (ppCat [ppStr "import", ppPStr mod, ppLparen])
222 4 (ppSep [ppCat [interpp'SP sty names, ppRparen],
223 pprRenamings sty renamings])