1 (* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 let deactivate_hints_from annotation_window n =
37 let annotation_hints = annotation_window#annotation_hints in
38 for i = n to Array.length annotation_hints - 1 do
39 annotation_hints.(i)#misc#hide ()
43 (* CSC: orripilante *)
44 (* the list of the signal ids *)
45 let sig_ids = ref ([] : GtkSignal.id list);;
47 let disconnect_hint annotation_window buttonno =
50 annotation_window#annotation_hints.(buttonno)#misc#disconnect id ;
55 (* link_hint annotation_window n label hint *)
56 (* set the label of the nth hint button of annotation_window to label *)
57 (* and the correspondent hint to hint *)
58 let link_hint annotation_window buttonno label hint =
59 let button = annotation_window#annotation_hints.(buttonno) in
61 (button#connect#clicked
62 ~callback:(fun () -> (annotation_window#annotation : GEdit.text)#insert hint)
65 match button#children with
66 [labelw] -> (GMisc.label_cast labelw)#set_text label
70 exception TooManyHints;;
72 let link_hints annotation_window a =
73 if Array.length a > Array.length annotation_window#annotation_hints then
75 for i = List.length !sig_ids - 1 downto 0 do
76 disconnect_hint annotation_window i
79 (fun i (label,hint) -> link_hint annotation_window i label hint) a ;
80 deactivate_hints_from annotation_window (Array.length a)
87 | he::tl -> (f n he)::(aux (n + 1) tl)
102 | C.ALambda (id,_,_,_)
103 | C.ALetIn (id,_,_,_)
106 | C.AMutInd (id,_,_,_)
107 | C.AMutConstruct (id,_,_,_,_)
108 | C.AMutCase (id,_,_,_,_,_,_)
110 | C.ACoFix (id,_,_) -> id
113 let create_hint_from_term annotation_window annterm =
114 let module C = Cic in
117 link_hints annotation_window
118 [| "Binder", "<attribute name = 'binder' id = '" ^ id ^ "'/>" |]
120 link_hints annotation_window
121 [| "relURI???", "<attribute name = 'relUri' id = '" ^ id ^ "'/>" |]
122 | C.AMeta (id,_,subst) ->
125 [| "Number", "<attribute name = 'no' id = '" ^ id ^ "'/>" |]
130 "Argument " ^ string_of_int i, "_"
132 "Argument " ^ string_of_int i, "<node id ='" ^ get_id t ^ "'/>"
133 ) (Array.of_list subst)
136 link_hints annotation_window res
138 link_hints annotation_window
139 [| "Value", "<attribute name = 'value' id = '" ^ id ^ "'/>" |]
141 link_hints annotation_window [| |]
142 | C.ACast (id,bo,ty) ->
144 and tyid = get_id ty in
145 link_hints annotation_window
146 [| "Body", "<node id = '" ^ boid ^ "'/>" ;
147 "Type", "<node id = '" ^ tyid ^ "'/>"
149 | C.AProd (id,_,ty,bo) ->
151 and tyid = get_id ty in
152 link_hints annotation_window
154 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
155 "Body", "<node id = '" ^ boid ^ "'/>" ;
156 "Type", "<node id = '" ^ tyid ^ "'/>"
158 | C.ALambda (id,_,ty,bo) ->
160 and tyid = get_id ty in
161 link_hints annotation_window
163 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
164 "Body", "<node id = '" ^ boid ^ "'/>" ;
165 "Type", "<node id = '" ^ tyid ^ "'/>"
167 | C.ALetIn (id,_,ty,bo) ->
169 and tyid = get_id ty in
170 link_hints annotation_window
172 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
173 "Term", "<node id = '" ^ boid ^ "'/>" ;
174 "Target", "<node id = '" ^ tyid ^ "'/>"
176 | C.AAppl (id,args) ->
179 (fun i te -> "Argument " ^ string_of_int i, "<node id ='" ^
183 link_hints annotation_window argsid
184 | C.AConst (id,_,_) ->
185 link_hints annotation_window
186 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
187 | C.AMutInd (id,_,_,_) ->
188 link_hints annotation_window
189 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
190 | C.AMutConstruct (id,_,_,_,_) ->
191 link_hints annotation_window
192 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
193 | C.AMutCase (id,_,_,_,outty,te,pl) ->
194 let outtyid = get_id outty
198 (fun i te -> "Pattern " ^ string_of_int i, "<node id ='" ^
202 link_hints annotation_window
204 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" ;
205 "Case Type", "<node id = '" ^ outtyid ^ "'/>" ;
206 "Term", "<node id = '" ^ teid ^ "'/>" ;
209 | C.AFix (id,_,funl) ->
213 "Type " ^ string_of_int i, "<node id ='" ^
219 "Body " ^ string_of_int i, "<node id ='" ^
225 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
226 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
231 "Recursive Index??? " ^ string_of_int i, "<attribute id = '" ^ id ^
232 "' name = 'recIndex' child='" ^ string_of_int i ^ "'/>")
235 link_hints annotation_window
241 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
244 | C.ACoFix (id,_,funl) ->
248 "Type " ^ string_of_int i, "<node id ='" ^
254 "Body " ^ string_of_int i, "<node id ='" ^
260 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
261 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
264 link_hints annotation_window
269 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
274 (*CSC: da riscrivere completamente eliminando il paciugo degli array - liste *)
275 let create_hint_from_obj annotation_window annobj =
276 let module C = Cic in
278 C.ADefinition (id,_,bo,ty,_) ->
280 and tyid = get_id ty in
281 link_hints annotation_window
282 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
283 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
284 "Body", "<node id = '" ^ boid ^ "'/>" ;
285 "Type", "<node id = '" ^ tyid ^ "'/>"
287 | C.AAxiom (id,_,ty,_) ->
288 let tyid = get_id ty in
289 link_hints annotation_window
290 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
291 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
292 "Type", "<node id = '" ^ tyid ^ "'/>"
294 | C.AVariable (id,_,bo,ty) ->
295 let tyid = get_id ty in
296 link_hints annotation_window
299 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
300 "Type", "<node id = '" ^ tyid ^ "'/>"
303 let boid = get_id bo in
304 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
305 "Body", "<node id = '" ^ boid ^ "'/>" ;
306 "Type", "<node id = '" ^ tyid ^ "'/>"
309 | C.ACurrentProof (id,_,conjs,bo,ty) ->
312 and conjsid = List.map (fun (id,_,_,_) -> id) conjs in
313 link_hints annotation_window
314 (*CSC: never tested since the introduction of the new Metas *)
316 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
317 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
318 "Body", "<node id = '" ^ boid ^ "'/>" ;
319 "Type", "<node id = '" ^ tyid ^ "'/>"
323 "Conjecture " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
324 ) (Array.of_list conjsid)
327 | C.AInductiveDefinition (id,itl,_,_) ->
330 (fun (_,_,arity,cons) ->
332 List.map (fun (_,ty,_) -> get_id ty) cons
335 link_hints annotation_window
338 [| "Ingredients","<attribute name = 'params' id = '" ^ id ^ "'/>" |];
341 "Type Name " ^ string_of_int i,
342 "<attribute name = 'name' child = '" ^ string_of_int i ^
343 "' id = '" ^ id ^ "'/>"
344 ) (Array.of_list itlids)
348 "Type " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
349 ) (Array.of_list itlids)
356 "Constructor Name " ^ string_of_int i ^ " " ^ string_of_int j,
357 "<attribute name = 'name' id = '" ^ id ^
358 "' child = '" ^ string_of_int i ^ "' grandchild = '" ^
359 string_of_int j ^ "'/>"
360 ) (Array.of_list consid)
370 "Constructor " ^ string_of_int i ^ " " ^ string_of_int j,
371 "<node id = '" ^ id ^ "'/>"
372 ) (Array.of_list consid)
381 exception IdUnknown of string;;
383 let create_hints annotation_window ids_to_targets xpath =
385 match Hashtbl.find ids_to_targets xpath with
386 Cic.Object annobj -> create_hint_from_obj annotation_window annobj
387 | Cic.Term annterm -> create_hint_from_term annotation_window annterm
388 (*CSC: never tested since the introduction of the new Metas *)
390 | Cic.Conjecture _ -> assert false
392 Not_found -> raise (IdUnknown xpath)