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 {-# LANGUAGE DeriveDataTypeable #-}
13 import Module ( ModuleName )
14 import HsDoc ( HsDocString )
18 import SrcLoc ( Located(..) )
23 %************************************************************************
25 \subsection{Import and export declaration lists}
27 %************************************************************************
29 One per \tr{import} declaration in a module.
31 type LImportDecl name = Located (ImportDecl name)
33 -- | A single Haskell @import@ declaration.
36 ideclName :: Located ModuleName, -- ^ Module name.
37 ideclPkgQual :: Maybe FastString, -- ^ Package qualifier.
38 ideclSource :: Bool, -- ^ True <=> {-# SOURCE #-} import
39 ideclQualified :: Bool, -- ^ True => qualified
40 ideclAs :: Maybe ModuleName, -- ^ as Module
41 ideclHiding :: Maybe (Bool, [LIE name]) -- ^ (True => hiding, names)
42 } deriving (Data, Typeable)
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, ies)) = ppr_ies ies
66 pp_spec (Just (True, ies)) = ptext (sLit "hiding") <+> ppr_ies ies
68 ppr_ies [] = ptext (sLit "()")
69 ppr_ies ies = char '(' <+> interpp'SP ies <+> char ')'
72 %************************************************************************
74 \subsection{Imported and exported entities}
76 %************************************************************************
79 type LIE name = Located (IE name)
81 -- | Imported or exported entity.
84 | IEThingAbs name -- ^ Class/Type (can't tell)
85 | IEThingAll name -- ^ Class/Type plus all methods/constructors
86 | IEThingWith name [name] -- ^ Class/Type plus some methods/constructors
87 | IEModuleContents ModuleName -- ^ (Export Only)
88 | IEGroup Int HsDocString -- ^ Doc section heading
89 | IEDoc HsDocString -- ^ Some documentation
90 | IEDocNamed String -- ^ Reference to named doc
91 deriving (Data, Typeable)
95 ieName :: IE name -> name
97 ieName (IEThingAbs n) = n
98 ieName (IEThingWith n _) = n
99 ieName (IEThingAll n) = n
100 ieName _ = panic "ieName failed pattern match!"
102 ieNames :: IE a -> [a]
103 ieNames (IEVar n ) = [n]
104 ieNames (IEThingAbs n ) = [n]
105 ieNames (IEThingAll n ) = [n]
106 ieNames (IEThingWith n ns) = n:ns
107 ieNames (IEModuleContents _ ) = []
108 ieNames (IEGroup _ _ ) = []
109 ieNames (IEDoc _ ) = []
110 ieNames (IEDocNamed _ ) = []
114 instance (Outputable name) => Outputable (IE name) where
115 ppr (IEVar var) = pprHsVar var
116 ppr (IEThingAbs thing) = ppr thing
117 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
118 ppr (IEThingWith thing withs)
119 = ppr thing <> parens (fsep (punctuate comma (map pprHsVar withs)))
120 ppr (IEModuleContents mod')
121 = ptext (sLit "module") <+> ppr mod'
122 ppr (IEGroup n _) = text ("<IEGroup: " ++ (show n) ++ ">")
123 ppr (IEDoc doc) = ppr doc
124 ppr (IEDocNamed string) = text ("<IEDocNamed: " ++ string ++ ">")