]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicLibrary.ml
The backward compatible management of aliases for NG is now fully completed.
[helm.git] / helm / software / components / ng_kernel / nCicLibrary.ml
index ae721526b948e6ff1bf723fd133c79ff852bef1e..86822aa74b28f56878e4fdeffd4cb6e563178654 100644 (file)
 
 exception ObjectNotFound of string Lazy.t
 
+let storage = ref [];;
+
+let aliases = ref [];;
+
+let resolve name =
+ try
+  HExtlib.filter_map
+   (fun (_,name',nref) -> if name'=name then Some nref else None) !aliases
+ with
+  Not_found -> raise (ObjectNotFound (lazy name))
+;;
+
+let aliases_of uri =
+ try
+  HExtlib.filter_map
+   (fun (uri',_,nref) -> if NUri.eq uri' uri then Some nref else None) !aliases
+ with
+  Not_found -> raise (ObjectNotFound (lazy (NUri.string_of_uri uri)))
+;;
+
+let add_obj u obj =
+ storage := (u,obj)::!storage;
+  let _,height,_,_,obj = obj in
+  let references =
+   match obj with
+      NCic.Constant (_,name,None,_,_) ->
+       [u,name,NReference.reference_of_spec u NReference.Decl]
+    | NCic.Constant (_,name,Some _,_,_) ->
+       [u,name,NReference.reference_of_spec u (NReference.Def height)]
+    | NCic.Fixpoint (is_ind,fl,_) ->
+       HExtlib.list_mapi
+        (fun (_,name,recno,_,_) i ->
+          if is_ind then
+           u,name,NReference.reference_of_spec u(NReference.Fix(i,recno,height))
+          else
+           u,name,NReference.reference_of_spec u (NReference.CoFix i)) fl
+    | NCic.Inductive (inductive,leftno,il,_) ->
+       List.flatten
+        (HExtlib.list_mapi
+         (fun (_,iname,_,cl) i ->
+           HExtlib.list_mapi
+            (fun (_,cname,_) j->
+              u,cname,
+               NReference.reference_of_spec u (NReference.Con (i,j,leftno))
+            ) cl @
+           [u,iname,
+             NReference.reference_of_spec u
+              (NReference.Ind (inductive,i,leftno))]
+         ) il)
+  in
+   aliases := references @ !aliases
+;;
+
 let cache = NUri.UriHash.create 313;;
 
 let get_obj u =
+ try List.assq u !storage
+ with Not_found ->
   try NUri.UriHash.find cache u
   with Not_found ->
     (* in the final implementation should get it from disk *)
     let ouri = NCic2OCic.ouri_of_nuri u in
-    let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
-    let l = OCic2NCic.convert_obj ouri o in
-    List.iter (fun (u,_,_,_,_ as o) -> 
-(*       prerr_endline ("+"^NUri.string_of_uri u);  *)
-      NUri.UriHash.add cache u o) l;
-    HExtlib.list_last l
+    try
+      let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
+      let l = OCic2NCic.convert_obj ouri o in
+      List.iter (fun (u,_,_,_,_ as o) -> 
+  (*       prerr_endline ("+"^NUri.string_of_uri u);  *)
+        NUri.UriHash.add cache u o) l;
+      HExtlib.list_last l
+    with CicEnvironment.Object_not_found u -> 
+      raise (ObjectNotFound 
+               (lazy (NUri.string_of_uri (OCic2NCic.nuri_of_ouri u))))
 ;;
 
 let clear_cache () = NUri.UriHash.clear cache;;