]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_generator/cGSearchPattern.ml
Universes introduction
[helm.git] / helm / ocaml / mathql_generator / cGSearchPattern.ml
1 (* Copyright (C) 2000, 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 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 02/12/2002                                 *)
32 (*                                                                            *)
33 (*                            Missing description                             *)
34 (*                                                                            *)
35 (******************************************************************************)
36
37 module T = MQGTypes
38 module U = MQGUtil
39
40 type classification =
41    Backbone of int
42  | Branch of int
43  | InConclusion
44  | InHypothesis
45 ;;
46
47 let soften_classification =
48  function
49     Backbone _ -> InConclusion
50   | Branch _ -> InHypothesis
51   | k -> k
52 ;;
53
54 let (!!) =
55  function
56     Backbone n -> `MainConclusion (Some n)
57   | Branch n -> `MainHypothesis (Some n)
58   | _        -> assert false
59 ;;
60
61 let (!!!) =
62  function
63     Backbone n -> `MainConclusion (Some n)
64   | Branch n -> `MainHypothesis (Some n)
65   | InConclusion -> `InConclusion
66   | InHypothesis -> `InHypothesis
67 ;;
68
69
70 let (@@) (l1,l2,l3) (l1',l2',l3') =
71  let merge l1 l2 =
72   List.fold_left (fun i t -> if List.mem t l2 then i else t::i) l2 l1
73  in
74   merge l1 l1', merge l2 l2', merge l3 l3'
75 ;;
76
77 let get_constraints term =
78  let module U = UriManager in
79  let module C = Cic in
80   let rec process_type_aux kind =
81    function
82       C.Var (uri,expl_named_subst) ->
83        ([!!!kind, UriManager.string_of_uri uri],[],[]) @@
84          (process_type_aux_expl_named_subst kind expl_named_subst)
85     | C.Rel _ ->
86        (match kind with
87          | InConclusion 
88          | InHypothesis -> [],[],[] 
89          | _            -> [],[!!kind],[])
90     | C.Sort s ->
91        (match kind with
92            Backbone _
93          | Branch _ ->
94             let s' =
95              match s with
96                 Cic.Prop -> T.Prop
97               | Cic.Set -> T.Set
98               | Cic.Type _ -> T.Type (* TASSI: ?? *)
99               | Cic.CProp -> T.CProp
100             in
101             [],[],[!!kind,s']
102          | _ -> [],[],[])
103     | C.Meta _ -> [],[],[] (* ???? To be understood *)
104     | C.Implicit _ -> assert false
105     | C.Cast (te,_) ->
106        (* type ignored *)
107        process_type_aux kind te
108     | C.Prod (_,sou,ta) ->
109        let (source_kind,target_kind) =
110         match kind with
111            Backbone n -> (Branch 0, Backbone (n+1))
112          | Branch n -> (InHypothesis, Branch (n+1))
113          | k -> (k,k)
114        in
115         process_type_aux source_kind sou @@
116         process_type_aux target_kind ta
117     | C.Lambda (_,sou,ta) ->
118         let kind' = soften_classification kind in
119          process_type_aux kind' sou @@
120          process_type_aux kind' ta
121     | C.LetIn (_,te,ta)->
122        let kind' = soften_classification kind in
123         process_type_aux kind' te @@
124         process_type_aux kind ta
125     | C.Appl (he::tl) ->
126        let kind' = soften_classification kind in
127         process_type_aux kind he @@
128         List.fold_left (fun i t -> i @@ process_type_aux kind' t) ([],[],[]) tl
129     | C.Appl _ -> assert false
130     | C.Const (uri,_) ->
131        [!!!kind, UriManager.string_of_uri uri],[],[]
132     | C.MutInd (uri,typeno,expl_named_subst) ->
133        ([!!!kind, U.string_of_uri uri ^ "#xpointer(1/" ^ 
134         string_of_int (typeno + 1) ^ ")"],[],[]) @@
135          (process_type_aux_expl_named_subst kind expl_named_subst)
136     | C.MutConstruct (uri,typeno,consno,expl_named_subst) ->
137         ([!!!kind, U.string_of_uri uri ^ "#xpointer(1/" ^
138          string_of_int (typeno + 1) ^ "/" ^ string_of_int consno ^ ")"],[],[])
139           @@ (process_type_aux_expl_named_subst kind expl_named_subst)
140     | C.MutCase (_,_,_,term,patterns) ->
141        (* outtype ignored *)
142        let kind' = soften_classification kind in
143         process_type_aux kind' term @@
144         List.fold_left (fun i t -> i @@ process_type_aux kind' t)
145          ([],[],[]) patterns
146     | C.Fix (_,funs) ->
147        let kind' = soften_classification kind in
148         List.fold_left
149          (fun i (_,_,bo,ty) ->
150            i @@
151             process_type_aux kind' bo @@
152             process_type_aux kind' ty
153          ) ([],[],[]) funs
154     | C.CoFix (_,funs) ->
155        let kind' = soften_classification kind in
156         List.fold_left
157          (fun i (_,bo,ty) ->
158            i @@
159             process_type_aux kind' bo @@
160             process_type_aux kind' ty
161          ) ([],[],[]) funs
162  and process_type_aux_expl_named_subst kind =
163   List.fold_left
164    (fun i (_,t) -> i @@ (process_type_aux (soften_classification kind) t))
165    ([],[],[])
166 in
167  let obj_constraints,rel_constraints,sort_constraints =
168   process_type_aux (Backbone 0) (CicMiniReduction.letin_nf term)
169  in
170   (obj_constraints,rel_constraints,sort_constraints)
171 ;;
172
173 (*CSC: Debugging only *)
174 let get_constraints term =
175  let res = get_constraints term in
176  let (objs,rels,sorts) = res in
177   let text_of_pos p =
178     U.text_of_position p ^ " " ^ U.text_of_depth p "NULL"
179   in
180   prerr_endline "Constraints on objs:" ;
181   List.iter
182    (function (p, u) -> prerr_endline (text_of_pos p ^ " " ^ u)) objs ;
183   prerr_endline "Constraints on Rels:" ;
184   List.iter (function p -> prerr_endline (text_of_pos (p:>T.full_position))) rels ;
185   prerr_endline "Constraints on Sorts:" ;
186   List.iter
187    (function (p, s) -> prerr_endline (text_of_pos (p:>T.full_position) ^ " " ^ U.text_of_sort s)
188    ) sorts ;
189   res
190 ;;
191
192 let universe =
193    [T.MainHypothesis; T.InHypothesis; T.MainConclusion; T.InConclusion]