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_______________________________________________________________ *)
18 module CL = CommonLibrary
21 (* nodes count **************************************************************)
40 let initial_counters = {
41 eabsts = 0; eabbrs = 0; evoids = 0;
42 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
43 tabsts = 0; tabbrs = 0; tvoids = 0;
44 uris = []; nodes = 0; xnodes = 0
47 let rec count_term_binder f c e = function
49 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
52 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
55 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
58 and count_term f c e = function
60 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
64 | Some (_, B.Abst _) ->
65 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
68 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
73 if Cps.list_mem ~eq:U.eq u c.uris
74 then {c with nodes = succ c.nodes}
75 else {c with xnodes = succ c.xnodes}
77 f {c with tgrefs = succ c.tgrefs}
79 let c = {c with tcasts = succ c.tcasts} in
80 let f c = count_term f c e t in
83 let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
84 let f c = count_term f c e t in
87 let f c e = count_term f c e t in
88 let f c = B.push (f c) e a b in
89 count_term_binder f c e b
91 let count_obj f c = function
94 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
96 count_term f c B.empty_context w
98 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
99 count_term f c B.empty_context v
101 let c = {c with evoids = succ c.evoids; xnodes = succ c.xnodes} in
104 let count_item f c = function
105 | Some obj -> count_obj f c obj
108 let print_counters f c =
110 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
113 let items = c.eabsts + c.eabbrs in
114 let nodes = c.nodes + c.xnodes in
115 L.warn (P.sprintf " Kernel representation summary (basic_rg)");
116 L.warn (P.sprintf " Total entry items: %7u" items);
117 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
118 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
119 L.warn (P.sprintf " Total term items: %7u" terms);
120 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
121 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
122 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
123 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
124 L.warn (P.sprintf " Application items: %7u" c.tappls);
125 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
126 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
127 L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
128 L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
131 (* context/term pretty printing *********************************************)
135 | None -> assert false
136 | Some (true, n) -> F.fprintf frm "%s" n
137 | Some (false, n) -> F.fprintf frm "^%s" n
141 let rec pp_term c frm = function
144 | Some s -> F.fprintf frm "@[%s@]" s
145 | None -> F.fprintf frm "@[*%u@]" h
150 | Some (a, _) -> F.fprintf frm "@[%a@]" id a
151 | None -> F.fprintf frm "@[#%u@]" i
153 if !O.indexes then f 0 None else B.get f c i
154 | B.GRef (_, s) -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
155 | B.Cast (_, u, t) ->
156 F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
157 | B.Appl (_, v, t) ->
158 F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
159 | B.Bind (a, B.Abst w, t) ->
161 F.fprintf frm "@[[%a:%a].%a@]" id a (pp_term c) w (pp_term cc) t
163 B.push f c a (B.Abst w)
164 | B.Bind (a, B.Abbr v, t) ->
166 F.fprintf frm "@[[%a=%a].%a@]" id a (pp_term c) v (pp_term cc) t
168 B.push f c a (B.Abbr v)
169 | B.Bind (a, B.Void, t) ->
170 let f cc = F.fprintf frm "@[[%a].%a@]" id a (pp_term cc) t in
173 let pp_context frm c =
174 let pp_entry frm = function
176 F.fprintf frm "@,@[%a : %a@]" id a (pp_term c) w
178 F.fprintf frm "@,@[%a = %a@]" id a (pp_term c) v
180 F.fprintf frm "@,%a" id a
182 let iter map frm l = List.iter (map frm) l in
183 let f es = F.fprintf frm "%a" (iter pp_entry) (List.rev es) in
187 L.pp_term = pp_term; L.pp_context = pp_context
190 (* term xml printing ********************************************************)
195 | Some (true, s) -> F.fprintf frm " name=%S" s
196 | Some (false, n) -> F.fprintf frm " name=%S" ("^" ^ n)
200 let rec exp_term frm = function
202 F.fprintf frm "<Sort position=%S%a/>" (string_of_int l) id a
204 F.fprintf frm "<LRef position=%S%a/>" (string_of_int i) id a
206 F.fprintf frm "<GRef uri=%S%a/>" (U.string_of_uri u) id a
207 | B.Cast (a, w, t) ->
208 F.fprintf frm "<Cast%a/>%a%a" id a exp_boxed w exp_term t
209 | B.Appl (a, v, t) ->
210 F.fprintf frm "<Appl%a/>%a%a" id a exp_boxed v exp_term t
211 | B.Bind (a, b, t) ->
212 F.fprintf frm "%a%a" (exp_bind a) b exp_term t
214 and exp_boxed frm t =
215 F.fprintf frm "@,@[<v3> %a@]@," exp_term t
217 and exp_bind a frm = function
219 F.fprintf frm "<Abst%a/>%a" id a exp_boxed w
221 F.fprintf frm "<Abbr%a/>%a" id a exp_boxed v
223 F.fprintf frm "<Void%a/>" id a
225 let export_obj frm = function
226 | _, uri, B.Abst w ->
227 let str = U.string_of_uri uri in
228 F.fprintf frm "%s@,@,<ABST uri=%S>%a</ABST>"
229 (CL.doctype "ABST") str exp_boxed w
230 | _, uri, B.Abbr v ->
231 let str = U.string_of_uri uri in
232 F.fprintf frm "%s@,@,<ABBR uri=%S>%a</ABBR>"
233 (CL.doctype "ABBR") str exp_boxed v
235 let str = U.string_of_uri uri in
236 F.fprintf frm "%s@,@,<VOID uri=%S/>"
237 (CL.doctype "VOID") str