43 val intros_of: theory -> string -> thm option * thm option |
43 val intros_of: theory -> string -> thm option * thm option |
44 val axioms_of: theory -> string -> thm list |
44 val axioms_of: theory -> string -> thm list |
45 val instance_of: theory -> string -> morphism -> term list |
45 val instance_of: theory -> string -> morphism -> term list |
46 val specification_of: theory -> string -> term option * term list |
46 val specification_of: theory -> string -> term option * term list |
47 val declarations_of: theory -> string -> declaration list * declaration list |
47 val declarations_of: theory -> string -> declaration list * declaration list |
48 val dependencies_of: theory -> string -> (string * morphism) list |
|
49 |
48 |
50 (* Storing results *) |
49 (* Storing results *) |
51 val add_thmss: string -> string -> (Attrib.binding * (thm list * Attrib.src list) list) list -> |
50 val add_thmss: string -> string -> (Attrib.binding * (thm list * Attrib.src list) list) list -> |
52 Proof.context -> Proof.context |
51 Proof.context -> Proof.context |
53 val add_type_syntax: string -> declaration -> Proof.context -> Proof.context |
52 val add_type_syntax: string -> declaration -> Proof.context -> Proof.context |
54 val add_term_syntax: string -> declaration -> Proof.context -> Proof.context |
53 val add_term_syntax: string -> declaration -> Proof.context -> Proof.context |
55 val add_declaration: string -> declaration -> Proof.context -> Proof.context |
54 val add_declaration: string -> declaration -> Proof.context -> Proof.context |
56 val add_dependency: string -> string * morphism -> theory -> theory |
|
57 |
55 |
58 (* Activation *) |
56 (* Activation *) |
59 val activate_declarations: string * morphism -> Proof.context -> Proof.context |
57 val activate_declarations: string * morphism -> Proof.context -> Proof.context |
60 val activate_facts: string * morphism -> Context.generic -> Context.generic |
58 val activate_facts: string * morphism -> Context.generic -> Context.generic |
61 val init: string -> theory -> Proof.context |
59 val init: string -> theory -> Proof.context |
67 val witness_add: attribute |
65 val witness_add: attribute |
68 val intro_add: attribute |
66 val intro_add: attribute |
69 val unfold_add: attribute |
67 val unfold_add: attribute |
70 val intro_locales_tac: bool -> Proof.context -> thm list -> tactic |
68 val intro_locales_tac: bool -> Proof.context -> thm list -> tactic |
71 |
69 |
72 (* Registrations *) |
70 (* Registrations and dependencies *) |
73 val add_registration: string * (morphism * morphism) -> theory -> theory |
71 val add_registration: string * (morphism * morphism) -> theory -> theory |
74 val amend_registration: morphism -> string * morphism -> theory -> theory |
72 val amend_registration: morphism -> string * morphism -> theory -> theory |
75 val get_registrations: theory -> (string * morphism) list |
73 val add_dependencies: string -> ((string * morphism) * Element.witness list) list -> |
|
74 morphism -> theory -> theory |
76 |
75 |
77 (* Diagnostic *) |
76 (* Diagnostic *) |
78 val print_locales: theory -> unit |
77 val print_locales: theory -> unit |
79 val print_locale: theory -> bool -> xstring -> unit |
78 val print_locale: theory -> bool -> xstring -> unit |
80 end; |
79 end; |
336 val copy = I; |
335 val copy = I; |
337 fun merge _ data : T = Library.merge (eq_snd op =) data; |
336 fun merge _ data : T = Library.merge (eq_snd op =) data; |
338 (* FIXME consolidate with dependencies, consider one data slot only *) |
337 (* FIXME consolidate with dependencies, consider one data slot only *) |
339 ); |
338 ); |
340 |
339 |
341 val get_registrations = |
340 fun reg_morph ((name, (base, export)), _) = (name, base $> export); |
342 Registrations.get #> map (#1 #> apsnd op $>); |
341 |
|
342 fun these_registrations thy name = Registrations.get thy |
|
343 |> filter (curry (op =) name o fst o fst) |
|
344 |> map reg_morph; |
|
345 |
|
346 fun all_registrations thy = Registrations.get thy |
|
347 |> map reg_morph; |
343 |
348 |
344 fun add_registration (name, (base_morph, export)) thy = |
349 fun add_registration (name, (base_morph, export)) thy = |
345 roundup thy (fn (name', morph') => Registrations.map (cons ((name', (morph', export)), stamp ()))) |
350 roundup thy (fn (name', morph') => Registrations.map (cons ((name', (morph', export)), stamp ()))) |
346 (name, base_morph) (get_idents (Context.Theory thy), thy) |> snd; |
351 (name, base_morph) (get_idents (Context.Theory thy), thy) |
347 (* FIXME |-> put_global_idents ?*) |
352 (* FIXME |-> (Context.theory_map o put_idents_diag)*) |> snd; |
348 |
353 |
349 fun amend_registration morph (name, base_morph) thy = |
354 fun amend_registration morph (name, base_morph) thy = |
350 let |
355 let |
351 val regs = map #1 (Registrations.get thy); |
356 val regs = map #1 (Registrations.get thy); |
352 val base = instance_of thy name base_morph; |
357 val base = instance_of thy name base_morph; |
362 Registrations.map (nth_map (length regs - 1 - i) |
367 Registrations.map (nth_map (length regs - 1 - i) |
363 (fn ((name, (base, export)), stamp) => ((name, (base $> morph, export)), stamp))) thy |
368 (fn ((name, (base, export)), stamp) => ((name, (base $> morph, export)), stamp))) thy |
364 end; |
369 end; |
365 |
370 |
366 |
371 |
|
372 (*** Dependencies ***) |
|
373 |
|
374 fun add_dependencies loc deps_witss export thy = |
|
375 thy |
|
376 |> fold (fn ((dep, morph), wits) => (change_locale loc o apsnd) |
|
377 (cons ((dep, morph $> Element.satisfy_morphism wits $> export), stamp ()))) |
|
378 deps_witss |
|
379 |> (fn thy => fold_rev (Context.theory_map o activate_facts) |
|
380 (all_registrations thy) thy); |
|
381 |
|
382 |
367 (*** Storing results ***) |
383 (*** Storing results ***) |
368 |
384 |
369 (* Theorems *) |
385 (* Theorems *) |
370 |
386 |
371 fun add_thmss loc kind args ctxt = |
387 fun add_thmss loc kind args ctxt = |
373 val (Notes args', ctxt') = Element.activate_i (Notes (kind, args)) ctxt; |
389 val (Notes args', ctxt') = Element.activate_i (Notes (kind, args)) ctxt; |
374 val ctxt'' = ctxt' |> ProofContext.theory ( |
390 val ctxt'' = ctxt' |> ProofContext.theory ( |
375 (change_locale loc o apfst o apsnd) (cons (args', stamp ())) |
391 (change_locale loc o apfst o apsnd) (cons (args', stamp ())) |
376 #> |
392 #> |
377 (* Registrations *) |
393 (* Registrations *) |
378 (fn thy => fold_rev (fn (name, morph) => |
394 (fn thy => fold_rev (fn (_, morph) => |
379 let |
395 let |
380 val args'' = snd args' |> Element.facts_map (Element.morph_ctxt morph) |> |
396 val args'' = snd args' |> Element.facts_map (Element.morph_ctxt morph) |> |
381 Attrib.map_facts (Attrib.attribute_i thy) |
397 Attrib.map_facts (Attrib.attribute_i thy) |
382 in PureThy.note_thmss kind args'' #> snd end) |
398 in PureThy.note_thmss kind args'' #> snd end) |
383 (get_registrations thy |> filter (fn (name, _) => name = loc)) thy)) |
399 (these_registrations thy loc) thy)) |
384 in ctxt'' end; |
400 in ctxt'' end; |
385 |
401 |
386 |
402 |
387 (* Declarations *) |
403 (* Declarations *) |
388 |
404 |
400 val add_type_syntax = add_decls (apfst o cons); |
416 val add_type_syntax = add_decls (apfst o cons); |
401 val add_term_syntax = add_decls (apsnd o cons); |
417 val add_term_syntax = add_decls (apsnd o cons); |
402 val add_declaration = add_decls (K I); |
418 val add_declaration = add_decls (K I); |
403 |
419 |
404 end; |
420 end; |
405 |
|
406 |
|
407 (* Dependencies *) |
|
408 |
|
409 fun add_dependency loc dep = (change_locale loc o apsnd) (cons (dep, stamp ())); |
|
410 |
421 |
411 |
422 |
412 (*** Reasoning about locales ***) |
423 (*** Reasoning about locales ***) |
413 |
424 |
414 (* Storage for witnesses, intro and unfold rules *) |
425 (* Storage for witnesses, intro and unfold rules *) |