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_______________________________________________________________ *)
30 let initial_counters = {
31 eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
32 tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
35 let rec count_term f c = function
37 f {c with tsorts = succ c.tsorts}
39 f {c with tlrefs = succ c.tlrefs}
40 | M.GRef (_, _, ts) ->
41 let c = {c with tgrefs = succ c.tgrefs} in
42 let c = {c with pappls = c.pappls + List.length ts} in
43 Cps.list_fold_left f count_term c ts
45 let c = {c with tappls = succ c.tappls} in
46 let f c = count_term f c t in
49 let c = {c with tabsts = succ c.tabsts} in
50 let f c = count_term f c t in
53 let count_par f c (_, w) = count_term f c w
55 let count_entry f c = function
56 | _, pars, _, w, None ->
57 let c = {c with eabsts = succ c.eabsts} in
58 let c = {c with pabsts = c.pabsts + List.length pars} in
59 let f c = count_term f c w in
60 Cps.list_fold_left f count_par c pars
61 | _, pars, _, w, Some (_, v) ->
62 let c = {c with eabbrs = succ c.eabbrs} in
63 let c = {c with pabsts = c.pabsts + List.length pars} in
64 let f c = count_term f c v in
65 let f c = count_term f c w in
66 Cps.list_fold_left f count_par c pars
68 let count_item f c = function
69 | Some e -> count_entry f c e
72 let print_counters f c =
73 let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
74 let pars = c.pabsts + c.pappls in
75 let items = c.eabsts + c.eabbrs in
76 L.warn (P.sprintf " Intermediate representation summary");
77 L.warn (P.sprintf " Total entry items: %6u" items);
78 L.warn (P.sprintf " Declaration items: %6u" c.eabsts);
79 L.warn (P.sprintf " Definition items: %6u" c.eabbrs);
80 L.warn (P.sprintf " Total parameter items: %6u" pars);
81 L.warn (P.sprintf " Application items: %6u" c.pappls);
82 L.warn (P.sprintf " Abstraction items: %6u" c.pabsts);
83 L.warn (P.sprintf " Total term items: %6u" terms);
84 L.warn (P.sprintf " Sort items: %6u" c.tsorts);
85 L.warn (P.sprintf " Local reference items: %6u" c.tlrefs);
86 L.warn (P.sprintf " Global reference items: %6u" c.tgrefs);
87 L.warn (P.sprintf " Application items: %6u" c.tappls);
88 L.warn (P.sprintf " Abstraction items: %6u" c.tabsts);
91 let string_of_sort = function
95 let string_of_transparent = function
99 let pp_list pp opend sep closed frm l =
100 let rec aux frm = function
103 | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl
105 if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
107 let pp_rev_list pp opend sep closed frm l =
108 pp_list pp opend sep closed frm (List.rev l)
110 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
112 and pp_term frm = function
114 F.fprintf frm "@[*%s@]" (string_of_sort s)
116 F.fprintf frm "@[%u@@#%u@]" l i
117 | M.GRef (l, uri, ts) ->
118 F.fprintf frm "@[%u@@$%s%a@]" l (U.string_of_uri uri) pp_args ts
120 F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
121 | M.Abst (id, w, t) ->
122 F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
124 let pp_par frm (id, w) =
125 F.fprintf frm "%s:%a" id pp_term w
127 let pp_pars = pp_rev_list pp_par "[" "," "]"
129 let pp_body frm = function
132 F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
134 let pp_entry frm (l, pars, uri, u, body) =
135 F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!"
136 l (U.string_of_uri uri) pp_pars pars pp_body body pp_term u
138 let pp_item f frm = function
139 | Some entry -> pp_entry frm entry; f ()