[project @ 1997-07-05 03:02:04 by sof]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsImpExp.lhs
index 031bf93..2e24797 100644 (file)
@@ -8,12 +8,15 @@
 
 module HsImpExp where
 
-import Ubiq
+IMP_Ubiq()
 
+import BasicTypes      ( IfaceFlavour(..) )
 import Outputable
-import PprStyle                ( PprStyle(..) )
 import Pretty
 import SrcLoc          ( SrcLoc )
+#if __GLASGOW_HASKELL__ >= 202
+import Name
+#endif
 \end{code}
 
 %************************************************************************
@@ -26,30 +29,35 @@ One per \tr{import} declaration in a module.
 \begin{code}
 data ImportDecl name
   = ImportDecl   Module                        -- module name
-                 Bool                          -- qualified?
+                 Bool                          -- True => qualified
+                 IfaceFlavour                  -- True => source imported module 
+                                               --    (current interpretation: ignore ufolding info)
                  (Maybe Module)                -- as Module
-                 (Maybe (Bool, [IE name]))     -- (hiding?, names)
+                 (Maybe (Bool, [IE name]))     -- (True => hiding, names)
                  SrcLoc
 \end{code}
 
 \begin{code}
-instance (Outputable name) => Outputable (ImportDecl name) where
-    ppr sty (ImportDecl mod qual as spec _)
-      = ppHang (ppCat [ppStr "import", pp_qual qual, ppPStr mod, pp_as as])
+instance (NamedThing name, Outputable name) => Outputable (ImportDecl name) where
+    ppr sty (ImportDecl mod qual as_source as spec _)
+      = hang (hsep [ptext SLIT("import"), pp_src as_source, 
+                    pp_qual qual, ptext mod, pp_as as])
             4 (pp_spec spec)
       where
-       pp_qual False   = ppNil
-       pp_qual True    = ppStr "qualified"
+       pp_src HiFile     = empty
+       pp_src HiBootFile = ptext SLIT("{-# SOURCE #-}")
 
-       pp_as Nothing   = ppNil
-       pp_as (Just a)  = ppCat [ppStr "as", ppPStr a]
+       pp_qual False   = empty
+       pp_qual True    = ptext SLIT("qualified")
 
-       pp_spec Nothing = ppNil
+       pp_as Nothing   = empty
+       pp_as (Just a)  = (<>) (ptext SLIT("as ")) (ptext a)
+
+       pp_spec Nothing = empty
        pp_spec (Just (False, spec))
-                       = ppBesides [ppStr "(", interpp'SP sty spec, ppStr ")"]
+                       = parens (interpp'SP sty spec)
        pp_spec (Just (True, spec))
-                       = ppBesides [ppStr "hiding (", interpp'SP sty spec, ppStr ")"]
-
+                       = (<>) (ptext SLIT("hiding ")) (parens (interpp'SP sty spec))
 \end{code}
 
 %************************************************************************
@@ -57,23 +65,34 @@ instance (Outputable name) => Outputable (ImportDecl name) where
 \subsection{Imported and exported entities}
 %*                                                                     *
 %************************************************************************
+
 \begin{code}
 data IE name
   = IEVar              name
-  | IEThingAbs          name           -- Constructor/Type/Class (can't tell)
+  | IEThingAbs          name           -- Class/Type (can't tell)
   | IEThingAll          name           -- Class/Type plus all methods/constructors
   | IEThingWith                name [name]     -- Class/Type plus some methods/constructors
   | IEModuleContents    Module         -- (Export Only)
 \end{code}
 
 \begin{code}
-instance (Outputable name) => Outputable (IE name) where
+ieName :: IE name -> name
+ieName (IEVar n)        = n
+ieName (IEThingAbs  n)   = n
+ieName (IEThingWith n _) = n
+ieName (IEThingAll  n)   = n
+\end{code}
+
+\begin{code}
+instance (NamedThing name, 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 "(..)"]
+       = hcat [ppr sty thing, text "(..)"]
     ppr sty (IEThingWith thing withs)
-       = ppBesides [ppr sty thing, ppLparen, ppInterleave ppComma (map (ppr sty) withs), ppRparen]
+       = (<>) (ppr sty thing)
+           (parens (fsep (punctuate comma (map (ppr sty) withs))))
     ppr sty (IEModuleContents mod)
-       = ppBeside (ppPStr SLIT("module ")) (ppPStr mod)
+       = (<>) (ptext SLIT("module ")) (ptext mod)
 \end{code}
+