src/Pure/Isar/generic_target.ML
author wenzelm
Wed, 27 Dec 2023 20:40:15 +0100
changeset 79376 b275e3379024
parent 79372 d02c8adce4e6
child 79435 e83f5e3813b1
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 41228
diff changeset
     1
(*  Title:      Pure/Isar/generic_target.ML
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     2
    Author:     Makarius
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     4
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     5
Common target infrastructure.
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     6
*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     7
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     8
signature GENERIC_TARGET =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
     9
sig
60345
592806806494 completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
haftmann
parents: 60344
diff changeset
    10
  (*auxiliary*)
592806806494 completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
haftmann
parents: 60344
diff 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: 60344
diff changeset
    12
      (term -> term) -> term -> term * ((string * sort) list * (term list * term list))
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
    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: 60344
diff 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: 60344
diff changeset
    15
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    16
  (*background primitives*)
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff 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: 57189
diff changeset
    18
    term list * term list -> local_theory -> (term * thm) * local_theory
78085
dd7bb7f99ad5 tuned signature;
wenzelm
parents: 78072
diff changeset
    19
  val background_declaration: Morphism.declaration_entity -> local_theory -> local_theory
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    20
  val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
    21
  val add_foundation_interpretation: (binding * (term * term list) -> Context.generic -> Context.generic) ->
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
    22
    theory -> theory
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    23
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    24
  (*nested local theories primitives*)
67652
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    25
  val standard_facts: local_theory -> Proof.context -> Attrib.fact list -> Attrib.fact list
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    26
  val standard_notes: (int * int -> bool) -> string -> Attrib.fact list ->
63269
27d51aa2d711 tuned signature;
wenzelm
parents: 63267
diff changeset
    27
    local_theory -> local_theory
78085
dd7bb7f99ad5 tuned signature;
wenzelm
parents: 78072
diff changeset
    28
  val standard_declaration: (int * int -> bool) -> Morphism.declaration_entity ->
78072
001739cb8d08 clarified signature: more explicit types;
wenzelm
parents: 78044
diff changeset
    29
    local_theory -> local_theory
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    30
  val standard_const: (int * int -> bool) -> Syntax.mode -> (binding * mixfix) * term ->
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    31
    local_theory -> local_theory
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
    32
  val local_interpretation: Locale.registration ->
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
    33
    local_theory -> local_theory
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    34
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
    35
  (*lifting target primitives to local theory operations*)
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    36
  val define: (((binding * typ) * mixfix) * (binding * term) ->
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    37
      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: 46916
diff changeset
    38
    bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory ->
40782
aa533c5e3f48 superficial tuning;
wenzelm
parents: 39557
diff changeset
    39
    (term * (string * thm)) * local_theory
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
    40
  val notes:
67652
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    41
    (string -> Attrib.fact list -> Attrib.fact list -> local_theory -> local_theory) ->
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    42
    string -> Attrib.fact list -> local_theory -> (string * thm list) list * local_theory
60337
haftmann
parents: 60283
diff changeset
    43
  val abbrev: (Syntax.mode -> binding * mixfix -> term ->
57160
cf00d3c9db43 explicit passing of params
haftmann
parents: 57118
diff changeset
    44
      term list * term list -> local_theory -> local_theory) ->
60337
haftmann
parents: 60283
diff changeset
    45
    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: 57189
diff changeset
    46
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    47
  (*theory target primitives*)
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    48
  val theory_target_foundation: ((binding * typ) * mixfix) * (binding * term) ->
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    49
     term list * term list -> local_theory -> (term * thm) * local_theory
67652
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    50
  val theory_target_notes: string -> Attrib.fact list -> Attrib.fact list ->
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    51
    local_theory -> local_theory
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    52
  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: 60340
diff changeset
    53
    local_theory -> local_theory
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    54
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    55
  (*theory target operations*)
60344
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
    56
  val theory_abbrev: Syntax.mode -> (binding * mixfix) * term ->
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
    57
    local_theory -> (term * term) * local_theory
78085
dd7bb7f99ad5 tuned signature;
wenzelm
parents: 78072
diff changeset
    58
  val theory_declaration: Morphism.declaration_entity -> local_theory -> local_theory
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
    59
  val theory_registration: Locale.registration -> local_theory -> local_theory
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    60
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    61
  (*locale target primitives*)
67652
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    62
  val locale_target_notes: string -> string -> Attrib.fact list -> Attrib.fact list ->
11716a084cae clarified signature;
wenzelm
parents: 66337
diff changeset
    63
    local_theory -> local_theory
63339
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
    64
  val locale_target_abbrev: string -> Syntax.mode ->
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
    65
    (binding * mixfix) -> term -> term list * term list -> local_theory -> local_theory
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
    66
  val locale_target_declaration: string -> {syntax: bool, pos: Position.T} ->
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
    67
    Morphism.declaration_entity -> local_theory -> local_theory
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    68
  val locale_target_const: string -> (morphism -> bool) -> Syntax.mode ->
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    69
    (binding * mixfix) * term -> local_theory -> local_theory
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    70
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
    71
  (*locale operations*)
60344
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
    72
  val locale_abbrev: string -> Syntax.mode -> (binding * mixfix) * term ->
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
    73
    local_theory -> (term * term) * local_theory
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
    74
  val locale_declaration: string -> {syntax: bool, pervasive: bool, pos: Position.T} ->
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
    75
    Morphism.declaration_entity -> local_theory -> local_theory
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    76
  val locale_const: string -> Syntax.mode -> (binding * mixfix) * term ->
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    77
    local_theory -> local_theory
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
    78
  val locale_dependency: string -> Locale.registration ->
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
    79
    local_theory -> local_theory
45353
wenzelm
parents: 45352
diff changeset
    80
end
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    81
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    82
structure Generic_Target: GENERIC_TARGET =
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    83
struct
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
    84
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
    85
(** consts **)
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
    86
60345
592806806494 completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
haftmann
parents: 60344
diff changeset
    87
fun export_abbrev lthy preprocess rhs =
60342
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    88
  let
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    89
    val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    90
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    91
    val rhs' = rhs
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    92
      |> Assumption.export_term lthy (Local_Theory.target_of lthy)
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    93
      |> preprocess;
63339
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
    94
    val term_params =
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
    95
      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: 60341
diff changeset
    96
    val u = fold_rev lambda term_params rhs';
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    97
    val global_rhs = singleton (Variable.polymorphic thy_ctxt) u;
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
    98
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74241
diff changeset
    99
    val type_tfrees = TFrees.build (TFrees.add_tfreesT (Term.fastype_of u));
60342
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
   100
    val extra_tfrees =
74278
a123db647573 clarified signature;
wenzelm
parents: 74266
diff changeset
   101
      TFrees.build (TFrees.add_tfrees_unless (TFrees.defined type_tfrees) u)
74284
8d1e27a23dd1 clarified order of extra TFrees: underlying fast_string_ord coincides with Name.invent (e.g. from type inference);
wenzelm
parents: 74282
diff changeset
   102
      |> TFrees.keys;
60342
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
   103
    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: 60344
diff changeset
   104
  in (global_rhs, (extra_tfrees, (type_params, term_params))) end;
60342
df9b153d866b separate function to compute exported abbreviation
haftmann
parents: 60341
diff changeset
   105
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   106
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: 62764
diff changeset
   107
  if null extra_tfrees then mx
d6b0d35b3aed relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
wenzelm
parents: 62764
diff changeset
   108
  else
d6b0d35b3aed relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
wenzelm
parents: 62764
diff changeset
   109
   (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: 62764
diff changeset
   110
      warning
d6b0d35b3aed relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
wenzelm
parents: 62764
diff changeset
   111
        ("Additional type variable(s) in specification of " ^ Binding.print b ^ ": " ^
74284
8d1e27a23dd1 clarified order of extra TFrees: underlying fast_string_ord coincides with Name.invent (e.g. from type inference);
wenzelm
parents: 74282
diff changeset
   112
          commas (map (Syntax.string_of_typ ctxt o TFree) extra_tfrees) ^
62767
d6b0d35b3aed relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
wenzelm
parents: 62764
diff changeset
   113
          (if Mixfix.is_empty mx then ""
d6b0d35b3aed relevant check_mixfix happens further at the bottom, to avoid duplicate reports via Specification.prepare;
wenzelm
parents: 62764
diff changeset
   114
           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: 62764
diff changeset
   115
    else (); NoSyn);
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   116
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   117
fun check_mixfix_global (b, no_params) mx =
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 61701
diff changeset
   118
  if no_params orelse Mixfix.is_empty mx then mx
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 61701
diff changeset
   119
  else
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 61701
diff changeset
   120
    (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: 62764
diff changeset
   121
      Pretty.string_of (Mixfix.pretty_mixfix mx)); NoSyn);
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   122
61701
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   123
fun same_const (Const (c, _), Const (c', _)) = c = c'
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   124
  | same_const (t $ _, t' $ _) = same_const (t, t')
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   125
  | same_const (_, _) = false;
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   126
78072
001739cb8d08 clarified signature: more explicit types;
wenzelm
parents: 78044
diff changeset
   127
fun const_decl phi_pred prmode ((b, mx), rhs) = Morphism.entity (fn phi => fn context =>
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   128
  if phi_pred phi then
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   129
    let
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   130
      val b' = Morphism.binding phi b;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   131
      val rhs' = Morphism.term phi rhs;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   132
      val same_shape = Term.aconv_untyped (rhs, rhs');
61701
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   133
      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: 57189
diff changeset
   134
      val const_alias =
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   135
        if same_shape then
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   136
          (case rhs' of
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   137
            Const (c, T) =>
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   138
              let
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   139
                val thy = Context.theory_of context;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   140
                val ctxt = Context.proof_of context;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   141
              in
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   142
                (case Type_Infer_Context.const_type ctxt c of
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   143
                  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: 57189
diff changeset
   144
                | NONE => NONE)
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   145
              end
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   146
          | _ => NONE)
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   147
        else NONE;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   148
    in
60283
c927fa99d045 tuned whitespace;
wenzelm
parents: 59621
diff changeset
   149
      (case const_alias of
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   150
        SOME c =>
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   151
          context
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   152
          |> Context.mapping (Sign.const_alias b' c) (Proof_Context.const_alias b' c)
78072
001739cb8d08 clarified signature: more explicit types;
wenzelm
parents: 78044
diff changeset
   153
          |> Morphism.form_entity (Proof_Context.generic_notation true prmode [(rhs', mx)])
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   154
      | NONE =>
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   155
          context
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   156
          |> Proof_Context.generic_add_abbrev Print_Mode.internal
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   157
            (b', Term.close_schematic_term rhs')
61701
e89cfc004f18 Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents: 61261
diff changeset
   158
          |-> (fn (const as Const (c, _), _) => same_stem ?
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   159
                (Proof_Context.generic_revert_abbrev (#1 prmode) c #>
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   160
                 same_shape ?
78072
001739cb8d08 clarified signature: more explicit types;
wenzelm
parents: 78044
diff changeset
   161
                  Morphism.form_entity (Proof_Context.generic_notation true prmode [(const, mx)]))))
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   162
    end
78072
001739cb8d08 clarified signature: more explicit types;
wenzelm
parents: 78044
diff changeset
   163
  else context);
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   164
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   165
60283
c927fa99d045 tuned whitespace;
wenzelm
parents: 59621
diff changeset
   166
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   167
(** background primitives **)
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   168
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   169
structure Foundation_Interpretations = Theory_Data
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   170
(
78044
2c3f4d80abfb more standard merge order, following logical structure of imports rather than physical serials;
wenzelm
parents: 74561
diff changeset
   171
  type T = ((binding * (term * term list) -> Context.generic -> Context.generic) * stamp) list
2c3f4d80abfb more standard merge order, following logical structure of imports rather than physical serials;
wenzelm
parents: 74561
diff changeset
   172
  val empty = [];
2c3f4d80abfb more standard merge order, following logical structure of imports rather than physical serials;
wenzelm
parents: 74561
diff changeset
   173
  val merge = Library.merge (eq_snd (op =));
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   174
);
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   175
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   176
fun add_foundation_interpretation f =
78044
2c3f4d80abfb more standard merge order, following logical structure of imports rather than physical serials;
wenzelm
parents: 74561
diff changeset
   177
  Foundation_Interpretations.map (cons (f, stamp ()));
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   178
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   179
fun foundation_interpretation binding_const_params lthy =
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   180
  let
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   181
    val interps = Foundation_Interpretations.get (Proof_Context.theory_of lthy);
78044
2c3f4d80abfb more standard merge order, following logical structure of imports rather than physical serials;
wenzelm
parents: 74561
diff changeset
   182
    val interp = fold (fn (f, _) => f binding_const_params) interps;
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   183
  in
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   184
    lthy
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   185
    |> Local_Theory.background_theory (Context.theory_map interp)
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   186
    |> Local_Theory.map_contexts (K (Context.proof_map interp))
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   187
  end;
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   188
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   189
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: 57189
diff changeset
   190
  let
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   191
    val params = type_params @ term_params;
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   192
    val target_params = type_params
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   193
      @ take_prefix is_Free (Variable.export_terms lthy (Local_Theory.target_of lthy) term_params);
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   194
    val mx' = check_mixfix_global (b, null params) mx;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   195
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   196
    val (const, lthy2) = lthy
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   197
      |> 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: 57189
diff changeset
   198
    val lhs = Term.list_comb (const, params);
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   199
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   200
    val ((_, def), lthy3) = lthy2
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   201
      |> Local_Theory.background_theory_result
61261
ddb2da7cb2e4 more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents: 60924
diff changeset
   202
        (Thm.add_def (Proof_Context.defs_context lthy2) false false
71788
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   203
          (Thm.def_binding_optional b b_def, Logic.mk_equals (lhs, rhs)))
ca3ac5238c41 hooks for foundational terms: protection of foundational terms during simplification
haftmann
parents: 71178
diff changeset
   204
      ||> foundation_interpretation (b, (const, target_params));
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   205
  in ((lhs, def), lthy3) end;
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   206
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   207
fun background_declaration decl lthy =
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   208
  let
71178
c7d4f2ab40b9 proper theory context, e.g. for Thm.transfer;
wenzelm
parents: 70544
diff changeset
   209
    fun theory_decl context =
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   210
      Local_Theory.standard_form lthy
71178
c7d4f2ab40b9 proper theory context, e.g. for Thm.transfer;
wenzelm
parents: 70544
diff changeset
   211
        (Proof_Context.init_global (Context.theory_of context)) decl context;
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   212
  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: 57189
diff changeset
   213
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   214
fun background_abbrev (b, global_rhs) params =
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   215
  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: 58028
diff changeset
   216
  #>> 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: 57189
diff changeset
   217
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   218
60283
c927fa99d045 tuned whitespace;
wenzelm
parents: 59621
diff changeset
   219
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   220
(** nested local theories primitives **)
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   221
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   222
fun standard_facts lthy ctxt =
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   223
  Attrib.transform_facts (Local_Theory.standard_morphism lthy ctxt);
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   224
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   225
fun standard_notes pred kind facts lthy =
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   226
  Local_Theory.map_contexts (fn level => fn ctxt =>
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   227
    if pred (Local_Theory.level lthy, level)
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   228
    then Attrib.local_notes kind (standard_facts lthy ctxt facts) ctxt |> snd
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   229
    else ctxt) lthy;
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   230
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   231
fun standard_declaration pred decl lthy =
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   232
  Local_Theory.map_contexts (fn level => fn ctxt =>
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   233
    if pred (Local_Theory.level lthy, level)
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   234
    then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   235
    else ctxt) lthy;
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   236
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   237
fun standard_const pred prmode ((b, mx), rhs) =
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   238
  standard_declaration pred (const_decl (K true) prmode ((b, mx), rhs));
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   239
73846
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   240
fun standard_registration pred registration lthy =
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   241
  Local_Theory.map_contexts (fn level =>
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   242
    if pred (Local_Theory.level lthy, level)
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   243
    then Context.proof_map (Locale.add_registration registration)
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   244
    else I) lthy;
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   245
74361
690928dd6f8f apply declarations from interpretations in eigen context also
haftmann
parents: 74284
diff changeset
   246
val local_interpretation = standard_registration (fn (n, level) => level >= n - 1);
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
   247
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
   248
60340
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   249
69394731c419 tuned order
haftmann
parents: 60337
diff changeset
   250
(** lifting target primitives to local theory operations **)
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   251
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   252
(* define *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   253
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: 46916
diff changeset
   254
fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   255
  let
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59573
diff changeset
   256
    val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   257
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   258
    (*term and type parameters*)
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   259
    val ((defs, _), rhs') = Thm.cterm_of lthy rhs
47276
wenzelm
parents: 47272
diff changeset
   260
      |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   261
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: 47250
diff changeset
   262
    val xs = Variable.add_fixed lthy rhs' [];
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   263
    val T = Term.fastype_of rhs;
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74241
diff changeset
   264
    val type_tfrees = TFrees.build (TFrees.add_tfreesT T #> fold (TFrees.add_tfreesT o #2) xs);
74230
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   265
    val extra_tfrees =
74278
a123db647573 clarified signature;
wenzelm
parents: 74266
diff changeset
   266
      TFrees.build (rhs |> TFrees.add_tfrees_unless (TFrees.defined type_tfrees))
74284
8d1e27a23dd1 clarified order of extra TFrees: underlying fast_string_ord coincides with Name.invent (e.g. from type inference);
wenzelm
parents: 74282
diff changeset
   267
      |> TFrees.keys;
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   268
    val mx' = check_mixfix lthy (b, extra_tfrees) mx;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   269
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   270
    val type_params = map (Logic.mk_type o TFree) extra_tfrees;
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58028
diff changeset
   271
    val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) xs);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   272
    val params = type_params @ term_params;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   273
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   274
    val U = map Term.fastype_of params ---> T;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   275
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   276
    (*foundation*)
45353
wenzelm
parents: 45352
diff changeset
   277
    val ((lhs', global_def), lthy2) = lthy
wenzelm
parents: 45352
diff changeset
   278
      |> foundation (((b, U), mx'), (b_def, rhs')) (type_params, term_params);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   279
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   280
    (*local definition*)
63344
c9910404cc8a tuned signature;
wenzelm
parents: 63339
diff changeset
   281
    val ([(lhs, (_, local_def))], lthy3) = lthy2
63346
c8366fb67538 clarified PIDE markup;
wenzelm
parents: 63344
diff changeset
   282
      |> Context_Position.set_visible false
63352
4eaf35781b23 tuned signature;
wenzelm
parents: 63346
diff changeset
   283
      |> Local_Defs.define [((b, NoSyn), (Binding.empty_atts, lhs'))]
63346
c8366fb67538 clarified PIDE markup;
wenzelm
parents: 63344
diff changeset
   284
      ||> Context_Position.restore_visible lthy2;
47240
wenzelm
parents: 47238
diff changeset
   285
wenzelm
parents: 47238
diff changeset
   286
    (*result*)
47238
289dcbdd5984 more direct Local_Defs.contract;
wenzelm
parents: 47081
diff changeset
   287
    val def =
47240
wenzelm
parents: 47238
diff changeset
   288
      Thm.transitive local_def global_def
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   289
      |> Local_Defs.contract lthy3 defs (Thm.cterm_of lthy3 (Logic.mk_equals (lhs, rhs)));
38315
fa3f90cf6d9c basic renumbering
haftmann
parents: 38313
diff changeset
   290
    val ([(res_name, [res])], lthy4) = lthy3
47080
wenzelm
parents: 46992
diff changeset
   291
      |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])];
38315
fa3f90cf6d9c basic renumbering
haftmann
parents: 38313
diff changeset
   292
  in ((lhs, (res_name, res)), lthy4) end;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   293
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   294
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   295
(* notes *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   296
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   297
local
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   298
79376
b275e3379024 tuned signature;
wenzelm
parents: 79372
diff changeset
   299
val name_thm1 = Global_Theory.name_thm Global_Theory.official1 o Thm_Name.short;
b275e3379024 tuned signature;
wenzelm
parents: 79372
diff changeset
   300
val name_thm2 = Global_Theory.name_thm Global_Theory.unofficial2 o Thm_Name.short;
79357
bb07298c5fb0 proper Thm_Name.make_list for thm_definition;
wenzelm
parents: 79356
diff changeset
   301
79356
e9828380e7e3 more robust: avoid crash of AFP/Transition_Systems_and_Automata (amending fe4bd39bfeac and 43d8385db923);
wenzelm
parents: 79355
diff changeset
   302
fun thm_def (name, pos) thm lthy =
79357
bb07298c5fb0 proper Thm_Name.make_list for thm_definition;
wenzelm
parents: 79356
diff changeset
   303
  if #1 name <> "" andalso Proofterm.zproof_enabled (Proofterm.get_proofs_level ()) then
bb07298c5fb0 proper Thm_Name.make_list for thm_definition;
wenzelm
parents: 79356
diff changeset
   304
    Local_Theory.background_theory_result (Thm.store_zproof (name, pos) thm) lthy
79356
e9828380e7e3 more robust: avoid crash of AFP/Transition_Systems_and_Automata (amending fe4bd39bfeac and 43d8385db923);
wenzelm
parents: 79355
diff changeset
   305
  else (thm, lthy);
79355
fe4bd39bfeac more robust: zproofs need to be enabled (amending 43d8385db923);
wenzelm
parents: 79354
diff changeset
   306
79359
5b01b93de062 more robust: avoid crash of Thm.solve_constraints due to changed background theory, e.g. relevant for AFP/Transition_Systems_and_Automata;
wenzelm
parents: 79358
diff changeset
   307
fun thm_definition (name_pos, thm) lthy =
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   308
  let
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   309
    val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   310
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   311
    (*export assumes/defines*)
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   312
    val ((defs, asms), thm') = Local_Defs.export lthy thy_ctxt thm;
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   313
    val asms' = map (rewrite_rule lthy (Drule.norm_hhf_eqs @ defs)) asms;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   314
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   315
    (*export fixes*)
74281
7829d6435c60 more scalable operations;
wenzelm
parents: 74278
diff changeset
   316
    val tfrees =
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   317
      TFrees.build (Thm.fold_terms {hyps = true} TFrees.add_tfrees thm')
74284
8d1e27a23dd1 clarified order of extra TFrees: underlying fast_string_ord coincides with Name.invent (e.g. from type inference);
wenzelm
parents: 74282
diff changeset
   318
      |> TFrees.keys |> map TFree;
74281
7829d6435c60 more scalable operations;
wenzelm
parents: 74278
diff changeset
   319
    val frees =
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   320
      Frees.build (Thm.fold_terms {hyps = true} Frees.add_frees thm')
74281
7829d6435c60 more scalable operations;
wenzelm
parents: 74278
diff changeset
   321
      |> Frees.list_set_rev |> map Free;
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   322
    val (schematic_thm :: variables) =
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   323
      (thm' :: map (Drule.mk_term o Thm.cterm_of lthy) (map Logic.mk_type tfrees @ frees))
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   324
      |> Variable.export lthy thy_ctxt
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   325
      |> Drule.zero_var_indexes_list;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   326
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   327
    (*thm definition*)
79357
bb07298c5fb0 proper Thm_Name.make_list for thm_definition;
wenzelm
parents: 79356
diff changeset
   328
    val (global_thm, lthy') = thm_def name_pos (name_thm1 name_pos schematic_thm) lthy;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   329
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   330
    (*import fixes*)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   331
    val (tvars, vars) =
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   332
      chop (length tfrees) (map (Thm.term_of o Drule.dest_term) variables)
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   333
      |>> map Logic.dest_type;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   334
74220
c49134ee16c1 more scalable data structure (but: rarely used many arguments);
wenzelm
parents: 73846
diff changeset
   335
    val instT =
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74241
diff changeset
   336
      TVars.build (fold2 (fn a => fn b =>
612b7e0d6721 clarified signature;
wenzelm
parents: 74241
diff changeset
   337
        (case a of TVar v => TVars.add (v, b) | _ => I)) tvars tfrees);
79354
43d8385db923 more thorough thm definition via Global_Theory.register_proofs: store (and purge) zproofs;
wenzelm
parents: 79353
diff changeset
   338
    val cinstT = TVars.map (K (Thm.ctyp_of lthy')) instT;
74220
c49134ee16c1 more scalable data structure (but: rarely used many arguments);
wenzelm
parents: 73846
diff changeset
   339
    val cinst =
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   340
      Vars.build
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   341
        (fold2 (fn v => fn t =>
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   342
          (case v of
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   343
            Var (xi, T) =>
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   344
              Vars.add ((xi, Term_Subst.instantiateT instT T),
79354
43d8385db923 more thorough thm definition via Global_Theory.register_proofs: store (and purge) zproofs;
wenzelm
parents: 79353
diff changeset
   345
                Thm.cterm_of lthy' (Term.map_types (Term_Subst.instantiateT instT) t))
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74281
diff changeset
   346
          | _ => I)) vars frees);
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   347
    val fixed_thm = Thm.instantiate (cinstT, cinst) global_thm;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   348
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   349
    (*import assumes/defines*)
79353
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   350
    val local_thm =
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   351
      (fold (curry op COMP) asms' fixed_thm
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   352
        handle THM _ => raise THM ("Failed to re-import result", 0, fixed_thm :: asms'))
af7881b2299d tuned names;
wenzelm
parents: 79352
diff changeset
   353
      |> Local_Defs.contract lthy defs (Thm.cprop_of thm)
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   354
      |> Goal.norm_result lthy
79357
bb07298c5fb0 proper Thm_Name.make_list for thm_definition;
wenzelm
parents: 79356
diff changeset
   355
      |> name_thm2 name_pos;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   356
79354
43d8385db923 more thorough thm definition via Global_Theory.register_proofs: store (and purge) zproofs;
wenzelm
parents: 79353
diff changeset
   357
  in ((local_thm, global_thm), lthy') end;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   358
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   359
in
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   360
79359
5b01b93de062 more robust: avoid crash of Thm.solve_constraints due to changed background theory, e.g. relevant for AFP/Transition_Systems_and_Automata;
wenzelm
parents: 79358
diff changeset
   361
fun notes target_notes kind facts0 lthy =
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   362
  let
79359
5b01b93de062 more robust: avoid crash of Thm.solve_constraints due to changed background theory, e.g. relevant for AFP/Transition_Systems_and_Automata;
wenzelm
parents: 79358
diff changeset
   363
    val facts = Attrib.map_thms (Goal.norm_result lthy) facts0;
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   364
    val (facts', lthy') =
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   365
      (facts, lthy) |-> fold_map (fn (a, thms) => fn lthy1 =>
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   366
        let
79372
d02c8adce4e6 clarified modules;
wenzelm
parents: 79371
diff changeset
   367
          val thms1 = Thm_Name.expr (Local_Theory.full_name_pos lthy1 (fst a)) thms;
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   368
          val (thms2, lthy2) =
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   369
            (thms1, lthy1) |-> fold_map (fn (args, atts) =>
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   370
              fold_map thm_definition args #>> rpair atts);
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   371
        in ((a, thms2), lthy2) end);
79347
8aca79b3a9cb clarified modules;
wenzelm
parents: 79345
diff changeset
   372
    val local_facts = Attrib.map_thms #1 facts';
8aca79b3a9cb clarified modules;
wenzelm
parents: 79345
diff changeset
   373
    val global_facts = Attrib.map_thms #2 facts';
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   374
  in
79352
e25c17f574f1 clarified signature: support update of local_theory;
wenzelm
parents: 79351
diff changeset
   375
    lthy'
79354
43d8385db923 more thorough thm definition via Global_Theory.register_proofs: store (and purge) zproofs;
wenzelm
parents: 79353
diff changeset
   376
    |> target_notes kind global_facts (Attrib.partial_evaluation lthy' local_facts)
47249
c0481c3c2a6c added Attrib.global_notes/local_notes/generic_notes convenience;
wenzelm
parents: 47246
diff changeset
   377
    |> Attrib.local_notes kind local_facts
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   378
  end;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   379
47250
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   380
end;
6523a21076a8 clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents: 47249
diff changeset
   381
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   382
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   383
(* abbrev *)
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   384
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   385
fun abbrev target_abbrev prmode ((b, mx), rhs) lthy =
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   386
  let
60345
592806806494 completely separated canonical class abbreviations from abbreviations stemming from non-canonical morphisms -- these have no shared concept
haftmann
parents: 60344
diff changeset
   387
    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: 38311
diff changeset
   388
    val mx' = check_mixfix lthy (b, extra_tfrees) mx;
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   389
  in
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   390
    lthy
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   391
    |> target_abbrev prmode (b, mx') global_rhs (type_params, term_params)
63346
c8366fb67538 clarified PIDE markup;
wenzelm
parents: 63344
diff changeset
   392
    |> Context_Position.set_visible false
57109
84c1e0453bda tuned variable names
haftmann
parents: 57075
diff changeset
   393
    |> Proof_Context.add_abbrev Print_Mode.internal (b, rhs) |> snd
84c1e0453bda tuned variable names
haftmann
parents: 57075
diff changeset
   394
    |> Local_Defs.fixed_abbrev ((b, NoSyn), rhs)
62992
d2e3b3b159d7 clarified PIDE reports;
wenzelm
parents: 62767
diff changeset
   395
    ||> Context_Position.restore_visible lthy
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   396
  end;
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   397
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   398
60283
c927fa99d045 tuned whitespace;
wenzelm
parents: 59621
diff changeset
   399
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   400
(** theory target primitives **)
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   401
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   402
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: 47283
diff changeset
   403
  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: 57191
diff changeset
   404
  #-> (fn (lhs, def) => standard_const (op <>) Syntax.mode_default ((b, mx), lhs)
57057
e54713f22a88 compactified level discriminator
haftmann
parents: 56294
diff changeset
   405
    #> pair (lhs, def));
47284
0e65b6a016dc clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents: 47283
diff changeset
   406
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   407
fun theory_target_notes kind global_facts local_facts =
57191
haftmann
parents: 57190
diff changeset
   408
  Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd)
haftmann
parents: 57190
diff changeset
   409
  #> standard_notes (op <>) kind local_facts;
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38315
diff changeset
   410
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   411
fun theory_target_abbrev prmode (b, mx) global_rhs params =
47286
392c4cd97e5c more uniform theory_abbrev with const_declaration;
wenzelm
parents: 47285
diff changeset
   412
  Local_Theory.background_theory_result
57109
84c1e0453bda tuned variable names
haftmann
parents: 57075
diff changeset
   413
    (Sign.add_abbrev (#1 prmode) (b, global_rhs) #->
47291
6a641856a0e9 better drop background syntax if entity depends on parameters;
wenzelm
parents: 47290
diff changeset
   414
      (fn (lhs, _) =>  (* FIXME type_params!? *)
63339
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
   415
        Sign.notation true prmode
fd9bd5024751 tuned whitespace;
wenzelm
parents: 63269
diff changeset
   416
          [(lhs, check_mixfix_global (b, null (snd params)) mx)] #> pair lhs))
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   417
  #-> (fn lhs =>
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   418
        standard_const (op <>) prmode
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   419
          ((b, if null (snd params) then NoSyn else mx),
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62752
diff changeset
   420
            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: 38315
diff changeset
   421
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   422
74361
690928dd6f8f apply declarations from interpretations in eigen context also
haftmann
parents: 74284
diff changeset
   423
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   424
(** theory operations **)
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   425
60344
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   426
val theory_abbrev = abbrev theory_target_abbrev;
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   427
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   428
fun theory_declaration decl =
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   429
  background_declaration decl #> standard_declaration (K true) decl;
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   430
73846
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   431
fun target_registration lthy {inst, mixin, export} =
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   432
  {inst = inst, mixin = mixin,
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   433
    export = export $> Proof_Context.export_morphism lthy (Local_Theory.target_of lthy)};
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   434
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   435
fun theory_registration registration lthy =
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   436
  lthy
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   437
  |> (Local_Theory.raw_theory o Context.theory_map)
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   438
    (Locale.add_registration (target_registration lthy registration))
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   439
  |> standard_registration (K true) registration;
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
   440
60283
c927fa99d045 tuned whitespace;
wenzelm
parents: 59621
diff changeset
   441
74361
690928dd6f8f apply declarations from interpretations in eigen context also
haftmann
parents: 74284
diff changeset
   442
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   443
(** locale target primitives **)
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   444
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   445
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: 57189
diff changeset
   446
  Local_Theory.background_theory
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   447
    (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: 57189
diff changeset
   448
  (fn lthy => lthy |>
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   449
    Local_Theory.target (fn ctxt => ctxt |>
67654
49f45fcd335b clarified signature;
wenzelm
parents: 67652
diff changeset
   450
      Locale.add_facts locale kind (standard_facts lthy ctxt local_facts))) #>
57191
haftmann
parents: 57190
diff changeset
   451
  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: 57189
diff changeset
   452
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   453
fun locale_target_declaration locale params decl lthy = lthy
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   454
  |> Local_Theory.target (fn ctxt => ctxt |>
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   455
    Locale.add_declaration locale params
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   456
      (Morphism.transform (Local_Theory.standard_morphism lthy ctxt) decl));
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   457
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   458
fun locale_target_const locale phi_pred prmode ((b, mx), rhs) =
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   459
  locale_target_declaration locale {syntax = true, pos = Binding.pos_of b}
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   460
    (const_decl phi_pred prmode ((b, mx), rhs));
60341
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   461
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   462
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   463
(** locale operations **)
fcbd7f0c52c3 clearly separated target primitives (target_foo) from self-contained target operations (foo)
haftmann
parents: 60340
diff changeset
   464
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   465
fun locale_declaration locale {syntax, pervasive, pos} decl =
57193
d59c4383cae4 self-contained locale_declaration operation
haftmann
parents: 57192
diff changeset
   466
  pervasive ? background_declaration decl
78095
bc42c074e58f tuned signature: more position information;
wenzelm
parents: 78085
diff changeset
   467
  #> locale_target_declaration locale {syntax = syntax, pos = pos} decl
57193
d59c4383cae4 self-contained locale_declaration operation
haftmann
parents: 57192
diff changeset
   468
  #> standard_declaration (fn (_, other) => other <> 0) decl;
d59c4383cae4 self-contained locale_declaration operation
haftmann
parents: 57192
diff changeset
   469
57190
05ad9aae4537 recovered structure of module, which got somehow convoluted due to incremental modifications
haftmann
parents: 57189
diff changeset
   470
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: 57191
diff changeset
   471
  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: 57191
diff changeset
   472
  #> 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: 57189
diff changeset
   473
73846
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   474
fun locale_dependency loc registration lthy =
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   475
  lthy
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   476
  |> Local_Theory.raw_theory (Locale.add_dependency loc registration)
9447668d1b77 global interpretation into nested targets
haftmann
parents: 73845
diff changeset
   477
  |> standard_registration (K true) registration;
73845
bfce186331be more succint interfaces
haftmann
parents: 72516
diff changeset
   478
60344
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   479
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   480
(** locale abbreviations **)
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   481
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   482
fun locale_target_abbrev locale prmode (b, mx) global_rhs params =
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   483
  background_abbrev (b, global_rhs) (snd params)
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   484
  #-> (fn (lhs, _) => locale_const locale prmode ((b, mx), lhs));
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   485
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   486
fun locale_abbrev locale = abbrev (locale_target_abbrev locale);
a40369ea3ba5 self-contained formulation of abbrev for named targets
haftmann
parents: 60342
diff changeset
   487
38309
9bd4e568c58c added generic_target.ML
haftmann
parents:
diff changeset
   488
end;