author | haftmann |
Fri, 05 Dec 2008 08:04:53 +0100 | |
changeset 28991 | 694227dd3e8c |
parent 28965 | 1de908189869 |
child 28994 | 49f602ae24e5 |
permissions | -rw-r--r-- |
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
1 |
(* Title: Pure/Isar/new_locale.ML |
28795 | 2 |
Author: Clemens Ballarin, TU Muenchen |
3 |
||
4 |
New locale development --- experimental. |
|
5 |
*) |
|
6 |
||
7 |
signature NEW_LOCALE = |
|
8 |
sig |
|
9 |
type locale |
|
10 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
11 |
val clear_idents: Proof.context -> Proof.context |
28795 | 12 |
val test_locale: theory -> string -> bool |
28991 | 13 |
val register_locale: bstring -> |
28965 | 14 |
(string * sort) list * (Binding.T * typ option * mixfix) list -> |
28795 | 15 |
term option * term list -> |
16 |
(declaration * stamp) list * (declaration * stamp) list -> |
|
17 |
((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list -> |
|
18 |
((string * Morphism.morphism) * stamp) list -> theory -> theory |
|
19 |
||
20 |
(* Locale name space *) |
|
21 |
val intern: theory -> xstring -> string |
|
22 |
val extern: theory -> string -> xstring |
|
23 |
||
24 |
(* Specification *) |
|
28965 | 25 |
val params_of: theory -> string -> (Binding.T * typ option * mixfix) list |
28872 | 26 |
val specification_of: theory -> string -> term option * term list |
27 |
val declarations_of: theory -> string -> declaration list * declaration list |
|
28795 | 28 |
|
28818 | 29 |
(* Storing results *) |
28833 | 30 |
val add_thmss: string -> string -> (Attrib.binding * (thm list * Attrib.src list) list) list -> |
28818 | 31 |
Proof.context -> Proof.context |
32 |
val add_type_syntax: string -> declaration -> Proof.context -> Proof.context |
|
33 |
val add_term_syntax: string -> declaration -> Proof.context -> Proof.context |
|
34 |
val add_declaration: string -> declaration -> Proof.context -> Proof.context |
|
28894
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
35 |
val add_dependency: string -> (string * Morphism.morphism) -> Proof.context -> Proof.context |
28818 | 36 |
|
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
37 |
(* Activation *) |
28878 | 38 |
val activate_declarations: theory -> string * Morphism.morphism -> |
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
39 |
Proof.context -> Proof.context |
28878 | 40 |
val activate_facts: theory -> string * Morphism.morphism -> |
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
41 |
Proof.context -> Proof.context |
28878 | 42 |
(* val activate: string -> theory -> (Element.context_i -> 'a -> 'a) -> 'a -> 'a *) |
28795 | 43 |
val init: string -> theory -> Proof.context |
44 |
||
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
45 |
(* Reasoning about locales *) |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
46 |
val witness_attrib: attribute |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
47 |
val intro_attrib: attribute |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
48 |
val unfold_attrib: attribute |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
49 |
val intro_locales_tac: bool -> Proof.context -> thm list -> tactic |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
50 |
|
28795 | 51 |
(* Diagnostic *) |
52 |
val print_locales: theory -> unit |
|
53 |
val print_locale: theory -> bool -> bstring -> unit |
|
54 |
end; |
|
55 |
||
56 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
57 |
(*** Theorem list extensible via attribute --- to control intro_locales_tac ***) |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
58 |
|
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
59 |
(* FIXME: consider moving named_thms.ML up in the build hierarchy and using that *) |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
60 |
functor ThmsFun() = |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
61 |
struct |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
62 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
63 |
structure Data = GenericDataFun |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
64 |
( |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
65 |
type T = thm list; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
66 |
val empty = []; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
67 |
val extend = I; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
68 |
fun merge _ = Thm.merge_thms; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
69 |
); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
70 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
71 |
val get = Data.get o Context.Proof; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
72 |
val add = Thm.declaration_attribute (Data.map o Thm.add_thm); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
73 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
74 |
end; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
75 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
76 |
|
28795 | 77 |
structure NewLocale: NEW_LOCALE = |
78 |
struct |
|
79 |
||
80 |
datatype ctxt = datatype Element.ctxt; |
|
81 |
||
82 |
||
83 |
(*** Basics ***) |
|
84 |
||
85 |
datatype locale = Loc of { |
|
86 |
(* extensible lists are in reverse order: decls, notes, dependencies *) |
|
28965 | 87 |
parameters: (string * sort) list * (Binding.T * typ option * mixfix) list, |
28795 | 88 |
(* type and term parameters *) |
89 |
spec: term option * term list, |
|
90 |
(* assumptions (as a single predicate expression) and defines *) |
|
91 |
decls: (declaration * stamp) list * (declaration * stamp) list, |
|
92 |
(* type and term syntax declarations *) |
|
93 |
notes: ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list, |
|
94 |
(* theorem declarations *) |
|
95 |
dependencies: ((string * Morphism.morphism) * stamp) list |
|
96 |
(* locale dependencies (sublocale relation) *) |
|
97 |
} |
|
98 |
||
99 |
||
100 |
(*** Theory data ***) |
|
101 |
||
102 |
structure LocalesData = TheoryDataFun |
|
103 |
( |
|
104 |
type T = NameSpace.T * locale Symtab.table; |
|
105 |
(* locale namespace and locales of the theory *) |
|
106 |
||
28991 | 107 |
val empty = NameSpace.empty_table; |
28795 | 108 |
val copy = I; |
109 |
val extend = I; |
|
110 |
||
111 |
fun join_locales _ |
|
112 |
(Loc {parameters, spec, decls = (decls1, decls2), notes, dependencies}, |
|
113 |
Loc {decls = (decls1', decls2'), notes = notes', |
|
114 |
dependencies = dependencies', ...}) = |
|
115 |
let fun s_merge x = merge (eq_snd (op =)) x in |
|
116 |
Loc {parameters = parameters, |
|
117 |
spec = spec, |
|
118 |
decls = (s_merge (decls1, decls1'), s_merge (decls2, decls2')), |
|
119 |
notes = s_merge (notes, notes'), |
|
120 |
dependencies = s_merge (dependencies, dependencies') |
|
121 |
} |
|
122 |
end; |
|
28991 | 123 |
fun merge _ = NameSpace.join_tables join_locales; |
28795 | 124 |
); |
125 |
||
126 |
val intern = NameSpace.intern o #1 o LocalesData.get; |
|
127 |
val extern = NameSpace.extern o #1 o LocalesData.get; |
|
128 |
||
129 |
fun get_locale thy name = Symtab.lookup (#2 (LocalesData.get thy)) name; |
|
130 |
||
131 |
fun the_locale thy name = case get_locale thy name |
|
132 |
of SOME loc => loc |
|
133 |
| NONE => error ("Unknown locale " ^ quote name); |
|
134 |
||
135 |
fun test_locale thy name = case get_locale thy name |
|
136 |
of SOME _ => true | NONE => false; |
|
137 |
||
28991 | 138 |
fun register_locale bname parameters spec decls notes dependencies thy = |
139 |
thy |> LocalesData.map (NameSpace.bind (Sign.naming_of thy) (Binding.name bname, |
|
140 |
Loc {parameters = parameters, spec = spec, decls = decls, notes = notes, |
|
141 |
dependencies = dependencies}) #> snd); |
|
28795 | 142 |
|
143 |
fun change_locale name f thy = |
|
144 |
let |
|
145 |
val Loc {parameters, spec, decls, notes, dependencies} = |
|
146 |
the_locale thy name; |
|
147 |
val (parameters', spec', decls', notes', dependencies') = |
|
148 |
f (parameters, spec, decls, notes, dependencies); |
|
149 |
in |
|
150 |
thy |
|
151 |
|> (LocalesData.map o apsnd) (Symtab.update (name, Loc {parameters = parameters', |
|
152 |
spec = spec', decls = decls', notes = notes', dependencies = dependencies'})) |
|
153 |
end; |
|
154 |
||
155 |
fun print_locales thy = |
|
156 |
let val (space, locs) = LocalesData.get thy in |
|
157 |
Pretty.strs ("locales:" :: map #1 (NameSpace.extern_table (space, locs))) |
|
158 |
|> Pretty.writeln |
|
159 |
end; |
|
160 |
||
161 |
||
162 |
(*** Primitive operations ***) |
|
163 |
||
164 |
fun params_of thy name = |
|
165 |
let |
|
166 |
val Loc {parameters = (_, params), ...} = the_locale thy name |
|
167 |
in params end; |
|
168 |
||
28872 | 169 |
fun specification_of thy name = |
28795 | 170 |
let |
28872 | 171 |
val Loc {spec, ...} = the_locale thy name |
172 |
in spec end; |
|
173 |
||
174 |
fun declarations_of thy name = |
|
175 |
let |
|
176 |
val Loc {decls, ...} = the_locale thy name |
|
28795 | 177 |
in |
178 |
decls |> apfst (map fst) |> apsnd (map fst) |
|
179 |
end; |
|
180 |
||
181 |
||
28818 | 182 |
(*** Activate context elements of locale ***) |
28795 | 183 |
|
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
184 |
(** Identifiers: activated locales in theory or proof context **) |
28795 | 185 |
|
28899
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
186 |
type identifiers = (string * term list) list; |
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
187 |
|
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
188 |
val empty = ([] : identifiers); |
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
189 |
|
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
190 |
fun ident_eq thy ((n, ts), (m, ss)) = (m = n) andalso Pattern.matchess thy (ss, ts); |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
191 |
|
28795 | 192 |
local |
193 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
194 |
structure IdentifiersData = GenericDataFun |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
195 |
( |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
196 |
type T = identifiers; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
197 |
val empty = empty; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
198 |
val extend = I; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
199 |
fun merge _ = Library.merge (op =); (* FIXME cannot do this properly without theory context *) |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
200 |
); |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
201 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
202 |
in |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
203 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
204 |
val get_idents = IdentifiersData.get o Context.Proof; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
205 |
val put_idents = Context.proof_map o IdentifiersData.put; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
206 |
val clear_idents = put_idents empty; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
207 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
208 |
end; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
209 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
210 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
211 |
(** Resolve locale dependencies in a depth-first fashion **) |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
212 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
213 |
local |
28872 | 214 |
|
28897 | 215 |
val roundup_bound = 120; |
216 |
||
217 |
fun add thy depth (name, morph) (deps, marked) = |
|
218 |
if depth > roundup_bound |
|
219 |
then error "Roundup bound exceeded (sublocale relation probably not terminating)." |
|
220 |
else |
|
221 |
let |
|
222 |
val Loc {parameters = (_, params), dependencies, ...} = the_locale thy name; |
|
223 |
val instance = params |> |
|
224 |
map ((fn (b, T, _) => Free (Name.name_of b, the T)) #> Morphism.term morph); |
|
225 |
in |
|
28899
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
226 |
if member (ident_eq thy) marked (name, instance) |
28897 | 227 |
then (deps, marked) |
228 |
else |
|
229 |
let |
|
230 |
val dependencies' = |
|
231 |
map (fn ((name, morph'), _) => (name, morph' $> morph)) dependencies; |
|
28899
7bf5d7f154b8
Perform higher-order pattern matching during round-up.
ballarin
parents:
28897
diff
changeset
|
232 |
val marked' = (name, instance) :: marked; |
28897 | 233 |
val (deps', marked'') = fold_rev (add thy (depth + 1)) dependencies' ([], marked'); |
234 |
in |
|
235 |
((name, morph) :: deps' @ deps, marked'') |
|
236 |
end |
|
237 |
end; |
|
238 |
||
239 |
in |
|
240 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
241 |
fun roundup thy activate_dep (name, morph) (marked, input) = |
28795 | 242 |
let |
28902
2019bcc9d8bf
Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents:
28899
diff
changeset
|
243 |
val (dependencies', marked') = add thy 0 (name, morph) ([], marked); |
28894
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
244 |
in |
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
245 |
(marked', input |> fold_rev (activate_dep thy) dependencies') |
28894
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
246 |
end; |
28795 | 247 |
|
248 |
end; |
|
249 |
||
28897 | 250 |
|
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
251 |
(* Declarations, facts and entire locale content *) |
28795 | 252 |
|
28818 | 253 |
fun activate_decls thy (name, morph) ctxt = |
254 |
let |
|
255 |
val Loc {decls = (typ_decls, term_decls), ...} = the_locale thy name; |
|
256 |
in |
|
257 |
ctxt |> fold_rev (fn (decl, _) => Context.proof_map (decl morph)) typ_decls |> |
|
258 |
fold_rev (fn (decl, _) => Context.proof_map (decl morph)) term_decls |
|
259 |
end; |
|
28795 | 260 |
|
28818 | 261 |
fun activate_notes activ_elem thy (name, morph) input = |
262 |
let |
|
263 |
val Loc {notes, ...} = the_locale thy name; |
|
264 |
fun activate ((kind, facts), _) input = |
|
28795 | 265 |
let |
28818 | 266 |
val facts' = facts |> Element.facts_map (Element.morph_ctxt morph) |
267 |
in activ_elem (Notes (kind, facts')) input end; |
|
28795 | 268 |
in |
28818 | 269 |
fold_rev activate notes input |
28795 | 270 |
end; |
271 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
272 |
fun activate_all name thy activ_elem (marked, input) = |
28795 | 273 |
let |
274 |
val Loc {parameters = (_, params), spec = (asm, defs), dependencies, ...} = |
|
28902
2019bcc9d8bf
Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents:
28899
diff
changeset
|
275 |
the_locale thy name; |
28795 | 276 |
in |
28818 | 277 |
input |> |
28851
368aca388dd9
Use 'if' in connection with 'is_some' and 'the'.
ballarin
parents:
28833
diff
changeset
|
278 |
(if not (null params) then activ_elem (Fixes params) else I) |> |
28795 | 279 |
(* FIXME type parameters *) |
28965 | 280 |
(if is_some asm then activ_elem (Assumes [(Attrib.empty_binding, [(the asm, [])])]) else I) |> |
28851
368aca388dd9
Use 'if' in connection with 'is_some' and 'the'.
ballarin
parents:
28833
diff
changeset
|
281 |
(if not (null defs) |
28965 | 282 |
then activ_elem (Defines (map (fn def => (Attrib.empty_binding, (def, []))) defs)) |
28851
368aca388dd9
Use 'if' in connection with 'is_some' and 'the'.
ballarin
parents:
28833
diff
changeset
|
283 |
else I) |> |
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
284 |
pair marked |> roundup thy (activate_notes activ_elem) (name, Morphism.identity) |
28795 | 285 |
end; |
286 |
||
28897 | 287 |
|
288 |
(** Public activation functions **) |
|
289 |
||
28818 | 290 |
local |
291 |
||
292 |
fun init_elem (Fixes fixes) ctxt = ctxt |> |
|
293 |
ProofContext.add_fixes_i fixes |> snd |
|
294 |
| init_elem (Assumes assms) ctxt = |
|
295 |
let |
|
296 |
val assms' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) assms |
|
297 |
in |
|
298 |
ctxt |> fold Variable.auto_fixes (maps (map fst o snd) assms') |> |
|
299 |
ProofContext.add_assms_i Assumption.assume_export assms' |> snd |
|
300 |
end |
|
301 |
| init_elem (Defines defs) ctxt = |
|
302 |
let |
|
303 |
val defs' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) defs |
|
304 |
in |
|
305 |
ctxt |> fold Variable.auto_fixes (map (fst o snd) defs') |> |
|
306 |
ProofContext.add_assms_i LocalDefs.def_export (map (fn (attn, t) => (attn, [t])) defs') |> |
|
307 |
snd |
|
308 |
end |
|
309 |
| init_elem (Notes (kind, facts)) ctxt = |
|
310 |
let |
|
311 |
val facts' = Attrib.map_facts (Attrib.attribute_i (ProofContext.theory_of ctxt)) facts |
|
28940 | 312 |
in Locale.local_note_qualified kind facts' ctxt |> snd end |
28818 | 313 |
|
314 |
fun cons_elem false (Notes notes) elems = elems |
|
315 |
| cons_elem _ elem elems = elem :: elems |
|
316 |
||
317 |
in |
|
318 |
||
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
319 |
fun activate_declarations thy dep ctxt = |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
320 |
roundup thy activate_decls dep (get_idents ctxt, ctxt) |> uncurry put_idents; |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
321 |
|
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
322 |
fun activate_facts thy dep ctxt = |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
323 |
roundup thy (activate_notes init_elem) dep (get_idents ctxt, ctxt) |> uncurry put_idents; |
28897 | 324 |
|
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
325 |
fun init name thy = activate_all name thy init_elem (empty, ProofContext.init thy) |> |
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
326 |
uncurry put_idents; |
28818 | 327 |
|
28795 | 328 |
fun print_locale thy show_facts name = |
28902
2019bcc9d8bf
Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents:
28899
diff
changeset
|
329 |
let |
2019bcc9d8bf
Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents:
28899
diff
changeset
|
330 |
val name' = intern thy name; |
2019bcc9d8bf
Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents:
28899
diff
changeset
|
331 |
val ctxt = init name' thy |
28795 | 332 |
in |
333 |
Pretty.big_list "locale elements:" |
|
28951
e89dde5f365c
Sublocale: removed public after_qed; identifiers private to NewLocale.
ballarin
parents:
28940
diff
changeset
|
334 |
(activate_all name' thy (cons_elem show_facts) (empty, []) |> snd |> rev |> |
28818 | 335 |
map (Element.pretty_ctxt ctxt) |> map Pretty.chunks) |> Pretty.writeln |
336 |
end |
|
28795 | 337 |
|
338 |
end; |
|
339 |
||
340 |
||
28818 | 341 |
(*** Storing results ***) |
342 |
||
28833 | 343 |
(* Theorems *) |
344 |
||
345 |
fun add_thmss loc kind args ctxt = |
|
346 |
let |
|
347 |
val (([Notes args'], _), ctxt') = Element.activate_i [Notes (kind, args)] ctxt; |
|
348 |
val ctxt'' = ctxt' |> ProofContext.theory |
|
349 |
(change_locale loc |
|
350 |
(fn (parameters, spec, decls, notes, dependencies) => |
|
351 |
(parameters, spec, decls, (args', stamp ()) :: notes, dependencies))) |
|
352 |
(* FIXME registrations *) |
|
353 |
in ctxt'' end; |
|
354 |
||
355 |
||
28818 | 356 |
(* Declarations *) |
357 |
||
358 |
local |
|
359 |
||
360 |
fun decl_attrib decl phi = Thm.declaration_attribute (K (decl phi)); |
|
361 |
||
362 |
fun add_decls add loc decl = |
|
363 |
ProofContext.theory (change_locale loc |
|
364 |
(fn (parameters, spec, decls, notes, dependencies) => |
|
28833 | 365 |
(parameters, spec, add (decl, stamp ()) decls, notes, dependencies))) #> |
28818 | 366 |
add_thmss loc Thm.internalK |
28965 | 367 |
[((Binding.empty, [Attrib.internal (decl_attrib decl)]), [([Drule.dummy_thm], [])])]; |
28818 | 368 |
|
369 |
in |
|
370 |
||
371 |
val add_type_syntax = add_decls (apfst o cons); |
|
372 |
val add_term_syntax = add_decls (apsnd o cons); |
|
373 |
val add_declaration = add_decls (K I); |
|
374 |
||
375 |
end; |
|
376 |
||
28894
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
377 |
(* Dependencies *) |
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
378 |
|
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
379 |
fun add_dependency loc dep = |
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
380 |
ProofContext.theory (change_locale loc |
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
381 |
(fn (parameters, spec, decls, notes, dependencies) => |
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
382 |
(parameters, spec, decls, notes, (dep, stamp ()) :: dependencies))); |
ff724071b902
Command to add dependencies, fixed processing of dependencies.
ballarin
parents:
28878
diff
changeset
|
383 |
|
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
384 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
385 |
(*** Reasoning about locales ***) |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
386 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
387 |
(** Storage for witnesses, intro and unfold rules **) |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
388 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
389 |
structure Witnesses = ThmsFun(); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
390 |
structure Intros = ThmsFun(); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
391 |
structure Unfolds = ThmsFun(); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
392 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
393 |
val witness_attrib = Witnesses.add; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
394 |
val intro_attrib = Intros.add; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
395 |
val unfold_attrib = Unfolds.add; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
396 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
397 |
(** Tactic **) |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
398 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
399 |
fun intro_locales_tac eager ctxt facts st = |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
400 |
Method.intros_tac |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
401 |
(Witnesses.get ctxt @ Intros.get ctxt @ (if eager then Unfolds.get ctxt else [])) facts st; |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
402 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
403 |
val _ = Context.>> (Context.map_theory |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
404 |
(Method.add_methods |
28927
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
405 |
[("intro_locales", |
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
406 |
Method.ctxt_args (fn ctxt => Method.METHOD (intro_locales_tac false ctxt ORELSE' |
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
407 |
Locale.intro_locales_tac false ctxt)), |
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
408 |
"back-chain introduction rules of locales without unfolding predicates"), |
28927
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
409 |
("unfold_locales", |
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
410 |
Method.ctxt_args (fn ctxt => Method.METHOD (intro_locales_tac true ctxt ORELSE' |
7e631979922f
Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents:
28903
diff
changeset
|
411 |
Locale.intro_locales_tac true ctxt)), |
28903
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
412 |
"back-chain all introduction rules of locales")])); |
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
413 |
|
b3fc3a62247a
Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents:
28902
diff
changeset
|
414 |
|
28818 | 415 |
end; |
416 |