]> matita.cs.unibo.it Git - helm.git/blob - components/cic/cicInspect.ml
experimental branch with no set baseuri command and no developments
[helm.git] / components / cic / cicInspect.ml
1 (* Copyright (C) 2003-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 module UM = UriManager
27 module C  = Cic
28
29 module Int = struct
30    type t = int
31    let compare = compare 
32 end
33 module S = Set.Make (Int) 
34
35 let overlaps s1 s2 =
36    let predicate x = S.mem x s1 in
37    S.exists predicate s2
38
39 let get_rels_from_premise h t = 
40    let rec aux d g = function
41       | C.Sort _
42       | C.Implicit _       -> g
43       | C.Rel i            -> 
44          if i < d then g else fun a -> g (S.add (i - d + h + 1) a)
45       | C.Appl ss          -> List.fold_left (aux d) g ss
46       | C.Const (_, ss)
47       | C.MutInd (_, _, ss)
48       | C.MutConstruct (_, _, _, ss)
49       | C.Var (_, ss)      -> 
50          let map g (_, t) = aux d g t in 
51          List.fold_left map g ss
52       | C.Meta (_, ss)     ->
53          let map g = function 
54             | None   -> g
55             | Some t -> aux d g t
56          in
57          List.fold_left map g ss
58       | C.Cast (t1, t2)    -> aux d (aux d g t2) t1
59       | C.LetIn (_, t1, t2)
60       | C.Lambda (_, t1, t2)
61       | C.Prod (_, t1, t2) -> aux d (aux (succ d) g t2) t1
62       | C.MutCase (_, _, t1, t2, ss) ->
63          aux d (aux d (List.fold_left (aux d) g ss) t2) t1
64       | C.Fix (_, ss) ->
65          let k = List.length ss in
66          let map g (_, _, t1, t2) = aux d (aux (d + k) g t2) t1 in
67          List.fold_left map g ss
68       | C.CoFix (_, ss) ->
69          let k = List.length ss in
70          let map g (_, t1, t2) = aux d (aux (d + k) g t2) t1 in
71          List.fold_left map g ss
72    in
73    let g a = a in
74    aux 1 g t S.empty
75
76 let get_mutinds_of_uri u t = 
77    let rec aux g = function
78       | C.Sort _
79       | C.Implicit _
80       | C.Rel _                      -> g
81       | C.Appl ss                    -> List.fold_left aux g ss
82       | C.Const (_, ss)
83       | C.MutConstruct (_, _, _, ss)
84       | C.Var (_, ss)                -> 
85          let map g (_, t) = aux g t in 
86          List.fold_left map g ss
87       | C.MutInd (uri, tyno, ss)     ->
88          let map g (_, t) = aux g t in 
89          let g = List.fold_left map g ss in
90          if UM.eq u uri then fun a -> g (S.add tyno a) else g
91       | C.Meta (_, ss)               ->
92          let map g = function 
93             | None   -> g
94             | Some t -> aux g t
95          in
96          List.fold_left map g ss
97       | C.Cast (t1, t2)              -> aux (aux g t2) t1
98       | C.LetIn (_, t1, t2)
99       | C.Lambda (_, t1, t2)
100       | C.Prod (_, t1, t2)           -> aux (aux g t2) t1
101       | C.MutCase (_, _, t1, t2, ss) ->
102          aux (aux (List.fold_left aux g ss) t2) t1
103       | C.Fix (_, ss)                ->
104          let map g (_, _, t1, t2) = aux (aux g t2) t1 in
105          List.fold_left map g ss
106       | C.CoFix (_, ss)              ->
107          let map g (_, t1, t2) = aux (aux g t2) t1 in
108          List.fold_left map g ss
109    in
110    let g a = a in
111    aux g t S.empty
112
113 let rec aux n = function
114    | C.Sort _
115    | C.Implicit _
116    | C.Rel _                      -> succ n
117    | C.Appl ts                    -> List.fold_left aux (succ n) ts
118    | C.Const (_, ss)
119    | C.MutConstruct (_, _, _, ss)
120    | C.MutInd (_, _, ss)
121    | C.Var (_, ss)                -> 
122       let map n (_, t) = aux n t in 
123       List.fold_left map (succ n) ss
124    | C.Meta (_, ss)               ->
125       let map n = function 
126          | None   -> n
127          | Some t -> aux n t
128       in
129       List.fold_left map (succ n) ss
130    | C.Cast (t1, t2)
131    | C.LetIn (_, t1, t2)
132    | C.Lambda (_, t1, t2)
133    | C.Prod (_, t1, t2)           -> aux (aux (succ n) t2) t1
134    | C.MutCase (_, _, t1, t2, ss) ->
135       aux (aux (List.fold_left aux (succ n) ss) t2) t1
136    | C.Fix (_, ss)                ->
137       let map n (_, _, t1, t2) = aux (aux n t2) t1 in
138       List.fold_left map (succ n) ss
139    | C.CoFix (_, ss)              ->
140       let map n (_, t1, t2) = aux (aux n t2) t1 in
141       List.fold_left map (succ n) ss
142
143 let count_nodes = aux