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_______________________________________________________________ *)
22 (* nodes count **************************************************************)
43 let initial_counters = {
44 eabsts = 0; eabbrs = 0; evoids = 0;
45 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
46 tabsts = 0; tabbrs = 0; tvoids = 0;
47 uris = []; nodes = 0; xnodes = 0
52 let rec count_term f c e = function
54 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
56 begin match D.get e i with
57 | _, _, _, D.Abbr _ ->
58 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
60 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
64 if C.list_mem ~eq:U.eq u c.uris
65 then {c with nodes = succ c.nodes}
66 else {c with xnodes = succ c.xnodes}
68 f {c with tgrefs = succ c.tgrefs}
70 let c = {c with tcasts = succ c.tcasts} in
71 let f c = count_term f c e t in
73 | D.TAppl (_, v, t) ->
74 let c = {c with tappls = succ c.tappls} in
75 let f c = count_term f c e t in
78 D.shift (count_term f c e) d t
79 | D.TBind (y, b, t) ->
80 let f c e = count_term f c e t in
81 count_binder f c e y b
83 and count_binder f c e y b = match b with
85 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
86 let f c = D.push_bind (f c) E.empty_node y b e in
89 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
90 let f c = D.push_bind (f c) E.empty_node y b e in
93 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
94 D.push_bind (f c) E.empty_node y b e
96 let count_entity f c = function
97 | _, _, u, E.Abst w ->
99 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
101 count_term f c D.ESort w
102 | _, _, _, E.Abbr v ->
103 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
104 count_term f c D.ESort v
105 | _, _, _, E.Void -> assert false
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 let marks = P.marks () in
115 L.warn level (KP.sprintf "Intermediate representation summary (complete_rg)");
116 L.warn level (KP.sprintf " Total entry items: %7u" items);
117 L.warn level (KP.sprintf " Declaration items: %7u" c.eabsts);
118 L.warn level (KP.sprintf " Definition items: %7u" c.eabbrs);
119 L.warn level (KP.sprintf " Total term items: %7u" terms);
120 L.warn level (KP.sprintf " Sort items: %7u" c.tsorts);
121 L.warn level (KP.sprintf " Local reference items: %7u" c.tlrefs);
122 L.warn level (KP.sprintf " Global reference items: %7u" c.tgrefs);
123 L.warn level (KP.sprintf " Explicit Cast items: %7u" c.tcasts);
124 L.warn level (KP.sprintf " Application items: %7u" c.tappls);
125 L.warn level (KP.sprintf " Abstraction items: %7u" c.tabsts);
126 L.warn level (KP.sprintf " Abbreviation items: %7u" c.tabbrs);
127 L.warn level (KP.sprintf " Ambiguous abstractions: %7u" marks);
128 L.warn level (KP.sprintf " Global Int. Complexity: %7u" c.nodes);
129 L.warn level (KP.sprintf " + Abbreviation nodes: %7u" nodes);
134 (* term/environment pretty printer ******************************************)
136 let pp_b_attrs out a =
137 let f s b = if b then out (KP.sprintf "%s;" s) else out (KP.sprintf "~%s;" s) in
140 let pp_n_attrs out a =
141 out (KP.sprintf "+%i;" a.E.n_apix)
143 let pp_state out x = if x then out "^"
145 let rec pp_term out st = function
146 | D.TSort k -> out (KP.sprintf "*%u" k)
147 | D.TLRef (a, i) -> pp_n_attrs out a; out (KP.sprintf "#%u" i)
148 | D.TGRef (a, u) -> pp_n_attrs out a; out (KP.sprintf "$")
149 | D.TCast (u, t) -> out "<"; pp_term out st u; out ">."; pp_term out st t
150 | D.TAppl (_, u, t) -> out "("; pp_term out st u; out ")."; pp_term out st t
151 | D.TBind (y, u, t) -> pp_b_attrs out y; pp_bind out st u; out "."; pp_term out st t
152 | D.TProj (u, t) -> out "{"; pp_lenv out st u; out "}."; pp_term out st t
154 and pp_bind out st = function
155 | D.Abst (r, n, u) ->
156 out "[:"; pp_term out st u; out "]"; pp_state out r; out (N.to_string st n); out " "
157 | D.Abbr u -> out "[="; pp_term out st u; out "] ";
158 | D.Void -> out "[] "
160 and pp_lenv out st = function
162 | D.EBind (u, a, y, t) -> pp_lenv out st u; pp_b_attrs out y; pp_n_attrs out a; pp_bind out st t
163 | D.EAppl (u, _, t) -> pp_lenv out st u; out "("; pp_term out st t; out ") "
164 | D.EProj (u, t) -> pp_lenv out st u; out "{"; pp_lenv out st t; out "} "