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