1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
42 let initial_counters = {
43 eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
44 tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
47 let rec count_term f c = function
49 f {c with tsorts = succ c.tsorts}
51 f {c with tlrefs = succ c.tlrefs}
52 | M.GRef (_, _, ts) ->
53 let c = {c with tgrefs = succ c.tgrefs} in
54 let c = {c with pappls = c.pappls + List.length ts} in
55 Cps.list_fold_left f count_term c ts
57 let c = {c with tappls = succ c.tappls} in
58 let f c = count_term f c t in
61 let c = {c with tabsts = succ c.tabsts} in
62 let f c = count_term f c t in
65 let count_par f c (_, w) = count_term f c w
67 let count_entry f c = function
68 | _, pars, _, w, None ->
69 let c = {c with eabsts = succ c.eabsts} in
70 let c = {c with pabsts = c.pabsts + List.length pars} in
71 let f c = count_term f c w in
72 Cps.list_fold_left f count_par c pars
73 | _, pars, _, w, Some (_, v) ->
74 let c = {c with eabbrs = succ c.eabbrs} in
75 let c = {c with pabsts = c.pabsts + List.length pars} in
76 let f c = count_term f c v in
77 let f c = count_term f c w in
78 Cps.list_fold_left f count_par c pars
80 let count_item f c = function
81 | Some e -> count_entry f c e
84 let print_counters f c =
85 let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
86 let pars = c.pabsts + c.pappls in
87 let items = c.eabsts + c.eabbrs in
88 Printf.printf " Intermediate representation summary\n";
89 Printf.printf " Total entry items: %6u\n" items;
90 Printf.printf " Declaration items: %6u\n" c.eabsts;
91 Printf.printf " Definition items: %6u\n" c.eabbrs;
92 Printf.printf " Total parameter items: %6u\n" pars;
93 Printf.printf " Application items: %6u\n" c.pappls;
94 Printf.printf " Abstraction items: %6u\n" c.pabsts;
95 Printf.printf " Total term items: %6u\n" terms;
96 Printf.printf " Sort items: %6u\n" c.tsorts;
97 Printf.printf " Local reference items: %6u\n" c.tlrefs;
98 Printf.printf " Global reference items: %6u\n" c.tgrefs;
99 Printf.printf " Application items: %6u\n" c.tappls;
100 Printf.printf " Abstraction items: %6u\n" c.tabsts;
103 let string_of_sort = function
107 let string_of_transparent = function
111 let pp_list pp opend sep closed frm l =
112 let rec aux frm = function
115 | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl
117 if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
119 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
121 and pp_term frm = function
123 F.fprintf frm "@[*%s@]" (string_of_sort s)
125 F.fprintf frm "@[%u@@#%u@]" l i
126 | M.GRef (l, uri, ts) ->
127 F.fprintf frm "@[%u@@$%s%a@]" l (U.string_of_uri uri) pp_args ts
129 F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
130 | M.Abst (id, w, t) ->
131 F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
133 let pp_par frm (id, w) =
134 F.fprintf frm "%s:%a" id pp_term w
136 let pp_pars = pp_list pp_par "[" "," "]"
138 let pp_body frm = function
141 F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
143 let pp_entry frm (l, pars, uri, u, body) =
144 F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!"
145 l (U.string_of_uri uri) pp_pars pars pp_body body pp_term u
147 let pp_item f frm = function
148 | Some entry -> pp_entry frm entry; f ()