author | wenzelm |
Thu, 02 Jun 2005 18:29:50 +0200 | |
changeset 16190 | 8382835019d1 |
parent 16158 | 2c3565b74b7a |
child 16198 | cfd070a2cc4d |
permissions | -rw-r--r-- |
1526 | 1 |
(* Title: Pure/theory.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson and Markus Wenzel |
|
4 |
||
5025 | 5 |
The abstract type "theory" of theories. |
1526 | 6 |
*) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
7 |
signature BASIC_THEORY = |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
8 |
sig |
1526 | 9 |
type theory |
10 |
exception THEORY of string * theory list |
|
3996 | 11 |
val rep_theory: theory -> |
3814 | 12 |
{sign: Sign.sg, |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
13 |
const_deps: Defs.graph, |
3996 | 14 |
axioms: term Symtab.table, |
4996 | 15 |
oracles: ((Sign.sg * Object.T -> term) * stamp) Symtab.table, |
4019 | 16 |
parents: theory list, |
17 |
ancestors: theory list} |
|
3996 | 18 |
val sign_of: theory -> Sign.sg |
6188 | 19 |
val is_draft: theory -> bool |
3996 | 20 |
val syn_of: theory -> Syntax.syntax |
21 |
val parents_of: theory -> theory list |
|
4019 | 22 |
val ancestors_of: theory -> theory list |
3996 | 23 |
val subthy: theory * theory -> bool |
24 |
val eq_thy: theory * theory -> bool |
|
25 |
val cert_axm: Sign.sg -> string * term -> string * term |
|
6311 | 26 |
val read_def_axm: Sign.sg * (indexname -> typ option) * (indexname -> sort option) -> |
27 |
string list -> string * string -> string * term |
|
3996 | 28 |
val read_axm: Sign.sg -> string * string -> string * term |
29 |
val inferT_axm: Sign.sg -> string * term -> string * term |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
30 |
end |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
31 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
32 |
signature THEORY = |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
33 |
sig |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
34 |
include BASIC_THEORY |
3996 | 35 |
val axiomK: string |
36 |
val oracleK: string |
|
4912 | 37 |
(*theory extension primitives*) |
3996 | 38 |
val add_classes: (bclass * xclass list) list -> theory -> theory |
39 |
val add_classes_i: (bclass * class list) list -> theory -> theory |
|
40 |
val add_classrel: (xclass * xclass) list -> theory -> theory |
|
41 |
val add_classrel_i: (class * class) list -> theory -> theory |
|
8897 | 42 |
val add_defsort: string -> theory -> theory |
3996 | 43 |
val add_defsort_i: sort -> theory -> theory |
44 |
val add_types: (bstring * int * mixfix) list -> theory -> theory |
|
4846 | 45 |
val add_nonterminals: bstring list -> theory -> theory |
3996 | 46 |
val add_tyabbrs: (bstring * string list * string * mixfix) list |
1526 | 47 |
-> theory -> theory |
3996 | 48 |
val add_tyabbrs_i: (bstring * string list * typ * mixfix) list |
1526 | 49 |
-> theory -> theory |
8897 | 50 |
val add_arities: (xstring * string list * string) list -> theory -> theory |
3996 | 51 |
val add_arities_i: (string * sort list * sort) list -> theory -> theory |
52 |
val add_consts: (bstring * string * mixfix) list -> theory -> theory |
|
53 |
val add_consts_i: (bstring * typ * mixfix) list -> theory -> theory |
|
54 |
val add_syntax: (bstring * string * mixfix) list -> theory -> theory |
|
55 |
val add_syntax_i: (bstring * typ * mixfix) list -> theory -> theory |
|
56 |
val add_modesyntax: string * bool -> (bstring * string * mixfix) list -> theory -> theory |
|
57 |
val add_modesyntax_i: string * bool -> (bstring * typ * mixfix) list -> theory -> theory |
|
15747 | 58 |
val del_modesyntax: string * bool -> (bstring * string * mixfix) list -> theory -> theory |
59 |
val del_modesyntax_i: string * bool -> (bstring * typ * mixfix) list -> theory -> theory |
|
3996 | 60 |
val add_trfuns: |
4344 | 61 |
(string * (Syntax.ast list -> Syntax.ast)) list * |
62 |
(string * (term list -> term)) list * |
|
63 |
(string * (term list -> term)) list * |
|
64 |
(string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory |
|
3996 | 65 |
val add_trfunsT: |
4344 | 66 |
(string * (bool -> typ -> term list -> term)) list -> theory -> theory |
14645 | 67 |
val add_advanced_trfuns: |
68 |
(string * (Sign.sg -> Syntax.ast list -> Syntax.ast)) list * |
|
69 |
(string * (Sign.sg -> term list -> term)) list * |
|
70 |
(string * (Sign.sg -> term list -> term)) list * |
|
71 |
(string * (Sign.sg -> Syntax.ast list -> Syntax.ast)) list -> theory -> theory |
|
72 |
val add_advanced_trfunsT: |
|
73 |
(string * (Sign.sg -> bool -> typ -> term list -> term)) list -> theory -> theory |
|
2693 | 74 |
val add_tokentrfuns: |
6311 | 75 |
(string * string * (string -> string * real)) list -> theory -> theory |
76 |
val add_mode_tokentrfuns: string -> (string * (string -> string * real)) list |
|
77 |
-> theory -> theory |
|
4617 | 78 |
val add_trrules: (xstring * string) Syntax.trrule list -> theory -> theory |
3996 | 79 |
val add_trrules_i: Syntax.ast Syntax.trrule list -> theory -> theory |
80 |
val add_axioms: (bstring * string) list -> theory -> theory |
|
81 |
val add_axioms_i: (bstring * term) list -> theory -> theory |
|
4996 | 82 |
val add_oracle: bstring * (Sign.sg * Object.T -> term) -> theory -> theory |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
83 |
val add_finals: bool -> string list -> theory -> theory |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
84 |
val add_finals_i: bool -> term list -> theory -> theory |
9320 | 85 |
val add_defs: bool -> (bstring * string) list -> theory -> theory |
86 |
val add_defs_i: bool -> (bstring * term) list -> theory -> theory |
|
3996 | 87 |
val add_path: string -> theory -> theory |
4846 | 88 |
val parent_path: theory -> theory |
89 |
val root_path: theory -> theory |
|
11501 | 90 |
val absolute_path: theory -> theory |
16134
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
91 |
val qualified_names: theory -> theory |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
92 |
val no_base_names: theory -> theory |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
93 |
val custom_accesses: (string list -> string list list) -> theory -> theory |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
94 |
val set_policy: (string -> bstring -> string) * (string list -> string list list) -> |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
95 |
theory -> theory |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
96 |
val restore_naming: theory -> theory -> theory |
12588 | 97 |
val hide_space: bool -> string * xstring list -> theory -> theory |
98 |
val hide_space_i: bool -> string * string list -> theory -> theory |
|
99 |
val hide_classes: bool -> string list -> theory -> theory |
|
100 |
val hide_types: bool -> string list -> theory -> theory |
|
101 |
val hide_consts: bool -> string list -> theory -> theory |
|
3996 | 102 |
val add_name: string -> theory -> theory |
5862 | 103 |
val copy: theory -> theory |
6661 | 104 |
val prep_ext: theory -> theory |
3996 | 105 |
val prep_ext_merge: theory list -> theory |
4970 | 106 |
val requires: theory -> string -> string -> unit |
6369 | 107 |
val assert_super: theory -> theory -> theory |
3996 | 108 |
val pre_pure: theory |
1526 | 109 |
end; |
110 |
||
6188 | 111 |
signature PRIVATE_THEORY = |
5642 | 112 |
sig |
113 |
include THEORY |
|
6546 | 114 |
val init_data: Object.kind -> (Object.T * (Object.T -> Object.T) * (Object.T -> Object.T) * |
12311 | 115 |
(Object.T * Object.T -> Object.T) * (Sign.sg -> Object.T -> unit)) -> theory -> theory |
5642 | 116 |
val print_data: Object.kind -> theory -> unit |
117 |
val get_data: Object.kind -> (Object.T -> 'a) -> theory -> 'a |
|
118 |
val put_data: Object.kind -> ('a -> Object.T) -> 'a -> theory -> theory |
|
119 |
end; |
|
1526 | 120 |
|
5642 | 121 |
|
6188 | 122 |
structure Theory: PRIVATE_THEORY = |
1526 | 123 |
struct |
2206 | 124 |
|
3996 | 125 |
|
2206 | 126 |
(** datatype theory **) |
1526 | 127 |
|
128 |
datatype theory = |
|
129 |
Theory of { |
|
130 |
sign: Sign.sg, |
|
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
131 |
const_deps: Defs.graph, |
3996 | 132 |
axioms: term Symtab.table, |
4996 | 133 |
oracles: ((Sign.sg * Object.T -> term) * stamp) Symtab.table, |
4019 | 134 |
parents: theory list, |
135 |
ancestors: theory list}; |
|
1526 | 136 |
|
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
137 |
fun make_theory sign const_deps axioms oracles parents ancestors = |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
138 |
Theory {sign = sign, const_deps = const_deps, axioms = axioms, |
16190 | 139 |
oracles = oracles, parents = parents, ancestors = ancestors}; |
3996 | 140 |
|
1526 | 141 |
fun rep_theory (Theory args) = args; |
142 |
||
3996 | 143 |
val sign_of = #sign o rep_theory; |
6188 | 144 |
val is_draft = Sign.is_draft o sign_of; |
14645 | 145 |
val syn_of = Sign.syn_of o sign_of; |
3996 | 146 |
val parents_of = #parents o rep_theory; |
4019 | 147 |
val ancestors_of = #ancestors o rep_theory; |
3996 | 148 |
|
1526 | 149 |
(*errors involving theories*) |
150 |
exception THEORY of string * theory list; |
|
151 |
||
152 |
(*compare theories*) |
|
153 |
val subthy = Sign.subsig o pairself sign_of; |
|
154 |
val eq_thy = Sign.eq_sg o pairself sign_of; |
|
155 |
||
6369 | 156 |
(*check for some theory*) |
4970 | 157 |
fun requires thy name what = |
10930 | 158 |
if Sign.exists_stamp name (sign_of thy) then () |
4846 | 159 |
else error ("Require theory " ^ quote name ^ " as an ancestor for " ^ what); |
1526 | 160 |
|
6369 | 161 |
fun assert_super thy1 thy2 = |
162 |
if subthy (thy1, thy2) then thy2 |
|
163 |
else raise THEORY ("Not a super theory", [thy1, thy2]); |
|
164 |
||
4846 | 165 |
(*partial Pure theory*) |
9282
0181ac100520
Defs are now checked for circularity (if not overloaded).
nipkow
parents:
9280
diff
changeset
|
166 |
val pre_pure = |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
167 |
make_theory Sign.pre_pure Defs.empty Symtab.empty Symtab.empty [] []; |
1526 | 168 |
|
169 |
||
170 |
||
171 |
(** extend theory **) |
|
172 |
||
8725 | 173 |
(*name spaces*) |
3996 | 174 |
val axiomK = "axiom"; |
3814 | 175 |
val oracleK = "oracle"; |
176 |
||
177 |
||
178 |
(* extend logical part of a theory *) |
|
179 |
||
1526 | 180 |
fun err_dup_axms names = |
10494 | 181 |
error ("Duplicate axiom name(s): " ^ commas_quote names); |
1526 | 182 |
|
3814 | 183 |
fun err_dup_oras names = |
10494 | 184 |
error ("Duplicate oracles: " ^ commas_quote names); |
3814 | 185 |
|
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
186 |
fun ext_theory thy ext_sg new_axms new_oras = |
1526 | 187 |
let |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
188 |
val Theory {sign, const_deps, axioms, oracles, parents, ancestors} = thy; |
1526 | 189 |
val draft = Sign.is_draft sign; |
3996 | 190 |
val axioms' = |
4488 | 191 |
Symtab.extend (if draft then axioms else Symtab.empty, new_axms) |
1526 | 192 |
handle Symtab.DUPS names => err_dup_axms names; |
3814 | 193 |
val oracles' = |
4488 | 194 |
Symtab.extend (oracles, new_oras) |
3814 | 195 |
handle Symtab.DUPS names => err_dup_oras names; |
4019 | 196 |
val (parents', ancestors') = |
197 |
if draft then (parents, ancestors) else ([thy], thy :: ancestors); |
|
1526 | 198 |
in |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
199 |
make_theory (ext_sg sign) const_deps axioms' oracles' parents' ancestors' |
1526 | 200 |
end; |
201 |
||
202 |
||
203 |
(* extend signature of a theory *) |
|
204 |
||
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
205 |
fun ext_sign ext_sg args thy = ext_theory thy (ext_sg args) [] []; |
1526 | 206 |
|
14645 | 207 |
val add_classes = ext_sign Sign.add_classes; |
208 |
val add_classes_i = ext_sign Sign.add_classes_i; |
|
209 |
val add_classrel = ext_sign Sign.add_classrel; |
|
210 |
val add_classrel_i = ext_sign Sign.add_classrel_i; |
|
211 |
val add_defsort = ext_sign Sign.add_defsort; |
|
212 |
val add_defsort_i = ext_sign Sign.add_defsort_i; |
|
213 |
val add_types = ext_sign Sign.add_types; |
|
214 |
val add_nonterminals = ext_sign Sign.add_nonterminals; |
|
215 |
val add_tyabbrs = ext_sign Sign.add_tyabbrs; |
|
216 |
val add_tyabbrs_i = ext_sign Sign.add_tyabbrs_i; |
|
217 |
val add_arities = ext_sign Sign.add_arities; |
|
218 |
val add_arities_i = ext_sign Sign.add_arities_i; |
|
219 |
val add_consts = ext_sign Sign.add_consts; |
|
220 |
val add_consts_i = ext_sign Sign.add_consts_i; |
|
221 |
val add_syntax = ext_sign Sign.add_syntax; |
|
222 |
val add_syntax_i = ext_sign Sign.add_syntax_i; |
|
223 |
val add_modesyntax = curry (ext_sign Sign.add_modesyntax); |
|
224 |
val add_modesyntax_i = curry (ext_sign Sign.add_modesyntax_i); |
|
15747 | 225 |
val del_modesyntax = curry (ext_sign Sign.del_modesyntax); |
226 |
val del_modesyntax_i = curry (ext_sign Sign.del_modesyntax_i); |
|
14645 | 227 |
val add_trfuns = ext_sign Sign.add_trfuns; |
228 |
val add_trfunsT = ext_sign Sign.add_trfunsT; |
|
229 |
val add_advanced_trfuns = ext_sign Sign.add_advanced_trfuns; |
|
230 |
val add_advanced_trfunsT = ext_sign Sign.add_advanced_trfunsT; |
|
231 |
val add_tokentrfuns = ext_sign Sign.add_tokentrfuns; |
|
6311 | 232 |
fun add_mode_tokentrfuns m = add_tokentrfuns o map (fn (s, f) => (m, s, f)); |
14645 | 233 |
val add_trrules = ext_sign Sign.add_trrules; |
234 |
val add_trrules_i = ext_sign Sign.add_trrules_i; |
|
235 |
val add_path = ext_sign Sign.add_path; |
|
236 |
val parent_path = add_path ".."; |
|
237 |
val root_path = add_path "/"; |
|
238 |
val absolute_path = add_path "//"; |
|
16134
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
239 |
val qualified_names = ext_sign (K Sign.qualified_names) (); |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
240 |
val no_base_names = ext_sign (K Sign.no_base_names) (); |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
241 |
val custom_accesses = ext_sign Sign.custom_accesses; |
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
242 |
val set_policy = ext_sign Sign.set_policy; |
16190 | 243 |
val restore_naming = ext_sign Sign.restore_naming o sign_of; |
14645 | 244 |
val add_space = ext_sign Sign.add_space; |
245 |
val hide_space = ext_sign o Sign.hide_space; |
|
246 |
val hide_space_i = ext_sign o Sign.hide_space_i; |
|
247 |
fun hide_classes b = curry (hide_space_i b) Sign.classK; |
|
248 |
fun hide_types b = curry (hide_space_i b) Sign.typeK; |
|
249 |
fun hide_consts b = curry (hide_space_i b) Sign.constK; |
|
250 |
val add_name = ext_sign Sign.add_name; |
|
251 |
val copy = ext_sign (K Sign.copy) (); |
|
252 |
val prep_ext = ext_sign (K Sign.prep_ext) (); |
|
3814 | 253 |
|
3996 | 254 |
|
6311 | 255 |
|
3814 | 256 |
(** add axioms **) |
257 |
||
1526 | 258 |
(* prepare axioms *) |
259 |
||
260 |
fun err_in_axm name = |
|
261 |
error ("The error(s) above occurred in axiom " ^ quote name); |
|
262 |
||
14184
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
263 |
fun no_vars sg tm = (case (term_vars tm, term_tvars tm) of |
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
264 |
([], []) => tm |
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
265 |
| (ts, ixns) => error (Pretty.string_of (Pretty.block (Pretty.breaks |
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
266 |
(Pretty.str "Illegal schematic variable(s) in term:" :: |
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
267 |
map (Sign.pretty_term sg) ts @ |
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
268 |
map (Sign.pretty_typ sg o TVar) ixns))))); |
1526 | 269 |
|
270 |
fun cert_axm sg (name, raw_tm) = |
|
271 |
let |
|
14828 | 272 |
val (t, T, _) = Sign.certify_term (Sign.pp sg) sg raw_tm |
2979 | 273 |
handle TYPE (msg, _, _) => error msg |
3996 | 274 |
| TERM (msg, _) => error msg; |
1526 | 275 |
in |
9537 | 276 |
Term.no_dummy_patterns t handle TERM (msg, _) => error msg; |
1526 | 277 |
assert (T = propT) "Term not of type prop"; |
14184
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
278 |
(name, no_vars sg t) |
9629 | 279 |
end; |
1526 | 280 |
|
5057 | 281 |
(*some duplication of code with read_def_cterm*) |
6661 | 282 |
fun read_def_axm (sg, types, sorts) used (name, str) = |
3814 | 283 |
let |
14914 | 284 |
val ts = Syntax.read (Sign.is_logtype sg) (Sign.syn_of sg) propT str; |
14828 | 285 |
val (t, _) = Sign.infer_types (Sign.pp sg) sg types sorts used true (ts, propT); |
9320 | 286 |
in cert_axm sg (name, t) end |
1960
ae390b599213
Improved error handling: if there are syntax or type-checking
paulson
parents:
1539
diff
changeset
|
287 |
handle ERROR => err_in_axm name; |
1526 | 288 |
|
15531 | 289 |
fun read_axm sg name_str = read_def_axm (sg, K NONE, K NONE) [] name_str; |
5057 | 290 |
|
1526 | 291 |
fun inferT_axm sg (name, pre_tm) = |
14828 | 292 |
let val (t, _) = Sign.infer_types (Sign.pp sg) sg |
15531 | 293 |
(K NONE) (K NONE) [] true ([pre_tm], propT); |
14184
2e0e02d68cbb
Changed no_vars such that it outputs list of illegal schematic variables.
berghofe
parents:
13646
diff
changeset
|
294 |
in (name, no_vars sg t) end |
1526 | 295 |
handle ERROR => err_in_axm name; |
296 |
||
297 |
||
298 |
(* extend axioms of a theory *) |
|
299 |
||
3814 | 300 |
fun ext_axms prep_axm raw_axms (thy as Theory {sign, ...}) = |
1526 | 301 |
let |
3814 | 302 |
val raw_axms' = map (apfst (Sign.full_name sign)) raw_axms; |
303 |
val axioms = |
|
304 |
map (apsnd (Term.compress_term o Logic.varify) o prep_axm sign) raw_axms'; |
|
4996 | 305 |
val ext_sg = Sign.add_space (axiomK, map fst axioms); |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
306 |
in ext_theory thy ext_sg axioms [] end; |
1526 | 307 |
|
308 |
val add_axioms = ext_axms read_axm; |
|
309 |
val add_axioms_i = ext_axms cert_axm; |
|
310 |
||
311 |
||
3814 | 312 |
(* add oracle **) |
313 |
||
314 |
fun add_oracle (raw_name, oracle) (thy as Theory {sign, ...}) = |
|
315 |
let |
|
316 |
val name = Sign.full_name sign raw_name; |
|
4996 | 317 |
val ext_sg = Sign.add_space (oracleK, [name]); |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
318 |
in ext_theory thy ext_sg [] [(name, (oracle, stamp ()))] end; |
3814 | 319 |
|
320 |
||
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
321 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
322 |
(** add constant definitions **) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
323 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
324 |
(* clash_types, clash_consts *) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
325 |
|
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
326 |
(*check if types have common instance (ignoring sorts) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
327 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
328 |
fun clash_types ty1 ty2 = |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
329 |
let |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
330 |
val ty1' = Type.varifyT ty1; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
331 |
val ty2' = incr_tvar (maxidx_of_typ ty1' + 1) (Type.varifyT ty2); |
9320 | 332 |
in Type.raw_unify (ty1', ty2') end; |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
333 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
334 |
fun clash_consts (c1, ty1) (c2, ty2) = |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
335 |
c1 = c2 andalso clash_types ty1 ty2; |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
336 |
*) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
337 |
|
16134
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
338 |
|
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
339 |
(* clash_defns |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
340 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
341 |
fun clash_defn c_ty (name, tm) = |
14204 | 342 |
let val (c, ty') = dest_Const (head_of (fst (Logic.dest_equals (Logic.strip_imp_concl tm)))) in |
15531 | 343 |
if clash_consts c_ty (c, ty') then SOME (name, ty') else NONE |
344 |
end handle TERM _ => NONE; |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
345 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
346 |
fun clash_defns c_ty axms = |
15570 | 347 |
distinct (List.mapPartial (clash_defn c_ty) axms); |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
348 |
*) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
349 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
350 |
|
9320 | 351 |
(* overloading *) |
9280 | 352 |
|
9320 | 353 |
datatype overloading = NoOverloading | Useless | Plain; |
354 |
||
355 |
fun overloading sg declT defT = |
|
10403 | 356 |
let val T = Term.incr_tvar (maxidx_of_typ declT + 1) (Type.varifyT defT) in |
357 |
if Sign.typ_instance sg (declT, T) then NoOverloading |
|
14789 | 358 |
else if Sign.typ_instance sg (Type.strip_sorts declT, Type.strip_sorts T) then Useless |
9320 | 359 |
else Plain |
9280 | 360 |
end; |
361 |
||
362 |
||
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
363 |
(* dest_defn *) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
364 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
365 |
fun dest_defn tm = |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
366 |
let |
3787
67571f49ebe3
new internal forms: add_classes_i, add_classrel_i, add_defsort_i, add_arities_i
wenzelm
parents:
3767
diff
changeset
|
367 |
fun err msg = raise TERM (msg, [tm]); |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
368 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
369 |
val (lhs, rhs) = Logic.dest_equals (Logic.strip_imp_concl tm) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
370 |
handle TERM _ => err "Not a meta-equality (==)"; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
371 |
val (head, args) = strip_comb lhs; |
9320 | 372 |
val c_ty as (c, ty) = dest_Const head |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
373 |
handle TERM _ => err "Head of lhs not a constant"; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
374 |
|
4141 | 375 |
fun dest_free (Free (x, _)) = x |
376 |
| dest_free (Const ("TYPE", Type ("itself", [TFree (x, _)]))) = x |
|
377 |
| dest_free _ = raise Match; |
|
378 |
||
379 |
val show_frees = commas_quote o map dest_free; |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
380 |
val show_tfrees = commas_quote o map fst; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
381 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
382 |
val lhs_dups = duplicates args; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
383 |
val rhs_extras = gen_rems (op =) (term_frees rhs, args); |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
384 |
val rhs_extrasT = gen_rems (op =) (term_tfrees rhs, typ_tfrees ty); |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
385 |
in |
4141 | 386 |
if not (forall (can dest_free) args) then |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
387 |
err "Arguments (on lhs) must be variables" |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
388 |
else if not (null lhs_dups) then |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
389 |
err ("Duplicate variables on lhs: " ^ show_frees lhs_dups) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
390 |
else if not (null rhs_extras) then |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
391 |
err ("Extra variables on rhs: " ^ show_frees rhs_extras) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
392 |
else if not (null rhs_extrasT) then |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
393 |
err ("Extra type variables on rhs: " ^ show_tfrees rhs_extrasT) |
9282
0181ac100520
Defs are now checked for circularity (if not overloaded).
nipkow
parents:
9280
diff
changeset
|
394 |
else if exists_Const (fn c_ty' => c_ty' = c_ty) rhs then |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
395 |
err ("Constant to be defined occurs on rhs") |
9320 | 396 |
else (c_ty, rhs) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
397 |
end; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
398 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
399 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
400 |
(* check_defn *) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
401 |
|
3814 | 402 |
fun err_in_defn sg name msg = |
16190 | 403 |
error (cat_lines [msg, "The error(s) above occurred in definition " ^ quote name]); |
9320 | 404 |
|
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
405 |
fun pretty_const sg (c, ty) = [Pretty.str c, Pretty.str " ::", Pretty.quote (Sign.pretty_typ sg (#1 (Type.freeze_thaw_type ty)))]; |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
406 |
|
16113
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
407 |
fun cycle_msg sg (infinite, namess) = |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
408 |
let val header = if not (infinite) then "cyclic dependency found: " else "infinite chain found: " |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
409 |
in |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
410 |
Pretty.string_of (Pretty.block (((Pretty.str header) :: Pretty.fbrk :: ( |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
411 |
let |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
412 |
fun f last (ty, constname, defname) = |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
413 |
(pretty_const sg (constname, ty)) @ (if last then [] else [Pretty.str (" depends via "^ quote defname^ " on ")]) |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
414 |
|
16113
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
415 |
in |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
416 |
foldr (fn (x,r) => (f (r=[]) x)@[Pretty.fbrk]@r) [] namess |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
417 |
end)))) |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
418 |
end |
9320 | 419 |
|
16190 | 420 |
fun check_defn sg overloaded ((deps, axms), def as (bname, tm)) = |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
421 |
let |
16190 | 422 |
val name = Sign.full_name sg bname; |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
423 |
|
10494 | 424 |
fun pretty_const (c, ty) = [Pretty.str c, Pretty.str " ::", Pretty.brk 1, |
425 |
Pretty.quote (Sign.pretty_typ sg (#1 (Type.freeze_thaw_type ty)))]; |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
426 |
|
10494 | 427 |
fun def_txt (c_ty, txt) = Pretty.block |
428 |
(Pretty.str "Definition of " :: pretty_const c_ty @ |
|
429 |
(if txt = "" then [] else [Pretty.str txt])); |
|
430 |
||
431 |
fun show_defn c (dfn, ty') = Pretty.block |
|
432 |
(Pretty.str " " :: pretty_const (c, ty') @ [Pretty.str " in ", Pretty.str dfn]); |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
433 |
|
9320 | 434 |
val (c_ty as (c, ty), rhs) = dest_defn tm |
9280 | 435 |
handle TERM (msg, _) => err_in_defn sg name msg; |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
436 |
|
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
437 |
fun decl deps c = |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
438 |
(case Sign.const_type sg c of |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
439 |
SOME T => (Defs.declare deps (c, T) handle _ => deps, T) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
440 |
| NONE => err_in_defn sg name ("Undeclared constant " ^ quote c)); |
9320 | 441 |
|
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
442 |
val (deps, c_decl) = decl deps c |
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
443 |
|
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
444 |
val body = Term.term_constsT rhs |
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
445 |
val deps = foldl (fn ((c, _), deps) => fst (decl deps c)) deps body |
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
446 |
|
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
447 |
in |
9320 | 448 |
(case overloading sg c_decl ty of |
16134
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
449 |
Useless => |
10494 | 450 |
err_in_defn sg name (Pretty.string_of (Pretty.chunks |
16134
89ea482e1649
added qualified_names, no_base_names, custom_accesses, set_policy, restore_naming;
wenzelm
parents:
16113
diff
changeset
|
451 |
[Library.setmp show_sorts true def_txt (c_ty, ""), Pretty.str |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
452 |
"imposes additional sort constraints on the declared type of the constant"])) |
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
453 |
| ov => |
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
454 |
let |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
455 |
val deps' = Defs.define deps c_ty name body |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
456 |
handle Defs.DEFS s => err_in_defn sg name ("DEFS: "^s) |
16113
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
457 |
| Defs.CIRCULAR s => err_in_defn sg name (cycle_msg sg (false, s)) |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
458 |
| Defs.INFINITE_CHAIN s => err_in_defn sg name (cycle_msg sg (true, s)) |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
459 |
| Defs.CLASH (_, def1, def2) => err_in_defn sg name ( |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
460 |
"clashing definitions "^ quote def1 ^" and "^ quote def2) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
461 |
| Defs.FINAL cfinal => |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
462 |
err_in_defn sg name (Pretty.string_of (Pretty.block |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
463 |
([Pretty.str "The constant",Pretty.brk 1] @ |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
464 |
pretty_const cfinal @ |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
465 |
[Pretty.brk 1,Pretty.str "has been declared final"]))) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
466 |
in |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
467 |
((if ov = Plain andalso not overloaded then |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
468 |
warning (Pretty.string_of (Pretty.chunks |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
469 |
[def_txt (c_ty, ""), Pretty.str ("is strictly less general than the declared type (see " ^ quote name ^ ")")])) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
470 |
else |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
471 |
()); (deps', def::axms)) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
472 |
end) |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
473 |
end; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
474 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
475 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
476 |
(* add_defs *) |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
477 |
|
9320 | 478 |
fun ext_defns prep_axm overloaded raw_axms thy = |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
479 |
let |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
480 |
val Theory {sign, const_deps, axioms, oracles, parents, ancestors} = thy; |
15570 | 481 |
val all_axioms = List.concat (map (Symtab.dest o #axioms o rep_theory) (thy :: ancestors)); |
9320 | 482 |
|
483 |
val axms = map (prep_axm sign) raw_axms; |
|
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
484 |
val (const_deps', _) = Library.foldl (check_defn sign overloaded) ((const_deps, all_axioms), axms); |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
485 |
in |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
486 |
make_theory sign const_deps' axioms oracles parents ancestors |
9320 | 487 |
|> add_axioms_i axms |
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
488 |
end; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
489 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
490 |
val add_defs_i = ext_defns cert_axm; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
491 |
val add_defs = ext_defns read_axm; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
492 |
|
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
493 |
|
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
494 |
(* add_finals *) |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
495 |
|
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
496 |
fun ext_finals prep_term overloaded raw_terms thy = |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
497 |
let |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
498 |
val Theory {sign, const_deps, axioms, oracles, parents, ancestors} = thy; |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
499 |
fun mk_final (tm, finals) = |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
500 |
let |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
501 |
fun err msg = raise TERM(msg,[tm]) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
502 |
val (c,ty) = dest_Const tm |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
503 |
handle TERM _ => err "Can only make constants final" |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
504 |
val c_decl = |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
505 |
(case Sign.const_type sign c of |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
506 |
SOME T => T |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
507 |
| NONE => err ("Undeclared constant " ^ quote c)) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
508 |
val _ = |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
509 |
case overloading sign c_decl ty of |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
510 |
NoOverloading => () |
16190 | 511 |
| Useless => err "Sort constraints too strong" |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
512 |
| Plain => (if overloaded then () else warning "Type is more general than declared") |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
513 |
val finals = Defs.declare finals (c, c_decl) handle _ => finals |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
514 |
in |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
515 |
Defs.finalize finals (c,ty) |
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
516 |
end |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
517 |
val consts = map (prep_term sign) raw_terms; |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
518 |
val const_deps' = foldl mk_final const_deps consts; |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
519 |
in |
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
520 |
make_theory sign const_deps' axioms oracles parents ancestors |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
521 |
end; |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
522 |
|
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
523 |
local |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
524 |
fun read_term sg = Sign.simple_read_term sg TypeInfer.logicT; |
14828 | 525 |
fun cert_term sg = #1 o Sign.certify_term (Sign.pp sg) sg; |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
526 |
in |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
527 |
val add_finals = ext_finals read_term; |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
528 |
val add_finals_i = ext_finals cert_term; |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
529 |
end; |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
530 |
|
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
531 |
fun merge_final sg = |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
532 |
let |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
533 |
fun merge_single (tys,ty) = |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
534 |
if exists (curry (Sign.typ_instance sg) ty) tys |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
535 |
then tys |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
536 |
else (ty::gen_rem (Sign.typ_instance sg) (tys,ty)); |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
537 |
fun merge ([],_) = [] |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
538 |
| merge (_,[]) = [] |
15570 | 539 |
| merge input = Library.foldl merge_single input; |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
540 |
in |
15531 | 541 |
SOME o merge |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
542 |
end; |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
14204
diff
changeset
|
543 |
|
3878 | 544 |
|
3865 | 545 |
(** additional theory data **) |
546 |
||
4996 | 547 |
val init_data = curry (ext_sign Sign.init_data); |
548 |
fun print_data kind = Sign.print_data kind o sign_of; |
|
549 |
fun get_data kind f = Sign.get_data kind f o sign_of; |
|
550 |
fun put_data kind f = ext_sign (Sign.put_data kind f); |
|
3865 | 551 |
|
552 |
||
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
553 |
|
6661 | 554 |
(** merge theories **) (*exception ERROR*) |
4019 | 555 |
|
3878 | 556 |
(*merge list of theories from left to right, preparing extend*) |
3967
edd5ff9371f8
sg_ref: automatic adjustment of thms of draft theories;
wenzelm
parents:
3956
diff
changeset
|
557 |
fun prep_ext_merge thys = |
15703 | 558 |
let |
559 |
val sign' = Sign.prep_ext_merge (map sign_of thys) |
|
3814 | 560 |
|
15703 | 561 |
val depss = map (#const_deps o rep_theory) thys; |
16108
cf468b93a02e
Implement cycle-free overloading, so that definitions cannot harm consistency any more (except of course via interaction with axioms).
obua
parents:
15747
diff
changeset
|
562 |
val deps' = foldl (uncurry Defs.merge) (hd depss) (tl depss) |
16113
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
563 |
handle Defs.CIRCULAR namess => error (cycle_msg sign' (false, namess)) |
692fe6595755
Infinite chains in definitions are now detected, too.
obua
parents:
16108
diff
changeset
|
564 |
| Defs.INFINITE_CHAIN namess => error (cycle_msg sign' (true, namess)) |
15703 | 565 |
|
566 |
val axioms' = Symtab.empty; |
|
9282
0181ac100520
Defs are now checked for circularity (if not overloaded).
nipkow
parents:
9280
diff
changeset
|
567 |
|
15703 | 568 |
fun eq_ora ((_, (_, s1: stamp)), (_, (_, s2))) = s1 = s2; |
569 |
val oracles' = |
|
570 |
Symtab.make (gen_distinct eq_ora |
|
571 |
(List.concat (map (Symtab.dest o #oracles o rep_theory) thys))) |
|
572 |
handle Symtab.DUPS names => err_dup_oras names; |
|
4019 | 573 |
|
15703 | 574 |
val parents' = gen_distinct eq_thy thys; |
575 |
val ancestors' = |
|
576 |
gen_distinct eq_thy (parents' @ List.concat (map ancestors_of thys)); |
|
577 |
in |
|
16158
2c3565b74b7a
Removed final_consts from theory data. Now const_deps deals with final
obua
parents:
16134
diff
changeset
|
578 |
make_theory sign' deps' axioms' oracles' parents' ancestors' |
15703 | 579 |
end; |
1526 | 580 |
|
3885 | 581 |
|
1526 | 582 |
end; |
583 |
||
3767
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
584 |
structure BasicTheory: BASIC_THEORY = Theory; |
e2bb53d8dd26
moved theory stuff (add_defs etc.) here from drule.ML;
wenzelm
parents:
2979
diff
changeset
|
585 |
open BasicTheory; |