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
15 {-# LANGUAGE DeriveDataTypeable #-}
19 import Module ( ModuleName )
20 import HsDoc ( HsDocString )
24 import SrcLoc ( Located(..) )
29 %************************************************************************
31 \subsection{Import and export declaration lists}
33 %************************************************************************
35 One per \tr{import} declaration in a module.
37 type LImportDecl name = Located (ImportDecl name)
39 -- | A single Haskell @import@ declaration.
42 ideclName :: Located ModuleName, -- ^ Module name.
43 ideclPkgQual :: Maybe FastString, -- ^ Package qualifier.
44 ideclSource :: Bool, -- ^ True <=> {-# SOURCE #-} import
45 ideclQualified :: Bool, -- ^ True => qualified
46 ideclAs :: Maybe ModuleName, -- ^ as Module
47 ideclHiding :: Maybe (Bool, [LIE name]) -- ^ (True => hiding, names)
48 } deriving (Data, Typeable)
52 instance (Outputable name) => Outputable (ImportDecl name) where
53 ppr (ImportDecl mod pkg from qual as spec)
54 = hang (hsep [ptext (sLit "import"), ppr_imp from,
55 pp_qual qual, pp_pkg pkg, ppr mod, pp_as as])
58 pp_pkg Nothing = empty
59 pp_pkg (Just p) = doubleQuotes (ftext p)
62 pp_qual True = ptext (sLit "qualified")
65 pp_as (Just a) = ptext (sLit "as") <+> ppr a
67 ppr_imp True = ptext (sLit "{-# SOURCE #-}")
70 pp_spec Nothing = empty
71 pp_spec (Just (False, ies)) = ppr_ies ies
72 pp_spec (Just (True, ies)) = ptext (sLit "hiding") <+> ppr_ies ies
74 ppr_ies [] = ptext (sLit "()")
75 ppr_ies ies = char '(' <+> interpp'SP ies <+> char ')'
78 %************************************************************************
80 \subsection{Imported and exported entities}
82 %************************************************************************
85 type LIE name = Located (IE name)
87 -- | Imported or exported entity.
90 | IEThingAbs name -- ^ Class/Type (can't tell)
91 | IEThingAll name -- ^ Class/Type plus all methods/constructors
92 | IEThingWith name [name] -- ^ Class/Type plus some methods/constructors
93 | IEModuleContents ModuleName -- ^ (Export Only)
94 | IEGroup Int HsDocString -- ^ Doc section heading
95 | IEDoc HsDocString -- ^ Some documentation
96 | IEDocNamed String -- ^ Reference to named doc
97 deriving (Data, Typeable)
101 ieName :: IE name -> name
103 ieName (IEThingAbs n) = n
104 ieName (IEThingWith n _) = n
105 ieName (IEThingAll n) = n
107 ieNames :: IE a -> [a]
108 ieNames (IEVar n ) = [n]
109 ieNames (IEThingAbs n ) = [n]
110 ieNames (IEThingAll n ) = [n]
111 ieNames (IEThingWith n ns) = n:ns
112 ieNames (IEModuleContents _ ) = []
113 ieNames (IEGroup _ _ ) = []
114 ieNames (IEDoc _ ) = []
115 ieNames (IEDocNamed _ ) = []
119 instance (Outputable name) => Outputable (IE name) where
120 ppr (IEVar var) = pprHsVar var
121 ppr (IEThingAbs thing) = ppr thing
122 ppr (IEThingAll thing) = hcat [ppr thing, text "(..)"]
123 ppr (IEThingWith thing withs)
124 = ppr thing <> parens (fsep (punctuate comma (map pprHsVar withs)))
125 ppr (IEModuleContents mod)
126 = ptext (sLit "module") <+> ppr mod
127 ppr (IEGroup n _) = text ("<IEGroup: " ++ (show n) ++ ">")
128 ppr (IEDoc doc) = ppr doc
129 ppr (IEDocNamed string) = text ("<IEDocNamed: " ++ string ++ ">")