]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_rg/brgOutput.ml
- basic_rg: architectural bug fix
[helm.git] / helm / software / lambda-delta / basic_rg / brgOutput.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 C = Cps
16 module L = Log
17 module B = Brg
18
19 type counters = {
20    eabsts: int;
21    eabbrs: int;
22    tsorts: int;
23    tlrefs: int;
24    tgrefs: int;
25    tcasts: int;
26    tappls: int;
27    tabsts: int;
28    tabbrs: int
29 }
30
31 let initial_counters = {
32    eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0;
33    tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0
34 }
35
36 let rec count_term_binder f c = function
37    | B.Abst w ->
38       let c = {c with tabsts = succ c.tabsts} in
39       count_term f c w
40    | B.Abbr v -> 
41       let c = {c with tabbrs = succ c.tabbrs} in
42       count_term f c v
43    | B.Void   -> f c
44
45 and count_term f c = function
46    | B.Sort _            -> 
47       f {c with tsorts = succ c.tsorts}
48    | B.LRef _            -> 
49       f {c with tlrefs = succ c.tlrefs}
50    | B.GRef _            -> 
51       f {c with tgrefs = succ c.tgrefs}
52    | B.Cast (v, t)       -> 
53       let c = {c with tcasts = succ c.tcasts} in
54       let f c = count_term f c t in
55       count_term f c v
56    | B.Appl (v, t)       -> 
57       let c = {c with tappls = succ c.tappls} in
58       let f c = count_term f c t in
59       count_term f c v
60    | B.Bind (_, b, t) -> 
61       let f c = count_term_binder f c b in
62       count_term f c t
63
64 let count_obj_binder f c = function
65    | B.Abst w -> 
66       let c = {c with eabsts = succ c.eabsts} in
67       count_term f c w
68    | B.Abbr v -> 
69       let c = {c with eabbrs = succ c.eabbrs} in
70       count_term f c v
71    | B.Void   -> f c
72
73 let count_obj f c (_, _, b) =
74    count_obj_binder f c b
75
76 let count_item f c = function
77    | Some obj -> count_obj f c obj
78    | None     -> f c
79
80 let print_counters f c =
81    let terms =
82       c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
83       c.tabbrs
84    in
85    let items = c.eabsts + c.eabbrs in
86    L.warn (P.sprintf "  Kernel representation summary (basic_rg)");
87    L.warn (P.sprintf "    Total entry items:        %6u" items);
88    L.warn (P.sprintf "      Declaration items:      %6u" c.eabsts);
89    L.warn (P.sprintf "      Definition items:       %6u" c.eabbrs);
90    L.warn (P.sprintf "    Total term items:         %6u" terms);
91    L.warn (P.sprintf "      Sort items:             %6u" c.tsorts);
92    L.warn (P.sprintf "      Local reference items:  %6u" c.tlrefs);
93    L.warn (P.sprintf "      Global reference items: %6u" c.tgrefs);
94    L.warn (P.sprintf "      Explicit Cast items:    %6u" c.tcasts);
95    L.warn (P.sprintf "      Application items:      %6u" c.tappls);
96    L.warn (P.sprintf "      Abstraction items:      %6u" c.tabsts);
97    L.warn (P.sprintf "      Abbreviation items:     %6u" c.tabbrs);
98    f ()
99
100 let rec pp_term c frm = function
101    | B.Sort h                 -> F.fprintf frm "@[*%u@]" h
102    | B.LRef i                 -> 
103       let f = function
104          | Some (id, _) -> F.fprintf frm "@[%s@]" id
105          | None         -> F.fprintf frm "@[#%u@]" i
106       in
107       B.get f c i
108    | B.GRef s                 -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
109    | B.Cast (u, t)            ->
110       F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
111    | B.Appl (v, t)            ->
112       F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
113    | B.Bind (id, B.Abst w, t) ->
114       let f cc =
115          F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term cc) t
116       in
117       B.push f c id (B.Abst w)
118    | B.Bind (id, B.Abbr v, t) ->
119       let f cc = 
120          F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term cc) t
121       in
122       B.push f c id (B.Abbr v)
123    | B.Bind (id, B.Void, t)   ->
124       let f cc = F.fprintf frm "@[[%s].%a@]" id (pp_term cc) t in
125       B.push f c id B.Void
126
127 let pp_context frm c =
128    let pp_entry f = function
129       | id, B.Abst w -> 
130          F.fprintf frm "%s : %a\n%!" id (pp_term c) w; f ()
131       | id, B.Abbr v -> 
132          F.fprintf frm "%s = %a\n%!" id (pp_term c) v; f ()
133       | id, B.Void   -> 
134          F.fprintf frm "%s\n%!" id; f ()
135    in
136    let f _ es = C.list_iter C.start pp_entry (List.rev es) in
137    B.contents f c
138
139 let pp_term frm c t = 
140    F.fprintf frm "%a\n%!" (pp_term c) t
141
142 let specs = {
143    L.pp_term = pp_term; L.pp_context = pp_context
144 }