1 (******************************************************************************)
5 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
9 (******************************************************************************)
11 let deactivate_hints_from annotation_window n =
12 let annotation_hints = annotation_window#annotation_hints in
13 for i = n to Array.length annotation_hints - 1 do
14 annotation_hints.(i)#misc#hide ()
18 (* CSC: orripilante *)
19 (* the list of the signal ids *)
20 let sig_ids = ref ([] : GtkSignal.id list);;
22 let disconnect_hint annotation_window buttonno =
25 annotation_window#annotation_hints.(buttonno)#misc#disconnect id ;
30 (* link_hint annotation_window n label hint *)
31 (* set the label of the nth hint button of annotation_window to label *)
32 (* and the correspondent hint to hint *)
33 let link_hint annotation_window buttonno label hint =
34 let button = annotation_window#annotation_hints.(buttonno) in
36 (button#connect#clicked
37 (fun () -> (annotation_window#annotation : GEdit.text)#insert hint)
40 match button#children with
41 [labelw] -> (GMisc.label_cast labelw)#set_text label
45 exception TooManyHints;;
47 let link_hints annotation_window a =
48 if Array.length a > Array.length annotation_window#annotation_hints then
50 for i = List.length !sig_ids - 1 downto 0 do
51 disconnect_hint annotation_window i
54 (fun i (label,hint) -> link_hint annotation_window i label hint) a ;
55 deactivate_hints_from annotation_window (Array.length a)
62 | he::tl -> (f n he)::(aux (n + 1) tl)
70 C.ARel (id,_,_,_) -> id
71 | C.AVar (id,_,_) -> id
72 | C.AMeta (id,_,_) -> id
73 | C.ASort (id,_,_) -> id
74 | C.AImplicit (id,_) -> id
75 | C.ACast (id,_,_,_) -> id
76 | C.AProd (id,_,_,_,_) -> id
77 | C.ALambda (id,_,_,_,_) -> id
78 | C.ALetIn (id,_,_,_,_) -> id
79 | C.AAppl (id,_,_) -> id
80 | C.AConst (id,_,_,_) -> id
81 | C.AAbst (id,_,_) -> id
82 | C.AMutInd (id,_,_,_,_) -> id
83 | C.AMutConstruct (id,_,_,_,_,_)-> id
84 | C.AMutCase (id,_,_,_,_,_,_,_) -> id
85 | C.AFix (id,_,_,_) -> id
86 | C.ACoFix (id,_,_,_) -> id
89 let create_hint_from_term annotation_window annterm =
93 link_hints annotation_window
94 [| "Binder", "<attribute name = 'binder' id = '" ^ id ^ "'/>" |]
96 link_hints annotation_window
97 [| "relURI???", "<attribute name = 'relUri' id = '" ^ id ^ "'/>" |]
99 link_hints annotation_window
100 [| "Number", "<attribute name = 'no' id = '" ^ id ^ "'/>" |]
101 | C.ASort (id,_,_) ->
102 link_hints annotation_window
103 [| "Value", "<attribute name = 'value' id = '" ^ id ^ "'/>" |]
104 | C.AImplicit (id,_) ->
105 link_hints annotation_window [| |]
106 | C.ACast (id,_,bo,ty) ->
108 and tyid = get_id ty in
109 link_hints annotation_window
110 [| "Body", "<node id = '" ^ boid ^ "'/>" ;
111 "Type", "<node id = '" ^ tyid ^ "'/>"
113 | C.AProd (id,_,_,ty,bo) ->
115 and tyid = get_id ty in
116 link_hints annotation_window
118 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
119 "Body", "<node id = '" ^ boid ^ "'/>" ;
120 "Type", "<node id = '" ^ tyid ^ "'/>"
122 | C.ALambda (id,_,_,ty,bo) ->
124 and tyid = get_id ty in
125 link_hints annotation_window
127 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
128 "Body", "<node id = '" ^ boid ^ "'/>" ;
129 "Type", "<node id = '" ^ tyid ^ "'/>"
131 | C.ALetIn (id,_,_,ty,bo) ->
133 and tyid = get_id ty in
134 link_hints annotation_window
136 "<attribute child = '2' name = 'binder' id = '" ^ id ^ "'/>" ;
137 "Term", "<node id = '" ^ boid ^ "'/>" ;
138 "Target", "<node id = '" ^ tyid ^ "'/>"
140 | C.AAppl (id,_,args) ->
143 (fun i te -> "Argument " ^ string_of_int i, "<node id ='" ^
147 link_hints annotation_window argsid
148 | C.AConst (id,_,_,_) ->
149 link_hints annotation_window
150 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
151 | C.AAbst (id,_,_) ->
152 link_hints annotation_window
153 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
154 | C.AMutInd (id,_,_,_,_) ->
155 link_hints annotation_window
156 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
157 | C.AMutConstruct (id,_,_,_,_,_) ->
158 link_hints annotation_window
159 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" |]
160 | C.AMutCase (id,_,_,_,_,outty,te,pl) ->
161 let outtyid = get_id outty
165 (fun i te -> "Pattern " ^ string_of_int i, "<node id ='" ^
169 link_hints annotation_window
171 [| "Uri???", "<attribute name = 'uri' id = '" ^ id ^ "'/>" ;
172 "Case Type", "<node id = '" ^ outtyid ^ "'/>" ;
173 "Term", "<node id = '" ^ teid ^ "'/>" ;
176 | C.AFix (id,_,_,funl) ->
180 "Type " ^ string_of_int i, "<node id ='" ^
186 "Body " ^ string_of_int i, "<node id ='" ^
192 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
193 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
198 "Recursive Index??? " ^ string_of_int i, "<attribute id = '" ^ id ^
199 "' name = 'recIndex' child='" ^ string_of_int i ^ "'/>")
202 link_hints annotation_window
208 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
211 | C.ACoFix (id,_,_,funl) ->
215 "Type " ^ string_of_int i, "<node id ='" ^
221 "Body " ^ string_of_int i, "<node id ='" ^
227 "Name " ^ string_of_int i, "<attribute id ='" ^ id ^
228 "' name = 'name' child='" ^ string_of_int i ^ "'/>")
231 link_hints annotation_window
236 [| "NoFun???", "<attribute name = 'noFun' id = '" ^ id ^ "'/>" |]
241 (*CSC: da riscrivere completamente eliminando il paciugo degli array - liste *)
242 let create_hint_from_obj annotation_window annobj =
243 let module C = Cic in
245 C.ADefinition (id,_,_,bo,ty,_) ->
247 and tyid = get_id ty in
248 link_hints annotation_window
249 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
250 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
251 "Body", "<node id = '" ^ boid ^ "'/>" ;
252 "Type", "<node id = '" ^ tyid ^ "'/>"
254 | C.AAxiom (id,_,_,ty,_) ->
255 let tyid = get_id ty in
256 link_hints annotation_window
257 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
258 "Ingredients", "<attribute name = 'params' id = '" ^ id ^ "'/>" ;
259 "Type", "<node id = '" ^ tyid ^ "'/>"
261 | C.AVariable (id,_,_,bo,ty) ->
262 let tyid = get_id ty in
263 link_hints annotation_window
266 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
267 "Type", "<node id = '" ^ tyid ^ "'/>"
270 let boid = get_id bo in
271 [| "Name", "<attribute name = 'name' id = '" ^ id ^ "'/>" ;
272 "Body", "<node id = '" ^ boid ^ "'/>" ;
273 "Type", "<node id = '" ^ tyid ^ "'/>"
276 | C.ACurrentProof (id,_,_,conjs,bo,ty) ->
279 and conjsid = List.map (fun (_,te) -> get_id te) conjs in
280 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 ^ "'/>"
289 "Conjecture " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
290 ) (Array.of_list conjsid)
293 | C.AInductiveDefinition (id,_,itl,_,_) ->
296 (fun (_,_,arity,cons) ->
298 List.map (fun (_,ty,_) -> get_id ty) cons
301 link_hints annotation_window
304 [| "Ingredients","<attribute name = 'params' id = '" ^ id ^ "'/>" |];
307 "Type Name " ^ string_of_int i,
308 "<attribute name = 'name' child = '" ^ string_of_int i ^
309 "' id = '" ^ id ^ "'/>"
310 ) (Array.of_list itlids)
314 "Type " ^ string_of_int i, "<node id = '" ^ id ^ "'/>"
315 ) (Array.of_list itlids)
322 "Constructor Name " ^ string_of_int i ^ " " ^ string_of_int j,
323 "<attribute name = 'name' id = '" ^ id ^
324 "' child = '" ^ string_of_int i ^ "' grandchild = '" ^
325 string_of_int j ^ "'/>"
326 ) (Array.of_list consid)
336 "Constructor " ^ string_of_int i ^ " " ^ string_of_int j,
337 "<node id = '" ^ id ^ "'/>"
338 ) (Array.of_list consid)
347 exception IdUnknown of string;;
349 let create_hints annotation_window (annobj,ids_to_targets) xpath =
351 match Hashtbl.find ids_to_targets xpath with
352 Cic.Object annobj -> create_hint_from_obj annotation_window annobj
353 | Cic.Term annterm -> create_hint_from_term annotation_window annterm
355 Not_found -> raise (IdUnknown xpath)