adam@1847
|
1 (* Copyright (c) 2008, 2013, Adam Chlipala
|
adamc@26
|
2 * All rights reserved.
|
adamc@26
|
3 *
|
adamc@26
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@26
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@26
|
6 *
|
adamc@26
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@26
|
8 * this list of conditions and the following disclaimer.
|
adamc@26
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@26
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@26
|
11 * and/or other materials provided with the distribution.
|
adamc@26
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@26
|
13 * derived from this software without specific prior written permission.
|
adamc@26
|
14 *
|
adamc@26
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@26
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@26
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@26
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
ziv@2218
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@26
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@26
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@26
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@26
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@26
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@26
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@26
|
26 *)
|
adamc@26
|
27
|
adamc@26
|
28 structure MonoUtil :> MONO_UTIL = struct
|
adamc@26
|
29
|
adamc@26
|
30 open Mono
|
adamc@26
|
31
|
adamc@26
|
32 structure S = Search
|
adamc@26
|
33
|
adamc@267
|
34 val dummyt = (TRecord [], ErrorMsg.dummySpan)
|
adamc@267
|
35
|
adamc@26
|
36 structure Typ = struct
|
adamc@26
|
37
|
adamc@193
|
38 open Order
|
adamc@109
|
39
|
adamc@109
|
40 fun compare ((t1, _), (t2, _)) =
|
adamc@109
|
41 case (t1, t2) of
|
adamc@109
|
42 (TFun (d1, r1), TFun (d2, r2)) =>
|
adamc@109
|
43 join (compare (d1, d2), fn () => compare (r1, r2))
|
adamc@109
|
44 | (TRecord xts1, TRecord xts2) =>
|
adamc@109
|
45 let
|
adamc@109
|
46 val xts1 = sortFields xts1
|
adamc@109
|
47 val xts2 = sortFields xts2
|
adamc@109
|
48 in
|
adamc@109
|
49 joinL compareFields (xts1, xts2)
|
adamc@109
|
50 end
|
adamc@196
|
51 | (TDatatype (n1, _), TDatatype (n2, _)) => Int.compare (n1, n2)
|
adamc@109
|
52 | (TFfi (m1, x1), TFfi (m2, x2)) => join (String.compare (m1, m2), fn () => String.compare (x1, x2))
|
adamc@288
|
53 | (TOption t1, TOption t2) => compare (t1, t2)
|
adamc@757
|
54 | (TList t1, TList t2) => compare (t1, t2)
|
adamc@577
|
55 | (TSource, TSource) => EQUAL
|
adamc@568
|
56 | (TSignal t1, TSignal t2) => compare (t1, t2)
|
adamc@109
|
57
|
adamc@109
|
58 | (TFun _, _) => LESS
|
adamc@109
|
59 | (_, TFun _) => GREATER
|
adamc@109
|
60
|
adamc@109
|
61 | (TRecord _, _) => LESS
|
adamc@109
|
62 | (_, TRecord _) => GREATER
|
adamc@109
|
63
|
adamc@168
|
64 | (TDatatype _, _) => LESS
|
adamc@168
|
65 | (_, TDatatype _) => GREATER
|
adamc@109
|
66
|
adamc@288
|
67 | (TFfi _, _) => LESS
|
adamc@288
|
68 | (_, TFfi _) => GREATER
|
adamc@288
|
69
|
adamc@568
|
70 | (TOption _, _) => LESS
|
adamc@568
|
71 | (_, TOption _) => GREATER
|
adamc@568
|
72
|
adamc@757
|
73 | (TList _, _) => LESS
|
adamc@757
|
74 | (_, TList _) => GREATER
|
adamc@757
|
75
|
adamc@577
|
76 | (TSource, _) => LESS
|
adamc@577
|
77 | (_, TSource) => GREATER
|
adamc@577
|
78
|
adamc@109
|
79 and compareFields ((x1, t1), (x2, t2)) =
|
adamc@109
|
80 join (String.compare (x1, x2),
|
adamc@109
|
81 fn () => compare (t1, t2))
|
adamc@109
|
82
|
adam@1314
|
83 and sortFields xts = ListMergeSort.sort (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) xts
|
adamc@109
|
84
|
adamc@26
|
85 fun mapfold fc =
|
adamc@26
|
86 let
|
adamc@26
|
87 fun mft c acc =
|
adamc@26
|
88 S.bindP (mft' c acc, fc)
|
adamc@26
|
89
|
adamc@26
|
90 and mft' (cAll as (c, loc)) =
|
adamc@26
|
91 case c of
|
adamc@26
|
92 TFun (t1, t2) =>
|
adamc@26
|
93 S.bind2 (mft t1,
|
adamc@26
|
94 fn t1' =>
|
adamc@26
|
95 S.map2 (mft t2,
|
adamc@26
|
96 fn t2' =>
|
adamc@26
|
97 (TFun (t1', t2'), loc)))
|
adamc@26
|
98 | TRecord xts =>
|
adamc@26
|
99 S.map2 (ListUtil.mapfold (fn (x, t) =>
|
adamc@26
|
100 S.map2 (mft t,
|
adamc@26
|
101 fn t' =>
|
adamc@26
|
102 (x, t')))
|
adamc@26
|
103 xts,
|
adamc@26
|
104 fn xts' => (TRecord xts', loc))
|
adamc@168
|
105 | TDatatype _ => S.return2 cAll
|
adamc@51
|
106 | TFfi _ => S.return2 cAll
|
adamc@288
|
107 | TOption t =>
|
adamc@288
|
108 S.map2 (mft t,
|
adamc@288
|
109 fn t' =>
|
adamc@288
|
110 (TOption t, loc))
|
adamc@757
|
111 | TList t =>
|
adamc@757
|
112 S.map2 (mft t,
|
adamc@757
|
113 fn t' =>
|
adamc@757
|
114 (TList t, loc))
|
adamc@577
|
115 | TSource => S.return2 cAll
|
adamc@568
|
116 | TSignal t =>
|
adamc@568
|
117 S.map2 (mft t,
|
adamc@568
|
118 fn t' =>
|
adamc@568
|
119 (TSignal t, loc))
|
adamc@26
|
120 in
|
adamc@26
|
121 mft
|
adamc@26
|
122 end
|
adamc@26
|
123
|
adamc@26
|
124 fun map typ c =
|
adamc@26
|
125 case mapfold (fn c => fn () => S.Continue (typ c, ())) c () of
|
adamc@26
|
126 S.Return () => raise Fail "Mono_util.Typ.map"
|
adamc@26
|
127 | S.Continue (c, ()) => c
|
adamc@26
|
128
|
adamc@26
|
129 fun fold typ s c =
|
adamc@26
|
130 case mapfold (fn c => fn s => S.Continue (c, typ (c, s))) c s of
|
adamc@26
|
131 S.Continue (_, s) => s
|
adamc@26
|
132 | S.Return _ => raise Fail "MonoUtil.Typ.fold: Impossible"
|
adamc@26
|
133
|
adamc@26
|
134 fun exists typ k =
|
adamc@26
|
135 case mapfold (fn c => fn () =>
|
adamc@26
|
136 if typ c then
|
adamc@26
|
137 S.Return ()
|
adamc@26
|
138 else
|
adamc@26
|
139 S.Continue (c, ())) k () of
|
adamc@26
|
140 S.Return _ => true
|
adamc@26
|
141 | S.Continue _ => false
|
adamc@26
|
142
|
adamc@26
|
143 end
|
adamc@26
|
144
|
adamc@26
|
145 structure Exp = struct
|
adamc@26
|
146
|
adamc@26
|
147 datatype binder =
|
adamc@168
|
148 Datatype of string * int * (string * int * typ option) list
|
adamc@26
|
149 | RelE of string * typ
|
adamc@109
|
150 | NamedE of string * int * typ * exp option * string
|
adamc@26
|
151
|
adamc@26
|
152 fun mapfoldB {typ = fc, exp = fe, bind} =
|
adamc@26
|
153 let
|
adamc@26
|
154 val mft = Typ.mapfold fc
|
adamc@26
|
155
|
adamc@26
|
156 fun mfe ctx e acc =
|
adamc@26
|
157 S.bindP (mfe' ctx e acc, fe ctx)
|
adamc@26
|
158
|
adam@1663
|
159 and mfet ctx (e, t) =
|
adam@1663
|
160 S.bind2 (mfe ctx e,
|
adam@1663
|
161 fn e' =>
|
adam@1663
|
162 S.map2 (mft t,
|
adam@1663
|
163 fn t' => (e', t')))
|
adam@1663
|
164
|
adamc@26
|
165 and mfe' ctx (eAll as (e, loc)) =
|
adamc@26
|
166 case e of
|
adamc@26
|
167 EPrim _ => S.return2 eAll
|
adamc@26
|
168 | ERel _ => S.return2 eAll
|
adamc@26
|
169 | ENamed _ => S.return2 eAll
|
adamc@188
|
170 | ECon (_, _, NONE) => S.return2 eAll
|
adamc@188
|
171 | ECon (dk, n, SOME e) =>
|
adamc@178
|
172 S.map2 (mfe ctx e,
|
adamc@178
|
173 fn e' =>
|
adamc@188
|
174 (ECon (dk, n, SOME e'), loc))
|
adamc@297
|
175 | ENone t =>
|
adamc@297
|
176 S.map2 (mft t,
|
adamc@297
|
177 fn t' =>
|
adamc@297
|
178 (ENone t', loc))
|
adamc@290
|
179 | ESome (t, e) =>
|
adamc@290
|
180 S.bind2 (mft t,
|
adamc@290
|
181 fn t' =>
|
adamc@290
|
182 S.map2 (mfe ctx e,
|
adamc@290
|
183 fn e' =>
|
adamc@290
|
184 (ESome (t', e'), loc)))
|
adamc@51
|
185 | EFfi _ => S.return2 eAll
|
adamc@51
|
186 | EFfiApp (m, x, es) =>
|
adam@1663
|
187 S.map2 (ListUtil.mapfold (fn e => mfet ctx e) es,
|
adamc@51
|
188 fn es' =>
|
adamc@51
|
189 (EFfiApp (m, x, es'), loc))
|
adamc@26
|
190 | EApp (e1, e2) =>
|
adamc@26
|
191 S.bind2 (mfe ctx e1,
|
adamc@26
|
192 fn e1' =>
|
adamc@26
|
193 S.map2 (mfe ctx e2,
|
adamc@26
|
194 fn e2' =>
|
adamc@26
|
195 (EApp (e1', e2'), loc)))
|
adamc@26
|
196 | EAbs (x, dom, ran, e) =>
|
adamc@26
|
197 S.bind2 (mft dom,
|
adamc@26
|
198 fn dom' =>
|
adamc@26
|
199 S.bind2 (mft ran,
|
adamc@26
|
200 fn ran' =>
|
adamc@26
|
201 S.map2 (mfe (bind (ctx, RelE (x, dom'))) e,
|
adamc@26
|
202 fn e' =>
|
adamc@26
|
203 (EAbs (x, dom', ran', e'), loc))))
|
adamc@26
|
204
|
adamc@387
|
205 | EUnop (s, e) =>
|
adamc@387
|
206 S.map2 (mfe ctx e,
|
adamc@387
|
207 fn e' =>
|
adamc@387
|
208 (EUnop (s, e'), loc))
|
adam@1360
|
209 | EBinop (bi, s, e1, e2) =>
|
adamc@387
|
210 S.bind2 (mfe ctx e1,
|
adamc@387
|
211 fn e1' =>
|
adamc@387
|
212 S.map2 (mfe ctx e2,
|
adamc@387
|
213 fn e2' =>
|
adam@1360
|
214 (EBinop (bi, s, e1', e2'), loc)))
|
adamc@387
|
215
|
adamc@26
|
216 | ERecord xes =>
|
adamc@29
|
217 S.map2 (ListUtil.mapfold (fn (x, e, t) =>
|
adamc@29
|
218 S.bind2 (mfe ctx e,
|
adamc@26
|
219 fn e' =>
|
adamc@29
|
220 S.map2 (mft t,
|
adamc@29
|
221 fn t' =>
|
adamc@29
|
222 (x, e', t'))))
|
adamc@26
|
223 xes,
|
adamc@26
|
224 fn xes' =>
|
adamc@26
|
225 (ERecord xes', loc))
|
adamc@26
|
226 | EField (e, x) =>
|
adamc@26
|
227 S.map2 (mfe ctx e,
|
adamc@26
|
228 fn e' =>
|
adamc@26
|
229 (EField (e', x), loc))
|
adamc@94
|
230
|
adamc@182
|
231 | ECase (e, pes, {disc, result}) =>
|
adamc@178
|
232 S.bind2 (mfe ctx e,
|
adamc@178
|
233 fn e' =>
|
adamc@178
|
234 S.bind2 (ListUtil.mapfold (fn (p, e) =>
|
adamc@179
|
235 let
|
adamc@179
|
236 fun pb ((p, _), ctx) =
|
adamc@179
|
237 case p of
|
adamc@179
|
238 PWild => ctx
|
adamc@182
|
239 | PVar (x, t) => bind (ctx, RelE (x, t))
|
adamc@179
|
240 | PPrim _ => ctx
|
adamc@188
|
241 | PCon (_, _, NONE) => ctx
|
adamc@188
|
242 | PCon (_, _, SOME p) => pb (p, ctx)
|
adamc@182
|
243 | PRecord xps => foldl (fn ((_, p, _), ctx) =>
|
adamc@179
|
244 pb (p, ctx)) ctx xps
|
adamc@288
|
245 | PNone _ => ctx
|
adamc@288
|
246 | PSome (_, p) => pb (p, ctx)
|
adamc@179
|
247 in
|
adamc@179
|
248 S.map2 (mfe (pb (p, ctx)) e,
|
adamc@179
|
249 fn e' => (p, e'))
|
adamc@179
|
250 end) pes,
|
adamc@178
|
251 fn pes' =>
|
adamc@182
|
252 S.bind2 (mft disc,
|
adamc@182
|
253 fn disc' =>
|
adamc@182
|
254 S.map2 (mft result,
|
adamc@182
|
255 fn result' =>
|
adamc@182
|
256 (ECase (e', pes', {disc = disc', result = result'}), loc)))))
|
adamc@178
|
257
|
adamc@283
|
258 | EError (e, t) =>
|
adamc@283
|
259 S.bind2 (mfe ctx e,
|
adamc@283
|
260 fn e' =>
|
adamc@283
|
261 S.map2 (mft t,
|
adamc@283
|
262 fn t' =>
|
adamc@283
|
263 (EError (e', t'), loc)))
|
adam@1932
|
264 | EReturnBlob {blob = NONE, mimeType, t} =>
|
adam@1932
|
265 S.bind2 (mfe ctx mimeType,
|
adam@1932
|
266 fn mimeType' =>
|
adam@1932
|
267 S.map2 (mft t,
|
adam@1932
|
268 fn t' =>
|
adam@1932
|
269 (EReturnBlob {blob = NONE, mimeType = mimeType', t = t'}, loc)))
|
adam@1932
|
270 | EReturnBlob {blob = SOME blob, mimeType, t} =>
|
adamc@741
|
271 S.bind2 (mfe ctx blob,
|
adamc@741
|
272 fn blob' =>
|
adamc@741
|
273 S.bind2 (mfe ctx mimeType,
|
adamc@741
|
274 fn mimeType' =>
|
adamc@741
|
275 S.map2 (mft t,
|
adamc@741
|
276 fn t' =>
|
adam@1932
|
277 (EReturnBlob {blob = SOME blob', mimeType = mimeType', t = t'}, loc))))
|
adamc@1065
|
278 | ERedirect (e, t) =>
|
adamc@1065
|
279 S.bind2 (mfe ctx e,
|
adamc@1065
|
280 fn e' =>
|
adamc@1065
|
281 S.map2 (mft t,
|
adamc@1065
|
282 fn t' =>
|
adamc@1065
|
283 (ERedirect (e', t'), loc)))
|
ziv@2218
|
284
|
adamc@94
|
285 | EStrcat (e1, e2) =>
|
adamc@94
|
286 S.bind2 (mfe ctx e1,
|
adamc@94
|
287 fn e1' =>
|
adamc@94
|
288 S.map2 (mfe ctx e2,
|
adamc@94
|
289 fn e2' =>
|
adamc@94
|
290 (EStrcat (e1', e2'), loc)))
|
adamc@102
|
291
|
adamc@102
|
292 | EWrite e =>
|
adamc@102
|
293 S.map2 (mfe ctx e,
|
adamc@102
|
294 fn e' =>
|
adamc@102
|
295 (EWrite e', loc))
|
adamc@106
|
296
|
adamc@106
|
297 | ESeq (e1, e2) =>
|
adamc@106
|
298 S.bind2 (mfe ctx e1,
|
adamc@106
|
299 fn e1' =>
|
adamc@106
|
300 S.map2 (mfe ctx e2,
|
adamc@106
|
301 fn e2' =>
|
adamc@106
|
302 (ESeq (e1', e2'), loc)))
|
adamc@251
|
303 | ELet (x, t, e1, e2) =>
|
adamc@251
|
304 S.bind2 (mft t,
|
adamc@251
|
305 fn t' =>
|
adamc@251
|
306 S.bind2 (mfe ctx e1,
|
adamc@251
|
307 fn e1' =>
|
adamc@252
|
308 S.map2 (mfe (bind (ctx, RelE (x, t'))) e2,
|
adamc@251
|
309 fn e2' =>
|
adamc@251
|
310 (ELet (x, t', e1', e2'), loc))))
|
adamc@111
|
311
|
adamc@111
|
312 | EClosure (n, es) =>
|
adamc@111
|
313 S.map2 (ListUtil.mapfold (mfe ctx) es,
|
adamc@111
|
314 fn es' =>
|
adamc@111
|
315 (EClosure (n, es'), loc))
|
adamc@252
|
316
|
ziv@2221
|
317 | EQuery {exps, tables, state, query, body, initial, sqlcacheInfo} =>
|
adamc@252
|
318 S.bind2 (ListUtil.mapfold (fn (x, t) =>
|
adamc@252
|
319 S.map2 (mft t,
|
adamc@252
|
320 fn t' => (x, t'))) exps,
|
adamc@252
|
321 fn exps' =>
|
adamc@252
|
322 S.bind2 (ListUtil.mapfold (fn (x, xts) =>
|
adamc@252
|
323 S.map2 (ListUtil.mapfold
|
adamc@252
|
324 (fn (x, t) =>
|
adamc@252
|
325 S.map2 (mft t,
|
adamc@252
|
326 fn t' => (x, t'))) xts,
|
adamc@252
|
327 fn xts' => (x, xts'))) tables,
|
adamc@252
|
328 fn tables' =>
|
adamc@252
|
329 S.bind2 (mft state,
|
adamc@252
|
330 fn state' =>
|
adamc@252
|
331 S.bind2 (mfe ctx query,
|
adamc@252
|
332 fn query' =>
|
adamc@267
|
333 S.bind2 (mfe (bind (bind (ctx, RelE ("r", dummyt)),
|
adamc@267
|
334 RelE ("acc", dummyt)))
|
adamc@267
|
335 body,
|
adamc@267
|
336 fn body' =>
|
ziv@2221
|
337 (* ASK: is this the right thing to do? *)
|
ziv@2221
|
338 S.bind2 (mfe ctx initial,
|
adamc@267
|
339 fn initial' =>
|
ziv@2221
|
340 S.map2 (mfe (bind (ctx, RelE ("queryResult", dummyt)))
|
ziv@2221
|
341 sqlcacheInfo,
|
ziv@2221
|
342 fn sqlcacheInfo' =>
|
ziv@2221
|
343 (EQuery {exps = exps',
|
ziv@2221
|
344 tables = tables',
|
ziv@2221
|
345 state = state',
|
ziv@2221
|
346 query = query',
|
ziv@2221
|
347 body = body',
|
ziv@2221
|
348 initial = initial',
|
ziv@2221
|
349 sqlcacheInfo = sqlcacheInfo},
|
ziv@2221
|
350 loc))))))))
|
adamc@307
|
351
|
adam@1293
|
352 | EDml (e, fm) =>
|
adamc@307
|
353 S.map2 (mfe ctx e,
|
adamc@307
|
354 fn e' =>
|
adam@1293
|
355 (EDml (e', fm), loc))
|
adamc@338
|
356 | ENextval e =>
|
adamc@338
|
357 S.map2 (mfe ctx e,
|
adamc@338
|
358 fn e' =>
|
adamc@338
|
359 (ENextval e', loc))
|
adamc@1073
|
360 | ESetval (e1, e2) =>
|
adamc@1073
|
361 S.bind2 (mfe ctx e1,
|
adamc@1073
|
362 fn e1' =>
|
adamc@1073
|
363 S.map2 (mfe ctx e2,
|
adamc@1073
|
364 fn e2' =>
|
adamc@1073
|
365 (ESetval (e1', e2'), loc)))
|
adamc@1112
|
366 | EUnurlify (e, t, b) =>
|
adamc@463
|
367 S.bind2 (mfe ctx e,
|
adamc@463
|
368 fn e' =>
|
adamc@463
|
369 S.map2 (mft t,
|
adamc@463
|
370 fn t' =>
|
adamc@1112
|
371 (EUnurlify (e', t', b), loc)))
|
adamc@815
|
372 | EJavaScript (m, e) =>
|
adamc@729
|
373 S.bind2 (mfmode ctx m,
|
adamc@729
|
374 fn m' =>
|
adamc@729
|
375 S.map2 (mfe ctx e,
|
adamc@729
|
376 fn e' =>
|
adamc@815
|
377 (EJavaScript (m', e'), loc)))
|
adamc@569
|
378
|
adamc@568
|
379 | ESignalReturn e =>
|
adamc@568
|
380 S.map2 (mfe ctx e,
|
adamc@568
|
381 fn e' =>
|
adamc@568
|
382 (ESignalReturn e', loc))
|
adamc@572
|
383 | ESignalBind (e1, e2) =>
|
adamc@572
|
384 S.bind2 (mfe ctx e1,
|
adamc@572
|
385 fn e1' =>
|
adamc@572
|
386 S.map2 (mfe ctx e2,
|
adamc@572
|
387 fn e2' =>
|
adamc@572
|
388 (ESignalBind (e1', e2'), loc)))
|
adamc@574
|
389 | ESignalSource e =>
|
adamc@574
|
390 S.map2 (mfe ctx e,
|
adamc@574
|
391 fn e' =>
|
adamc@574
|
392 (ESignalSource e', loc))
|
adamc@608
|
393
|
adam@1848
|
394 | EServerCall (s, t, eff, fm) =>
|
adamc@642
|
395 S.bind2 (mfe ctx s,
|
adamc@642
|
396 fn s' =>
|
adamc@1020
|
397 S.map2 (mft t,
|
adamc@1020
|
398 fn t' =>
|
adam@1848
|
399 (EServerCall (s', t', eff, fm), loc)))
|
adamc@1021
|
400 | ERecv (s, t) =>
|
adamc@670
|
401 S.bind2 (mfe ctx s,
|
adamc@695
|
402 fn s' =>
|
adamc@1021
|
403 S.map2 (mft t,
|
adamc@1021
|
404 fn t' =>
|
adamc@1021
|
405 (ERecv (s', t'), loc)))
|
adamc@1021
|
406 | ESleep s =>
|
adamc@1021
|
407 S.map2 (mfe ctx s,
|
adamc@695
|
408 fn s' =>
|
adamc@1021
|
409 (ESleep s', loc))
|
adamc@1021
|
410
|
adamc@1021
|
411 | ESpawn s =>
|
adamc@1021
|
412 S.map2 (mfe ctx s,
|
adamc@1021
|
413 fn s' =>
|
adamc@1021
|
414 (ESpawn s', loc))
|
adamc@729
|
415
|
adamc@729
|
416 and mfmode ctx mode =
|
adamc@729
|
417 case mode of
|
adamc@729
|
418 Attribute => S.return2 mode
|
adamc@729
|
419 | Script => S.return2 mode
|
adamc@729
|
420 | Source t =>
|
adamc@729
|
421 S.map2 (mft t,
|
adamc@729
|
422 fn t' => Source t')
|
adamc@26
|
423 in
|
adamc@26
|
424 mfe
|
adamc@26
|
425 end
|
adamc@26
|
426
|
adamc@26
|
427 fun mapfold {typ = fc, exp = fe} =
|
adamc@26
|
428 mapfoldB {typ = fc,
|
adamc@26
|
429 exp = fn () => fe,
|
adamc@26
|
430 bind = fn ((), _) => ()} ()
|
adamc@26
|
431
|
adamc@26
|
432 fun mapB {typ, exp, bind} ctx e =
|
adamc@26
|
433 case mapfoldB {typ = fn c => fn () => S.Continue (typ c, ()),
|
adamc@26
|
434 exp = fn ctx => fn e => fn () => S.Continue (exp ctx e, ()),
|
adamc@26
|
435 bind = bind} ctx e () of
|
adamc@26
|
436 S.Continue (e, ()) => e
|
adamc@26
|
437 | S.Return _ => raise Fail "MonoUtil.Exp.mapB: Impossible"
|
adamc@26
|
438
|
adamc@26
|
439 fun map {typ, exp} e =
|
adamc@26
|
440 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
|
adamc@26
|
441 exp = fn e => fn () => S.Continue (exp e, ())} e () of
|
adamc@26
|
442 S.Return () => raise Fail "Mono_util.Exp.map"
|
adamc@26
|
443 | S.Continue (e, ()) => e
|
adamc@26
|
444
|
adamc@26
|
445 fun fold {typ, exp} s e =
|
adamc@26
|
446 case mapfold {typ = fn c => fn s => S.Continue (c, typ (c, s)),
|
adamc@26
|
447 exp = fn e => fn s => S.Continue (e, exp (e, s))} e s of
|
adamc@26
|
448 S.Continue (_, s) => s
|
adamc@26
|
449 | S.Return _ => raise Fail "MonoUtil.Exp.fold: Impossible"
|
adamc@26
|
450
|
adamc@26
|
451 fun exists {typ, exp} k =
|
adamc@26
|
452 case mapfold {typ = fn c => fn () =>
|
adamc@26
|
453 if typ c then
|
adamc@26
|
454 S.Return ()
|
adamc@26
|
455 else
|
adamc@26
|
456 S.Continue (c, ()),
|
adamc@26
|
457 exp = fn e => fn () =>
|
adamc@26
|
458 if exp e then
|
adamc@26
|
459 S.Return ()
|
adamc@26
|
460 else
|
adamc@26
|
461 S.Continue (e, ())} k () of
|
adamc@26
|
462 S.Return _ => true
|
adamc@26
|
463 | S.Continue _ => false
|
adamc@26
|
464
|
adamc@919
|
465 fun existsB {typ, exp, bind} ctx e =
|
adamc@919
|
466 case mapfoldB {typ = fn t => fn () =>
|
adamc@919
|
467 if typ t then
|
adamc@919
|
468 S.Return ()
|
adamc@919
|
469 else
|
adamc@919
|
470 S.Continue (t, ()),
|
adamc@919
|
471 exp = fn ctx => fn e => fn () =>
|
adamc@919
|
472 if exp (ctx, e) then
|
adamc@919
|
473 S.Return ()
|
adamc@919
|
474 else
|
adamc@919
|
475 S.Continue (e, ()),
|
adamc@919
|
476 bind = bind} ctx e () of
|
adamc@919
|
477 S.Return _ => true
|
adamc@919
|
478 | S.Continue _ => false
|
adamc@919
|
479
|
adamc@567
|
480 fun foldB {typ, exp, bind} ctx s e =
|
adamc@567
|
481 case mapfoldB {typ = fn t => fn s => S.Continue (t, typ (t, s)),
|
adamc@567
|
482 exp = fn ctx => fn e => fn s => S.Continue (e, exp (ctx, e, s)),
|
adamc@567
|
483 bind = bind} ctx e s of
|
adamc@567
|
484 S.Continue (_, s) => s
|
adamc@567
|
485 | S.Return _ => raise Fail "MonoUtil.Exp.foldB: Impossible"
|
adamc@567
|
486
|
adam@1612
|
487 fun appLoc f =
|
adam@1612
|
488 let
|
adam@1612
|
489 fun appl e =
|
adam@1612
|
490 (f e;
|
adam@1612
|
491 case #1 e of
|
adam@1612
|
492 EPrim _ => ()
|
adam@1612
|
493 | ERel _ => ()
|
adam@1612
|
494 | ENamed _ => ()
|
adam@1612
|
495 | ECon (_, _, eo) => Option.app appl eo
|
adam@1612
|
496 | ENone _ => ()
|
adam@1612
|
497 | ESome (_, e) => appl e
|
adam@1612
|
498 | EFfi _ => ()
|
adam@1663
|
499 | EFfiApp (_, _, es) => app (appl o #1) es
|
adam@1612
|
500 | EApp (e1, e2) => (appl e1; appl e2)
|
adam@1612
|
501 | EAbs (_, _, _, e1) => appl e1
|
adam@1612
|
502 | EUnop (_, e1) => appl e1
|
adam@1612
|
503 | EBinop (_, _, e1, e2) => (appl e1; appl e2)
|
adam@1612
|
504 | ERecord xets => app (appl o #2) xets
|
adam@1612
|
505 | EField (e1, _) => appl e1
|
adam@1612
|
506 | ECase (e1, pes, _) => (appl e1; app (appl o #2) pes)
|
adam@1612
|
507 | EStrcat (e1, e2) => (appl e1; appl e2)
|
adam@1612
|
508 | EError (e1, _) => appl e1
|
adam@1932
|
509 | EReturnBlob {blob = NONE, mimeType = e2, ...} => appl e2
|
adam@1932
|
510 | EReturnBlob {blob = SOME e1, mimeType = e2, ...} => (appl e1; appl e2)
|
adam@1612
|
511 | ERedirect (e1, _) => appl e1
|
adam@1612
|
512 | EWrite e1 => appl e1
|
adam@1612
|
513 | ESeq (e1, e2) => (appl e1; appl e2)
|
adam@1612
|
514 | ELet (_, _, e1, e2) => (appl e1; appl e2)
|
adam@1612
|
515 | EClosure (_, es) => app appl es
|
adam@1612
|
516 | EQuery {query = e1, body = e2, initial = e3, ...} => (appl e1; appl e2; appl e3)
|
adam@1612
|
517 | EDml (e1, _) => appl e1
|
adam@1612
|
518 | ENextval e1 => appl e1
|
adam@1612
|
519 | ESetval (e1, e2) => (appl e1; appl e2)
|
adam@1612
|
520 | EUnurlify (e1, _, _) => appl e1
|
adam@1612
|
521 | EJavaScript (_, e1) => appl e1
|
adam@1612
|
522 | ESignalReturn e1 => appl e1
|
adam@1612
|
523 | ESignalBind (e1, e2) => (appl e1; appl e2)
|
adam@1612
|
524 | ESignalSource e1 => appl e1
|
adam@1848
|
525 | EServerCall (e1, _, _, _) => appl e1
|
adam@1612
|
526 | ERecv (e1, _) => appl e1
|
adam@1612
|
527 | ESleep e1 => appl e1
|
adam@1612
|
528 | ESpawn e1 => appl e1)
|
adam@1612
|
529 in
|
adam@1612
|
530 appl
|
adam@1612
|
531 end
|
adam@1612
|
532
|
adamc@26
|
533 end
|
adamc@26
|
534
|
adamc@26
|
535 structure Decl = struct
|
adamc@26
|
536
|
adamc@26
|
537 datatype binder = datatype Exp.binder
|
adamc@26
|
538
|
adamc@26
|
539 fun mapfoldB {typ = fc, exp = fe, decl = fd, bind} =
|
adamc@26
|
540 let
|
adamc@26
|
541 val mft = Typ.mapfold fc
|
adamc@26
|
542
|
adamc@26
|
543 val mfe = Exp.mapfoldB {typ = fc, exp = fe, bind = bind}
|
adamc@26
|
544
|
adamc@26
|
545 fun mfd ctx d acc =
|
adamc@26
|
546 S.bindP (mfd' ctx d acc, fd ctx)
|
adamc@26
|
547
|
adamc@26
|
548 and mfd' ctx (dAll as (d, loc)) =
|
adamc@26
|
549 case d of
|
adamc@808
|
550 DDatatype dts =>
|
adamc@808
|
551 S.map2 (ListUtil.mapfold (fn (x, n, xncs) =>
|
adamc@808
|
552 S.map2 (ListUtil.mapfold (fn (x, n, c) =>
|
adamc@808
|
553 case c of
|
adamc@808
|
554 NONE => S.return2 (x, n, c)
|
adamc@808
|
555 | SOME c =>
|
adamc@808
|
556 S.map2 (mft c,
|
adamc@808
|
557 fn c' => (x, n, SOME c'))) xncs,
|
adamc@808
|
558 fn xncs' => (x, n, xncs'))) dts,
|
adamc@808
|
559 fn dts' =>
|
adamc@808
|
560 (DDatatype dts', loc))
|
adamc@164
|
561 | DVal vi =>
|
adamc@126
|
562 S.map2 (mfvi ctx vi,
|
adamc@126
|
563 fn vi' =>
|
adamc@126
|
564 (DVal vi', loc))
|
adamc@126
|
565 | DValRec vis =>
|
adamc@196
|
566 let
|
adamc@196
|
567 val ctx' = foldl (fn ((x, n, t, _, s), ctx') => bind (ctx', NamedE (x, n, t, NONE, s))) ctx vis
|
adamc@196
|
568 in
|
adamc@196
|
569 S.map2 (ListUtil.mapfold (mfvi ctx') vis,
|
adamc@196
|
570 fn vis' =>
|
adamc@196
|
571 (DValRec vis', loc))
|
adamc@196
|
572 end
|
adamc@1104
|
573 | DExport (ek, s, n, ts, t, b) =>
|
adamc@609
|
574 S.bind2 (ListUtil.mapfold mft ts,
|
adamc@120
|
575 fn ts' =>
|
adamc@609
|
576 S.map2 (mft t,
|
adamc@609
|
577 fn t' =>
|
adamc@1104
|
578 (DExport (ek, s, n, ts', t', b), loc)))
|
adamc@707
|
579 | DTable (s, xts, pe, ce) =>
|
adamc@707
|
580 S.bind2 (mfe ctx pe,
|
adamc@707
|
581 fn pe' =>
|
adamc@707
|
582 S.map2 (mfe ctx ce,
|
adamc@707
|
583 fn ce' =>
|
adamc@707
|
584 (DTable (s, xts, pe', ce'), loc)))
|
adamc@338
|
585 | DSequence _ => S.return2 dAll
|
adamc@754
|
586 | DView (s, xts, e) =>
|
adamc@754
|
587 S.map2 (mfe ctx e,
|
adamc@754
|
588 fn e' =>
|
adamc@754
|
589 (DView (s, xts, e'), loc))
|
adamc@271
|
590 | DDatabase _ => S.return2 dAll
|
adamc@569
|
591 | DJavaScript _ => S.return2 dAll
|
adamc@725
|
592 | DCookie _ => S.return2 dAll
|
adamc@718
|
593 | DStyle _ => S.return2 dAll
|
adamc@1075
|
594 | DTask (e1, e2) =>
|
adamc@1075
|
595 S.bind2 (mfe ctx e1,
|
adamc@1075
|
596 fn e1' =>
|
adamc@1075
|
597 S.map2 (mfe ctx e2,
|
adamc@1075
|
598 fn e2' =>
|
adamc@1075
|
599 (DTask (e1', e2'), loc)))
|
adamc@1199
|
600 | DPolicy pol =>
|
adamc@1199
|
601 S.map2 (mfpol ctx pol,
|
adamc@1199
|
602 fn p' =>
|
adamc@1199
|
603 (DPolicy p', loc))
|
adam@1294
|
604 | DOnError _ => S.return2 dAll
|
adamc@1199
|
605
|
adamc@1199
|
606 and mfpol ctx pol =
|
adamc@1199
|
607 case pol of
|
adamc@1214
|
608 PolClient e =>
|
adamc@1199
|
609 S.map2 (mfe ctx e,
|
adamc@1214
|
610 PolClient)
|
adamc@1220
|
611 | PolInsert e =>
|
adamc@1220
|
612 S.map2 (mfe ctx e,
|
adamc@1220
|
613 PolInsert)
|
adamc@1221
|
614 | PolDelete e =>
|
adamc@1221
|
615 S.map2 (mfe ctx e,
|
adamc@1221
|
616 PolDelete)
|
adamc@1223
|
617 | PolUpdate e =>
|
adamc@1223
|
618 S.map2 (mfe ctx e,
|
adamc@1223
|
619 PolUpdate)
|
adamc@1229
|
620 | PolSequence e =>
|
adamc@1229
|
621 S.map2 (mfe ctx e,
|
adamc@1229
|
622 PolSequence)
|
adamc@126
|
623
|
adamc@126
|
624 and mfvi ctx (x, n, t, e, s) =
|
adamc@126
|
625 S.bind2 (mft t,
|
adamc@126
|
626 fn t' =>
|
adamc@126
|
627 S.map2 (mfe ctx e,
|
adamc@126
|
628 fn e' =>
|
adamc@126
|
629 (x, n, t', e', s)))
|
adamc@26
|
630 in
|
adamc@26
|
631 mfd
|
ziv@2218
|
632 end
|
adamc@26
|
633
|
adamc@26
|
634 fun mapfold {typ = fc, exp = fe, decl = fd} =
|
adamc@26
|
635 mapfoldB {typ = fc,
|
adamc@26
|
636 exp = fn () => fe,
|
adamc@26
|
637 decl = fn () => fd,
|
adamc@26
|
638 bind = fn ((), _) => ()} ()
|
adamc@26
|
639
|
adamc@26
|
640 fun fold {typ, exp, decl} s d =
|
adamc@26
|
641 case mapfold {typ = fn c => fn s => S.Continue (c, typ (c, s)),
|
adamc@26
|
642 exp = fn e => fn s => S.Continue (e, exp (e, s)),
|
adamc@26
|
643 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of
|
adamc@26
|
644 S.Continue (_, s) => s
|
adamc@26
|
645 | S.Return _ => raise Fail "MonoUtil.Decl.fold: Impossible"
|
adamc@26
|
646
|
adamc@506
|
647 fun map {typ, exp, decl} e =
|
adamc@506
|
648 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
|
adamc@506
|
649 exp = fn e => fn () => S.Continue (exp e, ()),
|
adamc@506
|
650 decl = fn d => fn () => S.Continue (decl d, ())} e () of
|
adamc@506
|
651 S.Return () => raise Fail "MonoUtil.Decl.map: Impossible"
|
adamc@506
|
652 | S.Continue (e, ()) => e
|
adamc@506
|
653
|
adam@1800
|
654 fun foldMap {typ, exp, decl} s d =
|
adam@1800
|
655 case mapfold {typ = fn c => fn s => S.Continue (typ (c, s)),
|
adam@1800
|
656 exp = fn e => fn s => S.Continue (exp (e, s)),
|
adam@1800
|
657 decl = fn d => fn s => S.Continue (decl (d, s))} d s of
|
adam@1800
|
658 S.Continue v => v
|
adam@1800
|
659 | S.Return _ => raise Fail "MonoUtil.Decl.foldMap: Impossible"
|
adam@1800
|
660
|
adamc@567
|
661 fun foldMapB {typ, exp, decl, bind} ctx s d =
|
adamc@567
|
662 case mapfoldB {typ = fn c => fn s => S.Continue (typ (c, s)),
|
adamc@567
|
663 exp = fn ctx => fn e => fn s => S.Continue (exp (ctx, e, s)),
|
adamc@567
|
664 decl = fn ctx => fn d => fn s => S.Continue (decl (ctx, d, s)),
|
adamc@567
|
665 bind = bind} ctx d s of
|
adamc@567
|
666 S.Continue v => v
|
adamc@567
|
667 | S.Return _ => raise Fail "MonoUtil.Decl.foldMapB: Impossible"
|
adamc@567
|
668
|
adam@1847
|
669 fun exists {typ, exp, decl} k =
|
adam@1847
|
670 case mapfold {typ = fn c => fn () =>
|
adam@1847
|
671 if typ c then
|
adam@1847
|
672 S.Return ()
|
adam@1847
|
673 else
|
adam@1847
|
674 S.Continue (c, ()),
|
adam@1847
|
675 exp = fn e => fn () =>
|
adam@1847
|
676 if exp e then
|
adam@1847
|
677 S.Return ()
|
adam@1847
|
678 else
|
adam@1847
|
679 S.Continue (e, ()),
|
adam@1847
|
680 decl = fn d => fn () =>
|
adam@1847
|
681 if decl d then
|
adam@1847
|
682 S.Return ()
|
adam@1847
|
683 else
|
adam@1847
|
684 S.Continue (d, ())} k () of
|
adam@1847
|
685 S.Return _ => true
|
adam@1847
|
686 | S.Continue _ => false
|
adam@1847
|
687
|
adamc@26
|
688 end
|
adamc@26
|
689
|
adamc@26
|
690 structure File = struct
|
adamc@26
|
691
|
adamc@26
|
692 datatype binder = datatype Exp.binder
|
adamc@26
|
693
|
adamc@26
|
694 fun mapfoldB (all as {bind, ...}) =
|
adamc@26
|
695 let
|
adamc@26
|
696 val mfd = Decl.mapfoldB all
|
adamc@26
|
697
|
ziv@2251
|
698 fun mff ctx (file : file) =
|
ziv@2251
|
699 case #decls file of
|
ziv@2251
|
700 nil => S.return2 {decls = nil, sideInfo = #sideInfo file}
|
adamc@26
|
701 | d :: ds' =>
|
adamc@26
|
702 S.bind2 (mfd ctx d,
|
adamc@26
|
703 fn d' =>
|
adamc@26
|
704 let
|
adamc@100
|
705 val ctx' =
|
adamc@26
|
706 case #1 d' of
|
adamc@808
|
707 DDatatype dts =>
|
adamc@808
|
708 foldl (fn ((x, n, xncs), ctx) =>
|
adamc@808
|
709 let
|
adamc@808
|
710 val ctx = bind (ctx, Datatype (x, n, xncs))
|
adamc@808
|
711 val t = (TDatatype (n, ref (ElabUtil.classifyDatatype xncs, xncs)),
|
adamc@808
|
712 #2 d')
|
adamc@808
|
713 in
|
adamc@808
|
714 foldl (fn ((x, n, to), ctx) =>
|
adamc@808
|
715 let
|
adamc@808
|
716 val t = case to of
|
adamc@808
|
717 NONE => t
|
adamc@808
|
718 | SOME t' => (TFun (t', t), #2 d')
|
adamc@808
|
719 in
|
adamc@808
|
720 bind (ctx, NamedE (x, n, t, NONE, ""))
|
adamc@808
|
721 end)
|
adamc@808
|
722 ctx xncs
|
adamc@808
|
723 end) ctx dts
|
adamc@164
|
724 | DVal (x, n, t, e, s) => bind (ctx, NamedE (x, n, t, SOME e, s))
|
adamc@126
|
725 | DValRec vis => foldl (fn ((x, n, t, e, s), ctx) =>
|
adamc@196
|
726 bind (ctx, NamedE (x, n, t, NONE, s))) ctx vis
|
adamc@109
|
727 | DExport _ => ctx
|
adamc@273
|
728 | DTable _ => ctx
|
adamc@338
|
729 | DSequence _ => ctx
|
adamc@754
|
730 | DView _ => ctx
|
adamc@271
|
731 | DDatabase _ => ctx
|
adamc@569
|
732 | DJavaScript _ => ctx
|
adamc@725
|
733 | DCookie _ => ctx
|
adamc@718
|
734 | DStyle _ => ctx
|
adamc@1075
|
735 | DTask _ => ctx
|
adamc@1199
|
736 | DPolicy _ => ctx
|
adam@1294
|
737 | DOnError _ => ctx
|
adamc@26
|
738 in
|
ziv@2251
|
739 S.map2 (mff ctx' {decls = ds', sideInfo = #sideInfo file},
|
ziv@2251
|
740 fn {decls = ds', ...} =>
|
ziv@2251
|
741 {decls = d' :: ds', sideInfo = #sideInfo file})
|
adamc@26
|
742 end)
|
adamc@26
|
743 in
|
adamc@26
|
744 mff
|
adamc@26
|
745 end
|
adamc@26
|
746
|
adamc@26
|
747 fun mapfold {typ = fc, exp = fe, decl = fd} =
|
adamc@26
|
748 mapfoldB {typ = fc,
|
adamc@26
|
749 exp = fn () => fe,
|
adamc@26
|
750 decl = fn () => fd,
|
adamc@26
|
751 bind = fn ((), _) => ()} ()
|
adamc@26
|
752
|
adamc@26
|
753 fun mapB {typ, exp, decl, bind} ctx ds =
|
adamc@26
|
754 case mapfoldB {typ = fn c => fn () => S.Continue (typ c, ()),
|
adamc@26
|
755 exp = fn ctx => fn e => fn () => S.Continue (exp ctx e, ()),
|
adamc@26
|
756 decl = fn ctx => fn d => fn () => S.Continue (decl ctx d, ()),
|
adamc@26
|
757 bind = bind} ctx ds () of
|
adamc@26
|
758 S.Continue (ds, ()) => ds
|
adamc@26
|
759 | S.Return _ => raise Fail "MonoUtil.File.mapB: Impossible"
|
adamc@26
|
760
|
adamc@96
|
761 fun map {typ, exp, decl} e =
|
adamc@96
|
762 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
|
adamc@96
|
763 exp = fn e => fn () => S.Continue (exp e, ()),
|
adamc@96
|
764 decl = fn d => fn () => S.Continue (decl d, ())} e () of
|
adamc@506
|
765 S.Return () => raise Fail "MonoUtil.File.map: Impossible"
|
adamc@96
|
766 | S.Continue (e, ()) => e
|
adamc@96
|
767
|
adamc@26
|
768 fun fold {typ, exp, decl} s d =
|
adamc@26
|
769 case mapfold {typ = fn c => fn s => S.Continue (c, typ (c, s)),
|
adamc@26
|
770 exp = fn e => fn s => S.Continue (e, exp (e, s)),
|
adamc@26
|
771 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of
|
adamc@26
|
772 S.Continue (_, s) => s
|
adamc@26
|
773 | S.Return _ => raise Fail "MonoUtil.File.fold: Impossible"
|
adamc@26
|
774
|
adam@1845
|
775 fun maxName (f : file) =
|
adam@1845
|
776 foldl (fn ((d, _) : decl, count) =>
|
adam@1845
|
777 case d of
|
adam@1845
|
778 DDatatype dts =>
|
adam@1845
|
779 foldl (fn ((_, n, ns), count) =>
|
adam@1845
|
780 foldl (fn ((_, n', _), m) => Int.max (n', m))
|
adam@1845
|
781 (Int.max (n, count)) ns) count dts
|
adam@1845
|
782 | DVal (_, n, _, _, _) => Int.max (n, count)
|
adam@1845
|
783 | DValRec vis => foldl (fn ((_, n, _, _, _), count) => Int.max (n, count)) count vis
|
adam@1845
|
784 | DExport _ => count
|
adam@1845
|
785 | DTable _ => count
|
adam@1845
|
786 | DSequence _ => count
|
adam@1845
|
787 | DView _ => count
|
adam@1845
|
788 | DDatabase _ => count
|
adam@1845
|
789 | DJavaScript _ => count
|
adam@1845
|
790 | DCookie _ => count
|
adam@1845
|
791 | DStyle _ => count
|
adam@1845
|
792 | DTask _ => count
|
adam@1845
|
793 | DPolicy _ => count
|
ziv@2251
|
794 | DOnError _ => count) 0 (#decls f)
|
adamc@506
|
795
|
adam@1845
|
796 fun appLoc f (fl : file) =
|
adam@1612
|
797 let
|
adam@1612
|
798 val eal = Exp.appLoc f
|
adam@1612
|
799
|
adam@1612
|
800 fun appl (d : decl) =
|
adam@1612
|
801 case #1 d of
|
adam@1612
|
802 DDatatype _ => ()
|
adam@1612
|
803 | DVal (_, _, _, e1, _) => eal e1
|
adam@1612
|
804 | DValRec vis => app (eal o #4) vis
|
adam@1612
|
805 | DExport _ => ()
|
adam@1612
|
806 | DTable (_, _, e1, e2) => (eal e1; eal e2)
|
adam@1612
|
807 | DSequence _ => ()
|
adam@1612
|
808 | DView (_, _, e1) => eal e1
|
adam@1612
|
809 | DDatabase _ => ()
|
adam@1612
|
810 | DJavaScript _ => ()
|
adam@1612
|
811 | DCookie _ => ()
|
adam@1612
|
812 | DStyle _ => ()
|
adam@1612
|
813 | DTask (e1, e2) => (eal e1; eal e2)
|
adam@1612
|
814 | DPolicy pol => applPolicy pol
|
adam@1612
|
815 | DOnError _ => ()
|
adam@1612
|
816
|
adam@1612
|
817 and applPolicy p =
|
adam@1612
|
818 case p of
|
adam@1612
|
819 PolClient e1 => eal e1
|
adam@1612
|
820 | PolInsert e1 => eal e1
|
adam@1612
|
821 | PolDelete e1 => eal e1
|
adam@1612
|
822 | PolUpdate e1 => eal e1
|
adam@1612
|
823 | PolSequence e1 => eal e1
|
adam@1612
|
824 in
|
ziv@2251
|
825 app appl (#decls fl)
|
adam@1612
|
826 end
|
adam@1612
|
827
|
adamc@26
|
828 end
|
adamc@26
|
829
|
adamc@26
|
830 end
|