]> matita.cs.unibo.it Git - helm.git/blob - components/ng_kernel/nCicEnvironment.ml
tagged 0.5.0-rc1
[helm.git] / components / ng_kernel / nCicEnvironment.ml
1 let cache = NUri.UriHash.create 313;;
2
3 let oldg = ref CicUniv.empty_ugraph;;
4
5 let load_graph uri = 
6   let _,g = CicEnvironment.get_obj !oldg uri in
7   oldg := g
8 ;;
9
10 let get_graph _ = !oldg;;
11
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
15   with Not_found ->
16     let ouri = NUri.ouri_of_nuri u in
17     let o,_ = 
18       try 
19         CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri 
20       with exn -> prerr_endline (UriManager.string_of_uri ouri); raise exn
21     in
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;
27     HExtlib.list_last l
28 ;;
29
30 let get_obj u =
31   try NUri.UriHash.find cache u
32   with Not_found ->
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
41 ;;
42
43 let add_obj (u,_,_,_,_ as o) =
44   NUri.UriHash.replace cache u (true, o)
45 ;;
46
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
56 ;;
57
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
65 ;;
66
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          funcs, att, height
72       | _ ->prerr_endline "get_checked_(co)fix on a non (co)fix 2";assert false)
73   | r -> prerr_endline ("get_checked_(co)fix on " ^ NReference.string_of_reference r); assert false
74 ;;
75 let get_checked_fixes r = get_checked_fix_or_cofix true r;;
76 let get_checked_cofixes r = get_checked_fix_or_cofix false r;;
77
78 let get_indty_leftno = function 
79   | NReference.Ref (_, uri, NReference.Ind _) 
80   | NReference.Ref (_, uri, NReference.Con _) ->
81       (match get_checked_obj uri with
82       | _,_,_,_, NCic.Inductive (_,left,_,_) -> left
83       | _ ->prerr_endline "get_indty_leftno called on a non ind 2";assert false)
84   | _ -> prerr_endline "get_indty_leftno called on a non indty";assert false
85 ;;
86
87 let invalidate _ = 
88   List.iter 
89     (fun (k,v) ->
90       NUri.UriHash.replace cache k (false,v))
91     (NUri.UriHash.fold (fun k v -> (@) [k,snd v]) cache [])
92 ;;
93