+
+let fake_annotate c =
+ let get_binder c m =
+ try match List.nth c (pred m) with
+ | Some (C.Name s, _) -> s
+ | _ -> assert false
+ with
+ | Invalid_argument _ -> assert false
+ in
+ let mk_decl n v = Some (n, C.Decl v) in
+ let mk_def n v = Some (n, C.Def (v, None)) in
+ let mk_fix (name, _, _, bo) = mk_def (C.Name name) bo in
+ let mk_cofix (name, _, bo) = mk_def (C.Name name) bo in
+ let rec ann_xns c (uri, t) = uri, ann_term c t
+ and ann_ms c = function
+ | None -> None
+ | Some t -> Some (ann_term c t)
+ and ann_fix newc c (name, i, ty, bo) =
+ "", name, i, ann_term c ty, ann_term (List.rev_append newc c) bo
+ and ann_cofix newc c (name, ty, bo) =
+ "", name, ann_term c ty, ann_term (List.rev_append newc c) bo
+ and ann_term c = function
+ | C.Sort sort -> C.ASort ("", sort)
+ | C.Implicit ann -> C.AImplicit ("", ann)
+ | C.Rel m -> C.ARel ("", "", m, get_binder c m)
+ | C.Const (uri, xnss) -> C.AConst ("", uri, List.map (ann_xns c) xnss)
+ | C.Var (uri, xnss) -> C.AVar ("", uri, List.map (ann_xns c) xnss)
+ | C.MutInd (uri, tyno, xnss) -> C.AMutInd ("", uri, tyno, List.map (ann_xns c) xnss)
+ | C.MutConstruct (uri, tyno, consno, xnss) -> C.AMutConstruct ("", uri,tyno,consno, List.map (ann_xns c) xnss)
+ | C.Meta (i, mss) -> C.AMeta("", i, List.map (ann_ms c) mss)
+ | C.Appl ts -> C.AAppl ("", List.map (ann_term c) ts)
+ | C.Cast (te, ty) -> C.ACast ("", ann_term c te, ann_term c ty)
+ | C.MutCase (sp, i, outty, t, pl) -> C.AMutCase ("", sp, i, ann_term c outty, ann_term c t, List.map (ann_term c) pl)
+ | C.Prod (n, s, t) -> C.AProd ("", n, ann_term c s, ann_term (mk_decl n s :: c) t)
+ | C.Lambda (n, s, t) -> C.ALambda ("", n, ann_term c s, ann_term (mk_decl n s :: c) t)
+ | C.LetIn (n, s, t) -> C.ALetIn ("", n, ann_term c s, ann_term (mk_def n s :: c) t)
+ | C.Fix (i, fl) -> C.AFix ("", i, List.map (ann_fix (List.rev_map mk_fix fl) c) fl)
+ | C.CoFix (i, fl) -> C.ACoFix ("", i, List.map (ann_cofix (List.rev_map mk_cofix fl) c) fl)
+ in
+ ann_term c
+
+let rec add_abst n t =
+ if n <= 0 then t else
+ let t = C.ALambda ("", C.Anonymous, C.AImplicit ("", None), lift 0 1 t) in
+ add_abst (pred n) t
+
+let mk_ind context id uri tyno outty arg cases =
+ let lpsno, (_, _, arity, constructors) = get_ind_type uri tyno in
+ let inty, _ = TC.type_of_aux' [] context (cic arg) Un.empty_ugraph in
+ let ps = match inty with
+ | C.MutInd _ -> []
+ | C.Appl (C.MutInd _ :: args) -> List.map (fake_annotate context) args
+ | _ -> assert false
+ in
+ let lps, rps = T.list_split lpsno ps in
+ let eliminator = get_default_eliminator context uri tyno inty in
+ let arg_ref = T.mk_arel 0 "" in
+ let body = C.AMutCase (id, uri, tyno, outty, arg_ref, cases) in
+ let predicate = add_abst (succ (List.length rps)) body in
+ None