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