]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/metaOutput.ml
lambda-delta/toplevel: improved transformation from automath (20 secs gained)
[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 U = NUri
28 module M = Meta
29
30 type counters = {
31    eabsts: int;
32    eabbrs: int;
33    pabsts: int;    
34    tsorts: int;
35    tlrefs: int;
36    tgrefs: int;
37    pappls: int;
38    tappls: int;
39    tabsts: int;
40 }
41
42 let initial_counters = {
43    eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
44    tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0
45 }
46
47 let rec count_term f c = function
48    | M.Sort _          -> 
49       f {c with tsorts = succ c.tsorts}
50    | M.LRef _          -> 
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
56    | M.Appl (v, t)     -> 
57       let c = {c with tappls = succ c.tappls} in
58       let f c = count_term f c t in
59       count_term f c v
60    | M.Abst (_, w, t)  -> 
61       let c = {c with tabsts = succ c.tabsts} in
62       let f c = count_term f c t in
63       count_term f c w
64
65 let count_par f c (_, w) = count_term f c w
66
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
79
80 let count_item f c = function
81    | Some e -> count_entry f c e
82    | None   -> f c
83
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;
101    flush stdout; f ()
102
103 let string_of_sort = function
104    | true -> "Type"
105    | false -> "Prop"
106
107 let string_of_transparent = function
108    | true  -> "="
109    | false -> "~"
110
111 let pp_list pp opend sep closed frm l =
112    let rec aux frm = function
113       | []       -> ()
114       | [hd]     -> pp frm hd
115       | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl 
116    in
117    if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
118
119 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
120
121 and pp_term frm = function
122    | M.Sort s            -> 
123       F.fprintf frm "@[*%s@]" (string_of_sort s)
124    | M.LRef (l, i)       ->
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
128    | M.Appl (v, t)       ->
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
132
133 let pp_par frm (id, w) =
134     F.fprintf frm "%s:%a" id pp_term w
135
136 let pp_pars = pp_list pp_par "[" "," "]"
137
138 let pp_body frm = function
139    | None            -> ()
140    | Some (trans, t) ->
141       F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
142
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
146
147 let pp_item f frm = function 
148    | Some entry -> pp_entry frm entry; f ()
149    | None       -> f ()