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/.
41 let initial_counters = {
42 eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
43 tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
46 let rec count_term f c = function
48 f {c with tsorts = succ c.tsorts}
50 f {c with tlrefs = succ c.tlrefs}
51 | M.GRef (_, _, ts) ->
52 let c = {c with tgrefs = succ c.tgrefs} in
53 let c = {c with pappls = c.pappls + List.length ts} in
54 Cps.list_fold_left f count_term c ts
56 let c = {c with tappls = succ c.tappls} in
57 let f c = count_term f c t in
60 let c = {c with tabsts = succ c.tabsts} in
61 let f c = count_term f c t in
64 let count_par f c (_, w) = count_term f c w
66 let count_entry f c = function
67 | _, pars, _, w, None ->
68 let c = {c with eabsts = succ c.eabsts} in
69 let c = {c with pabsts = c.pabsts + List.length pars} in
70 let f c = count_term f c w in
71 Cps.list_fold_left f count_par c pars
72 | _, pars, _, w, Some (_, v) ->
73 let c = {c with eabbrs = succ c.eabbrs} in
74 let c = {c with pabsts = c.pabsts + List.length pars} in
75 let f c = count_term f c v in
76 let f c = count_term f c w in
77 Cps.list_fold_left f count_par c pars
79 let count_item f c = function
80 | Some e -> count_entry f c e
83 let print_counters f c =
84 let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
85 let pars = c.pabsts + c.pappls in
86 let items = c.eabsts + c.eabbrs in
87 Printf.printf " Intermediate representation summary\n";
88 Printf.printf " Total entry items: %6u\n" items;
89 Printf.printf " Declaration items: %6u\n" c.eabsts;
90 Printf.printf " Definition items: %6u\n" c.eabbrs;
91 Printf.printf " Total parameter items: %6u\n" pars;
92 Printf.printf " Application items: %6u\n" c.pappls;
93 Printf.printf " Abstraction items: %6u\n" c.pabsts;
94 Printf.printf " Total term items: %6u\n" terms;
95 Printf.printf " Sort items: %6u\n" c.tsorts;
96 Printf.printf " Local reference items: %6u\n" c.tlrefs;
97 Printf.printf " Global reference items: %6u\n" c.tgrefs;
98 Printf.printf " Application items: %6u\n" c.tappls;
99 Printf.printf " Abstraction items: %6u\n" c.tabsts;
102 let string_of_sort = function
106 let string_of_qid (id, path) =
107 let path = String.concat "/" path in
108 Filename.concat path id
110 let string_of_transparent = function
114 let pp_list pp opend sep closed frm l =
115 let rec aux frm = function
118 | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl
120 if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
122 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
124 and pp_term frm = function
126 F.fprintf frm "@[*%s@]" (string_of_sort s)
128 F.fprintf frm "@[#%u@]" i
129 | M.GRef (l, qid, ts) ->
130 F.fprintf frm "@[%u@@$%s%a@]" l (string_of_qid qid) pp_args ts
132 F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
133 | M.Abst (id, w, t) ->
134 F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
136 let pp_par frm (qid, w) =
137 F.fprintf frm "%s:%a" (string_of_qid qid) pp_term w
139 let pp_pars = pp_list pp_par "[" "," "]"
141 let pp_body frm = function
144 F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
146 let pp_entry frm (l, pars, qid, u, body) =
147 F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!"
148 l (string_of_qid qid) pp_pars pars pp_body body pp_term u
150 let pp_item f frm = function
151 | Some entry -> pp_entry frm entry; f ()