src/Pure/Isar/theory_target.ML
author haftmann
Wed, 11 Aug 2010 14:41:16 +0200
changeset 38349 ed50e21e715a
parent 38348 cf7b2121ad9d
permissions -rw-r--r--
discontinue old implementation of `foundation`
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
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    13
end;
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    14
33553
35f2b30593a8 modernized structure Theory_Target;
wenzelm
parents: 33537
diff changeset
    15
structure Theory_Target: THEORY_TARGET =
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    16
struct
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
    17
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    18
(* context data *)
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    19
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    20
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
    21
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    22
fun make_target target is_locale is_class =
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    23
  Target {target = target, is_locale = is_locale, is_class = is_class};
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
    24
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
    25
val global_target = make_target "" false false;
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    26
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33466
diff changeset
    27
structure Data = Proof_Data
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    28
(
25012
448af76a1ba3 pass explicit target record -- more informative peek operation;
wenzelm
parents: 25002
diff changeset
    29
  type T = target;
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
    30
  fun init _ = global_target;
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    31
);
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
val peek = (fn Target args => args) o Data.get;
21006
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    34
ac2732072403 added peek;
wenzelm
parents: 20984
diff changeset
    35
33456
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    36
(* generic declarations *)
fbd47f9b9b12 allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents: 33282
diff changeset
    37
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    38
fun locale_declaration locale { syntax, pervasive } decl lthy =
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    39
  let
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    40
    val add = if syntax then Locale.add_syntax_declaration else Locale.add_declaration;
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    41
    val locale_decl = Morphism.transform (Local_Theory.target_morphism lthy) decl;
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    42
  in
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    43
    lthy
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
    44
    |> pervasive ? Generic_Target.theory_declaration decl
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    45
    |> Local_Theory.target (add locale locale_decl)
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    46
  end;
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    47
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    48
fun target_declaration (Target {target, ...}) { syntax, pervasive } =
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
    49
  if target = "" then Generic_Target.theory_declaration
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    50
  else locale_declaration target { syntax = syntax, pervasive = pervasive };
24838
1d1bddf87353 put declarations first
haftmann
parents: 24818
diff changeset
    51
21611
fc95ff1fe738 notes: proper import/export of proofs (still inactive);
wenzelm
parents: 21594
diff changeset
    52
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    53
(* consts in locales *)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    54
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    55
fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) ((b, mx), rhs) phi =
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    56
  let
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    57
    val b' = Morphism.binding phi b;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    58
    val rhs' = Morphism.term phi rhs;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    59
    val arg = (b', Term.close_schematic_term rhs');
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    60
    val same_shape = Term.aconv_untyped (rhs, rhs');
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    61
    (* FIXME workaround based on educated guess *)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    62
    val prefix' = Binding.prefix_of b';
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    63
    val is_canonical_class = is_class andalso
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    64
      (Binding.eq_name (b, b')
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    65
        andalso not (null prefix')
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    66
        andalso List.last prefix' = (Class_Target.class_prefix target, false)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    67
      orelse same_shape);
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    68
  in
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    69
    not is_canonical_class ?
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    70
      (Context.mapping_result
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    71
        (Sign.add_abbrev Print_Mode.internal arg)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    72
        (ProofContext.add_abbrev Print_Mode.internal arg)
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    73
      #-> (fn (lhs' as Const (d, _), _) =>
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    74
          same_shape ?
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
    75
            (Context.mapping
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
    76
              (Sign.revert_abbrev mode d) (ProofContext.revert_abbrev mode d) #>
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    77
             Morphism.form (ProofContext.target_notation true prmode [(lhs', mx)]))))
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    78
  end;
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    79
38305
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    80
fun locale_const_declaration (ta as Target {target, ...}) prmode arg =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    81
  locale_declaration target { syntax = true, pervasive = false } (locale_const ta prmode arg);
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    82
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    83
fun class_target (Target {target, ...}) f =
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    84
  Local_Theory.raw_theory f #>
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    85
  Local_Theory.target (Class_Target.refresh_syntax target);
ebc2abe6e160 restructured code for `declaration`
haftmann
parents: 38303
diff changeset
    86
38297
e0ad78503186 more convenient order
haftmann
parents: 38296
diff changeset
    87
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    88
(* define *)
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    89
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    90
fun locale_foundation ta (((b, U), mx), (b_def, rhs)) (type_params, term_params) =
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
    91
  Generic_Target.theory_foundation (((b, U), NoSyn), (b_def, rhs)) (type_params, term_params)
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    92
  #-> (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
    93
    #> pair (lhs, def))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    94
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    95
fun class_foundation (ta as Target {target, ...})
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    96
    (((b, U), mx), (b_def, rhs)) (type_params, term_params) =
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
    97
  Generic_Target.theory_foundation (((b, U), NoSyn), (b_def, rhs)) (type_params, term_params)
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
    98
  #-> (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
    99
    #> 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
   100
    #> pair (lhs, def))
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   101
38349
ed50e21e715a discontinue old implementation of `foundation`
haftmann
parents: 38348
diff changeset
   102
fun target_foundation (ta as Target {target, is_locale, is_class, ...}) =
ed50e21e715a discontinue old implementation of `foundation`
haftmann
parents: 38348
diff changeset
   103
  if is_class then class_foundation ta
ed50e21e715a discontinue old implementation of `foundation`
haftmann
parents: 38348
diff changeset
   104
  else if is_locale then locale_foundation ta
ed50e21e715a discontinue old implementation of `foundation`
haftmann
parents: 38348
diff changeset
   105
  else Generic_Target.theory_foundation;
38303
ad4b59e9d0f9 factored out foundation of `define` into separate function
haftmann
parents: 38302
diff changeset
   106
24939
wenzelm
parents: 24935
diff changeset
   107
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   108
(* notes *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   109
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   110
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
   111
  let
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   112
    val global_facts' = Attrib.map_facts (K I) global_facts;
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   113
    val local_facts' = Element.facts_map
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   114
      (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
   115
  in
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   116
    lthy
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   117
    |> 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
   118
    |> 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
   119
  end
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   120
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   121
fun target_notes (ta as Target {target, is_locale, ...}) =
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   122
  if is_locale then locale_notes target
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
   123
    else fn kind => fn global_facts => fn _ => Generic_Target.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
   124
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   125
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   126
(* abbrev *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   127
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   128
fun locale_abbrev ta prmode ((b, mx), t) xs = Local_Theory.theory_result
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   129
  (Sign.add_abbrev Print_Mode.internal (b, t)) #->
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   130
    (fn (lhs, _) => locale_const_declaration ta prmode
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   131
      ((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
   132
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   133
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
   134
    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
   135
  if is_locale
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   136
    then lthy
38318
1fade69519ab different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents: 38314
diff changeset
   137
      |> 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
   138
      |> 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
   139
    else lthy
38341
72dba5bd5f63 moved theory-level target operation fragements to Generic_Target; adjusted bootstrap order
haftmann
parents: 38339
diff changeset
   140
      |> Generic_Target.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
   141
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   142
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   143
(* pretty *)
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   144
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   145
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
   146
  let
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   147
    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
   148
    val target_name =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   149
      [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
   150
        Pretty.str (" " ^ Locale.extern thy target)];
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   151
    val fixes = map (fn (x, T) => (Binding.name x, SOME T, NoSyn))
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   152
      (#1 (ProofContext.inferred_fixes ctxt));
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   153
    val assumes = map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])]))
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   154
      (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
   155
    val elems =
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   156
      (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
   157
      (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
   158
  in
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   159
    if target = "" then []
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   160
    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
   161
    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
   162
      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
   163
  end;
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   164
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   165
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
   166
  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
   167
      Pretty.str (Context.theory_name (ProofContext.theory_of ctxt))] ::
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   168
    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
   169
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   170
35205
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   171
(* init various targets *)
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   172
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   173
local
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   174
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   175
fun init_data (Target {target, is_locale, is_class}) =
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   176
  if not is_locale then ProofContext.init_global
29576
669b560fc2b9 wrecked old locale package and related modules
haftmann
parents: 29393
diff changeset
   177
  else if not is_class then Locale.init target
29358
efdfe5dfe008 rearranged target theories
haftmann
parents: 29252
diff changeset
   178
  else Class_Target.init target;
25269
f9090ae5cec9 clarified theory target interface
haftmann
parents: 25240
diff changeset
   179
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   180
fun init_target (ta as Target {target, ...}) thy =
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   181
  thy
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   182
  |> init_data ta
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   183
  |> Data.put ta
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   184
  |> Local_Theory.init NONE (Long_Name.base_name target)
38349
ed50e21e715a discontinue old implementation of `foundation`
haftmann
parents: 38348
diff changeset
   185
     {define = Generic_Target.define (target_foundation ta),
38319
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   186
      notes = Generic_Target.notes (target_notes ta),
1cfc2b128e33 separate initialisation for overloading and instantiation target
haftmann
parents: 38318
diff changeset
   187
      abbrev = Generic_Target.abbrev (target_abbrev ta),
38310
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   188
      declaration = fn pervasive => target_declaration ta
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   189
        { syntax = false, pervasive = pervasive },
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   190
      syntax_declaration = fn pervasive => target_declaration ta
9d4c0c74ae7d whitespace tuning
haftmann
parents: 38308
diff changeset
   191
        { syntax = true, pervasive = pervasive },
38308
0e4649095739 try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents: 38307
diff changeset
   192
      pretty = pretty ta,
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   193
      reinit = init_target ta o ProofContext.theory_of,
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   194
      exit = Local_Theory.target_of};
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   195
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   196
fun named_target _ NONE = global_target
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   197
  | named_target thy (SOME target) =
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   198
      if Locale.defined thy target
38338
0e0e1fd9cc03 remove overloading and instantiation from data slot
haftmann
parents: 38319
diff changeset
   199
      then make_target target true (Class_Target.is_class thy target)
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   200
      else error ("No such locale: " ^ quote target);
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   201
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   202
in
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   203
38247
12d3a5f04a72 unravelled target initialization code
haftmann
parents: 37314
diff changeset
   204
fun init target thy = init_target (named_target thy target) thy;
25269
f9090ae5cec9 clarified theory target interface
haftmann
parents: 25240
diff changeset
   205
35205
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   206
fun context_cmd "-" thy = init NONE thy
611b90bb89bc removed unused Theory_Target.begin;
wenzelm
parents: 35127
diff changeset
   207
  | context_cmd target thy = init (SOME (Locale.intern thy target)) thy;
33282
c6364889fea5 misc tuning;
wenzelm
parents: 33173
diff changeset
   208
20894
784eefc906aa Common theory targets.
wenzelm
parents:
diff changeset
   209
end;
25291
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   210
870455627720 misc cleanup of init functions;
wenzelm
parents: 25269
diff changeset
   211
end;