]> matita.cs.unibo.it Git - helm.git/blob - matita/components/ng_cic_content/interpretations.ml
Use of standard OCaml syntax
[helm.git] / matita / components / ng_cic_content / interpretations.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 module Ast = NotationPt
31
32
33 let debug = false
34 let debug_print s = if debug then prerr_endline (Lazy.force s) else ()
35
36 type id = string
37 let hide_coercions = ref true;;
38
39 type cic_id = string
40
41 (*
42 type term_info =
43   { sort: (cic_id, Ast.sort_kind) Hashtbl.t;
44     uri: (cic_id, NReference.reference) Hashtbl.t;
45   }
46 *)
47
48 module IntMap = Map.Make(struct type t = int let compare = compare end);;
49 module StringMap = Map.Make(String);;
50
51 type db = {
52   counter: int;
53   pattern32_matrix: (bool * NotationPt.cic_appl_pattern * int) list;
54   level2_patterns32:
55    (string * string * NotationPt.argument_pattern list *
56      NotationPt.cic_appl_pattern) IntMap.t;
57   interpretations: int list StringMap.t; (* symb -> id list *)
58   compiled32:
59    (NCic.term -> ((string * NCic.term) list * NCic.term list * int) option)
60     Lazy.t
61 }
62
63 let initial_db status = {
64    counter = -1; 
65    pattern32_matrix = [];
66    level2_patterns32 = IntMap.empty;
67    interpretations = StringMap.empty;
68    compiled32 = lazy (Ncic2astMatcher.Matcher32.compiler status [])
69 }
70
71 class type g_status =
72   object
73     inherit NCicCoercion.g_status
74     method interp_db: db
75   end
76  
77 class virtual status =
78  object(self)
79    inherit NCicCoercion.status
80    val mutable interp_db = None (* mutable only to initialize it :-( *)
81    method interp_db = match interp_db with None -> assert false | Some x -> x
82    method set_interp_db v = {< interp_db = Some v >}
83    method set_interp_status
84     : 'status. (#g_status as 'status) -> 'self
85     = fun o -> {< interp_db = Some o#interp_db >}#set_coercion_status o
86    initializer
87     interp_db <- Some (initial_db self)
88  end
89
90 let idref register_ref =
91  let id = ref 0 in
92   fun ?reference t ->
93    incr id;
94    let id = "i" ^ string_of_int !id in
95     (match reference with None -> () | Some r -> register_ref id r);
96     Ast.AttributedTerm (`IdRef id, t)
97 ;;
98
99 let level_of_uri u = 
100   let name = NUri.name_of_uri u in
101   assert(String.length name > String.length "Type");
102   String.sub name 4 (String.length name - 4)
103 ;;
104
105 let find_level2_patterns32 status pid =
106  IntMap.find pid status#interp_db.level2_patterns32
107
108 let add_idrefs =
109   List.fold_right (fun idref t -> Ast.AttributedTerm (`IdRef idref, t))
110
111 let instantiate32 idrefs env symbol args =
112   let instantiate_arg = function
113     | Ast.IdentArg (n, name) ->
114         let t = 
115           try List.assoc name env 
116           with Not_found -> prerr_endline ("name not found in env: "^name);
117                             assert false
118         in
119         let rec count_lambda = function
120           | Ast.AttributedTerm (_, t) -> count_lambda t
121           | Ast.Binder (`Lambda, _, body) -> 1 + count_lambda body
122           | _ -> 0
123         in
124         let rec add_lambda t n =
125           if n > 0 then
126             let name = NotationUtil.fresh_name () in
127             Ast.Binder (`Lambda, (Ast.Ident (name, None), None),
128               Ast.Appl [add_lambda t (n - 1); Ast.Ident (name, None)])
129           else
130             t
131         in
132         add_lambda t (n - count_lambda t)
133   in
134   let head =
135     let symbol = Ast.Symbol (symbol, 0) in
136     add_idrefs idrefs symbol
137   in
138   if args = [] then head
139   else Ast.Appl (head :: List.map instantiate_arg args)
140
141 let fresh_id status =
142   let counter = status#interp_db.counter+1 in
143    status#set_interp_db ({ status#interp_db with counter = counter  }), counter
144
145 let load_patterns32 status t =
146  let t =
147   HExtlib.filter_map (function (true, ap, id) -> Some (ap, id) | _ -> None) t
148  in
149   status#set_interp_db
150    {status#interp_db with
151      compiled32 = lazy (Ncic2astMatcher.Matcher32.compiler status t) }
152 ;;
153
154 let add_interpretation status dsc (symbol, args) appl_pattern =
155   let status,id = fresh_id status in
156   let ids =
157    try
158     id::StringMap.find symbol status#interp_db.interpretations
159    with Not_found -> [id] in
160   let status =
161    status#set_interp_db { status#interp_db with
162     level2_patterns32 =
163       IntMap.add id (dsc, symbol, args, appl_pattern)
164        status#interp_db.level2_patterns32;
165     pattern32_matrix = (true,appl_pattern,id)::status#interp_db.pattern32_matrix;
166     interpretations = StringMap.add symbol ids status#interp_db.interpretations
167    }
168   in
169    load_patterns32 status status#interp_db.pattern32_matrix
170
171 let toggle_active_interpretations status b =
172   status#set_interp_db { status#interp_db with
173    pattern32_matrix =
174      List.map (fun (_,ap,id) -> b,ap,id) status#interp_db.pattern32_matrix }
175
176 exception Interpretation_not_found
177
178 let lookup_interpretations status ?(sorted=true) symbol =
179   try
180     let raw = 
181       List.map (
182         fun id ->
183           let (dsc, _, args, appl_pattern) =
184             try IntMap.find id status#interp_db.level2_patterns32
185             with Not_found -> assert false 
186           in
187           dsc, args, appl_pattern
188       ) (StringMap.find symbol status#interp_db.interpretations)
189     in
190     if sorted then HExtlib.list_uniq (List.sort Stdlib.compare raw)
191               else raw
192   with Not_found -> raise Interpretation_not_found
193
194 let instantiate_appl_pattern 
195   ~mk_appl ~mk_implicit ~term_of_nref env appl_pattern 
196 =
197   let lookup name =
198     try List.assoc name env
199     with Not_found ->
200       prerr_endline (sprintf "Name %s not found" name);
201       assert false
202   in
203   let rec aux = function
204     | Ast.NRefPattern nref -> term_of_nref nref
205     | Ast.ImplicitPattern -> mk_implicit false
206     | Ast.VarPattern name -> lookup name
207     | Ast.ApplPattern terms -> mk_appl (List.map aux terms)
208   in
209   aux appl_pattern
210
211 let destroy_nat =
212   let is_nat_URI = NUri.eq (NUri.uri_of_string
213   "cic:/matita/arithmetics/nat/nat.ind") in
214   let is_zero = function
215     | NCic.Const (NReference.Ref (uri, NReference.Con (0, 1, 0))) when
216        is_nat_URI uri -> true
217     | _ -> false
218   in
219   let is_succ = function
220     | NCic.Const (NReference.Ref (uri, NReference.Con (0, 2, 0))) when
221        is_nat_URI uri -> true
222     | _ -> false
223   in
224   let rec aux acc = function
225     | NCic.Appl [he ; tl] when is_succ he -> aux (acc + 1) tl
226     | t when is_zero t -> Some acc
227     | _ -> None
228   in
229    aux 0
230
231 (* CODICE c&p da NCicPp *)
232 let nast_of_cic0 status
233  ~(idref:
234     ?reference:NReference.reference -> NotationPt.term -> NotationPt.term)
235  ~output_type ~metasenv ~subst k ~context =
236   function
237     | NCic.Rel n ->
238        (try 
239          let name,_ = List.nth context (n-1) in
240          let name = if name = "_" then "__"^string_of_int n else name in
241           idref (Ast.Ident (name,None))
242         with Failure "nth" | Invalid_argument "List.nth" -> 
243          idref (Ast.Ident ("-" ^ string_of_int (n - List.length context),None)))
244     | NCic.Const r -> idref ~reference:r (Ast.Ident (NCicPp.r2s status true r, None))
245     | NCic.Meta (n,lc) when List.mem_assoc n subst -> 
246         let _,_,t,_ = List.assoc n subst in
247          k ~context (NCicSubstitution.subst_meta status lc t)
248     | NCic.Meta (n,(s,l)) ->
249        (* CSC: qua non dovremmo espandere *)
250        let l = NCicUtils.expand_local_context l in
251         idref (Ast.Meta
252          (n, List.map (fun x -> Some (k ~context (NCicSubstitution.lift status s x))) l))
253     | NCic.Sort NCic.Prop -> idref (Ast.Sort `Prop)
254     | NCic.Sort NCic.Type [] -> idref (Ast.Sort `Set)
255     | NCic.Sort NCic.Type ((`Type,u)::_) -> 
256               idref(Ast.Sort (`NType (level_of_uri u)))
257     | NCic.Sort NCic.Type ((`CProp,u)::_) -> 
258               idref(Ast.Sort (`NCProp (level_of_uri u)))
259     | NCic.Sort NCic.Type ((`Succ,u)::_) -> 
260               idref(Ast.Sort (`NType (level_of_uri u ^ "+1")))
261     | NCic.Implicit `Hole -> idref (Ast.UserInput)
262     | NCic.Implicit `Vector -> idref (Ast.Implicit `Vector)
263     | NCic.Implicit _ -> idref (Ast.Implicit `JustOne)
264     | NCic.Prod (n,s,t) ->
265         let n = if n.[0] = '_' then "_" else n in
266         let binder_kind = `Forall in
267          idref (Ast.Binder (binder_kind, (Ast.Ident (n,None), Some (k ~context s)),
268           k ~context:((n,NCic.Decl s)::context) t))
269     | NCic.Lambda (n,s,t) ->
270         idref (Ast.Binder (`Lambda,(Ast.Ident (n,None), Some (k ~context s)),
271          k ~context:((n,NCic.Decl s)::context) t))
272     | NCic.LetIn (_n,s,ty,NCic.Rel 1) ->
273         idref (Ast.Cast (k ~context ty, k ~context s))
274     | NCic.LetIn (n,s,ty,t) ->
275         idref (Ast.LetIn ((Ast.Ident (n,None), Some (k ~context s)), k ~context
276           ty, k ~context:((n,NCic.Decl s)::context) t))
277     | NCic.Appl (NCic.Meta (n,lc) :: args) when List.mem_assoc n subst -> 
278        let _,_,t,_ = List.assoc n subst in
279        let hd = NCicSubstitution.subst_meta status lc t in
280         k ~context
281          (NCicReduction.head_beta_reduce status ~upto:(List.length args)
282            (match hd with
283            | NCic.Appl l -> NCic.Appl (l@args)
284            | _ -> NCic.Appl (hd :: args)))
285     | NCic.Appl args as t ->
286        (match destroy_nat t with
287          | Some n -> idref (Ast.Num (string_of_int n, -1))
288          | None ->
289             let args =
290              if not !hide_coercions then args
291              else
292               match
293                NCicCoercion.match_coercion status ~metasenv ~context ~subst t
294               with
295                | None -> args
296                | Some (_,sats,cpos) -> 
297 (* CSC: sats e' il numero di pi, ma non so cosa farmene! voglio il numero di
298    argomenti da saltare, come prima! *)
299                   if cpos < List.length args - 1 then
300                    List.nth args (cpos + 1) ::
301                     try snd (HExtlib.split_nth (cpos+sats+2) args)
302                     with Failure _->[]
303                   else
304                    args
305             in
306              (match args with
307                  [arg] -> idref (k ~context arg)
308                | _ -> idref (Ast.Appl (List.map (k ~context) args))))
309     | NCic.Match (NReference.Ref (uri,_) as r,outty,te,patterns) ->
310        (try
311         let name = NUri.name_of_uri uri in
312 (* CSC
313         let uri_str = UriManager.string_of_uri uri in
314         let puri_str = sprintf "%s#xpointer(1/%d)" uri_str (typeno+1) in
315         let ctor_puri j =
316           UriManager.uri_of_string
317             (sprintf "%s#xpointer(1/%d/%d)" uri_str (typeno+1) j)
318         in
319 *)
320         let case_indty =
321          name, None(*CSC Some (UriManager.uri_of_string puri_str)*) in
322         let constructors, leftno =
323          let _,leftno,tys,_,n = NCicEnvironment.get_checked_indtys status r in
324          let _,_,_,cl  = List.nth tys n in
325           cl,leftno
326         in
327         let rec eat_branch n ctx ty pat =
328           match (ty, pat) with
329           | NCic.Prod (_name, _s, t), _ when n > 0 ->
330              eat_branch (pred n) ctx t pat 
331           | NCic.Prod (_, _, t), NCic.Lambda (name, s, t') ->
332               let cv, rhs = eat_branch 0 ((name,NCic.Decl s)::ctx) t t' in
333               (Ast.Ident (name,None), Some (k ~context:ctx s)) :: cv, rhs
334           | _, _ -> [], k ~context:ctx pat
335         in
336         let j = ref 0 in
337         let patterns =
338           try
339             List.map2
340               (fun (_, name, ty) pat ->
341                 incr j;
342                 let name,(capture_variables,rhs) =
343                  match output_type with
344                     `Term -> name, eat_branch leftno context ty pat
345                   | `Pattern -> "_", ([], k ~context pat)
346                 in
347                  Ast.Pattern (name, None(*CSC Some (ctor_puri !j)*), capture_variables), rhs
348               ) constructors patterns
349           with Invalid_argument _ -> assert false
350         in
351         let indty =
352          match output_type with
353             `Pattern -> None
354           | `Term -> Some case_indty
355         in
356          idref (Ast.Case (k ~context te, indty, Some (k ~context outty), patterns))
357      with
358       NCicEnvironment.ObjectNotFound msg ->
359        idref (Ast.Case(k ~context te,Some ("NOT_FOUND: " ^ Lazy.force msg,None),
360        Some (k ~context outty),
361        (List.map (fun t -> Ast.Pattern ("????", None, []), k ~context t)
362          patterns))))
363 ;;
364
365 let rec nast_of_cic1 status ~idref ~output_type ~metasenv ~subst ~context term =
366   match Lazy.force status#interp_db.compiled32 term with
367   | None ->
368      nast_of_cic0 status ~idref ~output_type ~metasenv ~subst
369       (nast_of_cic1 status ~idref ~output_type ~metasenv ~subst) ~context term 
370   | Some (env, ctors, pid) -> 
371       let idrefs =
372        List.map
373         (fun term ->
374           let attrterm =
375            idref
376             ~reference:
377               (match term with NCic.Const nref -> nref | _ -> assert false)
378            (NotationPt.Ident ("dummy",None))
379           in
380            match attrterm with
381               Ast.AttributedTerm (`IdRef id, _) -> id
382             | _ -> assert false
383         ) ctors
384       in
385       let env =
386        List.map
387         (fun (name, term) ->
388           name,
389            nast_of_cic1 status ~idref ~output_type ~subst ~metasenv ~context
390             term
391         ) env
392       in
393       let _, symbol, args, _ =
394         try
395          find_level2_patterns32 status pid
396         with Not_found -> assert false
397       in
398       let ast = instantiate32 idrefs env symbol args in
399       idref ast (*Ast.AttributedTerm (`IdRef (idref term), ast)*)
400 ;;
401
402 let nmap_context0 status ~idref ~metasenv ~subst context =
403  let module K = Content in
404  let nast_of_cic =
405   nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst
406  in
407  fst (
408   List.fold_right
409    (fun item (res,context) ->
410      match item with
411       | name,NCic.Decl t ->
412          Some
413           (* We should call build_decl_item, but we have not computed *)
414           (* the inner-types ==> we always produce a declaration      *)
415           (`Declaration
416             { K.dec_name = (Some name);
417               K.dec_id = "-1"; 
418               K.dec_inductive = false;
419               K.dec_aref = "-1";
420               K.dec_type = nast_of_cic ~context t
421             })::res,item::context
422       | name,NCic.Def (t,ty) ->
423          Some
424           (* We should call build_def_item, but we have not computed *)
425           (* the inner-types ==> we always produce a declaration     *)
426           (`Definition
427              { K.def_name = (Some name);
428                K.def_id = "-1"; 
429                K.def_aref = "-1";
430                K.def_term = nast_of_cic ~context t;
431                K.def_type = nast_of_cic ~context ty
432              })::res,item::context
433    ) context ([],[]))
434 ;;
435
436 let nmap_sequent0 status ~idref ~metasenv ~subst (i,(_n,context,ty)) =
437  let nast_of_cic =
438   nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst in
439  let context' = nmap_context0 status ~idref ~metasenv ~subst context in
440   ("-1",i,context',nast_of_cic ~context ty)
441 ;;
442
443 let object_prefix = "obj:";;
444 let declaration_prefix = "decl:";;
445 let definition_prefix = "def:";;
446 let inductive_prefix = "ind:";;
447 let joint_prefix = "joint:";;
448
449 let get_id =
450  function
451     Ast.AttributedTerm (`IdRef id, _) -> id
452   | _ -> assert false
453 ;;
454
455 let gen_id prefix seed =
456  let res = prefix ^ string_of_int !seed in
457   incr seed ;
458   res
459 ;;
460
461 let build_def_item seed _context _metasenv id n t ty =
462  let module K = Content in
463 (*
464   try
465    let sort = Hashtbl.find ids_to_inner_sorts id in
466    if sort = `Prop then
467        (let p = 
468         (acic2content seed context metasenv ?name:(name_of n) ~ids_to_inner_sorts  ~ids_to_inner_types t)
469        in 
470         `Proof p;)
471    else 
472 *)
473       `Definition
474         { K.def_name = Some n;
475           K.def_id = gen_id definition_prefix seed; 
476           K.def_aref = id;
477           K.def_term = t;
478           K.def_type = ty
479         }
480 (*
481   with
482    Not_found -> assert false
483 *)
484
485 let build_decl_item seed id n s =
486  let module K = Content in
487 (*
488  let sort =
489    try
490     Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
491    with Not_found -> None
492  in
493  match sort with
494  | Some `Prop ->
495     `Hypothesis
496       { K.dec_name = name_of n;
497         K.dec_id = gen_id declaration_prefix seed; 
498         K.dec_inductive = false;
499         K.dec_aref = id;
500         K.dec_type = s
501       }
502  | _ ->
503 *)
504     `Declaration
505       { K.dec_name = Some n;
506         K.dec_id = gen_id declaration_prefix seed; 
507         K.dec_inductive = false;
508         K.dec_aref = id;
509         K.dec_type = s
510       }
511 ;;
512
513 let nmap_cobj0 status ~idref (uri,_,metasenv,subst,kind) =
514   let module K = Content in
515   let nast_of_cic =
516    nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst in
517   let seed = ref 0 in
518   let conjectures =
519    match metasenv with
520       [] -> None
521     | _ -> (*Some (List.map (map_conjectures seed) metasenv)*)
522       (*CSC: used to be the previous line, that uses seed *)
523       Some (List.map (nmap_sequent0 status ~idref ~metasenv ~subst) metasenv)
524   in
525 let  build_constructors seed l =
526       List.map 
527        (fun (_,n,ty) ->
528            let ty = nast_of_cic ~context:[] ty in
529            { K.dec_name = Some n;
530              K.dec_id = gen_id declaration_prefix seed;
531              K.dec_inductive = false;
532              K.dec_aref = "";
533              K.dec_type = ty
534            }) l
535 in
536 let build_inductive b seed = 
537       fun (_,n,ty,cl) ->
538         let ty = nast_of_cic ~context:[] ty in
539         `Inductive
540           { K.inductive_id = gen_id inductive_prefix seed;
541             K.inductive_name = n;
542             K.inductive_kind = b;
543             K.inductive_type = ty;
544             K.inductive_constructors = build_constructors seed cl
545            }
546 in
547 let build_fixpoint _b seed = 
548       fun (_,n,_,ty,t) ->
549         let t = nast_of_cic ~context:[] t in
550         let ty = nast_of_cic ~context:[] ty in
551         `Definition
552           { K.def_id = gen_id inductive_prefix seed;
553             K.def_name = Some n;
554             K.def_aref = "";
555             K.def_type = ty;
556             K.def_term = t;
557            }
558 in
559  match kind with
560   | NCic.Fixpoint (is_rec, ifl, _) -> 
561        (gen_id object_prefix seed, conjectures,
562           `Joint
563             { K.joint_id = gen_id joint_prefix seed;
564               K.joint_kind = 
565                  if is_rec then 
566                       `Recursive (List.map (fun (_,_,i,_,_) -> i) ifl)
567                  else `CoRecursive;
568               K.joint_defs = List.map (build_fixpoint is_rec seed) ifl
569             }) 
570   | NCic.Inductive (is_ind, lno, itl, _) ->
571        (gen_id object_prefix seed, conjectures,
572           `Joint
573             { K.joint_id = gen_id joint_prefix seed;
574               K.joint_kind = 
575                  if is_ind then `Inductive lno else `CoInductive lno;
576               K.joint_defs = List.map (build_inductive is_ind seed) itl
577             }) 
578   | NCic.Constant (_,_,Some bo,ty,_) ->
579      let ty = nast_of_cic ~context:[] ty in
580      let bo = nast_of_cic ~context:[] bo in
581       (gen_id object_prefix seed, conjectures,
582         `Def (K.Const,ty,
583           build_def_item seed [] [] (get_id bo) (NUri.name_of_uri uri) bo ty))
584   | NCic.Constant (_,_,None,ty,_) ->
585      let ty = nast_of_cic ~context:[] ty in
586        (gen_id object_prefix seed, conjectures,
587          `Decl (K.Const,
588            (*CSC: ??? get_id ty here used to be the id of the axiom! *)
589            build_decl_item seed (get_id ty) (NUri.name_of_uri uri) ty))
590 ;;
591
592 let with_idrefs foo status obj =
593  let ids_to_refs = Hashtbl.create 211 in
594  let register_ref = Hashtbl.add ids_to_refs in
595   foo status ~idref:(idref register_ref) obj, ids_to_refs
596 ;;
597
598 let nmap_cobj status = with_idrefs nmap_cobj0 status
599
600 let nmap_sequent status ~metasenv ~subst =
601  with_idrefs (nmap_sequent0 ~metasenv ~subst) status
602
603 let nmap_term status ~metasenv ~subst ~context =
604  with_idrefs (nast_of_cic1 ~output_type:`Term ~metasenv ~subst ~context) status
605
606 let nmap_context status ~metasenv ~subst =
607  with_idrefs (nmap_context0 ~metasenv ~subst) status
608
609 (* FG ***********************************************************************)
610
611 let nmap_obj0 status ~idref (_, _, metasenv, subst, kind) =
612    let module N = NotationPt in
613    let nast_of_cic =
614       nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst
615    in
616    let rec mk_captures lno k c u = match lno, u with
617       | 0, _                                -> k, c
618       | _, NCic.Prod (n, w, u) when lno > 0 ->
619          let cap = nast_of_cic ~context:c w, None in
620          let hyp = n, NCic.Decl w in
621          mk_captures (pred lno) (cap :: k) (hyp :: c) u
622       | _                                 -> assert false
623    in
624    let build_captures lno = function
625       | []                -> [], []
626       | (_, _, u, _) :: _ -> mk_captures lno [] [] u
627    in
628    let rec eat_prods prods lno t = match prods, lno, t with
629       | _, 0, _                                      -> t
630       | true, _, NCic.Prod (_, _, t) when lno > 0    -> eat_prods prods (pred lno) t
631       | false, _, NCic.Lambda (_, _, t) when lno > 0 -> eat_prods prods (pred lno) t
632       | _                                            -> assert false
633    in
634    let build_constractor lno context (_, n, bo) =
635       let bo = nast_of_cic ~context (eat_prods false lno bo) in      
636       n, bo
637    in
638    let build_inductive is_ind lno context (_, n, ty, cl) =
639       let ty = nast_of_cic ~context (eat_prods true lno ty) in
640       n, is_ind, ty, List.map (build_constractor lno context) cl
641    in
642    match kind with
643       | NCic.Constant (_, n, xbo, ty, attrs) ->
644          let ty = nast_of_cic ~context:[] ty in
645          let xbo = match xbo with 
646             | Some bo -> Some (nast_of_cic ~context:[] bo)
647             | None    -> None
648          in
649          N.Theorem (n, ty, xbo, attrs)
650       | NCic.Inductive (is_ind, lno, itl, (src, `Regular)) ->      
651          let captures, context = build_captures lno itl in
652          N.Inductive (captures, List.map (build_inductive is_ind lno context) itl, src)
653       | _ -> assert false  (* NCic.Fixpoint (is_rec, ifl, _) -> *)
654
655 let nmap_obj status = with_idrefs nmap_obj0 status