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_______________________________________________________________ *)
23 (* nodes count **************************************************************)
42 let initial_counters = {
43 eabsts = 0; eabbrs = 0; evoids = 0;
44 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
45 tabsts = 0; tabbrs = 0; tvoids = 0;
46 uris = []; nodes = 0; xnodes = 0
49 let rec count_term_binder f c e = function
51 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
54 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
57 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
60 and count_term f c e = function
62 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
64 begin match B.get e i with
67 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
68 | _, _, _, B.Abbr _ ->
69 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 = count_term f c (B.push e B.empty a b) t in
88 count_term_binder f c e b
90 let count_entity f c = function
93 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
95 count_term f c B.empty w
97 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
98 count_term f c B.empty v
99 | _, _, Y.Void -> assert false
101 let print_counters f c =
103 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
106 let items = c.eabsts + c.eabbrs in
107 let nodes = c.nodes + c.xnodes in
108 L.warn (P.sprintf " Kernel representation summary (basic_rg)");
109 L.warn (P.sprintf " Total entry items: %7u" items);
110 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
111 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
112 L.warn (P.sprintf " Total term items: %7u" terms);
113 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
114 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
115 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
116 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
117 L.warn (P.sprintf " Application items: %7u" c.tappls);
118 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
119 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
120 L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
121 L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
124 (* supplementary annotation *************************************************)
126 let rec does_not_occur f n r = function
128 | B.Cons (e, _, a, _) ->
130 if n1 = n && r1 = r then f false else does_not_occur f n r e
135 let rec aux f e n r =
138 | false -> aux f e (n ^ "'") r
140 does_not_occur f n r e
143 let f n r = if n = n0 && r = r0 then f a else f (Y.Name (n, r) :: a) in
148 (* lenv/term pretty printing ************************************************)
152 | true -> F.fprintf frm "%s" n
153 | false -> F.fprintf frm "^%s" n
157 let rec pp_term e frm = function
159 let err _ = F.fprintf frm "@[*%u@]" h in
160 let f s = F.fprintf frm "@[%s@]" s in
163 let err _ = F.fprintf frm "@[#%u@]" i in
164 if !O.indexes then err () else
165 let _, _, a, b = B.get e i in
166 F.fprintf frm "@[%a@]" (name err) a
168 F.fprintf frm "@[$%s@]" (U.string_of_uri s)
169 | B.Cast (_, u, t) ->
170 F.fprintf frm "@[{%a}.%a@]" (pp_term e) u (pp_term e) t
171 | B.Appl (_, v, t) ->
172 F.fprintf frm "@[(%a).%a@]" (pp_term e) v (pp_term e) t
173 | B.Bind (a, B.Abst w, t) ->
175 let ee = B.push e B.empty a (B.abst w) in
176 F.fprintf frm "@[[%a:%a].%a@]" (name C.err) a (pp_term e) w (pp_term ee) t
179 | B.Bind (a, B.Abbr v, t) ->
181 let ee = B.push e B.empty a (B.abbr v) in
182 F.fprintf frm "@[[%a=%a].%a@]" (name C.err) a (pp_term e) v (pp_term ee) t
185 | B.Bind (a, B.Void, t) ->
187 let ee = B.push e B.empty a B.Void in
188 F.fprintf frm "@[[%a].%a@]" (name C.err) a (pp_term ee) t
193 let pp_entry f e c a b x = f x (*match b with
195 let f a = F.fprintf frm "@,@[%a : %a@]" (name C.err) a (pp_term e) w; f a in
198 let f a = F.fprintf frm "@,@[%a = %a@]" (name C.err) a (pp_term e) v; f a in
201 let f a = F.fprintf frm "@,%a" (name C.err) a; f a in
204 B.fold_right ignore pp_entry e B.empty
207 L.pp_term = pp_term; L.pp_lenv = pp_lenv
210 (* term xml printing ********************************************************)
212 let rec exp_term e t out tab = match t with
216 let f s = Y.Name (s, true) :: a in
219 let attrs = [X.position l; X.name a] in
220 X.tag X.sort attrs out tab
224 let f n r = Y.Name (n, r) :: a in
225 let _, _, a, b = B.get e i in
228 let attrs = [X.position i; X.name a] in
229 X.tag X.lref attrs out tab
231 let a = Y.Name (U.name_of_uri n, true) :: a in
232 let attrs = [X.uri n; X.name a] in
233 X.tag X.gref attrs out tab
234 | B.Cast (a, u, t) ->
236 X.tag X.cast attrs ~contents:(exp_term e u) out tab;
238 | B.Appl (a, v, t) ->
240 X.tag X.appl attrs ~contents:(exp_term e v) out tab;
242 | B.Bind (a, b, t) ->
243 let a = rename C.start e a in
244 exp_bind e a b out tab;
245 exp_term (B.push e B.empty a b) t out tab
247 and exp_bind e a b out tab = match b with
249 let attrs = [X.name a; X.mark a] in
250 X.tag X.abst attrs ~contents:(exp_term e w) out tab
252 let attrs = [X.name a; X.mark a] in
253 X.tag X.abbr attrs ~contents:(exp_term e v) out tab
255 let attrs = [X.name a; X.mark a] in
256 X.tag X.void attrs out tab
258 let export_term = exp_term B.empty