]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCic2OCic.ml
height of constants properly handled
[helm.git] / helm / software / components / ng_kernel / nCic2OCic.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 (* $Id$ *)
13
14 let ouri_of_nuri u = UriManager.uri_of_string (NUri.string_of_uri u);;
15
16 let ouri_of_reference (NReference.Ref (u,_)) = ouri_of_nuri u;;
17
18 let nn_2_on = function
19   | "_" -> Cic.Anonymous
20   | s -> Cic.Name s
21 ;;
22
23 let convert_term uri n_fl t =
24  let rec convert_term k = function (* pass k along *)
25  | NCic.Rel i -> Cic.Rel i
26  | NCic.Meta _ -> assert false
27  | NCic.Appl l -> Cic.Appl (List.map (convert_term k) l)
28  | NCic.Prod (n,s,t) -> 
29      Cic.Prod (nn_2_on n,convert_term k s, convert_term (k+1) t)
30  | NCic.Lambda  (n,s,t) -> 
31      Cic.Lambda(nn_2_on n,convert_term k s, convert_term (k+1) t)
32  | NCic.LetIn (n,ty_s,s,t) -> 
33      Cic.LetIn (nn_2_on n,convert_term k s,convert_term k ty_s, convert_term (k+1) t)
34  | NCic.Sort NCic.Prop -> Cic.Sort Cic.Prop 
35  | NCic.Sort NCic.CProp -> Cic.Sort Cic.CProp 
36  | NCic.Sort (NCic.Type _) -> Cic.Sort (Cic.Type (CicUniv.fresh ()))
37  | NCic.Implicit _ -> assert false
38  | NCic.Const (NReference.Ref (u,NReference.Ind (_,i))) -> 
39      Cic.MutInd (ouri_of_nuri u,i,[])
40  | NCic.Const (NReference.Ref (u,NReference.Con (i,j))) -> 
41      Cic.MutConstruct (ouri_of_nuri u,i,j,[])
42  | NCic.Const (NReference.Ref (u,NReference.Def _))
43  | NCic.Const (NReference.Ref (u,NReference.Decl)) ->
44      Cic.Const (ouri_of_nuri u,[])
45  | NCic.Match (NReference.Ref (u,NReference.Ind (_,i)),oty,t,pl) ->
46      Cic.MutCase (ouri_of_nuri u,i, convert_term k oty, convert_term k t,
47        List.map (convert_term k) pl)
48  | NCic.Const (NReference.Ref (u,NReference.Fix (i,_,_))) 
49  | NCic.Const (NReference.Ref (u,NReference.CoFix i)) ->
50     if NUri.eq u uri then             
51       Cic.Rel (n_fl - i + k)
52     else
53      let ouri = ouri_of_nuri u in
54      let ouri =
55       UriManager.uri_of_string 
56        (UriManager.buri_of_uri ouri ^ "/" ^
57         UriManager.name_of_uri ouri ^ string_of_int i ^ ".con") in
58       Cic.Const (ouri,[])
59  | _ -> assert false
60  in
61   convert_term 0 t
62 ;;
63
64 let convert_fix is_fix uri k fl = 
65   let n_fl = List.length fl in
66   if is_fix then 
67     let fl = 
68       List.map
69       (fun (_, name,recno,ty,bo) -> 
70         name, recno, convert_term uri n_fl ty, convert_term uri n_fl bo)
71       fl
72     in 
73      Cic.Fix (k, fl) 
74   else 
75     let fl = 
76       List.map
77       (fun (_, name,_,ty,bo) -> 
78         name, convert_term uri n_fl ty, convert_term uri n_fl bo)
79       fl
80     in 
81      Cic.CoFix (k, fl) 
82 ;;
83
84 let convert_nobj = function 
85  | u,_,_,_,NCic.Constant (_, name, Some bo, ty, _) ->
86      [ouri_of_nuri u,Cic.Constant 
87         (name, Some (convert_term u 0 bo), convert_term u 0 ty, [],[])]
88  | u,_,_,_,NCic.Constant (_, name,  None, ty, _) ->
89      [ouri_of_nuri u,Cic.Constant (name, None, convert_term u 0 ty, [],[])]
90  | u,_,_,_,NCic.Fixpoint (is_fix, fl, _) ->
91      List.map 
92       (fun nth ->
93         let name =
94          UriManager.name_of_uri (ouri_of_nuri u) ^ string_of_int nth in
95         let buri = UriManager.buri_of_uri (ouri_of_nuri u) in
96         let uri = UriManager.uri_of_string (buri ^"/"^name^".con") in
97         uri,
98         Cic.Constant (name, 
99          Some (convert_fix is_fix u nth fl), 
100           convert_term u 0 (let _,_,_,ty,_ = List.hd fl in ty), [], []))
101      (let rec seq = function 0 -> [0]|n -> n::seq (n-1) in 
102       seq (List.length fl-1))
103  | _,_,_,_,NCic.Inductive _ -> assert false
104 ;;