[project @ 1998-08-14 12:09:33 by sof]
[ghc-hetmet.git] / ghc / compiler / deSugar / Desugar.lhs
index 281d988..6e02ef8 100644 (file)
@@ -4,38 +4,29 @@
 \section[Desugar]{@deSugar@: the main function}
 
 \begin{code}
+module Desugar ( deSugar, pprDsWarnings ) where
+
 #include "HsVersions.h"
 
-module Desugar ( deSugar, pprDsWarnings
-#if __GLASGOW_HASKELL__ < 200
-               , DsMatchContext
-               , DsWarnFlavour -- fluff needed for closure, 
-                                -- removed when compiling with 1.4
-#endif
-              ) where
-
-IMP_Ubiq(){-uitous-}
-
-import HsSyn           ( HsBinds, HsExpr, MonoBinds,
-                         SYN_IE(RecFlag), nonRecursive, recursive
-                       )
-import TcHsSyn         ( SYN_IE(TypecheckedMonoBinds), SYN_IE(TypecheckedHsExpr)
-                       )
+import CmdLineOpts     ( opt_D_dump_ds )
+import HsSyn           ( MonoBinds )
+import TcHsSyn         ( TypecheckedMonoBinds, TypecheckedForeignDecl )
+
 import CoreSyn
-import Name             ( isExported )
+import PprCore         ( pprCoreBindings )
 import DsMonad
 import DsBinds         ( dsMonoBinds )
+import DsForeign       ( dsForeigns )
 import DsUtils
 
-import Bag             ( unionBags )
-import BasicTypes       ( SYN_IE(Module) )
-import CmdLineOpts     ( opt_DoCoreLinting, opt_SccGroup, opt_SccProfilingOn )
-import CostCentre       ( IsCafCC(..), mkAutoCC )
+import Bag             ( isEmptyBag )
+import BasicTypes       ( Module )
+import CmdLineOpts     ( opt_SccGroup, opt_SccProfilingOn )
 import CoreLift                ( liftCoreBindings )
 import CoreLint                ( lintCoreBindings )
-import Id              ( nullIdEnv, mkIdEnv, idType, 
-                         SYN_IE(DictVar), GenId, SYN_IE(Id) )
-import Outputable      ( PprStyle(..) )
+import Id              ( nullIdEnv, GenId, Id )
+import ErrUtils                ( dumpIfSet, doIfSet )
+import Outputable
 import UniqSupply      ( splitUniqSupply, UniqSupply )
 \end{code}
 
@@ -46,26 +37,40 @@ start.
 deSugar :: UniqSupply          -- name supply
        -> Module               -- module name
        -> TypecheckedMonoBinds
-       -> ([CoreBinding],      -- output
-           DsWarnings)     -- Shadowing complaints
+       -> [TypecheckedForeignDecl]
+       -> IO ([CoreBinding], SDoc, SDoc, SDoc) -- output
 
-deSugar us mod_name all_binds
+deSugar us mod_name all_binds fo_decls
   = let
        (us1, us2) = splitUniqSupply us
+       (us3, us4) = splitUniqSupply us2
 
         module_and_group = (mod_name, grp_name)
        grp_name  = case opt_SccGroup of
                        Just xx -> _PK_ xx
                        Nothing -> mod_name     -- default: module name
 
-       (core_prs, shadows) = initDs us1 nullIdEnv module_and_group 
-                             (dsMonoBinds opt_SccProfilingOn recursive all_binds [])
+       (core_prs, ds_warns) = initDs us1 nullIdEnv module_and_group 
+                              (dsMonoBinds opt_SccProfilingOn all_binds [])
 
-       lift_final_binds = liftCoreBindings us2 [Rec core_prs]
+       ((fi_binds, fe_binds, hc_code, h_code, c_code), ds_warns2) = 
+                  initDs us3 nullIdEnv module_and_group 
+                        (dsForeigns fo_decls)
 
-       really_final_binds = if opt_DoCoreLinting
-                            then lintCoreBindings PprDebug "Desugarer" False lift_final_binds
-                            else lift_final_binds
+       ds_binds' = liftCoreBindings us4 [Rec (core_prs)]
+       ds_binds  = fi_binds ++ ds_binds' ++ fe_binds
     in
-    (really_final_binds, shadows)
+
+       -- Display any warnings
+    doIfSet (not (isEmptyBag ds_warns))
+       (printErrs (pprDsWarnings ds_warns)) >>
+
+       -- Lint result if necessary
+    lintCoreBindings "Desugarer" False ds_binds >>
+
+       -- Dump output
+    dumpIfSet opt_D_dump_ds "Desugared:"
+       (pprCoreBindings ds_binds)      >>
+
+    return (ds_binds, hc_code, h_code, c_code)
 \end{code}