comparison src/monoize.sml @ 265:b66e692422a4

Monoize COUNT(*)
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 16:20:34 -0400
parents 35ed669a253f
children 7a7efbb3e354
comparison
equal deleted inserted replaced
264:35ed669a253f 265:b66e692422a4
421 let 421 let
422 val e1 = List.last es 422 val e1 = List.last es
423 val es = List.take (es, length es - 1) 423 val es = List.take (es, length es - 1)
424 in 424 in
425 foldr (fn (e, e') => 425 foldr (fn (e, e') =>
426 case e of 426 case (e, e') of
427 (L'.EPrim (Prim.String ""), _) => e' 427 ((L'.EPrim (Prim.String ""), _), _) => e'
428 | (_, (L'.EPrim (Prim.String ""), _)) => e
428 | _ => 429 | _ =>
429 (L'.EStrcat (e, 430 (L'.EStrcat (e,
430 (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc)) 431 (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc))
431 e1 es 432 e1 es
432 end 433 end
619 strcat loc [sc "SELECT ", 620 strcat loc [sc "SELECT ",
620 strcatComma loc (map (fn (x, t) => 621 strcatComma loc (map (fn (x, t) =>
621 strcat loc [ 622 strcat loc [
622 (L'.EField (gf "SelectExps", x), loc), 623 (L'.EField (gf "SelectExps", x), loc),
623 sc (" AS _" ^ x) 624 sc (" AS _" ^ x)
624 ]) sexps), 625 ]) sexps
625 case sexps of 626 @ map (fn (x, xts) =>
626 [] => sc "" 627 strcatComma loc
627 | _ => sc ", ", 628 (map (fn (x', _) =>
628 strcatComma loc (map (fn (x, xts) => 629 sc (x ^ "." ^ x'))
629 strcatComma loc 630 xts)) stables),
630 (map (fn (x', _) =>
631 sc (x ^ "." ^ x'))
632 xts)) stables),
633 sc " FROM ", 631 sc " FROM ",
634 strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc), 632 strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc),
635 sc (" AS " ^ x)]) tables), 633 sc (" AS " ^ x)]) tables),
636 (L'.ECase (gf "Where", 634 (L'.ECase (gf "Where",
637 [((L'.PPrim (Prim.String "TRUE"), loc), 635 [((L'.PPrim (Prim.String "TRUE"), loc),
916 914
917 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm) 915 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm)
918 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm) 916 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
919 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm) 917 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
920 918
919 | L.ECApp (
920 (L.ECApp (
921 (L.ECApp (
922 (L.EFfi ("Basis", "sql_count"), _),
923 _), _),
924 _), _),
925 _) => ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
926 (L'.EPrim (Prim.String "COUNT(*)"), loc)), loc),
927 fm)
928
921 | L.EApp ( 929 | L.EApp (
922 (L.ECApp ( 930 (L.ECApp (
923 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _), 931 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
924 _), _), 932 _), _),
925 se) => 933 se) =>