2 (* Copyright (C) 2000, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
27 (*CSC codice cut & paste da cicPp e xmlcommand *)
29 exception ImpossiblePossible;;
30 exception NotImplemented;;
31 let dtdname = "http://localhost:8081/getdtd?url=cic.dtd";;
33 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
34 let print_term curi ids_to_inner_sorts =
38 let module U = UriManager in
41 let sort = Hashtbl.find ids_to_inner_sorts id in
43 ["value",(string_of_int n) ; "binder",b ; "id",id ; "sort",sort]
45 let vdepth = U.depth_of_uri uri
46 and cdepth = U.depth_of_uri curi
47 and sort = Hashtbl.find ids_to_inner_sorts id in
49 ["relUri",(string_of_int (cdepth - vdepth)) ^ "," ^
51 "id",id ; "sort",sort]
53 let sort = Hashtbl.find ids_to_inner_sorts id in
54 X.xml_nempty "META" ["no",(string_of_int n) ; "id",id ; "sort",sort]
59 [< i ; X.xml_nempty "substitution" [] (aux t') >]
61 [< i ; X.xml_empty "substitution" [] >]
70 X.xml_empty "SORT" ["value",(string_of_sort s) ; "id",id]
71 | C.AImplicit _ -> raise NotImplemented
72 | C.AProd (id,C.Anonimous,s,t) ->
73 let ty = Hashtbl.find ids_to_inner_sorts id in
74 X.xml_nempty "PROD" ["id",id ; "type",ty]
75 [< X.xml_nempty "source" [] (aux s) ;
76 X.xml_nempty "target" [] (aux t)
78 | C.AProd (xid,C.Name id,s,t) ->
79 let ty = Hashtbl.find ids_to_inner_sorts xid in
80 X.xml_nempty "PROD" ["id",xid ; "type",ty]
81 [< X.xml_nempty "source" [] (aux s) ;
82 X.xml_nempty "target" ["binder",id] (aux t)
85 let sort = Hashtbl.find ids_to_inner_sorts id in
86 X.xml_nempty "CAST" ["id",id ; "sort",sort]
87 [< X.xml_nempty "term" [] (aux v) ;
88 X.xml_nempty "type" [] (aux t)
90 | C.ALambda (id,C.Anonimous,s,t) ->
91 let sort = Hashtbl.find ids_to_inner_sorts id in
92 X.xml_nempty "LAMBDA" ["id",id ; "sort",sort]
93 [< X.xml_nempty "source" [] (aux s) ;
94 X.xml_nempty "target" [] (aux t)
96 | C.ALambda (xid,C.Name id,s,t) ->
97 let sort = Hashtbl.find ids_to_inner_sorts xid in
98 X.xml_nempty "LAMBDA" ["id",xid ; "sort",sort]
99 [< X.xml_nempty "source" [] (aux s) ;
100 X.xml_nempty "target" ["binder",id] (aux t)
102 | C.ALetIn (xid,C.Anonimous,s,t) ->
104 | C.ALetIn (xid,C.Name id,s,t) ->
105 let sort = Hashtbl.find ids_to_inner_sorts xid in
106 X.xml_nempty "LETIN" ["id",xid ; "sort",sort]
107 [< X.xml_nempty "term" [] (aux s) ;
108 X.xml_nempty "letintarget" ["binder",id] (aux t)
111 let sort = Hashtbl.find ids_to_inner_sorts id in
112 X.xml_nempty "APPLY" ["id",id ; "sort",sort]
113 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
115 | C.AConst (id,uri,_) ->
116 let sort = Hashtbl.find ids_to_inner_sorts id in
118 ["uri", (U.string_of_uri uri) ; "id",id ; "sort",sort]
119 | C.AMutInd (id,uri,_,i) ->
121 ["uri", (U.string_of_uri uri) ;
122 "noType",(string_of_int i) ;
124 | C.AMutConstruct (id,uri,_,i,j) ->
125 let sort = Hashtbl.find ids_to_inner_sorts id in
126 X.xml_empty "MUTCONSTRUCT"
127 ["uri", (U.string_of_uri uri) ;
128 "noType",(string_of_int i) ; "noConstr",(string_of_int j) ;
129 "id",id ; "sort",sort]
130 | C.AMutCase (id,uri,_,typeno,ty,te,patterns) ->
131 let sort = Hashtbl.find ids_to_inner_sorts id in
132 X.xml_nempty "MUTCASE"
133 ["uriType",(U.string_of_uri uri) ;
134 "noType", (string_of_int typeno) ;
135 "id", id ; "sort",sort]
136 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
137 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
139 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
142 | C.AFix (id, no, funs) ->
143 let sort = Hashtbl.find ids_to_inner_sorts id in
145 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
147 (fun (fi,ai,ti,bi) i ->
148 [< X.xml_nempty "FixFunction"
149 ["name", fi; "recIndex", (string_of_int ai)]
150 [< X.xml_nempty "type" [] [< aux ti >] ;
151 X.xml_nempty "body" [] [< aux bi >]
157 | C.ACoFix (id,no,funs) ->
158 let sort = Hashtbl.find ids_to_inner_sorts id in
160 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
163 [< X.xml_nempty "CofixFunction" ["name", fi]
164 [< X.xml_nempty "type" [] [< aux ti >] ;
165 X.xml_nempty "body" [] [< aux bi >]
175 exception NotImplemented;;
177 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
178 let print_object curi ids_to_inner_sorts =
180 let module C = Cic in
181 let module X = Xml in
182 let module U = UriManager in
184 C.ACurrentProof (id,n,conjectures,bo,ty) ->
185 X.xml_nempty "CurrentProof" ["name",n ; "id", id]
187 (fun i (cid,n,canonical_context,t) ->
189 X.xml_nempty "Conjecture"
190 ["id", cid ; "no",(string_of_int n)]
194 Some (n,C.ADecl t) ->
197 C.Name n' -> ["id",hid;"name",n']
198 | C.Anonimous -> ["id",hid])
199 (print_term curi ids_to_inner_sorts t)
200 | Some (n,C.ADef t) ->
203 C.Name n' -> ["id",hid;"name",n']
204 | C.Anonimous -> ["id",hid])
205 (print_term curi ids_to_inner_sorts t)
206 | None -> X.xml_empty "Hidden" ["id",hid]
210 ) [< >] canonical_context ;
211 X.xml_nempty "Goal" []
212 (print_term curi ids_to_inner_sorts t)
216 X.xml_nempty "body" [] (print_term curi ids_to_inner_sorts bo) ;
217 X.xml_nempty "type" [] (print_term curi ids_to_inner_sorts ty) >]
218 | C.ADefinition (id,n,bo,ty,C.Actual params) ->
224 U.string_of_uri x ^ match i with "" -> "" | i' -> " " ^ i'
225 ) x "" ^ match i with "" -> "" | i' -> " " ^ i'
228 X.xml_nempty "Definition" ["name",n ; "params",params' ; "id", id]
229 [< X.xml_nempty "body" [] (print_term curi ids_to_inner_sorts bo) ;
230 X.xml_nempty "type" [] (print_term curi ids_to_inner_sorts ty) >]
231 | C.ADefinition _ -> assert false
232 | _ -> raise NotImplemented
237 let print_inner_types curi ids_to_inner_sorts ids_to_inner_types =
238 let module C2A = Cic2acic in
239 let module X = Xml in
240 X.xml_nempty "InnerTypes" ["of",UriManager.string_of_uri curi]
242 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
244 X.xml_nempty "TYPE" ["of",id]
245 [< print_term curi ids_to_inner_sorts synty ;
248 | Some expty' -> print_term curi ids_to_inner_sorts expty'
251 ) ids_to_inner_types [<>]