X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=compiler%2FhsSyn%2FHsDecls.lhs;h=dc4bac71eebb3e231a268cd4dc3d663bb7615d99;hb=127d259f77deda6f03c2213c3dacba0354b37322;hp=0038ebed0a59d5d8b0e34ae03de1a9998b50d3e0;hpb=f278f0676579f67075033a4f9857715909c4b71e;p=ghc-hetmet.git diff --git a/compiler/hsSyn/HsDecls.lhs b/compiler/hsSyn/HsDecls.lhs index 0038ebe..dc4bac7 100644 --- a/compiler/hsSyn/HsDecls.lhs +++ b/compiler/hsSyn/HsDecls.lhs @@ -24,7 +24,7 @@ module HsDecls ( -- ** Class or type declarations TyClDecl(..), LTyClDecl, isClassDecl, isSynDecl, isDataDecl, isTypeDecl, isFamilyDecl, - isFamInstDecl, tcdName, tyClDeclNames, tyClDeclTyVars, + isFamInstDecl, tcdName, tyClDeclTyVars, countTyClDecls, -- ** Instance declarations InstDecl(..), LInstDecl, NewOrData(..), FamilyFlavour(..), @@ -43,7 +43,7 @@ module HsDecls ( CImportSpec(..), -- ** Data-constructor declarations ConDecl(..), LConDecl, ResType(..), - HsConDeclDetails, hsConDeclArgTys, hsConDeclsNames, + HsConDeclDetails, hsConDeclArgTys, -- ** Document comments DocDecl(..), LDocDecl, docDeclDoc, -- ** Deprecations @@ -232,11 +232,15 @@ instance OutputableBndr name => Outputable (HsGroup name) where ppr_ds [] = empty ppr_ds ds = blankLine $$ vcat (map ppr ds) -data SpliceDecl id = SpliceDecl (Located (HsExpr id)) -- Top level splice +data SpliceDecl id + = SpliceDecl -- Top level splice + (Located (HsExpr id)) + HsExplicitFlag -- Explicit <=> $(f x y) + -- Implicit <=> f x y, i.e. a naked top level expression deriving (Data, Typeable) instance OutputableBndr name => Outputable (SpliceDecl name) where - ppr (SpliceDecl e) = ptext (sLit "$") <> parens (pprExpr (unLoc e)) + ppr (SpliceDecl e _) = ptext (sLit "$") <> parens (pprExpr (unLoc e)) \end{code} @@ -540,23 +544,6 @@ Dealing with names tcdName :: TyClDecl name -> name tcdName decl = unLoc (tcdLName decl) -tyClDeclNames :: Eq name => TyClDecl name -> [Located name] --- ^ Returns all the /binding/ names of the decl, along with their SrcLocs. --- The first one is guaranteed to be the name of the decl. For record fields --- mentioned in multiple constructors, the SrcLoc will be from the first --- occurence. We use the equality to filter out duplicate field names - -tyClDeclNames (TyFamily {tcdLName = name}) = [name] -tyClDeclNames (TySynonym {tcdLName = name}) = [name] -tyClDeclNames (ForeignType {tcdLName = name}) = [name] - -tyClDeclNames (ClassDecl {tcdLName = cls_name, tcdSigs = sigs, tcdATs = ats}) - = cls_name : - concatMap (tyClDeclNames . unLoc) ats ++ [n | L _ (TypeSig n _) <- sigs] - -tyClDeclNames (TyData {tcdLName = tc_name, tcdCons = cons}) - = tc_name : hsConDeclsNames cons - tyClDeclTyVars :: TyClDecl name -> [LHsTyVarBndr name] tyClDeclTyVars (TyFamily {tcdTyVars = tvs}) = tvs tyClDeclTyVars (TySynonym {tcdTyVars = tvs}) = tvs @@ -753,24 +740,6 @@ instance OutputableBndr name => Outputable (ResType name) where ppr (ResTyGADT ty) = ptext (sLit "ResTyGADT") <+> pprParendHsType (unLoc ty) \end{code} -\begin{code} -hsConDeclsNames :: (Eq name) => [LConDecl name] -> [Located name] - -- See tyClDeclNames for what this does - -- The function is boringly complicated because of the records - -- And since we only have equality, we have to be a little careful -hsConDeclsNames cons - = snd (foldl do_one ([], []) cons) - where - do_one (flds_seen, acc) (L _ (ConDecl { con_name = lname, con_details = RecCon flds })) - = (map unLoc new_flds ++ flds_seen, lname : new_flds ++ acc) - where - new_flds = filterOut (\f -> unLoc f `elem` flds_seen) - (map cd_fld_name flds) - - do_one (flds_seen, acc) (L _ (ConDecl { con_name = lname })) - = (flds_seen, lname:acc) -\end{code} - \begin{code} instance (OutputableBndr name) => Outputable (ConDecl name) where @@ -833,8 +802,8 @@ instance (OutputableBndr name) => Outputable (InstDecl name) where -- Extract the declarations of associated types from an instance -- -instDeclATs :: InstDecl name -> [LTyClDecl name] -instDeclATs (InstDecl _ _ _ ats) = ats +instDeclATs :: [LInstDecl name] -> [LTyClDecl name] +instDeclATs inst_decls = [at | L _ (InstDecl _ _ _ ats) <- inst_decls, at <- ats] \end{code} %************************************************************************