]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/metadata/metadataConstraints.ml
prerr_endline => debug_print
[helm.git] / helm / software / components / metadata / metadataConstraints.ml
index c2dee6f5edb40cdc839ea5df43f1d8f56e96f800..e35e35894978ac33651b9f7c3e17663b1ec8a72b 100644 (file)
@@ -153,7 +153,7 @@ let add_constraint ?(start=0) ?(tables=default_tables) (n,from,where) metadata =
       in
       ((n+2), from, where)
 
-let exec ~(dbd:HSql.dbd) ?rating (n,from,where) =
+let exec dbtype ~(dbd:HSql.dbd) ?rating (n,from,where) =
   let from = String.concat ", " from in
   let where = String.concat " and " where in
   let query =
@@ -166,12 +166,14 @@ let exec ~(dbd:HSql.dbd) ?rating (n,from,where) =
           from where 
   in
   (* prerr_endline query; *) 
-  let result = HSql.exec dbd query in
+  let result = HSql.exec dbtype dbd query in
   HSql.map result
-    (fun row -> match row.(0) with Some s -> UriManager.uri_of_string s | _ -> assert false)
-
+    ~f:(fun row -> 
+     match row.(0) with Some s -> UriManager.uri_of_string s 
+     | _ -> assert false)
+;;
 
-let at_least ~(dbd:HSql.dbd) ?concl_card ?full_card ?diff ?rating tables
+let at_least dbtype ~(dbd:HSql.dbd) ?concl_card ?full_card ?diff ?rating tables
   (metadata: MetadataTypes.constr list)
 =
   let obj_tbl,rel_tbl,sort_tbl, count_tbl = tables in
@@ -187,7 +189,7 @@ let at_least ~(dbd:HSql.dbd) ?concl_card ?full_card ?diff ?rating tables
     let (n,from,where) =
       add_all_constr ~tbl:count_tbl (n,from,where) concl_card full_card diff
     in
-    exec ~dbd ?rating (n,from,where)
+    exec dbtype ~dbd ?rating (n,from,where)
 ;;
     
 let at_least  
@@ -195,13 +197,26 @@ let at_least
       (metadata: MetadataTypes.constr list)
 =
   if are_tables_ownerized () then
-    (at_least 
-       ~dbd ?concl_card ?full_card ?diff ?rating default_tables metadata) @
-    (at_least 
-       ~dbd ?concl_card ?full_card ?diff ?rating (current_tables ()) metadata)
+    at_least 
+      HSql.Library ~dbd ?concl_card ?full_card ?diff ?rating 
+        default_tables metadata
+    @
+    at_least 
+      HSql.Legacy ~dbd ?concl_card ?full_card ?diff ?rating 
+        default_tables metadata
+    @
+    at_least 
+      HSql.User ~dbd ?concl_card ?full_card ?diff ?rating 
+        (current_tables ()) metadata
+
   else
     at_least 
-      ~dbd ?concl_card ?full_card ?diff ?rating default_tables metadata 
+      HSql.Library ~dbd ?concl_card ?full_card ?diff ?rating 
+        default_tables metadata 
+    @
+    at_least 
+      HSql.Legacy ~dbd ?concl_card ?full_card ?diff ?rating 
+        default_tables metadata 
   
     
   (** Prefix handling *)
@@ -254,8 +269,9 @@ and inspect_conclusion n t =
        merge n (inspect_conclusion n s) (inspect_conclusion n t)
     | Cic.Lambda (_, s, t) ->
        merge n (inspect_conclusion n s) (inspect_conclusion n t)
-    | Cic.LetIn (_, s, t) ->
-       merge n (inspect_conclusion n s) (inspect_conclusion n t)
+    | Cic.LetIn (_, s, ty, t) ->
+       merge n (inspect_conclusion n s)
+       (merge n (inspect_conclusion n ty) (inspect_conclusion n t))
     | Cic.Appl ((Cic.Const (u,exp_named_subst))::l) ->
        add_root (n-1) u l
     | Cic.Appl ((Cic.MutInd (u, t, exp_named_subst))::l) ->
@@ -293,7 +309,7 @@ let rec inspect_term n t =
        Some uri, SetSet.empty
     | Cic.Cast (t, _) -> inspect_term n t
     | Cic.Prod (_, _, t) -> inspect_term n t
-    | Cic.LetIn (_, _, t) -> inspect_term n t
+    | Cic.LetIn (_, _, _, t) -> inspect_term n t
     | Cic.Appl ((Cic.Const (u,exp_named_subst))::l) ->
        let childunion = inspect_children (n-1) l in
        Some u, childunion
@@ -362,18 +378,28 @@ and signature_concl =
     | Cic.Const (u,exp_named_subst) -> 
         UriManagerSet.singleton u
     | Cic.MutInd (u, t, exp_named_subst) -> 
+        let rec projections_of uris =
+          List.flatten
+           (List.map 
+            (fun uri ->
+              let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+              projections_of (CicUtil.projections_of_record o uri))
+            uris)
+        in
         let uri = UriManager.uri_of_uriref u t None in
-       UriManagerSet.singleton uri
+        List.fold_right UriManagerSet.add
+          (projections_of [u]) (UriManagerSet.singleton uri)
     | Cic.MutConstruct (u, t, c, exp_named_subst) -> 
         let uri = UriManager.uri_of_uriref u t (Some c) in
-       UriManagerSet.singleton uri
+        UriManagerSet.singleton uri
     | Cic.Cast (t, _) -> signature_concl t
     | Cic.Prod (_, s, t) -> 
        UriManagerSet.union (signature_concl s) (signature_concl t)
     | Cic.Lambda (_, s, t) ->
        UriManagerSet.union (signature_concl s) (signature_concl t)
-    | Cic.LetIn (_, s, t) ->
-       UriManagerSet.union (signature_concl s) (signature_concl t)
+    | Cic.LetIn (_, s, ty, t) ->
+       UriManagerSet.union (signature_concl s)
+       (UriManagerSet.union (signature_concl ty) (signature_concl t))
     | Cic.Appl l  -> add l
     | Cic.MutCase _
     | Cic.Fix _
@@ -383,7 +409,7 @@ and signature_concl =
 let rec signature_of = function
   | Cic.Cast (t, _)      -> signature_of t
   | Cic.Prod (_, _, t)   -> signature_of t               
-  | Cic.LetIn (_, _, t) -> signature_of t
+  | Cic.LetIn (_, _, _, t) -> signature_of t
   | Cic.Appl ((Cic.Const (u,exp_named_subst))::l) ->
       Some (u, []), add l
   | Cic.Appl ((Cic.MutInd (u, t, exp_named_subst))::l) ->
@@ -447,24 +473,30 @@ let get_constants (dbd:HSql.dbd) ~where uri =
         [ MetadataTypes.mainconcl_pos; MetadataTypes.inconcl_pos;
           MetadataTypes.inhyp_pos; MetadataTypes.mainhyp_pos ]
   in
-  let query = 
-    let pos_predicate =
-      String.concat " OR "
-        (List.map (fun pos -> sprintf "(h_position = \"%s\")" pos) positions)
-    in
-    sprintf ("SELECT h_occurrence FROM %s WHERE source=\"%s\" AND (%s) UNION "^^
-             "SELECT h_occurrence FROM %s WHERE source=\"%s\" AND (%s)")
-      (MetadataTypes.obj_tbl ()) uri pos_predicate
-      MetadataTypes.library_obj_tbl uri pos_predicate
-      
+  let pos_predicate =
+    String.concat " OR "
+      (List.map (fun pos -> sprintf "(h_position = \"%s\")" pos) positions)
+  in
+  let query tbl = 
+    sprintf "SELECT h_occurrence FROM %s WHERE source=\"%s\" AND (%s)"
+      tbl uri pos_predicate
+  in
+  let db = [
+    HSql.Library, MetadataTypes.library_obj_tbl;
+    HSql.Legacy, MetadataTypes.library_obj_tbl;
+    HSql.User, MetadataTypes.obj_tbl ()]
   in
-  let result = HSql.exec dbd query in
   let set = ref UriManagerSet.empty in
-  HSql.iter result
-    (fun col ->
-      match col.(0) with
-      | Some uri -> set := UriManagerSet.add (UriManager.uri_of_string uri) !set
-      | _ -> assert false);
+  List.iter
+    (fun (dbtype, table) ->
+      let result = HSql.exec dbtype dbd (query table) in
+      HSql.iter result
+        (fun col ->
+         match col.(0) with
+         | Some uri -> 
+             set := UriManagerSet.add (UriManager.uri_of_string uri) !set
+         | _ -> assert false)) 
+    db;
   !set
 
 let at_most ~(dbd:HSql.dbd) ?(where = `Conclusion) only u =