(* ||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 KF = Filename module KP = Printf module U = NUri module C = Cps module L = Log module G = Options module H = Hierarchy module N = Layer module E = Entity module R = Alpha module XD = XmlCrg module B = Brg module BD = BrgCrg (* nodes count **************************************************************) type counters = { eabsts: int; eabbrs: int; evoids: int; tsorts: int; tlrefs: int; tgrefs: int; tcasts: int; tappls: int; tabsts: int; tabbrs: int; tvoids: int; uris : B.uri list; nodes : int; xnodes: int } let level = 2 let initial_counters = { eabsts = 0; eabbrs = 0; evoids = 0; tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0; tvoids = 0; uris = []; nodes = 0; xnodes = 0 } IFDEF SUMMARY THEN let rec count_term_binder f c e = function | B.Abst (_, _, w) -> let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in count_term f c e w | B.Abbr v -> let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in count_term f c e v | B.Void -> let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in f c and count_term f c e = function | B.Sort _ -> f {c with tsorts = succ c.tsorts; nodes = succ c.nodes} | B.LRef (_, i) -> begin match B.get e i with | _, _, _, _, B.Abst _ | _, _, _, _, B.Void -> f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes} | _, _, _, _, B.Abbr _ -> f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes} end | B.GRef (_, u) -> let c = if Cps.list_mem ~eq:U.eq u c.uris then {c with nodes = succ c.nodes} else {c with xnodes = succ c.xnodes} in 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 e t in count_term f c e v | B.Appl (_, v, t) -> let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in let f c = count_term f c e t in count_term f c e v | B.Bind (y, b, t) -> let f c = count_term f c (B.push e B.empty E.empty_node y b) t in count_term_binder f c e b let count_entity f c = function | _, _, u, E.Abst (_, w) -> let c = {c with eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris } in count_term f c B.empty w | _, _, _, E.Abbr (_, v) -> let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in count_term f c B.empty v | _, _, _, E.Void -> assert false let print_counters f c = let terms = c.tsorts + c.tlrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts + c.tabbrs in let items = c.eabsts + c.eabbrs in let nodes = c.nodes + c.xnodes in L.warn level (KP.sprintf "Kernel representation summary (basic_rg)"); 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 " Global Int. Complexity: %7u" c.nodes); L.warn level (KP.sprintf " + Abbreviation nodes: %7u" nodes); f () END (* lenv/term pretty printing ************************************************) 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 pp_reduced och x = if x then KP.fprintf och "%s" "^" let pp_level st och n = KP.fprintf och "%s" (N.to_string st n) let rec pp_term st e och = function | B.Sort k -> let err _ = KP.fprintf och "*%u" k in let f s = KP.fprintf och "%s" s in H.string_of_sort err f k | B.LRef (_, i) -> let err _ = KP.fprintf och "#%u" i in if !G.indexes then err () else let _, _, _, y, b = B.get e i in KP.fprintf och "%a" (name err) y | B.GRef (_, s) -> let u = U.string_of_uri s in KP.fprintf och "$%s" (if !G.short then KF.basename u else u) | B.Cast (u, t) -> KP.fprintf och "<%a>.%a" (pp_term st e) u (pp_term st e) t | B.Appl (_, v, t) -> KP.fprintf och "(%a).%a" (pp_term st e) v (pp_term st e) t | B.Bind (y, B.Abst (r, n, w), t) -> let y = R.alpha B.mem e y in let ee = B.push e B.empty E.empty_node y (B.abst r n w) in KP.fprintf och "%a%a[%a:%a].%a" (pp_level st) n pp_reduced r (name C.start) y (pp_term st e) w (pp_term st ee) t | B.Bind (y, B.Abbr v, t) -> let y = R.alpha B.mem e y in let ee = B.push e B.empty E.empty_node y (B.abbr v) in KP.fprintf och "[%a=%a].%a" (name C.start) y (pp_term st e) v (pp_term st ee) t | B.Bind (y, B.Void, t) -> let y = R.alpha B.mem e y in let ee = B.push e B.empty E.empty_node y B.Void in KP.fprintf och "[%a].%a" (name C.start) y (pp_term st ee) t let pp_lenv st och e = let pp_entry f c a y b x = let y = R.alpha B.mem e y in let x = B.push x c a y b in match b with | B.Abst (_, _, w) -> KP.fprintf och "[%a : %a] " (name C.start) y (pp_term st c) w; f x | B.Abbr v -> KP.fprintf och "[%a = %a] " (name C.start) y (pp_term st c) v; f x | B.Void -> KP.fprintf och "[%a]" (name C.start) y; f x in if e = B.empty then KP.fprintf och "%s" "empty" else B.fold_right ignore pp_entry e B.empty let specs = { L.pp_term = pp_term; L.pp_lenv = pp_lenv } IFDEF OBJECTS THEN (* term xml printing ********************************************************) let export_term st = BD.crg_of_brg (XD.export_term st) END