]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Language/Haskell/TH/HideName.hs
nix: cleanup
[haskell/symantic-parser.git] / src / Language / Haskell / TH / HideName.hs
1 module Language.Haskell.TH.HideName where
2
3 import Data.Functor ((<$>))
4 import Language.Haskell.TH
5 import Language.Haskell.TH.Syntax
6 import Prelude (undefined)
7
8 class HideName a where
9 -- | Map all 'Name's to a constant in order to overcome
10 -- cases where reseting 'TH.counter' is not enough
11 -- to get deterministic 'TH.Name's.
12 hideName :: a -> a
13 instance HideName Body where
14 hideName (GuardedB gs) = GuardedB ((\(g, e) -> (hideName g, hideName e)) <$> gs)
15 hideName (NormalB e) = NormalB (hideName e)
16 instance HideName Clause where
17 hideName (Clause ps b ds) = Clause (hideName <$> ps) (hideName b) (hideName <$> ds)
18 instance HideName Dec where
19 hideName (FunD f cs) = FunD (hideName f) (hideName <$> cs)
20 hideName (ValD p r ds) = ValD (hideName p) (hideName r) (hideName <$> ds)
21 -- Other alternatives are not used by Symantic.Parser, hence don't bother.
22 hideName _ = undefined
23 instance HideName Exp where
24 hideName (AppE e1 e2) = AppE (hideName e1) (hideName e2)
25 hideName (AppTypeE e t) = AppTypeE (hideName e) (hideName t)
26 hideName (ArithSeqE d) = ArithSeqE (hideName d)
27 hideName (CaseE e ms) = CaseE (hideName e) (hideName <$> ms)
28 hideName (CompE ss) = CompE (hideName <$> ss)
29 hideName (ConE c) = ConE (hideName c)
30 hideName (CondE guard true false) = CondE (hideName guard) (hideName true) (hideName false)
31 hideName (DoE m ss) = DoE (hideName <$> m) (hideName <$> ss)
32 hideName (ImplicitParamVarE n) = ImplicitParamVarE n
33 hideName (InfixE e1 op e2) = InfixE (hideName <$> e1) (hideName op) (hideName <$> e2)
34 hideName (LabelE s) = LabelE s
35 hideName (LamCaseE ms) = LamCaseE (hideName <$> ms)
36 hideName (LamE ps e) = LamE (hideName <$> ps) (hideName e)
37 hideName (LetE ds e) = LetE (hideName <$> ds) (hideName e)
38 hideName (ListE es) = ListE (hideName <$> es)
39 hideName (LitE l) = LitE l
40 hideName (MDoE m ss) = MDoE (hideName <$> m) (hideName <$> ss)
41 hideName (MultiIfE alts) = MultiIfE ((\(g, e) -> (hideName g, hideName e)) <$> alts)
42 hideName (ParensE e) = ParensE (hideName e)
43 hideName (RecConE nm fs) = RecConE (hideName nm) ((\(n, e) -> (hideName n, hideName e)) <$> fs)
44 hideName (RecUpdE e fs) = RecUpdE (hideName e) ((\(n, ee) -> (hideName n, hideName ee)) <$> fs)
45 hideName (SigE e t) = SigE (hideName e) (hideName t)
46 hideName (StaticE e) = StaticE (hideName e)
47 hideName (TupE es) = TupE ((hideName <$>) <$> es)
48 hideName (UInfixE e1 op e2) = UInfixE (hideName e1) (hideName op) (hideName e2)
49 hideName (UnboundVarE v) = UnboundVarE (hideName v)
50 hideName (UnboxedSumE e alt arity) = UnboxedSumE (hideName e) alt arity
51 hideName (UnboxedTupE es) = UnboxedTupE ((hideName <$>) <$> es)
52 hideName (VarE v) = VarE (hideName v)
53 instance HideName Guard where
54 hideName (NormalG e) = NormalG (hideName e)
55 hideName (PatG ss) = PatG (hideName <$> ss)
56 instance HideName Lit where
57 hideName x = x
58 instance HideName Match where
59 hideName (Match p b ds) = Match (hideName p) (hideName b) (hideName <$> ds)
60 instance HideName ModName where
61 hideName (ModName n) = ModName n
62 instance HideName Name where
63 -- This is the hidding
64 hideName (Name (OccName on) (NameU _u)) = Name (OccName on) NameS
65 hideName (Name (OccName on) (NameL _u)) = Name (OccName on) NameS
66 hideName (Name on n) = Name (hideName on) (hideName n)
67 instance HideName NameFlavour where
68 hideName (NameG n p m) = NameG n p m
69 hideName (NameL n) = NameL n
70 hideName (NameQ n) = NameQ n
71 hideName NameS = NameS
72 hideName (NameU n) = NameU n
73 instance HideName OccName where
74 hideName (OccName n) = OccName n
75 instance HideName Range where
76 hideName (FromR e) = FromR (hideName e)
77 hideName (FromThenR f t) = FromThenR (hideName f) (hideName t)
78 hideName (FromToR f t) = FromToR (hideName f) (hideName t)
79 hideName (FromThenToR f t to) = FromThenToR (hideName f) (hideName t) (hideName to)
80 instance HideName Stmt where
81 hideName (BindS p e) = BindS (hideName p) (hideName e)
82 hideName (LetS ds) = LetS (hideName <$> ds)
83 hideName (NoBindS e) = NoBindS (hideName e)
84 hideName (ParS ss) = ParS ((hideName <$>) <$> ss)
85 hideName (RecS ss) = RecS (hideName <$> ss)
86 instance HideName (TyVarBndr f) where
87 hideName (PlainTV n f) = PlainTV (hideName n) f
88 hideName (KindedTV n f k) = KindedTV (hideName n) f (hideName k)
89 instance HideName Type where
90 hideName (ForallT vs ctx t) = ForallT (hideName <$> vs) (hideName <$> ctx) (hideName t)
91 hideName (ForallVisT vs t) = ForallVisT (hideName <$> vs) (hideName t)
92 hideName (AppT t x) = AppT (hideName t) (hideName x)
93 hideName (AppKindT t k) = AppKindT (hideName t) (hideName k)
94 hideName (SigT t k) = SigT (hideName t) (hideName k)
95 hideName (VarT n) = VarT (hideName n)
96 hideName (ConT n) = ConT (hideName n)
97 hideName (PromotedT n) = PromotedT (hideName n)
98 hideName (InfixT x n y) = InfixT (hideName x) (hideName n) (hideName y)
99 hideName (UInfixT x n y) = UInfixT (hideName x) (hideName n) (hideName y)
100 hideName (ParensT t) = ParensT (hideName t)
101 hideName (TupleT x) = TupleT x
102 hideName (UnboxedTupleT x) = UnboxedTupleT x
103 hideName (UnboxedSumT x) = UnboxedSumT x
104 hideName (ArrowT) = ArrowT
105 hideName (MulArrowT) = MulArrowT
106 hideName (EqualityT) = EqualityT
107 hideName (ListT) = ListT
108 hideName (PromotedTupleT x) = PromotedTupleT x
109 hideName (PromotedNilT) = PromotedNilT
110 hideName (PromotedConsT) = PromotedConsT
111 hideName (StarT) = StarT
112 hideName (ConstraintT) = ConstraintT
113 hideName (LitT t) = LitT t
114 hideName (WildCardT) = WildCardT
115 hideName (ImplicitParamT n t) = ImplicitParamT n (hideName t)
116 instance HideName Pat where
117 hideName (AsP v p) = AsP (hideName v) (hideName p)
118 hideName (BangP p) = BangP (hideName p)
119 hideName (ConP s ps) = ConP (hideName s) (hideName <$> ps)
120 hideName (InfixP p1 n p2) = InfixP (hideName p1) (hideName n) (hideName p2)
121 hideName (ListP ps) = ListP (hideName <$> ps)
122 hideName (LitP l) = LitP (hideName l)
123 hideName (ParensP p) = ParensP (hideName p)
124 hideName (RecP nm fs) = RecP (nm) ((\(n,p) -> (hideName n, hideName p)) <$> fs)
125 hideName (SigP p t) = SigP (hideName p) (hideName t)
126 hideName (TildeP p) = TildeP (hideName p)
127 hideName (TupP ps) = TupP (hideName <$> ps)
128 hideName (UInfixP p1 n p2) = UInfixP (hideName p1) (hideName n) (hideName p2)
129 hideName (UnboxedSumP p alt arity) = UnboxedSumP (hideName p) alt arity
130 hideName (UnboxedTupP ps) = UnboxedTupP (hideName <$> ps)
131 hideName (VarP v) = VarP (hideName v)
132 hideName (ViewP e p) = ViewP (hideName e) (hideName p)
133 hideName WildP = WildP