]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/metaOutput.ml
- nodes count is now working for aut and meta
[helm.git] / helm / software / lambda-delta / toplevel / metaOutput.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 F = Format
14 module U = NUri
15 module L = Log
16 module M = Meta
17
18 type counters = {
19    eabsts: int;
20    eabbrs: int;
21    pabsts: int;    
22    tsorts: int;
23    tlrefs: int;
24    tgrefs: int;
25    pappls: int;
26    tappls: int;
27    tabsts: int;
28    uris  : U.uri list;
29    nodes : int;
30    xnodes: int
31 }
32
33 let initial_counters = {
34    eabsts = 0; eabbrs = 0; pabsts = 0; pappls = 0;
35    tsorts = 0; tlrefs = 0; tgrefs = 0; tappls = 0; tabsts = 0;
36    uris = []; nodes = 0; xnodes = 0
37 }
38
39 let rec count_term f c = function
40    | M.Sort _          -> 
41       f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
42    | M.LRef _          -> 
43       f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
44    | M.GRef (_, u, ts) -> 
45       let c = {c with tgrefs = succ c.tgrefs} in
46       let c = {c with pappls = c.pappls + List.length ts} in
47       let c = {c with nodes = c.nodes + List.length ts} in
48       let c =    
49          if Cps.list_mem ~eq:U.eq u c.uris
50          then {c with nodes = succ c.nodes}
51          else {c with xnodes = succ c.xnodes}
52       in
53       Cps.list_fold_left f count_term c ts
54    | M.Appl (v, t)     -> 
55       let c = {c with tappls = succ c.tappls; nodes = succ c.nodes} in
56       let f c = count_term f c t in
57       count_term f c v
58    | M.Abst (_, w, t)  -> 
59       let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
60       let f c = count_term f c t in
61       count_term f c w
62
63 let count_par f c (_, w) = 
64    let c = {c with nodes = succ c.nodes} in
65    count_term f c w
66
67 let count_entry f c = function
68    | _, pars, u, w, None        ->
69       let c = {c with eabsts = succ c.eabsts} in
70       let c = {c with pabsts = c.pabsts + List.length pars} in
71       let c = {c with uris = u :: c.uris; nodes = succ c.nodes + List.length pars} in
72       let f c = count_term f c w in
73       Cps.list_fold_left f count_par c pars   
74    | _, pars, _, w, Some (_, v) ->
75       let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
76       let c = {c with pabsts = c.pabsts + List.length pars} in
77       let c = {c with nodes = c.nodes + List.length pars} in
78       let f c = count_term f c v in
79       let f c = count_term f c w in
80       Cps.list_fold_left f count_par c pars
81
82 let count_item f c = function
83    | Some e -> count_entry f c e
84    | None   -> f c
85
86 let print_counters f c =
87    let terms = c.tsorts + c.tgrefs + c.tgrefs + c.tappls + c.tabsts in
88    let pars = c.pabsts + c.pappls in
89    let items = c.eabsts + c.eabbrs in
90    let nodes = c.nodes + c.xnodes in
91    L.warn (P.sprintf "  Intermediate representation summary");
92    L.warn (P.sprintf "    Total entry items:        %7u" items);
93    L.warn (P.sprintf "      Declaration items:      %7u" c.eabsts);
94    L.warn (P.sprintf "      Definition items:       %7u" c.eabbrs);
95    L.warn (P.sprintf "    Total parameter items:    %7u" pars);
96    L.warn (P.sprintf "      Application items:      %7u" c.pappls);
97    L.warn (P.sprintf "      Abstraction items:      %7u" c.pabsts);
98    L.warn (P.sprintf "    Total term items:         %7u" terms);
99    L.warn (P.sprintf "      Sort items:             %7u" c.tsorts);
100    L.warn (P.sprintf "      Local reference items:  %7u" c.tlrefs);
101    L.warn (P.sprintf "      Global reference items: %7u" c.tgrefs);
102    L.warn (P.sprintf "      Application items:      %7u" c.tappls);
103    L.warn (P.sprintf "      Abstraction items:      %7u" c.tabsts);
104    L.warn (P.sprintf "    Global Int. Complexity:   %7u" c.nodes);
105    L.warn (P.sprintf "      + Abbreviation nodes:   %7u" nodes);
106    f ()
107
108 let string_of_sort = function
109    | true -> "Type"
110    | false -> "Prop"
111
112 let string_of_transparent = function
113    | true  -> "="
114    | false -> "~"
115
116 let pp_list pp opend sep closed frm l =
117    let rec aux frm = function
118       | []       -> ()
119       | [hd]     -> pp frm hd
120       | hd :: tl -> F.fprintf frm "%a%s%a" pp hd sep aux tl 
121    in
122    if l = [] then () else F.fprintf frm "%s%a%s" opend aux l closed
123
124 let pp_rev_list pp opend sep closed frm l =
125    pp_list pp opend sep closed frm (List.rev l)
126
127 let rec pp_args frm args = pp_list pp_term "(" "," ")" frm args
128
129 and pp_term frm = function
130    | M.Sort s            -> 
131       F.fprintf frm "@[*%s@]" (string_of_sort s)
132    | M.LRef (l, i)       ->
133       F.fprintf frm "@[%u@@#%u@]" l i
134    | M.GRef (l, uri, ts) ->
135       F.fprintf frm "@[%u@@$%s%a@]" l (U.string_of_uri uri) pp_args ts
136    | M.Appl (v, t)       ->
137       F.fprintf frm "@[(%a).%a@]" pp_term v pp_term t
138    | M.Abst (id, w, t)   ->
139       F.fprintf frm "@[[%s:%a].%a@]" id pp_term w pp_term t
140
141 let pp_par frm (id, w) =
142     F.fprintf frm "%s:%a" id pp_term w
143
144 let pp_pars = pp_rev_list pp_par "[" "," "]"
145
146 let pp_body frm = function
147    | None            -> ()
148    | Some (trans, t) ->
149       F.fprintf frm "%s%a" (string_of_transparent trans) pp_term t
150
151 let pp_entry frm (l, pars, uri, u, body) =
152    F.fprintf frm "@[%u@@%s%a%a:%a@]@\n%!" 
153       l (U.string_of_uri uri) pp_pars pars pp_body body pp_term u
154
155 let pp_item f frm = function 
156    | Some entry -> pp_entry frm entry; f ()
157    | None       -> f ()