[project @ 2003-05-19 15:10:40 by simonpj]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsDecls.lhs
index 4bda850..001d4f8 100644 (file)
@@ -9,7 +9,7 @@ Definitions for: @TyDecl@ and @oCnDecl@, @ClassDecl@,
 \begin{code}
 module HsDecls (
        HsDecl(..), TyClDecl(..), InstDecl(..), RuleDecl(..), RuleBndr(..),
-       DefaultDecl(..), HsGroup(..),
+       DefaultDecl(..), HsGroup(..), SpliceDecl(..),
        ForeignDecl(..), ForeignImport(..), ForeignExport(..),
        CImportSpec(..), FoType(..),
        ConDecl(..), CoreDecl(..),
@@ -18,7 +18,7 @@ module HsDecls (
        tyClDeclName, tyClDeclNames, tyClDeclTyVars,
        isClassDecl, isSynDecl, isDataDecl, isIfaceSigDecl, 
        isTypeOrClassDecl, countTyClDecls,
-       isSourceInstDecl, ifaceRuleDeclName,
+       isSourceInstDecl, instDeclDFun, ifaceRuleDeclName,
        conDetailsTys,
        collectRuleBndrSigTys, isSrcRule
     ) where
@@ -74,7 +74,7 @@ data HsDecl id
   | DeprecD    (DeprecDecl id)
   | RuleD      (RuleDecl id)
   | CoreD      (CoreDecl id)
-  | SpliceD    (HsExpr id)     -- Top level splice
+  | SpliceD    (SpliceDecl id)
 
 -- NB: all top-level fixity decls are contained EITHER
 -- EITHER SigDs
@@ -125,7 +125,7 @@ instance OutputableBndr name => Outputable (HsDecl name) where
     ppr (RuleD rd)   = ppr rd
     ppr (DeprecD dd) = ppr dd
     ppr (CoreD dd)   = ppr dd
-    ppr (SpliceD e)  = ptext SLIT("splice") <> parens (pprExpr e)
+    ppr (SpliceD dd) = ppr dd
 
 instance OutputableBndr name => Outputable (HsGroup name) where
     ppr (HsGroup { hs_valds  = val_decls,
@@ -145,6 +145,11 @@ instance OutputableBndr name => Outputable (HsGroup name) where
        where
          ppr_ds [] = empty
          ppr_ds ds = text "" $$ vcat (map ppr ds)
+
+data SpliceDecl id = SpliceDecl (HsExpr id) SrcLoc     -- Top level splice
+
+instance OutputableBndr name => Outputable (SpliceDecl name) where
+   ppr (SpliceDecl e _) = ptext SLIT("$") <> parens (pprExpr e)
 \end{code}
 
 
@@ -206,6 +211,7 @@ Here's the deal.  (We distinguish the two cases because source-code decls
 have (Just binds) in the tcdMeths field, whereas interface decls have Nothing.
 
 In *source-code* class declarations:
+
  - When parsing, every ClassOpSig gets a DefMeth with a suitable RdrName
    This is done by RdrHsSyn.mkClassOpSigDM
 
@@ -644,6 +650,9 @@ data InstDecl name
 
 isSourceInstDecl :: InstDecl name -> Bool
 isSourceInstDecl (InstDecl _ _ _ maybe_dfun _) = isNothing maybe_dfun
+
+instDeclDFun :: InstDecl name -> Maybe name
+instDeclDFun (InstDecl _ _ _ df _) = df        -- A Maybe, but that's ok
 \end{code}
 
 \begin{code}
@@ -832,6 +841,7 @@ data RuleDecl name
        name                    -- Head of LHS
        CoreRule
 
+isSrcRule :: RuleDecl name -> Bool
 isSrcRule (HsRule _ _ _ _ _ _) = True
 isSrcRule other                       = False