Mercurial > urweb
changeset 676:e0c186464612
Make sql_injectable class nicer with inclusion
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 26 Mar 2009 15:26:35 -0400 |
parents | 43430b7190f4 |
children | 81573f62d6c3 |
files | lib/ur/basis.urs src/monoize.sml |
diffstat | 2 files changed, 40 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ur/basis.urs Thu Mar 26 15:13:36 2009 -0400 +++ b/lib/ur/basis.urs Thu Mar 26 15:26:35 2009 -0400 @@ -189,17 +189,17 @@ -> nm :: Name -> sql_exp tabs agg ([nm = t] ++ rest) t +class sql_injectable_prim +val sql_bool : sql_injectable_prim bool +val sql_int : sql_injectable_prim int +val sql_float : sql_injectable_prim float +val sql_string : sql_injectable_prim string +val sql_time : sql_injectable_prim time + class sql_injectable -val sql_bool : sql_injectable bool -val sql_int : sql_injectable int -val sql_float : sql_injectable float -val sql_string : sql_injectable string -val sql_time : sql_injectable time -val sql_option_bool : sql_injectable (option bool) -val sql_option_int : sql_injectable (option int) -val sql_option_float : sql_injectable (option float) -val sql_option_string : sql_injectable (option string) -val sql_option_time : sql_injectable (option time) +val sql_prim : t ::: Type -> sql_injectable_prim t -> sql_injectable t +val sql_option_prim : t ::: Type -> sql_injectable_prim t -> sql_injectable (option t) + val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type -> sql_injectable t -> t -> sql_exp tables agg exps t
--- a/src/monoize.sml Thu Mar 26 15:13:36 2009 -0400 +++ b/src/monoize.sml Thu Mar 26 15:26:35 2009 -0400 @@ -163,6 +163,8 @@ | L.CFfi ("Basis", "sql_offset") => (L'.TFfi ("Basis", "string"), loc) + | L.CApp ((L.CFfi ("Basis", "sql_injectable_prim"), _), t) => + (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc) | L.CApp ((L.CFfi ("Basis", "sql_injectable"), _), t) => (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc) | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) => @@ -1423,26 +1425,34 @@ ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc), (L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc), fm) - | L.EFfi ("Basis", "sql_option_int") => - ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "int"), loc), loc), (L'.TFfi ("Basis", "string"), loc), - (L'.EFfiApp ("Basis", "sqlifyIntN", [(L'.ERel 0, loc)]), loc)), loc), - fm) - | L.EFfi ("Basis", "sql_option_float") => - ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "float"), loc), loc), (L'.TFfi ("Basis", "string"), loc), - (L'.EFfiApp ("Basis", "sqlifyFloatN", [(L'.ERel 0, loc)]), loc)), loc), - fm) - | L.EFfi ("Basis", "sql_option_bool") => - ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "bool"), loc), loc), (L'.TFfi ("Basis", "string"), loc), - (L'.EFfiApp ("Basis", "sqlifyBoolN", [(L'.ERel 0, loc)]), loc)), loc), - fm) - | L.EFfi ("Basis", "sql_option_string") => - ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "string"), loc), loc), (L'.TFfi ("Basis", "string"), loc), - (L'.EFfiApp ("Basis", "sqlifyStringN", [(L'.ERel 0, loc)]), loc)), loc), - fm) - | L.EFfi ("Basis", "sql_option_time") => - ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "time"), loc), loc), (L'.TFfi ("Basis", "string"), loc), - (L'.EFfiApp ("Basis", "sqlifyTimeN", [(L'.ERel 0, loc)]), loc)), loc), - fm) + | L.ECApp ((L.EFfi ("Basis", "sql_prim"), _), t) => + let + val t = monoType env t + val tf = (L'.TFun (t, (L'.TFfi ("Basis", "string"), loc)), loc) + in + ((L'.EAbs ("f", tf, tf, (L'.ERel 0, loc)), loc), + fm) + end + | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) => + let + val t = monoType env t + val s = (L'.TFfi ("Basis", "string"), loc) + in + ((L'.EAbs ("f", + (L'.TFun (t, s), loc), + (L'.TFun ((L'.TOption t, loc), s), loc), + (L'.EAbs ("x", + (L'.TOption t, loc), + s, + (L'.ECase ((L'.ERel 0, loc), + [((L'.PNone t, loc), + (L'.EPrim (Prim.String "NULL"), loc)), + ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc), + (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))], + {disc = (L'.TOption t, loc), + result = s}), loc)), loc)), loc), + fm) + end | L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) => ((L'.ERecord [], loc), fm)