| author | wenzelm | 
| Sun, 18 Jan 2015 22:20:48 +0100 | |
| changeset 59400 | d833cba5cce5 | 
| parent 59058 | a78612c67ec0 | 
| child 59573 | d09cc83cdce9 | 
| 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 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 10 | (* consts *) | 
| 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 | 11 | val standard_const: (int * int -> bool) -> Syntax.mode -> (binding * mixfix) * term -> | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 12 | local_theory -> local_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 13 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 14 | (* background operations *) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 15 | 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 | 16 | 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 | 17 | 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 | 18 | 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 | 19 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 20 | (* lifting primitives to local theory operations *) | 
| 40782 | 21 | val define: (((binding * typ) * mixfix) * (binding * term) -> | 
| 22 | 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 | 23 | bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory -> | 
| 40782 | 24 | (term * (string * thm)) * local_theory | 
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 25 | val notes: | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 26 | (string -> (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 27 | (Attrib.binding * (thm list * Token.src list) list) list -> local_theory -> local_theory) -> | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 28 | string -> (Attrib.binding * (thm list * Token.src list) list) list -> local_theory -> | 
| 40782 | 29 | (string * thm list) list * local_theory | 
| 57118 | 30 | val abbrev: (string * bool -> binding * mixfix -> term -> | 
| 57160 | 31 | term list * term list -> local_theory -> local_theory) -> | 
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 32 | string * bool -> (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 | 33 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 34 | (* theory operations *) | 
| 40782 | 35 | val theory_foundation: ((binding * typ) * mixfix) * (binding * term) -> | 
| 36 | term list * term list -> local_theory -> (term * thm) * local_theory | |
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 37 | val theory_notes: string -> | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 38 | (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 39 | (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 40782 | 40 | local_theory -> local_theory | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 41 | val theory_declaration: declaration -> local_theory -> local_theory | 
| 57160 | 42 | val theory_abbrev: Syntax.mode -> (binding * mixfix) -> term -> term list * term list -> | 
| 47286 
392c4cd97e5c
more uniform theory_abbrev with const_declaration;
 wenzelm parents: 
47285diff
changeset | 43 | local_theory -> local_theory | 
| 52153 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 44 | 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 | 45 | local_theory -> local_theory | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 46 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 47 | (* locale operations *) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 48 | val locale_notes: string -> string -> | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 49 | (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57926diff
changeset | 50 | (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 51 | 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 | 52 | val locale_target_declaration: string -> bool -> declaration -> local_theory -> local_theory | 
| 57193 | 53 |   val locale_declaration: string -> {syntax: bool, pervasive: bool} -> declaration ->
 | 
| 54 | 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 | 55 | val locale_target_const: string -> (morphism -> bool) -> Syntax.mode -> | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 56 | (binding * mixfix) * term -> local_theory -> local_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 57 | 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 | 58 | local_theory -> local_theory | 
| 52153 
f5773a46cf05
more specific structure for registration into theory and dependency onto locale
 haftmann parents: 
47313diff
changeset | 59 | 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 | 60 | local_theory -> local_theory | 
| 45353 | 61 | end | 
| 38309 | 62 | |
| 63 | structure Generic_Target: GENERIC_TARGET = | |
| 64 | struct | |
| 65 | ||
| 57191 | 66 | (** notes **) | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 67 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 68 | fun standard_facts lthy ctxt = | 
| 58028 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58011diff
changeset | 69 | Attrib.transform_facts (Local_Theory.standard_morphism lthy ctxt); | 
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 70 | |
| 57191 | 71 | fun standard_notes pred kind facts lthy = | 
| 72 | Local_Theory.map_contexts (fn level => fn ctxt => | |
| 73 | if pred (Local_Theory.level lthy, level) | |
| 74 | then Attrib.local_notes kind (standard_facts lthy ctxt facts) ctxt |> snd | |
| 75 | else ctxt) lthy; | |
| 76 | ||
| 77 | ||
| 78 | (** declarations **) | |
| 79 | ||
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 80 | fun standard_declaration pred decl lthy = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 81 | Local_Theory.map_contexts (fn level => fn ctxt => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 82 | if pred (Local_Theory.level lthy, level) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 83 | then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 84 | else ctxt) lthy; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 85 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 86 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 87 | (** consts **) | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 88 | |
| 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 89 | fun check_mixfix ctxt (b, extra_tfrees) mx = | 
| 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 90 | if null extra_tfrees then mx | 
| 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 91 | else | 
| 56294 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 92 | (if Context_Position.is_visible ctxt then | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 93 | warning | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 94 |         ("Additional type variable(s) in specification of " ^ Binding.print b ^ ": " ^
 | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 95 | commas (map (Syntax.string_of_typ ctxt o TFree) (sort_wrt #1 extra_tfrees)) ^ | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 96 | (if mx = NoSyn then "" | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 97 | else "\nDropping mixfix syntax " ^ Pretty.string_of (Mixfix.pretty_mixfix mx))) | 
| 
85911b8a6868
prefer Context_Position where a context is available;
 wenzelm parents: 
56141diff
changeset | 98 | else (); NoSyn); | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 99 | |
| 47291 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 100 | fun check_mixfix_global (b, no_params) mx = | 
| 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 101 | if no_params orelse mx = NoSyn then mx | 
| 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 102 |   else (warning ("Dropping global mixfix syntax: " ^ Binding.print b ^ " " ^
 | 
| 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 103 | Pretty.string_of (Mixfix.pretty_mixfix mx)); NoSyn); | 
| 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 104 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 105 | 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 | 106 | if phi_pred phi then | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 107 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 108 | val b' = Morphism.binding phi b; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 109 | val rhs' = Morphism.term phi rhs; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 110 | val same_shape = Term.aconv_untyped (rhs, rhs'); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 111 | val const_alias = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 112 | if same_shape then | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 113 | (case rhs' of | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 114 | Const (c, T) => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 115 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 116 | val thy = Context.theory_of context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 117 | val ctxt = Context.proof_of context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 118 | in | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 119 | (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 | 120 | 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 | 121 | | NONE => NONE) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 122 | end | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 123 | | _ => NONE) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 124 | else NONE; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 125 | in | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 126 | case const_alias of | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 127 | SOME c => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 128 | context | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 129 | |> 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 | 130 | |> 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 | 131 | | NONE => | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 132 | context | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 133 | |> Proof_Context.generic_add_abbrev Print_Mode.internal (b', Term.close_schematic_term rhs') | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 134 | |-> (fn (const as Const (c, _), _) => same_shape ? | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 135 | (Proof_Context.generic_revert_abbrev (#1 prmode) c #> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 136 | Morphism.form (Proof_Context.generic_notation true prmode [(const, mx)]))) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 137 | end | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 138 | else context; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 139 | |
| 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 | 140 | fun standard_const pred prmode ((b, mx), rhs) = | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 141 | standard_declaration pred (const_decl (K true) prmode ((b, mx), rhs)); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 142 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 143 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 144 | (** background primitives **) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 145 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 146 | 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 | 147 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 148 | val params = type_params @ term_params; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 149 | 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 | 150 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 151 | val (const, lthy2) = lthy | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 152 | |> 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 | 153 | val lhs = Term.list_comb (const, params); | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 154 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 155 | val ((_, def), lthy3) = lthy2 | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 156 | |> Local_Theory.background_theory_result | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 157 | (Thm.add_def lthy2 false false | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 158 | (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 | 159 | in ((lhs, def), lthy3) end; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 160 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 161 | fun background_declaration decl lthy = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 162 | let | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 163 | val theory_decl = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 164 | Local_Theory.standard_form lthy | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 165 | (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 | 166 | 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 | 167 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 168 | fun background_abbrev (b, global_rhs) params = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 169 | 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 | 170 | #>> 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 | 171 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 172 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 173 | (** lifting primitive to local theory operations **) | 
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 174 | |
| 38309 | 175 | (* define *) | 
| 176 | ||
| 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 | 177 | fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy = | 
| 38309 | 178 | let | 
| 42360 | 179 | val thy = Proof_Context.theory_of lthy; | 
| 180 | val thy_ctxt = Proof_Context.init_global thy; | |
| 38309 | 181 | |
| 182 | (*term and type parameters*) | |
| 47276 | 183 | val ((defs, _), rhs') = Thm.cterm_of thy rhs | 
| 184 | |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of; | |
| 38309 | 185 | |
| 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 | 186 | val xs = Variable.add_fixed lthy rhs' []; | 
| 38309 | 187 | val T = Term.fastype_of rhs; | 
| 188 | val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []); | |
| 189 | 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 | 190 | val mx' = check_mixfix lthy (b, extra_tfrees) mx; | 
| 38309 | 191 | |
| 192 | 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 | 193 | val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) xs); | 
| 38309 | 194 | val params = type_params @ term_params; | 
| 195 | ||
| 196 | val U = map Term.fastype_of params ---> T; | |
| 197 | ||
| 198 | (*foundation*) | |
| 45353 | 199 | val ((lhs', global_def), lthy2) = lthy | 
| 200 | |> foundation (((b, U), mx'), (b_def, rhs')) (type_params, term_params); | |
| 38309 | 201 | |
| 202 | (*local definition*) | |
| 38315 | 203 | val ((lhs, local_def), lthy3) = lthy2 | 
| 38309 | 204 | |> Local_Defs.add_def ((b, NoSyn), lhs'); | 
| 47240 | 205 | |
| 206 | (*result*) | |
| 47238 | 207 | val def = | 
| 47240 | 208 | Thm.transitive local_def global_def | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
52230diff
changeset | 209 | |> Local_Defs.contract lthy3 defs | 
| 47240 | 210 | (Thm.cterm_of (Proof_Context.theory_of lthy3) (Logic.mk_equals (lhs, rhs))); | 
| 38315 | 211 | val ([(res_name, [res])], lthy4) = lthy3 | 
| 47080 | 212 | |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])]; | 
| 38315 | 213 | in ((lhs, (res_name, res)), lthy4) end; | 
| 38309 | 214 | |
| 215 | ||
| 216 | (* notes *) | |
| 217 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 218 | local | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 219 | |
| 38309 | 220 | fun import_export_proof ctxt (name, raw_th) = | 
| 221 | let | |
| 42360 | 222 | val thy = Proof_Context.theory_of ctxt; | 
| 223 | val thy_ctxt = Proof_Context.init_global thy; | |
| 38309 | 224 | val certT = Thm.ctyp_of thy; | 
| 225 | val cert = Thm.cterm_of thy; | |
| 226 | ||
| 227 | (*export assumes/defines*) | |
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 228 | 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 | 229 | 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 | 230 | val asms' = map (rewrite_rule ctxt (Drule.norm_hhf_eqs @ defs)) asms; | 
| 38309 | 231 | |
| 232 | (*export fixes*) | |
| 233 | val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []); | |
| 234 | val frees = map Free (Thm.fold_terms Term.add_frees th' []); | |
| 45352 | 235 | val (th'' :: vs) = | 
| 236 | (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees)) | |
| 38309 | 237 | |> Variable.export ctxt thy_ctxt | 
| 238 | |> Drule.zero_var_indexes_list; | |
| 239 | ||
| 240 | (*thm definition*) | |
| 45413 
117ff038f8f7
disabled Thm.compress (again) -- costs for building tables tend to be higher than potential benefit;
 wenzelm parents: 
45407diff
changeset | 241 | val result = Global_Theory.name_thm true true name th''; | 
| 38309 | 242 | |
| 243 | (*import fixes*) | |
| 244 | val (tvars, vars) = | |
| 245 | chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs) | |
| 246 | |>> map Logic.dest_type; | |
| 247 | ||
| 248 | val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees); | |
| 249 | val inst = filter (is_Var o fst) (vars ~~ frees); | |
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58028diff
changeset | 250 | val cinstT = map (apply2 certT o apfst TVar) instT; | 
| 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58028diff
changeset | 251 | val cinst = map (apply2 (cert o Term.map_types (Term_Subst.instantiateT instT))) inst; | 
| 38309 | 252 | val result' = Thm.instantiate (cinstT, cinst) result; | 
| 253 | ||
| 254 | (*import assumes/defines*) | |
| 255 | 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 | 256 | (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 | 257 |         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 | 258 | |> Local_Defs.contract ctxt defs (Thm.cprop_of th) | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 259 | |> 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 | 260 | |> Global_Theory.name_thm false false name; | 
| 38309 | 261 | |
| 262 | in (result'', result) end; | |
| 263 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 264 | in | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 265 | |
| 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 | 266 | fun notes notes' kind facts lthy = | 
| 38309 | 267 | let | 
| 268 | 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 | 269 | |> map (fn (a, bs) => (a, Global_Theory.burrow_fact (Global_Theory.name_multi | 
| 38309 | 270 | (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 | 271 | |> 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 | 272 | 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 | 273 | val global_facts = Global_Theory.map_facts #2 facts'; | 
| 38309 | 274 | in | 
| 275 | lthy | |
| 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 | 276 | |> 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 | 277 | |> Attrib.local_notes kind local_facts | 
| 38309 | 278 | end; | 
| 279 | ||
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 280 | end; | 
| 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 281 | |
| 38309 | 282 | |
| 283 | (* abbrev *) | |
| 284 | ||
| 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 | 285 | fun abbrev abbrev' prmode ((b, mx), rhs) lthy = | 
| 38309 | 286 | let | 
| 42360 | 287 | val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy); | 
| 38309 | 288 | |
| 57109 | 289 | val rhs' = Assumption.export_term lthy (Local_Theory.target_of lthy) rhs; | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58028diff
changeset | 290 | val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) (Variable.add_fixed lthy rhs' [])); | 
| 57160 | 291 | val u = fold_rev lambda term_params rhs'; | 
| 47290 | 292 | val global_rhs = singleton (Variable.polymorphic thy_ctxt) u; | 
| 38309 | 293 | |
| 294 | val extra_tfrees = | |
| 295 | subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []); | |
| 38312 
9dd57db3c0f2
moved extra_tfrees check for mixfix syntax to Generic_Target
 haftmann parents: 
38311diff
changeset | 296 | val mx' = check_mixfix lthy (b, extra_tfrees) mx; | 
| 57160 | 297 | val type_params = map (Logic.mk_type o TFree) extra_tfrees; | 
| 38309 | 298 | in | 
| 299 | lthy | |
| 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 | 300 | |> abbrev' prmode (b, mx') global_rhs (type_params, term_params) | 
| 57109 | 301 | |> Proof_Context.add_abbrev Print_Mode.internal (b, rhs) |> snd | 
| 302 | |> Local_Defs.fixed_abbrev ((b, NoSyn), rhs) | |
| 38309 | 303 | end; | 
| 304 | ||
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 305 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 306 | (** theory operations **) | 
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 307 | |
| 47284 
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
 wenzelm parents: 
47283diff
changeset | 308 | fun theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) = | 
| 
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
 wenzelm parents: 
47283diff
changeset | 309 | 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 | 310 | #-> (fn (lhs, def) => standard_const (op <>) Syntax.mode_default ((b, mx), lhs) | 
| 57057 | 311 | #> pair (lhs, def)); | 
| 47284 
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
 wenzelm parents: 
47283diff
changeset | 312 | |
| 47250 
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
 wenzelm parents: 
47249diff
changeset | 313 | fun theory_notes kind global_facts local_facts = | 
| 57191 | 314 | Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd) | 
| 315 | #> standard_notes (op <>) kind local_facts; | |
| 38341 
72dba5bd5f63
moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
 haftmann parents: 
38315diff
changeset | 316 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 317 | fun theory_declaration decl = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 318 | background_declaration decl #> standard_declaration (K true) decl; | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 319 | |
| 57118 | 320 | fun theory_abbrev prmode (b, mx) global_rhs params = | 
| 47286 
392c4cd97e5c
more uniform theory_abbrev with const_declaration;
 wenzelm parents: 
47285diff
changeset | 321 | Local_Theory.background_theory_result | 
| 57109 | 322 | (Sign.add_abbrev (#1 prmode) (b, global_rhs) #-> | 
| 47291 
6a641856a0e9
better drop background syntax if entity depends on parameters;
 wenzelm parents: 
47290diff
changeset | 323 | (fn (lhs, _) => (* FIXME type_params!? *) | 
| 57160 | 324 | Sign.notation true prmode [(lhs, check_mixfix_global (b, null (snd params)) mx)] #> pair lhs)) | 
| 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 | 325 | #-> (fn lhs => standard_const (op <>) prmode | 
| 57160 | 326 | ((b, if null (snd params) then NoSyn else mx), 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 | 327 | |
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 328 | val theory_registration = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 329 | 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 | 330 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 331 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 332 | (** locale operations **) | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 333 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 334 | fun locale_notes locale kind global_facts local_facts = | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 335 | Local_Theory.background_theory | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 336 | (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 | 337 | (fn lthy => lthy |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 338 | Local_Theory.target (fn ctxt => ctxt |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 339 | Locale.add_thmss locale kind (standard_facts lthy ctxt local_facts))) #> | 
| 57191 | 340 | 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 | 341 | |
| 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 | 342 | 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 | 343 | |> Local_Theory.target (fn ctxt => ctxt |> | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 344 | Locale.add_declaration locale syntax | 
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 345 | (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 | 346 | |
| 57193 | 347 | fun locale_declaration locale {syntax, pervasive} decl =
 | 
| 348 | pervasive ? background_declaration decl | |
| 349 | #> locale_target_declaration locale syntax decl | |
| 350 | #> standard_declaration (fn (_, other) => other <> 0) decl; | |
| 351 | ||
| 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 | 352 | fun locale_target_const locale phi_pred 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 | 353 | locale_target_declaration locale true (const_decl phi_pred prmode ((b, mx), rhs)) | 
| 57190 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 354 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 355 | 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 | 356 | 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 | 357 | #> 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 | 358 | |
| 
05ad9aae4537
recovered structure of module, which got somehow convoluted due to incremental modifications
 haftmann parents: 
57189diff
changeset | 359 | 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 | 360 | (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 | 361 | #> Locale.activate_fragment_nonbrittle dep_morph mixin export; | 
| 47279 
4bab649dedf0
clarified standard_declaration vs. theory_declaration;
 wenzelm parents: 
47276diff
changeset | 362 | |
| 38309 | 363 | end; |