]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/metaOutput.ml
4efee4a6833e511ba53428c3670cc2aec2e79082
[helm.git] / helm / software / lambda-delta / toplevel / metaOutput.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 module F = Format
27 module M = Meta
28
29 type counters = {
30    eabsts: int;
31    eabbrs: int;
32    pabsts: int;    
33    tsorts: int;
34    tlrefs: int;
35    tgrefs: int;
36    pappls: int;
37    tappls: int;
38    tabsts: int;
39 }
40
41 let initial_counters = {
42    eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
43    tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
44 }
45
46 let rec count_term f c = function
47    | M.Sort _          -> 
48       f {c with tsorts = succ c.tsorts}
49    | M.LRef _          -> 
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
55    | M.Appl (v, t)     -> 
56       let c = {c with tappls = succ c.tappls} in
57       let f c = count_term f c t in
58       count_term f c v
59    | M.Abst (_, w, t)  -> 
60       let c = {c with tabsts = succ c.tabsts} in
61       let f c = count_term f c t in
62       count_term f c w
63
64 let count_par f c (_, w) = count_term f c w
65
66 let count_item 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
78
79 let count f c b =
80    Cps.list_fold_left f count_item c b
81
82 let print_counters f c =
83    let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
84    let pars = c.pabsts + c.pappls in
85    let items = c.eabsts + c.eabbrs in
86    Printf.printf "  Intermediate representation summary\n";
87    Printf.printf "    Total entry items:        %6u\n" items;
88    Printf.printf "      Declaration items:      %6u\n" c.eabsts;
89    Printf.printf "      Definition items:       %6u\n" c.eabbrs;
90    Printf.printf "    Total parameter items:    %6u\n" pars;
91    Printf.printf "      Application items:      %6u\n" c.pappls;
92    Printf.printf "      Abstraction items:      %6u\n" c.pabsts;
93    Printf.printf "    Total term items:         %6u\n" terms;
94    Printf.printf "      Sort items:             %6u\n" c.tsorts;
95    Printf.printf "      Local reference items:  %6u\n" c.tlrefs;
96    Printf.printf "      Global reference items: %6u\n" c.tgrefs;
97    Printf.printf "      Application items:      %6u\n" c.tappls;
98    Printf.printf "      Abstraction items:      %6u\n" c.tabsts;
99    flush stdout; f ()
100
101 let string_of_sort = function
102    | true -> "Type"
103    | false -> "Prop"
104
105 let string_of_qid (id, path) =
106    let path = String.concat "/" path in
107    Filename.concat path id
108
109 let string_of_transparent = function
110    | true  -> "="
111    | false -> "~"
112
113 let pp_list pp opend sep closed frm l =
114    let rec aux frm = function
115       | []       -> ()
116       | [hd]     -> pp frm hd
117       | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl 
118    in
119    if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
120
121 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
122
123 and pp_term frm = function
124    | M.Sort s            -> 
125       F.fprintf frm "@[*%s@]" (string_of_sort s)
126    | M.LRef i            ->
127       F.fprintf frm "@[#%u@]" i
128    | M.GRef (l, qid, ts) ->
129       F.fprintf frm "@[%u@@$%s%a@]" l (string_of_qid qid) pp_args ts
130    | M.Appl (v, t)       ->
131       F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
132    | M.Abst (id, w, t)   ->
133       F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
134
135 let pp_par frm (qid, w) =
136     F.fprintf frm "%s:%a" (string_of_qid qid) pp_term w
137
138 let pp_pars = pp_list pp_par "[" "," "]"
139
140 let pp_body frm = function
141    | None            -> ()
142    | Some (trans, t) ->
143       F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
144
145 let pp_item frm (l, pars, qid, u, body) =
146    F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!" 
147       l (string_of_qid qid) pp_pars pars pp_body body pp_term u
148
149 let pp_environment f frm genv =
150    List.iter (pp_item frm) genv; f ()