350 /* theorems */ |
353 /* theorems */ |
351 |
354 |
352 sealed case class Thm_Id(serial: Long, theory_name: String) |
355 sealed case class Thm_Id(serial: Long, theory_name: String) |
353 { |
356 { |
354 def pure: Boolean = theory_name == Thy_Header.PURE |
357 def pure: Boolean = theory_name == Thy_Header.PURE |
355 |
|
356 def cache(cache: Term.Cache): Thm_Id = |
|
357 Thm_Id(serial, cache.string(theory_name)) |
|
358 } |
358 } |
359 |
359 |
360 sealed case class Thm( |
360 sealed case class Thm( |
361 entity: Entity, |
361 entity: Entity, |
362 prop: Prop, |
362 prop: Prop, |
363 deps: List[String], |
363 deps: List[String], |
364 proof_boxes: List[Thm_Id], |
|
365 proof: Term.Proof) |
364 proof: Term.Proof) |
366 { |
365 { |
367 def cache(cache: Term.Cache): Thm = |
366 def cache(cache: Term.Cache): Thm = |
368 Thm( |
367 Thm( |
369 entity.cache(cache), |
368 entity.cache(cache), |
370 prop.cache(cache), |
369 prop.cache(cache), |
371 deps.map(cache.string _), |
370 deps.map(cache.string _), |
372 proof_boxes.map(_.cache(cache)), |
|
373 cache.proof(proof)) |
371 cache.proof(proof)) |
374 } |
372 } |
375 |
373 |
376 def read_thms(provider: Export.Provider): List[Thm] = |
374 def read_thms(provider: Export.Provider): List[Thm] = |
377 provider.uncompressed_yxml(export_prefix + "thms").map((tree: XML.Tree) => |
375 provider.uncompressed_yxml(export_prefix + "thms").map((tree: XML.Tree) => |
378 { |
376 { |
379 val (entity, body) = decode_entity(Kind.THM, tree) |
377 val (entity, body) = decode_entity(Kind.THM, tree) |
380 val (prop, (deps, (prf_boxes, prf))) = |
378 val (prop, deps, prf) = |
381 { |
379 { |
382 import XML.Decode._ |
380 import XML.Decode._ |
383 import Term_XML.Decode._ |
381 import Term_XML.Decode._ |
384 def thm_id(body: XML.Body): Thm_Id = |
382 triple(decode_prop, list(string), proof)(body) |
385 { |
|
386 val (serial, theory_name) = pair(long, string)(body) |
|
387 Thm_Id(serial, theory_name) |
|
388 } |
|
389 pair(decode_prop _, pair(list(string), pair(list(thm_id), proof)))(body) |
|
390 } |
383 } |
391 Thm(entity, prop, deps, prf_boxes, prf) |
384 Thm(entity, prop, deps, prf) |
392 }) |
385 }) |
393 |
386 |
394 sealed case class Proof( |
387 sealed case class Proof( |
395 typargs: List[(String, Term.Sort)], |
388 typargs: List[(String, Term.Sort)], |
396 args: List[(String, Term.Typ)], |
389 args: List[(String, Term.Typ)], |
424 val proof = Term_XML.Decode.proof_env(env)(proof_body) |
417 val proof = Term_XML.Decode.proof_env(env)(proof_body) |
425 |
418 |
426 val result = Proof(typargs, args, prop, proof) |
419 val result = Proof(typargs, args, prop, proof) |
427 cache.map(result.cache(_)) getOrElse result |
420 cache.map(result.cache(_)) getOrElse result |
428 } |
421 } |
|
422 } |
|
423 |
|
424 def read_proof_boxes( |
|
425 store: Sessions.Store, |
|
426 provider: Export.Provider, |
|
427 proof: Term.Proof, |
|
428 suppress: Thm_Id => Boolean = _ => false, |
|
429 cache: Option[Term.Cache] = None): List[(Thm_Id, Proof)] = |
|
430 { |
|
431 var seen = Set.empty[Long] |
|
432 var result = SortedMap.empty[Long, (Thm_Id, Proof)] |
|
433 |
|
434 def boxes(prf: Term.Proof) |
|
435 { |
|
436 prf match { |
|
437 case Term.Abst(_, _, p) => boxes(p) |
|
438 case Term.AbsP(_, _, p) => boxes(p) |
|
439 case Term.Appt(p, _) => boxes(p) |
|
440 case Term.AppP(p, q) => boxes(p); boxes(q) |
|
441 case thm: Term.PThm if !seen(thm.serial) => |
|
442 seen += thm.serial |
|
443 val id = Thm_Id(thm.serial, thm.theory_name) |
|
444 if (!suppress(id)) { |
|
445 val read = |
|
446 if (id.pure) Export_Theory.read_pure_proof(store, id, cache = cache) |
|
447 else Export_Theory.read_proof(provider, id, cache = cache) |
|
448 read match { |
|
449 case Some(p) => |
|
450 result += (thm.serial -> (id -> p)) |
|
451 boxes(p.proof) |
|
452 case None => |
|
453 error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")") |
|
454 } |
|
455 } |
|
456 case _ => |
|
457 } |
|
458 } |
|
459 |
|
460 boxes(proof) |
|
461 result.iterator.map(_._2).toList |
429 } |
462 } |
430 |
463 |
431 |
464 |
432 /* type classes */ |
465 /* type classes */ |
433 |
466 |