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_______________________________________________________________ *)
21 (* nodes count **************************************************************)
40 let initial_counters = {
41 eabsts = 0; eabbrs = 0; evoids = 0;
42 tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
43 tabsts = 0; tabbrs = 0; tvoids = 0;
44 uris = []; nodes = 0; xnodes = 0
47 let rec count_term f c e = function
49 f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
50 | D.TLRef (_, i, j) ->
51 begin match D.get e i with
52 | _, _, D.Abbr vs when j < List.length vs ->
53 f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
55 f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
59 if C.list_mem ~eq:U.eq u c.uris
60 then {c with nodes = succ c.nodes}
61 else {c with xnodes = succ c.xnodes}
63 f {c with tgrefs = succ c.tgrefs}
64 | D.TCast (_, v, t) ->
65 let c = {c with tcasts = succ c.tcasts} in
66 let f c = count_term f c e t in
68 | D.TAppl (_, vs, t) ->
69 let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
70 let f c = count_term f c e t in
71 C.list_fold_right f (map1 e) vs c
72 | D.TProj (a, d, t) ->
73 count_term f c e (D.tshift d t)
74 | D.TBind (a, b, t) ->
75 let f c e = count_term f c e t in
76 count_binder f c e a b
78 and count_binder f c e a = function
80 let k = List.length ws in
81 let c = {c with tabsts = c.tabsts + k; nodes = c.nodes + k} in
82 let e = D.push_bind C.start e a (D.Abst (n, [])) in
83 let f (c, e) = f c e in
84 C.list_fold_right f map2 ws (c, e)
86 let k = List.length vs in
87 let c = {c with tabbrs = c.tabbrs + k; xnodes = c.xnodes + k} in
88 let e = D.push_bind C.start e a (D.Abbr []) in
89 let f (c, e) = f c e in
90 C.list_fold_right f map2 vs (c, e)
92 let c = {c with tvoids = c.tvoids + k; xnodes = c.xnodes + k} in
93 let e = D.push_bind C.start e a (D.Void k) in
96 and map1 e f t c = count_term f c e t
99 let f c e = f (c, e) in
100 let f c = D.push2 C.err (f c) e ~t () in
103 let count_entity f c = function
104 | _, u, E.Abst (_, w) ->
106 eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
108 count_term f c D.ESort w
110 let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
111 count_term f c D.ESort v
112 | _, _, E.Void -> assert false
114 let print_counters f c =
116 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
119 let items = c.eabsts + c.eabbrs in
120 let nodes = c.nodes + c.xnodes in
121 L.warn (P.sprintf " Intermediate representation summary (crg)");
122 L.warn (P.sprintf " Total entry items: %7u" items);
123 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
124 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
125 L.warn (P.sprintf " Total term items: %7u" terms);
126 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
127 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
128 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
129 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
130 L.warn (P.sprintf " Application items: %7u" c.tappls);
131 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
132 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
133 L.warn (P.sprintf " Global Int. Complexity: %7u" c.nodes);
134 L.warn (P.sprintf " + Abbreviation nodes: %7u" nodes);
137 (* term/environment pretty printer ******************************************)
141 | E.Name (s, true) -> out (P.sprintf "%s;" s)
142 | E.Name (s, false) -> out (P.sprintf "~%s;" s)
143 | E.Apix i -> out (P.sprintf "+%i;" i)
144 | E.Mark i -> out (P.sprintf "@%i;" i)
150 let rec pp_term out = function
151 | D.TSort (a, l) -> pp_attrs out a; out (P.sprintf "*%u" l)
152 | D.TLRef (a, i, j) -> pp_attrs out a; out (P.sprintf "#(%u,%u)" i j)
153 | D.TGRef (a, u) -> pp_attrs out a; out (P.sprintf "$")
154 | D.TCast (a, x, y) -> pp_attrs out a; out "<"; pp_term out x; out ">."; pp_term out y
155 | D.TProj (a, x, y) -> assert false
156 | D.TAppl (a, x, y) -> pp_attrs out a; pp_terms "(" ")" out x; pp_term out y
157 | D.TBind (a, x, y) -> pp_attrs out a; pp_bind out x; pp_term out y
159 and pp_terms bg eg out vs =
160 let rec aux = function
162 | [v] -> pp_term out v
163 | v :: vs -> pp_term out v; out ", "; aux vs
165 out bg; aux vs; out (eg ^ ".")
167 and pp_bind out = function
168 | D.Abst (n, x) when N.is_infinite n -> pp_terms "[:" "]" out x
170 pp_terms "[:" (P.sprintf "]^%s" (N.to_string n)) out x
171 | D.Abbr x -> pp_terms "[=" "]" out x
172 | D.Void x -> out (P.sprintf "[%u]" x)
174 let rec pp_lenv out = function
176 | D.EProj (x, a, y) -> assert false
177 | D.EBind (x, a, y) -> pp_lenv out x; pp_attrs out a; pp_bind out y