]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matita/contribs/lambdadelta/bin/roles/rolesUtils.ml
update in binaries for λδ
[helm.git] / matita / matita / contribs / lambdadelta / bin / roles / rolesUtils.ml
index 7c779fddfebdcf6aadcad2d331c158eba49e0acc..a617c3607f9f754e0a7e454bf68a58acd5d7dc57 100644 (file)
@@ -43,13 +43,13 @@ let rec list_nth n = function
   | []         -> raise_error ET.ENoEntry
   | (_,hd)::tl -> if n = 0 then hd else list_nth (pred n) tl
 
-let rec list_toggle n = function
+let rec list_select n = function
   | []         -> raise_error ET.ENoEntry
-  | (b,hd)::tl -> if n = 0 then (not b,hd)::tl else (b,hd)::list_toggle (pred n) tl
+  | (b,hd)::tl -> if n = 0 then (not b,hd)::tl else (b,hd)::list_select (pred n) tl
 
-let rec list_toggle_all = function
+let rec list_select_all = function
   | []         -> []
-  | (b,hd)::tl -> (not b,hd)::list_toggle_all tl
+  | (b,hd)::tl -> (not b,hd)::list_select_all tl
 
 let rec list_split = function
   | []                -> [], []
@@ -58,12 +58,12 @@ let rec list_split = function
     if fst hd then fs,((false,a)::ts)
     else (hd::fs),ts
 
-let rec list_select r = function
+let rec list_find_selected r = function
   | []         -> r
   | (b,hd)::tl ->
     begin match b, r with
-    | false, _      -> list_select r tl
-    | true , None   -> list_select (Some hd) tl
+    | false, _      -> list_find_selected r tl
+    | true , None   -> list_find_selected (Some hd) tl
     | true , Some _ -> raise_error (ET.EWrongSelect)
     end
 
@@ -74,6 +74,10 @@ let rec list_exists compare = function
     if b <= 0 then b = 0 else
     list_exists compare tl
 
+let rec list_count s c = function
+  | []         -> s, c
+  | (b, _)::tl -> list_count (s + if b then 1 else 0) (succ c) tl
+
 let string_of_version v =
   String.concat "." (List.map string_of_int v)
 
@@ -96,6 +100,16 @@ let names_union ns1 ns2 =
   let error n = ET.ENameClash n in
   list_union error compare_names ns1 ns2
 
+let rec match_names oi ni os ns =
+  match os, ns with
+  | _         , []        -> None
+  | []        , _         -> None
+  | (_,o)::otl,(_,n)::ntl ->
+    let b = compare_names (snd o) n in
+    if b > 0 then match_names oi (succ ni) os ntl else
+    if b < 0 then match_names (succ oi) ni otl ns else
+    Some (oi, ni)
+
 let string_of_obj (v,n) =
   Printf.sprintf "%s/%s" (string_of_version v) (string_of_name n)
 
@@ -116,6 +130,17 @@ let rec rev_objs_of_names v os = function
   | []        -> os
   | (b,n)::tl -> rev_objs_of_names v ((b,(v,n))::os) tl
 
+let rec get_tops v = function
+  | []        -> [], []
+  | (_,r)::tl ->
+    let ds, ts = get_tops v tl in
+    if compare_versions v r.ET.v = 0 then begin
+      if r.ET.n = [] then objs_union r.ET.o ds, ts else
+      let tops = rev_objs_of_names v [] r.ET.n in
+      ds, objs_union (List.rev tops) ts
+    end else
+      ds, ts
+
 let obj_of_role r =
   let n = match r.ET.n with
     | []        -> []
@@ -133,58 +158,81 @@ let roles_union rs1 rs2 =
   let error r = ET.ERoleClash r in
   list_union error compare_roles rs1 rs2
 
+let roles_expand_all rs =
+  let map (b, r) = r.ET.x <- not r.ET.x in
+  List.iter map rs
+
+let rec roles_expand n = function
+  | []        -> ()
+  | (_,r)::tl ->
+    if n = 0 then r.ET.x <- not r.ET.x else
+    roles_expand (pred n) tl
+
 let exists_role_deleted v r =
   let o = v, [] in
   let compare r = compare_objs o (obj_of_role r) in
   list_exists compare r
 
-let rec get_tops v = function
-  | []        -> [], []
-  | (_,r)::tl ->
-    let ds, ts = get_tops v tl in
-    if compare_versions v r.ET.v = 0 then begin
-      if r.ET.n = [] then objs_union r.ET.o ds, ts else
-      let tops = rev_objs_of_names v [] r.ET.n in
-      ds, objs_union (List.rev tops) ts
-    end else
-      ds, ts
-
-let rec match_names oi ni os ns =
-  match os, ns with
-  | _         , []        -> None
-  | []        , _         -> None
-  | (_,o)::otl,(_,n)::ntl ->
-    let b = compare_names (snd o) n in
-    if b > 0 then match_names oi (succ ni) os ntl else
-    if b < 0 then match_names (succ oi) ni otl ns else
-    Some (oi, ni)
+let roles_split s rs =
+  let rec aux rs os ns = function
+  | []           -> List.rev rs, os, ns
+  | (b, r) :: tl ->
+    if compare_versions s r.ET.v <> 0 then aux ((b, r)::rs) os ns tl else
+    if b then aux rs (objs_union os r.ET.o) (names_union ns r.ET.n) tl else
+    let ro, so = list_split r.ET.o in
+    let rn, sn = list_split r.ET.n in
+    if ro = [] && rn = [] then aux rs (objs_union os so) (names_union ns sn) tl else begin
+      r.ET.o <- ro; r.ET.o <- ro;
+      aux ((b, r)::rs) (objs_union os so) (names_union ns sn) tl
+    end
+  in
+  aux [] [] [] rs
 
 let new_status = {
-  ET.r = []; ET.s = []; ET.t = []; ET.w = [];
+  ET.m = false; ET.r = []; ET.s = []; ET.t = []; ET.w = [];
 }
 
+let string_of_pointer = string_of_version
+
 let pointer_of_string = version_of_string
 
+let list_visit before each visit after string_of p l =
+  let ptr p = string_of_pointer (List.rev p) in
+  let rec aux i = function
+    | []         -> ()
+    | (b, x)::tl ->
+      each (ptr (i::p)) b (string_of x);
+      visit (i::p) x;
+      aux (succ i) tl
+  in
+  let s, c = list_count 0 0 l in
+  let count = Printf.sprintf "%u/%u" s c in
+  before (ptr p) count;
+  aux 0 l;
+  after ()
+
 let string_of_error = function
-  | ET.EWrongExt x   ->
+  | ET.EWrongExt x         ->
     Printf.sprintf "unknown input file type %S" x
-  | ET.EStage v      ->
+  | ET.EStage v            ->
     Printf.sprintf "current stage %S" (string_of_version v)
-  | ET.ENoStage      ->
+  | ET.ENoStage            ->
     Printf.sprintf "current stage not defined"
-  | ET.EWaiting      ->
+  | ET.EWaiting            ->
     Printf.sprintf "current stage not finished"
-  | ET.ENameClash n  ->
+  | ET.ENameClash n        ->
     Printf.sprintf "name clash %S" (string_of_name n)
-  | ET.EObjClash o   ->
+  | ET.EObjClash o         ->
     Printf.sprintf "object clash %S" (string_of_obj o)
-  | ET.ERoleClash r  ->
+  | ET.ERoleClash r        ->
     Printf.sprintf "role clash %S" (string_of_role r)
-  | ET.ENoEntry      ->
+  | ET.ENoEntry            ->
     Printf.sprintf "entry not found"
-  | ET.EWrongSelect  ->
+  | ET.EWrongSelect        ->
     Printf.sprintf "selected role is not unique"
-  | ET.EWrongVersion ->
+  | ET.EWrongVersion       ->
     Printf.sprintf "selected role is not in the current stage"
-  | ET.ETops         ->
+  | ET.ETops               ->
     Printf.sprintf "top objects already computed"
+  | ET.EWrongRequest (r,a) ->
+    Printf.sprintf "unknown request \"%s=%s\"" r a