]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_rg/brgOutput.ml
- we updated some preambles to match that of nUri.ml
[helm.git] / helm / software / lambda-delta / basic_rg / brgOutput.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 module B = Brg
13
14 type counters = {
15    eabsts: int;
16    eabbrs: int;
17    tsorts: int;
18    tlrefs: int;
19    tgrefs: int;
20    tcasts: int;
21    tappls: int;
22    tabsts: int;
23    tabbrs: int
24 }
25
26 let initial_counters = {
27    eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0;
28    tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0
29 }
30
31 let count_term_binder f c = function
32    | B.Abst -> f {c with tabsts = succ c.tabsts}
33    | B.Abbr -> f {c with tabbrs = succ c.tabbrs}
34
35 let rec count_term f c = function
36    | B.Sort _            -> 
37       f {c with tsorts = succ c.tsorts}
38    | B.LRef _            -> 
39       f {c with tlrefs = succ c.tlrefs}
40    | B.GRef _            -> 
41       f {c with tgrefs = succ c.tgrefs}
42    | B.Cast (v, t)       -> 
43       let c = {c with tcasts = succ c.tcasts} in
44       let f c = count_term f c t in
45       count_term f c v
46    | B.Appl (v, t)       -> 
47       let c = {c with tappls = succ c.tappls} in
48       let f c = count_term f c t in
49       count_term f c v
50    | B.Bind (_, b, u, t) -> 
51       let f c = count_term_binder f c b in
52       let f c = count_term f c t in
53       count_term f c u
54
55 let count_entry_binder f c = function
56    | B.Abst -> f {c with eabsts = succ c.eabsts}
57    | B.Abbr -> f {c with eabbrs = succ c.eabbrs}
58
59 let count_entry f c (_, b, t) =
60    let f c = count_entry_binder f c b in
61    count_term f c t
62
63 let count_item f c = function
64    | Some e -> count_entry f c e
65    | None   -> f c
66
67 let print_counters f c =
68    let terms =
69       c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
70       c.tabbrs
71    in
72    let items = c.eabsts + c.eabbrs in
73    Printf.printf "  Kernel representation summary (basic_rg)\n";
74    Printf.printf "    Total entry items:        %6u\n" items;
75    Printf.printf "      Declaration items:      %6u\n" c.eabsts;
76    Printf.printf "      Definition items:       %6u\n" c.eabbrs;
77    Printf.printf "    Total term items:         %6u\n" terms;
78    Printf.printf "      Sort items:             %6u\n" c.tsorts;
79    Printf.printf "      Local reference items:  %6u\n" c.tlrefs;
80    Printf.printf "      Global reference items: %6u\n" c.tgrefs;
81    Printf.printf "      Explicit Cast items:    %6u\n" c.tcasts;
82    Printf.printf "      Application items:      %6u\n" c.tappls;
83    Printf.printf "      Abstraction items:      %6u\n" c.tabsts;
84    Printf.printf "      Abbreviation items:     %6u\n" c.tabbrs;
85    flush stdout; f ()