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