]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/automath/autOutput.ml
Additional contribs.
[helm.git] / helm / software / lambda-delta / automath / autOutput.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 P = Printf
13 module C = Cps
14 module L = Log
15 module A = Aut
16 module R = AutProcess
17
18 type counters = {
19    sections: int;
20    contexts: int;
21    blocks:   int;
22    decls:    int;
23    defs:     int;
24    sorts:    int;
25    grefs:    int;
26    appls:    int;
27    absts:    int;
28    pars:     int;
29    xnodes:   int
30 }
31
32 let initial_counters = {
33    sections = 0; contexts = 0; blocks = 0; decls = 0; defs = 0;
34    sorts = 0; grefs = 0; appls = 0; absts = 0; pars = 0; xnodes = 0
35 }
36
37 let rec count_term f c = function
38    | A.Sort _         -> 
39       f {c with sorts = succ c.sorts; xnodes = succ c.xnodes}
40    | A.GRef (_, ts)   -> 
41       let c = {c with grefs = succ c.grefs} in
42       let c = {c with pars = c.pars + List.length ts} in
43       let c = {c with xnodes = succ c.xnodes + List.length ts} in
44       C.list_fold_left f count_term c ts
45    | A.Appl (v, t)    -> 
46       let c = {c with appls = succ c.appls; xnodes = succ c.xnodes} in
47       let f c = count_term f c t in
48       count_term f c v
49    | A.Abst (_, w, t) -> 
50       let c = {c with absts = succ c.absts; xnodes = succ c.xnodes} in
51       let f c = count_term f c t in
52       count_term f c w
53
54 let count_entity f c = function
55    | A.Section _        ->
56       f {c with sections = succ c.sections}
57    | A.Context _        ->
58       f {c with contexts = succ c.contexts}
59    | A.Block (_, w)     -> 
60       let c = {c with blocks = succ c.blocks; xnodes = succ c.xnodes} in
61       count_term f c w
62    | A.Decl (_, w)      -> 
63       let c = {c with decls = succ c.decls; xnodes = succ c.xnodes} in
64       count_term f c w
65    | A.Def (_, w, _, t) -> 
66       let c = {c with defs = succ c.defs; xnodes = succ c.xnodes} in
67       let f c = count_term f c t in
68       count_term f c w
69
70 let print_counters f c =
71    let terms = c.sorts + c.grefs + c.appls + c.absts in
72    let entities = c.sections + c.contexts + c.blocks + c.decls + c.defs in
73    L.warn (P.sprintf "  Automath representation summary");
74    L.warn (P.sprintf "    Total book entities:      %7u" entities);
75    L.warn (P.sprintf "      Section entities:       %7u" c.sections);
76    L.warn (P.sprintf "      Context entities:       %7u" c.contexts);
77    L.warn (P.sprintf "      Block entities:         %7u" c.blocks);
78    L.warn (P.sprintf "      Declaration entities:   %7u" c.decls);
79    L.warn (P.sprintf "      Definition entities:    %7u" c.defs);
80    L.warn (P.sprintf "    Total Parameter items:    %7u" c.pars);
81    L.warn (P.sprintf "      Application items:      %7u" c.pars);
82    L.warn (P.sprintf "    Total term items:         %7u" terms);
83    L.warn (P.sprintf "      Sort items:             %7u" c.sorts);
84    L.warn (P.sprintf "      Reference items:        %7u" c.grefs);
85    L.warn (P.sprintf "      Application items:      %7u" c.appls);
86    L.warn (P.sprintf "      Abstraction items:      %7u" c.absts);
87    L.warn (P.sprintf "    Global Int. Complexity:   unknown");
88    L.warn (P.sprintf "      + Abbreviation nodes:   %7u" c.xnodes);
89    f ()
90
91 let print_process_counters f c =
92    let f iao iar iac iag =
93       L.warn (P.sprintf "  Automath process summary");
94       L.warn (P.sprintf "    Implicit after opening:   %7u" iao);
95       L.warn (P.sprintf "    Implicit after reopening: %7u" iar);
96       L.warn (P.sprintf "    Implicit after closing:   %7u" iac);
97       L.warn (P.sprintf "    Implicit after global:    %7u" iag);
98       f ()
99    in
100    R.get_counters f c