]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCic2OCic.ml
70d174e60c84ce3ba4b274b39f679b91cea1fb68
[helm.git] / helm / software / components / ng_kernel / nCic2OCic.ml
1 let nn_2_on = function
2   | "_" -> Cic.Anonymous
3   | s -> Cic.Name s
4 ;;
5
6 let convert_term uri n_fl t =
7  let rec convert_term k = function (* pass k along *)
8  | NCic.Rel i -> Cic.Rel i
9  | NCic.Meta _ -> assert false
10  | NCic.Appl l -> Cic.Appl (List.map (convert_term k) l)
11  | NCic.Prod (n,s,t) -> 
12      Cic.Prod (nn_2_on n,convert_term k s, convert_term (k+1) t)
13  | NCic.Lambda  (n,s,t) -> 
14      Cic.Lambda(nn_2_on n,convert_term k s, convert_term (k+1) t)
15  | NCic.LetIn (n,_,s,t) -> 
16      Cic.LetIn (nn_2_on n,convert_term k s, convert_term (k+1) t)
17  | NCic.Sort NCic.Prop -> Cic.Sort Cic.Prop 
18  | NCic.Sort NCic.CProp -> Cic.Sort Cic.CProp 
19  | NCic.Sort NCic.Set -> Cic.Sort Cic.Set 
20  | NCic.Sort (NCic.Type _) -> Cic.Sort (Cic.Type (CicUniv.fresh ()))
21  | NCic.Implicit _ -> assert false
22  | NCic.Const (NReference.Ref (_,u,NReference.Ind i)) -> 
23      Cic.MutInd (NUri.ouri_of_nuri u,i,[])
24  | NCic.Const (NReference.Ref (_,u,NReference.Con (i,j))) -> 
25      Cic.MutConstruct (NUri.ouri_of_nuri u,i,j,[])
26  | NCic.Const (NReference.Ref (_,u,NReference.Def))
27  | NCic.Const (NReference.Ref (_,u,NReference.Decl)) ->
28      Cic.Const (NUri.ouri_of_nuri u,[])
29  | NCic.Match (NReference.Ref (_,u,NReference.Ind i),oty,t,pl) ->
30      Cic.MutCase (NUri.ouri_of_nuri u,i, convert_term k oty, convert_term k t,
31        List.map (convert_term k) pl)
32  | NCic.Const (NReference.Ref (_,u,NReference.Fix (i,_))) 
33  | NCic.Const (NReference.Ref (_,u,NReference.CoFix i)) ->
34     if NUri.eq u uri then             
35       Cic.Rel (n_fl - i + k)
36     else
37       Cic.Const (NUri.ouri_of_nuri u,[])
38  | _ -> assert false
39  in
40   convert_term 0 t
41 ;;
42
43 let convert_fix is_fix uri k fl = 
44   let n_fl = List.length fl in
45   if is_fix then 
46     let fl = 
47       List.map
48       (fun (_, name,recno,ty,bo) -> 
49         name, recno, convert_term uri n_fl ty, convert_term uri n_fl bo)
50       fl
51     in 
52      Cic.Fix (k, fl) 
53   else 
54     let fl = 
55       List.map
56       (fun (_, name,_,ty,bo) -> 
57         name, convert_term uri n_fl ty, convert_term uri n_fl bo)
58       fl
59     in 
60      Cic.CoFix (k, fl) 
61 ;;
62
63 let convert_nobj = function 
64  | u,_,_,_,NCic.Constant (_, name, Some bo, ty, _) ->
65      [NUri.ouri_of_nuri u,Cic.Constant 
66         (name, Some (convert_term u 0 bo), convert_term u 0 ty, [],[])]
67  | u,_,_,_,NCic.Constant (_, name,  None, ty, _) ->
68      [NUri.ouri_of_nuri u,Cic.Constant (name, None, convert_term u 0 ty, [],[])]
69  | u,_,_,_,NCic.Fixpoint (is_fix, fl, _) ->
70      List.map 
71       (fun nth ->
72         let name = UriManager.name_of_uri (NUri.ouri_of_nuri u) in
73         let buri = UriManager.buri_of_uri (NUri.ouri_of_nuri u) in
74         let uri = UriManager.uri_of_string (buri ^"/"^name^".con") in
75         uri,
76         Cic.Constant (name, 
77          Some (convert_fix is_fix u nth fl), 
78           convert_term u 0 (let _,_,_,ty,_ = List.hd fl in ty), [], []))
79      (let rec seq = function 0 -> [0]|n -> n::seq (n-1) in 
80       seq (List.length fl-1))
81  | _,_,_,_,NCic.Inductive _ -> assert false
82 ;;