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