]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/automath/autHelpers.ml
transformation from automath to intermediate language started
[helm.git] / helm / software / lambda-delta / automath / autHelpers.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 A = Aut
27
28 type counters = {
29    sections: int;
30    contexts: int;
31    blocks:   int;
32    decls:    int;
33    defs:     int;
34    sorts:    int;
35    grefs:    int;
36    appls:    int;
37    absts:    int
38 }
39
40 let initial_counters = {
41    sections = 0; contexts = 0; blocks = 0; decls = 0; defs = 0;
42    sorts = 0; grefs = 0; appls = 0; absts = 0
43 }
44
45 let rec count_term f c = function
46    | A.Sort _         -> 
47       f {c with sorts = succ c.sorts}
48    | A.GRef (_, ts)   -> 
49       let c = {c with grefs = succ c.grefs} in
50       Cps.list_fold_left f count_term c ts
51    | A.Appl (v, t)    -> 
52       let c = {c with appls = succ c.appls} in
53       let f c = count_term f c t in
54       count_term f c v
55    | A.Abst (_, w, t) -> 
56       let c = {c with absts = succ c.absts} in
57       let f c = count_term f c t in
58       count_term f c w
59
60 let count_item f c = function
61    | A.Section _        ->
62       f {c with sections = succ c.sections}
63    | A.Context _        ->
64       f {c with contexts = succ c.contexts}
65    | A.Block (_, w)     -> 
66       let c = {c with blocks = succ c.blocks} in
67       count_term f c w
68    | A.Decl (_, w)      -> 
69       let c = {c with decls = succ c.decls} in
70       count_term f c w
71    | A.Def (_, w, _, t) -> 
72       let c = {c with defs = succ c.defs} in
73       let f c = count_term f c t in
74       count_term f c w
75
76 let count f c b =
77    Cps.list_fold_left f count_item c b
78
79 let print_counters f c =
80    let terms = c.sorts + c.grefs + c.appls + c.absts in
81    let items = c.sections + c.contexts + c.blocks + c.decls + c.defs in
82    Printf.printf "  Automath representation summary\n";
83    Printf.printf "    Total book items:    %6u\n" items;
84    Printf.printf "      Section items:     %6u\n" c.sections;
85    Printf.printf "      Context items:     %6u\n" c.contexts;
86    Printf.printf "      Block items:       %6u\n" c.blocks;
87    Printf.printf "      Declaration items: %6u\n" c.decls;
88    Printf.printf "      Definition items:  %6u\n" c.defs;
89    Printf.printf "    Total term items:    %6u\n" terms;
90    Printf.printf "      Sort items:        %6u\n" c.sorts;
91    Printf.printf "      Reference items:   %6u\n" c.grefs;
92    Printf.printf "      Application items: %6u\n" c.appls;
93    Printf.printf "      Abstraction items: %6u\n" c.absts;
94    flush stdout; f ()