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 (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)
95 C.ARel (id,_,_,_) -> id
96 | C.AVar (id,_,_) -> id
97 | C.AMeta (id,_,_) -> id
98 | C.ASort (id,_,_) -> id
99 | C.AImplicit (id,_) -> id
100 | C.ACast (id,_,_,_) -> id
101 | C.AProd (id,_,_,_,_) -> id
102 | C.ALambda (id,_,_,_,_) -> id
103 | C.ALetIn (id,_,_,_,_) -> id
104 | C.AAppl (id,_,_) -> id
105 | C.AConst (id,_,_,_) -> id
106 | C.AAbst (id,_,_) -> id
107 | C.AMutInd (id,_,_,_,_) -> id
108 | C.AMutConstruct (id,_,_,_,_,_)-> id
109 | C.AMutCase (id,_,_,_,_,_,_,_) -> id
110 | C.AFix (id,_,_,_) -> id
111 | C.ACoFix (id,_,_,_) -> id
114 let create_hint_from_term annotation_window annterm =
115 let module C = Cic in
118 link_hints annotation_window
119 [| "Binder", "<attribute name = 'binder' id = '" ^ id ^ "'/>" |]
121 link_hints annotation_window
122 [| "relURI???", "<attribute name = 'relUri' id = '" ^ id ^ "'/>" |]
123 | C.AMeta (id,_,_) ->
124 link_hints annotation_window
125 [| "Number", "<attribute name = 'no' id = '" ^ id ^ "'/>" |]
126 | C.ASort (id,_,_) ->
127 link_hints annotation_window
128 [| "Value", "<attribute name = 'value' id = '" ^ id ^ "'/>" |]
129 | C.AImplicit (id,_) ->
130 link_hints annotation_window [| |]
131 | C.ACast (id,_,bo,ty) ->
133 and tyid = get_id ty in
134 link_hints annotation_window
135 [| "Body", "<node id = '" ^ boid ^ "'/>" ;
136 "Type", "<node id = '" ^ tyid ^ "'/>"
138 | C.AProd (id,_,_,ty,bo) ->
140 and tyid = get_id ty in
141 link_hints annotation_window
143 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
144 "Body", "<node id = '" ^ boid ^ "'/>" ;
145 "Type", "<node id = '" ^ tyid ^ "'/>"
147 | C.ALambda (id,_,_,ty,bo) ->
149 and tyid = get_id ty in
150 link_hints annotation_window
152 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
153 "Body", "<node id = '" ^ boid ^ "'/>" ;
154 "Type", "<node id = '" ^ tyid ^ "'/>"
156 | C.ALetIn (id,_,_,ty,bo) ->
158 and tyid = get_id ty in
159 link_hints annotation_window
161 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
162 "Term", "<node id = '" ^ boid ^ "'/>" ;
163 "Target", "<node id = '" ^ tyid ^ "'/>"
165 | C.AAppl (id,_,args) ->
168 (fun i te -> "Argument " ^ string_of_int i, "<node id ='" ^
172 link_hints annotation_window argsid
173 | C.AConst (id,_,_,_) ->
174 link_hints annotation_window
175 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
176 | C.AAbst (id,_,_) ->
177 link_hints annotation_window
178 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
179 | C.AMutInd (id,_,_,_,_) ->
180 link_hints annotation_window
181 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
182 | C.AMutConstruct (id,_,_,_,_,_) ->
183 link_hints annotation_window
184 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
185 | C.AMutCase (id,_,_,_,_,outty,te,pl) ->
186 let outtyid = get_id outty
190 (fun i te -> "Pattern " ^ string_of_int i, "<node id ='" ^
194 link_hints annotation_window
196 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" ;
197 "Case Type", "<node id = '" ^ outtyid ^ "'/>" ;
198 "Term", "<node id = '" ^ teid ^ "'/>" ;
201 | C.AFix (id,_,_,funl) ->
205 "Type " ^ string_of_int i, "<node id ='" ^
211 "Body " ^ string_of_int i, "<node id ='" ^
217 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
218 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
223 "Recursive Index??? " ^ string_of_int i, "<attribute id = '" ^ id ^
224 "' name = 'recIndex' child='" ^ string_of_int i ^ "'/>")
227 link_hints annotation_window
233 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
236 | C.ACoFix (id,_,_,funl) ->
240 "Type " ^ string_of_int i, "<node id ='" ^
246 "Body " ^ string_of_int i, "<node id ='" ^
252 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
253 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
256 link_hints annotation_window
261 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
266 (*CSC: da riscrivere completamente eliminando il paciugo degli array - liste *)
267 let create_hint_from_obj annotation_window annobj =
268 let module C = Cic in
270 C.ADefinition (id,_,_,bo,ty,_) ->
272 and tyid = get_id ty in
273 link_hints annotation_window
274 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
275 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
276 "Body", "<node id = '" ^ boid ^ "'/>" ;
277 "Type", "<node id = '" ^ tyid ^ "'/>"
279 | C.AAxiom (id,_,_,ty,_) ->
280 let 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 "Type", "<node id = '" ^ tyid ^ "'/>"
286 | C.AVariable (id,_,_,bo,ty) ->
287 let tyid = get_id ty in
288 link_hints annotation_window
291 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
292 "Type", "<node id = '" ^ tyid ^ "'/>"
295 let boid = get_id bo in
296 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
297 "Body", "<node id = '" ^ boid ^ "'/>" ;
298 "Type", "<node id = '" ^ tyid ^ "'/>"
301 | C.ACurrentProof (id,_,_,conjs,bo,ty) ->
304 and conjsid = List.map (fun (_,te) -> get_id te) conjs in
305 link_hints annotation_window
307 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
308 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
309 "Body", "<node id = '" ^ boid ^ "'/>" ;
310 "Type", "<node id = '" ^ tyid ^ "'/>"
314 "Conjecture " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
315 ) (Array.of_list conjsid)
318 | C.AInductiveDefinition (id,_,itl,_,_) ->
321 (fun (_,_,arity,cons) ->
323 List.map (fun (_,ty,_) -> get_id ty) cons
326 link_hints annotation_window
329 [| "Ingredients","<attribute name = 'params' id = '" ^ id ^ "'/>" |];
332 "Type Name " ^ string_of_int i,
333 "<attribute name = 'name' child = '" ^ string_of_int i ^
334 "' id = '" ^ id ^ "'/>"
335 ) (Array.of_list itlids)
339 "Type " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
340 ) (Array.of_list itlids)
347 "Constructor Name " ^ string_of_int i ^ " " ^ string_of_int j,
348 "<attribute name = 'name' id = '" ^ id ^
349 "' child = '" ^ string_of_int i ^ "' grandchild = '" ^
350 string_of_int j ^ "'/>"
351 ) (Array.of_list consid)
361 "Constructor " ^ string_of_int i ^ " " ^ string_of_int j,
362 "<node id = '" ^ id ^ "'/>"
363 ) (Array.of_list consid)
372 exception IdUnknown of string;;
374 let create_hints annotation_window (annobj,ids_to_targets) xpath =
376 match Hashtbl.find ids_to_targets xpath with
377 Cic.Object annobj -> create_hint_from_obj annotation_window annobj
378 | Cic.Term annterm -> create_hint_from_term annotation_window annterm
380 Not_found -> raise (IdUnknown xpath)