src/HOL/thy_data.ML
author oheimb
Thu, 18 Dec 1997 12:50:58 +0100
changeset 4435 41a7e4f0e957
parent 4329 9d99bfdd7441
child 4458 ad8be126603d
permissions -rw-r--r--
added expand_split_asm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/thy_data.ML
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     4
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     5
HOL theory data: simpset, claset, records, datatypes.
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     6
*)
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     7
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     8
(*for records*)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     9
type record_info =
4329
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
    10
 {args:     string list,
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
    11
  parent:   (typ list * string) option,
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
    12
  fields:   (string * typ) list,
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
    13
  sign_ref: Sign.sg_ref};
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    14
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    15
(*for datatypes*)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    16
type datatype_info =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    17
 {case_const: term,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    18
  case_rewrites: thm list,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    19
  constructors: term list,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    20
  induct_tac: string -> int -> tactic,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    21
  nchotomy: thm,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    22
  exhaustion: thm,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    23
  exhaust_tac: string -> int -> tactic,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    24
  case_cong: thm};
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    25
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    26
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    27
signature THY_DATA =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    28
sig
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    29
  val get_records: theory -> record_info Symtab.table;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    30
  val put_records: record_info Symtab.table -> theory -> theory;
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    31
  val get_datatypes_sg: Sign.sg -> datatype_info Symtab.table
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    32
  val get_datatypes: theory -> datatype_info Symtab.table
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    33
  val put_datatypes: datatype_info Symtab.table -> theory -> theory
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    34
  val hol_data: (string * (object * (object -> object) *
4259
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
    35
    (object * object -> object) * (Sign.sg -> object -> unit))) list
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    36
end;
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    37
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    38
structure ThyData: THY_DATA =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    39
struct
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    40
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    41
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    42
(** datatypes **)
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    43
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    44
(* data kind 'datatypes' *)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    45
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    46
val datatypesK = "datatypes";
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    47
exception DatatypeInfo of datatype_info Symtab.table;
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    48
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    49
local
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    50
  val empty = DatatypeInfo Symtab.null;
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    51
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    52
  fun prep_ext (x as DatatypeInfo _) = x;
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    53
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    54
  fun merge (DatatypeInfo tab1, DatatypeInfo tab2) =
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    55
    DatatypeInfo (Symtab.merge (K true) (tab1, tab2));
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    56
4259
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
    57
  fun print sg (DatatypeInfo tab) =
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
    58
    Pretty.writeln (Pretty.strs ("datatypes:" ::
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
    59
      map (Sign.cond_extern sg Sign.typeK o fst) (Symtab.dest tab)));
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    60
in
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    61
  val datatypes_thy_data = (datatypesK, (empty, prep_ext, merge, print));
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    62
end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    63
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    64
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    65
(* get and put datatypes *)
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    66
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    67
fun get_datatypes_sg sg =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    68
  (case Sign.get_data sg datatypesK of
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    69
    DatatypeInfo tab => tab
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    70
  | _ => sys_error "get_datatypes_sg");
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    71
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    72
val get_datatypes = get_datatypes_sg o sign_of;
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    73
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    74
fun put_datatypes tab thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    75
  Theory.put_data (datatypesK, DatatypeInfo tab) thy;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    76
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    77
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    78
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    79
(** records **)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    80
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    81
(* data kind 'records' *)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    82
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    83
val recordsK = "records";
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    84
exception Records of record_info Symtab.table;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    85
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    86
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    87
(* methods *)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    88
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    89
local
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    90
  val empty = Records Symtab.null;
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    91
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    92
  fun prep_ext (x as Records _) = x;
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    93
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    94
  fun merge (Records tab1, Records tab2) =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    95
    Records (Symtab.merge (K true) (tab1, tab2));
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    96
4259
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
    97
  fun print sg (Records tab) =
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    98
    let
4329
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
    99
      fun pretty_args args = Pretty.lst ("(", ")") (map Pretty.str args);
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   100
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   101
      fun pretty_parent sign None = []
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   102
        | pretty_parent sign (Some (ts, name)) = 
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   103
            (Pretty.lst ("(", ")") (map (Sign.pretty_typ sign) ts)) :: [Pretty.str (name ^ " +")];
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   104
4329
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   105
      fun pretty_field sign (c, T) = Pretty.block
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   106
        [Pretty.str (c ^ " :: "), Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)];
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
   107
4329
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   108
      fun pretty_record (name, {args, parent, fields, sign_ref}) =
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   109
        let val sign = Sign.deref sign_ref in
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   110
          Pretty.block 
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   111
            (Pretty.fbreaks
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   112
              ((Pretty.block ((pretty_args args) :: [Pretty.str (" " ^ name ^ " =")])) ::
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   113
              pretty_parent sign parent @ map (pretty_field sign) fields))
9d99bfdd7441 args for record data
narasche
parents: 4259
diff changeset
   114
        end
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   115
    in
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   116
      seq (Pretty.writeln o pretty_record) (Symtab.dest tab)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   117
    end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   118
in
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   119
  val record_thy_data = (recordsK, (empty, prep_ext, merge, print));
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   120
end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   121
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   122
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   123
(* get and put records *)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   124
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   125
fun get_records thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   126
  (case Theory.get_data thy recordsK of
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   127
    Records tab => tab
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   128
  | _ => sys_error "get_records");
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   129
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   130
fun put_records tab thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   131
  Theory.put_data (recordsK, Records tab) thy;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   132
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   133
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   134
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   135
(** hol_data **)
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   136
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   137
val hol_data =
4259
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
   138
 [Simplifier.simpset_thy_data,
adbe3f4e7caf adapted print methods;
wenzelm
parents: 4150
diff changeset
   139
  ClasetThyData.thy_data,
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   140
  datatypes_thy_data,
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   141
  record_thy_data];
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   142
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   143
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   144
end;