diff options
author | partain <unknown> | 1996-03-19 09:11:07 +0000 |
---|---|---|
committer | partain <unknown> | 1996-03-19 09:11:07 +0000 |
commit | 6c381e873e222417d9a67aeec77b9555eca7b7a8 (patch) | |
tree | 32cbd1de14ff19e21dd48e94051ccbe58b5fbdf5 /ghc/compiler/hsSyn/HsImpExp.lhs | |
parent | 8147a9f0bcc48ef0db1e91f8b985a4f5c3fed560 (diff) | |
download | haskell-6c381e873e222417d9a67aeec77b9555eca7b7a8.tar.gz |
[project @ 1996-03-19 08:58:34 by partain]
simonpj/sansom/partain/dnt 1.3 compiler stuff through 96/03/18
Diffstat (limited to 'ghc/compiler/hsSyn/HsImpExp.lhs')
-rw-r--r-- | ghc/compiler/hsSyn/HsImpExp.lhs | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/ghc/compiler/hsSyn/HsImpExp.lhs b/ghc/compiler/hsSyn/HsImpExp.lhs new file mode 100644 index 0000000000..f5c579b318 --- /dev/null +++ b/ghc/compiler/hsSyn/HsImpExp.lhs @@ -0,0 +1,144 @@ +% +% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996 +% +\section[HsImpExp]{Abstract syntax: imports, exports, interfaces} + +\begin{code} +#include "HsVersions.h" + +module HsImpExp where + +import Ubiq{-uitous-} + +-- friends: +import HsDecls ( FixityDecl, TyDecl, ClassDecl, InstDecl ) +import HsBinds ( Sig ) + +-- others: +import Outputable +import PprStyle ( PprStyle(..) ) +import Pretty +import SrcLoc ( SrcLoc{-instances-} ) +\end{code} + +%************************************************************************ +%* * +\subsection{Import and export declaration lists} +%* * +%************************************************************************ + +One per \tr{import} declaration in a module. +\begin{code} +data ImportedInterface tyvar uvar name pat + = ImportMod (Interface tyvar uvar name pat) + Bool -- qualified? + (Maybe FAST_STRING) -- as Modid + (Maybe (Bool, [IE name])) -- (hiding?, names) +\end{code} + +\begin{code} +instance (NamedThing name, Outputable name, Outputable pat, + Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar) + => Outputable (ImportedInterface tyvar uvar name pat) where + + ppr sty (ImportMod iface qual as spec) + = ppAbove (ppHang (ppCat [ppStr "import", pp_qual qual, ppr PprForUser iface, pp_as as]) + 4 (pp_spec spec)) + (case sty of {PprForUser -> ppNil; _ -> ppr sty iface}) + where + pp_qual False = ppNil + pp_qual True = ppStr "qualified" + + pp_as Nothing = ppNil + pp_as (Just a) = ppCat [ppStr "as", ppPStr a] + + pp_spec Nothing = ppNil + pp_spec (Just (False, spec)) + = ppBesides [ppStr "(", interpp'SP sty spec, ppStr ")"] + pp_spec (Just (True, spec)) + = ppBesides [ppStr "hiding (", interpp'SP sty spec, ppStr ")"] + +\end{code} + +%************************************************************************ +%* * +\subsection{Imported and exported entities} +%* * +%************************************************************************ +\begin{code} +data IE name + = IEVar name + | IEThingAbs name -- Constructor/Type/Class (can't tell) + | IEThingAll name -- Class/Type plus all methods/constructors + | IEThingWith name [name] -- Class/Type plus some methods/constructors + | IEModuleContents FAST_STRING -- (Export Only) +\end{code} + +\begin{code} +instance (Outputable name) => Outputable (IE name) where + ppr sty (IEVar var) = ppr sty var + ppr sty (IEThingAbs thing) = ppr sty thing + ppr sty (IEThingAll thing) + = ppBesides [ppr sty thing, ppStr "(..)"] + ppr sty (IEThingWith thing withs) + = ppBesides [ppr sty thing, ppLparen, ppInterleave ppComma (map (ppr sty) withs), ppRparen] + ppr sty (IEModuleContents mod) + = ppBeside (ppPStr SLIT("module ")) (ppPStr mod) +\end{code} + +%************************************************************************ +%* * +\subsection{Interfaces} +%* * +%************************************************************************ + +\begin{code} +data Interface tyvar uvar name pat + = Interface FAST_STRING -- module name + [IfaceImportDecl name] + [FixityDecl name] + [TyDecl name] -- data decls may have no constructors + [ClassDecl tyvar uvar name pat] -- without default methods + [InstDecl tyvar uvar name pat] -- without method defns + [Sig name] + SrcLoc +\end{code} + +\begin{code} +instance (NamedThing name, Outputable name, Outputable pat, + Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar) + => Outputable (Interface tyvar uvar name pat) where + + ppr PprForUser (Interface name _ _ _ _ _ _ _) = ppPStr name + + ppr sty (Interface name iimpdecls fixities tydecls classdecls instdecls sigs anns) + = ppAboves [ppStr "{-", + ifPprShowAll sty (ppr sty anns), + ppCat [ppStr "interface", ppPStr name, ppStr "where"], + ppNest 4 (ppAboves [ + pp_nonnull iimpdecls, + pp_nonnull fixities, + pp_nonnull tydecls, + pp_nonnull classdecls, + pp_nonnull instdecls, + pp_nonnull sigs]), + ppStr "-}"] + where + pp_nonnull [] = ppNil + pp_nonnull xs = ppAboves (map (ppr sty) xs) +\end{code} + +\begin{code} +data IfaceImportDecl name + = IfaceImportDecl FAST_STRING -- module we're being told about + [IE name] -- things we're being told about + SrcLoc +\end{code} + +\begin{code} +instance Outputable name => Outputable (IfaceImportDecl name) where + + ppr sty (IfaceImportDecl mod names src_loc) + = ppHang (ppCat [ppPStr SLIT("import"), ppPStr mod, ppLparen]) + 4 (ppSep [ppCat [interpp'SP sty names, ppRparen]]) +\end{code} |