src/Pure/Isar/theory_target.ML
author haftmann
Wed, 11 Aug 2010 08:59:41 +0200
changeset 38339 fb8fd73827d4
parent 38338 0e0e1fd9cc03
child 38341 72dba5bd5f63
permissions -rw-r--r--
whitespace tuning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/theory_target.ML
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
30437
910a7aeb8dec more precise treatment of qualified bindings;
wenzelm
parents: 30364
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     4
25542
haftmann
parents: 25519
diff changeset
     5
Common theory/locale/class/instantiation/overloading targets.
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     6
*)
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     7
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     8
signature THEORY_TARGET =
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
     9
sig
38339
fb8fd73827d4 whitespace tuning
haftmann
parents: 38338
diff changeset
    10
  val peek: local_theory -> {target: string, is_locale: bool, is_class: bool}
25269
f9090ae5cec9 clarified theory target interface
haftmann
parents: 25240
diff changeset
    11
  val init: string option -> theory -> local_theory
35205
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
    12
  val context_cmd: xstring -> theory -> local_theory
25864
11f531354852 explicit type variables for instantiation
haftmann
parents: 25684
diff changeset
    13
  val instantiation: string list * (string * sort) list * sort -> theory -> local_theory
29971
68331b62c873 fixed signature
haftmann
parents: 29710
diff changeset
    14
  val instantiation_cmd: xstring list * xstring list * xstring -> theory -> local_theory
25864
11f531354852 explicit type variables for instantiation
haftmann
parents: 25684
diff changeset
    15
  val overloading: (string * (string * typ) * bool) list -> theory -> local_theory
26049
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
    16
  val overloading_cmd: (string * string * bool) list -> theory -> local_theory
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    17
end;
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    18
33553
35f2b30593a8 modernized structure Theory_Target;
wenzelm
parents: 33537
diff changeset
    19
structure Theory_Target: THEORY_TARGET =
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    20
struct
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    21
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    22
(* context data *)
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    23
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    24
datatype target = Target of {target: string, is_locale: bool, is_class: bool};
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    25
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    26
fun make_target target is_locale is_class =
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    27
  Target {target = target, is_locale = is_locale, is_class = is_class};
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
    28
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    29
val global_target = make_target "" false false;
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    30
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33466
diff changeset
    31
structure Data = Proof_Data
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    32
(
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    33
  type T = target;
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
    34
  fun init _ = global_target;
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    35
);
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    36
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    37
val peek = (fn Target args => args) o Data.get;
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    38
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    39
33456
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    40
(* generic declarations *)
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    41
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    42
fun theory_declaration decl lthy =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    43
  let
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    44
    val global_decl = Morphism.form
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    45
      (Morphism.transform (Local_Theory.global_morphism lthy) decl);
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    46
  in
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    47
    lthy
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    48
    |> Local_Theory.theory (Context.theory_map global_decl)
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    49
    |> Local_Theory.target (Context.proof_map global_decl)
33456
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    50
  end;
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    51
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    52
fun locale_declaration locale { syntax, pervasive } decl lthy =
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    53
  let
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    54
    val add = if syntax then Locale.add_syntax_declaration else Locale.add_declaration;
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    55
    val locale_decl = Morphism.transform (Local_Theory.target_morphism lthy) decl;
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    56
  in
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    57
    lthy
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    58
    |> pervasive ? theory_declaration decl
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    59
    |> Local_Theory.target (add locale locale_decl)
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    60
  end;
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    61
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    62
fun target_declaration (Target {target, ...}) { syntax, pervasive } =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    63
  if target = "" then theory_declaration
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    64
  else locale_declaration target { syntax = syntax, pervasive = pervasive };
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    65
21611
fc95ff1fe738 notes: proper import/export of proofs (still inactive);
wenzelm
parents: 21594
diff changeset
    66
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    67
(* consts in locales *)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    68
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    69
fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) ((b, mx), rhs) phi =
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    70
  let
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    71
    val b' = Morphism.binding phi b;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    72
    val rhs' = Morphism.term phi rhs;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    73
    val arg = (b', Term.close_schematic_term rhs');
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    74
    val same_shape = Term.aconv_untyped (rhs, rhs');
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    75
    (* FIXME workaround based on educated guess *)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    76
    val prefix' = Binding.prefix_of b';
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    77
    val is_canonical_class = is_class andalso
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    78
      (Binding.eq_name (b, b')
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    79
        andalso not (null prefix')
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    80
        andalso List.last prefix' = (Class_Target.class_prefix target, false)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    81
      orelse same_shape);
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    82
  in
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    83
    not is_canonical_class ?
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    84
      (Context.mapping_result
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    85
        (Sign.add_abbrev Print_Mode.internal arg)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    86
        (ProofContext.add_abbrev Print_Mode.internal arg)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    87
      #-> (fn (lhs' as Const (d, _), _) =>
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    88
          same_shape ?
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
    89
            (Context.mapping
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
    90
              (Sign.revert_abbrev mode d) (ProofContext.revert_abbrev mode d) #>
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    91
             Morphism.form (ProofContext.target_notation true prmode [(lhs', mx)]))))
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    92
  end;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    93
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    94
fun locale_const_declaration (ta as Target {target, ...}) prmode arg =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    95
  locale_declaration target { syntax = true, pervasive = false } (locale_const ta prmode arg);
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    96
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    97
fun class_target (Target {target, ...}) f =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    98
  Local_Theory.raw_theory f #>
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    99
  Local_Theory.target (Class_Target.refresh_syntax target);
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
   100
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
   101
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   102
(* define *)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   103
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   104
fun syntax_error c = error ("Illegal mixfix syntax for overloaded constant " ^ quote c);
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   105
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   106
fun theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   107
  let
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   108
    val (const, lthy2) = lthy |> Local_Theory.theory_result
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   109
      (Sign.declare_const ((b, U), mx));
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   110
    val lhs = list_comb (const, type_params @ term_params);
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   111
    val ((_, def), lthy3) = lthy2 |> Local_Theory.theory_result
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   112
      (Thm.add_def false false (b_def, Logic.mk_equals (lhs, rhs)));
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   113
  in ((lhs, def), lthy3) end;
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   114
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   115
fun locale_foundation ta (((b, U), mx), (b_def, rhs)) (type_params, term_params) =
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   116
  theory_foundation (((b, U), NoSyn), (b_def, rhs)) (type_params, term_params)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   117
  #-> (fn (lhs, def) => locale_const_declaration ta Syntax.mode_default ((b, mx), lhs)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   118
    #> pair (lhs, def))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   119
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   120
fun class_foundation (ta as Target {target, ...})
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   121
    (((b, U), mx), (b_def, rhs)) (type_params, term_params) =
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   122
  theory_foundation (((b, U), NoSyn), (b_def, rhs)) (type_params, term_params)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   123
  #-> (fn (lhs, def) => locale_const_declaration ta Syntax.mode_default ((b, NoSyn), lhs)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   124
    #> class_target ta (Class_Target.declare target ((b, mx), (type_params, lhs)))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   125
    #> pair (lhs, def))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   126
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   127
fun instantiation_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   128
  case Class_Target.instantiation_param lthy b
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   129
   of SOME c => if mx <> NoSyn then syntax_error c
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   130
        else lthy |> Local_Theory.theory_result (AxClass.declare_overloaded (c, U)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   131
            ##>> AxClass.define_overloaded b_def (c, rhs))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   132
          ||> Class_Target.confirm_declaration b
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   133
    | NONE => lthy |>
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   134
        theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params);
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   135
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   136
fun overloading_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   137
  case Overloading.operation lthy b
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   138
   of SOME (c, checked) => if mx <> NoSyn then syntax_error c
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   139
        else lthy |> Local_Theory.theory_result (Overloading.declare (c, U)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   140
            ##>> Overloading.define checked b_def (c, rhs))
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   141
          ||> Overloading.confirm b
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   142
    | NONE => lthy |>
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   143
        theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params);
37314
f5abedb7aed5 more robust handling of additional type variables: warning, more canonical order, drop mixfix syntax if implicit type arguments are introduced (to avoid delusion due to shifted arguments);
wenzelm
parents: 37205
diff changeset
   144
25105
c9f67836c4d8 internal tuning: class_target, fork_mixfix, declare_const (singleton), abbrev;
wenzelm
parents: 25096
diff changeset
   145
fun fork_mixfix (Target {is_locale, is_class, ...}) mx =
c9f67836c4d8 internal tuning: class_target, fork_mixfix, declare_const (singleton), abbrev;
wenzelm
parents: 25096
diff changeset
   146
  if not is_locale then (NoSyn, NoSyn, mx)
c9f67836c4d8 internal tuning: class_target, fork_mixfix, declare_const (singleton), abbrev;
wenzelm
parents: 25096
diff changeset
   147
  else if not is_class then (NoSyn, mx, NoSyn)
c9f67836c4d8 internal tuning: class_target, fork_mixfix, declare_const (singleton), abbrev;
wenzelm
parents: 25096
diff changeset
   148
  else (mx, NoSyn, NoSyn);
25068
a11d25316c3d tuned fork_mixfix (back from class.ML);
wenzelm
parents: 25064
diff changeset
   149
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   150
fun foundation (ta as Target {target, is_locale, is_class, ...})
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   151
    (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   152
  let
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   153
    val (mx1, mx2, mx3) = fork_mixfix ta mx;
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   154
    val (const, lthy2) = lthy |>
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   155
      (case Class_Target.instantiation_param lthy b of
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   156
        SOME c =>
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   157
          if mx3 <> NoSyn then syntax_error c
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   158
          else Local_Theory.theory_result (AxClass.declare_overloaded (c, U))
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   159
            ##> Class_Target.confirm_declaration b
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   160
      | NONE =>
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   161
          (case Overloading.operation lthy b of
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   162
            SOME (c, _) =>
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   163
              if mx3 <> NoSyn then syntax_error c
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   164
              else Local_Theory.theory_result (Overloading.declare (c, U))
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   165
                ##> Overloading.confirm b
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   166
          | NONE => Local_Theory.theory_result (Sign.declare_const ((b, U), mx3))));
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   167
    val Const (head, _) = const;
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   168
    val lhs = list_comb (const, type_params @ term_params);
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   169
  in
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   170
    lthy2
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   171
    |> pair lhs
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   172
    ||>> Local_Theory.theory_result
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   173
      (case Overloading.operation lthy b of
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   174
        SOME (_, checked) => Overloading.define checked b_def (head, rhs)
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   175
      | NONE =>
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   176
          if is_some (Class_Target.instantiation_param lthy b)
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   177
          then AxClass.define_overloaded b_def (head, rhs)
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   178
          else Thm.add_def false false (b_def, Logic.mk_equals (lhs, rhs)) #>> snd)
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   179
    ||> is_locale ? locale_const_declaration ta Syntax.mode_default ((b, mx2), lhs)
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   180
    ||> is_class ? class_target ta
38314
a1d63457a3c9 avoiding redundant primes
haftmann
parents: 38313
diff changeset
   181
          (Class_Target.declare target ((b, mx1), (type_params, lhs)))
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   182
  end;
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   183
24939
wenzelm
parents: 24935
diff changeset
   184
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   185
(* notes *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   186
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   187
fun theory_notes kind global_facts lthy =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   188
  let
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   189
    val thy = ProofContext.theory_of lthy;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   190
    val global_facts' = Attrib.map_facts (Attrib.attribute_i thy) global_facts;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   191
  in
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   192
    lthy
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   193
    |> Local_Theory.theory (PureThy.note_thmss kind global_facts' #> snd)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   194
    |> Local_Theory.target (ProofContext.note_thmss kind global_facts' #> snd)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   195
  end;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   196
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   197
fun locale_notes locale kind global_facts local_facts lthy = 
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   198
  let
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   199
    val global_facts' = Attrib.map_facts (K I) global_facts;
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   200
    val local_facts' = Element.facts_map
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   201
      (Element.morph_ctxt (Local_Theory.target_morphism lthy)) local_facts;
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   202
  in
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   203
    lthy
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   204
    |> Local_Theory.theory (PureThy.note_thmss kind global_facts' #> snd)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   205
    |> Local_Theory.target (Locale.add_thmss locale kind local_facts')
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   206
  end
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   207
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   208
fun target_notes (ta as Target {target, is_locale, ...}) =
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   209
  if is_locale then locale_notes target
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   210
    else fn kind => fn global_facts => fn _ => theory_notes kind global_facts;
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   211
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   212
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   213
(* abbrev *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   214
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   215
fun theory_abbrev prmode ((b, mx), t) = Local_Theory.theory
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   216
  (Sign.add_abbrev (#1 prmode) (b, t) #->
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   217
    (fn (lhs, _) => Sign.notation true prmode [(lhs, mx)]));
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   218
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   219
fun locale_abbrev ta prmode ((b, mx), t) xs = Local_Theory.theory_result
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   220
  (Sign.add_abbrev Print_Mode.internal (b, t)) #->
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   221
    (fn (lhs, _) => locale_const_declaration ta prmode
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   222
      ((b, mx), Term.list_comb (Logic.unvarify_global lhs, xs)));
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   223
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   224
fun target_abbrev (ta as Target {target, is_locale, is_class, ...})
38312
9dd57db3c0f2 moved extra_tfrees check for mixfix syntax to Generic_Target
haftmann
parents: 38311
diff changeset
   225
    prmode (b, mx) (global_rhs, t') xs lthy =
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   226
  if is_locale
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   227
    then lthy
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   228
      |> locale_abbrev ta prmode ((b, if is_class then NoSyn else mx), global_rhs) xs
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   229
      |> is_class ? class_target ta (Class_Target.abbrev target prmode ((b, mx), t'))
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   230
    else lthy
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   231
      |> theory_abbrev prmode ((b, mx), global_rhs);
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   232
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   233
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   234
(* pretty *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   235
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   236
fun pretty_thy ctxt target is_class =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   237
  let
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   238
    val thy = ProofContext.theory_of ctxt;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   239
    val target_name =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   240
      [Pretty.command (if is_class then "class" else "locale"),
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   241
        Pretty.str (" " ^ Locale.extern thy target)];
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   242
    val fixes = map (fn (x, T) => (Binding.name x, SOME T, NoSyn))
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   243
      (#1 (ProofContext.inferred_fixes ctxt));
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   244
    val assumes = map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])]))
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   245
      (Assumption.all_assms_of ctxt);
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   246
    val elems =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   247
      (if null fixes then [] else [Element.Fixes fixes]) @
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   248
      (if null assumes then [] else [Element.Assumes assumes]);
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   249
  in
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   250
    if target = "" then []
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   251
    else if null elems then [Pretty.block target_name]
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   252
    else [Pretty.block (Pretty.fbreaks (Pretty.block (target_name @ [Pretty.str " ="]) ::
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   253
      map (Pretty.chunks o Element.pretty_ctxt ctxt) elems))]
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   254
  end;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   255
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   256
fun pretty (Target {target, is_class, ...}) ctxt =
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   257
  Pretty.block [Pretty.command "theory", Pretty.brk 1,
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   258
      Pretty.str (Context.theory_name (ProofContext.theory_of ctxt))] ::
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   259
    pretty_thy ctxt target is_class;
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   260
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   261
35205
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   262
(* init various targets *)
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   263
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   264
local
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   265
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   266
fun init_data (Target {target, is_locale, is_class}) =
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   267
  if not is_locale then ProofContext.init_global
29576
669b560fc2b9 wrecked old locale package and related modules
haftmann
parents: 29393
diff changeset
   268
  else if not is_class then Locale.init target
29358
efdfe5dfe008 rearranged target theories
haftmann
parents: 29252
diff changeset
   269
  else Class_Target.init target;
25269
f9090ae5cec9 clarified theory target interface
haftmann
parents: 25240
diff changeset
   270
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   271
fun init_target (ta as Target {target, ...}) thy =
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   272
  thy
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   273
  |> init_data ta
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   274
  |> Data.put ta
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   275
  |> Local_Theory.init NONE (Long_Name.base_name target)
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   276
     {define = Generic_Target.define (foundation ta),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   277
      notes = Generic_Target.notes (target_notes ta),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   278
      abbrev = Generic_Target.abbrev (target_abbrev ta),
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   279
      declaration = fn pervasive => target_declaration ta
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   280
        { syntax = false, pervasive = pervasive },
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   281
      syntax_declaration = fn pervasive => target_declaration ta
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   282
        { syntax = true, pervasive = pervasive },
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   283
      pretty = pretty ta,
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   284
      reinit = init_target ta o ProofContext.theory_of,
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   285
      exit = Local_Theory.target_of};
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   286
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   287
fun named_target _ NONE = global_target
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   288
  | named_target thy (SOME target) =
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   289
      if Locale.defined thy target
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   290
      then make_target target true (Class_Target.is_class thy target)
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   291
      else error ("No such locale: " ^ quote target);
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   292
26049
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   293
fun gen_overloading prep_const raw_ops thy =
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   294
  let
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 36106
diff changeset
   295
    val ctxt = ProofContext.init_global thy;
26049
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   296
    val ops = raw_ops |> map (fn (name, const, checked) =>
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   297
      (name, Term.dest_Const (prep_const ctxt const), checked));
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   298
  in
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   299
    thy
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   300
    |> Overloading.init ops
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   301
    |> Local_Theory.init NONE ""
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   302
       {define = Generic_Target.define overloading_foundation,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   303
        notes = Generic_Target.notes
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   304
          (fn kind => fn global_facts => fn _ => theory_notes kind global_facts),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   305
        abbrev = Generic_Target.abbrev
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   306
          (fn prmode => fn (b, mx) => fn (t, _) => fn _ =>
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   307
            theory_abbrev prmode ((b, mx), t)),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   308
        declaration = fn pervasive => theory_declaration,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   309
        syntax_declaration = fn pervasive => theory_declaration,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   310
        pretty = single o Overloading.pretty,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   311
        reinit = gen_overloading prep_const raw_ops o ProofContext.theory_of,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   312
        exit = Local_Theory.target_of o Overloading.conclude}
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   313
  end;
26049
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   314
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   315
in
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   316
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   317
fun init target thy = init_target (named_target thy target) thy;
25269
f9090ae5cec9 clarified theory target interface
haftmann
parents: 25240
diff changeset
   318
35205
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   319
fun context_cmd "-" thy = init NONE thy
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   320
  | context_cmd target thy = init (SOME (Locale.intern thy target)) thy;
33282
c6364889fea5 misc tuning;
wenzelm
parents: 33173
diff changeset
   321
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   322
fun instantiation arities thy =
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   323
  thy
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   324
  |> Class_Target.init_instantiation arities
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   325
  |> Local_Theory.init NONE ""
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   326
     {define = Generic_Target.define instantiation_foundation,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   327
      notes = Generic_Target.notes
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   328
        (fn kind => fn global_facts => fn _ => theory_notes kind global_facts),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   329
      abbrev = Generic_Target.abbrev
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   330
        (fn prmode => fn (b, mx) => fn (t, _) => fn _ => theory_abbrev prmode ((b, mx), t)),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   331
      declaration = fn pervasive => theory_declaration,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   332
      syntax_declaration = fn pervasive => theory_declaration,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   333
      pretty = single o Class_Target.pretty_instantiation,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   334
      reinit = instantiation arities o ProofContext.theory_of,
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   335
      exit = Local_Theory.target_of o Class_Target.conclude_instantiation};
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   336
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   337
fun instantiation_cmd arities thy =
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   338
  instantiation (Class_Target.read_multi_arity thy arities) thy;
25519
8570745cb40b overloading target
haftmann
parents: 25514
diff changeset
   339
26049
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   340
val overloading = gen_overloading (fn ctxt => Syntax.check_term ctxt o Const);
8186c03194ed overloading: reduced code redundancy, no xstrings here;
wenzelm
parents: 25984
diff changeset
   341
val overloading_cmd = gen_overloading Syntax.read_term;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25395
diff changeset
   342
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   343
end;
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   344
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   345
end;