]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_annotations/cicXPath.ml
first moogle template checkin
[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 (* creates a hashtable mapping each unique id to a node of the annotated 
46 object *)
47 let get_ids_to_targets annobj =
48  let module C = Cic in
49   let ids_to_targets = Hashtbl.create 503 in
50    let set_target id target =
51     try
52      ignore (Hashtbl.find ids_to_targets id) ;
53      raise (MoreThanOneTargetFor id)
54     with
55      Not_found -> Hashtbl.add ids_to_targets id target
56    in
57     let rec add_target_term t =
58      match t with
59         C.ARel (id,_,_,_)
60       | C.AMeta (id,_,_)
61       | C.ASort (id,_)
62       | C.AImplicit (id, _) ->
63          set_target id (C.Term t)
64       | C.ACast (id,va,ty) ->
65          set_target id (C.Term t) ;
66          add_target_term va ;
67          add_target_term ty
68       | C.AProd (id,_,so,ta)
69       | C.ALambda (id,_,so,ta)
70       | C.ALetIn (id,_,so,ta) ->
71          set_target id (C.Term t) ;
72          add_target_term so ;
73          add_target_term ta
74       | C.AAppl (id,l) ->
75          set_target id (C.Term t) ;
76          List.iter add_target_term l
77       | C.AVar (id,_,exp_named_subst)
78       | C.AConst (id,_,exp_named_subst)
79       | C.AMutInd (id,_,_,exp_named_subst)
80       | C.AMutConstruct (id,_,_,_,exp_named_subst) ->
81          set_target id (C.Term t) ;
82          List.iter (function (_,t) -> add_target_term t) exp_named_subst
83       | C.AMutCase (id,_,_,ot,it,pl) ->
84          set_target id (C.Term t) ;
85          List.iter add_target_term (ot::it::pl)
86       | C.AFix (id,_,ifl) ->
87          set_target id (C.Term t) ;
88          List.iter
89           (function (_,_,_,ty,bo) ->
90             add_target_term ty ;
91             add_target_term bo
92           ) ifl
93       | C.ACoFix (id,_,cfl) ->
94          set_target id (C.Term t) ;
95          List.iter
96           (function (_,_,ty,bo) ->
97             add_target_term ty ;
98             add_target_term bo
99           ) cfl
100     in
101      let add_target_obj annobj =
102       match annobj with
103         C.AConstant (id,idbody,_,bo,ty,_) ->
104          set_target id (C.Object annobj) ;
105          (match idbody,bo with
106              Some idbody,Some bo ->
107               set_target idbody (C.ConstantBody annobj) ;
108               add_target_term bo
109            | None, None -> ()
110            | _,_ -> assert false
111          ) ;
112          add_target_term ty
113       | C.AVariable (id,_,None,ty,_) ->
114          set_target id (C.Object annobj) ;
115          add_target_term ty
116       | C.AVariable (id,_,Some bo,ty,_) ->
117          set_target id (C.Object annobj) ;
118          add_target_term bo ;
119          add_target_term ty
120       | C.ACurrentProof (id,idbody,_,cl,bo,ty,_) ->
121          set_target id (C.Object annobj) ;
122          set_target idbody (C.ConstantBody annobj) ;
123          List.iter (function (cid,_,context, t) as annconj ->
124            set_target cid (C.Conjecture annconj) ;
125            List.iter 
126              (function ((hid,h) as annhyp) ->
127                set_target hid (C.Hypothesis annhyp) ;
128                match h with
129                   Some (_,C.ADecl at) -> add_target_term at
130                 | Some (_,C.ADef at) -> add_target_term at
131                 | None -> ()
132              ) context;
133            add_target_term t) cl ;
134          add_target_term bo ;
135          add_target_term ty
136       | C.AInductiveDefinition (id,itl,_,_) ->
137          set_target id (C.Object annobj) ;
138          List.iter
139           (function (_,_,_,arity,cl) ->
140             add_target_term arity ;
141             List.iter (function (_,ty) -> add_target_term ty) cl
142           ) itl
143      in
144       add_target_obj annobj ;
145       ids_to_targets
146 ;;