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