| author | wenzelm |
| Tue, 12 Mar 2013 16:47:24 +0100 | |
| changeset 51399 | 6ac3c29a300e |
| parent 50239 | fb579401dc26 |
| child 51583 | 9100c8e66b69 |
| permissions | -rw-r--r-- |
| 5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
| 19001 | 4 |
The key concept of Isar proof contexts: elevates primitive local |
5 |
reasoning Gamma |- phi to a structured concept, with generic context |
|
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
6 |
elements. See also structure Variable and Assumption. |
| 5819 | 7 |
*) |
8 |
||
9 |
signature PROOF_CONTEXT = |
|
10 |
sig |
|
| 20310 | 11 |
val theory_of: Proof.context -> theory |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36542
diff
changeset
|
12 |
val init_global: theory -> Proof.context |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
13 |
type mode |
| 24501 | 14 |
val mode_default: mode |
15 |
val mode_stmt: mode |
|
16 |
val mode_pattern: mode |
|
17 |
val mode_schematic: mode |
|
18 |
val mode_abbrev: mode |
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
19 |
val set_mode: mode -> Proof.context -> Proof.context |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
20 |
val get_mode: Proof.context -> mode |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
21 |
val restore_mode: Proof.context -> Proof.context -> Proof.context |
| 27286 | 22 |
val abbrev_mode: Proof.context -> bool |
|
21667
ce813b82c88b
add_notation: permissive about undeclared consts;
wenzelm
parents:
21648
diff
changeset
|
23 |
val set_stmt: bool -> Proof.context -> Proof.context |
|
42241
dd8029f71e1c
separate module for standard implementation of inner syntax operations;
wenzelm
parents:
42224
diff
changeset
|
24 |
val syntax_of: Proof.context -> Local_Syntax.T |
| 35111 | 25 |
val syn_of: Proof.context -> Syntax.syntax |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
26 |
val tsig_of: Proof.context -> Type.tsig |
| 36451 | 27 |
val set_defsort: sort -> Proof.context -> Proof.context |
| 35680 | 28 |
val default_sort: Proof.context -> indexname -> sort |
| 20310 | 29 |
val consts_of: Proof.context -> Consts.T |
| 24752 | 30 |
val the_const_constraint: Proof.context -> string -> typ |
| 20784 | 31 |
val set_syntax_mode: Syntax.mode -> Proof.context -> Proof.context |
| 20310 | 32 |
val restore_syntax_mode: Proof.context -> Proof.context -> Proof.context |
| 26284 | 33 |
val facts_of: Proof.context -> Facts.T |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
33957
diff
changeset
|
34 |
val cases_of: Proof.context -> (string * (Rule_Cases.T * bool)) list |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
35 |
val map_naming: (Name_Space.naming -> Name_Space.naming) -> Proof.context -> Proof.context |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
36 |
val naming_of: Proof.context -> Name_Space.naming |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
37 |
val restore_naming: Proof.context -> Proof.context -> Proof.context |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
38 |
val full_name: Proof.context -> binding -> string |
| 42359 | 39 |
val class_space: Proof.context -> Name_Space.T |
40 |
val type_space: Proof.context -> Name_Space.T |
|
41 |
val const_space: Proof.context -> Name_Space.T |
|
42 |
val intern_class: Proof.context -> xstring -> string |
|
43 |
val intern_type: Proof.context -> xstring -> string |
|
44 |
val intern_const: Proof.context -> xstring -> string |
|
45 |
val extern_class: Proof.context -> string -> xstring |
|
46 |
val extern_type: Proof.context -> string -> xstring |
|
47 |
val extern_const: Proof.context -> string -> xstring |
|
| 27259 | 48 |
val transfer_syntax: theory -> Proof.context -> Proof.context |
| 20310 | 49 |
val transfer: theory -> Proof.context -> Proof.context |
|
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
50 |
val background_theory: (theory -> theory) -> Proof.context -> Proof.context |
|
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
51 |
val background_theory_result: (theory -> 'a * theory) -> Proof.context -> 'a * Proof.context |
| 28212 | 52 |
val extern_fact: Proof.context -> string -> xstring |
| 21728 | 53 |
val pretty_term_abbrev: Proof.context -> term -> Pretty.T |
| 49888 | 54 |
val markup_fact: Proof.context -> string -> Markup.T |
| 20310 | 55 |
val pretty_fact: Proof.context -> string * thm list -> Pretty.T |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
56 |
val read_class: Proof.context -> xstring -> class |
| 20310 | 57 |
val read_typ: Proof.context -> string -> typ |
58 |
val read_typ_syntax: Proof.context -> string -> typ |
|
59 |
val read_typ_abbrev: Proof.context -> string -> typ |
|
60 |
val cert_typ: Proof.context -> typ -> typ |
|
61 |
val cert_typ_syntax: Proof.context -> typ -> typ |
|
62 |
val cert_typ_abbrev: Proof.context -> typ -> typ |
|
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
63 |
val infer_type: Proof.context -> string * typ -> typ |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
64 |
val inferred_param: string -> Proof.context -> typ * Proof.context |
| 25328 | 65 |
val inferred_fixes: Proof.context -> (string * typ) list * Proof.context |
|
35360
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
66 |
val read_type_name: Proof.context -> bool -> string -> typ |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
67 |
val read_type_name_proper: Proof.context -> bool -> string -> typ |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
68 |
val read_const_proper: Proof.context -> bool -> string -> term |
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
69 |
val read_const: Proof.context -> bool -> typ -> string -> term |
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
70 |
val read_arity: Proof.context -> xstring * string list * string -> arity |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
71 |
val cert_arity: Proof.context -> arity -> arity |
| 27259 | 72 |
val allow_dummies: Proof.context -> Proof.context |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
73 |
val prepare_sortsT: Proof.context -> typ list -> string * typ list |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
74 |
val prepare_sorts: Proof.context -> term list -> string * term list |
| 36152 | 75 |
val check_tfree: Proof.context -> string * sort -> string * sort |
|
42250
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
76 |
val intern_skolem: Proof.context -> string -> string option |
| 24684 | 77 |
val read_term_pattern: Proof.context -> string -> term |
78 |
val read_term_schematic: Proof.context -> string -> term |
|
79 |
val read_term_abbrev: Proof.context -> string -> term |
|
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
80 |
val show_abbrevs_raw: Config.raw |
|
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
81 |
val show_abbrevs: bool Config.T |
|
25345
dd5b851f8ef0
renamed ProofContext.read_const' to ProofContext.read_const_proper;
wenzelm
parents:
25332
diff
changeset
|
82 |
val expand_abbrevs: Proof.context -> term -> term |
| 20310 | 83 |
val cert_term: Proof.context -> term -> term |
84 |
val cert_prop: Proof.context -> term -> term |
|
|
35616
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
85 |
val def_type: Proof.context -> indexname -> typ option |
| 45429 | 86 |
val standard_typ_check: Proof.context -> typ list -> typ list |
87 |
val standard_term_check_finish: Proof.context -> term list -> term list |
|
88 |
val standard_term_uncheck: Proof.context -> term list -> term list |
|
| 20310 | 89 |
val goal_export: Proof.context -> Proof.context -> thm list -> thm list |
90 |
val export: Proof.context -> Proof.context -> thm list -> thm list |
|
| 21531 | 91 |
val export_morphism: Proof.context -> Proof.context -> morphism |
| 28396 | 92 |
val norm_export_morphism: Proof.context -> Proof.context -> morphism |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
93 |
val bind_terms: (indexname * term option) list -> Proof.context -> Proof.context |
| 20310 | 94 |
val auto_bind_goal: term list -> Proof.context -> Proof.context |
95 |
val auto_bind_facts: term list -> Proof.context -> Proof.context |
|
96 |
val match_bind: bool -> (string list * string) list -> Proof.context -> term list * Proof.context |
|
97 |
val match_bind_i: bool -> (term list * term) list -> Proof.context -> term list * Proof.context |
|
| 45327 | 98 |
val read_propp: (string * string list) list list -> Proof.context -> |
99 |
(term * term list) list list * Proof.context |
|
100 |
val cert_propp: (term * term list) list list -> Proof.context -> |
|
101 |
(term * term list) list list * Proof.context |
|
102 |
val read_propp_schematic: (string * string list) list list -> Proof.context -> |
|
103 |
(term * term list) list list * Proof.context |
|
104 |
val cert_propp_schematic: (term * term list) list list -> Proof.context -> |
|
105 |
(term * term list) list list * Proof.context |
|
106 |
val bind_propp: (string * string list) list list -> Proof.context -> |
|
107 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
108 |
val bind_propp_i: (term * term list) list list -> Proof.context -> |
|
109 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
110 |
val bind_propp_schematic: (string * string list) list list -> Proof.context -> |
|
111 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
112 |
val bind_propp_schematic_i: (term * term list) list list -> Proof.context -> |
|
113 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
| 18042 | 114 |
val fact_tac: thm list -> int -> tactic |
| 20310 | 115 |
val some_fact_tac: Proof.context -> int -> tactic |
|
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
116 |
val get_fact: Proof.context -> Facts.ref -> thm list |
|
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
117 |
val get_fact_single: Proof.context -> Facts.ref -> thm |
|
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
118 |
val get_thms: Proof.context -> xstring -> thm list |
|
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
119 |
val get_thm: Proof.context -> xstring -> thm |
|
30761
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
120 |
val note_thmss: string -> (Thm.binding * (thm list * attribute list) list) list -> |
| 30211 | 121 |
Proof.context -> (string * thm list) list * Proof.context |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
122 |
val put_thms: bool -> string * thm list option -> Proof.context -> Proof.context |
| 29581 | 123 |
val read_vars: (binding * string option * mixfix) list -> Proof.context -> |
124 |
(binding * typ option * mixfix) list * Proof.context |
|
125 |
val cert_vars: (binding * typ option * mixfix) list -> Proof.context -> |
|
126 |
(binding * typ option * mixfix) list * Proof.context |
|
|
30763
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
127 |
val add_fixes: (binding * typ option * mixfix) list -> Proof.context -> |
|
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
128 |
string list * Proof.context |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
129 |
val add_assms: Assumption.export -> |
| 30211 | 130 |
(Thm.binding * (string * string list) list) list -> |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
131 |
Proof.context -> (string * thm list) list * Proof.context |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
132 |
val add_assms_i: Assumption.export -> |
| 30211 | 133 |
(Thm.binding * (term * term list) list) list -> |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
134 |
Proof.context -> (string * thm list) list * Proof.context |
| 33368 | 135 |
val add_cases: bool -> (string * Rule_Cases.T option) list -> Proof.context -> Proof.context |
136 |
val apply_case: Rule_Cases.T -> Proof.context -> (string * term list) list * Proof.context |
|
| 42496 | 137 |
val get_case: Proof.context -> string -> binding option list -> Rule_Cases.T |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
138 |
val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> Proof.context -> Proof.context |
| 24949 | 139 |
val notation: bool -> Syntax.mode -> (term * mixfix) list -> Proof.context -> Proof.context |
| 47247 | 140 |
val generic_type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> morphism -> |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
141 |
Context.generic -> Context.generic |
| 47247 | 142 |
val generic_notation: bool -> Syntax.mode -> (term * mixfix) list -> morphism -> |
| 21744 | 143 |
Context.generic -> Context.generic |
| 35680 | 144 |
val class_alias: binding -> class -> Proof.context -> Proof.context |
145 |
val type_alias: binding -> string -> Proof.context -> Proof.context |
|
146 |
val const_alias: binding -> string -> Proof.context -> Proof.context |
|
| 24767 | 147 |
val add_const_constraint: string * typ option -> Proof.context -> Proof.context |
|
33173
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents:
33165
diff
changeset
|
148 |
val add_abbrev: string -> binding * term -> Proof.context -> (term * term) * Proof.context |
| 25052 | 149 |
val revert_abbrev: string -> string -> Proof.context -> Proof.context |
| 47275 | 150 |
val generic_add_abbrev: string -> binding * term -> Context.generic -> |
151 |
(term * term) * Context.generic |
|
152 |
val generic_revert_abbrev: string -> string -> Context.generic -> Context.generic |
|
| 20310 | 153 |
val print_syntax: Proof.context -> unit |
| 21728 | 154 |
val print_abbrevs: Proof.context -> unit |
| 20310 | 155 |
val print_binds: Proof.context -> unit |
156 |
val print_lthms: Proof.context -> unit |
|
157 |
val print_cases: Proof.context -> unit |
|
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
158 |
val debug: bool Config.T |
|
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
159 |
val verbose: bool Config.T |
| 20310 | 160 |
val pretty_ctxt: Proof.context -> Pretty.T list |
161 |
val pretty_context: Proof.context -> Pretty.T list |
|
| 5819 | 162 |
end; |
163 |
||
| 42360 | 164 |
structure Proof_Context: PROOF_CONTEXT = |
| 5819 | 165 |
struct |
166 |
||
| 42363 | 167 |
val theory_of = Proof_Context.theory_of; |
168 |
val init_global = Proof_Context.init_global; |
|
169 |
||
| 12057 | 170 |
|
| 7270 | 171 |
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
172 |
(** inner syntax mode **) |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
173 |
|
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
174 |
datatype mode = |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
175 |
Mode of |
| 24486 | 176 |
{stmt: bool, (*inner statement mode*)
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
177 |
pattern: bool, (*pattern binding schematic variables*) |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
178 |
schematic: bool, (*term referencing loose schematic variables*) |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
179 |
abbrev: bool}; (*abbrev mode -- no normalization*) |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
180 |
|
| 24486 | 181 |
fun make_mode (stmt, pattern, schematic, abbrev) = |
182 |
Mode {stmt = stmt, pattern = pattern, schematic = schematic, abbrev = abbrev};
|
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
183 |
|
| 24486 | 184 |
val mode_default = make_mode (false, false, false, false); |
185 |
val mode_stmt = make_mode (true, false, false, false); |
|
186 |
val mode_pattern = make_mode (false, true, false, false); |
|
187 |
val mode_schematic = make_mode (false, false, true, false); |
|
188 |
val mode_abbrev = make_mode (false, false, false, true); |
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
189 |
|
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
190 |
|
| 5819 | 191 |
|
| 16540 | 192 |
(** Isar proof context information **) |
| 5819 | 193 |
|
| 45650 | 194 |
datatype data = |
195 |
Data of |
|
| 36451 | 196 |
{mode: mode, (*inner syntax mode*)
|
197 |
syntax: Local_Syntax.T, (*local syntax*) |
|
198 |
tsig: Type.tsig * Type.tsig, (*local/global type signature -- local name space / defsort only*) |
|
199 |
consts: Consts.T * Consts.T, (*local/global consts -- local name space / abbrevs only*) |
|
200 |
facts: Facts.T, (*local facts*) |
|
| 33368 | 201 |
cases: (string * (Rule_Cases.T * bool)) list}; (*named case contexts*) |
| 5819 | 202 |
|
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
203 |
fun make_data (mode, syntax, tsig, consts, facts, cases) = |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
204 |
Data {mode = mode, syntax = syntax, tsig = tsig, consts = consts, facts = facts, cases = cases};
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
205 |
|
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37145
diff
changeset
|
206 |
structure Data = Proof_Data |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
207 |
( |
| 45650 | 208 |
type T = data; |
| 16540 | 209 |
fun init thy = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
210 |
make_data (mode_default, Local_Syntax.init thy, |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
211 |
(Sign.tsig_of thy, Sign.tsig_of thy), |
| 26284 | 212 |
(Sign.consts_of thy, Sign.consts_of thy), Facts.empty, []); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
213 |
); |
| 5819 | 214 |
|
| 45650 | 215 |
fun rep_data ctxt = Data.get ctxt |> (fn Data rep => rep); |
| 5819 | 216 |
|
| 45650 | 217 |
fun map_data f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
218 |
Data.map (fn Data {mode, syntax, tsig, consts, facts, cases} =>
|
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
219 |
make_data (f (mode, syntax, tsig, consts, facts, cases))); |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
220 |
|
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
221 |
fun set_mode mode = map_data (fn (_, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
222 |
(mode, syntax, tsig, consts, facts, cases)); |
|
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
223 |
|
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
224 |
fun map_mode f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
225 |
map_data (fn (Mode {stmt, pattern, schematic, abbrev}, syntax, tsig, consts, facts, cases) =>
|
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
226 |
(make_mode (f (stmt, pattern, schematic, abbrev)), syntax, tsig, consts, facts, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
227 |
|
| 19001 | 228 |
fun map_syntax f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
229 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
230 |
(mode, f syntax, tsig, consts, facts, cases)); |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
231 |
|
| 36450 | 232 |
fun map_tsig f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
233 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
234 |
(mode, syntax, f tsig, consts, facts, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
235 |
|
| 19001 | 236 |
fun map_consts f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
237 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
238 |
(mode, syntax, tsig, f consts, facts, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
239 |
|
| 26284 | 240 |
fun map_facts f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
241 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
242 |
(mode, syntax, tsig, consts, f facts, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
243 |
|
| 19001 | 244 |
fun map_cases f = |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
245 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
246 |
(mode, syntax, tsig, consts, facts, f cases)); |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
247 |
|
| 45650 | 248 |
val get_mode = #mode o rep_data; |
| 28407 | 249 |
val restore_mode = set_mode o get_mode; |
| 27286 | 250 |
val abbrev_mode = get_mode #> (fn Mode {abbrev, ...} => abbrev);
|
|
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
251 |
|
| 24486 | 252 |
fun set_stmt stmt = |
253 |
map_mode (fn (_, pattern, schematic, abbrev) => (stmt, pattern, schematic, abbrev)); |
|
| 19001 | 254 |
|
| 45650 | 255 |
val syntax_of = #syntax o rep_data; |
| 33387 | 256 |
val syn_of = Local_Syntax.syn_of o syntax_of; |
257 |
val set_syntax_mode = map_syntax o Local_Syntax.set_mode; |
|
258 |
val restore_syntax_mode = map_syntax o Local_Syntax.restore_mode o syntax_of; |
|
| 19001 | 259 |
|
| 45650 | 260 |
val tsig_of = #1 o #tsig o rep_data; |
| 36451 | 261 |
val set_defsort = map_tsig o apfst o Type.set_defsort; |
| 35680 | 262 |
fun default_sort ctxt = the_default (Type.defaultS (tsig_of ctxt)) o Variable.def_sort ctxt; |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
263 |
|
| 45650 | 264 |
val consts_of = #1 o #consts o rep_data; |
| 24752 | 265 |
val the_const_constraint = Consts.the_constraint o consts_of; |
| 5819 | 266 |
|
| 45650 | 267 |
val facts_of = #facts o rep_data; |
268 |
val cases_of = #cases o rep_data; |
|
| 5819 | 269 |
|
270 |
||
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
271 |
(* naming *) |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
272 |
|
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
273 |
val naming_of = Name_Space.naming_of o Context.Proof; |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
274 |
val map_naming = Context.proof_map o Name_Space.map_naming; |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
275 |
val restore_naming = map_naming o K o naming_of; |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
276 |
|
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
277 |
val full_name = Name_Space.full_name o naming_of; |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
278 |
|
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
279 |
|
| 42359 | 280 |
(* name spaces *) |
281 |
||
282 |
val class_space = Type.class_space o tsig_of; |
|
283 |
val type_space = Type.type_space o tsig_of; |
|
284 |
val const_space = Consts.space_of o consts_of; |
|
285 |
||
286 |
val intern_class = Name_Space.intern o class_space; |
|
287 |
val intern_type = Name_Space.intern o type_space; |
|
288 |
val intern_const = Name_Space.intern o const_space; |
|
289 |
||
290 |
fun extern_class ctxt = Name_Space.extern ctxt (class_space ctxt); |
|
291 |
fun extern_type ctxt = Name_Space.extern ctxt (type_space ctxt); |
|
292 |
fun extern_const ctxt = Name_Space.extern ctxt (const_space ctxt); |
|
293 |
||
294 |
||
| 20367 | 295 |
(* theory transfer *) |
| 12093 | 296 |
|
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
297 |
fun transfer_syntax thy ctxt = ctxt |> |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
298 |
map_syntax (Local_Syntax.rebuild thy) |> |
| 36450 | 299 |
map_tsig (fn tsig as (local_tsig, global_tsig) => |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
300 |
let val thy_tsig = Sign.tsig_of thy in |
| 36450 | 301 |
if Type.eq_tsig (thy_tsig, global_tsig) then tsig |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
302 |
else (Type.merge_tsig (Context.pretty ctxt) (local_tsig, thy_tsig), thy_tsig) |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
303 |
end) |> |
|
30424
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
304 |
map_consts (fn consts as (local_consts, global_consts) => |
|
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
305 |
let val thy_consts = Sign.consts_of thy in |
|
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
306 |
if Consts.eq_consts (thy_consts, global_consts) then consts |
|
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
307 |
else (Consts.merge (local_consts, thy_consts), thy_consts) |
|
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
308 |
end); |
| 17072 | 309 |
|
|
33031
b75c35574e04
backpatching of structure Proof and ProofContext -- avoid odd aliases;
wenzelm
parents:
32966
diff
changeset
|
310 |
fun transfer thy = Context.raw_transfer thy #> transfer_syntax thy; |
| 17072 | 311 |
|
|
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
312 |
fun background_theory f ctxt = transfer (f (theory_of ctxt)) ctxt; |
| 20367 | 313 |
|
|
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
314 |
fun background_theory_result f ctxt = |
| 20367 | 315 |
let val (res, thy') = f (theory_of ctxt) |
316 |
in (res, ctxt |> transfer thy') end; |
|
| 19019 | 317 |
|
| 12093 | 318 |
|
319 |
||
| 14828 | 320 |
(** pretty printing **) |
321 |
||
| 28212 | 322 |
(* extern *) |
323 |
||
| 42378 | 324 |
fun which_facts ctxt name = |
| 28212 | 325 |
let |
326 |
val local_facts = facts_of ctxt; |
|
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
327 |
val global_facts = Global_Theory.facts_of (theory_of ctxt); |
| 28212 | 328 |
in |
329 |
if is_some (Facts.lookup (Context.Proof ctxt) local_facts name) |
|
| 42378 | 330 |
then local_facts else global_facts |
| 28212 | 331 |
end; |
332 |
||
| 42379 | 333 |
fun markup_fact ctxt name = Name_Space.markup (Facts.space_of (which_facts ctxt name)) name; |
| 42378 | 334 |
|
335 |
fun extern_fact ctxt name = Facts.extern ctxt (which_facts ctxt name) name; |
|
336 |
||
| 28212 | 337 |
|
338 |
(* pretty *) |
|
339 |
||
| 24922 | 340 |
fun pretty_term_abbrev ctxt = Syntax.pretty_term (set_mode mode_abbrev ctxt); |
| 14828 | 341 |
|
| 42378 | 342 |
fun pretty_fact_name ctxt a = |
343 |
Pretty.block [Pretty.mark_str (markup_fact ctxt a, extern_fact ctxt a), Pretty.str ":"]; |
|
|
28209
02f3222a392d
pretty_fact: extern fact name wrt. the given context, assuming that is the proper one for presentation;
wenzelm
parents:
28087
diff
changeset
|
344 |
|
|
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49888
diff
changeset
|
345 |
fun pretty_fact ctxt ("", ths) = Display.pretty_thms ctxt ths
|
|
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49888
diff
changeset
|
346 |
| pretty_fact ctxt (a, [th]) = Pretty.block |
|
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49888
diff
changeset
|
347 |
[pretty_fact_name ctxt a, Pretty.brk 1, Display.pretty_thm ctxt th] |
|
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49888
diff
changeset
|
348 |
| pretty_fact ctxt (a, ths) = Pretty.block |
|
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49888
diff
changeset
|
349 |
(Pretty.fbreaks (pretty_fact_name ctxt a :: map (Display.pretty_thm ctxt) ths)); |
| 14828 | 350 |
|
351 |
||
352 |
||
| 5819 | 353 |
(** prepare types **) |
354 |
||
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
355 |
(* classes *) |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
356 |
|
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
357 |
fun read_class ctxt text = |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
358 |
let |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
359 |
val tsig = tsig_of ctxt; |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
360 |
val (syms, pos) = Syntax.read_token text; |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
361 |
val c = Type.cert_class tsig (Type.intern_class tsig (Symbol_Pos.content syms)) |
| 48992 | 362 |
handle TYPE (msg, _, _) => error (msg ^ Position.here pos); |
| 42467 | 363 |
val _ = Context_Position.report ctxt pos (Name_Space.markup (Type.class_space tsig) c); |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
364 |
in c end; |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
365 |
|
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
366 |
|
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
367 |
(* types *) |
| 24277 | 368 |
|
369 |
fun read_typ_mode mode ctxt s = |
|
| 24486 | 370 |
Syntax.read_typ (Type.set_mode mode ctxt) s; |
| 24277 | 371 |
|
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
372 |
val read_typ = read_typ_mode Type.mode_default; |
| 24277 | 373 |
val read_typ_syntax = read_typ_mode Type.mode_syntax; |
374 |
val read_typ_abbrev = read_typ_mode Type.mode_abbrev; |
|
375 |
||
376 |
||
377 |
fun cert_typ_mode mode ctxt T = |
|
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
378 |
Type.cert_typ_mode mode (tsig_of ctxt) T |
| 24277 | 379 |
handle TYPE (msg, _, _) => error msg; |
380 |
||
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
381 |
val cert_typ = cert_typ_mode Type.mode_default; |
| 24277 | 382 |
val cert_typ_syntax = cert_typ_mode Type.mode_syntax; |
383 |
val cert_typ_abbrev = cert_typ_mode Type.mode_abbrev; |
|
384 |
||
385 |
||
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
386 |
|
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
387 |
(** prepare variables **) |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
388 |
|
|
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
389 |
(* check Skolem constants *) |
| 7679 | 390 |
|
| 18678 | 391 |
fun no_skolem internal x = |
|
20086
94ca946fb689
adapted to more efficient Name/Variable implementation;
wenzelm
parents:
20049
diff
changeset
|
392 |
if can Name.dest_skolem x then |
| 18678 | 393 |
error ("Illegal reference to internal Skolem constant: " ^ quote x)
|
|
20086
94ca946fb689
adapted to more efficient Name/Variable implementation;
wenzelm
parents:
20049
diff
changeset
|
394 |
else if not internal andalso can Name.dest_internal x then |
| 18678 | 395 |
error ("Illegal reference to internal variable: " ^ quote x)
|
| 7679 | 396 |
else x; |
397 |
||
398 |
||
| 18187 | 399 |
|
| 5819 | 400 |
(** prepare terms and propositions **) |
401 |
||
| 25328 | 402 |
(* inferred types of parameters *) |
403 |
||
404 |
fun infer_type ctxt x = |
|
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
405 |
Term.fastype_of (singleton (Syntax.check_terms (set_mode mode_schematic ctxt)) (Free x)); |
| 25328 | 406 |
|
407 |
fun inferred_param x ctxt = |
|
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
408 |
let val T = infer_type ctxt (x, dummyT) |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
409 |
in (T, ctxt |> Variable.declare_term (Free (x, T))) end; |
| 25328 | 410 |
|
411 |
fun inferred_fixes ctxt = |
|
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
412 |
let |
|
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
413 |
val xs = map #2 (Variable.dest_fixes ctxt); |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
414 |
val (Ts, ctxt') = fold_map inferred_param xs ctxt; |
|
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
415 |
in (xs ~~ Ts, ctxt') end; |
| 25328 | 416 |
|
417 |
||
418 |
(* type and constant names *) |
|
419 |
||
| 27821 | 420 |
local |
421 |
||
| 30573 | 422 |
val token_content = Syntax.read_token #>> Symbol_Pos.content; |
| 27821 | 423 |
|
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
424 |
fun prep_const_proper ctxt strict (c, pos) = |
|
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
425 |
let |
| 48992 | 426 |
fun err msg = error (msg ^ Position.here pos); |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
427 |
val consts = consts_of ctxt; |
|
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
428 |
val t as Const (d, _) = |
|
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
429 |
(case Variable.lookup_const ctxt c of |
|
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
430 |
SOME d => |
|
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
431 |
Const (d, Consts.type_scheme (consts_of ctxt) d handle TYPE (msg, _, _) => err msg) |
| 42469 | 432 |
| NONE => Consts.read_const consts (c, pos)); |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
433 |
val _ = |
|
43794
49cbbe2768a8
sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents:
43552
diff
changeset
|
434 |
if strict then ignore (Consts.the_const consts d) handle TYPE (msg, _, _) => err msg |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
435 |
else (); |
| 42467 | 436 |
val _ = Context_Position.report ctxt pos (Name_Space.markup (Consts.space_of consts) d); |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
437 |
in t end; |
| 27821 | 438 |
|
439 |
in |
|
| 25328 | 440 |
|
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
441 |
fun read_type_name ctxt strict text = |
| 27821 | 442 |
let |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
443 |
val tsig = tsig_of ctxt; |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
444 |
val (c, pos) = token_content text; |
| 27821 | 445 |
in |
|
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
42287
diff
changeset
|
446 |
if Lexicon.is_tid c then |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50126
diff
changeset
|
447 |
(Context_Position.report ctxt pos Markup.tfree; |
| 35680 | 448 |
TFree (c, default_sort ctxt (c, ~1))) |
| 27821 | 449 |
else |
450 |
let |
|
| 42359 | 451 |
val d = intern_type ctxt c; |
| 42468 | 452 |
val decl = Type.the_decl tsig (d, pos); |
| 48992 | 453 |
fun err () = error ("Bad type name: " ^ quote d ^ Position.here pos);
|
|
35360
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
454 |
val args = |
|
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
455 |
(case decl of |
|
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
456 |
Type.LogicalType n => n |
|
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
457 |
| Type.Abbreviation (vs, _, _) => if strict then err () else length vs |
|
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
458 |
| Type.Nonterminal => if strict then err () else 0); |
| 42467 | 459 |
val _ = Context_Position.report ctxt pos (Name_Space.markup (Type.type_space tsig) d); |
|
35360
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35262
diff
changeset
|
460 |
in Type (d, replicate args dummyT) end |
| 27821 | 461 |
end; |
| 25328 | 462 |
|
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
463 |
fun read_type_name_proper ctxt strict text = |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
464 |
(case read_type_name ctxt strict text of |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
465 |
T as Type _ => T |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
466 |
| T => error ("Not a type constructor: " ^ Syntax.string_of_typ ctxt T));
|
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
467 |
|
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
468 |
|
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
469 |
fun read_const_proper ctxt strict = prep_const_proper ctxt strict o token_content; |
| 27821 | 470 |
|
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
471 |
fun read_const ctxt strict ty text = |
|
36542
7cb6b40d19b2
read_const: disallow internal names as usual in visible Isar text;
wenzelm
parents:
36505
diff
changeset
|
472 |
let |
|
7cb6b40d19b2
read_const: disallow internal names as usual in visible Isar text;
wenzelm
parents:
36505
diff
changeset
|
473 |
val (c, pos) = token_content text; |
|
7cb6b40d19b2
read_const: disallow internal names as usual in visible Isar text;
wenzelm
parents:
36505
diff
changeset
|
474 |
val _ = no_skolem false c; |
|
7cb6b40d19b2
read_const: disallow internal names as usual in visible Isar text;
wenzelm
parents:
36505
diff
changeset
|
475 |
in |
|
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
476 |
(case (Variable.lookup_fixed ctxt c, Variable.is_const ctxt c) of |
| 27821 | 477 |
(SOME x, false) => |
|
39507
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39441
diff
changeset
|
478 |
(Context_Position.report ctxt pos |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50126
diff
changeset
|
479 |
(Markup.name x (if can Name.dest_skolem x then Markup.skolem else Markup.free)); |
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
480 |
Free (x, infer_type ctxt (x, ty))) |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
481 |
| _ => prep_const_proper ctxt strict (c, pos)) |
| 27821 | 482 |
end; |
483 |
||
484 |
end; |
|
| 25328 | 485 |
|
486 |
||
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
487 |
(* type arities *) |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
488 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
489 |
local |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
490 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
491 |
fun prep_arity prep_tycon prep_sort ctxt (t, Ss, S) = |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
492 |
let val arity = (prep_tycon ctxt t, map (prep_sort ctxt) Ss, prep_sort ctxt S) |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
493 |
in Type.add_arity (Context.pretty ctxt) arity (tsig_of ctxt); arity end; |
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
494 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
495 |
in |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
496 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
497 |
val read_arity = |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
498 |
prep_arity (fn ctxt => #1 o dest_Type o read_type_name_proper ctxt true) Syntax.read_sort; |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
499 |
|
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
500 |
val cert_arity = prep_arity (K I) (Type.cert_sort o tsig_of); |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
501 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
502 |
end; |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
503 |
|
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
504 |
|
|
42250
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
505 |
(* skolem variables *) |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
506 |
|
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
507 |
fun intern_skolem ctxt x = |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
508 |
let |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
509 |
val _ = no_skolem false x; |
|
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
510 |
val sko = Variable.lookup_fixed ctxt x; |
|
42250
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
511 |
val is_const = can (read_const_proper ctxt false) x orelse Long_Name.is_qualified x; |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
512 |
val is_declared = is_some (Variable.def_type ctxt false (x, ~1)); |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
513 |
in |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
514 |
if Variable.is_const ctxt x then NONE |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
515 |
else if is_some sko then sko |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
516 |
else if not is_const orelse is_declared then SOME x |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
517 |
else NONE |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
518 |
end; |
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
519 |
|
|
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
520 |
|
| 24684 | 521 |
(* read_term *) |
522 |
||
523 |
fun read_term_mode mode ctxt = Syntax.read_term (set_mode mode ctxt); |
|
524 |
||
525 |
val read_term_pattern = read_term_mode mode_pattern; |
|
526 |
val read_term_schematic = read_term_mode mode_schematic; |
|
527 |
val read_term_abbrev = read_term_mode mode_abbrev; |
|
528 |
||
529 |
||
| 19001 | 530 |
(* local abbreviations *) |
| 5819 | 531 |
|
| 24501 | 532 |
local |
533 |
||
|
42383
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
534 |
fun certify_consts ctxt = Consts.certify (Context.pretty ctxt) (tsig_of ctxt) |
| 27286 | 535 |
(not (abbrev_mode ctxt)) (consts_of ctxt); |
| 19001 | 536 |
|
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
537 |
fun expand_binds ctxt = |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
538 |
let |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
539 |
val Mode {pattern, schematic, ...} = get_mode ctxt;
|
| 5819 | 540 |
|
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
541 |
fun reject_schematic (t as Var _) = |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
542 |
error ("Unbound schematic variable: " ^ Syntax.string_of_term ctxt t)
|
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
543 |
| reject_schematic (Abs (_, _, t)) = reject_schematic t |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
544 |
| reject_schematic (t $ u) = (reject_schematic t; reject_schematic u) |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
545 |
| reject_schematic _ = (); |
|
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
546 |
in |
| 24495 | 547 |
if pattern then I |
548 |
else Variable.expand_binds ctxt #> (if schematic then I else tap reject_schematic) |
|
549 |
end; |
|
| 5819 | 550 |
|
| 24501 | 551 |
in |
552 |
||
553 |
fun expand_abbrevs ctxt = certify_consts ctxt #> expand_binds ctxt; |
|
554 |
||
555 |
end; |
|
556 |
||
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
557 |
val show_abbrevs_raw = Config.declare "show_abbrevs" (fn _ => Config.Bool true); |
|
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
558 |
val show_abbrevs = Config.bool show_abbrevs_raw; |
| 5819 | 559 |
|
| 24922 | 560 |
fun contract_abbrevs ctxt t = |
561 |
let |
|
562 |
val thy = theory_of ctxt; |
|
563 |
val consts = consts_of ctxt; |
|
564 |
val Mode {abbrev, ...} = get_mode ctxt;
|
|
|
30566
9643f54c4184
reverted abbreviations: improved performance via Item_Net.T;
wenzelm
parents:
30473
diff
changeset
|
565 |
val retrieve = Consts.retrieve_abbrevs consts (print_mode_value () @ [""]); |
|
9643f54c4184
reverted abbreviations: improved performance via Item_Net.T;
wenzelm
parents:
30473
diff
changeset
|
566 |
fun match_abbrev u = Option.map #1 (get_first (Pattern.match_rew thy u) (retrieve u)); |
| 24922 | 567 |
in |
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
568 |
if abbrev orelse not (Config.get ctxt show_abbrevs) orelse not (can Term.type_of t) then t |
|
35211
5d2fe4e09354
Use top-down rewriting to contract abbreviations.
berghofe
parents:
35141
diff
changeset
|
569 |
else Pattern.rewrite_term_top thy [] [match_abbrev] t |
| 24922 | 570 |
end; |
571 |
||
572 |
||
| 24518 | 573 |
(* patterns *) |
574 |
||
| 32003 | 575 |
fun prepare_patternT ctxt T = |
576 |
let |
|
577 |
val Mode {pattern, schematic, ...} = get_mode ctxt;
|
|
578 |
val _ = |
|
579 |
pattern orelse schematic orelse |
|
580 |
T |> Term.exists_subtype |
|
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
581 |
(fn T as TVar (xi, _) => |
|
37145
01aa36932739
renamed structure TypeInfer to Type_Infer, keeping the old name as legacy alias for some time;
wenzelm
parents:
36610
diff
changeset
|
582 |
not (Type_Infer.is_param xi) andalso |
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
583 |
error ("Illegal schematic type variable: " ^ Syntax.string_of_typ ctxt T)
|
| 32003 | 584 |
| _ => false) |
585 |
in T end; |
|
| 24518 | 586 |
|
| 22712 | 587 |
|
| 24505 | 588 |
local |
| 6550 | 589 |
|
| 42360 | 590 |
val dummies = Config.bool (Config.declare "Proof_Context.dummies" (K (Config.Bool false))); |
| 27259 | 591 |
|
592 |
fun check_dummies ctxt t = |
|
|
39508
dfacdb01e1ec
simplified some internal flags using Config.T instead of full-blown Proof_Data;
wenzelm
parents:
39507
diff
changeset
|
593 |
if Config.get ctxt dummies then t |
| 27259 | 594 |
else Term.no_dummy_patterns t handle TERM _ => error "Illegal dummy pattern(s) in term"; |
595 |
||
| 24767 | 596 |
fun prepare_dummies ts = #1 (fold_map Term.replace_dummy_patterns ts 1); |
| 6762 | 597 |
|
| 27259 | 598 |
in |
| 6550 | 599 |
|
|
39508
dfacdb01e1ec
simplified some internal flags using Config.T instead of full-blown Proof_Data;
wenzelm
parents:
39507
diff
changeset
|
600 |
val allow_dummies = Config.put dummies true; |
| 24505 | 601 |
|
| 24684 | 602 |
fun prepare_patterns ctxt = |
| 24518 | 603 |
let val Mode {pattern, ...} = get_mode ctxt in
|
| 39296 | 604 |
Type_Infer.fixate ctxt #> |
| 24767 | 605 |
pattern ? Variable.polymorphic ctxt #> |
| 24684 | 606 |
(map o Term.map_types) (prepare_patternT ctxt) #> |
| 27259 | 607 |
(if pattern then prepare_dummies else map (check_dummies ctxt)) |
| 24505 | 608 |
end; |
609 |
||
610 |
end; |
|
611 |
||
| 6550 | 612 |
|
|
42250
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
613 |
(* sort constraints *) |
| 27286 | 614 |
|
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
615 |
local |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
616 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
617 |
fun prepare_sorts_env ctxt tys = |
| 27286 | 618 |
let |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
619 |
val tsig = tsig_of ctxt; |
| 45453 | 620 |
val defaultS = Type.defaultS tsig; |
| 27286 | 621 |
|
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
622 |
fun constraint (xi, raw_S) env = |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
623 |
let val (ps, S) = Term_Position.decode_positionS raw_S in |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
624 |
if S = dummyS then env |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
625 |
else |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
626 |
Vartab.insert (op =) (xi, Type.minimize_sort tsig S) env |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
627 |
handle Vartab.DUP _ => |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
628 |
error ("Inconsistent sort constraints for type variable " ^
|
| 49691 | 629 |
quote (Term.string_of_vname' xi) ^ Position.here_list ps) |
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
630 |
end; |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
631 |
|
| 45453 | 632 |
val env = |
633 |
(fold o fold_atyps) |
|
634 |
(fn TFree (x, S) => constraint ((x, ~1), S) |
|
635 |
| TVar v => constraint v |
|
636 |
| _ => I) tys Vartab.empty; |
|
| 36152 | 637 |
|
| 45453 | 638 |
fun get_sort xi = |
639 |
(case (Vartab.lookup env xi, Variable.def_sort ctxt xi) of |
|
640 |
(NONE, NONE) => defaultS |
|
| 27286 | 641 |
| (NONE, SOME S) => S |
642 |
| (SOME S, NONE) => S |
|
643 |
| (SOME S, SOME S') => |
|
644 |
if Type.eq_sort tsig (S, S') then S' |
|
| 45453 | 645 |
else |
646 |
error ("Sort constraint " ^ Syntax.string_of_sort ctxt S ^
|
|
647 |
" inconsistent with default " ^ Syntax.string_of_sort ctxt S' ^ |
|
648 |
" for type variable " ^ quote (Term.string_of_vname' xi))); |
|
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
649 |
|
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
650 |
fun add_report S pos reports = |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
651 |
if Position.is_reported pos andalso not (AList.defined (op =) reports pos) then |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50126
diff
changeset
|
652 |
(pos, Position.reported_text pos Markup.sorting (Syntax.string_of_sort ctxt S)) :: reports |
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
653 |
else reports; |
|
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
654 |
|
| 49691 | 655 |
fun get_sort_reports xi raw_S = |
656 |
let |
|
657 |
val ps = #1 (Term_Position.decode_positionS raw_S); |
|
658 |
val S = get_sort xi handle ERROR msg => error (msg ^ Position.here_list ps); |
|
659 |
in fold (add_report S) ps end; |
|
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
660 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
661 |
val reports = |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
662 |
(fold o fold_atyps) |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
663 |
(fn T => |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
664 |
if Term_Position.is_positionT T then I |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
665 |
else |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
666 |
(case T of |
| 49691 | 667 |
TFree (x, raw_S) => get_sort_reports (x, ~1) raw_S |
668 |
| TVar (xi, raw_S) => get_sort_reports xi raw_S |
|
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
669 |
| _ => I)) tys []; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
670 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
671 |
in (implode (map #2 reports), get_sort) end; |
| 27286 | 672 |
|
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
673 |
fun replace_sortsT get_sort = |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
674 |
map_atyps |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
675 |
(fn T => |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
676 |
if Term_Position.is_positionT T then T |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
677 |
else |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
678 |
(case T of |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
679 |
TFree (x, _) => TFree (x, get_sort (x, ~1)) |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
680 |
| TVar (xi, _) => TVar (xi, get_sort xi) |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
681 |
| _ => T)); |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
682 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
683 |
in |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
684 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
685 |
fun prepare_sortsT ctxt tys = |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
686 |
let val (sorting_report, get_sort) = prepare_sorts_env ctxt tys |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
687 |
in (sorting_report, map (replace_sortsT get_sort) tys) end; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
688 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
689 |
fun prepare_sorts ctxt tms = |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
690 |
let |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
691 |
val tys = rev ((fold o fold_types) cons tms []); |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
692 |
val (sorting_report, get_sort) = prepare_sorts_env ctxt tys; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
693 |
in (sorting_report, (map o map_types) (replace_sortsT get_sort) tms) end; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
694 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
695 |
fun check_tfree ctxt v = |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
696 |
let |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
697 |
val (sorting_report, [TFree a]) = prepare_sortsT ctxt [TFree v]; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
698 |
val _ = Context_Position.if_visible ctxt Output.report sorting_report; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
699 |
in a end; |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
700 |
|
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
701 |
end; |
| 36152 | 702 |
|
| 5819 | 703 |
|
704 |
(* certify terms *) |
|
705 |
||
| 10554 | 706 |
local |
707 |
||
| 24684 | 708 |
fun gen_cert prop ctxt t = |
709 |
t |
|
710 |
|> expand_abbrevs ctxt |
|
|
42383
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
711 |
|> (fn t' => |
|
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
712 |
#1 (Sign.certify' prop (Context.pretty ctxt) false (consts_of ctxt) (theory_of ctxt) t') |
|
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
713 |
handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg); |
| 16501 | 714 |
|
| 10554 | 715 |
in |
| 8096 | 716 |
|
| 24684 | 717 |
val cert_term = gen_cert false; |
718 |
val cert_prop = gen_cert true; |
|
| 10554 | 719 |
|
720 |
end; |
|
| 5819 | 721 |
|
722 |
||
|
42405
13ecdb3057d8
split Type_Infer into early and late part, after Proof_Context;
wenzelm
parents:
42402
diff
changeset
|
723 |
(* check/uncheck *) |
| 22701 | 724 |
|
|
35616
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
725 |
fun def_type ctxt = |
|
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
726 |
let val Mode {pattern, ...} = get_mode ctxt
|
|
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
727 |
in Variable.def_type ctxt pattern end; |
|
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
728 |
|
| 24518 | 729 |
fun standard_typ_check ctxt = |
| 45429 | 730 |
map (cert_typ_mode (Type.get_mode ctxt) ctxt #> prepare_patternT ctxt); |
| 24922 | 731 |
|
| 45429 | 732 |
val standard_term_check_finish = prepare_patterns; |
| 24518 | 733 |
|
| 45429 | 734 |
fun standard_term_uncheck ctxt = map (contract_abbrevs ctxt); |
| 22701 | 735 |
|
736 |
||
| 9553 | 737 |
|
| 21610 | 738 |
(** export results **) |
| 21531 | 739 |
|
| 20310 | 740 |
fun common_export is_goal inner outer = |
741 |
map (Assumption.export is_goal inner outer) #> |
|
742 |
Variable.export inner outer; |
|
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
743 |
|
| 20310 | 744 |
val goal_export = common_export true; |
745 |
val export = common_export false; |
|
| 12704 | 746 |
|
| 21531 | 747 |
fun export_morphism inner outer = |
748 |
Assumption.export_morphism inner outer $> |
|
749 |
Variable.export_morphism inner outer; |
|
750 |
||
| 28396 | 751 |
fun norm_export_morphism inner outer = |
752 |
export_morphism inner outer $> |
|
753 |
Morphism.thm_morphism Goal.norm_result; |
|
754 |
||
| 21531 | 755 |
|
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
756 |
|
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
757 |
(** term bindings **) |
| 5819 | 758 |
|
| 8096 | 759 |
(* simult_matches *) |
760 |
||
| 19867 | 761 |
fun simult_matches ctxt (t, pats) = |
762 |
(case Seq.pull (Unify.matchers (theory_of ctxt) (map (rpair t) pats)) of |
|
763 |
NONE => error "Pattern match failed!" |
|
| 32032 | 764 |
| SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
| 8096 | 765 |
|
766 |
||
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
767 |
(* bind_terms *) |
| 7925 | 768 |
|
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
769 |
val bind_terms = fold (fn (xi, t) => fn ctxt => |
|
24511
69d270cc7e4f
removed obsolete read/cert variations (cf. Syntax.read/check);
wenzelm
parents:
24505
diff
changeset
|
770 |
ctxt |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
771 |
|> Variable.bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t)); |
| 5819 | 772 |
|
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
773 |
|
|
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
774 |
(* auto_bind *) |
| 10810 | 775 |
|
| 20330 | 776 |
fun drop_schematic (b as (xi, SOME t)) = if Term.exists_subterm is_Var t then (xi, NONE) else b |
| 10554 | 777 |
| drop_schematic b = b; |
778 |
||
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
779 |
fun auto_bind f ts ctxt = ctxt |> bind_terms (map drop_schematic (f (theory_of ctxt) ts)); |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
780 |
|
| 33386 | 781 |
val auto_bind_goal = auto_bind Auto_Bind.goal; |
782 |
val auto_bind_facts = auto_bind Auto_Bind.facts; |
|
| 7925 | 783 |
|
| 5819 | 784 |
|
| 8096 | 785 |
(* match_bind(_i) *) |
| 5819 | 786 |
|
| 8096 | 787 |
local |
788 |
||
| 24684 | 789 |
fun gen_bind prep_terms gen raw_binds ctxt = |
| 5819 | 790 |
let |
| 24684 | 791 |
fun prep_bind (raw_pats, t) ctxt1 = |
792 |
let |
|
793 |
val T = Term.fastype_of t; |
|
794 |
val ctxt2 = Variable.declare_term t ctxt1; |
|
795 |
val pats = prep_terms (set_mode mode_pattern ctxt2) T raw_pats; |
|
796 |
val binds = simult_matches ctxt2 (t, pats); |
|
797 |
in (binds, ctxt2) end; |
|
| 7670 | 798 |
|
| 24686 | 799 |
val ts = prep_terms ctxt dummyT (map snd raw_binds); |
800 |
val (binds, ctxt') = apfst flat (fold_map prep_bind (map fst raw_binds ~~ ts) ctxt); |
|
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
801 |
val binds' = |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
802 |
if gen then map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
803 |
else binds; |
| 15531 | 804 |
val binds'' = map (apsnd SOME) binds'; |
| 18310 | 805 |
val ctxt'' = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
806 |
tap (Variable.warn_extra_tfrees ctxt) |
| 18310 | 807 |
(if gen then |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
808 |
ctxt (*sic!*) |> fold Variable.declare_term (map #2 binds') |> bind_terms binds'' |
|
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
809 |
else ctxt' |> bind_terms binds''); |
| 18310 | 810 |
in (ts, ctxt'') end; |
| 8096 | 811 |
|
812 |
in |
|
| 5935 | 813 |
|
| 24684 | 814 |
fun read_terms ctxt T = |
| 39288 | 815 |
map (Syntax.parse_term ctxt #> Type.constraint T) #> Syntax.check_terms ctxt; |
| 24684 | 816 |
|
817 |
val match_bind = gen_bind read_terms; |
|
818 |
val match_bind_i = gen_bind (fn ctxt => fn _ => map (cert_term ctxt)); |
|
| 8096 | 819 |
|
820 |
end; |
|
| 5935 | 821 |
|
822 |
||
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
823 |
(* propositions with patterns *) |
| 5935 | 824 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
825 |
local |
| 8096 | 826 |
|
| 45327 | 827 |
fun prep_propp mode prep_props args context = |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
828 |
let |
| 19585 | 829 |
fun prep (_, raw_pats) (ctxt, prop :: props) = |
| 24684 | 830 |
let val ctxt' = Variable.declare_term prop ctxt |
831 |
in ((prop, prep_props (set_mode mode_pattern ctxt') raw_pats), (ctxt', props)) end; |
|
832 |
||
| 45327 | 833 |
val (propp, (context', _)) = |
834 |
(fold_map o fold_map) prep args |
|
835 |
(context, prep_props (set_mode mode context) (maps (map fst) args)); |
|
836 |
in (propp, context') end; |
|
| 5935 | 837 |
|
| 45327 | 838 |
fun gen_bind_propp mode parse_prop raw_args ctxt = |
| 8096 | 839 |
let |
| 45327 | 840 |
val (args, ctxt') = prep_propp mode parse_prop raw_args ctxt; |
| 19585 | 841 |
val binds = flat (flat (map (map (simult_matches ctxt')) args)); |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
842 |
val propss = map (map #1) args; |
|
45330
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
843 |
fun gen_binds ctxt0 = ctxt0 |
|
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
844 |
|> bind_terms (map #1 binds ~~ |
|
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
845 |
map (SOME o Term.close_schematic_term) (Variable.export_terms ctxt' ctxt0 (map #2 binds))); |
| 45327 | 846 |
in ((propss, gen_binds), ctxt' |> bind_terms (map (apsnd SOME) binds)) end; |
| 8096 | 847 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
848 |
in |
|
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
849 |
|
| 24684 | 850 |
val read_propp = prep_propp mode_default Syntax.read_props; |
851 |
val cert_propp = prep_propp mode_default (map o cert_prop); |
|
852 |
val read_propp_schematic = prep_propp mode_schematic Syntax.read_props; |
|
853 |
val cert_propp_schematic = prep_propp mode_schematic (map o cert_prop); |
|
| 10554 | 854 |
|
| 24684 | 855 |
val bind_propp = gen_bind_propp mode_default Syntax.read_props; |
856 |
val bind_propp_i = gen_bind_propp mode_default (map o cert_prop); |
|
857 |
val bind_propp_schematic = gen_bind_propp mode_schematic Syntax.read_props; |
|
858 |
val bind_propp_schematic_i = gen_bind_propp mode_schematic (map o cert_prop); |
|
| 6789 | 859 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
860 |
end; |
|
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
861 |
|
| 6789 | 862 |
|
| 5819 | 863 |
|
864 |
(** theorems **) |
|
865 |
||
| 18042 | 866 |
(* fact_tac *) |
867 |
||
| 27867 | 868 |
fun comp_incr_tac [] _ = no_tac |
869 |
| comp_incr_tac (th :: ths) i = |
|
870 |
(fn st => Goal.compose_hhf_tac (Drule.incr_indexes st th) i st) APPEND comp_incr_tac ths i; |
|
| 18042 | 871 |
|
| 21687 | 872 |
fun fact_tac facts = Goal.norm_hhf_tac THEN' comp_incr_tac facts; |
| 18122 | 873 |
|
| 27867 | 874 |
fun potential_facts ctxt prop = |
875 |
Facts.could_unify (facts_of ctxt) (Term.strip_all_body prop); |
|
876 |
||
877 |
fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) => fact_tac (potential_facts ctxt goal) i); |
|
| 18042 | 878 |
|
879 |
||
| 6091 | 880 |
(* get_thm(s) *) |
| 5819 | 881 |
|
| 26361 | 882 |
local |
883 |
||
| 26687 | 884 |
fun retrieve_thms pick ctxt (Facts.Fact s) = |
| 16501 | 885 |
let |
| 46849 | 886 |
val pos = Syntax.read_token_pos s; |
| 42502 | 887 |
val prop = |
888 |
Syntax.read_prop (ctxt |> set_mode mode_default |> allow_dummies) s |
|
|
24511
69d270cc7e4f
removed obsolete read/cert variations (cf. Syntax.read/check);
wenzelm
parents:
24505
diff
changeset
|
889 |
|> singleton (Variable.polymorphic ctxt); |
| 48992 | 890 |
fun err msg = error (msg ^ Position.here pos ^ ":\n" ^ Syntax.string_of_term ctxt prop); |
| 27867 | 891 |
|
| 42502 | 892 |
val (prop', _) = Term.replace_dummy_patterns prop (Variable.maxidx_of ctxt + 1); |
| 27867 | 893 |
fun prove_fact th = |
| 42502 | 894 |
Goal.prove ctxt [] [] prop' (K (ALLGOALS (fact_tac [th]))); |
895 |
val results = map_filter (try prove_fact) (potential_facts ctxt prop'); |
|
| 27867 | 896 |
val res = |
| 42502 | 897 |
(case distinct Thm.eq_thm_prop results of |
898 |
[res] => res |
|
899 |
| [] => err "Failed to retrieve literal fact" |
|
900 |
| _ => err "Ambiguous specification of literal fact"); |
|
| 27867 | 901 |
in pick "" [res] end |
| 26687 | 902 |
| retrieve_thms pick ctxt xthmref = |
| 18042 | 903 |
let |
904 |
val thy = theory_of ctxt; |
|
| 26284 | 905 |
val local_facts = facts_of ctxt; |
| 26673 | 906 |
val thmref = Facts.map_name_of_ref (Facts.intern local_facts) xthmref; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26321
diff
changeset
|
907 |
val name = Facts.name_of_ref thmref; |
| 27821 | 908 |
val pos = Facts.pos_of_ref xthmref; |
| 24012 | 909 |
val thms = |
910 |
if name = "" then [Thm.transfer thy Drule.dummy_thm] |
|
911 |
else |
|
| 26393 | 912 |
(case Facts.lookup (Context.Proof ctxt) local_facts name of |
|
39507
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39441
diff
changeset
|
913 |
SOME (_, ths) => |
| 42378 | 914 |
(Context_Position.report ctxt pos |
| 42379 | 915 |
(Name_Space.markup (Facts.space_of local_facts) name); |
| 42378 | 916 |
map (Thm.transfer thy) (Facts.select thmref ths)) |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
917 |
| NONE => Global_Theory.get_fact (Context.Proof ctxt) thy xthmref); |
| 24012 | 918 |
in pick name thms end; |
| 5819 | 919 |
|
| 26361 | 920 |
in |
|
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
921 |
|
| 26687 | 922 |
val get_fact = retrieve_thms (K I); |
923 |
val get_fact_single = retrieve_thms Facts.the_single; |
|
|
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
924 |
|
| 26361 | 925 |
fun get_thms ctxt = get_fact ctxt o Facts.named; |
926 |
fun get_thm ctxt = get_fact_single ctxt o Facts.named; |
|
927 |
||
928 |
end; |
|
| 5819 | 929 |
|
930 |
||
| 26284 | 931 |
(* facts *) |
| 5819 | 932 |
|
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
933 |
local |
|
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
934 |
|
| 28965 | 935 |
fun update_thms _ (b, NONE) ctxt = ctxt |> map_facts (Facts.del (full_name ctxt b)) |
| 49747 | 936 |
| update_thms flags (b, SOME ths) ctxt = ctxt |> map_facts |
937 |
(Facts.add_static (Context.Proof ctxt) flags (b, ths) #> snd); |
|
| 5819 | 938 |
|
|
30761
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
939 |
in |
|
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
940 |
|
|
46775
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
941 |
fun note_thmss kind = fold_map (fn ((b, more_atts), raw_facts) => fn ctxt => |
| 5819 | 942 |
let |
| 28965 | 943 |
val name = full_name ctxt b; |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
944 |
val facts = Global_Theory.name_thmss false name raw_facts; |
|
46775
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
945 |
fun app (ths, atts) = |
|
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
946 |
fold_map (Thm.proof_attributes (surround (Thm.kind kind) (atts @ more_atts))) ths; |
|
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
947 |
val (res, ctxt') = fold_map app facts ctxt; |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
948 |
val thms = Global_Theory.name_thms false false name (flat res); |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
949 |
val Mode {stmt, ...} = get_mode ctxt;
|
| 49747 | 950 |
in ((name, thms), ctxt' |> update_thms {strict = false, index = stmt} (b, SOME thms)) end);
|
| 12711 | 951 |
|
| 49747 | 952 |
fun put_thms index thms ctxt = ctxt |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
953 |
|> map_naming (K Name_Space.local_naming) |
| 33383 | 954 |
|> Context_Position.set_visible false |
| 49747 | 955 |
|> update_thms {strict = false, index = index} (apfst Binding.name thms)
|
| 33383 | 956 |
|> Context_Position.restore_visible ctxt |
| 28417 | 957 |
|> restore_naming ctxt; |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
958 |
|
| 12711 | 959 |
end; |
| 9196 | 960 |
|
| 5819 | 961 |
|
962 |
||
| 35680 | 963 |
(** basic logical entities **) |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
964 |
|
| 8096 | 965 |
(* variables *) |
966 |
||
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
967 |
fun declare_var (x, opt_T, mx) ctxt = |
|
42287
d98eb048a2e4
discontinued special treatment of structure Mixfix;
wenzelm
parents:
42267
diff
changeset
|
968 |
let val T = (case opt_T of SOME T => T | NONE => Mixfix.mixfixT mx) |
| 20163 | 969 |
in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end; |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
970 |
|
| 10381 | 971 |
local |
972 |
||
|
25353
17f04d987f37
removed unused read_termTs_schematic, read/cert_vars_legacy, add_fixes_legacy;
wenzelm
parents:
25345
diff
changeset
|
973 |
fun prep_vars prep_typ internal = |
| 35129 | 974 |
fold_map (fn (b, raw_T, mx) => fn ctxt => |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
975 |
let |
| 42494 | 976 |
val x = Variable.check_name b; |
| 50239 | 977 |
val _ = Symbol_Pos.is_identifier (no_skolem internal x) orelse |
|
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42379
diff
changeset
|
978 |
error ("Illegal variable name: " ^ Binding.print b);
|
| 12504 | 979 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
980 |
fun cond_tvars T = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
981 |
if internal then T |
| 18678 | 982 |
else Type.no_tvars T handle TYPE (msg, _, _) => error msg; |
| 24277 | 983 |
val opt_T = Option.map (cond_tvars o cert_typ ctxt o prep_typ ctxt) raw_T; |
| 35129 | 984 |
val (_, ctxt') = ctxt |> declare_var (x, opt_T, mx); |
985 |
in ((b, opt_T, mx), ctxt') end); |
|
| 8096 | 986 |
|
| 10381 | 987 |
in |
988 |
||
|
45427
fca432074fb2
sort assignment before simultaneous term_check, not isolated parse_term;
wenzelm
parents:
45330
diff
changeset
|
989 |
val read_vars = prep_vars Syntax.read_typ false; |
|
25353
17f04d987f37
removed unused read_termTs_schematic, read/cert_vars_legacy, add_fixes_legacy;
wenzelm
parents:
25345
diff
changeset
|
990 |
val cert_vars = prep_vars (K I) true; |
| 8096 | 991 |
|
| 10381 | 992 |
end; |
993 |
||
| 8096 | 994 |
|
| 21744 | 995 |
(* notation *) |
996 |
||
| 24949 | 997 |
local |
998 |
||
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
999 |
fun type_syntax (Type (c, args), mx) = |
|
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
42287
diff
changeset
|
1000 |
SOME (Local_Syntax.Type, (Lexicon.mark_type c, Mixfix.make_type (length args), mx)) |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1001 |
| type_syntax _ = NONE; |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1002 |
|
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1003 |
fun const_syntax _ (Free (x, T), mx) = SOME (Local_Syntax.Fixed, (x, T, mx)) |
| 24949 | 1004 |
| const_syntax ctxt (Const (c, _), mx) = |
| 35255 | 1005 |
(case try (Consts.type_scheme (consts_of ctxt)) c of |
|
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
42287
diff
changeset
|
1006 |
SOME T => SOME (Local_Syntax.Const, (Lexicon.mark_const c, T, mx)) |
| 35255 | 1007 |
| NONE => NONE) |
| 24949 | 1008 |
| const_syntax _ _ = NONE; |
1009 |
||
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1010 |
fun gen_notation syntax add mode args ctxt = |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1011 |
ctxt |> map_syntax |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1012 |
(Local_Syntax.update_modesyntax (theory_of ctxt) add mode (map_filter (syntax ctxt) args)); |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1013 |
|
| 24949 | 1014 |
in |
| 21744 | 1015 |
|
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1016 |
val type_notation = gen_notation (K type_syntax); |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1017 |
val notation = gen_notation const_syntax; |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1018 |
|
| 47247 | 1019 |
fun generic_type_notation add mode args phi = |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1020 |
let |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1021 |
val args' = args |> map_filter (fn (T, mx) => |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1022 |
let |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1023 |
val T' = Morphism.typ phi T; |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1024 |
val similar = (case (T, T') of (Type (c, _), Type (c', _)) => c = c' | _ => false); |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1025 |
in if similar then SOME (T', mx) else NONE end); |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1026 |
in Context.mapping (Sign.type_notation add mode args') (type_notation add mode args') end; |
| 24949 | 1027 |
|
| 47247 | 1028 |
fun generic_notation add mode args phi = |
|
33537
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1029 |
let |
|
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1030 |
val args' = args |> map_filter (fn (t, mx) => |
|
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1031 |
let val t' = Morphism.term phi t |
|
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1032 |
in if Term.aconv_untyped (t, t') then SOME (t', mx) else NONE end); |
| 24949 | 1033 |
in Context.mapping (Sign.notation add mode args') (notation add mode args') end; |
1034 |
||
| 35680 | 1035 |
end; |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1036 |
|
| 35680 | 1037 |
|
1038 |
(* aliases *) |
|
1039 |
||
| 36450 | 1040 |
fun class_alias b c ctxt = (map_tsig o apfst) (Type.class_alias (naming_of ctxt) b c) ctxt; |
1041 |
fun type_alias b c ctxt = (map_tsig o apfst) (Type.type_alias (naming_of ctxt) b c) ctxt; |
|
| 35680 | 1042 |
fun const_alias b c ctxt = (map_consts o apfst) (Consts.alias (naming_of ctxt) b c) ctxt; |
| 21744 | 1043 |
|
1044 |
||
| 24767 | 1045 |
(* local constants *) |
1046 |
||
1047 |
fun add_const_constraint (c, opt_T) ctxt = |
|
1048 |
let |
|
1049 |
fun prepT raw_T = |
|
1050 |
let val T = cert_typ ctxt raw_T |
|
1051 |
in cert_term ctxt (Const (c, T)); T end; |
|
| 25039 | 1052 |
in ctxt |> (map_consts o apfst) (Consts.constrain (c, Option.map prepT opt_T)) end; |
| 19001 | 1053 |
|
|
33173
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents:
33165
diff
changeset
|
1054 |
fun add_abbrev mode (b, raw_t) ctxt = |
| 19001 | 1055 |
let |
|
24675
2be1253a20d3
removed obsolete set_expand_abbrevs (superceded by mode_abbrev);
wenzelm
parents:
24612
diff
changeset
|
1056 |
val t0 = cert_term (ctxt |> set_mode mode_abbrev) raw_t |
|
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42379
diff
changeset
|
1057 |
handle ERROR msg => cat_error msg ("in constant abbreviation " ^ Binding.print b);
|
|
20008
8d9d770e1f06
add_abbrevs/polymorphic: Variable.exportT_terms avoids over-generalization;
wenzelm
parents:
19916
diff
changeset
|
1058 |
val [t] = Variable.exportT_terms (Variable.declare_term t0 ctxt) ctxt [t0]; |
|
21807
a59f083632a7
add_abbrev: removed Assumption.add_assms (danger of inconsistent naming);
wenzelm
parents:
21803
diff
changeset
|
1059 |
val ((lhs, rhs), consts') = consts_of ctxt |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
1060 |
|> Consts.abbreviate (Context.Proof ctxt) (tsig_of ctxt) mode (b, t); |
| 19001 | 1061 |
in |
1062 |
ctxt |
|
| 25039 | 1063 |
|> (map_consts o apfst) (K consts') |
| 21803 | 1064 |
|> Variable.declare_term rhs |
1065 |
|> pair (lhs, rhs) |
|
| 21704 | 1066 |
end; |
| 19001 | 1067 |
|
| 25052 | 1068 |
fun revert_abbrev mode c = (map_consts o apfst) (Consts.revert_abbrev mode c); |
1069 |
||
| 47275 | 1070 |
fun generic_add_abbrev mode arg = |
1071 |
Context.mapping_result (Sign.add_abbrev mode arg) (add_abbrev mode arg); |
|
1072 |
||
1073 |
fun generic_revert_abbrev mode arg = |
|
1074 |
Context.mapping (Sign.revert_abbrev mode arg) (revert_abbrev mode arg); |
|
1075 |
||
| 19001 | 1076 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1077 |
(* fixes *) |
| 5819 | 1078 |
|
|
30763
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
1079 |
fun add_fixes raw_vars ctxt = |
| 8096 | 1080 |
let |
|
42491
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1081 |
val thy = theory_of ctxt; |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1082 |
val vars = #1 (cert_vars raw_vars ctxt); |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1083 |
in |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1084 |
ctxt |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1085 |
|> Variable.add_fixes_binding (map #1 vars) |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1086 |
|-> (fn xs => |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1087 |
fold_map declare_var (map2 (fn x => fn (_, T, mx) => (x, T, mx)) xs vars) |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1088 |
#-> (map_syntax o Local_Syntax.add_syntax thy o map (pair Local_Syntax.Fixed)) |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1089 |
#> pair xs) |
|
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1090 |
end; |
| 5819 | 1091 |
|
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1092 |
|
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1093 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1094 |
(** assumptions **) |
| 18187 | 1095 |
|
| 20209 | 1096 |
local |
1097 |
||
1098 |
fun gen_assms prepp exp args ctxt = |
|
1099 |
let |
|
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1100 |
val cert = Thm.cterm_of (theory_of ctxt); |
| 45327 | 1101 |
val ((propss, _), ctxt1) = prepp (map snd args) ctxt; |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1102 |
val _ = Variable.warn_extra_tfrees ctxt ctxt1; |
|
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1103 |
val (premss, ctxt2) = fold_burrow (Assumption.add_assms exp o map cert) propss ctxt1; |
|
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1104 |
in |
|
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1105 |
ctxt2 |
|
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1106 |
|> auto_bind_facts (flat propss) |
|
33644
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents:
33537
diff
changeset
|
1107 |
|> note_thmss "" (map fst args ~~ map (map (fn th => ([th], []))) premss) |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1108 |
end; |
| 20209 | 1109 |
|
1110 |
in |
|
1111 |
||
| 45327 | 1112 |
val add_assms = gen_assms bind_propp; |
1113 |
val add_assms_i = gen_assms bind_propp_i; |
|
| 20209 | 1114 |
|
1115 |
end; |
|
1116 |
||
1117 |
||
| 5819 | 1118 |
|
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1119 |
(** cases **) |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1120 |
|
| 16147 | 1121 |
local |
1122 |
||
| 16668 | 1123 |
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name; |
| 16147 | 1124 |
|
| 18476 | 1125 |
fun add_case _ ("", _) cases = cases
|
1126 |
| add_case _ (name, NONE) cases = rem_case name cases |
|
1127 |
| add_case is_proper (name, SOME c) cases = (name, (c, is_proper)) :: rem_case name cases; |
|
| 16147 | 1128 |
|
| 18678 | 1129 |
fun prep_case name fxs c = |
| 18609 | 1130 |
let |
1131 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys |
|
1132 |
| replace [] ys = ys |
|
| 18678 | 1133 |
| replace (_ :: _) [] = error ("Too many parameters for case " ^ quote name);
|
| 33368 | 1134 |
val Rule_Cases.Case {fixes, assumes, binds, cases} = c;
|
| 18609 | 1135 |
val fixes' = replace fxs fixes; |
1136 |
val binds' = map drop_schematic binds; |
|
1137 |
in |
|
1138 |
if null (fold (Term.add_tvarsT o snd) fixes []) andalso |
|
1139 |
null (fold (fold Term.add_vars o snd) assumes []) then |
|
| 33368 | 1140 |
Rule_Cases.Case {fixes = fixes', assumes = assumes, binds = binds', cases = cases}
|
| 18678 | 1141 |
else error ("Illegal schematic variable(s) in case " ^ quote name)
|
| 18609 | 1142 |
end; |
1143 |
||
|
42501
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1144 |
fun fix (b, T) ctxt = |
|
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1145 |
let val ([x], ctxt') = add_fixes [(b, SOME T, NoSyn)] ctxt |
|
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1146 |
in (Free (x, T), ctxt') end; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1147 |
|
| 16147 | 1148 |
in |
1149 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1150 |
fun add_cases is_proper = map_cases o fold (add_case is_proper); |
| 18609 | 1151 |
|
1152 |
fun case_result c ctxt = |
|
1153 |
let |
|
| 33368 | 1154 |
val Rule_Cases.Case {fixes, ...} = c;
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1155 |
val (ts, ctxt') = ctxt |> fold_map fix fixes; |
| 33368 | 1156 |
val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c;
|
| 18609 | 1157 |
in |
1158 |
ctxt' |
|
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
1159 |
|> bind_terms (map drop_schematic binds) |
| 18609 | 1160 |
|> add_cases true (map (apsnd SOME) cases) |
1161 |
|> pair (assumes, (binds, cases)) |
|
1162 |
end; |
|
1163 |
||
1164 |
val apply_case = apfst fst oo case_result; |
|
1165 |
||
| 16540 | 1166 |
fun get_case ctxt name xs = |
| 17184 | 1167 |
(case AList.lookup (op =) (cases_of ctxt) name of |
| 18678 | 1168 |
NONE => error ("Unknown case: " ^ quote name)
|
1169 |
| SOME (c, _) => prep_case name xs c); |
|
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1170 |
|
| 16147 | 1171 |
end; |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1172 |
|
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1173 |
|
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1174 |
|
| 10810 | 1175 |
(** print context information **) |
1176 |
||
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1177 |
(* local syntax *) |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1178 |
|
| 12093 | 1179 |
val print_syntax = Syntax.print_syntax o syn_of; |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1180 |
|
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1181 |
|
| 21728 | 1182 |
(* abbreviations *) |
| 18971 | 1183 |
|
| 21728 | 1184 |
fun pretty_abbrevs show_globals ctxt = |
| 18971 | 1185 |
let |
| 25052 | 1186 |
val ((space, consts), (_, globals)) = |
| 45650 | 1187 |
pairself (#constants o Consts.dest) (#consts (rep_data ctxt)); |
| 21803 | 1188 |
fun add_abbr (_, (_, NONE)) = I |
| 25406 | 1189 |
| add_abbr (c, (T, SOME t)) = |
| 21728 | 1190 |
if not show_globals andalso Symtab.defined globals c then I |
1191 |
else cons (c, Logic.mk_equals (Const (c, T), t)); |
|
|
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42357
diff
changeset
|
1192 |
val abbrevs = |
|
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42357
diff
changeset
|
1193 |
Name_Space.extern_table ctxt (space, Symtab.make (Symtab.fold add_abbr consts [])); |
| 18971 | 1194 |
in |
| 35141 | 1195 |
if null abbrevs then [] |
| 21728 | 1196 |
else [Pretty.big_list "abbreviations:" (map (pretty_term_abbrev ctxt o #2) abbrevs)] |
| 18971 | 1197 |
end; |
1198 |
||
| 21728 | 1199 |
val print_abbrevs = Pretty.writeln o Pretty.chunks o pretty_abbrevs true; |
1200 |
||
| 18971 | 1201 |
|
| 10810 | 1202 |
(* term bindings *) |
1203 |
||
| 16540 | 1204 |
fun pretty_binds ctxt = |
| 10810 | 1205 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1206 |
val binds = Variable.binds_of ctxt; |
| 21728 | 1207 |
fun prt_bind (xi, (T, t)) = pretty_term_abbrev ctxt (Logic.mk_equals (Var (xi, T), t)); |
| 10810 | 1208 |
in |
| 35141 | 1209 |
if Vartab.is_empty binds then [] |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1210 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
| 10810 | 1211 |
end; |
1212 |
||
1213 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1214 |
||
1215 |
||
1216 |
(* local theorems *) |
|
1217 |
||
| 16540 | 1218 |
fun pretty_lthms ctxt = |
| 20012 | 1219 |
let |
| 26284 | 1220 |
val local_facts = facts_of ctxt; |
1221 |
val props = Facts.props local_facts; |
|
| 26673 | 1222 |
val facts = |
| 35141 | 1223 |
(if null props then [] else [("<unnamed>", props)]) @
|
| 28212 | 1224 |
Facts.dest_static [] local_facts; |
| 20012 | 1225 |
in |
| 35141 | 1226 |
if null facts then [] |
| 28212 | 1227 |
else [Pretty.big_list "facts:" (map #1 (sort_wrt (#1 o #2) (map (`(pretty_fact ctxt)) facts)))] |
| 20012 | 1228 |
end; |
| 10810 | 1229 |
|
| 12057 | 1230 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
| 10810 | 1231 |
|
1232 |
||
1233 |
(* local contexts *) |
|
1234 |
||
| 26722 | 1235 |
local |
1236 |
||
1237 |
fun pretty_case (name, (fixes, ((asms, (lets, cs)), ctxt))) = |
|
| 10810 | 1238 |
let |
| 24922 | 1239 |
val prt_term = Syntax.pretty_term ctxt; |
| 12057 | 1240 |
|
| 10810 | 1241 |
fun prt_let (xi, t) = Pretty.block |
| 10818 | 1242 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
| 10810 | 1243 |
Pretty.quote (prt_term t)]; |
1244 |
||
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1245 |
fun prt_asm (a, ts) = Pretty.block (Pretty.breaks |
|
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1246 |
((if a = "" then [] else [Pretty.str (a ^ ":")]) @ map (Pretty.quote o prt_term) ts)); |
|
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1247 |
|
| 10810 | 1248 |
fun prt_sect _ _ _ [] = [] |
| 35141 | 1249 |
| prt_sect s sep prt xs = |
1250 |
[Pretty.block (Pretty.breaks (Pretty.str s :: |
|
1251 |
flat (separate sep (map (single o prt) xs))))]; |
|
| 26722 | 1252 |
in |
1253 |
Pretty.block (Pretty.fbreaks |
|
| 10810 | 1254 |
(Pretty.str (name ^ ":") :: |
| 42496 | 1255 |
prt_sect "fix" [] (Pretty.str o Binding.name_of o fst) fixes @ |
| 10810 | 1256 |
prt_sect "let" [Pretty.str "and"] prt_let |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
1257 |
(map_filter (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @ |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1258 |
(if forall (null o #2) asms then [] |
| 18609 | 1259 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms) @ |
| 26722 | 1260 |
prt_sect "subcases:" [] (Pretty.str o fst) cs)) |
1261 |
end; |
|
| 16540 | 1262 |
|
| 26722 | 1263 |
in |
1264 |
||
1265 |
fun pretty_cases ctxt = |
|
1266 |
let |
|
| 18476 | 1267 |
fun add_case (_, (_, false)) = I |
| 33368 | 1268 |
| add_case (name, (c as Rule_Cases.Case {fixes, ...}, true)) =
|
| 26722 | 1269 |
cons (name, (fixes, case_result c ctxt)); |
| 18476 | 1270 |
val cases = fold add_case (cases_of ctxt) []; |
| 10810 | 1271 |
in |
| 35141 | 1272 |
if null cases then [] |
| 26722 | 1273 |
else [Pretty.big_list "cases:" (map pretty_case cases)] |
| 10810 | 1274 |
end; |
1275 |
||
1276 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1277 |
||
| 26722 | 1278 |
end; |
1279 |
||
| 10810 | 1280 |
|
| 12057 | 1281 |
(* core context *) |
| 10810 | 1282 |
|
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1283 |
val debug = Config.bool (Config.declare "Proof_Context.debug" (K (Config.Bool false))); |
|
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1284 |
val verbose = Config.bool (Config.declare "Proof_Context.verbose" (K (Config.Bool false))); |
| 10810 | 1285 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1286 |
fun pretty_ctxt ctxt = |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1287 |
if not (Config.get ctxt debug) then [] |
| 20310 | 1288 |
else |
1289 |
let |
|
| 24922 | 1290 |
val prt_term = Syntax.pretty_term ctxt; |
| 12057 | 1291 |
|
| 20310 | 1292 |
(*structures*) |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
1293 |
val {structs, ...} = Local_Syntax.idents_of (syntax_of ctxt);
|
| 35139 | 1294 |
val prt_structs = |
1295 |
if null structs then [] |
|
| 20310 | 1296 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
1297 |
Pretty.commas (map Pretty.str structs))]; |
|
| 12093 | 1298 |
|
| 20310 | 1299 |
(*fixes*) |
1300 |
fun prt_fix (x, x') = |
|
1301 |
if x = x' then Pretty.str x |
|
1302 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
1303 |
val fixes = |
|
|
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
1304 |
filter_out ((can Name.dest_internal orf member (op =) structs) o #1) |
|
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
1305 |
(Variable.dest_fixes ctxt); |
| 35139 | 1306 |
val prt_fixes = |
1307 |
if null fixes then [] |
|
| 20310 | 1308 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
1309 |
Pretty.commas (map prt_fix fixes))]; |
|
| 12057 | 1310 |
|
| 20310 | 1311 |
(*prems*) |
|
30473
e0b66c11e7e4
Assumption.all_prems_of, Assumption.all_assms_of;
wenzelm
parents:
30469
diff
changeset
|
1312 |
val prems = Assumption.all_prems_of ctxt; |
| 35139 | 1313 |
val prt_prems = |
1314 |
if null prems then [] |
|
| 39165 | 1315 |
else [Pretty.big_list "prems:" (map (Display.pretty_thm ctxt) prems)]; |
| 20310 | 1316 |
in prt_structs @ prt_fixes @ prt_prems end; |
| 10810 | 1317 |
|
1318 |
||
1319 |
(* main context *) |
|
1320 |
||
| 16540 | 1321 |
fun pretty_context ctxt = |
| 10810 | 1322 |
let |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1323 |
val verbose = Config.get ctxt verbose; |
|
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1324 |
fun verb f x = if verbose then f (x ()) else []; |
| 35141 | 1325 |
|
| 24922 | 1326 |
val prt_term = Syntax.pretty_term ctxt; |
1327 |
val prt_typ = Syntax.pretty_typ ctxt; |
|
1328 |
val prt_sort = Syntax.pretty_sort ctxt; |
|
| 10810 | 1329 |
|
1330 |
(*theory*) |
|
| 12057 | 1331 |
val pretty_thy = Pretty.block |
| 17384 | 1332 |
[Pretty.str "theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
| 10810 | 1333 |
|
1334 |
(*defaults*) |
|
1335 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1336 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1337 |
||
1338 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1339 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1340 |
||
1341 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1342 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1343 |
||
1344 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1345 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
| 16540 | 1346 |
|
| 20163 | 1347 |
val (types, sorts) = Variable.constraints_of ctxt; |
| 10810 | 1348 |
in |
| 18609 | 1349 |
verb single (K pretty_thy) @ |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1350 |
pretty_ctxt ctxt @ |
| 21728 | 1351 |
verb (pretty_abbrevs false) (K ctxt) @ |
| 10810 | 1352 |
verb pretty_binds (K ctxt) @ |
| 12057 | 1353 |
verb pretty_lthms (K ctxt) @ |
| 10810 | 1354 |
verb pretty_cases (K ctxt) @ |
| 18609 | 1355 |
verb single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
| 20163 | 1356 |
verb single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) |
| 10810 | 1357 |
end; |
1358 |
||
| 5819 | 1359 |
end; |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
1360 |
|
| 42360 | 1361 |
val show_abbrevs = Proof_Context.show_abbrevs; |
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
1362 |