adamc@448
|
1 (* Copyright (c) 2008, Adam Chlipala
|
adamc@448
|
2 * All rights reserved.
|
adamc@448
|
3 *
|
adamc@448
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@448
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@448
|
6 *
|
adamc@448
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@448
|
8 * this list of conditions and the following disclaimer.
|
adamc@448
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@448
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@448
|
11 * and/or other materials provided with the distribution.
|
adamc@448
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@448
|
13 * derived from this software without specific prior written permission.
|
adamc@448
|
14 *
|
adamc@448
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@448
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@448
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@448
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@448
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@448
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@448
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@448
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@448
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@448
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@448
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@448
|
26 *)
|
adamc@448
|
27
|
adamc@448
|
28 (* Remove nested function definitions *)
|
adamc@448
|
29
|
adamc@448
|
30 structure Unnest :> UNNEST = struct
|
adamc@448
|
31
|
adamc@448
|
32 open Elab
|
adamc@448
|
33
|
adamc@448
|
34 structure E = ElabEnv
|
adamc@448
|
35 structure U = ElabUtil
|
adamc@448
|
36
|
adamc@448
|
37 structure IS = IntBinarySet
|
adamc@448
|
38
|
adamc@487
|
39 fun liftExpInExp by =
|
adamc@623
|
40 U.Exp.mapB {kind = fn _ => fn k => k,
|
adamc@487
|
41 con = fn _ => fn c => c,
|
adamc@487
|
42 exp = fn bound => fn e =>
|
adamc@487
|
43 case e of
|
adamc@487
|
44 ERel xn =>
|
adamc@487
|
45 if xn < bound then
|
adamc@487
|
46 e
|
adamc@487
|
47 else
|
adamc@487
|
48 ERel (xn + by)
|
adamc@487
|
49 | _ => e,
|
adamc@487
|
50 bind = fn (bound, U.Exp.RelE _) => bound + 1
|
adamc@487
|
51 | (bound, _) => bound}
|
adamc@487
|
52
|
adamc@487
|
53 val subExpInExp =
|
adamc@623
|
54 U.Exp.mapB {kind = fn _ => fn k => k,
|
adamc@487
|
55 con = fn _ => fn c => c,
|
adamc@487
|
56 exp = fn (xn, rep) => fn e =>
|
adamc@487
|
57 case e of
|
adamc@487
|
58 ERel xn' =>
|
adamc@487
|
59 if xn' = xn then
|
adamc@487
|
60 #1 rep
|
adamc@487
|
61 else
|
adamc@487
|
62 e
|
adamc@487
|
63 | _ => e,
|
adamc@487
|
64 bind = fn ((xn, rep), U.Exp.RelE _) => (xn+1, E.liftExpInExp 0 rep)
|
adamc@487
|
65 | ((xn, rep), U.Exp.RelC _) => (xn, E.liftConInExp 0 rep)
|
adamc@487
|
66 | (ctx, _) => ctx}
|
adamc@487
|
67
|
adamc@623
|
68 val fvsCon = U.Con.foldB {kind = fn (_, _, st) => st,
|
adamc@448
|
69 con = fn (cb, c, cvs) =>
|
adamc@448
|
70 case c of
|
adamc@448
|
71 CRel n =>
|
adamc@448
|
72 if n >= cb then
|
adamc@448
|
73 IS.add (cvs, n - cb)
|
adamc@448
|
74 else
|
adamc@448
|
75 cvs
|
adamc@448
|
76 | _ => cvs,
|
adamc@448
|
77 bind = fn (cb, b) =>
|
adamc@448
|
78 case b of
|
adamc@623
|
79 U.Con.RelC _ => cb + 1
|
adamc@448
|
80 | _ => cb}
|
adamc@448
|
81 0 IS.empty
|
adamc@448
|
82
|
adamc@623
|
83 fun fvsExp nr = U.Exp.foldB {kind = fn (_, _, st) => st,
|
adamc@448
|
84 con = fn ((cb, eb), c, st as (cvs, evs)) =>
|
adamc@448
|
85 case c of
|
adamc@448
|
86 CRel n =>
|
adamc@448
|
87 if n >= cb then
|
adamc@448
|
88 (IS.add (cvs, n - cb), evs)
|
adamc@448
|
89 else
|
adamc@448
|
90 st
|
adamc@448
|
91 | _ => st,
|
adamc@448
|
92 exp = fn ((cb, eb), e, st as (cvs, evs)) =>
|
adamc@448
|
93 case e of
|
adamc@448
|
94 ERel n =>
|
adamc@448
|
95 if n >= eb then
|
adamc@448
|
96 (cvs, IS.add (evs, n - eb))
|
adamc@448
|
97 else
|
adamc@448
|
98 st
|
adamc@448
|
99 | _ => st,
|
adamc@448
|
100 bind = fn (ctx as (cb, eb), b) =>
|
adamc@448
|
101 case b of
|
adamc@448
|
102 U.Exp.RelC _ => (cb + 1, eb)
|
adamc@448
|
103 | U.Exp.RelE _ => (cb, eb + 1)
|
adamc@448
|
104 | _ => ctx}
|
adamc@448
|
105 (0, nr) (IS.empty, IS.empty)
|
adamc@448
|
106
|
adamc@448
|
107 fun positionOf (x : int) ls =
|
adamc@448
|
108 let
|
adamc@448
|
109 fun po n ls =
|
adamc@448
|
110 case ls of
|
adamc@448
|
111 [] => raise Fail "Unnest.positionOf"
|
adamc@448
|
112 | x' :: ls' =>
|
adamc@448
|
113 if x' = x then
|
adamc@448
|
114 n
|
adamc@448
|
115 else
|
adamc@448
|
116 po (n + 1) ls'
|
adamc@448
|
117 in
|
adamc@448
|
118 po 0 ls
|
adamc@487
|
119 handle Fail _ => raise Fail ("Unnest.positionOf("
|
adamc@448
|
120 ^ Int.toString x
|
adamc@448
|
121 ^ ", "
|
adamc@448
|
122 ^ String.concatWith ";" (map Int.toString ls)
|
adamc@448
|
123 ^ ")")
|
adamc@448
|
124 end
|
adamc@448
|
125
|
adamc@448
|
126 fun squishCon cfv =
|
adamc@623
|
127 U.Con.mapB {kind = fn _ => fn k => k,
|
adamc@448
|
128 con = fn cb => fn c =>
|
adamc@448
|
129 case c of
|
adamc@448
|
130 CRel n =>
|
adamc@448
|
131 if n >= cb then
|
adamc@448
|
132 CRel (positionOf (n - cb) cfv + cb)
|
adamc@448
|
133 else
|
adamc@448
|
134 c
|
adamc@448
|
135 | _ => c,
|
adamc@448
|
136 bind = fn (cb, b) =>
|
adamc@448
|
137 case b of
|
adamc@623
|
138 U.Con.RelC _ => cb + 1
|
adamc@448
|
139 | _ => cb}
|
adamc@448
|
140 0
|
adamc@448
|
141
|
adamc@448
|
142 fun squishExp (nr, cfv, efv) =
|
adamc@623
|
143 U.Exp.mapB {kind = fn _ => fn k => k,
|
adamc@448
|
144 con = fn (cb, eb) => fn c =>
|
adamc@448
|
145 case c of
|
adamc@448
|
146 CRel n =>
|
adamc@448
|
147 if n >= cb then
|
adamc@448
|
148 CRel (positionOf (n - cb) cfv + cb)
|
adamc@448
|
149 else
|
adamc@448
|
150 c
|
adamc@448
|
151 | _ => c,
|
adamc@448
|
152 exp = fn (cb, eb) => fn e =>
|
adamc@448
|
153 case e of
|
adamc@448
|
154 ERel n =>
|
adamc@448
|
155 if n >= eb then
|
adamc@487
|
156 ERel (positionOf (n - eb) efv + eb - nr)
|
adamc@448
|
157 else
|
adamc@448
|
158 e
|
adamc@448
|
159 | _ => e,
|
adamc@448
|
160 bind = fn (ctx as (cb, eb), b) =>
|
adamc@448
|
161 case b of
|
adamc@448
|
162 U.Exp.RelC _ => (cb + 1, eb)
|
adamc@448
|
163 | U.Exp.RelE _ => (cb, eb + 1)
|
adamc@448
|
164 | _ => ctx}
|
adamc@448
|
165 (0, nr)
|
adamc@448
|
166
|
adamc@448
|
167 type state = {
|
adamc@448
|
168 maxName : int,
|
adamc@455
|
169 decls : (string * int * con * exp) list
|
adamc@448
|
170 }
|
adamc@448
|
171
|
adamc@623
|
172 fun kind (_, k, st) = (k, st)
|
adamc@448
|
173
|
adamc@453
|
174 fun exp ((ks, ts), e as old, st : state) =
|
adamc@448
|
175 case e of
|
adamc@825
|
176 ELet (eds, e, t) =>
|
adamc@448
|
177 let
|
adamc@487
|
178 (*val () = Print.prefaces "Letto" [("e", ElabPrint.p_exp E.empty (old, ErrorMsg.dummySpan))]*)
|
adamc@453
|
179
|
adamc@487
|
180 fun doSubst' (e, subs) = foldl (fn (p, e) => subExpInExp p e) e subs
|
adamc@448
|
181
|
adamc@487
|
182 fun doSubst (e, subs, by) =
|
adamc@487
|
183 let
|
adamc@487
|
184 val e = doSubst' (e, subs)
|
adamc@487
|
185 in
|
adamc@487
|
186 liftExpInExp (~by) (length subs) e
|
adamc@487
|
187 end
|
adamc@487
|
188
|
adamc@487
|
189 val (eds, (ts, maxName, ds, subs, by)) =
|
adamc@448
|
190 ListUtil.foldlMapConcat
|
adamc@487
|
191 (fn (ed, (ts, maxName, ds, subs, by)) =>
|
adamc@448
|
192 case #1 ed of
|
adamc@825
|
193 EDVal (p, t, e) =>
|
adamc@487
|
194 let
|
adamc@487
|
195 val e = doSubst (e, subs, by)
|
adamc@825
|
196
|
adamc@825
|
197 fun doVars ((p, _), ts) =
|
adamc@825
|
198 case p of
|
adamc@825
|
199 PWild => ts
|
adamc@825
|
200 | PVar xt => xt :: ts
|
adamc@825
|
201 | PPrim _ => ts
|
adamc@825
|
202 | PCon (_, _, _, NONE) => ts
|
adamc@825
|
203 | PCon (_, _, _, SOME p) => doVars (p, ts)
|
adamc@825
|
204 | PRecord xpcs =>
|
adamc@825
|
205 foldl (fn ((_, p, _), ts) => doVars (p, ts))
|
adamc@825
|
206 ts xpcs
|
adamc@487
|
207 in
|
adamc@825
|
208 ([(EDVal (p, t, e), #2 ed)],
|
adamc@825
|
209 (doVars (p, ts),
|
adamc@487
|
210 maxName, ds,
|
adamc@487
|
211 ((0, (ERel 0, #2 ed))
|
adamc@487
|
212 :: map (fn (n, e) => (n + 1, E.liftExpInExp 0 e)) subs),
|
adamc@487
|
213 by))
|
adamc@487
|
214 end
|
adamc@448
|
215 | EDValRec vis =>
|
adamc@448
|
216 let
|
adamc@448
|
217 val loc = #2 ed
|
adamc@448
|
218
|
adamc@448
|
219 val nr = length vis
|
adamc@490
|
220 val subsLocal = List.filter (fn (_, (ERel _, _)) => false
|
adamc@490
|
221 | _ => true) subs
|
adamc@490
|
222 val subsLocal = map (fn (n, e) => (n + nr, liftExpInExp nr 0 e))
|
adamc@490
|
223 subsLocal
|
adamc@490
|
224
|
adamc@490
|
225 val vis = map (fn (x, t, e) =>
|
adamc@490
|
226 (x, t, doSubst' (e, subsLocal))) vis
|
adamc@490
|
227
|
adamc@448
|
228 val (cfv, efv) = foldl (fn ((_, t, e), (cfv, efv)) =>
|
adamc@448
|
229 let
|
adamc@448
|
230 val (cfv', efv') = fvsExp nr e
|
adamc@448
|
231 (*val () = Print.prefaces "fvsExp"
|
adamc@448
|
232 [("e", ElabPrint.p_exp E.empty e),
|
adamc@448
|
233 ("cfv", Print.PD.string
|
adamc@448
|
234 (Int.toString (IS.numItems cfv'))),
|
adamc@448
|
235 ("efv", Print.PD.string
|
adamc@448
|
236 (Int.toString (IS.numItems efv')))]*)
|
adamc@448
|
237 val cfv'' = fvsCon t
|
adamc@448
|
238 in
|
adamc@448
|
239 (IS.union (cfv, IS.union (cfv', cfv'')),
|
adamc@448
|
240 IS.union (efv, efv'))
|
adamc@448
|
241 end)
|
adamc@448
|
242 (IS.empty, IS.empty) vis
|
adamc@448
|
243
|
adamc@453
|
244 (*val () = print ("A: " ^ Int.toString (length ts) ^ ", " ^ Int.toString (length ks) ^ "\n")
|
adamc@453
|
245 val () = app (fn (x, t) =>
|
adamc@453
|
246 Print.prefaces "Var" [("x", Print.PD.string x),
|
adamc@453
|
247 ("t", ElabPrint.p_con E.empty t)]) ts*)
|
adamc@487
|
248
|
adamc@448
|
249 val cfv = IS.foldl (fn (x, cfv) =>
|
adamc@448
|
250 let
|
adamc@448
|
251 (*val () = print (Int.toString x ^ "\n")*)
|
adamc@448
|
252 val (_, t) = List.nth (ts, x)
|
adamc@448
|
253 in
|
adamc@448
|
254 IS.union (cfv, fvsCon t)
|
adamc@448
|
255 end)
|
adamc@448
|
256 cfv efv
|
adamc@448
|
257 (*val () = print "B\n"*)
|
adamc@448
|
258
|
adamc@448
|
259 val (vis, maxName) =
|
adamc@448
|
260 ListUtil.foldlMap (fn ((x, t, e), maxName) =>
|
adamc@448
|
261 ((x, maxName, t, e),
|
adamc@448
|
262 maxName + 1))
|
adamc@448
|
263 maxName vis
|
adamc@448
|
264
|
adamc@487
|
265 val subs = map (fn (n, e) => (n + nr,
|
adamc@487
|
266 case e of
|
adamc@487
|
267 (ERel _, _) => e
|
adamc@487
|
268 | _ => liftExpInExp nr 0 e))
|
adamc@487
|
269 subs
|
adamc@487
|
270
|
adamc@448
|
271 val subs' = ListUtil.mapi (fn (i, (_, n, _, _)) =>
|
adamc@448
|
272 let
|
adamc@487
|
273 val e = (ENamed n, loc)
|
adamc@487
|
274
|
adamc@487
|
275 val e = IS.foldr (fn (x, e) =>
|
adamc@487
|
276 (ECApp (e, (CRel x, loc)), loc))
|
adamc@487
|
277 e cfv
|
adamc@487
|
278
|
adamc@487
|
279 val e = IS.foldr (fn (x, e) =>
|
adamc@487
|
280 (EApp (e, (ERel (nr + x), loc)),
|
adamc@487
|
281 loc))
|
adamc@487
|
282 e efv
|
adamc@448
|
283 in
|
adamc@487
|
284 (nr - i - 1, e)
|
adamc@448
|
285 end)
|
adamc@450
|
286 vis
|
adamc@450
|
287
|
adamc@448
|
288 val cfv = IS.listItems cfv
|
adamc@448
|
289 val efv = IS.listItems efv
|
adamc@448
|
290
|
adamc@487
|
291 val subs = subs' @ subs
|
adamc@448
|
292
|
adamc@448
|
293 val vis = map (fn (x, n, t, e) =>
|
adamc@448
|
294 let
|
adamc@448
|
295 (*val () = Print.prefaces "preSubst"
|
adamc@448
|
296 [("e", ElabPrint.p_exp E.empty e)]*)
|
adamc@490
|
297 val e = doSubst' (e, subs')
|
adamc@448
|
298
|
adamc@448
|
299 (*val () = Print.prefaces "squishCon"
|
adamc@448
|
300 [("t", ElabPrint.p_con E.empty t)]*)
|
adamc@448
|
301 val t = squishCon cfv t
|
adamc@448
|
302 (*val () = Print.prefaces "squishExp"
|
adamc@448
|
303 [("e", ElabPrint.p_exp E.empty e)]*)
|
adamc@487
|
304 val e = squishExp (nr, cfv, efv) e
|
adamc@448
|
305
|
adamc@487
|
306 (*val () = print ("Avail: " ^ Int.toString (length ts) ^ "\n")*)
|
adamc@453
|
307 val (e, t) = foldl (fn (ex, (e, t)) =>
|
adamc@448
|
308 let
|
adamc@487
|
309 (*val () = print (Int.toString ex ^ "\n")*)
|
adamc@448
|
310 val (name, t') = List.nth (ts, ex)
|
adamc@448
|
311 in
|
adamc@448
|
312 ((EAbs (name,
|
adamc@448
|
313 t',
|
adamc@448
|
314 t,
|
adamc@448
|
315 e), loc),
|
adamc@448
|
316 (TFun (t',
|
adamc@448
|
317 t), loc))
|
adamc@448
|
318 end)
|
adamc@448
|
319 (e, t) efv
|
adamc@487
|
320 (*val () = print "Done\n"*)
|
adamc@448
|
321
|
adamc@453
|
322 val (e, t) = foldl (fn (cx, (e, t)) =>
|
adamc@448
|
323 let
|
adamc@448
|
324 val (name, k) = List.nth (ks, cx)
|
adamc@448
|
325 in
|
adamc@448
|
326 ((ECAbs (Explicit,
|
adamc@448
|
327 name,
|
adamc@448
|
328 k,
|
adamc@448
|
329 e), loc),
|
adamc@448
|
330 (TCFun (Explicit,
|
adamc@448
|
331 name,
|
adamc@448
|
332 k,
|
adamc@448
|
333 t), loc))
|
adamc@448
|
334 end)
|
adamc@448
|
335 (e, t) cfv
|
adamc@448
|
336 in
|
adamc@487
|
337 (*Print.prefaces "Have a vi"
|
adamc@487
|
338 [("x", Print.PD.string x),
|
adamc@487
|
339 ("e", ElabPrint.p_exp ElabEnv.empty e)];*)
|
adamc@448
|
340 (x, n, t, e)
|
adamc@448
|
341 end)
|
adamc@448
|
342 vis
|
adamc@448
|
343
|
adamc@487
|
344 val ts = List.revAppend (map (fn (x, _, t, _) => (x, t)) vis, ts)
|
adamc@448
|
345 in
|
adamc@487
|
346 ([], (ts, maxName, vis @ ds, subs, by + nr))
|
adamc@448
|
347 end)
|
adamc@487
|
348 (ts, #maxName st, #decls st, [], 0) eds
|
adamc@487
|
349
|
adamc@487
|
350 val e' = doSubst (e, subs, by)
|
adamc@448
|
351 in
|
adamc@487
|
352 (*Print.prefaces "Before" [("e", ElabPrint.p_exp ElabEnv.empty e),
|
adamc@487
|
353 ("se", ElabPrint.p_exp ElabEnv.empty (doSubst' (e, subs))),
|
adamc@487
|
354 ("e'", ElabPrint.p_exp ElabEnv.empty e')];*)
|
adamc@825
|
355 (ELet (eds, e', t),
|
adamc@448
|
356 {maxName = maxName,
|
adamc@448
|
357 decls = ds})
|
adamc@487
|
358 (*(ELet (eds, doSubst (liftExpInExp (~(length subs - numRemaining)) (length subs) e) subs),*)
|
adamc@448
|
359 end
|
adamc@448
|
360
|
adamc@448
|
361 | _ => (e, st)
|
adamc@448
|
362
|
adamc@448
|
363 fun default (ctx, d, st) = (d, st)
|
adamc@448
|
364
|
adamc@448
|
365 fun bind ((ks, ts), b) =
|
adamc@448
|
366 case b of
|
adamc@448
|
367 U.Decl.RelC p => (p :: ks, map (fn (name, t) => (name, E.liftConInCon 0 t)) ts)
|
adamc@448
|
368 | U.Decl.RelE p => (ks, p :: ts)
|
adamc@448
|
369 | _ => (ks, ts)
|
adamc@448
|
370
|
adamc@448
|
371 val unnestDecl = U.Decl.foldMapB {kind = kind,
|
adamc@448
|
372 con = default,
|
adamc@448
|
373 exp = exp,
|
adamc@448
|
374 sgn_item = default,
|
adamc@448
|
375 sgn = default,
|
adamc@448
|
376 str = default,
|
adamc@448
|
377 decl = default,
|
adamc@448
|
378 bind = bind}
|
adamc@448
|
379 ([], [])
|
adamc@448
|
380
|
adamc@448
|
381 fun unnest file =
|
adamc@448
|
382 let
|
adamc@448
|
383 fun doDecl (all as (d, loc), st : state) =
|
adamc@448
|
384 let
|
adamc@448
|
385 fun default () = ([all], st)
|
adamc@448
|
386 fun explore () =
|
adamc@448
|
387 let
|
adamc@448
|
388 val (d, st) = unnestDecl st all
|
adamc@455
|
389
|
adamc@455
|
390 val ds =
|
adamc@455
|
391 case #1 d of
|
adamc@455
|
392 DValRec vis => [(DValRec (vis @ #decls st), #2 d)]
|
adamc@455
|
393 | _ => [(DValRec (#decls st), #2 d), d]
|
adamc@448
|
394 in
|
adamc@455
|
395 (ds,
|
adamc@448
|
396 {maxName = #maxName st,
|
adamc@448
|
397 decls = []})
|
adamc@448
|
398 end
|
adamc@448
|
399 in
|
adamc@448
|
400 case d of
|
adamc@448
|
401 DCon _ => default ()
|
adamc@448
|
402 | DDatatype _ => default ()
|
adamc@448
|
403 | DDatatypeImp _ => default ()
|
adamc@448
|
404 | DVal _ => explore ()
|
adamc@448
|
405 | DValRec _ => explore ()
|
adamc@448
|
406 | DSgn _ => default ()
|
adamc@448
|
407 | DStr (x, n, sgn, str) =>
|
adamc@448
|
408 let
|
adamc@448
|
409 val (str, st) = doStr (str, st)
|
adamc@448
|
410 in
|
adamc@448
|
411 ([(DStr (x, n, sgn, str), loc)], st)
|
adamc@448
|
412 end
|
adamc@448
|
413 | DFfiStr _ => default ()
|
adamc@448
|
414 | DConstraint _ => default ()
|
adamc@448
|
415 | DExport _ => default ()
|
adamc@448
|
416 | DTable _ => default ()
|
adamc@448
|
417 | DSequence _ => default ()
|
adamc@754
|
418 | DView _ => default ()
|
adamc@448
|
419 | DClass _ => default ()
|
adamc@448
|
420 | DDatabase _ => default ()
|
adamc@459
|
421 | DCookie _ => default ()
|
adamc@718
|
422 | DStyle _ => default ()
|
adamc@448
|
423 end
|
adamc@448
|
424
|
adamc@448
|
425 and doStr (all as (str, loc), st) =
|
adamc@448
|
426 let
|
adamc@448
|
427 fun default () = (all, st)
|
adamc@448
|
428 in
|
adamc@448
|
429 case str of
|
adamc@448
|
430 StrConst ds =>
|
adamc@448
|
431 let
|
adamc@448
|
432 val (ds, st) = ListUtil.foldlMapConcat doDecl st ds
|
adamc@448
|
433 in
|
adamc@448
|
434 ((StrConst ds, loc), st)
|
adamc@448
|
435 end
|
adamc@448
|
436 | StrVar _ => default ()
|
adamc@448
|
437 | StrProj _ => default ()
|
adamc@448
|
438 | StrFun (x, n, dom, ran, str) =>
|
adamc@448
|
439 let
|
adamc@448
|
440 val (str, st) = doStr (str, st)
|
adamc@448
|
441 in
|
adamc@448
|
442 ((StrFun (x, n, dom, ran, str), loc), st)
|
adamc@448
|
443 end
|
adamc@448
|
444 | StrApp _ => default ()
|
adamc@448
|
445 | StrError => raise Fail "Unnest: StrError"
|
adamc@448
|
446 end
|
adamc@448
|
447
|
adamc@448
|
448 val (ds, _) = ListUtil.foldlMapConcat doDecl
|
adamc@448
|
449 {maxName = U.File.maxName file + 1,
|
adamc@448
|
450 decls = []} file
|
adamc@448
|
451 in
|
adamc@448
|
452 ds
|
adamc@448
|
453 end
|
adamc@448
|
454
|
adamc@448
|
455 end
|