@@ -0,0 +1,53 @@
1+module LetBoundVars (letBoundVars) where
2+
3+import Context
4+import Ast
5+
6+class LetBoundVars a where
7+ letBoundVars :: a -> [String]
8+
9+instance LetBoundVars a => LetBoundVars [a] where
10+ letBoundVars = concatMap letBoundVars
11+
12+instance 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 _ _ _ -> []
21+
22+instance LetBoundVars Def where
23+ letBoundVars (FnDef n _ e) = n : letBoundVars' e
24+ letBoundVars (OpDef _ _ _ e) = letBoundVars' e
25+
26+letBoundVars' :: CExpr -> [String]
27+letBoundVars' (C _ _ e) = letBoundVars e
28+
29+instance LetBoundVars Expr where
30+ letBoundVars expr =
31+ let f = letBoundVars' in
32+ case expr of
33+ IntNum _ -> []
34+ FloatNum _ -> []
35+ Chr _ -> []
36+ Str _ -> []
37+ Boolean _ -> []
38+ Range e1 e2 -> f e1 ++ f e2
39+ Access e _ -> []
40+ Remove e _ -> []
41+ Insert e1 _ e2 -> f e1 ++ f e2
42+ Modify e ps -> f e ++ concatMap (f . snd) ps
43+ Record trps -> concatMap (\(_,_,e) -> f e) trps
44+ Binop op e1 e2 -> f e1 ++ f e2
45+ Lambda x e -> f e
46+ App e1 e2 -> f e1 ++ f e2
47+ If e1 e2 e3 -> concatMap f [e1,e2,e3]
48+ MultiIf ps -> concatMap (\(b,e) -> f b ++ f e) ps
49+ Let defs e -> concatMap letBoundVars defs ++ f e
50+ Var x -> []
51+ Data name es -> concatMap f es
52+ Case e cases -> f e ++ concatMap (f . snd) cases
53+ Markdown _ -> []