[project @ 2006-01-06 16:30:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / rename / RnNames.lhs
index 5b888b7..4cdb241 100644 (file)
@@ -26,15 +26,17 @@ import TcRnMonad
 
 import FiniteMap
 import PrelNames       ( pRELUDE, isUnboundName, main_RDR_Unqual )
-import Module          ( Module, moduleUserString, unitModuleEnv, 
+import Module          ( Module, moduleString, unitModuleEnv, 
                          lookupModuleEnv, moduleEnvElts, foldModuleEnv )
 import Name            ( Name, nameSrcLoc, nameOccName, nameModule, isWiredInName,
                          nameParent, nameParent_maybe, isExternalName,
                          isBuiltInSyntax )
 import NameSet
 import NameEnv
-import OccName         ( srcDataName, isTcOcc, occNameFlavour, OccEnv, 
-                         mkOccEnv, lookupOccEnv, emptyOccEnv, extendOccEnv )
+import OccName         ( srcDataName, isTcOcc, pprNonVarNameSpace,
+                         occNameSpace,
+                         OccEnv, mkOccEnv, lookupOccEnv, emptyOccEnv,
+                         extendOccEnv )
 import HscTypes                ( GenAvailInfo(..), AvailInfo,
                          HomePackageTable, PackageIfaceTable, 
                          unQualInScope, 
@@ -221,11 +223,10 @@ importsFromImportDecl this_mod
                 ASSERT2( not (pkg `elem` dep_pkgs deps), ppr pkg <+> ppr (dep_pkgs deps) )
                 ([], pkg : dep_pkgs deps)
 
+       -- True <=> import M ()
        import_all = case imp_details of
-                       Just (is_hiding, ls)     -- Imports are spec'd explicitly
-                         | not is_hiding -> Just (not (null ls))
-                       _ -> Nothing            -- Everything is imported, 
-                                               -- (or almost everything [hiding])
+                       Just (is_hiding, ls) -> not is_hiding && null ls        
+                       other                -> False
 
        -- unqual_avails is the Avails that are visible in *unqualified* form
        -- We need to know this so we know what to export when we see
@@ -301,21 +302,21 @@ importsFromLocalDecls group
            ; this_mod = tcg_mod gbl_env
            ; imports = emptyImportAvails {
                          imp_env = unitModuleEnv this_mod $
-                                 mkNameSet filtered_names
+                                   mkNameSet filtered_names
                        }
            }
 
-       ; rdr_env' <- extendRdrEnvRn this_mod (tcg_rdr_env gbl_env) names
+       ; rdr_env' <- extendRdrEnvRn (tcg_rdr_env gbl_env) names
 
        ; returnM (gbl_env { tcg_rdr_env = rdr_env',
                             tcg_imports = imports `plusImportAvails` tcg_imports gbl_env }) 
        }
 
-extendRdrEnvRn :: Module -> GlobalRdrEnv -> [Name] -> RnM GlobalRdrEnv
+extendRdrEnvRn :: GlobalRdrEnv -> [Name] -> RnM GlobalRdrEnv
 -- Add the new locally-bound names one by one, checking for duplicates as
 -- we do so.  Remember that in Template Haskell the duplicates
 -- might *already be* in the GlobalRdrEnv from higher up the module
-extendRdrEnvRn mod rdr_env names
+extendRdrEnvRn rdr_env names
   = foldlM add_local rdr_env names
   where
     add_local rdr_env name
@@ -326,9 +327,7 @@ extendRdrEnvRn mod rdr_env names
        | otherwise
        = return (extendGlobalRdrEnv rdr_env new_gre)
        where
-         new_gre = GRE {gre_name = name, gre_prov = prov}
-
-    prov = LocalDef mod
+         new_gre = GRE {gre_name = name, gre_prov = LocalDef}
 \end{code}
 
 @getLocalDeclBinders@ returns the names for an @HsDecl@.  It's
@@ -354,7 +353,7 @@ getLocalDeclBinders gbl_env (HsGroup {hs_valds = ValBindsIn val_decls val_sigs,
 
     new_simple rdr_name = newTopSrcBinder mod Nothing rdr_name
 
-    sig_hs_bndrs = [nm | L _ (Sig nm _) <- val_sigs]
+    sig_hs_bndrs = [nm | L _ (TypeSig nm _) <- val_sigs]
     val_hs_bndrs = collectHsBindLocatedBinders val_decls
     for_hs_bndrs = [nm | L _ (ForeignImport nm _ _ _) <- foreign_decls]
 
@@ -686,7 +685,7 @@ reportDeprecations tcg_env
       ,        Just deprec_txt <- lookupDeprec hpt pit name
       = setSrcSpan (importSpecLoc imp_spec) $
        addWarn (sep [ptext SLIT("Deprecated use of") <+> 
-                       occNameFlavour (nameOccName name) <+> 
+                       pprNonVarNameSpace (occNameSpace (nameOccName name)) <+> 
                        quotes (ppr name),
                      (parens imp_msg) <> colon,
                      (ppr deprec_txt) ])
@@ -848,7 +847,7 @@ reportUnusedNames export_decls gbl_env
    
     imports = tcg_imports gbl_env
 
-    direct_import_mods :: [(Module, Maybe Bool, SrcSpan)]
+    direct_import_mods :: [(Module, Bool, SrcSpan)]
        -- See the type of the imp_mods for this triple
     direct_import_mods = moduleEnvElts (imp_mods imports)
 
@@ -859,11 +858,11 @@ reportUnusedNames export_decls gbl_env
     --
     -- BUG WARNING: does not deal correctly with multiple imports of the same module
     --             becuase direct_import_mods has only one entry per module
-    unused_imp_mods = [(mod,loc) | (mod,imp,loc) <- direct_import_mods,
+    unused_imp_mods = [(mod,loc) | (mod,no_imp,loc) <- direct_import_mods,
                       not (mod `elemFM` minimal_imports1),
                       mod /= pRELUDE,
-                      imp /= Just False]
-       -- The Just False part is not to complain about
+                      not no_imp]
+       -- The not no_imp part is not to complain about
        -- import M (), which is an idiom for importing
        -- instance declarations
     
@@ -961,7 +960,7 @@ printMinimalImports imps
                                 (vcat (map ppr_mod_ie mod_ies)) })
    }
   where
-    mkFilename this_mod = moduleUserString this_mod ++ ".imports"
+    mkFilename this_mod = moduleString this_mod ++ ".imports"
     ppr_mod_ie (mod_name, ies) 
        | mod_name == pRELUDE 
        = empty