on 727d708 help sign in
elk/compiler/Transform/LetBoundVars.hs
54 lines 1.6 kB history raw
1module LetBoundVars (letBoundVars) where
3import Context
4import Ast
6class LetBoundVars a where
7 letBoundVars :: a -> [String]
9instance LetBoundVars a => LetBoundVars [a] where
10 letBoundVars = concatMap letBoundVars
12instance LetBoundVars Statement where
13 letBoundVars stmt =
14 case stmt of
15 Definition d -> letBoundVars d
16 Datatype _ _ tcs -> []
17 ImportEvent _ e _ _ -> letBoundVars e
18 ExportEvent _ _ _ -> []
19 TypeAnnotation _ _ -> []
20 TypeAlias _ _ _ -> []
22instance LetBoundVars Def where
23 letBoundVars (FnDef n _ e) = n : letBoundVars e
24 letBoundVars (OpDef _ _ _ e) = letBoundVars e
25 letBoundVars _ = []
27instance LetBoundVars e => LetBoundVars (Context e) where
28 letBoundVars (C _ _ e) = letBoundVars e
30instance LetBoundVars Expr where
31 letBoundVars expr =
32 let f = letBoundVars in
33 case expr of
34 IntNum _ -> []
35 FloatNum _ -> []
36 Chr _ -> []
37 Str _ -> []
38 Boolean _ -> []
39 Range e1 e2 -> f e1 ++ f e2
40 Access e _ -> []
41 Remove e _ -> []
42 Insert e1 _ e2 -> f e1 ++ f e2
43 Modify e ps -> f e ++ concatMap (f . snd) ps
44 Record trps -> concatMap (\(_,_,e) -> f e) trps
45 Binop op e1 e2 -> f e1 ++ f e2
46 Lambda x e -> f e
47 App e1 e2 -> f e1 ++ f e2
48 If e1 e2 e3 -> concatMap f [e1,e2,e3]
49 MultiIf ps -> concatMap (\(b,e) -> f b ++ f e) ps
50 Let defs e -> concatMap letBoundVars defs ++ f e
51 Var x -> []
52 Data name es -> concatMap f es
53 Case e cases -> f e ++ concatMap (f . snd) cases
54 Markdown _ -> []