src/Pure/variable.ML
changeset 59798 45c89526208f
parent 59796 f05ef8c62e4f
child 59828 0e9baaf0e0bb
equal deleted inserted replaced
59797:f313ca9fbba0 59798:45c89526208f
     4 Fixed type/term variables and polymorphic term abbreviations.
     4 Fixed type/term variables and polymorphic term abbreviations.
     5 *)
     5 *)
     6 
     6 
     7 signature VARIABLE =
     7 signature VARIABLE =
     8 sig
     8 sig
     9   val is_body: Proof.context -> bool
       
    10   val set_body: bool -> Proof.context -> Proof.context
       
    11   val restore_body: Proof.context -> Proof.context -> Proof.context
       
    12   val names_of: Proof.context -> Name.context
     9   val names_of: Proof.context -> Name.context
    13   val binds_of: Proof.context -> (typ * term) Vartab.table
    10   val binds_of: Proof.context -> (typ * term) Vartab.table
    14   val maxidx_of: Proof.context -> int
    11   val maxidx_of: Proof.context -> int
    15   val sorts_of: Proof.context -> sort list
    12   val sorts_of: Proof.context -> sort list
    16   val constraints_of: Proof.context -> typ Vartab.table * sort Vartab.table
    13   val constraints_of: Proof.context -> typ Vartab.table * sort Vartab.table
    32   val lookup_const: Proof.context -> string -> string option
    29   val lookup_const: Proof.context -> string -> string option
    33   val is_const: Proof.context -> string -> bool
    30   val is_const: Proof.context -> string -> bool
    34   val declare_const: string * string -> Proof.context -> Proof.context
    31   val declare_const: string * string -> Proof.context -> Proof.context
    35   val next_bound: string * typ -> Proof.context -> term * Proof.context
    32   val next_bound: string * typ -> Proof.context -> term * Proof.context
    36   val revert_bounds: Proof.context -> term -> term
    33   val revert_bounds: Proof.context -> term -> term
       
    34   val is_body: Proof.context -> bool
       
    35   val set_body: bool -> Proof.context -> Proof.context
       
    36   val restore_body: Proof.context -> Proof.context -> Proof.context
    37   val improper_fixes: Proof.context -> Proof.context
    37   val improper_fixes: Proof.context -> Proof.context
    38   val restore_proper_fixes: Proof.context -> Proof.context -> Proof.context
    38   val restore_proper_fixes: Proof.context -> Proof.context -> Proof.context
    39   val is_improper: Proof.context -> string -> bool
    39   val is_improper: Proof.context -> string -> bool
    40   val is_fixed: Proof.context -> string -> bool
    40   val is_fixed: Proof.context -> string -> bool
    41   val newly_fixed: Proof.context -> Proof.context -> string -> bool
    41   val newly_fixed: Proof.context -> Proof.context -> string -> bool
    88 
    88 
    89 type fixes = (string * bool) Name_Space.table;
    89 type fixes = (string * bool) Name_Space.table;
    90 val empty_fixes: fixes = Name_Space.empty_table Markup.fixedN;
    90 val empty_fixes: fixes = Name_Space.empty_table Markup.fixedN;
    91 
    91 
    92 datatype data = Data of
    92 datatype data = Data of
    93  {is_body: bool,                        (*inner body mode*)
    93  {names: Name.context,                  (*type/term variable names*)
    94   names: Name.context,                  (*type/term variable names*)
       
    95   consts: string Symtab.table,          (*consts within the local scope*)
    94   consts: string Symtab.table,          (*consts within the local scope*)
    96   bounds: int * ((string * typ) * string) list,  (*next index, internal name, type, external name*)
    95   bounds: int * ((string * typ) * string) list,  (*next index, internal name, type, external name*)
    97   fixes: fixes,                         (*term fixes -- global name space, intern ~> extern*)
    96   fixes: fixes,                         (*term fixes -- global name space, intern ~> extern*)
    98   binds: (typ * term) Vartab.table,     (*term bindings*)
    97   binds: (typ * term) Vartab.table,     (*term bindings*)
    99   type_occs: string list Symtab.table,  (*type variables -- possibly within term variables*)
    98   type_occs: string list Symtab.table,  (*type variables -- possibly within term variables*)
   101   sorts: sort Ord_List.T,               (*declared sort occurrences*)
   100   sorts: sort Ord_List.T,               (*declared sort occurrences*)
   102   constraints:
   101   constraints:
   103     typ Vartab.table *                  (*type constraints*)
   102     typ Vartab.table *                  (*type constraints*)
   104     sort Vartab.table};                 (*default sorts*)
   103     sort Vartab.table};                 (*default sorts*)
   105 
   104 
   106 fun make_data
   105 fun make_data (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =
   107     (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =
   106   Data {names = names, consts = consts, bounds = bounds, fixes = fixes, binds = binds,
   108   Data {is_body = is_body, names = names, consts = consts, bounds = bounds, fixes = fixes,
   107     type_occs = type_occs, maxidx = maxidx, sorts = sorts, constraints = constraints};
   109     binds = binds, type_occs = type_occs, maxidx = maxidx, sorts = sorts, constraints = constraints};
       
   110 
   108 
   111 val empty_data =
   109 val empty_data =
   112   make_data (false, Name.context, Symtab.empty, (0, []), empty_fixes, Vartab.empty,
   110   make_data (Name.context, Symtab.empty, (0, []), empty_fixes, Vartab.empty,
   113     Symtab.empty, ~1, [], (Vartab.empty, Vartab.empty));
   111     Symtab.empty, ~1, [], (Vartab.empty, Vartab.empty));
   114 
   112 
   115 structure Data = Proof_Data
   113 structure Data = Proof_Data
   116 (
   114 (
   117   type T = data;
   115   type T = data;
   118   fun init _ = empty_data;
   116   fun init _ = empty_data;
   119 );
   117 );
   120 
   118 
   121 fun map_data f =
   119 fun map_data f =
   122   Data.map (fn
   120   Data.map (fn Data {names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints} =>
   123       Data {is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints} =>
   121     make_data (f (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints)));
   124     make_data
       
   125       (f (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints)));
       
   126 
   122 
   127 fun map_names f =
   123 fun map_names f =
   128   map_data (fn
   124   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   129       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   125     (f names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
   130     (is_body, f names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
       
   131 
   126 
   132 fun map_consts f =
   127 fun map_consts f =
   133   map_data (fn
   128   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   134       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   129     (names, f consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
   135     (is_body, names, f consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
       
   136 
   130 
   137 fun map_bounds f =
   131 fun map_bounds f =
   138   map_data (fn
   132   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   139       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   133     (names, consts, f bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
   140     (is_body, names, consts, f bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
       
   141 
   134 
   142 fun map_fixes f =
   135 fun map_fixes f =
   143   map_data (fn
   136   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   144       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   137     (names, consts, bounds, f fixes, binds, type_occs, maxidx, sorts, constraints));
   145     (is_body, names, consts, bounds, f fixes, binds, type_occs, maxidx, sorts, constraints));
       
   146 
   138 
   147 fun map_binds f =
   139 fun map_binds f =
   148   map_data (fn
   140   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   149       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   141     (names, consts, bounds, fixes, f binds, type_occs, maxidx, sorts, constraints));
   150     (is_body, names, consts, bounds, fixes, f binds, type_occs, maxidx, sorts, constraints));
       
   151 
   142 
   152 fun map_type_occs f =
   143 fun map_type_occs f =
   153   map_data (fn
   144   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   154       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   145     (names, consts, bounds, fixes, binds, f type_occs, maxidx, sorts, constraints));
   155     (is_body, names, consts, bounds, fixes, binds, f type_occs, maxidx, sorts, constraints));
       
   156 
   146 
   157 fun map_maxidx f =
   147 fun map_maxidx f =
   158   map_data (fn
   148   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   159       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   149     (names, consts, bounds, fixes, binds, type_occs, f maxidx, sorts, constraints));
   160     (is_body, names, consts, bounds, fixes, binds, type_occs, f maxidx, sorts, constraints));
       
   161 
   150 
   162 fun map_sorts f =
   151 fun map_sorts f =
   163   map_data (fn
   152   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   164       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   153     (names, consts, bounds, fixes, binds, type_occs, maxidx, f sorts, constraints));
   165     (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, f sorts, constraints));
       
   166 
   154 
   167 fun map_constraints f =
   155 fun map_constraints f =
   168   map_data (fn
   156   map_data (fn (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   169       (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
   157     (names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, f constraints));
   170     (is_body, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, f constraints));
       
   171 
   158 
   172 fun rep_data ctxt = Data.get ctxt |> (fn Data rep => rep);
   159 fun rep_data ctxt = Data.get ctxt |> (fn Data rep => rep);
   173 
       
   174 val is_body = #is_body o rep_data;
       
   175 
       
   176 fun set_body b =
       
   177   map_data (fn (_, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints) =>
       
   178     (b, names, consts, bounds, fixes, binds, type_occs, maxidx, sorts, constraints));
       
   179 
       
   180 fun restore_body ctxt = set_body (is_body ctxt);
       
   181 
   160 
   182 val names_of = #names o rep_data;
   161 val names_of = #names o rep_data;
   183 val fixes_of = #fixes o rep_data;
   162 val fixes_of = #fixes o rep_data;
   184 val fixes_space = Name_Space.space_of_table o fixes_of;
   163 val fixes_space = Name_Space.space_of_table o fixes_of;
   185 val binds_of = #binds o rep_data;
   164 val binds_of = #binds o rep_data;
   336       in Term.subst_atomic (map2 subst bounds xs) t end);
   315       in Term.subst_atomic (map2 subst bounds xs) t end);
   337 
   316 
   338 
   317 
   339 
   318 
   340 (** fixes **)
   319 (** fixes **)
       
   320 
       
   321 (* inner body mode *)
       
   322 
       
   323 val inner_body =
       
   324   Config.bool (Config.declare ("inner_body", @{here}) (K (Config.Bool false)));
       
   325 
       
   326 fun is_body ctxt = Config.get ctxt inner_body;
       
   327 val set_body = Config.put inner_body;
       
   328 fun restore_body ctxt = set_body (is_body ctxt);
       
   329 
   341 
   330 
   342 (* proper mode *)
   331 (* proper mode *)
   343 
   332 
   344 val proper_fixes =
   333 val proper_fixes =
   345   Config.bool (Config.declare ("proper_fixes", @{here}) (K (Config.Bool true)));
   334   Config.bool (Config.declare ("proper_fixes", @{here}) (K (Config.Bool true)));