Mercurial > urweb
comparison src/iflow.sml @ 1229:a2cd6664f57f
sendOwnIds policies
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 11 Apr 2010 17:55:37 -0400 |
parents | 7dfa67560916 |
children | 8768145eed1e |
comparison
equal
deleted
inserted
replaced
1228:7dfa67560916 | 1229:a2cd6664f57f |
---|---|
480 | 480 |
481 type database = {Vars : representative IM.map ref, | 481 type database = {Vars : representative IM.map ref, |
482 Consts : representative CM.map ref, | 482 Consts : representative CM.map ref, |
483 Con0s : representative SM.map ref, | 483 Con0s : representative SM.map ref, |
484 Records : (representative SM.map * representative) list ref, | 484 Records : (representative SM.map * representative) list ref, |
485 Funcs : ((string * representative list) * representative) list ref } | 485 Funcs : ((string * representative list) * representative) list ref} |
486 | 486 |
487 fun database () = {Vars = ref IM.empty, | 487 fun database () = {Vars = ref IM.empty, |
488 Consts = ref CM.empty, | 488 Consts = ref CM.empty, |
489 Con0s = ref SM.empty, | 489 Con0s = ref SM.empty, |
490 Records = ref [], | 490 Records = ref [], |
845 if !(#Known (unNode r2)) then | 845 if !(#Known (unNode r2)) then |
846 markKnown r1 | 846 markKnown r1 |
847 else | 847 else |
848 (); | 848 (); |
849 #Cons (unNode r2) := SM.unionWith #1 (!(#Cons (unNode r2)), !(#Cons (unNode r1))); | 849 #Cons (unNode r2) := SM.unionWith #1 (!(#Cons (unNode r2)), !(#Cons (unNode r1))); |
850 | |
850 compactFuncs ()) | 851 compactFuncs ()) |
851 | 852 |
852 and compactFuncs () = | 853 and compactFuncs () = |
853 let | 854 let |
854 fun loop funcs = | 855 fun loop funcs = |
1448 let | 1449 let |
1449 fun expIn (e, rvN) = | 1450 fun expIn (e, rvN) = |
1450 let | 1451 let |
1451 fun default () = | 1452 fun default () = |
1452 let | 1453 let |
1453 val (rvN, e) = rv rvN | 1454 val (rvN, e') = rv rvN |
1454 in | 1455 in |
1455 (inl e, rvN) | 1456 (inl e', rvN) |
1456 end | 1457 end |
1457 in | 1458 in |
1458 case e of | 1459 case e of |
1459 SqConst p => (inl (Const p), rvN) | 1460 SqConst p => (inl (Const p), rvN) |
1460 | Field (v, f) => (inl (Proj (rvOf v, f)), rvN) | 1461 | Field (v, f) => (inl (Proj (rvOf v, f)), rvN) |
1684 val p = | 1685 val p = |
1685 foldl (fn ((t, v), p) => | 1686 foldl (fn ((t, v), p) => |
1686 let | 1687 let |
1687 val t = | 1688 val t = |
1688 case v of | 1689 case v of |
1689 "New" => "$New" | 1690 "New" => t ^ "$New" |
1690 | _ => t | 1691 | _ => t |
1691 in | 1692 in |
1692 And (p, Reln (Sql t, [rvOf v])) | 1693 And (p, Reln (Sql t, [rvOf v])) |
1693 end) True (#From r) | 1694 end) True (#From r) |
1694 | 1695 |
1765 val p = | 1766 val p = |
1766 foldl (fn ((t, v), p) => | 1767 foldl (fn ((t, v), p) => |
1767 let | 1768 let |
1768 val t = | 1769 val t = |
1769 case v of | 1770 case v of |
1770 "New" => "$New" | 1771 "New" => t ^ "$New" |
1771 | _ => t | 1772 | _ => t |
1772 in | 1773 in |
1773 And (p, Reln (Sql t, [rvOf v])) | 1774 And (p, Reln (Sql t, [rvOf v])) |
1774 end) True (#From r) | 1775 end) True (#From r) |
1775 | 1776 |
1987 let | 1988 let |
1988 fun default () = | 1989 fun default () = |
1989 let | 1990 let |
1990 val (st, nv) = St.nextVar st | 1991 val (st, nv) = St.nextVar st |
1991 in | 1992 in |
1993 (*Print.prefaces "default" [("e", MonoPrint.p_exp MonoEnv.empty e), | |
1994 ("nv", p_exp (Var nv))];*) | |
1992 (Var nv, st) | 1995 (Var nv, st) |
1993 end | 1996 end |
1994 | 1997 |
1995 fun addSent (p, e, st) = | 1998 fun addSent (p, e, st) = |
1996 let | 1999 let |
2231 ((x, e), st) | 2234 ((x, e), st) |
2232 end) | 2235 end) |
2233 st es | 2236 st es |
2234 in | 2237 in |
2235 (Recd [], St.addInsert (st, (loc, And (St.ambient st, | 2238 (Recd [], St.addInsert (st, (loc, And (St.ambient st, |
2236 Reln (Sql "$New", [Recd es]))))) | 2239 Reln (Sql (tab ^ "$New"), [Recd es]))))) |
2237 end | 2240 end |
2238 | Delete (tab, e) => | 2241 | Delete (tab, e) => |
2239 let | 2242 let |
2240 val (st, old) = St.nextVar st | 2243 val (st, old) = St.nextVar st |
2241 | 2244 |
2300 val (p, st) = case expIn (e, st) of | 2303 val (p, st) = case expIn (e, st) of |
2301 (inl e, _) => raise Fail "Iflow.evalExp: UPDATE with non-boolean" | 2304 (inl e, _) => raise Fail "Iflow.evalExp: UPDATE with non-boolean" |
2302 | (inr p, st) => (p, st) | 2305 | (inr p, st) => (p, st) |
2303 | 2306 |
2304 val p = And (p, | 2307 val p = And (p, |
2305 And (Reln (Sql "$New", [Recd fs]), | 2308 And (Reln (Sql (tab ^ "$New"), [Recd fs]), |
2306 And (Reln (Sql "$Old", [Var old]), | 2309 And (Reln (Sql "$Old", [Var old]), |
2307 Reln (Sql tab, [Var old])))) | 2310 Reln (Sql tab, [Var old])))) |
2308 in | 2311 in |
2309 (Recd [], St.addUpdate (st, (loc, And (St.ambient st, p)))) | 2312 (Recd [], St.addUpdate (st, (loc, And (St.ambient st, p)))) |
2310 end) | 2313 end) |
2311 | 2314 |
2315 | ENextval (EPrim (Prim.String seq), _) => | |
2316 let | |
2317 val (st, nv) = St.nextVar st | |
2318 in | |
2319 (Var nv, St.setAmbient (st, And (St.ambient st, Reln (Sql (String.extract (seq, 3, NONE)), [Var nv])))) | |
2320 end | |
2312 | ENextval _ => default () | 2321 | ENextval _ => default () |
2313 | ESetval _ => default () | 2322 | ESetval _ => default () |
2314 | 2323 |
2315 | EUnurlify ((EFfiApp ("Basis", "get_cookie", _), _), _, _) => | 2324 | EUnurlify ((EFfiApp ("Basis", "get_cookie", _), _), _, _) => |
2316 let | 2325 let |
2414 let | 2423 let |
2415 val p = updateProp 0 rv e | 2424 val p = updateProp 0 rv e |
2416 in | 2425 in |
2417 (vals, inserts, deletes, updates, client, insert, delete, p :: update) | 2426 (vals, inserts, deletes, updates, client, insert, delete, p :: update) |
2418 end | 2427 end |
2428 | PolSequence e => | |
2429 (case #1 e of | |
2430 EPrim (Prim.String seq) => | |
2431 let | |
2432 val p = Reln (Sql (String.extract (seq, 3, NONE)), [Lvar 0]) | |
2433 val outs = [Lvar 0] | |
2434 in | |
2435 (vals, inserts, deletes, updates, (p, outs) :: client, insert, delete, update) | |
2436 end | |
2437 | _ => (vals, inserts, deletes, updates, client, insert, delete, update)) | |
2419 end | 2438 end |
2420 | 2439 |
2421 | _ => (vals, inserts, deletes, updates, client, insert, delete, update) | 2440 | _ => (vals, inserts, deletes, updates, client, insert, delete, update) |
2422 | 2441 |
2423 val () = reset () | 2442 val () = reset () |
2432 fun doDml (cmds, pols) = | 2451 fun doDml (cmds, pols) = |
2433 app (fn (loc, p) => | 2452 app (fn (loc, p) => |
2434 if decompH p | 2453 if decompH p |
2435 (fn hyps => | 2454 (fn hyps => |
2436 List.exists (fn p' => | 2455 List.exists (fn p' => |
2437 decompG p' | 2456 if decompG p' |
2438 (fn goals => imply (hyps, goals, NONE))) | 2457 (fn goals => imply (hyps, goals, NONE)) then |
2458 ((*reset (); | |
2459 Print.prefaces "Match" [("hyp", p_prop p), | |
2460 ("goal", p_prop p')];*) | |
2461 true) | |
2462 else | |
2463 false) | |
2439 pols) then | 2464 pols) then |
2440 () | 2465 () |
2441 else | 2466 else |
2442 (ErrorMsg.errorAt loc "The information flow policy may be violated here."; | 2467 (ErrorMsg.errorAt loc "The information flow policy may be violated here."; |
2443 Print.preface ("The state satisifies this predicate:", p_prop p))) cmds | 2468 Print.preface ("The state satisifies this predicate:", p_prop p))) cmds |
2485 decompG p' | 2510 decompG p' |
2486 (fn goals => imply (hyps, goals, SOME outs))) | 2511 (fn goals => imply (hyps, goals, SOME outs))) |
2487 client | 2512 client |
2488 orelse tryCombos (0, client, True, []) | 2513 orelse tryCombos (0, client, True, []) |
2489 orelse (reset (); | 2514 orelse (reset (); |
2490 Print.preface ("Untenable hypotheses", | 2515 Print.preface ("Untenable hypotheses" |
2516 ^ (case fl of | |
2517 Control Where => " (WHERE clause)" | |
2518 | Control Case => " (case discriminee)" | |
2519 | Data => " (returned data value)"), | |
2491 Print.p_list p_atom hyps); | 2520 Print.p_list p_atom hyps); |
2492 false) | 2521 false) |
2493 end) then | 2522 end) then |
2494 () | 2523 () |
2495 else | 2524 else |