1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
module AbstractCurry.Select
( progName, imports, functions, constructors, types, publicFuncNames
, publicConsNames, publicTypeNames
, typeName, typeVis, typeCons
, consName, consVis
, isBaseType, isPolyType, isFunctionalType, isIOType, isIOReturnType
, argTypes, resultType, tvarsOfType, tconsOfType, modsOfType
, funcName, funcArity, funcComment, funcVis, funcType, funcRules
, ruleRHS, ldeclsOfRule
, varsOfPat, varsOfExp, varsOfRhs, varsOfStat, varsOfLDecl
, varsOfFDecl, varsOfRule
, funcNamesOfLDecl, funcNamesOfFDecl, funcNamesOfStat
, isPrelude
) where
import AbstractCurry.Types
import List(union)
progName :: CurryProg -> String
progName (CurryProg modname _ _ _ _) = modname
imports :: CurryProg -> [MName]
imports (CurryProg _ ms _ _ _) = ms
functions :: CurryProg -> [CFuncDecl]
functions (CurryProg _ _ _ fs _) = fs
constructors :: CurryProg -> [CConsDecl]
constructors = concatMap typeCons . types
types :: CurryProg -> [CTypeDecl]
types (CurryProg _ _ ts _ _) = ts
publicFuncNames :: CurryProg -> [QName]
publicFuncNames = map funcName . filter ((== Public) . funcVis) . functions
publicConsNames :: CurryProg -> [QName]
publicConsNames = map consName
. filter ((== Public) . consVis)
. constructors
publicTypeNames :: CurryProg -> [QName]
publicTypeNames = map typeName . filter ((== Public) . typeVis) . types
typeName :: CTypeDecl -> QName
typeName (CType n _ _ _) = n
typeName (CTypeSyn n _ _ _) = n
typeName (CNewType n _ _ _) = n
typeVis :: CTypeDecl -> CVisibility
typeVis (CType _ vis _ _) = vis
typeVis (CTypeSyn _ vis _ _) = vis
typeVis (CNewType _ vis _ _) = vis
typeCons :: CTypeDecl -> [CConsDecl]
typeCons (CType _ _ _ cs) = cs
typeCons (CTypeSyn _ _ _ _ ) = []
typeCons (CNewType _ _ _ c ) = [c]
consName :: CConsDecl -> QName
consName (CCons n _ _) = n
consName (CRecord n _ _) = n
consVis :: CConsDecl -> CVisibility
consVis (CCons _ vis _) = vis
consVis (CRecord _ vis _) = vis
isBaseType :: CTypeExpr -> Bool
isBaseType texp = case texp of
CTCons _ args -> null args
_ -> False
isPolyType :: CTypeExpr -> Bool
isPolyType (CTVar _) = True
isPolyType (CFuncType domain range) = isPolyType domain || isPolyType range
isPolyType (CTCons _ typelist) = any isPolyType typelist
isFunctionalType :: CTypeExpr -> Bool
isFunctionalType texp = case texp of
CFuncType _ _ -> True
_ -> False
isIOType :: CTypeExpr -> Bool
isIOType texp = case texp of
CTCons tc _ -> tc == pre "IO"
_ -> False
isIOReturnType :: CTypeExpr -> Bool
isIOReturnType (CTVar _) = False
isIOReturnType (CFuncType _ _) = False
isIOReturnType (CTCons tc typelist) =
tc==pre "IO" && head typelist /= CTCons (pre "()") []
&& not (isFunctionalType (head typelist))
argTypes :: CTypeExpr -> [CTypeExpr]
argTypes (CTVar _) = []
argTypes (CTCons _ _) = []
argTypes (CFuncType t1 t2) = t1 : argTypes t2
resultType :: CTypeExpr -> CTypeExpr
resultType (CTVar n) = CTVar n
resultType (CTCons name args) = CTCons name args
resultType (CFuncType _ t2) = resultType t2
tvarsOfType :: CTypeExpr -> [CTVarIName]
tvarsOfType (CTVar v) = [v]
tvarsOfType (CFuncType t1 t2) = tvarsOfType t1 ++ tvarsOfType t2
tvarsOfType (CTCons _ args) = concatMap tvarsOfType args
tconsOfType :: CTypeExpr -> [QName]
tconsOfType (CTVar _) = []
tconsOfType (CFuncType t1 t2) = tconsOfType t1 `union` tconsOfType t2
tconsOfType (CTCons tc tys) = foldr union [tc] $ map tconsOfType tys
modsOfType :: CTypeExpr -> [String]
modsOfType = map fst . tconsOfType
funcName :: CFuncDecl -> QName
funcName (CFunc n _ _ _ _) = n
funcName (CmtFunc _ n _ _ _ _) = n
funcArity :: CFuncDecl -> Int
funcArity (CFunc _ a _ _ _) = a
funcArity (CmtFunc _ _ a _ _ _) = a
funcComment :: CFuncDecl -> String
(CFunc _ _ _ _ _) = ""
funcComment (CmtFunc cmt _ _ _ _ _) = cmt
funcVis :: CFuncDecl -> CVisibility
funcVis (CFunc _ _ vis _ _) = vis
funcVis (CmtFunc _ _ _ vis _ _) = vis
funcType :: CFuncDecl -> CTypeExpr
funcType (CFunc _ _ _ texp _) = texp
funcType (CmtFunc _ _ _ _ texp _) = texp
funcRules :: CFuncDecl -> [CRule]
funcRules (CFunc _ _ _ _ rules) = rules
funcRules (CmtFunc _ _ _ _ _ rules) = rules
ruleRHS :: CRule -> CRhs
ruleRHS (CRule _ rhs) = rhs
ldeclsOfRule :: CRule -> [CLocalDecl]
ldeclsOfRule (CRule _ (CSimpleRhs _ lDecls)) = lDecls
ldeclsOfRule (CRule _ (CGuardedRhs _ lDecls)) = lDecls
varsOfPat :: CPattern -> [CVarIName]
varsOfPat (CPVar v) = [v]
varsOfPat (CPLit _) = []
varsOfPat (CPComb _ pats) = concatMap varsOfPat pats
varsOfPat (CPAs v pat) = v : varsOfPat pat
varsOfPat (CPFuncComb _ pats) = concatMap varsOfPat pats
varsOfPat (CPLazy pat) = varsOfPat pat
varsOfPat (CPRecord _ recpats) = concatMap (varsOfPat . snd) recpats
varsOfExp :: CExpr -> [CVarIName]
varsOfExp (CVar v) = [v]
varsOfExp (CLit _) = []
varsOfExp (CSymbol _) = []
varsOfExp (CApply e1 e2) = varsOfExp e1 ++ varsOfExp e2
varsOfExp (CLambda pl le) = concatMap varsOfPat pl ++ varsOfExp le
varsOfExp (CLetDecl ld le) = concatMap varsOfLDecl ld ++ varsOfExp le
varsOfExp (CDoExpr sl) = concatMap varsOfStat sl
varsOfExp (CListComp le sl) = varsOfExp le ++ concatMap varsOfStat sl
varsOfExp (CCase _ ce bl) =
varsOfExp ce ++ concatMap (\ (p,rhs) -> varsOfPat p ++ varsOfRhs rhs) bl
varsOfExp (CTyped te _) = varsOfExp te
varsOfExp (CRecConstr _ upds) = concatMap (varsOfExp . snd) upds
varsOfExp (CRecUpdate e upds) = varsOfExp e ++ concatMap (varsOfExp . snd) upds
varsOfRhs :: CRhs -> [CVarIName]
varsOfRhs (CSimpleRhs rhs ldecls) =
varsOfExp rhs ++ concatMap varsOfLDecl ldecls
varsOfRhs (CGuardedRhs gs ldecls) =
concatMap (\ (g,e) -> varsOfExp g ++ varsOfExp e) gs ++
concatMap varsOfLDecl ldecls
varsOfStat :: CStatement -> [CVarIName]
varsOfStat (CSExpr e) = varsOfExp e
varsOfStat (CSPat p e) = varsOfPat p ++ varsOfExp e
varsOfStat (CSLet ld) = concatMap varsOfLDecl ld
varsOfLDecl :: CLocalDecl -> [CVarIName]
varsOfLDecl (CLocalFunc f) = varsOfFDecl f
varsOfLDecl (CLocalPat p rhs) = varsOfPat p ++ varsOfRhs rhs
varsOfLDecl (CLocalVars lvars) = lvars
varsOfFDecl :: CFuncDecl -> [CVarIName]
varsOfFDecl (CFunc _ _ _ _ r) = concatMap varsOfRule r
varsOfFDecl (CmtFunc _ _ _ _ _ r) = concatMap varsOfRule r
varsOfRule :: CRule -> [CVarIName]
varsOfRule (CRule pats rhs) = concatMap varsOfPat pats ++ varsOfRhs rhs
funcNamesOfLDecl :: CLocalDecl -> [QName]
funcNamesOfLDecl lDecl =
case lDecl of CLocalFunc f -> funcNamesOfFDecl f
_ -> []
funcNamesOfFDecl :: CFuncDecl -> [QName]
funcNamesOfFDecl (CFunc qn _ _ _ _) = [qn]
funcNamesOfFDecl (CmtFunc _ qn _ _ _ _) = [qn]
funcNamesOfStat :: CStatement -> [QName]
funcNamesOfStat stms =
case stms of CSLet ld -> concatMap funcNamesOfLDecl ld
_ -> []
isPrelude :: String -> Bool
isPrelude m = m == "Prelude"
|