+ let nodes = c.nodes + c.xnodes in
+ L.warn (P.sprintf " Kernel representation summary (basic_rg)");
+ L.warn (P.sprintf " Total entry items: %7u" items);
+ L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
+ L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
+ L.warn (P.sprintf " Total term items: %7u" terms);
+ L.warn (P.sprintf " Sort items: %7u" c.tsorts);
+ L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
+ L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
+ L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
+ L.warn (P.sprintf " Application items: %7u" c.tappls);
+ L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
+ L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
+ L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
+ L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
+ f ()
+
+(* supplementary annotation *************************************************)
+
+let attrs_of_binder f = function
+ | B.Abst (a, _)
+ | B.Abbr (a, _)
+ | B.Void a -> f a
+
+let rec does_not_occur f n r = function
+ | B.Null -> f true
+ | B.Cons (c, _, b) ->
+ let f n1 r1 =
+ if n1 = n && r1 = r then f false else does_not_occur f n r c
+ in
+ attrs_of_binder (Y.name C.err f) b
+
+let rename f c a =
+ let rec aux f c n r =
+ let f = function
+ | true -> f n r
+ | false -> aux f c (n ^ "'") r
+ in
+ does_not_occur f n r c
+ in
+ let f n0 r0 =
+ let f n r = if n = n0 && r = r0 then f a else f (Y.Name (n, r) :: a) in
+ aux f c n0 r0
+ in
+ Y.name C.err f a
+
+let rename_bind f c = function
+ | B.Abst (a, w) -> let f a = f (B.abst a w) in rename f c a
+ | B.Abbr (a, v) -> let f a = f (B.abbr a v) in rename f c a
+ | B.Void a -> let f a = f (B.Void a) in rename f c a
+
+(* lenv/term pretty printing ************************************************)
+
+let name frm a =
+ let f n = function
+ | true -> F.fprintf frm "%s" n
+ | false -> F.fprintf frm "^%s" n
+ in
+ Y.name C.err f a
+
+let rec pp_term c frm = function
+ | B.Sort (_, h) ->
+ let err _ = F.fprintf frm "@[*%u@]" h in
+ let f s = F.fprintf frm "@[%s@]" s in
+ H.get_sort err f h
+ | B.LRef (_, i) ->
+ let err _ = F.fprintf frm "@[#%u@]" i in
+ let f _ = function
+ | B.Abst (a, _)
+ | B.Abbr (a, _)
+ | B.Void a -> F.fprintf frm "@[%a@]" name a
+ in
+ if !O.indexes then err () else B.get err f c i
+ | B.GRef (_, s) ->
+ F.fprintf frm "@[$%s@]" (U.string_of_uri s)
+ | B.Cast (_, u, t) ->
+ F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
+ | B.Appl (_, v, t) ->
+ F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
+ | B.Bind (B.Abst (a, w), t) ->
+ let f a cc =
+ F.fprintf frm "@[[%a:%a].%a@]" name a (pp_term c) w (pp_term cc) t
+ in
+ let f a = B.push (f a) c (B.abst a w) in
+ rename f c a
+ | B.Bind (B.Abbr (a, v), t) ->
+ let f a cc =
+ F.fprintf frm "@[[%a=%a].%a@]" name a (pp_term c) v (pp_term cc) t
+ in
+ let f a = B.push (f a) c (B.abbr a v) in
+ rename f c a
+ | B.Bind (B.Void a, t) ->
+ let f a cc = F.fprintf frm "@[[%a].%a@]" name a (pp_term cc) t in
+ let f a = B.push (f a) c (B.Void a) in
+ rename f c a
+
+let pp_lenv frm c =
+ let pp_entry f c = function
+ | B.Abst (a, w) ->
+ let f a = F.fprintf frm "@,@[%a : %a@]" name a (pp_term c) w; f () in
+ rename f c a
+ | B.Abbr (a, v) ->
+ let f a = F.fprintf frm "@,@[%a = %a@]" name a (pp_term c) v; f () in
+ rename f c a
+ | B.Void a ->
+ let f a = F.fprintf frm "@,%a" name a; f () in
+ rename f c a
+ in
+ B.rev_iter C.start pp_entry c
+
+let specs = {
+ L.pp_term = pp_term; L.pp_lenv = pp_lenv
+}
+
+(* term xml printing ********************************************************)
+
+let rec exp_term c frm = function
+ | B.Sort (a, l) ->
+ let a =
+ let err _ = a in
+ let f s = Y.Name (s, true) :: a in
+ H.get_sort err f l
+ in
+ F.fprintf frm "<Sort position=%S%a/>" (string_of_int l) X.old_name a
+ | B.LRef (a, i) ->
+ let a =
+ let err _ = a in
+ let f n r = Y.Name (n, r) :: a in
+ let f _ b = attrs_of_binder (Y.name err f) b in
+ B.get err f c i
+ in
+ F.fprintf frm "<LRef position=%S%a/>" (string_of_int i) X.old_name a
+ | B.GRef (a, u) ->
+ let a = Y.Name (U.name_of_uri u, true) :: a in
+ F.fprintf frm "<GRef uri=%S%a/>" (U.string_of_uri u) X.old_name a
+ | B.Cast (a, w, t) ->
+ F.fprintf frm "<Cast%a>%a</Cast>@,%a" X.old_name a (exp_boxed c) w (exp_term c) t
+ | B.Appl (a, v, t) ->
+ F.fprintf frm "<Appl%a>%a</Appl>@,%a" X.old_name a (exp_boxed c) v (exp_term c) t
+ | B.Bind (b, t) ->
+ let f b cc = F.fprintf frm "%a@,%a" (exp_bind c) b (exp_term cc) t in
+ let f b = B.push (f b) c b in
+ rename_bind f c b
+
+and exp_boxed c frm t =
+ F.fprintf frm "@,@[<v3> %a@]@," (exp_term c) t
+
+and exp_bind c frm = function
+ | B.Abst (a, w) ->
+ F.fprintf frm "<Abst%a>%a</Abst>" X.old_name a (exp_boxed c) w
+ | B.Abbr (a, v) ->
+ F.fprintf frm "<Abbr%a/>%a</Abbr>" X.old_name a (exp_boxed c) v
+ | B.Void a ->
+ F.fprintf frm "<Void%a/>" X.old_name a
+
+let export_term frm t =
+ F.fprintf frm "%a" (exp_boxed B.empty_lenv) t