| author | wenzelm | 
| Wed, 17 Jan 2018 14:40:18 +0100 | |
| changeset 67460 | dfc93f2b01ea | 
| parent 66337 | 5caea089dd17 | 
| child 67652 | 11716a084cae | 
| permissions | -rw-r--r-- | 
| 41959 | 1 | (* Title: Pure/Isar/generic_target.ML | 
| 38309 | 2 | Author: Makarius | 
| 3 | Author: Florian Haftmann, TU Muenchen | |
| 4 | ||
| 5 | Common target infrastructure. | |
| 6 | *) | |
| 7 | ||
| 8 | signature GENERIC_TARGET = | |
| 9 | sig | |
| 60345 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 10 | (*auxiliary*) | 
| 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 11 | val export_abbrev: Proof.context -> | 
| 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 12 | (term -> term) -> term -> term * ((string * sort) list * (term list * term list)) | 
| 62764 | 13 | val check_mixfix: Proof.context -> binding * (string * sort) list -> mixfix -> mixfix | 
| 60345 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 14 | val check_mixfix_global: binding * bool -> mixfix -> mixfix | 
| 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 15 | |
| 60340 | 16 | (*background primitives*) | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 17 | val background_foundation: ((binding * typ) * mixfix) * (binding * term) -> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 18 | term list * term list -> local_theory -> (term * thm) * local_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 19 | val background_declaration: declaration -> local_theory -> local_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 20 | val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 21 | |
| 60340 | 22 | (*nested local theories primitives*) | 
| 63269 | 23 | val standard_facts: local_theory -> Proof.context -> | 
| 24 | (Attrib.binding * Attrib.thms) list -> (Attrib.binding * Attrib.thms) list | |
| 25 | val standard_notes: (int * int -> bool) -> string -> (Attrib.binding * Attrib.thms) list -> | |
| 26 | local_theory -> local_theory | |
| 27 | val standard_declaration: (int * int -> bool) -> | |
| 28 | (morphism -> Context.generic -> Context.generic) -> local_theory -> local_theory | |
| 60340 | 29 | val standard_const: (int * int -> bool) -> Syntax.mode -> (binding * mixfix) * term -> | 
| 30 | local_theory -> local_theory | |
| 31 | ||
| 32 | (*lifting target primitives to local theory operations*) | |
| 40782 | 33 | val define: (((binding * typ) * mixfix) * (binding * term) -> | 
| 34 | term list * term list -> local_theory -> (term * thm) * local_theory) -> | |
| 46992 
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
 wenzelm parents: 
46916diff
changeset | 35 | bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory -> | 
| 40782 | 36 | (term * (string * thm)) * local_theory | 
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 37 | val notes: | 
| 63267 | 38 | (string -> (Attrib.binding * Attrib.thms) list -> | 
| 39 | (Attrib.binding * Attrib.thms) list -> local_theory -> local_theory) -> | |
| 40 | string -> (Attrib.binding * Attrib.thms) list -> local_theory -> | |
| 40782 | 41 | (string * thm list) list * local_theory | 
| 60337 | 42 | val abbrev: (Syntax.mode -> binding * mixfix -> term -> | 
| 57160 | 43 | term list * term list -> local_theory -> local_theory) -> | 
| 60337 | 44 | Syntax.mode -> (binding * mixfix) * term -> local_theory -> (term * term) * local_theory | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 45 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 46 | (*theory target primitives*) | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 47 | val theory_target_foundation: ((binding * typ) * mixfix) * (binding * term) -> | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 48 | term list * term list -> local_theory -> (term * thm) * local_theory | 
| 63267 | 49 | val theory_target_notes: string -> (Attrib.binding * Attrib.thms) list -> | 
| 50 | (Attrib.binding * Attrib.thms) list -> local_theory -> local_theory | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 51 | val theory_target_abbrev: Syntax.mode -> (binding * mixfix) -> term -> term list * term list -> | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 52 | local_theory -> local_theory | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 53 | |
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 54 | (*theory target operations*) | 
| 60344 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 55 | val theory_abbrev: Syntax.mode -> (binding * mixfix) * term -> | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 56 | local_theory -> (term * term) * local_theory | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 57 | val theory_declaration: declaration -> local_theory -> local_theory | 
| 52153 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 58 | val theory_registration: string * morphism -> (morphism * bool) option -> morphism -> | 
| 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 59 | local_theory -> local_theory | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 60 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 61 | (*locale target primitives*) | 
| 63267 | 62 | val locale_target_notes: string -> string -> (Attrib.binding * Attrib.thms) list -> | 
| 63 | (Attrib.binding * Attrib.thms) list -> local_theory -> local_theory | |
| 63339 | 64 | val locale_target_abbrev: string -> Syntax.mode -> | 
| 65 | (binding * mixfix) -> term -> term list * term list -> local_theory -> local_theory | |
| 57192 
180e955711cf
yet another attempt for terminology: foo_target_bar denotes an operation bar operating solely on the target context of target foo, foo_bar denotes a whole stack of operations to accomplish bar for target foo
 haftmann parents: 
57191diff
changeset | 66 | val locale_target_declaration: string -> bool -> declaration -> local_theory -> local_theory | 
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 67 | val locale_target_const: string -> (morphism -> bool) -> Syntax.mode -> | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 68 | (binding * mixfix) * term -> local_theory -> local_theory | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 69 | |
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 70 | (*locale operations*) | 
| 60344 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 71 | val locale_abbrev: string -> Syntax.mode -> (binding * mixfix) * term -> | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 72 | local_theory -> (term * term) * local_theory | 
| 57193 | 73 |   val locale_declaration: string -> {syntax: bool, pervasive: bool} -> declaration ->
 | 
| 74 | local_theory -> local_theory | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 75 | val locale_const: string -> Syntax.mode -> (binding * mixfix) * term -> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 76 | local_theory -> local_theory | 
| 52153 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 77 | val locale_dependency: string -> string * morphism -> (morphism * bool) option -> morphism -> | 
| 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 78 | local_theory -> local_theory | 
| 66337 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 79 | |
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 80 | (*initialisation*) | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 81 |   val init: {background_naming: Name_Space.naming, setup: theory -> Proof.context,
 | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 82 | conclude: local_theory -> local_theory} -> | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 83 | Local_Theory.operations -> theory -> local_theory | 
| 45353 | 84 | end | 
| 38309 | 85 | |
| 86 | structure Generic_Target: GENERIC_TARGET = | |
| 87 | struct | |
| 88 | ||
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 89 | (** consts **) | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 90 | |
| 60345 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 91 | fun export_abbrev lthy preprocess rhs = | 
| 60342 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 92 | let | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 93 | val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy); | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 94 | |
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 95 | val rhs' = rhs | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 96 | |> Assumption.export_term lthy (Local_Theory.target_of lthy) | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 97 | |> preprocess; | 
| 63339 | 98 | val term_params = | 
| 99 | map Free (sort (Variable.fixed_ord lthy o apply2 #1) (Variable.add_fixed lthy rhs' [])); | |
| 60342 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 100 | val u = fold_rev lambda term_params rhs'; | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 101 | val global_rhs = singleton (Variable.polymorphic thy_ctxt) u; | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 102 | |
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 103 | val extra_tfrees = | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 104 | subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []); | 
| 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 105 | val type_params = map (Logic.mk_type o TFree) extra_tfrees; | 
| 60345 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 106 | in (global_rhs, (extra_tfrees, (type_params, term_params))) end; | 
| 60342 
df9b153d866b
separate function to compute exported abbreviation
 haftmann parents: 
60341diff
changeset | 107 | |
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 108 | fun check_mixfix ctxt (b, extra_tfrees) mx = | 
| 62767 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 109 | if null extra_tfrees then mx | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 110 | else | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 111 | (if Context_Position.is_visible ctxt then | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 112 | warning | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 113 |         ("Additional type variable(s) in specification of " ^ Binding.print b ^ ": " ^
 | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 114 | commas (map (Syntax.string_of_typ ctxt o TFree) (sort_by #1 extra_tfrees)) ^ | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 115 | (if Mixfix.is_empty mx then "" | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 116 | else "\nDropping mixfix syntax " ^ Pretty.string_of (Mixfix.pretty_mixfix mx))) | 
| 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 117 | else (); NoSyn); | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 118 | |
| 47291 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 119 | fun check_mixfix_global (b, no_params) mx = | 
| 62752 | 120 | if no_params orelse Mixfix.is_empty mx then mx | 
| 121 | else | |
| 122 |     (warning ("Dropping global mixfix syntax: " ^ Binding.print b ^ " " ^
 | |
| 62767 
d6b0d35b3aed
relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
 wenzelm parents: 
62764diff
changeset | 123 | Pretty.string_of (Mixfix.pretty_mixfix mx)); NoSyn); | 
| 47291 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 124 | |
| 61701 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 125 | fun same_const (Const (c, _), Const (c', _)) = c = c' | 
| 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 126 | | same_const (t $ _, t' $ _) = same_const (t, t') | 
| 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 127 | | same_const (_, _) = false; | 
| 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 128 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 129 | fun const_decl phi_pred prmode ((b, mx), rhs) phi context = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 130 | if phi_pred phi then | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 131 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 132 | val b' = Morphism.binding phi b; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 133 | val rhs' = Morphism.term phi rhs; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 134 | val same_shape = Term.aconv_untyped (rhs, rhs'); | 
| 61701 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 135 | val same_stem = same_shape orelse same_const (rhs, rhs'); | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 136 | val const_alias = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 137 | if same_shape then | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 138 | (case rhs' of | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 139 | Const (c, T) => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 140 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 141 | val thy = Context.theory_of context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 142 | val ctxt = Context.proof_of context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 143 | in | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 144 | (case Type_Infer_Context.const_type ctxt c of | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 145 | SOME T' => if Sign.typ_equiv thy (T, T') then SOME c else NONE | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 146 | | NONE => NONE) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 147 | end | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 148 | | _ => NONE) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 149 | else NONE; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 150 | in | 
| 60283 | 151 | (case const_alias of | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 152 | SOME c => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 153 | context | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 154 | |> Context.mapping (Sign.const_alias b' c) (Proof_Context.const_alias b' c) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 155 | |> Morphism.form (Proof_Context.generic_notation true prmode [(rhs', mx)]) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 156 | | NONE => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 157 | context | 
| 62764 | 158 | |> Proof_Context.generic_add_abbrev Print_Mode.internal | 
| 159 | (b', Term.close_schematic_term rhs') | |
| 61701 
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
 ballarin parents: 
61261diff
changeset | 160 | |-> (fn (const as Const (c, _), _) => same_stem ? | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 161 | (Proof_Context.generic_revert_abbrev (#1 prmode) c #> | 
| 62764 | 162 | same_shape ? | 
| 163 | Morphism.form (Proof_Context.generic_notation true prmode [(const, mx)])))) | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 164 | end | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 165 | else context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 166 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 167 | |
| 60283 | 168 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 169 | (** background primitives **) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 170 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 171 | fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 172 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 173 | val params = type_params @ term_params; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 174 | val mx' = check_mixfix_global (b, null params) mx; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 175 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 176 | val (const, lthy2) = lthy | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 177 | |> Local_Theory.background_theory_result (Sign.declare_const lthy ((b, U), mx')); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 178 | val lhs = Term.list_comb (const, params); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 179 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 180 | val ((_, def), lthy3) = lthy2 | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 181 | |> Local_Theory.background_theory_result | 
| 61261 
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
 wenzelm parents: 
60924diff
changeset | 182 | (Thm.add_def (Proof_Context.defs_context lthy2) false false | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 183 | (Thm.def_binding_optional b b_def, Logic.mk_equals (lhs, rhs))); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 184 | in ((lhs, def), lthy3) end; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 185 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 186 | fun background_declaration decl lthy = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 187 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 188 | val theory_decl = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 189 | Local_Theory.standard_form lthy | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 190 | (Proof_Context.init_global (Proof_Context.theory_of lthy)) decl; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 191 | in Local_Theory.background_theory (Context.theory_map theory_decl) lthy end; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 192 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 193 | fun background_abbrev (b, global_rhs) params = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 194 | Local_Theory.background_theory_result (Sign.add_abbrev Print_Mode.internal (b, global_rhs)) | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58028diff
changeset | 195 | #>> apply2 (fn t => Term.list_comb (Logic.unvarify_global t, params)) | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 196 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 197 | |
| 60283 | 198 | |
| 60340 | 199 | (** nested local theories primitives **) | 
| 200 | ||
| 201 | fun standard_facts lthy ctxt = | |
| 202 | Attrib.transform_facts (Local_Theory.standard_morphism lthy ctxt); | |
| 203 | ||
| 204 | fun standard_notes pred kind facts lthy = | |
| 205 | Local_Theory.map_contexts (fn level => fn ctxt => | |
| 206 | if pred (Local_Theory.level lthy, level) | |
| 207 | then Attrib.local_notes kind (standard_facts lthy ctxt facts) ctxt |> snd | |
| 208 | else ctxt) lthy; | |
| 209 | ||
| 210 | fun standard_declaration pred decl lthy = | |
| 211 | Local_Theory.map_contexts (fn level => fn ctxt => | |
| 212 | if pred (Local_Theory.level lthy, level) | |
| 213 | then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt | |
| 214 | else ctxt) lthy; | |
| 215 | ||
| 216 | fun standard_const pred prmode ((b, mx), rhs) = | |
| 217 | standard_declaration pred (const_decl (K true) prmode ((b, mx), rhs)); | |
| 218 | ||
| 219 | ||
| 220 | (** lifting target primitives to local theory operations **) | |
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 221 | |
| 38309 | 222 | (* define *) | 
| 223 | ||
| 46992 
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
 wenzelm parents: 
46916diff
changeset | 224 | fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy = | 
| 38309 | 225 | let | 
| 59616 | 226 | val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy); | 
| 38309 | 227 | |
| 228 | (*term and type parameters*) | |
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59616diff
changeset | 229 | val ((defs, _), rhs') = Thm.cterm_of lthy rhs | 
| 47276 | 230 | |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of; | 
| 38309 | 231 | |
| 47272 
ca31cfa509b1
refined define/abbrev: allow extra fixes in aux. context vs. bottom target (NB: export_term expands defined variables, leaving fixed ones);
 wenzelm parents: 
47250diff
changeset | 232 | val xs = Variable.add_fixed lthy rhs' []; | 
| 38309 | 233 | val T = Term.fastype_of rhs; | 
| 234 | val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []); | |
| 235 | val extra_tfrees = rev (subtract (op =) tfreesT (Term.add_tfrees rhs [])); | |
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 236 | val mx' = check_mixfix lthy (b, extra_tfrees) mx; | 
| 38309 | 237 | |
| 238 | val type_params = map (Logic.mk_type o TFree) extra_tfrees; | |
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58028diff
changeset | 239 | val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) xs); | 
| 38309 | 240 | val params = type_params @ term_params; | 
| 241 | ||
| 242 | val U = map Term.fastype_of params ---> T; | |
| 243 | ||
| 244 | (*foundation*) | |
| 45353 | 245 | val ((lhs', global_def), lthy2) = lthy | 
| 246 | |> foundation (((b, U), mx'), (b_def, rhs')) (type_params, term_params); | |
| 38309 | 247 | |
| 248 | (*local definition*) | |
| 63344 | 249 | val ([(lhs, (_, local_def))], lthy3) = lthy2 | 
| 63346 | 250 | |> Context_Position.set_visible false | 
| 63352 | 251 | |> Local_Defs.define [((b, NoSyn), (Binding.empty_atts, lhs'))] | 
| 63346 | 252 | ||> Context_Position.restore_visible lthy2; | 
| 47240 | 253 | |
| 254 | (*result*) | |
| 47238 | 255 | val def = | 
| 47240 | 256 | Thm.transitive local_def global_def | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59616diff
changeset | 257 | |> Local_Defs.contract lthy3 defs (Thm.cterm_of lthy3 (Logic.mk_equals (lhs, rhs))); | 
| 38315 | 258 | val ([(res_name, [res])], lthy4) = lthy3 | 
| 47080 | 259 | |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])]; | 
| 38315 | 260 | in ((lhs, (res_name, res)), lthy4) end; | 
| 38309 | 261 | |
| 262 | ||
| 263 | (* notes *) | |
| 264 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 265 | local | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 266 | |
| 38309 | 267 | fun import_export_proof ctxt (name, raw_th) = | 
| 268 | let | |
| 59616 | 269 | val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of ctxt); | 
| 38309 | 270 | |
| 271 | (*export assumes/defines*) | |
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 272 | val th = Goal.norm_result ctxt raw_th; | 
| 45407 
a83574606719
more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
 wenzelm parents: 
45390diff
changeset | 273 | val ((defs, asms), th') = Local_Defs.export ctxt thy_ctxt th; | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
52230diff
changeset | 274 | val asms' = map (rewrite_rule ctxt (Drule.norm_hhf_eqs @ defs)) asms; | 
| 38309 | 275 | |
| 276 | (*export fixes*) | |
| 277 | val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []); | |
| 278 | val frees = map Free (Thm.fold_terms Term.add_frees th' []); | |
| 45352 | 279 | val (th'' :: vs) = | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59616diff
changeset | 280 | (th' :: map (Drule.mk_term o Thm.cterm_of ctxt) (map Logic.mk_type tfrees @ frees)) | 
| 38309 | 281 | |> Variable.export ctxt thy_ctxt | 
| 282 | |> Drule.zero_var_indexes_list; | |
| 283 | ||
| 284 | (*thm definition*) | |
| 45413 
117ff038f8f7
disabled Thm.compress (again) -- costs for building tables tend to be higher than potential benefit;
 wenzelm parents: 
45407diff
changeset | 285 | val result = Global_Theory.name_thm true true name th''; | 
| 38309 | 286 | |
| 287 | (*import fixes*) | |
| 288 | val (tvars, vars) = | |
| 289 | chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs) | |
| 290 | |>> map Logic.dest_type; | |
| 291 | ||
| 292 | val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees); | |
| 60642 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 293 | val inst = | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 294 | map_filter | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 295 | (fn (Var (xi, T), t) => | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 296 | SOME ((xi, Term_Subst.instantiateT instT T), | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 297 | Thm.cterm_of ctxt (Term.map_types (Term_Subst.instantiateT instT) t)) | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 298 | | _ => NONE) (vars ~~ frees); | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60345diff
changeset | 299 | val result' = Thm.instantiate (map (apsnd (Thm.ctyp_of ctxt)) instT, inst) result; | 
| 38309 | 300 | |
| 301 | (*import assumes/defines*) | |
| 302 | val result'' = | |
| 45407 
a83574606719
more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
 wenzelm parents: 
45390diff
changeset | 303 | (fold (curry op COMP) asms' result' | 
| 
a83574606719
more specific treatment of defines/assumes -- avoid normalizing defs by themselves (NB: locale specifications and Local_Theory.define may lead to arbitrary mixture);
 wenzelm parents: 
45390diff
changeset | 304 |         handle THM _ => raise THM ("Failed to re-import result", 0, result' :: asms'))
 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
52230diff
changeset | 305 | |> Local_Defs.contract ctxt defs (Thm.cprop_of th) | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 306 | |> Goal.norm_result ctxt | 
| 39557 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
38831diff
changeset | 307 | |> Global_Theory.name_thm false false name; | 
| 38309 | 308 | |
| 309 | in (result'', result) end; | |
| 310 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 311 | in | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 312 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 313 | fun notes target_notes kind facts lthy = | 
| 38309 | 314 | let | 
| 315 | val facts' = facts | |
| 39557 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
38831diff
changeset | 316 | |> map (fn (a, bs) => (a, Global_Theory.burrow_fact (Global_Theory.name_multi | 
| 38309 | 317 | (Local_Theory.full_name lthy (fst a))) bs)) | 
| 39557 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
38831diff
changeset | 318 | |> Global_Theory.map_facts (import_export_proof lthy); | 
| 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
38831diff
changeset | 319 | val local_facts = Global_Theory.map_facts #1 facts'; | 
| 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
38831diff
changeset | 320 | val global_facts = Global_Theory.map_facts #2 facts'; | 
| 38309 | 321 | in | 
| 322 | lthy | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 323 | |> target_notes kind global_facts (Attrib.partial_evaluation lthy local_facts) | 
| 47249 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47246diff
changeset | 324 | |> Attrib.local_notes kind local_facts | 
| 38309 | 325 | end; | 
| 326 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 327 | end; | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 328 | |
| 38309 | 329 | |
| 330 | (* abbrev *) | |
| 331 | ||
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 332 | fun abbrev target_abbrev prmode ((b, mx), rhs) lthy = | 
| 38309 | 333 | let | 
| 60345 
592806806494
completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
 haftmann parents: 
60344diff
changeset | 334 | val (global_rhs, (extra_tfrees, (type_params, term_params))) = export_abbrev lthy I rhs; | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 335 | val mx' = check_mixfix lthy (b, extra_tfrees) mx; | 
| 38309 | 336 | in | 
| 337 | lthy | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 338 | |> target_abbrev prmode (b, mx') global_rhs (type_params, term_params) | 
| 63346 | 339 | |> Context_Position.set_visible false | 
| 57109 | 340 | |> Proof_Context.add_abbrev Print_Mode.internal (b, rhs) |> snd | 
| 341 | |> Local_Defs.fixed_abbrev ((b, NoSyn), rhs) | |
| 62992 | 342 | ||> Context_Position.restore_visible lthy | 
| 38309 | 343 | end; | 
| 344 | ||
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 345 | |
| 60283 | 346 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 347 | (** theory target primitives **) | 
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 348 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 349 | fun theory_target_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) = | 
| 47284 
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
 wenzelm parents: 
47283diff
changeset | 350 | background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) | 
| 57192 
180e955711cf
yet another attempt for terminology: foo_target_bar denotes an operation bar operating solely on the target context of target foo, foo_bar denotes a whole stack of operations to accomplish bar for target foo
 haftmann parents: 
57191diff
changeset | 351 | #-> (fn (lhs, def) => standard_const (op <>) Syntax.mode_default ((b, mx), lhs) | 
| 57057 | 352 | #> pair (lhs, def)); | 
| 47284 
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
 wenzelm parents: 
47283diff
changeset | 353 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 354 | fun theory_target_notes kind global_facts local_facts = | 
| 57191 | 355 | Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd) | 
| 356 | #> standard_notes (op <>) kind local_facts; | |
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 357 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 358 | fun theory_target_abbrev prmode (b, mx) global_rhs params = | 
| 47286 
392c4cd97e5c
more uniform theory_abbrev with const_declaration;
 wenzelm parents: 
47285diff
changeset | 359 | Local_Theory.background_theory_result | 
| 57109 | 360 | (Sign.add_abbrev (#1 prmode) (b, global_rhs) #-> | 
| 47291 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 361 | (fn (lhs, _) => (* FIXME type_params!? *) | 
| 63339 | 362 | Sign.notation true prmode | 
| 363 | [(lhs, check_mixfix_global (b, null (snd params)) mx)] #> pair lhs)) | |
| 62764 | 364 | #-> (fn lhs => | 
| 365 | standard_const (op <>) prmode | |
| 366 | ((b, if null (snd params) then NoSyn else mx), | |
| 367 | Term.list_comb (Logic.unvarify_global lhs, snd params))); | |
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 368 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 369 | |
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 370 | (** theory operations **) | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 371 | |
| 60344 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 372 | val theory_abbrev = abbrev theory_target_abbrev; | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 373 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 374 | fun theory_declaration decl = | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 375 | background_declaration decl #> standard_declaration (K true) decl; | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 376 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 377 | val theory_registration = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 378 | Local_Theory.raw_theory o Context.theory_map ooo Locale.add_registration; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 379 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 380 | |
| 60283 | 381 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 382 | (** locale target primitives **) | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 383 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 384 | fun locale_target_notes locale kind global_facts local_facts = | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 385 | Local_Theory.background_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 386 | (Attrib.global_notes kind (Attrib.map_facts (K []) global_facts) #> snd) #> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 387 | (fn lthy => lthy |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 388 | Local_Theory.target (fn ctxt => ctxt |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 389 | Locale.add_thmss locale kind (standard_facts lthy ctxt local_facts))) #> | 
| 57191 | 390 | standard_notes (fn (this, other) => other <> 0 andalso this <> other) kind local_facts; | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 391 | |
| 57192 
180e955711cf
yet another attempt for terminology: foo_target_bar denotes an operation bar operating solely on the target context of target foo, foo_bar denotes a whole stack of operations to accomplish bar for target foo
 haftmann parents: 
57191diff
changeset | 392 | fun locale_target_declaration locale syntax decl lthy = lthy | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 393 | |> Local_Theory.target (fn ctxt => ctxt |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 394 | Locale.add_declaration locale syntax | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 395 | (Morphism.transform (Local_Theory.standard_morphism lthy ctxt) decl)); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 396 | |
| 60341 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 397 | fun locale_target_const locale phi_pred prmode ((b, mx), rhs) = | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 398 | locale_target_declaration locale true (const_decl phi_pred prmode ((b, mx), rhs)) | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 399 | |
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 400 | |
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 401 | (** locale operations **) | 
| 
fcbd7f0c52c3
clearly separated target primitives (target_foo) from self-contained target operations (foo)
 haftmann parents: 
60340diff
changeset | 402 | |
| 57193 | 403 | fun locale_declaration locale {syntax, pervasive} decl =
 | 
| 404 | pervasive ? background_declaration decl | |
| 405 | #> locale_target_declaration locale syntax decl | |
| 406 | #> standard_declaration (fn (_, other) => other <> 0) decl; | |
| 407 | ||
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 408 | fun locale_const locale prmode ((b, mx), rhs) = | 
| 57192 
180e955711cf
yet another attempt for terminology: foo_target_bar denotes an operation bar operating solely on the target context of target foo, foo_bar denotes a whole stack of operations to accomplish bar for target foo
 haftmann parents: 
57191diff
changeset | 409 | locale_target_const locale (K true) prmode ((b, mx), rhs) | 
| 
180e955711cf
yet another attempt for terminology: foo_target_bar denotes an operation bar operating solely on the target context of target foo, foo_bar denotes a whole stack of operations to accomplish bar for target foo
 haftmann parents: 
57191diff
changeset | 410 | #> standard_const (fn (this, other) => other <> 0 andalso this <> other) prmode ((b, mx), rhs); | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 411 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 412 | fun locale_dependency locale dep_morph mixin export = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 413 | (Local_Theory.raw_theory ooo Locale.add_dependency locale) dep_morph mixin export | 
| 57926 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57193diff
changeset | 414 | #> Locale.activate_fragment_nonbrittle dep_morph mixin export; | 
| 47279 
4bab649dedf0
clarified standard_declaration vs. theory_declaration;
 wenzelm parents: 
47276diff
changeset | 415 | |
| 60344 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 416 | |
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 417 | (** locale abbreviations **) | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 418 | |
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 419 | fun locale_target_abbrev locale prmode (b, mx) global_rhs params = | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 420 | background_abbrev (b, global_rhs) (snd params) | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 421 | #-> (fn (lhs, _) => locale_const locale prmode ((b, mx), lhs)); | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 422 | |
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 423 | fun locale_abbrev locale = abbrev (locale_target_abbrev locale); | 
| 
a40369ea3ba5
self-contained formulation of abbrev for named targets
 haftmann parents: 
60342diff
changeset | 424 | |
| 66337 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 425 | |
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 426 | (** initialisation **) | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 427 | |
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 428 | fun init {background_naming, setup, conclude} operations thy =
 | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 429 | thy | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 430 | |> Sign.change_begin | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 431 | |> setup | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 432 | |> Local_Theory.init | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 433 |       {background_naming = background_naming,
 | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 434 | exit = conclude #> Local_Theory.target_of #> Sign.change_end_local} | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 435 | operations; | 
| 
5caea089dd17
more structural sharing between common target Generic_Target.init
 haftmann parents: 
63352diff
changeset | 436 | |
| 38309 | 437 | end; |