[project @ 1999-03-02 17:12:54 by sof]
[ghc-hetmet.git] / ghc / compiler / rename / RnSource.lhs
index 0c673e6..1fd4d95 100644 (file)
@@ -13,7 +13,10 @@ import HsSyn
 import HsDecls         ( HsIdInfo(..), HsStrictnessInfo(..) )
 import HsPragmas
 import HsTypes         ( getTyVarName, pprClassAssertion, cmpHsTypes )
-import RdrHsSyn
+import RdrName         ( RdrName, isRdrDataCon, rdrNameOcc )
+import RdrHsSyn                ( RdrNameContext, RdrNameHsType, RdrNameConDecl,
+                         extractHsTyVars
+                       )
 import RnHsSyn
 import HsCore
 
@@ -21,22 +24,22 @@ import RnBinds              ( rnTopBinds, rnMethodBinds, renameSigs )
 import RnEnv           ( bindTyVarsRn, lookupBndrRn, lookupOccRn, 
                          lookupImplicitOccRn, addImplicitOccRn,
                          bindLocalsRn, 
-                         bindTyVarsFVRn, bindTyVarsFV2Rn, extendTyVarEnvRn,
+                         bindTyVarsFVRn, bindTyVarsFV2Rn, extendTyVarEnvFVRn,
                          checkDupOrQualNames, checkDupNames,
                          newLocallyDefinedGlobalName, newImportedGlobalName, 
                          newImportedGlobalFromRdrName,
-                         ifaceFlavour, newDFunName,
+                         newDFunName,
                          FreeVars, emptyFVs, plusFV, plusFVs, unitFV, addOneFV
                        )
 import RnMonad
 
 import Name            ( Name, OccName,
                          ExportFlag(..), Provenance(..), 
-                         nameOccName, NamedThing(..), isConOcc,
+                         nameOccName, NamedThing(..),
                          mkDefaultMethodOcc, mkDFunOcc
                        )
 import NameSet
-import BasicTypes      ( TopLevelFlag(..), IfaceFlavour(..) )
+import BasicTypes      ( TopLevelFlag(..) )
 import TysWiredIn      ( tupleTyCon, unboxedTupleTyCon, listTyCon )
 import Type            ( funTyCon )
 import FiniteMap       ( elemFM )
@@ -82,8 +85,8 @@ rnSourceDecls decls
        -- Fixity decls have been dealt with already; ignore them
     go fvs ds' []          = returnRn (ds', fvs)
     go fvs ds' (FixD _:ds) = go fvs ds' ds
-    go fvs ds' (d:ds)      = rnDecl d  `thenRn` \(d', fvs) ->
-                            go (fvs `plusFV` fvs) (d':ds') ds
+    go fvs ds' (d:ds)      = rnDecl d  `thenRn` \(d', fvs') ->
+                            go (fvs `plusFV` fvs') (d':ds') ds
 
 rnIfaceDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
 rnIfaceDecl d
@@ -153,7 +156,7 @@ rnDecl (TyClD (TyData new_or_data context tycon tyvars condecls derivings pragma
     returnRn (TyClD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc),
              cxt_fvs `plusFV` plusFVs con_fvs_s `plusFV` deriv_fvs)
   where
-    data_doc = text "the data typecodeGen/ declaration for" <+> ppr tycon
+    data_doc = text "the data type declaration for" <+> quotes (ppr tycon)
     con_names = map conDeclName condecls
 
 rnDecl (TyClD (TySynonym name tyvars ty src_loc))
@@ -244,8 +247,8 @@ rnDecl (TyClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname sr
 
            (InterfaceMode _, Just _) 
                ->      -- Imported class that has a default method decl
-                   newImportedGlobalName mod_name dm_occ (ifaceFlavour clas)   `thenRn` \ dm_name ->
-                   addOccurrenceName dm_name                                   `thenRn_`
+                   newImportedGlobalName mod_name dm_occ       `thenRn` \ dm_name ->
+                   addOccurrenceName dm_name                   `thenRn_`
                    returnRn (Just dm_name)
 
            other -> returnRn Nothing
@@ -273,7 +276,7 @@ rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
        -- (Slightly strangely) the forall-d tyvars scope over
        -- the method bindings too
     in
-    extendTyVarEnvRn inst_tyvars               $
+    extendTyVarEnvFVRn inst_tyvars             $
 
        -- Rename the bindings
        -- NB meth_names can be qualified!
@@ -282,7 +285,7 @@ rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
     let 
        binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
     in
-    renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
+    renameSigs NotTopLevel True binders uprags `thenRn` \ (new_uprags, prag_fvs) ->
     mkDFunName inst_ty' maybe_dfun src_loc     `thenRn` \ dfun_name ->
     addOccurrenceName dfun_name                        `thenRn_`
                        -- The dfun is not optional, because we use its version number
@@ -290,7 +293,7 @@ rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
 
        -- The typechecker checks that all the bindings are for the right class.
     returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc),
-             inst_fvs `plusFV` meth_fvs)
+             inst_fvs `plusFV` meth_fvs `plusFV` prag_fvs)
   where
     meth_doc = text "the bindings in an instance declaration"
     meth_names   = bagToList (collectMonoBinders mbinds)
@@ -353,7 +356,7 @@ rnDerivs Nothing -- derivs not specified
 
 rnDerivs (Just ds)
   = mapRn rn_deriv ds `thenRn` \ derivs ->
-    returnRn (Just derivs, mkNameSet derivs)
+    returnRn (Just derivs, foldl addOneFV emptyFVs derivs)
   where
     rn_deriv clas
       = lookupOccRn clas           `thenRn` \ clas_name ->
@@ -396,9 +399,15 @@ rnConDetails doc locn (InfixCon ty1 ty2)
     rnBangTy doc ty2           `thenRn` \ (new_ty2, fvs2) ->
     returnRn (InfixCon new_ty1 new_ty2, fvs1 `plusFV` fvs2)
 
-rnConDetails doc locn (NewCon ty)
-  = rnHsType doc ty                    `thenRn` \ (new_ty, fvs)  ->
-    returnRn (NewCon new_ty, fvs)
+rnConDetails doc locn (NewCon ty mb_field)
+  = rnHsType doc ty                    `thenRn` \ (new_ty, fvs) ->
+    rn_field mb_field                  `thenRn` \ new_mb_field  ->
+    returnRn (NewCon new_ty new_mb_field, fvs)
+  where
+    rn_field Nothing  = returnRn Nothing
+    rn_field (Just f) =
+       lookupBndrRn f      `thenRn` \ new_f ->
+       returnRn (Just new_f)
 
 rnConDetails doc locn (RecCon fields)
   = checkDupOrQualNames doc field_names        `thenRn_`
@@ -431,7 +440,7 @@ rnBangTy doc (Unbanged ty)
 -- from interface files, which always print in prefix form
 
 checkConName name
-  = checkRn (isConOcc (rdrNameOcc name))
+  = checkRn (isRdrDataCon name)
            (badDataCon name)
 \end{code}
 
@@ -668,7 +677,7 @@ rnCoreExpr (UfApp fun arg)
 
 rnCoreExpr (UfCase scrut bndr alts) 
   = rnCoreExpr scrut                   `thenRn` \ scrut' ->
-    bindLocalsRn "UfCase" [bndr]       $ \ [bndr'] ->
+    bindLocalsRn "a UfCase" [bndr]     $ \ [bndr'] ->
     mapRn rnCoreAlt alts               `thenRn` \ alts' ->
     returnRn (UfCase scrut' bndr' alts')
 
@@ -706,7 +715,7 @@ rnCoreBndr (UfValBinder name ty) thing_inside
     str = "unfolding id"
     
 rnCoreBndr (UfTyBinder name kind) thing_inside
-  = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
+  = bindLocalsRn "an unfolding tyvar" [name] $ \ [name'] ->
     thing_inside (UfTyBinder name' kind)
     
 rnCoreBndrs bndrs thing_inside         -- Expect them all to be ValBinders
@@ -721,9 +730,9 @@ rnCoreBndrs bndrs thing_inside              -- Expect them all to be ValBinders
 
 \begin{code}
 rnCoreAlt (con, bndrs, rhs)
-  = rnUfCon con                                `thenRn` \ con' ->
-    bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
-    rnCoreExpr rhs                     `thenRn` \ rhs' ->
+  = rnUfCon con                                        `thenRn` \ con' ->
+    bindLocalsRn "an unfolding alt" bndrs      $ \ bndrs' ->
+    rnCoreExpr rhs                             `thenRn` \ rhs' ->
     returnRn (con', bndrs', rhs')
 
 
@@ -753,8 +762,8 @@ rnUfCon (UfPrimOp op)
   = lookupOccRn op             `thenRn` \ op' ->
     returnRn (UfPrimOp op')
 
-rnUfCon (UfCCallOp str casm gc)
-  = returnRn (UfCCallOp str casm gc)
+rnUfCon (UfCCallOp str is_dyn casm gc)
+  = returnRn (UfCCallOp str is_dyn casm gc)
 \end{code}
 
 %*********************************************************
@@ -777,7 +786,7 @@ dupClassAssertWarn ctxt (assertion : dups)
   = sep [hsep [ptext SLIT("Duplicate class assertion"), 
               quotes (pprClassAssertion assertion),
               ptext SLIT("in the context:")],
-        nest 4 (pprContext ctxt)]
+        nest 4 (pprContext ctxt <+> ptext SLIT("..."))]
 
 badDataCon name
    = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]