]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/automath/autHelpers.ml
Initial version of the Helena Checker
[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 list_fold_left f map a = function
46    | []       -> f a
47    | hd :: tl -> 
48       let f a = list_fold_left f map a tl in
49       map f a hd
50
51 let rec count_term f c = function
52    | A.Sort _         -> 
53       f {c with sorts = succ c.sorts}
54    | A.GRef (_, ts)   -> 
55       let c = {c with grefs = succ c.grefs} in
56       list_fold_left f count_term c ts
57    | A.Appl (v, t)    -> 
58       let c = {c with appls = succ c.appls} in
59       let f c = count_term f c t in
60       count_term f c v
61    | A.Abst (_, w, t) -> 
62       let c = {c with absts = succ c.absts} in
63       let f c = count_term f c t in
64       count_term f c w
65
66 let count_item f c = function
67    | A.Section _        ->
68       f {c with sections = succ c.sections}
69    | A.Context _        ->
70       f {c with contexts = succ c.contexts}
71    | A.Block (_, w)     -> 
72       let c = {c with blocks = succ c.blocks} in
73       count_term f c w
74    | A.Decl (_, w)      -> 
75       let c = {c with decls = succ c.decls} in
76       count_term f c w
77    | A.Def (_, w, _, t) -> 
78       let c = {c with defs = succ c.defs} in
79       let f c = count_term f c t in
80       count_term f c w
81
82 let count f c b =
83    list_fold_left f count_item c b
84
85 let print_counters f c =
86    let terms = c.sorts + c.grefs + c.appls + c.absts in
87    let items = c.sections + c.contexts + c.blocks + c.decls + c.defs in
88    Printf.printf "  Total book items:    %6u\n" items;
89    Printf.printf "    Section items:     %6u\n" c.sections;
90    Printf.printf "    Context items:     %6u\n" c.contexts;
91    Printf.printf "    Block items:       %6u\n" c.blocks;
92    Printf.printf "    Declaration items: %6u\n" c.decls;
93    Printf.printf "    Definition items:  %6u\n" c.defs;
94    Printf.printf "  Total term items:    %6u\n" terms;
95    Printf.printf "    Sort items:        %6u\n" c.sorts;
96    Printf.printf "    Reference items:   %6u\n" c.grefs;
97    Printf.printf "    Application items: %6u\n" c.appls;
98    Printf.printf "    Abstraction items: %6u\n" c.absts;
99    flush stdout; f ()