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_______________________________________________________________ *)
27 (* nodes count **************************************************************)
48 let initial_counters = {
49 eabsts = 0; eabbrs = 0; evoids = 0;
50 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
51 tabsts = 0; tabbrs = 0; tvoids = 0;
52 uris = []; nodes = 0; xnodes = 0
57 let rec count_term_binder f c e = function
59 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
62 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
65 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
68 and count_term f c e = function
70 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
72 begin match B.get e i with
73 | _, _, _, _, B.Abst _
74 | _, _, _, _, B.Void ->
75 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
76 | _, _, _, _, B.Abbr _ ->
77 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
81 if Cps.list_mem ~eq:U.eq u c.uris
82 then {c with nodes = succ c.nodes}
83 else {c with xnodes = succ c.xnodes}
85 f {c with tgrefs = succ c.tgrefs}
87 let c = {c with tcasts = succ c.tcasts} in
88 let f c = count_term f c e t in
91 let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
92 let f c = count_term f c e t in
95 let f c = count_term f c (B.push e B.empty E.empty_node y b) t in
96 count_term_binder f c e b
98 let count_entity f c = function
99 | _, _, u, E.Abst w ->
101 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
103 count_term f c B.empty w
104 | _, _, _, E.Abbr v ->
105 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
106 count_term f c B.empty v
107 | _, _, _, E.Void -> assert false
109 let print_counters f c =
111 c.tsorts + c.tlrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
114 let items = c.eabsts + c.eabbrs in
115 let nodes = c.nodes + c.xnodes in
116 L.warn level (KP.sprintf "Kernel representation summary (basic_rg)");
117 L.warn level (KP.sprintf " Total entry items: %7u" items);
118 L.warn level (KP.sprintf " Declaration items: %7u" c.eabsts);
119 L.warn level (KP.sprintf " Definition items: %7u" c.eabbrs);
120 L.warn level (KP.sprintf " Total term items: %7u" terms);
121 L.warn level (KP.sprintf " Sort items: %7u" c.tsorts);
122 L.warn level (KP.sprintf " Local reference items: %7u" c.tlrefs);
123 L.warn level (KP.sprintf " Global reference items: %7u" c.tgrefs);
124 L.warn level (KP.sprintf " Explicit Cast items: %7u" c.tcasts);
125 L.warn level (KP.sprintf " Application items: %7u" c.tappls);
126 L.warn level (KP.sprintf " Abstraction items: %7u" c.tabsts);
127 L.warn level (KP.sprintf " Abbreviation items: %7u" c.tabbrs);
128 L.warn level (KP.sprintf " Global Int. Complexity: %7u" c.nodes);
129 L.warn level (KP.sprintf " + Abbreviation nodes: %7u" nodes);
134 (* lenv/term pretty printing ************************************************)
138 | true -> KP.fprintf och "%s" n
139 | false -> KP.fprintf och "-%s" n
143 let pp_reduced och x =
144 if x then KP.fprintf och "%s" "^"
146 let pp_level st och n =
147 KP.fprintf och "%s" (N.to_string st n)
149 let rec pp_term st e och = function
151 let err _ = KP.fprintf och "*%u" k in
152 let f s = KP.fprintf och "%s" s in
153 H.string_of_sort err f k
155 let err _ = KP.fprintf och "#%u" i in
156 if !G.indexes then err () else
157 let _, _, _, y, b = B.get e i in
158 KP.fprintf och "%a" (name err) y
160 let u = U.string_of_uri s in
161 KP.fprintf och "$%s" (if !G.short then KF.basename u else u)
163 KP.fprintf och "<%a>.%a" (pp_term st e) u (pp_term st e) t
164 | B.Appl (_, v, t) ->
165 KP.fprintf och "(%a).%a" (pp_term st e) v (pp_term st e) t
166 | B.Bind (y, B.Abst (r, n, w), t) ->
167 let y = R.alpha B.mem e y in
168 let ee = B.push e B.empty E.empty_node y (B.abst r n w) in
169 KP.fprintf och "%a%a[%a:%a].%a" (pp_level st) n pp_reduced r (name C.start) y (pp_term st e) w (pp_term st ee) t
170 | B.Bind (y, B.Abbr v, t) ->
171 let y = R.alpha B.mem e y in
172 let ee = B.push e B.empty E.empty_node y (B.abbr v) in
173 KP.fprintf och "[%a=%a].%a" (name C.start) y (pp_term st e) v (pp_term st ee) t
174 | B.Bind (y, B.Void, t) ->
175 let y = R.alpha B.mem e y in
176 let ee = B.push e B.empty E.empty_node y B.Void in
177 KP.fprintf och "[%a].%a" (name C.start) y (pp_term st ee) t
179 let pp_lenv st och e =
180 let pp_entry f c a y b x =
181 let y = R.alpha B.mem e y in
182 let x = B.push x c a y b in
184 | B.Abst (_, _, w) ->
185 KP.fprintf och "[%a : %a] " (name C.start) y (pp_term st c) w; f x
187 KP.fprintf och "[%a = %a] " (name C.start) y (pp_term st c) v; f x
189 KP.fprintf och "[%a]" (name C.start) y; f x
191 if e = B.empty then KP.fprintf och "%s" "empty" else
192 B.fold_right ignore pp_entry e B.empty
195 L.pp_term = pp_term; L.pp_lenv = pp_lenv
200 (* term xml printing ********************************************************)
203 BD.crg_of_brg (XD.export_term st)