1 let cache = NUri.UriHash.create 313;;
3 let oldg = ref CicUniv.empty_ugraph;;
6 let _,g = CicEnvironment.get_obj !oldg uri in
10 let get_graph _ = !oldg;;
12 let get_checked_obj u =
13 try let b, o = NUri.UriHash.find cache u in
14 if not b then assert false else o
16 let ouri = NUri.ouri_of_nuri u in
19 CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri
20 with exn -> prerr_endline (UriManager.string_of_uri ouri); raise exn
22 (* FIX: add all objects to the environment and give back the last one *)
23 let l = OCic2NCic.convert_obj ouri o in
24 List.iter (fun (u,_,_,_,_ as o) ->
25 (* prerr_endline ("+"^NUri.string_of_uri u); *)
26 NUri.UriHash.add cache u (false,o)) l;
31 try NUri.UriHash.find cache u
33 (* in th final implementation should get it from disk *)
34 let ouri = NUri.ouri_of_nuri u in
35 let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
36 let l = OCic2NCic.convert_obj ouri o in
37 List.iter (fun (u,_,_,_,_ as o) ->
38 (* prerr_endline ("+"^NUri.string_of_uri u); *)
39 NUri.UriHash.add cache u (false,o)) l;
40 false, HExtlib.list_last l
43 let add_obj (u,_,_,_,_ as o) =
44 NUri.UriHash.replace cache u (true, o)
47 let get_checked_def = function
48 | NReference.Ref (_, uri, NReference.Def) ->
49 (match get_checked_obj uri with
50 | _,height,_,_, NCic.Constant (rlv,name,Some bo,ty,att) ->
51 rlv,name,bo,ty,att,height
52 | _,_,_,_, NCic.Constant (_,_,None,_,_) ->
53 prerr_endline "get_checked_def on an axiom"; assert false
54 | _ -> prerr_endline "get_checked_def on a non def 2"; assert false)
55 | _ -> prerr_endline "get_checked_def on a non def"; assert false
58 let get_checked_indtys = function
59 | NReference.Ref (_, uri, NReference.Ind n) ->
60 (match get_checked_obj uri with
61 | _,_,_,_, NCic.Inductive (inductive,leftno,tys,att) ->
62 inductive,leftno,tys,att,n
63 | _ -> prerr_endline "get_checked_indtys on a non ind 2"; assert false)
64 | _ -> prerr_endline "get_checked_indtys on a non ind"; assert false
67 let get_checked_fix_or_cofix b = function
68 | NReference.Ref (_, uri, (NReference.Fix (fixno,_)|NReference.CoFix fixno))->
69 (match get_checked_obj uri with
70 | _,height,_,_, NCic.Fixpoint (is_fix,funcs,att) when is_fix = b ->
71 let rlv, name, _, ty, bo = List.nth funcs fixno in
72 rlv, name, bo, ty, att, height
73 | _ ->prerr_endline "get_checked_(co)fix on a non (co)fix 2";assert false)
74 | r -> prerr_endline ("get_checked_(co)fix on " ^ NReference.string_of_reference r); assert false
76 let get_checked_fix r = get_checked_fix_or_cofix true r;;
77 let get_checked_cofix r = get_checked_fix_or_cofix false r;;
79 let get_indty_leftno = function
80 | NReference.Ref (_, uri, NReference.Ind _)
81 | NReference.Ref (_, uri, NReference.Con _) ->
82 (match get_checked_obj uri with
83 | _,_,_,_, NCic.Inductive (_,left,_,_) -> left
84 | _ ->prerr_endline "get_indty_leftno called on a non ind 2";assert false)
85 | _ -> prerr_endline "get_indty_leftno called on a non indty";assert false
91 NUri.UriHash.replace cache k (false,v))
92 (NUri.UriHash.fold (fun k v -> (@) [k,snd v]) cache [])