]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/complete_rg/crgOutput.ml
- we are moving from old (patched) management of sort inclusion
[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 P = Printf
13
14 module U = NUri
15 module C = Cps
16 module L = Log
17 module J = 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 let rec count_term f c e = function
51    | D.TSort _          -> 
52       f {c with tsorts = succ c.tsorts; nodes = succ c.nodes}
53    | D.TLRef (_, i)     -> 
54       begin match D.get e i with
55          | _, _, D.Abbr _ ->
56             f {c with tlrefs = succ c.tlrefs; xnodes = succ c.xnodes}
57          | _              ->
58             f {c with tlrefs = succ c.tlrefs; nodes = succ c.nodes}
59       end      
60    | D.TGRef (_, u)     -> 
61       let c =    
62          if C.list_mem ~eq:U.eq u c.uris
63          then {c with nodes = succ c.nodes}
64          else {c with xnodes = succ c.xnodes}
65       in
66       f {c with tgrefs = succ c.tgrefs}
67    | D.TCast (_, v, t)  -> 
68       let c = {c with tcasts = succ c.tcasts} in
69       let f c = count_term f c e t in
70       count_term f c e v
71    | D.TAppl (_, v, t)  -> 
72       let c = {c with tappls = succ c.tappls} in
73       let f c = count_term f c e t in
74       count_term f c e v
75    | D.TProj (_, d, t)  ->
76       D.shift (count_term f c e) d t
77    | D.TBind (a, b, t)  -> 
78       let f c e = count_term f c e t in
79       count_binder f c e a b
80
81 and count_binder f c e a b = match b with
82    | D.Abst (_, w) ->
83       let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in
84       let f c = D.push_bind (f c) a b e in
85       count_term f c e w
86    | D.Abbr v      -> 
87       let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in
88       let f c = D.push_bind (f c) a b e in
89       count_term f c e v     
90    | D.Void        ->
91       let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in
92       D.push_bind (f c) a b e
93
94 let count_entity f c = function
95    | _, _, u, E.Abst w -> 
96       let c = {c with
97          eabsts = succ c.eabsts; nodes = succ c.nodes; uris = u :: c.uris
98       } in
99       count_term f c D.ESort w
100    | _, _, _, E.Abbr v ->  
101       let c = {c with eabbrs = succ c.eabbrs; xnodes = succ c.xnodes} in
102       count_term f c D.ESort v
103    | _, _, _, E.Void   -> assert false
104
105 let print_counters f c =
106    let terms =
107       c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
108       c.tabbrs
109    in
110    let items = c.eabsts + c.eabbrs in
111    let nodes = c.nodes + c.xnodes in
112    let marks = J.marks () in
113    L.warn level (P.sprintf "Intermediate representation summary (complete_rg)");
114    L.warn level (P.sprintf "  Total entry items:        %7u" items);
115    L.warn level (P.sprintf "    Declaration items:      %7u" c.eabsts);
116    L.warn level (P.sprintf "    Definition items:       %7u" c.eabbrs);
117    L.warn level (P.sprintf "  Total term items:         %7u" terms);
118    L.warn level (P.sprintf "    Sort items:             %7u" c.tsorts);
119    L.warn level (P.sprintf "    Local reference items:  %7u" c.tlrefs);
120    L.warn level (P.sprintf "    Global reference items: %7u" c.tgrefs);
121    L.warn level (P.sprintf "    Explicit Cast items:    %7u" c.tcasts);
122    L.warn level (P.sprintf "    Application items:      %7u" c.tappls);
123    L.warn level (P.sprintf "    Abstraction items:      %7u" c.tabsts);
124    L.warn level (P.sprintf "    Abbreviation items:     %7u" c.tabbrs);
125    L.warn level (P.sprintf "  Ambiguous abstractions:   %7u" marks);   
126    L.warn level (P.sprintf "  Global Int. Complexity:   %7u" c.nodes);
127    L.warn level (P.sprintf "    + Abbreviation nodes:   %7u" nodes);
128    f ()
129
130 (* term/environment pretty printer ******************************************)
131
132 let pp_attrs out a =
133    let f s b = if b then out (P.sprintf "%s;" s) else out (P.sprintf "~%s;" s) in
134    E.name ignore f a;
135    out (P.sprintf "+%i;" a.E.n_apix)
136
137 let rec pp_term out st = function
138    | D.TSort (a, l)    -> pp_attrs out a; out (P.sprintf "*%u" l)
139    | D.TLRef (a, i   ) -> pp_attrs out a; out (P.sprintf "#%u" i)
140    | D.TGRef (a, u)    -> pp_attrs out a; out (P.sprintf "$")
141    | D.TCast (a, x, y) -> pp_attrs out a; out "<"; pp_term out st x; out ">."; pp_term out st y
142    | D.TAppl (a, x, y) -> pp_attrs out a; out "("; pp_term out st x; out ")."; pp_term out st y
143    | D.TBind (a, x, y) -> pp_attrs out a; pp_bind out st x; out "."; pp_term out st y
144    | D.TProj (a, x, y) -> pp_attrs out a; out "{"; pp_lenv out st x; out "}."; pp_term out st y
145
146 and pp_bind out st = function
147    | D.Abst (n, x) ->
148       out "[:"; pp_term out st x; out "]"; out (N.to_string st n)  
149    | D.Abbr x      -> out "[="; pp_term out st x; out "]";
150    | D.Void        -> out "[]"
151
152 and pp_lenv out st = function
153    | D.ESort           -> ()
154    | D.EBind (x, a, y) -> pp_lenv out st x; pp_attrs out a; pp_bind out st y
155    | D.EAppl (x, a, y) -> pp_lenv out st x; out "("; pp_term out st y; out ")"
156    | D.EProj (x, a, y) -> pp_lenv out st x; out "{"; pp_lenv out st y; out "}"