2 exception NotImplemented of int * string;;
3 exception WrongUriToConstant;;
4 exception WrongUriToVariable of string;;
5 exception WrongUriToInductiveDefinition;;
7 (* mem x lol is true if x is a member of one *)
8 (* of the lists of the list of (int * list) lol *)
10 List.fold_right (fun (_,l) i -> i || List.mem x l) lol false
14 let cook curi cookingsno var =
20 n when n >= k -> C.Rel (n + 1)
24 if UriManager.eq uri var then
30 | C.Implicit as t -> t
31 | C.Cast (te, ty) -> C.Cast (aux k te, aux k ty)
32 | C.Prod (n,s,t) -> C.Prod (n, aux k s, aux (k + 1) t)
33 | C.Lambda (n,s,t) -> C.Lambda (n, aux k s, aux (k + 1) t)
35 (* Get rid of C.Appl (C.Appl l1) l2 *)
36 let newtl = List.map (aux k) tl in
38 C.Appl (he'::tl') -> C.Appl (he'::(tl'@newtl))
39 | t -> C.Appl (t::newtl)
41 | C.Appl [] -> raise Impossible
43 if match CicCache.get_obj uri with
44 C.Definition (_,_,_,params) when mem var params -> true
45 | C.Definition _ -> false
46 | C.Axiom (_,_,params) when mem var params -> true
49 raise (NotImplemented (2,(UriManager.string_of_uri uri)))
50 | _ -> raise WrongUriToConstant
53 ((C.Const (uri,UriManager.relative_depth curi uri cookingsno))::
56 C.Const (uri,UriManager.relative_depth curi uri cookingsno)
58 | C.MutInd (uri,_,i) ->
59 if match CicCache.get_obj uri with
60 C.InductiveDefinition (_,params,_) when mem var params -> true
61 | C.InductiveDefinition _ -> false
62 | _ -> raise WrongUriToInductiveDefinition
64 C.Appl ((C.MutInd (uri,UriManager.relative_depth curi uri cookingsno,i))::[C.Rel k])
66 C.MutInd (uri,UriManager.relative_depth curi uri cookingsno,i)
67 | C.MutConstruct (uri,_,i,j) ->
68 if match CicCache.get_obj uri with
69 C.InductiveDefinition (_,params,_) when mem var params -> true
70 | C.InductiveDefinition _ -> false
71 | _ -> raise WrongUriToInductiveDefinition
73 C.Appl ((C.MutConstruct (uri,UriManager.relative_depth curi uri cookingsno,i,j))::[C.Rel k])
75 C.MutConstruct (uri,UriManager.relative_depth curi uri cookingsno,i,j)
76 | C.MutCase (uri,_,i,outt,term,pl) ->
80 C.MutCase (uri,UriManager.relative_depth curi uri cookingsno,i,
81 aux k outt,aux k term, substitutedfl)
83 let len = List.length fl in
86 (fun (name,i,ty,bo) -> (name,i,aux k ty, aux (k+len) bo))
89 C.Fix (i, substitutedfl)
91 let len = List.length fl in
94 (fun (name,ty,bo) -> (name,aux k ty, aux (k+len) bo))
97 C.CoFix (i, substitutedfl)
102 let cook_gen add_binder curi cookingsno ty vars =
103 let module C = Cic in
104 let module U = UriManager in
108 let (varname, vartype) =
109 match CicCache.get_obj var with
110 C.Variable (varname, vartype) -> (varname, vartype)
111 | _ -> raise (WrongUriToVariable (U.string_of_uri var))
113 cookrec (add_binder (C.Name varname) vartype (cook curi cookingsno var ty)) tl
120 cook_gen (fun n s t -> Cic.Prod (n,s,t))
122 cook_gen (fun n s t -> Cic.Lambda (n,s,t))
125 (*CSC: sbagliato da rifare e completare *)
126 let cook_one_level obj curi cookingsno vars =
127 let module C = Cic in
129 C.Definition (id,te,ty,params) ->
130 let ty' = cook_prod curi cookingsno ty vars in
131 let te' = cook_lambda curi cookingsno te vars in
132 C.Definition (id,te',ty',params)
133 | C.Axiom (id,ty,parameters) ->
134 let ty' = cook_prod curi cookingsno ty vars in
135 C.Axiom (id,ty',parameters)
136 | C.Variable _ as obj -> obj
137 | C.CurrentProof (id,conjs,te,ty) ->
138 let ty' = cook_prod curi cookingsno ty vars in
139 let te' = cook_lambda curi cookingsno te vars in
140 C.CurrentProof (id,conjs,te',ty')
141 | C.InductiveDefinition (dl, params, n_ind_params) ->
144 (fun (name,inductive,arity,constructors) ->
150 None -> raise Impossible
151 | Some r -> List.map (fun _ -> false) vars @ r
153 (name,cook_prod curi cookingsno ty vars,ref (Some r'))
156 (name,inductive,cook_prod curi cookingsno arity vars,constructors')
159 C.InductiveDefinition (dl', params, n_ind_params + List.length vars)
162 let cook_obj obj uri =
163 let module C = Cic in
166 C.Definition (_,_,_,params) -> params
167 | C.Axiom (_,_,params) -> params
169 | C.CurrentProof _ -> []
170 | C.InductiveDefinition (_,params,_) -> params
172 let rec cook_all_levels obj =
176 let cooked_obj = cook_one_level obj uri (n + 1) (List.rev vars) in
177 (n,cooked_obj)::(cook_all_levels cooked_obj tl)
179 cook_all_levels obj (List.rev params)
182 CicCache.cook_obj := cook_obj;;