]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCicEnvironment.ml
79014def5ef29866317569197dba712875688276
[helm.git] / helm / software / components / ng_kernel / nCicEnvironment.ml
1 let cache = NUri.UriHash.create 313;;
2
3 let get_checked_obj u =
4   try NUri.UriHash.find cache u
5   with Not_found ->
6     let ouri = NUri.ouri_of_nuri u in
7     let o,_ = 
8       CicEnvironment.get_cooked_obj ~trust:false CicUniv.oblivion_ugraph ouri 
9     in
10     (* FIX: add all objects to the environment and give back the last one *)
11     let no = HExtlib.list_last (OCic2NCic.convert_obj ouri o) in
12     NUri.UriHash.add cache u no;
13     no
14 ;;
15
16 let get_obj u =
17   try true, NUri.UriHash.find cache u
18   with Not_found ->
19     (* in th final implementation should get it from disk *)
20     let ouri = NUri.ouri_of_nuri u in
21     let o,_ = 
22       CicEnvironment.get_cooked_obj ~trust:false CicUniv.oblivion_ugraph ouri 
23     in
24     false, HExtlib.list_last (OCic2NCic.convert_obj ouri o)
25 ;;
26
27 let get_checked_def = function
28   | NReference.Ref (_, uri, NReference.Def) ->
29       (match get_checked_obj uri with
30       | _,height,_,_, NCic.Constant (rlv,name,Some bo,ty,att) ->
31           rlv,name,bo,ty,att,height
32       | _,_,_,_, NCic.Constant (_,_,None,_,_) ->
33           prerr_endline "get_checked_def on an axiom"; assert false
34       | _ -> prerr_endline "get_checked_def on a non def 2"; assert false)
35   | _ -> prerr_endline "get_checked_def on a non def"; assert false
36 ;;
37
38 let get_checked_indtys = function
39   | NReference.Ref (_, uri, NReference.Ind n) ->
40       (match get_checked_obj uri with
41       | _,_,_,_, NCic.Inductive (inductive,leftno,tys,att) ->
42         inductive,leftno,tys,att,n
43       | _ -> prerr_endline "get_checked_indtys on a non ind 2"; assert false)
44   | _ -> prerr_endline "get_checked_indtys on a non ind"; assert false
45 ;;
46
47 let get_checked_fix_or_cofix b = function
48   | NReference.Ref (_, uri, NReference.Fix (fixno,_)) ->
49       (match get_checked_obj uri with
50       | _,height,_,_, NCic.Fixpoint (is_fix,funcs,att) when is_fix = b ->
51          let rlv, name, _, ty, bo = List.nth funcs fixno in
52          rlv, name, bo, ty, att, height
53       | _ ->prerr_endline "get_checked_(co)fix on a non (co)fix 2";assert false)
54   | _ -> prerr_endline "get_checked_(co)fix on a non (co)fix"; assert false
55 ;;
56 let get_checked_fix r = get_checked_fix_or_cofix true r;;
57 let get_checked_cofix r = get_checked_fix_or_cofix false r;;
58
59 let get_indty_leftno = function 
60   | NReference.Ref (_, uri, NReference.Ind _) 
61   | NReference.Ref (_, uri, NReference.Con _) ->
62       (match get_checked_obj uri with
63       | _,_,_,_, NCic.Inductive (_,left,_,_) -> left
64       | _ ->prerr_endline "get_indty_leftno called on a non ind 2";assert false)
65   | _ -> prerr_endline "get_indty_leftno called on a non indty";assert false