230 val typargs = rev (add_tfrees used prop []); |
230 val typargs = rev (add_tfrees used prop []); |
231 val used_typargs = fold (Name.declare o #1) typargs used; |
231 val used_typargs = fold (Name.declare o #1) typargs used; |
232 val sorts = Name.invent used_typargs Name.aT (length extra_shyps) ~~ extra_shyps; |
232 val sorts = Name.invent used_typargs Name.aT (length extra_shyps) ~~ extra_shyps; |
233 in ((sorts @ typargs, args, prop), proof) end; |
233 in ((sorts @ typargs, args, prop), proof) end; |
234 |
234 |
|
235 fun standard_prop_of thm = |
|
236 standard_prop Name.context (Thm.extra_shyps thm) (Thm.full_prop_of thm); |
|
237 |
235 val encode_prop = |
238 val encode_prop = |
236 let open XML.Encode Term_XML.Encode |
239 let open XML.Encode Term_XML.Encode |
237 in triple (list (pair string sort)) (list (pair string typ)) encode_term end; |
240 in triple (list (pair string sort)) (list (pair string typ)) encode_term end; |
238 |
241 |
239 fun encode_axiom used prop = |
242 fun encode_axiom used prop = |
245 |
248 |
246 |
249 |
247 (* theorems and proof terms *) |
250 (* theorems and proof terms *) |
248 |
251 |
249 val clean_thm = Thm.check_hyps (Context.Theory thy) #> Thm.strip_shyps; |
252 val clean_thm = Thm.check_hyps (Context.Theory thy) #> Thm.strip_shyps; |
|
253 val prep_thm = clean_thm #> Thm.unconstrainT; |
250 |
254 |
251 val lookup_thm_id = Global_Theory.lookup_thm_id thy; |
255 val lookup_thm_id = Global_Theory.lookup_thm_id thy; |
252 |
256 |
253 fun expand_name thm_id (header: Proofterm.thm_header) = |
257 fun expand_name thm_id (header: Proofterm.thm_header) = |
254 if #serial header = #serial thm_id then "" |
258 if #serial header = #serial thm_id then "" |
265 in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end; |
269 in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end; |
266 |
270 |
267 fun encode_thm thm_id raw_thm = |
271 fun encode_thm thm_id raw_thm = |
268 let |
272 let |
269 val deps = map (Thm_Name.print o #2) (Thm_Deps.thm_deps thy [raw_thm]); |
273 val deps = map (Thm_Name.print o #2) (Thm_Deps.thm_deps thy [raw_thm]); |
270 val thm = clean_thm (Thm.unconstrainT raw_thm); |
274 val thm = prep_thm raw_thm; |
271 |
275 |
272 val proof0 = |
276 val proof0 = |
273 if Proofterm.export_standard_enabled () then |
277 if Proofterm.export_standard_enabled () then |
274 Proof_Syntax.standard_proof_of |
278 Proof_Syntax.standard_proof_of |
275 {full = true, expand_name = SOME o expand_name thm_id} thm |
279 {full = true, expand_name = SOME o expand_name thm_id} thm |
276 else if Proofterm.export_enabled () then Thm.reconstruct_proof_of thm |
280 else if Proofterm.export_enabled () then Thm.reconstruct_proof_of thm |
277 else MinProof; |
281 else MinProof; |
278 val (prop, SOME proof) = |
282 val (prop, SOME proof) = standard_prop_of thm (SOME proof0); |
279 standard_prop Name.context (Thm.extra_shyps thm) (Thm.full_prop_of thm) (SOME proof0); |
|
280 val _ = Thm.expose_proofs thy [thm]; |
283 val _ = Thm.expose_proofs thy [thm]; |
281 in |
284 in |
282 (prop, deps, proof) |> |
285 (prop, deps, proof) |> |
283 let |
286 let |
284 open XML.Encode Term_XML.Encode; |
287 open XML.Encode Term_XML.Encode; |
395 |
398 |
396 val _ = |
399 val _ = |
397 if null constdefs then () else export_body thy "constdefs" (encode_constdefs constdefs); |
400 if null constdefs then () else export_body thy "constdefs" (encode_constdefs constdefs); |
398 |
401 |
399 |
402 |
|
403 (* spec rules *) |
|
404 |
|
405 fun encode_spec {name, rough_classification, terms, rules} = |
|
406 let |
|
407 val terms' = map Logic.unvarify_global terms; |
|
408 val rules' = map (fn rule => #1 (standard_prop_of (prep_thm rule) NONE)) rules; |
|
409 open XML.Encode; |
|
410 in |
|
411 pair string (pair Spec_Rules.encode_rough_classification |
|
412 (pair (list encode_term) (list encode_prop))) |
|
413 (name, (rough_classification, (terms', rules'))) |
|
414 end; |
|
415 |
|
416 val _ = |
|
417 (case Spec_Rules.dest_theory thy of |
|
418 [] => () |
|
419 | spec_rules => export_body thy "spec_rules" (XML.Encode.list encode_spec spec_rules)); |
|
420 |
|
421 |
400 (* parents *) |
422 (* parents *) |
401 |
423 |
402 val _ = |
424 val _ = |
403 Export.export thy \<^path_binding>\<open>theory/parents\<close> |
425 Export.export thy \<^path_binding>\<open>theory/parents\<close> |
404 (XML.Encode.string (cat_lines (map Context.theory_long_name parents))); |
426 (XML.Encode.string (cat_lines (map Context.theory_long_name parents))); |