1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (**************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (**************************************************************************)
35 (* e se mettessi la conversione di BY nell'apply_context ? *)
36 (* sarebbe carino avere l'invariante che la proof2pres
37 generasse sempre prove con contesto vuoto *)
40 let res = "p" ^ string_of_int !seed in
45 let name_of = function
47 | Cic.Name b -> Some b;;
49 exception Not_a_proof;;
50 exception NotImplemented;;
51 exception NotApplicable;;
53 (* we do not care for positivity, here, that in any case is enforced by
54 well typing. Just a brutal search *)
63 | C.Implicit -> raise NotImplemented
64 | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
65 | C.Cast (te,ty) -> (occur uri te)
66 | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
67 | C.LetIn (_,s,t) -> (occur uri s) or (occur uri t)
72 else (occur uri a)) false l
73 | C.Const (_,_) -> false
74 | C.MutInd (uri1,_,_) -> if uri = uri1 then true else false
75 | C.MutConstruct (_,_,_,_) -> false
76 | C.MutCase _ -> false (* presuming too much?? *)
77 | C.Fix _ -> false (* presuming too much?? *)
78 | C.CoFix (_,_) -> false (* presuming too much?? *)
84 C.ARel (id,_,_,_) -> id
85 | C.AVar (id,_,_) -> id
86 | C.AMeta (id,_,_) -> id
87 | C.ASort (id,_) -> id
88 | C.AImplicit _ -> raise NotImplemented
89 | C.AProd (id,_,_,_) -> id
90 | C.ACast (id,_,_) -> id
91 | C.ALambda (id,_,_,_) -> id
92 | C.ALetIn (id,_,_,_) -> id
93 | C.AAppl (id,_) -> id
94 | C.AConst (id,_,_) -> id
95 | C.AMutInd (id,_,_,_) -> id
96 | C.AMutConstruct (id,_,_,_,_) -> id
97 | C.AMutCase (id,_,_,_,_,_) -> id
98 | C.AFix (id,_,_) -> id
99 | C.ACoFix (id,_,_) -> id
102 let test_for_lifting ~ids_to_inner_types =
103 let module C = Cic in
104 let module C2A = Cic2acic in
105 (* atomic terms are never lifted, according to my policy *)
107 C.ARel (id,_,_,_) -> false
108 | C.AVar (id,_,_) -> false
109 | C.AMeta (id,_,_) -> false
110 | C.ASort (id,_) -> false
111 | C.AImplicit _ -> raise NotImplemented
112 | C.AProd (id,_,_,_) -> false
113 | C.ACast (id,_,_) ->
115 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
117 with Not_found -> false)
118 | C.ALambda (id,_,_,_) ->
120 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
122 with Not_found -> false)
123 | C.ALetIn (id,_,_,_) ->
125 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
127 with Not_found -> false)
130 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
132 with Not_found -> false)
133 | C.AConst (id,_,_) ->
135 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
137 with Not_found -> false)
138 | C.AMutInd (id,_,_,_) -> false
139 | C.AMutConstruct (id,_,_,_,_) ->
141 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
143 with Not_found -> false)
145 | C.AMutCase (id,_,_,_,_,_) ->
147 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
149 with Not_found -> false)
152 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
154 with Not_found -> false)
155 | C.ACoFix (id,_,_) ->
157 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
159 with Not_found -> false)
162 let build_args seed l subproofs ~ids_to_inner_types ~ids_to_inner_sorts =
163 let module C = Cic in
164 let module K = Content in
165 let rec aux l subrpoofs =
169 if (test_for_lifting t ~ids_to_inner_types) then
170 (match subproofs with
175 { K.premise_id = gen_id seed;
176 K.premise_xref = p.K.proof_id;
177 K.premise_binder = p.K.proof_name;
180 in new_arg::(aux l1 tl))
184 C.ARel (idr,idref,n,b) ->
186 (try Hashtbl.find ids_to_inner_sorts idr
187 with Not_found -> "Type") in
190 { K.premise_id = gen_id seed;
191 K.premise_xref = idr;
192 K.premise_binder = Some b;
196 | _ -> (K.Term t)) in
197 hd::(aux l1 subproofs)
201 (* transform a proof p into a proof list, concatenating the last
202 conclude element to the apply_context list, in case context is
203 empty. Otherwise, it just returns [p] *)
206 let module K = Content in
207 if (p.K.proof_context = []) then
208 if p.K.proof_apply_context = [] then [p]
212 K.proof_id = gen_id seed;
213 K.proof_context = [];
214 K.proof_apply_context = []
216 p.K.proof_apply_context@[p1]
221 let rec serialize seed =
224 | p::tl -> (flat seed p)@(serialize seed tl);;
226 (* top_down = true if the term is a LAMBDA or a decl *)
227 let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
228 let module C2A = Cic2acic in
229 let module K = Content in
230 let exp = (try ((Hashtbl.find ids_to_inner_types id).C2A.annexpected)
231 with Not_found -> None)
236 if inner_proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
237 { K.proof_name = None ;
238 K.proof_id = gen_id seed;
239 K.proof_context = [] ;
240 K.proof_apply_context = [];
242 { K.conclude_id = gen_id seed;
243 K.conclude_aref = id;
244 K.conclude_method = "TD_Conversion";
245 K.conclude_args = [K.ArgProof inner_proof];
246 K.conclude_conclusion = Some expty
250 { K.proof_name = None ;
251 K.proof_id = gen_id seed;
252 K.proof_context = [] ;
253 K.proof_apply_context = [inner_proof];
255 { K.conclude_id = gen_id seed;
256 K.conclude_aref = id;
257 K.conclude_method = "BU_Conversion";
260 { K.premise_id = gen_id seed;
261 K.premise_xref = inner_proof.K.proof_id;
262 K.premise_binder = None;
266 K.conclude_conclusion = Some expty
271 let generate_exact seed t id name ~ids_to_inner_types =
272 let module C2A = Cic2acic in
273 let module K = Content in
274 { K.proof_name = name;
276 K.proof_context = [] ;
277 K.proof_apply_context = [];
279 { K.conclude_id = gen_id seed;
280 K.conclude_aref = id;
281 K.conclude_method = "Exact";
282 K.conclude_args = [K.Term t];
283 K.conclude_conclusion =
284 try Some (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
285 with Not_found -> None
290 let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_types =
291 let module C2A = Cic2acic in
292 let module C = Cic in
293 let module K = Content in
294 { K.proof_name = name;
296 K.proof_context = [] ;
297 K.proof_apply_context = [];
299 { K.conclude_id = gen_id seed;
300 K.conclude_aref = id;
301 K.conclude_method = "Intros+LetTac";
302 K.conclude_args = [K.ArgProof inner_proof];
303 K.conclude_conclusion =
305 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
307 (match inner_proof.K.proof_conclude.K.conclude_conclusion with
310 if is_intro then Some (C.AProd ("gen"^id,n,s,t))
311 else Some (C.ALetIn ("gen"^id,n,s,t)))
316 let build_decl_item seed id n s ~ids_to_inner_sorts =
317 let module K = Content in
319 let sort = Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id) in
320 if sort = "Prop" then
322 { K.dec_name = name_of n;
323 K.dec_id = gen_id seed;
324 K.dec_inductive = false;
330 { K.dec_name = name_of n;
331 K.dec_id = gen_id seed;
332 K.dec_inductive = false;
337 Not_found -> assert false
340 let rec build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
341 let module K = Content in
343 let sort = Hashtbl.find ids_to_inner_sorts id in
344 if sort = "Prop" then
345 `Proof (acic2content seed ~name:(name_of n) ~ids_to_inner_sorts ~ids_to_inner_types t)
348 { K.def_name = name_of n;
349 K.def_id = gen_id seed;
354 Not_found -> assert false
356 (* the following function must be called with an object of sort
357 Prop. For debugging purposes this is tested again, possibly raising an
358 Not_a_proof exception *)
360 and acic2content seed ?(name = None) ~ids_to_inner_sorts ~ids_to_inner_types t =
361 let rec aux ?(name = None) t =
362 let module C = Cic in
363 let module K = Content in
364 let module C2A = Cic2acic in
367 C.ARel (id,idref,n,b) as t ->
368 let sort = Hashtbl.find ids_to_inner_sorts id in
369 if sort = "Prop" then
370 generate_exact seed t id name ~ids_to_inner_types
371 else raise Not_a_proof
372 | C.AVar (id,uri,exp_named_subst) as t ->
373 let sort = Hashtbl.find ids_to_inner_sorts id in
374 if sort = "Prop" then
375 generate_exact seed t id name ~ids_to_inner_types
376 else raise Not_a_proof
377 | C.AMeta (id,n,l) as t ->
378 let sort = Hashtbl.find ids_to_inner_sorts id in
379 if sort = "Prop" then
380 generate_exact seed t id name ~ids_to_inner_types
381 else raise Not_a_proof
382 | C.ASort (id,s) -> raise Not_a_proof
383 | C.AImplicit _ -> raise NotImplemented
384 | C.AProd (_,_,_,_) -> raise Not_a_proof
385 | C.ACast (id,v,t) -> aux v
386 | C.ALambda (id,n,s,t) ->
387 let sort = Hashtbl.find ids_to_inner_sorts id in
388 if sort = "Prop" then
389 let proof = aux t ~name:None in
391 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
392 match proof.K.proof_conclude.K.conclude_args with
400 (build_decl_item seed id n s ids_to_inner_sorts)::
401 proof'.K.proof_context
404 generate_intros_let_tac seed id n s true proof'' name ~ids_to_inner_types
405 else raise Not_a_proof
406 | C.ALetIn (id,n,s,t) ->
407 let sort = Hashtbl.find ids_to_inner_sorts id in
408 if sort = "Prop" then
411 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
412 match proof.K.proof_conclude.K.conclude_args with
420 ((build_def_item seed id n s ids_to_inner_sorts
421 ids_to_inner_types):> Cic.annterm K.in_proof_context_element)
422 ::proof'.K.proof_context;
425 generate_intros_let_tac seed id n s false proof'' name ~ids_to_inner_types
426 else raise Not_a_proof
429 seed name id li ids_to_inner_types ids_to_inner_sorts
430 with NotApplicable ->
432 seed name id li ids_to_inner_types ids_to_inner_sorts
433 with NotApplicable ->
435 List.filter (test_for_lifting ~ids_to_inner_types) li in
437 match args_to_lift with
438 [_] -> List.map aux args_to_lift
439 | _ -> List.map (aux ~name:(Some "H")) args_to_lift in
440 let args = build_args seed li subproofs
441 ~ids_to_inner_types ~ids_to_inner_sorts in
442 { K.proof_name = name;
443 K.proof_id = gen_id seed;
444 K.proof_context = [];
445 K.proof_apply_context = serialize seed subproofs;
447 { K.conclude_id = gen_id seed;
448 K.conclude_aref = id;
449 K.conclude_method = "Apply";
450 K.conclude_args = args;
451 K.conclude_conclusion =
453 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
454 with Not_found -> None
457 | C.AConst (id,uri,exp_named_subst) as t ->
458 let sort = Hashtbl.find ids_to_inner_sorts id in
459 if sort = "Prop" then
460 generate_exact seed t id name ~ids_to_inner_types
461 else raise Not_a_proof
462 | C.AMutInd (id,uri,i,exp_named_subst) -> raise Not_a_proof
463 | C.AMutConstruct (id,uri,i,j,exp_named_subst) as t ->
464 let sort = Hashtbl.find ids_to_inner_sorts id in
465 if sort = "Prop" then
466 generate_exact seed t id name ~ids_to_inner_types
467 else raise Not_a_proof
468 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
469 let teid = get_id te in
470 let pp = List.map (function p -> (K.ArgProof (aux p))) patterns in
472 (try Some (Hashtbl.find ids_to_inner_types teid).C2A.annsynthesized
473 with Not_found -> None)
475 Some tety -> (* we must lift up the argument *)
477 { K.proof_name = Some "name";
478 K.proof_id = gen_id seed;
479 K.proof_context = [];
480 K.proof_apply_context = flat seed p;
482 { K.conclude_id = gen_id seed;
483 K.conclude_aref = id;
484 K.conclude_method = "Case";
485 K.conclude_args = (K.Term ty)::(K.Term te)::pp;
486 K.conclude_conclusion =
488 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
489 with Not_found -> None
493 { K.proof_name = name;
494 K.proof_id = gen_id seed;
495 K.proof_context = [];
496 K.proof_apply_context = [];
498 { K.conclude_id = gen_id seed;
499 K.conclude_aref = id;
500 K.conclude_method = "Case";
501 K.conclude_args = (K.Term ty)::(K.Term te)::pp;
502 K.conclude_conclusion =
504 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
505 with Not_found -> None
509 | C.AFix (id, no, [(id1,n,_,ty,bo)]) ->
510 let proof = (aux bo) in (* must be recursive !! *)
511 { K.proof_name = name;
512 K.proof_id = gen_id seed;
513 K.proof_context = [`Proof proof];
514 K.proof_apply_context = [];
516 { K.conclude_id = gen_id seed;
517 K.conclude_aref = id;
518 K.conclude_method = "Exact";
521 { K.premise_id = gen_id seed;
522 K.premise_xref = proof.K.proof_id;
523 K.premise_binder = proof.K.proof_name;
524 K.premise_n = Some 1;
527 K.conclude_conclusion =
529 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
530 with Not_found -> None
533 | C.AFix (id, no, funs) ->
535 List.map (function (id1,n,_,ty,bo) -> (`Proof (aux bo))) funs in
537 { K.joint_id = gen_id seed;
538 K.joint_kind = `Recursive;
539 K.joint_defs = proofs
542 { K.proof_name = name;
543 K.proof_id = gen_id seed;
544 K.proof_context = [`Joint jo];
545 K.proof_apply_context = [];
547 { K.conclude_id = gen_id seed;
548 K.conclude_aref = id;
549 K.conclude_method = "Exact";
552 { K.premise_id = gen_id seed;
553 K.premise_xref = jo.K.joint_id;
554 K.premise_binder = Some "tiralo fuori";
555 K.premise_n = Some no;
558 K.conclude_conclusion =
560 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
561 with Not_found -> None
564 | C.ACoFix (id,no,[(id1,n,ty,bo)]) ->
565 let proof = (aux bo) in (* must be recursive !! *)
566 { K.proof_name = name;
567 K.proof_id = gen_id seed;
568 K.proof_context = [`Proof proof];
569 K.proof_apply_context = [];
571 { K.conclude_id = gen_id seed;
572 K.conclude_aref = id;
573 K.conclude_method = "Exact";
576 { K.premise_id = gen_id seed;
577 K.premise_xref = proof.K.proof_id;
578 K.premise_binder = proof.K.proof_name;
579 K.premise_n = Some 1;
582 K.conclude_conclusion =
584 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
585 with Not_found -> None
588 | C.ACoFix (id,no,funs) ->
590 List.map (function (id1,n,ty,bo) -> (`Proof (aux bo))) funs in
592 { K.joint_id = gen_id seed;
593 K.joint_kind = `Recursive;
594 K.joint_defs = proofs
597 { K.proof_name = name;
598 K.proof_id = gen_id seed;
599 K.proof_context = [`Joint jo];
600 K.proof_apply_context = [];
602 { K.conclude_id = gen_id seed;
603 K.conclude_aref = id;
604 K.conclude_method = "Exact";
607 { K.premise_id = gen_id seed;
608 K.premise_xref = jo.K.joint_id;
609 K.premise_binder = Some "tiralo fuori";
610 K.premise_n = Some no;
613 K.conclude_conclusion =
615 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
616 with Not_found -> None
621 generate_conversion seed false id t1 ~ids_to_inner_types
624 and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
625 let aux ?(name = None) = acic2content seed ~name:None ~ids_to_inner_types ~ids_to_inner_sorts in
626 let module C2A = Cic2acic in
627 let module K = Content in
628 let module C = Cic in
630 C.AConst (idc,uri,exp_named_subst)::args ->
631 let uri_str = UriManager.string_of_uri uri in
632 let suffix = Str.regexp_string "_ind.con" in
633 let len = String.length uri_str in
634 let n = (try (Str.search_backward suffix uri_str len)
635 with Not_found -> -1) in
636 if n<0 then raise NotApplicable
638 let prefix = String.sub uri_str 0 n in
639 let ind_str = (prefix ^ ".ind") in
640 let ind_uri = UriManager.uri_of_string ind_str in
641 let inductive_types,noparams =
642 (match CicEnvironment.get_obj ind_uri with
643 Cic.Constant _ -> assert false
644 | Cic.Variable _ -> assert false
645 | Cic.CurrentProof _ -> assert false
646 | Cic.InductiveDefinition (l,_,n) -> (l,n)
649 if n = 0 then ([],l) else
650 let p,a = split (n-1) (List.tl l) in
651 ((List.hd l::p),a) in
652 let params_and_IP,tail_args = split (noparams+1) args in
654 (match inductive_types with
656 | _ -> raise NotApplicable) (* don't care for mutual ind *) in
658 let rec clean_up n t =
661 (label,Cic.Prod (_,_,t)) -> clean_up (n-1) (label,t)
662 | _ -> assert false) in
663 List.map (clean_up noparams) constructors in
664 let no_constructors= List.length constructors in
665 let args_for_cases, other_args =
666 split no_constructors tail_args in
668 List.filter (test_for_lifting ~ids_to_inner_types) other_args in
670 match args_to_lift with
671 [_] -> List.map aux args_to_lift
672 | _ -> List.map (aux ~name:(Some "H")) args_to_lift in
673 prerr_endline "****** end subproofs *******"; flush stderr;
674 let other_method_args =
675 build_args seed other_args subproofs
676 ~ids_to_inner_types ~ids_to_inner_sorts in
678 let rparams,inductive_arg =
683 | a::tl -> let (p,ia) = aux tl in (a::p,ia) in
684 aux other_method_args in
686 prerr_endline "****** end other *******"; flush stderr;
688 let rec build_method_args =
690 [],_-> [] (* extra args are ignored ???? *)
691 | (name,ty)::tlc,arg::tla ->
692 let idarg = get_id arg in
694 (try (Hashtbl.find ids_to_inner_sorts idarg)
695 with Not_found -> "Type") in
697 if sortarg = "Prop" then
701 Cic.Prod (_,s,t),Cic.ALambda(idl,n,s1,t1) ->
704 seed idl n s1 ~ids_to_inner_sorts in
705 if (occur ind_uri s) then
706 ( prerr_endline ("inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr;
708 Cic.ALambda(id2,n2,s2,t2) ->
711 { K.dec_name = name_of n2;
712 K.dec_id = gen_id seed;
713 K.dec_inductive = true;
717 let (context,body) = bc (t,t2) in
718 (ce::inductive_hyp::context,body)
721 ( prerr_endline ("no inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr;
722 let (context,body) = bc (t,t1) in
724 | _ , t -> ([],aux t ~name:None) in
728 K.proof_name = Some name;
729 K.proof_context = co;
732 hdarg::(build_method_args (tlc,tla))
733 | _ -> assert false in
734 build_method_args (constructors1,args_for_cases) in
735 { K.proof_name = None;
736 K.proof_id = gen_id seed;
737 K.proof_context = [];
738 K.proof_apply_context = subproofs;
740 { K.conclude_id = gen_id seed;
741 K.conclude_aref = id;
742 K.conclude_method = "ByInduction";
744 K.Aux no_constructors
745 ::K.Term (C.AAppl id ((C.AConst(idc,uri,exp_named_subst))::params_and_IP))
746 ::method_args@other_method_args;
747 K.conclude_conclusion =
749 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
750 with Not_found -> None
753 | _ -> raise NotApplicable
755 and rewrite seed name id li ids_to_inner_types ids_to_inner_sorts =
756 let aux ?(name = None) = acic2content seed ~name:None ~ids_to_inner_types ~ids_to_inner_sorts in
757 let module C2A = Cic2acic in
758 let module K = Content in
759 let module C = Cic in
761 C.AConst (sid,uri,exp_named_subst)::args ->
762 let uri_str = UriManager.string_of_uri uri in
763 if uri_str = "cic:/Coq/Init/Logic/eq_ind.con" or
764 uri_str = "cic:/Coq/Init/Logic/eq_ind_r.con" then
765 let subproof = aux (List.nth args 3) in
767 let rec ma_aux n = function
773 { K.premise_id = gen_id seed;
774 K.premise_xref = subproof.K.proof_id;
775 K.premise_binder = None;
779 let aid = get_id a in
780 let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
781 with Not_found -> "Type") in
782 if asort = "Prop" then
785 hd::(ma_aux (n-1) tl) in
787 { K.proof_name = None;
788 K.proof_id = gen_id seed;
789 K.proof_context = [];
790 K.proof_apply_context = [subproof];
792 { K.conclude_id = gen_id seed;
793 K.conclude_aref = id;
794 K.conclude_method = "Rewrite";
796 K.Term (C.AConst (sid,uri,exp_named_subst))::method_args;
797 K.conclude_conclusion =
799 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
800 with Not_found -> None
803 else raise NotApplicable
804 | _ -> raise NotApplicable
808 seed ~ids_to_inner_sorts ~ids_to_inner_types (id,n,context,ty)
810 let module K = Content in
814 (id,None) as item -> item
815 | (id,Some (name,Cic.ADecl t)) ->
818 (* We should call build_decl_item, but we have not computed *)
819 (* the inner-types ==> we always produce a declaration *)
821 { K.dec_name = name_of name;
822 K.dec_id = gen_id seed;
823 K.dec_inductive = false;
824 K.dec_aref = get_id t;
827 | (id,Some (name,Cic.ADef t)) ->
830 (* We should call build_def_item, but we have not computed *)
831 (* the inner-types ==> we always produce a declaration *)
833 { K.def_name = name_of name;
834 K.def_id = gen_id seed;
835 K.def_aref = get_id t;
843 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
844 let module C = Cic in
845 let module K = Content in
846 let module C2A = Cic2acic in
849 C.ACurrentProof (_,_,n,conjectures,bo,ty,params) ->
850 (gen_id seed, params,
853 (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
856 build_def_item seed (get_id bo) (C.Name n) bo
857 ~ids_to_inner_sorts ~ids_to_inner_types))
858 | C.AConstant (_,_,n,Some bo,ty,params) ->
859 (gen_id seed, params, None,
861 build_def_item seed (get_id bo) (C.Name n) bo
862 ~ids_to_inner_sorts ~ids_to_inner_types))
863 | C.AConstant (id,_,n,None,ty,params) ->
864 (gen_id seed, params, None,
866 build_decl_item seed id (C.Name n) ty
867 ~ids_to_inner_sorts))
868 | C.AVariable (_,n,Some bo,ty,params) ->
869 (gen_id seed, params, None,
871 build_def_item seed (get_id bo) (C.Name n) bo
872 ~ids_to_inner_sorts ~ids_to_inner_types))
873 | C.AVariable (id,n,None,ty,params) ->
874 (gen_id seed, params, None,
876 build_decl_item seed id (C.Name n) ty
877 ~ids_to_inner_sorts))
878 | C.AInductiveDefinition (id,l,params,nparams) ->
879 (gen_id seed, params, None,
881 { K.joint_id = gen_id seed;
882 K.joint_kind = `Inductive nparams;
883 K.joint_defs = List.map (build_inductive seed) l
887 build_inductive seed =
888 let module K = Content in
891 { K.inductive_id = gen_id seed;
892 K.inductive_kind = b;
893 K.inductive_type = ty;
894 K.inductive_constructors = build_constructors seed l
898 build_constructors seed l =
899 let module K = Content in
902 { K.dec_name = Some n;
903 K.dec_id = gen_id seed;
904 K.dec_inductive = false;
911 and 'term cinductiveType =
912 id * string * bool * 'term * (* typename, inductive, arity *)
913 'term cconstructor list (* constructors *)
915 and 'term cconstructor =