110 ); |
110 ); |
111 |
111 |
112 fun assert lthy = |
112 fun assert lthy = |
113 if null (Data.get lthy) then error "Missing local theory context" else lthy; |
113 if null (Data.get lthy) then error "Missing local theory context" else lthy; |
114 |
114 |
115 val get_last_lthy = List.last o Data.get o assert; |
115 val bottom_of = List.last o Data.get o assert; |
116 val get_first_lthy = hd o Data.get o assert; |
116 val top_of = hd o Data.get o assert; |
117 |
117 |
118 fun map_first_lthy f = |
118 fun map_bottom f = |
119 assert #> |
119 assert #> |
120 Data.map (fn {naming, operations, after_close, brittle, target} :: parents => |
120 Data.map (fn {naming, operations, after_close, brittle, target} :: parents => |
121 make_lthy (f (naming, operations, after_close, brittle, target)) :: parents); |
121 make_lthy (f (naming, operations, after_close, brittle, target)) :: parents); |
122 |
122 |
123 fun restore lthy = #target (get_first_lthy lthy) |> Data.put (Data.get lthy); |
123 fun restore lthy = #target (top_of lthy) |> Data.put (Data.get lthy); |
124 |
124 |
125 |
125 |
126 (* nested structure *) |
126 (* nested structure *) |
127 |
127 |
128 val level = length o Data.get; (*1: main target at bottom, >= 2: nested context*) |
128 val level = length o Data.get; (*1: main target at bottom, >= 2: nested context*) |
161 |
161 |
162 (* brittle context -- implicit for nested structures *) |
162 (* brittle context -- implicit for nested structures *) |
163 |
163 |
164 fun mark_brittle lthy = |
164 fun mark_brittle lthy = |
165 if level lthy = 1 |
165 if level lthy = 1 |
166 then map_first_lthy (fn (naming, operations, after_close, brittle, target) => |
166 then map_bottom (fn (naming, operations, after_close, brittle, target) => |
167 (naming, operations, after_close, true, target)) lthy |
167 (naming, operations, after_close, true, target)) lthy |
168 else lthy; |
168 else lthy; |
169 |
169 |
170 fun assert_nonbrittle lthy = |
170 fun assert_nonbrittle lthy = |
171 if #brittle (get_first_lthy lthy) |
171 if #brittle (top_of lthy) |
172 then error "Brittle local theory context" |
172 then error "Brittle local theory context" |
173 else lthy; |
173 else lthy; |
174 |
174 |
175 |
175 |
176 (* naming *) |
176 (* naming *) |
177 |
177 |
178 val naming_of = #naming o get_first_lthy; |
178 val naming_of = #naming o top_of; |
179 val full_name = Name_Space.full_name o naming_of; |
179 val full_name = Name_Space.full_name o naming_of; |
180 |
180 |
181 fun map_naming f = |
181 fun map_naming f = |
182 map_first_lthy (fn (naming, operations, after_close, brittle, target) => |
182 map_bottom (fn (naming, operations, after_close, brittle, target) => |
183 (f naming, operations, after_close, brittle, target)); |
183 (f naming, operations, after_close, brittle, target)); |
184 |
184 |
185 val conceal = map_naming Name_Space.conceal; |
185 val conceal = map_naming Name_Space.conceal; |
186 val new_group = map_naming Name_Space.new_group; |
186 val new_group = map_naming Name_Space.new_group; |
187 val reset_group = map_naming Name_Space.reset_group; |
187 val reset_group = map_naming Name_Space.reset_group; |
309 |
309 |
310 |
310 |
311 (* activation of locale fragments *) |
311 (* activation of locale fragments *) |
312 |
312 |
313 fun activate_nonbrittle dep_morph mixin export = |
313 fun activate_nonbrittle dep_morph mixin export = |
314 map_first_lthy (fn (naming, operations, after_close, brittle, target) => |
314 map_bottom (fn (naming, operations, after_close, brittle, target) => |
315 (naming, operations, after_close, brittle, |
315 (naming, operations, after_close, brittle, |
316 (Context.proof_map ooo Locale.add_registration) dep_morph mixin export target)); |
316 (Context.proof_map ooo Locale.add_registration) dep_morph mixin export target)); |
317 |
317 |
318 fun activate dep_morph mixin export = |
318 fun activate dep_morph mixin export = |
319 mark_brittle #> activate_nonbrittle dep_morph mixin export; |
319 mark_brittle #> activate_nonbrittle dep_morph mixin export; |