]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/probe/nCicScan.ml
- nUri : added Sets of uris for use in "probe"
[helm.git] / matita / components / binaries / probe / nCicScan.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 L  = List
13
14 module U  = NUri
15 module US = U.UriSet
16 module R  = NReference
17 module C  = NCic
18 module P  = NCicPp
19 module E  = NCicEnvironment
20
21 module O  = Options
22
23 let status = new P.status
24
25 let malformed () =
26    failwith "probe: malformed term"
27
28 let rec set_list c ts cts =
29    let map cts t = (c, t) :: cts in
30    L.fold_left map cts ts
31
32 let set_funs c rfs cts =
33    let map cts (_, _, _, t0, t1) = set_list c [t0; t1] cts in
34    L.fold_left map cts rfs
35
36 let set_type c cts (_, _, t, css) =
37    let map cts (_, _, t) = (c, t) :: cts in 
38    (c, t) :: L.fold_left map cts css 
39
40 let scan_lref a c i = 
41    try match List.nth c (pred i) with
42       | _, C.Decl _ -> succ a
43       | _, C.Def  _ -> a
44    with 
45       | Failure _ -> succ a 
46
47 let scan_gref a = function
48    | R.Ref (_, R.Decl) 
49    | R.Ref (_, R.Ind _)
50    | R.Ref (_, R.Con _)   -> succ a
51    | R.Ref (u, R.Def _)
52    | R.Ref (u, R.Fix _)
53    | R.Ref (u, R.CoFix _) ->
54       if US.mem u !O.objs then a else succ a
55
56 let rec scan_term a = function
57    | []                                 -> a
58    | (_, C.Meta _)                :: tl
59    | (_, C.Implicit _)            :: tl -> scan_term a tl
60    | (_, C.Sort _)                :: tl -> scan_term (succ a) tl
61    | (c, C.Rel i)                 :: tl -> scan_term (scan_lref a c i) tl
62    | (_, C.Const p)               :: tl -> scan_term (scan_gref a p) tl
63    | (_, C.Appl [])               :: tl -> malformed ()
64    | (c, C.Appl ts)               :: tl ->
65       scan_term (L.length ts + pred a) (set_list c ts tl)
66    | (c, C.Match (_, t0, t1, ts)) :: tl ->
67       scan_term a (set_list c (t0::t1::ts) tl)   
68    | (c, C.Prod (s, t0, t1))      :: tl
69    | (c, C.Lambda (s, t0, t1))    :: tl ->
70       scan_term (succ a) ((c, t0) :: ((s, C.Decl t0) :: c, t1) :: tl)
71    | (c, C.LetIn (s, t0, t1, t2)) :: tl ->
72       scan_term a ((c, t0) :: (c, t1) :: ((s, C.Def (t1, t0)) :: c, t2) :: tl)
73
74 let scan_obj u a = 
75    let _, _, _, _, obj = E.get_checked_obj status u in 
76    match obj with
77       | C.Constant (_, _, None, t, _)     ->
78          scan_term (succ a) [[], t]
79       | C.Constant (_, _, Some t0, t1, _) ->
80          scan_term (succ a) (set_list [] [t0; t1] [])
81       | C.Fixpoint (_, rfs, _)            ->
82          scan_term (a + L.length rfs) (set_funs [] rfs [])
83       | C.Inductive (_, _, its, _)        ->
84          let cts = L.fold_left (set_type []) [] its in
85          scan_term (a + L.length cts) cts
86
87 let accept_obj u = 
88    let _, _, _, _, obj = E.get_checked_obj status u in 
89    let g = match obj with
90       | C.Constant (_, _, _, _, (g, _, _))
91       | C.Fixpoint (_, _, (g, _, _))
92       | C.Inductive (_, _, _, (g, _))    -> g
93    in
94    if L.mem g !O.exclude then false else true
95
96 let scan () = 
97    if !O.exclude <> [] then 
98       O.objs := US.filter accept_obj !O.objs;
99    O.net := US.fold scan_obj !O.objs !O.net