(* ||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 KP = Printf module U = NUri module L = Log module P = Marks module G = Options module H = Hierarchy module E = Entity module XD = XmlCrg module Z = Bag module ZD = BagCrg type counters = { eabsts: int; eabbrs: int; tsorts: int; tlrefs: int; tgrefs: int; tcasts: int; tappls: int; tabsts: int; tabbrs: int } let level = 2 let initial_counters = { eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0 } IFDEF SUMMARY THEN let rec count_term_binder f c = function | Z.Abst w -> let c = {c with tabsts = succ c.tabsts} in count_term f c w | Z.Abbr v -> let c = {c with tabbrs = succ c.tabbrs} in count_term f c v | Z.Void -> f c and count_term f c = function | Z.Sort _ -> f {c with tsorts = succ c.tsorts} | Z.LRef _ -> f {c with tlrefs = succ c.tlrefs} | Z.GRef _ -> f {c with tgrefs = succ c.tgrefs} | Z.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 | Z.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 | Z.Bind (_, _, b, t) -> let f c = count_term_binder f c b in count_term f c t let count_entity f c = function | _, _, _, E.Abst (_, w) -> let c = {c with eabsts = succ c.eabsts} in count_term f c w | _, _, _, E.Abbr (_, v) -> let c = {c with eabbrs = succ c.eabbrs} in count_term f c v | _, _, _, E.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 = P.marks () in L.warn level (KP.sprintf "Kernel representation summary (basic_ag)"); L.warn level (KP.sprintf " Total entry items: %7u" items); L.warn level (KP.sprintf " Declaration items: %7u" c.eabsts); L.warn level (KP.sprintf " Definition items: %7u" c.eabbrs); L.warn level (KP.sprintf " Total term items: %7u" terms); L.warn level (KP.sprintf " Sort items: %7u" c.tsorts); L.warn level (KP.sprintf " Local reference items: %7u" c.tlrefs); L.warn level (KP.sprintf " Global reference items: %7u" c.tgrefs); L.warn level (KP.sprintf " Explicit Cast items: %7u" c.tcasts); L.warn level (KP.sprintf " Application items: %7u" c.tappls); L.warn level (KP.sprintf " Abstraction items: %7u" c.tabsts); L.warn level (KP.sprintf " Abbreviation items: %7u" c.tabbrs); L.warn level (KP.sprintf " Total binder locations: %7u" locations); f () END let name err och a = let f n = function | true -> KP.fprintf och "%s" n | false -> KP.fprintf och "-%s" n in E.name err f a let res a l och = let err () = KP.fprintf och "#%s" (P.string_of_mark l) in if !G.indexes then err () else name err och a let rec pp_term st c och = function | Z.Sort h -> let err () = KP.fprintf och "*%u" h in let f s = KP.fprintf och "%s" s in H.string_of_sort err f h | Z.LRef i -> let err () = KP.fprintf och "#%s" (P.string_of_mark i) in let f a _ = name err och a in if !G.indexes then err () else Z.get err f c i | Z.GRef s -> KP.fprintf och "$%s" (U.string_of_uri s) | Z.Cast (u, t) -> KP.fprintf och "{%a}.%a" (pp_term st c) u (pp_term st c) t | Z.Appl (v, t) -> KP.fprintf och "(%a).%a" (pp_term st c) v (pp_term st c) t | Z.Bind (y, l, Z.Abst w, t) -> let f cc = KP.fprintf och "[%t:%a].%a" (res y l) (pp_term st c) w (pp_term st cc) t in Z.push "output abst" f c y l (Z.Abst w) | Z.Bind (y, l, Z.Abbr v, t) -> let f cc = KP.fprintf och "[%t=%a].%a" (res y l) (pp_term st c) v (pp_term st cc) t in Z.push "output abbr" f c y l (Z.Abbr v) | Z.Bind (y, l, Z.Void, t) -> let f cc = KP.fprintf och "[%t].%a" (res y l) (pp_term st cc) t in Z.push "output void" f c y l Z.Void let pp_lenv st och c = let pp_entry och = function | y, l, Z.Abst w -> KP.fprintf och "%t : %a\n" (res y l) (pp_term st c) w | y, l, Z.Abbr v -> KP.fprintf och "%t = %a\n" (res y l) (pp_term st c) v | y, l, Z.Void -> KP.fprintf och "%t\n" (res y l) in let iter map och l = List.iter (map och) l in let f es = KP.fprintf och "%a" (iter pp_entry) (List.rev es) in Z.contents f c let specs = { L.pp_term = pp_term; L.pp_lenv = pp_lenv } IFDEF OBJECTS THEN (* term xml printing ********************************************************) let export_term st = ZD.crg_of_bag (XD.export_term st) END