2 % (c) The AQUA Project, Glasgow University, 1996-1998
4 \section[RnHsSyn]{Specialisations of the @HsSyn@ syntax for the renamer}
9 #include "HsVersions.h"
12 import TysWiredIn ( tupleTyCon, listTyCon, charTyCon )
13 import Name ( Name, getName, isTyVarName )
15 import BasicTypes ( Boxity )
21 type RenamedArithSeqInfo = ArithSeqInfo Name RenamedPat
22 type RenamedClassOpSig = Sig Name
23 type RenamedConDecl = ConDecl Name
24 type RenamedContext = HsContext Name
25 type RenamedHsDecl = HsDecl Name RenamedPat
26 type RenamedRuleDecl = RuleDecl Name RenamedPat
27 type RenamedTyClDecl = TyClDecl Name RenamedPat
28 type RenamedDefaultDecl = DefaultDecl Name
29 type RenamedForeignDecl = ForeignDecl Name
30 type RenamedGRHS = GRHS Name RenamedPat
31 type RenamedGRHSs = GRHSs Name RenamedPat
32 type RenamedHsBinds = HsBinds Name RenamedPat
33 type RenamedHsExpr = HsExpr Name RenamedPat
34 type RenamedHsModule = HsModule Name RenamedPat
35 type RenamedInstDecl = InstDecl Name RenamedPat
36 type RenamedMatch = Match Name RenamedPat
37 type RenamedMonoBinds = MonoBinds Name RenamedPat
38 type RenamedPat = InPat Name
39 type RenamedHsType = HsType Name
40 type RenamedHsPred = HsPred Name
41 type RenamedRecordBinds = HsRecordBinds Name RenamedPat
42 type RenamedSig = Sig Name
43 type RenamedStmt = Stmt Name RenamedPat
44 type RenamedFixitySig = FixitySig Name
45 type RenamedDeprecation = DeprecDecl Name
46 type RenamedHsOverLit = HsOverLit Name
49 %************************************************************************
51 \subsection{Free variables}
53 %************************************************************************
55 These free-variable finders returns tycons and classes too.
58 charTyCon_name, listTyCon_name :: Name
59 charTyCon_name = getName charTyCon
60 listTyCon_name = getName listTyCon
62 tupleTyCon_name :: Boxity -> Int -> Name
63 tupleTyCon_name boxity n = getName (tupleTyCon boxity n)
65 extractHsTyVars :: RenamedHsType -> NameSet
66 extractHsTyVars x = filterNameSet isTyVarName (extractHsTyNames x)
68 extractHsTyNames :: RenamedHsType -> NameSet
72 get (HsAppTy ty1 ty2) = get ty1 `unionNameSets` get ty2
73 get (HsListTy ty) = unitNameSet listTyCon_name `unionNameSets` get ty
74 get (HsTupleTy (HsTupCon n _) tys) = unitNameSet n
75 `unionNameSets` extractHsTyNames_s tys
76 get (HsFunTy ty1 ty2) = get ty1 `unionNameSets` get ty2
77 get (HsPredTy p) = extractHsPredTyNames p
78 get (HsUsgForAllTy uv ty) = get ty
79 get (HsUsgTy u ty) = get ty
80 get (HsOpTy ty1 tycon ty2) = get ty1 `unionNameSets` get ty2 `unionNameSets`
82 get (HsNumTy n) = emptyNameSet
83 get (HsTyVar tv) = unitNameSet tv
84 get (HsForAllTy (Just tvs)
85 ctxt ty) = (extractHsCtxtTyNames ctxt `unionNameSets` get ty)
87 mkNameSet (hsTyVarNames tvs)
88 get ty@(HsForAllTy Nothing _ _) = pprPanic "extractHsTyNames" (ppr ty)
90 extractHsTyNames_s :: [RenamedHsType] -> NameSet
91 extractHsTyNames_s tys = foldr (unionNameSets . extractHsTyNames) emptyNameSet tys
93 extractHsCtxtTyNames :: RenamedContext -> NameSet
94 extractHsCtxtTyNames ctxt = foldr (unionNameSets . extractHsPredTyNames) emptyNameSet ctxt
96 -- You don't import or export implicit parameters,
97 -- so don't mention the IP names
98 extractHsPredTyNames (HsPClass cls tys)
99 = unitNameSet cls `unionNameSets` extractHsTyNames_s tys
100 extractHsPredTyNames (HsPIParam n ty)
101 = extractHsTyNames ty
105 %************************************************************************
107 \subsection{A few functions on generic defintions
109 %************************************************************************
111 These functions on generics are defined over RenamedMatches, which is
112 why they are here and not in HsMatches.
115 maybeGenericMatch :: RenamedMatch -> Maybe (RenamedHsType, RenamedMatch)
116 -- Tells whether a Match is for a generic definition
117 -- and extract the type from a generic match and put it at the front
119 maybeGenericMatch (Match tvs (TypePatIn ty : pats) sig_ty grhss)
120 = Just (ty, Match tvs pats sig_ty grhss)
122 maybeGenericMatch other_match = Nothing