author | wenzelm |
Sun, 30 Oct 2011 22:35:18 +0100 | |
changeset 45311 | ca9e66c523a2 |
parent 45310 | adaf2184b79d |
child 45352 | 0b4038361a3a |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: Pure/Isar/named_target.ML |
20894 | 2 |
Author: Makarius |
30437 | 3 |
Author: Florian Haftmann, TU Muenchen |
20894 | 4 |
|
38350
480b2de9927c
renamed Theory_Target to the more appropriate Named_Target
haftmann
parents:
38349
diff
changeset
|
5 |
Targets for theory, locale and class. |
20894 | 6 |
*) |
7 |
||
38350
480b2de9927c
renamed Theory_Target to the more appropriate Named_Target
haftmann
parents:
38349
diff
changeset
|
8 |
signature NAMED_TARGET = |
20894 | 9 |
sig |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
10 |
val init: (local_theory -> local_theory) -> string -> theory -> local_theory |
38388 | 11 |
val theory_init: theory -> local_theory |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
12 |
val reinit: local_theory -> local_theory -> local_theory |
35205 | 13 |
val context_cmd: xstring -> theory -> local_theory |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
14 |
val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} option |
20894 | 15 |
end; |
16 |
||
38350
480b2de9927c
renamed Theory_Target to the more appropriate Named_Target
haftmann
parents:
38349
diff
changeset
|
17 |
structure Named_Target: NAMED_TARGET = |
20894 | 18 |
struct |
19 |
||
21006 | 20 |
(* context data *) |
21 |
||
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
22 |
datatype target = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
23 |
Target of {target: string, is_locale: bool, is_class: bool, |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
24 |
before_exit: local_theory -> local_theory}; |
25012
448af76a1ba3
pass explicit target record -- more informative peek operation;
wenzelm
parents:
25002
diff
changeset
|
25 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
26 |
fun make_target target is_locale is_class before_exit = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
27 |
Target {target = target, is_locale = is_locale, is_class = is_class, |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
28 |
before_exit = before_exit}; |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
29 |
|
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
30 |
fun named_target _ "" before_exit = make_target "" false false before_exit |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
31 |
| named_target thy locale before_exit = |
38378 | 32 |
if Locale.defined thy locale |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
33 |
then make_target locale true (Class.is_class thy locale) before_exit |
38378 | 34 |
else error ("No such locale: " ^ quote locale); |
25012
448af76a1ba3
pass explicit target record -- more informative peek operation;
wenzelm
parents:
25002
diff
changeset
|
35 |
|
33519 | 36 |
structure Data = Proof_Data |
21006 | 37 |
( |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
38 |
type T = target option; |
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
39 |
fun init _ = NONE; |
21006 | 40 |
); |
41 |
||
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
42 |
val peek = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
43 |
Data.get #> Option.map (fn Target {target, is_locale, is_class, ...} => |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
44 |
{target = target, is_locale = is_locale, is_class = is_class}); |
21006 | 45 |
|
46 |
||
33456
fbd47f9b9b12
allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents:
33282
diff
changeset
|
47 |
(* generic declarations *) |
fbd47f9b9b12
allow "pervasive" local theory declarations, which are applied the background theory;
wenzelm
parents:
33282
diff
changeset
|
48 |
|
45311
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
49 |
fun locale_declaration locale syntax decl lthy = |
24838 | 50 |
let |
38305 | 51 |
val add = if syntax then Locale.add_syntax_declaration else Locale.add_declaration; |
52 |
val locale_decl = Morphism.transform (Local_Theory.target_morphism lthy) decl; |
|
24838 | 53 |
in |
38305 | 54 |
lthy |
55 |
|> Local_Theory.target (add locale locale_decl) |
|
24838 | 56 |
end; |
57 |
||
45311
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
58 |
fun target_declaration (Target {target, ...}) {syntax, pervasive} decl = |
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
59 |
if target = "" then Generic_Target.theory_declaration decl |
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
60 |
else |
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
61 |
locale_declaration target syntax decl |
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
62 |
#> pervasive ? Generic_Target.theory_declaration decl |
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
63 |
#> not pervasive ? Context.proof_map (Morphism.form decl); |
24838 | 64 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
65 |
|
38297 | 66 |
(* consts in locales *) |
67 |
||
68 |
fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) ((b, mx), rhs) phi = |
|
69 |
let |
|
70 |
val b' = Morphism.binding phi b; |
|
71 |
val rhs' = Morphism.term phi rhs; |
|
72 |
val arg = (b', Term.close_schematic_term rhs'); |
|
73 |
val same_shape = Term.aconv_untyped (rhs, rhs'); |
|
74 |
(* FIXME workaround based on educated guess *) |
|
75 |
val prefix' = Binding.prefix_of b'; |
|
76 |
val is_canonical_class = is_class andalso |
|
77 |
(Binding.eq_name (b, b') |
|
78 |
andalso not (null prefix') |
|
38379
67d71449e85b
more convenient split of class modules: class and class_declaration
haftmann
parents:
38378
diff
changeset
|
79 |
andalso List.last prefix' = (Class.class_prefix target, false) |
38297 | 80 |
orelse same_shape); |
81 |
in |
|
82 |
not is_canonical_class ? |
|
83 |
(Context.mapping_result |
|
84 |
(Sign.add_abbrev Print_Mode.internal arg) |
|
42360 | 85 |
(Proof_Context.add_abbrev Print_Mode.internal arg) |
38297 | 86 |
#-> (fn (lhs' as Const (d, _), _) => |
87 |
same_shape ? |
|
38310 | 88 |
(Context.mapping |
42360 | 89 |
(Sign.revert_abbrev mode d) (Proof_Context.revert_abbrev mode d) #> |
90 |
Morphism.form (Proof_Context.target_notation true prmode [(lhs', mx)])))) |
|
38297 | 91 |
end; |
92 |
||
38305 | 93 |
fun locale_const_declaration (ta as Target {target, ...}) prmode arg = |
45311
ca9e66c523a2
even more uniform Local_Theory.declaration for locales (cf. 57def0b39696, aa35859c8741);
wenzelm
parents:
45310
diff
changeset
|
94 |
locale_declaration target true (locale_const ta prmode arg); |
38305 | 95 |
|
38297 | 96 |
|
38318
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
97 |
(* define *) |
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
98 |
|
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
#-> (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
|
102 |
#> pair (lhs, def)) |
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 class_foundation (ta as Target {target, ...}) |
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
105 |
(((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
|
106 |
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
|
107 |
#-> (fn (lhs, def) => locale_const_declaration ta Syntax.mode_default ((b, NoSyn), lhs) |
38619
25e401d53900
tuned: less formal noise in Named_Target, more coherence in Class
haftmann
parents:
38392
diff
changeset
|
108 |
#> Class.const target ((b, mx), (type_params, lhs)) |
38318
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
109 |
#> pair (lhs, def)) |
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
110 |
|
39639 | 111 |
fun target_foundation (ta as Target {is_locale, is_class, ...}) = |
38349 | 112 |
if is_class then class_foundation ta |
113 |
else if is_locale then locale_foundation ta |
|
114 |
else Generic_Target.theory_foundation; |
|
38303
ad4b59e9d0f9
factored out foundation of `define` into separate function
haftmann
parents:
38302
diff
changeset
|
115 |
|
24939 | 116 |
|
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
117 |
(* notes *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
118 |
|
40782 | 119 |
fun locale_notes locale kind global_facts local_facts lthy = |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
120 |
let |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
121 |
val global_facts' = Attrib.map_facts (K I) global_facts; |
38310 | 122 |
val local_facts' = Element.facts_map |
45290 | 123 |
(Element.transform_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
|
124 |
in |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
125 |
lthy |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
38757
diff
changeset
|
126 |
|> Local_Theory.background_theory (Global_Theory.note_thmss kind global_facts' #> snd) |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
127 |
|> 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
|
128 |
end |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
129 |
|
39639 | 130 |
fun target_notes (Target {target, is_locale, ...}) = |
38319
1cfc2b128e33
separate initialisation for overloading and instantiation target
haftmann
parents:
38318
diff
changeset
|
131 |
if is_locale then locale_notes target |
40782 | 132 |
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
|
133 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
134 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
135 |
(* abbrev *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
136 |
|
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
137 |
fun locale_abbrev ta prmode ((b, mx), t) xs = |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
138 |
Local_Theory.background_theory_result |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
139 |
(Sign.add_abbrev Print_Mode.internal (b, t)) #-> |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
140 |
(fn (lhs, _) => locale_const_declaration ta prmode |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
141 |
((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
|
142 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
143 |
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
|
144 |
prmode (b, mx) (global_rhs, t') xs lthy = |
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
145 |
if is_locale then |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
146 |
lthy |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
147 |
|> locale_abbrev ta prmode ((b, if is_class then NoSyn else mx), global_rhs) xs |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
148 |
|> is_class ? Class.abbrev target prmode ((b, mx), t') |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
149 |
else |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
150 |
lthy |
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
151 |
|> 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
|
152 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
153 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
154 |
(* pretty *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
155 |
|
39639 | 156 |
fun pretty (Target {target, is_locale, is_class, ...}) ctxt = |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
157 |
let |
42360 | 158 |
val thy = Proof_Context.theory_of ctxt; |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
159 |
val target_name = |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
160 |
[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
|
161 |
Pretty.str (" " ^ Locale.extern thy target)]; |
38310 | 162 |
val fixes = map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) |
42360 | 163 |
(#1 (Proof_Context.inferred_fixes ctxt)); |
38310 | 164 |
val assumes = map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])])) |
165 |
(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
|
166 |
val elems = |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
167 |
(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
|
168 |
(if null assumes then [] else [Element.Assumes assumes]); |
40782 | 169 |
val body_elems = |
170 |
if not is_locale then [] |
|
39639 | 171 |
else if null elems then [Pretty.block target_name] |
172 |
else [Pretty.block (Pretty.fbreaks (Pretty.block (target_name @ [Pretty.str " ="]) :: |
|
40782 | 173 |
map (Pretty.chunks o Element.pretty_ctxt ctxt) elems))]; |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
174 |
in |
39639 | 175 |
Pretty.block [Pretty.command "theory", Pretty.brk 1, |
42360 | 176 |
Pretty.str (Context.theory_name (Proof_Context.theory_of ctxt))] :: body_elems |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
177 |
end; |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
178 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
179 |
|
38378 | 180 |
(* init *) |
25291 | 181 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
182 |
fun init_context (Target {target, is_locale, is_class, ...}) = |
42360 | 183 |
if not is_locale then Proof_Context.init_global |
29576 | 184 |
else if not is_class then Locale.init target |
38379
67d71449e85b
more convenient split of class modules: class and class_declaration
haftmann
parents:
38378
diff
changeset
|
185 |
else Class.init target; |
25269 | 186 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
187 |
fun init before_exit target thy = |
39639 | 188 |
let |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
189 |
val ta = named_target thy target before_exit; |
39639 | 190 |
in |
191 |
thy |
|
192 |
|> init_context ta |
|
193 |
|> Data.put (SOME ta) |
|
194 |
|> Local_Theory.init NONE (Long_Name.base_name target) |
|
195 |
{define = Generic_Target.define (target_foundation ta), |
|
196 |
notes = Generic_Target.notes (target_notes ta), |
|
197 |
abbrev = Generic_Target.abbrev (target_abbrev ta), |
|
45291
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
wenzelm
parents:
45290
diff
changeset
|
198 |
declaration = target_declaration ta, |
39639 | 199 |
pretty = pretty ta, |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
200 |
exit = Local_Theory.target_of o before_exit} |
39639 | 201 |
end; |
38247 | 202 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
203 |
val theory_init = init I ""; |
25269 | 204 |
|
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
205 |
fun reinit lthy = |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
206 |
(case Data.get lthy of |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
207 |
SOME (Target {target, before_exit, ...}) => init before_exit target o Local_Theory.exit_global |
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38619
diff
changeset
|
208 |
| NONE => error "Not in a named target"); |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
209 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
210 |
fun context_cmd "-" thy = init I "" thy |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
211 |
| context_cmd target thy = init I (Locale.intern thy target) thy; |
33282 | 212 |
|
20894 | 213 |
end; |