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
50 let rec count_term f c e = function
52 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
54 begin match D.get e i with
56 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
58 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
62 if C.list_mem ~eq:U.eq u c.uris
63 then {c with nodes = succ c.nodes}
64 else {c with xnodes = succ c.xnodes}
66 f {c with tgrefs = succ c.tgrefs}
67 | D.TCast (_, v, t) ->
68 let c = {c with tcasts = succ c.tcasts} in
69 let f c = count_term f c e t in
71 | D.TAppl (_, _, v, t) ->
72 let c = {c with tappls = succ c.tappls} in
73 let f c = count_term f c e t in
75 | D.TProj (_, d, t) ->
76 D.shift (count_term f c e) d t
77 | D.TBind (a, b, t) ->
78 let f c e = count_term f c e t in
79 count_binder f c e a b
81 and count_binder f c e a b = match b with
83 let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
84 let f c = D.push_bind (f c) a b e in
87 let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
88 let f c = D.push_bind (f c) a b e in
91 let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
92 D.push_bind (f c) a b e
94 let count_entity f c = function
95 | _, _, u, E.Abst w ->
97 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
99 count_term f c D.ESort w
100 | _, _, _, E.Abbr v ->
101 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
102 count_term f c D.ESort v
103 | _, _, _, E.Void -> assert false
105 let print_counters f c =
107 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
110 let items = c.eabsts + c.eabbrs in
111 let nodes = c.nodes + c.xnodes in
112 let marks = P.marks () in
113 L.warn level (KP.sprintf "Intermediate representation summary (complete_rg)");
114 L.warn level (KP.sprintf " Total entry items: %7u" items);
115 L.warn level (KP.sprintf " Declaration items: %7u" c.eabsts);
116 L.warn level (KP.sprintf " Definition items: %7u" c.eabbrs);
117 L.warn level (KP.sprintf " Total term items: %7u" terms);
118 L.warn level (KP.sprintf " Sort items: %7u" c.tsorts);
119 L.warn level (KP.sprintf " Local reference items: %7u" c.tlrefs);
120 L.warn level (KP.sprintf " Global reference items: %7u" c.tgrefs);
121 L.warn level (KP.sprintf " Explicit Cast items: %7u" c.tcasts);
122 L.warn level (KP.sprintf " Application items: %7u" c.tappls);
123 L.warn level (KP.sprintf " Abstraction items: %7u" c.tabsts);
124 L.warn level (KP.sprintf " Abbreviation items: %7u" c.tabbrs);
125 L.warn level (KP.sprintf " Ambiguous abstractions: %7u" marks);
126 L.warn level (KP.sprintf " Global Int. Complexity: %7u" c.nodes);
127 L.warn level (KP.sprintf " + Abbreviation nodes: %7u" nodes);
130 (* term/environment pretty printer ******************************************)
133 let f s b = if b then out (KP.sprintf "%s;" s) else out (KP.sprintf "~%s;" s) in
135 out (KP.sprintf "+%i;" a.E.n_apix)
137 let pp_state out x = if x then out "^"
139 let rec pp_term out st = function
140 | D.TSort (a, l) -> pp_attrs out a; out (KP.sprintf "*%u" l)
141 | D.TLRef (a, i ) -> pp_attrs out a; out (KP.sprintf "#%u" i)
142 | D.TGRef (a, u) -> pp_attrs out a; out (KP.sprintf "$")
143 | D.TCast (a, u, t) -> pp_attrs out a; out "<"; pp_term out st u; out ">."; pp_term out st t
144 | D.TAppl (a, _, u, t) -> pp_attrs out a; out "("; pp_term out st u; out ")."; pp_term out st t
145 | D.TBind (a, u, t) -> pp_attrs out a; pp_bind out st u; out "."; pp_term out st t
146 | D.TProj (a, u, t) -> pp_attrs out a; out "{"; pp_lenv out st u; out "}."; pp_term out st t
148 and pp_bind out st = function
149 | D.Abst (r, n, u) ->
150 out "[:"; pp_term out st u; out "]"; pp_state out r; out (N.to_string st n); out " "
151 | D.Abbr u -> out "[="; pp_term out st u; out "] ";
152 | D.Void -> out "[] "
154 and pp_lenv out st = function
156 | D.EBind (u, a, t) -> pp_lenv out st u; pp_attrs out a; pp_bind out st t
157 | D.EAppl (u, a, _, t) -> pp_lenv out st u; out "("; pp_term out st t; out ") "
158 | D.EProj (u, a, t) -> pp_lenv out st u; out "{"; pp_lenv out st t; out "} "