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 )
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)
44 simpleImportDecl :: ModuleName -> ImportDecl name
45 simpleImportDecl mn = ImportDecl {
47 ideclPkgQual = Nothing,
49 ideclQualified = False,
56 instance (Outputable name) => Outputable (ImportDecl name) where
57 ppr (ImportDecl mod pkg from qual as spec)
58 = hang (hsep [ptext (sLit "import"), ppr_imp from,
59 pp_qual qual, pp_pkg pkg, ppr mod, pp_as as])
62 pp_pkg Nothing = empty
63 pp_pkg (Just p) = doubleQuotes (ftext p)
66 pp_qual True = ptext (sLit "qualified")
69 pp_as (Just a) = ptext (sLit "as") <+> ppr a
71 ppr_imp True = ptext (sLit "{-# SOURCE #-}")
74 pp_spec Nothing = empty
75 pp_spec (Just (False, ies)) = ppr_ies ies
76 pp_spec (Just (True, ies)) = ptext (sLit "hiding") <+> ppr_ies ies
78 ppr_ies [] = ptext (sLit "()")
79 ppr_ies ies = char '(' <+> interpp'SP ies <+> char ')'
82 %************************************************************************
84 \subsection{Imported and exported entities}
86 %************************************************************************
89 type LIE name = Located (IE name)
91 -- | Imported or exported entity.
94 | IEThingAbs name -- ^ Class/Type (can't tell)
95 | IEThingAll name -- ^ Class/Type plus all methods/constructors
96 | IEThingWith name [name] -- ^ Class/Type plus some methods/constructors
97 | IEModuleContents ModuleName -- ^ (Export Only)
98 | IEGroup Int HsDocString -- ^ Doc section heading
99 | IEDoc HsDocString -- ^ Some documentation
100 | IEDocNamed String -- ^ Reference to named doc
101 deriving (Data, Typeable)
105 ieName :: IE name -> name
107 ieName (IEThingAbs n) = n
108 ieName (IEThingWith n _) = n
109 ieName (IEThingAll n) = n
110 ieName _ = panic "ieName failed pattern match!"
112 ieNames :: IE a -> [a]
113 ieNames (IEVar n ) = [n]
114 ieNames (IEThingAbs n ) = [n]
115 ieNames (IEThingAll n ) = [n]
116 ieNames (IEThingWith n ns) = n:ns
117 ieNames (IEModuleContents _ ) = []
118 ieNames (IEGroup _ _ ) = []
119 ieNames (IEDoc _ ) = []
120 ieNames (IEDocNamed _ ) = []
124 instance (Outputable name) => Outputable (IE name) where
125 ppr (IEVar var) = pprHsVar var
126 ppr (IEThingAbs thing) = ppr thing
127 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
128 ppr (IEThingWith thing withs)
129 = ppr thing <> parens (fsep (punctuate comma (map pprHsVar withs)))
130 ppr (IEModuleContents mod')
131 = ptext (sLit "module") <+> ppr mod'
132 ppr (IEGroup n _) = text ("<IEGroup: " ++ (show n) ++ ">")
133 ppr (IEDoc doc) = ppr doc
134 ppr (IEDocNamed string) = text ("<IEDocNamed: " ++ string ++ ">")