(* ||M|| This file is part of HELM, an Hypertextual, Electronic ||A|| Library of Mathematics, developed at the Computer Science ||T|| Department, University of Bologna, Italy. ||I|| ||T|| HELM is free software; you can redistribute it and/or ||A|| modify it under the terms of the GNU General Public License \ / version 2 or (at your option) any later version. \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) module P = Printf module F = Format module U = NUri module L = Log module Y = Entity module H = Hierarchy module O = Output module B = Bag type counters = { eabsts: int; eabbrs: int; tsorts: int; tlrefs: int; tgrefs: int; tcasts: int; tappls: int; tabsts: int; tabbrs: int } let initial_counters = { eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0 } let rec count_term_binder f c = function | B.Abst w -> let c = {c with tabsts = succ c.tabsts} in count_term f c w | B.Abbr v -> let c = {c with tabbrs = succ c.tabbrs} in count_term f c v | B.Void -> f c and count_term f c = function | B.Sort _ -> f {c with tsorts = succ c.tsorts} | B.LRef _ -> f {c with tlrefs = succ c.tlrefs} | B.GRef _ -> f {c with tgrefs = succ c.tgrefs} | B.Cast (v, t) -> let c = {c with tcasts = succ c.tcasts} in let f c = count_term f c t in count_term f c v | B.Appl (v, t) -> let c = {c with tappls = succ c.tappls} in let f c = count_term f c t in count_term f c v | B.Bind (_, _, b, t) -> let f c = count_term_binder f c b in count_term f c t let count_entity f c = function | _, _, Y.Abst w -> let c = {c with eabsts = succ c.eabsts} in count_term f c w | _, _, Y.Abbr v -> let c = {c with eabbrs = succ c.eabbrs} in count_term f c v | _, _, Y.Void -> assert false let print_counters f c = let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts + c.tabbrs in let items = c.eabsts + c.eabbrs in let locations = B.locations () in L.warn (P.sprintf " Kernel representation summary (basic_ag)"); 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 " Total binder locations: %7u" locations); f () let res l id = if !O.indexes then P.sprintf "#%u" l else id 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 f = function | Some (id, _) -> F.fprintf frm "@[%s@]" id | None -> F.fprintf frm "@[#%u@]" i in if !O.indexes then f None else B.get 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 (l, id, B.Abst w, t) -> let f cc = F.fprintf frm "@[[%s:%a].%a@]" (res l id) (pp_term c) w (pp_term cc) t in B.push "output abst" f c l id (B.Abst w) | B.Bind (l, id, B.Abbr v, t) -> let f cc = F.fprintf frm "@[[%s=%a].%a@]" (res l id) (pp_term c) v (pp_term cc) t in B.push "output abbr" f c l id (B.Abbr v) | B.Bind (l, id, B.Void, t) -> let f cc = F.fprintf frm "@[[%s].%a@]" (res l id) (pp_term cc) t in B.push "output void" f c l id B.Void let pp_lenv frm c = let pp_entry frm = function | l, id, B.Abst w -> F.fprintf frm "@,@[%s : %a@]" (res l id) (pp_term c) w | l, id, B.Abbr v -> F.fprintf frm "@,@[%s = %a@]" (res l id) (pp_term c) v | l, id, B.Void -> F.fprintf frm "@,%s" (res l id) in let iter map frm l = List.iter (map frm) l in let f es = F.fprintf frm "%a" (iter pp_entry) (List.rev es) in B.contents f c let specs = { L.pp_term = pp_term; L.pp_lenv = pp_lenv }