2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[HsImpExp]{Abstract syntax: imports, exports, interfaces}
7 #include "HsVersions.h"
14 import HsDecls ( FixityDecl, TyDecl, ClassDecl, InstDecl )
15 import HsBinds ( Sig )
19 import PprStyle ( PprStyle(..) )
21 import SrcLoc ( SrcLoc{-instances-} )
24 %************************************************************************
26 \subsection{Import and export declaration lists}
28 %************************************************************************
30 One per \tr{import} declaration in a module.
32 data ImportedInterface tyvar uvar name pat
33 = ImportMod (Interface tyvar uvar name pat)
35 (Maybe FAST_STRING) -- as Modid
36 (Maybe (Bool, [IE name])) -- (hiding?, names)
40 instance (NamedThing name, Outputable name, Outputable pat,
41 Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
42 => Outputable (ImportedInterface tyvar uvar name pat) where
44 ppr sty (ImportMod iface qual as spec)
45 = ppAbove (ppHang (ppCat [ppStr "import", pp_qual qual, ppr PprForUser iface, pp_as as])
47 (case sty of {PprForUser -> ppNil; _ -> ppr sty iface})
50 pp_qual True = ppStr "qualified"
53 pp_as (Just a) = ppCat [ppStr "as", ppPStr a]
55 pp_spec Nothing = ppNil
56 pp_spec (Just (False, spec))
57 = ppBesides [ppStr "(", interpp'SP sty spec, ppStr ")"]
58 pp_spec (Just (True, spec))
59 = ppBesides [ppStr "hiding (", interpp'SP sty spec, ppStr ")"]
63 %************************************************************************
65 \subsection{Imported and exported entities}
67 %************************************************************************
71 | IEThingAbs name -- Constructor/Type/Class (can't tell)
72 | IEThingAll name -- Class/Type plus all methods/constructors
73 | IEThingWith name [name] -- Class/Type plus some methods/constructors
74 | IEModuleContents FAST_STRING -- (Export Only)
78 instance (Outputable name) => Outputable (IE name) where
79 ppr sty (IEVar var) = ppr sty var
80 ppr sty (IEThingAbs thing) = ppr sty thing
81 ppr sty (IEThingAll thing)
82 = ppBesides [ppr sty thing, ppStr "(..)"]
83 ppr sty (IEThingWith thing withs)
84 = ppBesides [ppr sty thing, ppLparen, ppInterleave ppComma (map (ppr sty) withs), ppRparen]
85 ppr sty (IEModuleContents mod)
86 = ppBeside (ppPStr SLIT("module ")) (ppPStr mod)
89 %************************************************************************
91 \subsection{Interfaces}
93 %************************************************************************
96 data Interface tyvar uvar name pat
97 = Interface FAST_STRING -- module name
98 [IfaceImportDecl name]
100 [TyDecl name] -- data decls may have no constructors
101 [ClassDecl tyvar uvar name pat] -- without default methods
102 [InstDecl tyvar uvar name pat] -- without method defns
108 instance (NamedThing name, Outputable name, Outputable pat,
109 Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
110 => Outputable (Interface tyvar uvar name pat) where
112 ppr PprForUser (Interface name _ _ _ _ _ _ _) = ppPStr name
114 ppr sty (Interface name iimpdecls fixities tydecls classdecls instdecls sigs anns)
115 = ppAboves [ppStr "{-",
116 ifPprShowAll sty (ppr sty anns),
117 ppCat [ppStr "interface", ppPStr name, ppStr "where"],
119 pp_nonnull iimpdecls,
122 pp_nonnull classdecls,
123 pp_nonnull instdecls,
127 pp_nonnull [] = ppNil
128 pp_nonnull xs = ppAboves (map (ppr sty) xs)
132 data IfaceImportDecl name
133 = IfaceImportDecl FAST_STRING -- module we're being told about
134 [IE name] -- things we're being told about
139 instance Outputable name => Outputable (IfaceImportDecl name) where
141 ppr sty (IfaceImportDecl mod names src_loc)
142 = ppHang (ppCat [ppPStr SLIT("import"), ppPStr mod, ppLparen])
143 4 (ppSep [ppCat [interpp'SP sty names, ppRparen]])