46 val intro_attrib: attribute |
46 val intro_attrib: attribute |
47 val unfold_attrib: attribute |
47 val unfold_attrib: attribute |
48 val intro_locales_tac: bool -> Proof.context -> thm list -> tactic |
48 val intro_locales_tac: bool -> Proof.context -> thm list -> tactic |
49 |
49 |
50 (* Registrations *) |
50 (* Registrations *) |
51 val add_global_registration: (string * Morphism.morphism) -> theory -> theory |
51 val add_global_registration: (string * (Morphism.morphism * Morphism.morphism)) -> |
|
52 theory -> theory |
|
53 val amend_global_registration: (string * Morphism.morphism) -> Morphism.morphism -> |
|
54 theory -> theory |
52 val get_global_registrations: theory -> (string * Morphism.morphism) list |
55 val get_global_registrations: theory -> (string * Morphism.morphism) list |
53 |
56 |
54 (* Diagnostic *) |
57 (* Diagnostic *) |
55 val print_locales: theory -> unit |
58 val print_locales: theory -> unit |
56 val print_locale: theory -> bool -> bstring -> unit |
59 val print_locale: theory -> bool -> bstring -> unit |
452 (*** Registrations: interpretations in theories ***) |
455 (*** Registrations: interpretations in theories ***) |
453 |
456 |
454 (* FIXME only global variant needed *) |
457 (* FIXME only global variant needed *) |
455 structure RegistrationsData = GenericDataFun |
458 structure RegistrationsData = GenericDataFun |
456 ( |
459 ( |
457 type T = ((string * Morphism.morphism) * stamp) list; |
460 type T = ((string * (Morphism.morphism * Morphism.morphism)) * stamp) list; |
|
461 (* FIXME mixins need to be stamped *) |
458 (* registrations, in reverse order of declaration *) |
462 (* registrations, in reverse order of declaration *) |
459 val empty = []; |
463 val empty = []; |
460 val extend = I; |
464 val extend = I; |
461 fun merge _ = Library.merge (eq_snd (op =)); |
465 fun merge _ = Library.merge (eq_snd (op =)); |
462 (* FIXME consolidate with dependencies, consider one data slot only *) |
466 (* FIXME consolidate with dependencies, consider one data slot only *) |
463 ); |
467 ); |
464 |
468 |
465 val get_global_registrations = map fst o RegistrationsData.get o Context.Theory; |
469 val get_global_registrations = |
|
470 Context.Theory #> RegistrationsData.get #> map fst #> map (apsnd op $>); |
466 fun add_global_registration reg = |
471 fun add_global_registration reg = |
467 (Context.theory_map o RegistrationsData.map) (cons (reg, stamp ())); |
472 (Context.theory_map o RegistrationsData.map) (cons (reg, stamp ())); |
468 |
473 |
469 end; |
474 fun amend_global_registration (name, base_morph) morph thy = |
470 |
475 let |
|
476 val regs = (Context.Theory #> RegistrationsData.get #> map fst) thy; |
|
477 val base = instance_of thy name base_morph; |
|
478 fun match (name', (morph', _)) = |
|
479 name = name' andalso eq_list (op aconv) (base, instance_of thy name' morph'); |
|
480 val i = find_index match (rev regs); |
|
481 val _ = if i = ~1 then error ("No interpretation of locale " ^ |
|
482 quote (extern thy name) ^ " and parameter instantiation " ^ |
|
483 space_implode " " (map (quote o Syntax.string_of_term_global thy) base) ^ " available.") |
|
484 else (); |
|
485 in |
|
486 (Context.theory_map o RegistrationsData.map) (nth_map (length regs - 1 - i) |
|
487 (fn ((name, (base, export)), stamp) => ((name, (base $> morph, export)), stamp))) thy |
|
488 end; |
|
489 |
|
490 end; |
|
491 |