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 let err _ = f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes} in
68 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
70 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
75 if Cps.list_mem ~eq:U.eq u c.uris
76 then {c with nodes = succ c.nodes}
77 else {c with xnodes = succ c.xnodes}
79 f {c with tgrefs = succ c.tgrefs}
81 let c = {c with tcasts = succ c.tcasts} in
82 let f c = count_term f c e t in
85 let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
86 let f c = count_term f c e t in
89 let f c e = count_term f c e t in
90 let f c = B.push (f c) e b in
91 count_term_binder f c e b
93 let count_entity f c = function
96 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
98 count_term f c B.empty_lenv w
100 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
101 count_term f c B.empty_lenv v
103 let print_counters f c =
105 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
108 let items = c.eabsts + c.eabbrs in
109 let nodes = c.nodes + c.xnodes in
110 L.warn (P.sprintf " Kernel representation summary (basic_rg)");
111 L.warn (P.sprintf " Total entry items: %7u" items);
112 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
113 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
114 L.warn (P.sprintf " Total term items: %7u" terms);
115 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
116 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
117 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
118 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
119 L.warn (P.sprintf " Application items: %7u" c.tappls);
120 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
121 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
122 L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
123 L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
126 (* supplementary annotation *************************************************)
128 let attrs_of_binder f = function
133 let rec does_not_occur f n r = function
135 | B.Cons (c, _, b) ->
137 if n1 = n && r1 = r then f false else does_not_occur f n r c
139 attrs_of_binder (Y.name C.err f) b
142 let rec aux f c n r =
145 | false -> aux f c (n ^ "'") r
147 does_not_occur f n r c
150 let f n r = if n = n0 && r = r0 then f a else f (Y.Name (n, r) :: a) in
155 let rename_bind f c = function
156 | B.Abst (a, w) -> let f a = f (B.abst a w) in rename f c a
157 | B.Abbr (a, v) -> let f a = f (B.abbr a v) in rename f c a
158 | B.Void a -> let f a = f (B.Void a) in rename f c a
160 (* lenv/term pretty printing ************************************************)
164 | true -> F.fprintf frm "%s" n
165 | false -> F.fprintf frm "^%s" n
169 let rec pp_term c frm = function
171 let err _ = F.fprintf frm "@[*%u@]" h in
172 let f s = F.fprintf frm "@[%s@]" s in
175 let err _ = F.fprintf frm "@[#%u@]" i in
179 | B.Void a -> F.fprintf frm "@[%a@]" name a
181 if !O.indexes then err () else B.get err f c i
183 F.fprintf frm "@[$%s@]" (U.string_of_uri s)
184 | B.Cast (_, u, t) ->
185 F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
186 | B.Appl (_, v, t) ->
187 F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
188 | B.Bind (B.Abst (a, w), t) ->
190 F.fprintf frm "@[[%a:%a].%a@]" name a (pp_term c) w (pp_term cc) t
192 let f a = B.push (f a) c (B.abst a w) in
194 | B.Bind (B.Abbr (a, v), t) ->
196 F.fprintf frm "@[[%a=%a].%a@]" name a (pp_term c) v (pp_term cc) t
198 let f a = B.push (f a) c (B.abbr a v) in
200 | B.Bind (B.Void a, t) ->
201 let f a cc = F.fprintf frm "@[[%a].%a@]" name a (pp_term cc) t in
202 let f a = B.push (f a) c (B.Void a) in
206 let pp_entry f c = function
208 let f a = F.fprintf frm "@,@[%a : %a@]" name a (pp_term c) w; f () in
211 let f a = F.fprintf frm "@,@[%a = %a@]" name a (pp_term c) v; f () in
214 let f a = F.fprintf frm "@,%a" name a; f () in
217 B.rev_iter C.start pp_entry c
220 L.pp_term = pp_term; L.pp_lenv = pp_lenv
223 (* term xml printing ********************************************************)
225 let rec exp_term c frm = function
229 let f s = Y.Name (s, true) :: a in
232 F.fprintf frm "<Sort position=%S%a/>" (string_of_int l) X.old_name a
236 let f n r = Y.Name (n, r) :: a in
237 let f _ b = attrs_of_binder (Y.name err f) b in
240 F.fprintf frm "<LRef position=%S%a/>" (string_of_int i) X.old_name a
242 let a = Y.Name (U.name_of_uri u, true) :: a in
243 F.fprintf frm "<GRef uri=%S%a/>" (U.string_of_uri u) X.old_name a
244 | B.Cast (a, w, t) ->
245 F.fprintf frm "<Cast%a>%a</Cast>@,%a" X.old_name a (exp_boxed c) w (exp_term c) t
246 | B.Appl (a, v, t) ->
247 F.fprintf frm "<Appl%a>%a</Appl>@,%a" X.old_name a (exp_boxed c) v (exp_term c) t
249 let f b cc = F.fprintf frm "%a@,%a" (exp_bind c) b (exp_term cc) t in
250 let f b = B.push (f b) c b in
253 and exp_boxed c frm t =
254 F.fprintf frm "@,@[<v3> %a@]@," (exp_term c) t
256 and exp_bind c frm = function
258 F.fprintf frm "<Abst%a>%a</Abst>" X.old_name a (exp_boxed c) w
260 F.fprintf frm "<Abbr%a/>%a</Abbr>" X.old_name a (exp_boxed c) v
262 F.fprintf frm "<Void%a/>" X.old_name a
264 let export_term frm t =
265 F.fprintf frm "%a" (exp_boxed B.empty_lenv) t