changeset 725:4c5796512edc

Catching duplicate cookie and style paths
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Apr 2009 12:07:21 -0400
parents 12ec14a6be0b
children 6fc633d990e7
files src/cjr.sml src/cjr_env.sml src/cjr_print.sml src/cjrize.sml src/mono.sml src/mono_env.sml src/mono_print.sml src/mono_shake.sml src/mono_util.sml src/monoize.sml src/pathcheck.sml src/prepare.sml tests/badCookie.ur tests/badCookie.urp
diffstat 14 files changed, 51 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/cjr.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -110,6 +110,7 @@
        | DPreparedStatements of (string * int) list
 
        | DJavaScript of string
+       | DCookie of string
        | DStyle of string
 
 withtype decl = decl' located
--- a/src/cjr_env.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/cjr_env.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -167,6 +167,7 @@
       | DDatabase _ => env
       | DPreparedStatements _ => env
       | DJavaScript _ => env
+      | DCookie _ => env
       | DStyle _ => env
 
 end
--- a/src/cjr_print.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/cjr_print.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -2146,6 +2146,13 @@
       | DJavaScript s => box [string "static char jslib[] = \"",
                               string (String.toString s),
                               string "\";"]
+      | DCookie s => box [string "/*",
+                          space,
+                          string "cookie",
+                          space,
+                          string s,
+                          space,
+                          string "*/"]
       | DStyle s => box [string "/*",
                          space,
                          string "style",
--- a/src/cjrize.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/cjrize.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -556,6 +556,7 @@
         (SOME (L'.DSequence s, loc), NONE, sm)
       | L.DDatabase s => (SOME (L'.DDatabase s, loc), NONE, sm)
       | L.DJavaScript s => (SOME (L'.DJavaScript s, loc), NONE, sm)
+      | L.DCookie args => (SOME (L'.DCookie args, loc), NONE, sm)
       | L.DStyle args => (SOME (L'.DStyle args, loc), NONE, sm)
 
 fun cjrize ds =
--- a/src/mono.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/mono.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -127,6 +127,7 @@
 
        | DJavaScript of string
 
+       | DCookie of string
        | DStyle of string
 
 
--- a/src/mono_env.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/mono_env.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -111,6 +111,7 @@
       | DSequence _ => env
       | DDatabase _ => env
       | DJavaScript _ => env
+      | DCookie _ => env
       | DStyle _ => env
 
 fun patBinds env (p, loc) =
--- a/src/mono_print.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/mono_print.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -440,6 +440,9 @@
                               string s,
                               string ")"]
 
+      | DCookie s => box [string "cookie",
+                          space,
+                          string s]
       | DStyle s => box [string "style",
                          space,
                          string s]
--- a/src/mono_shake.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/mono_shake.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -59,6 +59,7 @@
                                    | ((DSequence _, _), acc) => acc
                                    | ((DDatabase _, _), acc) => acc
                                    | ((DJavaScript _, _), acc) => acc
+                                   | ((DCookie _, _), acc) => acc
                                    | ((DStyle _, _), acc) => acc)
                                  (IM.empty, IM.empty) file
 
@@ -117,6 +118,7 @@
                       | (DSequence _, _) => true
                       | (DDatabase _, _) => true
                       | (DJavaScript _, _) => true
+                      | (DCookie _, _) => true
                       | (DStyle _, _) => true) file
     end
 
--- a/src/mono_util.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/mono_util.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -474,6 +474,7 @@
               | DSequence _ => S.return2 dAll
               | DDatabase _ => S.return2 dAll
               | DJavaScript _ => S.return2 dAll
+              | DCookie _ => S.return2 dAll
               | DStyle _ => S.return2 dAll
 
         and mfvi ctx (x, n, t, e, s) =
@@ -556,6 +557,7 @@
                                       | DSequence _ => ctx
                                       | DDatabase _ => ctx
                                       | DJavaScript _ => ctx
+                                      | DCookie _ => ctx
                                       | DStyle _ => ctx
                             in
                                 S.map2 (mff ctx' ds',
@@ -606,6 +608,7 @@
                           | DSequence _ => count
                           | DDatabase _ => count
                           | DJavaScript _ => count
+                          | DCookie _ => count
                           | DStyle _ => count) 0
 
 end
--- a/src/monoize.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/monoize.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -2725,7 +2725,8 @@
             in
                 SOME (Env.pushENamed env x n t NONE s,
                       fm,
-                      [(L'.DVal (x, n, t', e, s), loc)])
+                      [(L'.DCookie s, loc),
+                       (L'.DVal (x, n, t', e, s), loc)])
             end
           | L.DStyle (x, n, s) =>
             let
--- a/src/pathcheck.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/pathcheck.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -36,21 +36,35 @@
                            val compare = String.compare
                            end)
 
-fun checkDecl ((d, loc), (funcs, rels)) =
+fun checkDecl ((d, loc), (funcs, rels, cookies, styles)) =
     let
         fun doFunc s =
             (if SS.member (funcs, s) then
                  E.errorAt loc ("Duplicate function path " ^ s)
              else
                  ();
-             (SS.add (funcs, s), rels))
+             (SS.add (funcs, s), rels, cookies, styles))
 
         fun doRel s =
             (if SS.member (rels, s) then
                  E.errorAt loc ("Duplicate table/sequence path " ^ s)
              else
                  ();
-             (funcs, SS.add (rels, s)))
+             (funcs, SS.add (rels, s), cookies, styles))
+
+        fun doCookie s =
+            (if SS.member (cookies, s) then
+                 E.errorAt loc ("Duplicate cookie path " ^ s)
+             else
+                 ();
+             (funcs, rels, SS.add (cookies, s), styles))
+
+        fun doStyle s =
+            (if SS.member (styles, s) then
+                 E.errorAt loc ("Duplicate style path " ^ s)
+             else
+                 ();
+             (funcs, rels, cookies, SS.add (styles, s)))
     in
         case d of
             DExport (_, s, _, _, _) => doFunc s
@@ -86,13 +100,16 @@
                                    SS.add (rels, s')
                                end
             in
-                (funcs, constraints (ce, rels))
+                (funcs, constraints (ce, rels), cookies, styles)
             end
           | DSequence s => doRel s
 
-          | _ => (funcs, rels)
+          | DCookie s => doCookie s
+          | DStyle s => doStyle s
+
+          | _ => (funcs, rels, cookies, styles)
     end
 
-fun check ds = ignore (foldl checkDecl (SS.empty, SS.empty) ds)
+fun check ds = ignore (foldl checkDecl (SS.empty, SS.empty, SS.empty, SS.empty) ds)
 
 end
--- a/src/prepare.sml	Thu Apr 16 12:00:44 2009 -0400
+++ b/src/prepare.sml	Thu Apr 16 12:07:21 2009 -0400
@@ -259,6 +259,7 @@
       | DDatabase _ => (d, sns)
       | DPreparedStatements _ => (d, sns)
       | DJavaScript _ => (d, sns)
+      | DCookie _ => (d, sns)
       | DStyle _ => (d, sns)
 
 fun prepare (ds, ps) =
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/badCookie.ur	Thu Apr 16 12:07:21 2009 -0400
@@ -0,0 +1,2 @@
+cookie x : int
+cookie x : float
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/badCookie.urp	Thu Apr 16 12:07:21 2009 -0400
@@ -0,0 +1,3 @@
+debug
+
+badCookie