]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/complete_rg/crgOutput.ml
update in helena
[helm.git] / helm / software / helena / src / complete_rg / crgOutput.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 KP = Printf
13
14 module U = NUri
15 module C = Cps
16 module L = Log
17 module P = Marks
18 module N = Layer
19 module E = Entity
20 module D = Crg
21
22 (* nodes count **************************************************************)
23
24 let level = 2
25
26 type counters = {
27    eabsts: int;
28    eabbrs: int;
29    evoids: int;
30    tsorts: int;
31    tlrefs: int;
32    tgrefs: int;
33    tcasts: int;
34    tappls: int;
35    tabsts: int;
36    tabbrs: int;
37    tvoids: int;
38    uris  : D.uri list;
39    nodes : int;
40    xnodes: int
41 }
42
43 let initial_counters = {
44    eabsts = 0; eabbrs = 0; evoids = 0; 
45    tsorts = 0; tlrefs = 0; tgrefs = 0; tcasts = 0; tappls = 0;
46    tabsts = 0; tabbrs = 0; tvoids = 0;
47    uris = []; nodes = 0; xnodes = 0
48 }
49
50 IFDEF SUMMARY THEN
51
52 let rec count_term f c e = function
53    | D.TSort _         -> 
54       f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
55    | D.TLRef (_, i)    -> 
56       begin match D.get e i with
57          | _, _, _, D.Abbr _ ->
58             f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
59          | _                 ->
60             f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
61       end      
62    | D.TGRef (_, u)    -> 
63       let c =    
64          if C.list_mem ~eq:U.eq u c.uris
65          then {c with nodes = succ c.nodes}
66          else {c with xnodes = succ c.xnodes}
67       in
68       f {c with tgrefs = succ c.tgrefs}
69    | D.TCast (v, t)    -> 
70       let c = {c with tcasts = succ c.tcasts} in
71       let f c = count_term f c e t in
72       count_term f c e v
73    | D.TAppl (_, v, t) -> 
74       let c = {c with tappls = succ c.tappls} in
75       let f c = count_term f c e t in
76       count_term f c e v
77    | D.TProj (d, t)    ->
78       D.shift (count_term f c e) d t
79    | D.TBind (y, b, t) -> 
80       let f c e = count_term f c e t in
81       count_binder f c e y b
82
83 and count_binder f c e y b = match b with
84    | D.Abst (_, _, w) ->
85       let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
86       let f c = D.push_bind (f c) E.empty_node y b e in
87       count_term f c e w
88    | D.Abbr v         -> 
89       let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
90       let f c = D.push_bind (f c) E.empty_node y b e in
91       count_term f c e v     
92    | D.Void           ->
93       let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
94       D.push_bind (f c) E.empty_node y b e
95
96 let count_entity f c = function
97    | _, _, u, E.Abst (_, w) -> 
98       let c = {c with
99          eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
100       } in
101       count_term f c D.ESort w
102    | _, _, _, E.Abbr (_, v) ->  
103       let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
104       count_term f c D.ESort v
105    | _, _, _, E.Void        -> assert false
106
107 let print_counters f c =
108    let terms =
109       c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
110       c.tabbrs
111    in
112    let items = c.eabsts + c.eabbrs in
113    let nodes = c.nodes + c.xnodes in
114    let marks = P.marks () in
115    L.warn level (KP.sprintf "Intermediate representation summary (complete_rg)");
116    L.warn level (KP.sprintf "  Total entry items:        %7u" items);
117    L.warn level (KP.sprintf "    Declaration items:      %7u" c.eabsts);
118    L.warn level (KP.sprintf "    Definition items:       %7u" c.eabbrs);
119    L.warn level (KP.sprintf "  Total term items:         %7u" terms);
120    L.warn level (KP.sprintf "    Sort items:             %7u" c.tsorts);
121    L.warn level (KP.sprintf "    Local reference items:  %7u" c.tlrefs);
122    L.warn level (KP.sprintf "    Global reference items: %7u" c.tgrefs);
123    L.warn level (KP.sprintf "    Explicit Cast items:    %7u" c.tcasts);
124    L.warn level (KP.sprintf "    Application items:      %7u" c.tappls);
125    L.warn level (KP.sprintf "    Abstraction items:      %7u" c.tabsts);
126    L.warn level (KP.sprintf "    Abbreviation items:     %7u" c.tabbrs);
127    L.warn level (KP.sprintf "  Ambiguous abstractions:   %7u" marks);   
128    L.warn level (KP.sprintf "  Global Int. Complexity:   %7u" c.nodes);
129    L.warn level (KP.sprintf "    + Abbreviation nodes:   %7u" nodes);
130    f ()
131
132 END
133
134 (* term/environment pretty printer ******************************************)
135
136 let pp_b_attrs out a =
137    let f s b = if b then out (KP.sprintf "%s;" s) else out (KP.sprintf "~%s;" s) in
138    E.name ignore f a
139
140 let pp_n_attrs out a =
141    out (KP.sprintf "+%i;" a.E.n_apix)
142
143 let pp_state out x = if x then out "^"
144
145 let rec pp_term out st = function
146    | D.TSort k         -> out (KP.sprintf "*%u" k)
147    | D.TLRef (a, i)    -> pp_n_attrs out a; out (KP.sprintf "#%u" i)
148    | D.TGRef (a, u)    -> pp_n_attrs out a; out (KP.sprintf "$")
149    | D.TCast (u, t)    -> out "<"; pp_term out st u; out ">."; pp_term out st t
150    | D.TAppl (_, u, t) -> out "("; pp_term out st u; out ")."; pp_term out st t
151    | D.TBind (y, u, t) -> pp_b_attrs out y; pp_bind out st u; out "."; pp_term out st t
152    | D.TProj (u, t)    -> out "{"; pp_lenv out st u; out "}."; pp_term out st t
153
154 and pp_bind out st = function
155    | D.Abst (r, n, u) ->
156       out "[:"; pp_term out st u; out "]"; pp_state out r; out (N.to_string st n); out " "  
157    | D.Abbr u         -> out "[="; pp_term out st u; out "] ";
158    | D.Void           -> out "[] "
159
160 and pp_lenv out st = function
161    | D.ESort              -> ()
162    | D.EBind (u, a, y, t) -> pp_lenv out st u; pp_b_attrs out y; pp_n_attrs out a; pp_bind out st t
163    | D.EAppl (u, _, t)    -> pp_lenv out st u; out "("; pp_term out st t; out ") "
164    | D.EProj (u, t)       -> pp_lenv out st u; out "{"; pp_lenv out st t; out "} "