(* ||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 C = Cps module L = Log module P = Marks module N = Layer module E = Entity module D = Crg (* nodes count **************************************************************) let level = 2 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 : D.uri list; nodes : int; xnodes: int } 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 f c e = function | D.TSort _ -> f {c with tsorts = succ c.tsorts; nodes = succ c.nodes} | D.TLRef (_, i) -> begin match D.get e i with | _, _, _, D.Abbr _ -> f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes} | _ -> f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes} end | D.TGRef (_, u) -> let c = if C.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} | D.TCast (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 | D.TAppl (_, v, t) -> let c = {c with tappls = succ c.tappls} in let f c = count_term f c e t in count_term f c e v | D.TProj (d, t) -> D.shift (count_term f c e) d t | D.TBind (y, b, t) -> let f c e = count_term f c e t in count_binder f c e y b and count_binder f c e y b = match b with | D.Abst (_, _, w) -> let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in let f c = D.push_bind (f c) E.empty_node y b e in count_term f c e w | D.Abbr v -> let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in let f c = D.push_bind (f c) E.empty_node y b e in count_term f c e v | D.Void -> let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in D.push_bind (f c) E.empty_node y b e 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 D.ESort w | _, _, _, E.Abbr (_, v) -> let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in count_term f c D.ESort 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 nodes = c.nodes + c.xnodes in let marks = P.marks () in L.warn level (KP.sprintf "Intermediate representation summary (complete_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 " Ambiguous abstractions: %7u" marks); L.warn level (KP.sprintf " Global Int. Complexity: %7u" c.nodes); L.warn level (KP.sprintf " + Abbreviation nodes: %7u" nodes); f () END (* term/environment pretty printer ******************************************) let pp_b_attrs out a = let f s b = if b then out (KP.sprintf "%s;" s) else out (KP.sprintf "~%s;" s) in E.name ignore f a let pp_n_attrs out a = out (KP.sprintf "+%i;" a.E.n_apix) let pp_state out x = if x then out "^" let rec pp_term out st = function | D.TSort k -> out (KP.sprintf "*%u" k) | D.TLRef (a, i) -> pp_n_attrs out a; out (KP.sprintf "#%u" i) | D.TGRef (a, u) -> pp_n_attrs out a; out (KP.sprintf "$") | D.TCast (u, t) -> out "<"; pp_term out st u; out ">."; pp_term out st t | D.TAppl (_, u, t) -> out "("; pp_term out st u; out ")."; pp_term out st t | D.TBind (y, u, t) -> pp_b_attrs out y; pp_bind out st u; out "."; pp_term out st t | D.TProj (u, t) -> out "{"; pp_lenv out st u; out "}."; pp_term out st t and pp_bind out st = function | D.Abst (r, n, u) -> out "[:"; pp_term out st u; out "]"; pp_state out r; out (N.to_string st n); out " " | D.Abbr u -> out "[="; pp_term out st u; out "] "; | D.Void -> out "[] " and pp_lenv out st = function | D.ESort -> () | D.EBind (u, a, y, t) -> pp_lenv out st u; pp_b_attrs out y; pp_n_attrs out a; pp_bind out st t | D.EAppl (u, _, t) -> pp_lenv out st u; out "("; pp_term out st t; out ") " | D.EProj (u, t) -> pp_lenv out st u; out "{"; pp_lenv out st t; out "} "