2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
20 (* nodes count **************************************************************)
39 let initial_counters = {
40 eabsts = 0; eabbrs = 0; evoids = 0;
41 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
42 tabsts = 0; tabbrs = 0; tvoids = 0;
43 uris = []; nodes = 0; xnodes = 0
46 let rec count_term_binder f c e = function
48 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
51 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
54 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
57 and count_term f c e = function
59 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
63 | Some (_, B.Abst _) ->
64 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
67 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
72 if Cps.list_mem ~eq:U.eq u c.uris
73 then {c with nodes = succ c.nodes}
74 else {c with xnodes = succ c.xnodes}
76 f {c with tgrefs = succ c.tgrefs}
78 let c = {c with tcasts = succ c.tcasts} in
79 let f c = count_term f c e t in
82 let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
83 let f c = count_term f c e t in
86 let f c e = count_term f c e t in
87 let f c = B.push (f c) e a b in
88 count_term_binder f c e b
90 let count_obj f c = function
93 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
95 count_term f c B.empty_context w
97 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
98 count_term f c B.empty_context v
100 let c = {c with evoids = succ c.evoids; xnodes = succ c.xnodes} in
103 let count_item f c = function
104 | Some obj -> count_obj f c obj
107 let print_counters f c =
109 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
112 let items = c.eabsts + c.eabbrs in
113 let nodes = c.nodes + c.xnodes in
114 L.warn (P.sprintf " Kernel representation summary (basic_rg)");
115 L.warn (P.sprintf " Total entry items: %7u" items);
116 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
117 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
118 L.warn (P.sprintf " Total term items: %7u" terms);
119 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
120 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
121 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
122 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
123 L.warn (P.sprintf " Application items: %7u" c.tappls);
124 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
125 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
126 L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
127 L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
130 (* context/term pretty printing *********************************************)
134 | None -> assert false
135 | Some (true, n) -> F.fprintf frm "%s" n
136 | Some (false, n) -> F.fprintf frm "^%s" n
140 let rec pp_term c frm = function
143 | Some s -> F.fprintf frm "@[%s@]" s
144 | None -> F.fprintf frm "@[*%u@]" h
149 | Some (a, _) -> F.fprintf frm "@[%a@]" id a
150 | None -> F.fprintf frm "@[#%u@]" i
152 if !O.indexes then f 0 None else B.get f c i
153 | B.GRef (_, s) -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
154 | B.Cast (_, u, t) ->
155 F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
156 | B.Appl (_, v, t) ->
157 F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
158 | B.Bind (a, B.Abst w, t) ->
160 F.fprintf frm "@[[%a:%a].%a@]" id a (pp_term c) w (pp_term cc) t
162 B.push f c a (B.Abst w)
163 | B.Bind (a, B.Abbr v, t) ->
165 F.fprintf frm "@[[%a=%a].%a@]" id a (pp_term c) v (pp_term cc) t
167 B.push f c a (B.Abbr v)
168 | B.Bind (a, B.Void, t) ->
169 let f cc = F.fprintf frm "@[[%a].%a@]" id a (pp_term cc) t in
172 let pp_context frm c =
173 let pp_entry frm = function
175 F.fprintf frm "@,@[%a : %a@]" id a (pp_term c) w
177 F.fprintf frm "@,@[%a = %a@]" id a (pp_term c) v
179 F.fprintf frm "@,%a" id a
181 let iter map frm l = List.iter (map frm) l in
182 let f es = F.fprintf frm "%a" (iter pp_entry) (List.rev es) in
186 L.pp_term = pp_term; L.pp_context = pp_context