]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_annotations/cicXPath.ml
1eaf31f4e97611319a3e8759c7297a51e014104f
[helm.git] / helm / ocaml / cic_annotations / cicXPath.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 (*                                 14/06/2000                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 let get_annotation ids_to_annotations xpath =
37  try
38   Some (Hashtbl.find ids_to_annotations xpath)
39  with
40   Not_found -> None
41 ;;
42
43 exception MoreThanOneTargetFor of Cic.id;;
44
45 let get_ids_to_targets annobj =
46  let module C = Cic in
47   let ids_to_targets = Hashtbl.create 503 in
48    let set_target id target =
49     try
50      ignore (Hashtbl.find ids_to_targets id) ;
51      raise (MoreThanOneTargetFor id)
52     with
53      Not_found -> Hashtbl.add ids_to_targets id target
54    in
55     let rec add_target_term t =
56      match t with
57         C.ARel (id,_,_)
58       | C.AVar (id,_)
59       | C.AMeta (id,_)
60       | C.ASort (id,_)
61       | C.AImplicit id ->
62          set_target id (C.Term t)
63       | C.ACast (id,va,ty) ->
64          set_target id (C.Term t) ;
65          add_target_term va ;
66          add_target_term ty
67       | C.AProd (id,_,so,ta)
68       | C.ALambda (id,_,so,ta)
69       | C.ALetIn (id,_,so,ta) ->
70          set_target id (C.Term t) ;
71          add_target_term so ;
72          add_target_term ta
73       | C.AAppl (id,l) ->
74          set_target id (C.Term t) ;
75          List.iter add_target_term l
76       | C.AConst (id,_,_)
77       | C.AAbst (id,_)
78       | C.AMutInd (id,_,_,_)
79       | C.AMutConstruct (id,_,_,_,_) ->
80          set_target id (C.Term t)
81       | C.AMutCase (id,_,_,_,ot,it,pl) ->
82          set_target id (C.Term t) ;
83          List.iter add_target_term (ot::it::pl)
84       | C.AFix (id,_,ifl) ->
85          set_target id (C.Term t) ;
86          List.iter
87           (function (_,_,ty,bo) ->
88             add_target_term ty ;
89             add_target_term bo
90           ) ifl
91       | C.ACoFix (id,_,cfl) ->
92          set_target id (C.Term t) ;
93          List.iter
94           (function (_,ty,bo) ->
95             add_target_term ty ;
96             add_target_term bo
97           ) cfl
98     in
99      let add_target_obj annobj =
100       match annobj with
101         C.ADefinition (id,_,bo,ty,_) ->
102          set_target id (C.Object annobj) ;
103          add_target_term bo ;
104          add_target_term ty
105       | C.AAxiom (id,_,ty,_) ->
106          set_target id (C.Object annobj) ;
107          add_target_term ty
108       | C.AVariable (id,_,None,ty) ->
109          set_target id (C.Object annobj) ;
110          add_target_term ty
111       | C.AVariable (id,_,Some bo,ty) ->
112          set_target id (C.Object annobj) ;
113          add_target_term bo ;
114          add_target_term ty
115       | C.ACurrentProof (id,_,cl,bo,ty) ->
116          set_target id (C.Object annobj) ;
117          List.iter (function (_,t) -> add_target_term t) cl ;
118          add_target_term bo ;
119          add_target_term ty
120       | C.AInductiveDefinition (id,itl,_,_) ->
121          set_target id (C.Object annobj) ;
122          List.iter
123           (function (_,_,arity,cl) ->
124             add_target_term arity ;
125             List.iter (function (_,ty,_) -> add_target_term ty) cl
126           ) itl
127      in
128       add_target_obj annobj ;
129       ids_to_targets
130 ;;