src/HOL/Import/hol4rews.ML
author wenzelm
Sun, 08 Mar 2009 17:26:14 +0100
changeset 30364 577edc39b501
parent 29585 c23295521af5
child 30528 7173bf123335
permissions -rw-r--r--
moved basic algebra of long names from structure NameSpace to Long_Name;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14620
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     1
(*  Title:      HOL/Import/hol4rews.ML
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     2
    ID:         $Id$
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     3
    Author:     Sebastian Skalberg (TU Muenchen)
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     4
*)
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     5
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     6
structure StringPair = TableFun(type key = string * string val ord = prod_ord string_ord string_ord);
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     7
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     8
type holthm = (term * term) list * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     9
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    10
datatype ImportStatus =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    11
	 NoImport
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    12
       | Generating of string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    13
       | Replaying of string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    14
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    15
structure HOL4DefThy = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    16
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    17
  type T = ImportStatus
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    18
  val empty = NoImport
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    19
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    20
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    21
  fun merge _ (NoImport,NoImport) = NoImport
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    22
    | merge _ _ = (warning "Import status set during merge"; NoImport)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    23
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    24
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    25
structure ImportSegment = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    26
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    27
  type T = string
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    28
  val empty = ""
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    29
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    30
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    31
  fun merge _ ("",arg) = arg
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    32
    | merge _ (arg,"") = arg
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    33
    | merge _ (s1,s2) =
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    34
      if s1 = s2
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    35
      then s1
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    36
      else error "Trying to merge two different import segments"
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    37
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    38
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    39
val get_import_segment = ImportSegment.get
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    40
val set_import_segment = ImportSegment.put
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    41
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    42
structure HOL4UNames = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    43
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    44
  type T = string list
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    45
  val empty = []
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    46
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    47
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    48
  fun merge _ ([],[]) = []
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    49
    | merge _ _ = error "Used names not empty during merge"
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    50
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    51
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    52
structure HOL4Dump = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    53
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    54
  type T = string * string * string list
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    55
  val empty = ("","",[])
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    56
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    57
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    58
  fun merge _ (("","",[]),("","",[])) = ("","",[])
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    59
    | merge _ _ = error "Dump data not empty during merge"
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    60
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    61
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    62
structure HOL4Moves = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    63
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    64
  type T = string Symtab.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    65
  val empty = Symtab.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    66
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    67
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    68
  fun merge _ : T * T -> T = Symtab.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    69
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    70
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    71
structure HOL4Imports = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    72
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    73
  type T = string Symtab.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    74
  val empty = Symtab.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    75
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    76
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    77
  fun merge _ : T * T -> T = Symtab.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    78
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    79
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    80
fun get_segment2 thyname thy =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
    81
  Symtab.lookup (HOL4Imports.get thy) thyname
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    82
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    83
fun set_segment thyname segname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    84
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    85
	val imps = HOL4Imports.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
    86
	val imps' = Symtab.update_new (thyname,segname) imps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    87
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    88
	HOL4Imports.put imps' thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    89
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    90
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    91
structure HOL4CMoves = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    92
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    93
  type T = string Symtab.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    94
  val empty = Symtab.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    95
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    96
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    97
  fun merge _ : T * T -> T = Symtab.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
    98
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    99
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   100
structure HOL4Maps = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   101
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   102
  type T = (string option) StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   103
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   104
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   105
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   106
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   107
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   108
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   109
structure HOL4Thms = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   110
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   111
  type T = holthm StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   112
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   113
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   114
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   115
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   116
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   117
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   118
structure HOL4ConstMaps = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   119
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   120
  type T = (bool * string * typ option) StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   121
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   122
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   123
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   124
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   125
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   126
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   127
structure HOL4Rename = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   128
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   129
  type T = string StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   130
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   131
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   132
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   133
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   134
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   135
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   136
structure HOL4DefMaps = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   137
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   138
  type T = string StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   139
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   140
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   141
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   142
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   143
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   144
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   145
structure HOL4TypeMaps = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   146
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   147
  type T = (bool * string) StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   148
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   149
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   150
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   151
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   152
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   153
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   154
structure HOL4Pending = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   155
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   156
  type T = ((term * term) list * thm) StringPair.table
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   157
  val empty = StringPair.empty
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   158
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   159
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   160
  fun merge _ : T * T -> T = StringPair.merge (K true)
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   161
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   162
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   163
structure HOL4Rewrites = TheoryDataFun
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   164
(
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   165
  type T = thm list
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   166
  val empty = []
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   167
  val copy = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   168
  val extend = I
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   169
  fun merge _ = Library.gen_union Thm.eq_thm
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   170
)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   171
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   172
val hol4_debug = ref false
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   173
fun message s = if !hol4_debug then writeln s else ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   174
21546
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   175
local
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   176
  val eq_reflection = thm "eq_reflection"
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   177
in
20897
3f8d2834b2c4 attribute: Context.mapping;
wenzelm
parents: 20071
diff changeset
   178
fun add_hol4_rewrite (Context.Theory thy, th) =
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   179
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   180
	val _ = message "Adding HOL4 rewrite"
21546
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   181
	val th1 = th RS eq_reflection
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   182
	val current_rews = HOL4Rewrites.get thy
18921
f47c46d7d654 canonical member/insert/merge;
wenzelm
parents: 18728
diff changeset
   183
	val new_rews = insert Thm.eq_thm th1 current_rews
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   184
	val updated_thy  = HOL4Rewrites.put new_rews thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   185
    in
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   186
	(Context.Theory updated_thy,th1)
20897
3f8d2834b2c4 attribute: Context.mapping;
wenzelm
parents: 20071
diff changeset
   187
    end
21546
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   188
  | add_hol4_rewrite (context, th) = (context, th RS eq_reflection);
268b6bed0cc8 removed HOL structure
haftmann
parents: 21056
diff changeset
   189
end
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   190
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   191
fun ignore_hol4 bthy bthm thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   192
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   193
	val _ = message ("Ignoring " ^ bthy ^ "." ^ bthm)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   194
	val curmaps = HOL4Maps.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   195
	val newmaps = StringPair.update_new ((bthy,bthm),NONE) curmaps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   196
	val upd_thy = HOL4Maps.put newmaps thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   197
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   198
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   199
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   200
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   201
val opt_get_output_thy = #2 o HOL4Dump.get
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   202
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   203
fun get_output_thy thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   204
    case #2 (HOL4Dump.get thy) of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   205
	"" => error "No theory file being output"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   206
      | thyname => thyname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   207
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   208
val get_output_dir = #1 o HOL4Dump.get
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   209
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   210
fun add_hol4_move bef aft thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   211
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   212
	val curmoves = HOL4Moves.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   213
	val newmoves = Symtab.update_new (bef, aft) curmoves
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   214
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   215
	HOL4Moves.put newmoves thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   216
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   217
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   218
fun get_hol4_move bef thy =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   219
  Symtab.lookup (HOL4Moves.get thy) bef
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   220
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   221
fun follow_name thmname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   222
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   223
	val moves = HOL4Moves.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   224
	fun F thmname =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   225
	    case Symtab.lookup moves thmname of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   226
		SOME name => F name
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   227
	      | NONE => thmname
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   228
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   229
	F thmname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   230
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   231
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   232
fun add_hol4_cmove bef aft thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   233
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   234
	val curmoves = HOL4CMoves.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   235
	val newmoves = Symtab.update_new (bef, aft) curmoves
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   236
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   237
	HOL4CMoves.put newmoves thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   238
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   239
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   240
fun get_hol4_cmove bef thy =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   241
  Symtab.lookup (HOL4CMoves.get thy) bef
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   242
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   243
fun follow_cname thmname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   244
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   245
	val moves = HOL4CMoves.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   246
	fun F thmname =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   247
	    case Symtab.lookup moves thmname of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   248
		SOME name => F name
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   249
	      | NONE => thmname
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   250
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   251
	F thmname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   252
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   253
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   254
fun add_hol4_mapping bthy bthm isathm thy =
17644
bd59bfd4bf37 fixed disambiguation problem
obua
parents: 17607
diff changeset
   255
    let	
bd59bfd4bf37 fixed disambiguation problem
obua
parents: 17607
diff changeset
   256
       (* val _ = writeln ("Before follow_name: "^isathm)  *)
bd59bfd4bf37 fixed disambiguation problem
obua
parents: 17607
diff changeset
   257
      val isathm = follow_name isathm thy
bd59bfd4bf37 fixed disambiguation problem
obua
parents: 17607
diff changeset
   258
       (* val _ = writeln ("Adding theorem map: " ^ bthy ^ "." ^ bthm ^ " --> " ^ isathm)*)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   259
	val curmaps = HOL4Maps.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   260
	val newmaps = StringPair.update_new ((bthy,bthm),SOME isathm) curmaps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   261
	val upd_thy = HOL4Maps.put newmaps thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   262
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   263
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   264
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   265
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   266
fun get_hol4_type_mapping bthy tycon thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   267
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   268
	val maps = HOL4TypeMaps.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   269
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   270
	StringPair.lookup maps (bthy,tycon)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   271
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   272
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   273
fun get_hol4_mapping bthy bthm thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   274
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   275
	val curmaps = HOL4Maps.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   276
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   277
	StringPair.lookup curmaps (bthy,bthm)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   278
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   279
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   280
fun add_hol4_const_mapping bthy bconst internal isaconst thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   281
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   282
	val thy = case opt_get_output_thy thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   283
		      "" => thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   284
		    | output_thy => if internal
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28677
diff changeset
   285
				    then add_hol4_cmove (Sign.full_bname thy bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   286
				    else thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   287
	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   288
	val curmaps = HOL4ConstMaps.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   289
	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,NONE)) curmaps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   290
	val upd_thy = HOL4ConstMaps.put newmaps thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   291
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   292
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   293
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   294
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   295
fun add_hol4_const_renaming bthy bconst newname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   296
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   297
	val currens = HOL4Rename.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   298
	val _ = message ("Adding renaming " ^ bthy ^ "." ^ bconst ^ " -> " ^ newname)
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   299
	val newrens = StringPair.update_new ((bthy,bconst),newname) currens
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   300
	val upd_thy = HOL4Rename.put newrens thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   301
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   302
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   303
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   304
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   305
fun get_hol4_const_renaming bthy bconst thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   306
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   307
	val currens = HOL4Rename.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   308
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   309
	StringPair.lookup currens (bthy,bconst)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   310
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   311
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   312
fun get_hol4_const_mapping bthy bconst thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   313
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   314
	val bconst = case get_hol4_const_renaming bthy bconst thy of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   315
			 SOME name => name
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   316
		       | NONE => bconst
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   317
	val maps = HOL4ConstMaps.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   318
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   319
	StringPair.lookup maps (bthy,bconst)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   320
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   321
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   322
fun add_hol4_const_wt_mapping bthy bconst internal isaconst typ thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   323
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   324
	val thy = case opt_get_output_thy thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   325
		      "" => thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   326
		    | output_thy => if internal
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28677
diff changeset
   327
				    then add_hol4_cmove (Sign.full_bname thy bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   328
				    else thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   329
	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   330
	val curmaps = HOL4ConstMaps.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   331
	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,SOME typ)) curmaps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   332
	val upd_thy = HOL4ConstMaps.put newmaps thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   333
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   334
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   335
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   336
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   337
fun add_hol4_type_mapping bthy bconst internal isaconst thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   338
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   339
	val curmaps = HOL4TypeMaps.get thy
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 17261
diff changeset
   340
	val _ = writeln ("Adding tmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   341
	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst)) curmaps
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   342
               handle x => let val (internal, isaconst') = the (StringPair.lookup curmaps (bthy, bconst)) in
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 17261
diff changeset
   343
                      warning ("couldn't map type "^bthy^"."^bconst^" to "^isaconst^": already mapped to "^isaconst'); raise x end
781abf7011e6 Added HOLLight support to importer.
obua
parents: 17261
diff changeset
   344
        val upd_thy = HOL4TypeMaps.put newmaps thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   345
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   346
	upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   347
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   348
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   349
fun add_hol4_pending bthy bthm hth thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   350
    let
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28677
diff changeset
   351
	val thmname = Sign.full_bname thy bthm
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   352
	val _ = message ("Add pending " ^ bthy ^ "." ^ bthm)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   353
	val curpend = HOL4Pending.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   354
	val newpend = StringPair.update_new ((bthy,bthm),hth) curpend
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   355
	val upd_thy = HOL4Pending.put newpend thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   356
	val thy' = case opt_get_output_thy upd_thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   357
		       "" => add_hol4_mapping bthy bthm thmname upd_thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   358
		     | output_thy =>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   359
		       let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   360
			   val new_thmname = output_thy ^ "." ^ bthy ^ "." ^ bthm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   361
		       in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   362
			   upd_thy |> add_hol4_move thmname new_thmname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   363
				   |> add_hol4_mapping bthy bthm new_thmname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   364
		       end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   365
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   366
	thy'
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   367
    end;
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   368
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   369
fun get_hol4_theorem thyname thmname thy =
21056
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   370
  let
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   371
    val isathms = HOL4Thms.get thy
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   372
  in
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   373
    StringPair.lookup isathms (thyname,thmname)
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   374
  end;
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   375
21056
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   376
fun add_hol4_theorem thyname thmname hth =
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   377
  let
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   378
    val _ = message ("Adding HOL4 theorem " ^ thyname ^ "." ^ thmname)
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   379
  in
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   380
    HOL4Thms.map (StringPair.update_new ((thyname, thmname), hth))
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   381
  end;
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   382
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   383
fun export_hol4_pending thy =
21056
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   384
  let
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   385
    val rews = HOL4Rewrites.get thy;
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   386
    val pending = HOL4Pending.get thy;
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   387
    fun process ((bthy,bthm), hth as (_,thm)) thy =
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   388
      let
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   389
        val thm1 = rewrite_rule (map (Thm.transfer thy) rews) (Thm.transfer thy thm);
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   390
        val thm2 = standard thm1;
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   391
      in
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   392
        thy
29585
c23295521af5 binding replaces bstring
haftmann
parents: 28965
diff changeset
   393
        |> PureThy.store_thm (Binding.name bthm, thm2)
21056
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   394
        |> snd
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   395
        |> add_hol4_theorem bthy bthm hth
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   396
      end;
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   397
  in
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   398
    thy
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   399
    |> StringPair.fold process pending
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   400
    |> HOL4Pending.put StringPair.empty
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   401
  end;
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   402
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   403
fun setup_dump (dir,thyname) thy =
15647
b1f486a9c56b Updated import configuration.
skalberg
parents: 15570
diff changeset
   404
    HOL4Dump.put (dir,thyname,["(* AUTOMATICALLY GENERATED, DO NOT EDIT! *)"]) thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   405
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   406
fun add_dump str thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   407
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   408
	val (dir,thyname,curdump) = HOL4Dump.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   409
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   410
	HOL4Dump.put (dir,thyname,str::curdump) thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   411
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   412
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   413
fun flush_dump thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   414
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   415
	val (dir,thyname,dumpdata) = HOL4Dump.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   416
	val os = TextIO.openOut (OS.Path.joinDirFile {dir=dir,
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   417
						      file=thyname ^ ".thy"})
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   418
	val _  = app (fn s => TextIO.output(os,s ^ "\n\n")) (rev dumpdata)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   419
	val  _ = TextIO.closeOut os
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   420
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   421
	HOL4Dump.put ("","",[]) thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   422
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   423
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   424
fun set_generating_thy thyname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   425
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   426
	NoImport => HOL4DefThy.put (Generating thyname) thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   427
      | _ => error "Import already in progess"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   428
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   429
fun set_replaying_thy thyname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   430
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   431
	NoImport => HOL4DefThy.put (Replaying thyname) thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   432
      | _ => error "Import already in progess"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   433
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   434
fun clear_import_thy thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   435
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   436
	NoImport => error "No import in progress"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   437
      | _ => HOL4DefThy.put NoImport thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   438
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   439
fun get_generating_thy thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   440
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   441
	Generating thyname => thyname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   442
      | _ => error "No theory being generated"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   443
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   444
fun get_replaying_thy thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   445
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   446
	Replaying thyname => thyname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   447
      | _ => error "No theory being replayed"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   448
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   449
fun get_import_thy thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   450
    case HOL4DefThy.get thy of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   451
	Replaying thyname => thyname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   452
      | Generating thyname => thyname
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   453
      | _ => error "No theory being imported"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   454
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   455
fun should_ignore thyname thy thmname =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   456
    case get_hol4_mapping thyname thmname thy of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   457
	SOME NONE => true 
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   458
      | _ => false
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   459
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   460
val trans_string =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   461
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   462
	fun quote s = "\"" ^ s ^ "\""
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   463
	fun F [] = []
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   464
	  | F (#"\\" :: cs) = patch #"\\" cs
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   465
	  | F (#"\"" :: cs) = patch #"\"" cs
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   466
	  | F (c     :: cs) = c :: F cs
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   467
	and patch c rest = #"\\" :: c :: F rest
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   468
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   469
	quote o String.implode o F o String.explode
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   470
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   471
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   472
fun dump_import_thy thyname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   473
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   474
	val output_dir = get_output_dir thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   475
	val output_thy = get_output_thy thy
17607
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   476
	val input_thy = Context.theory_name thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   477
	val import_segment = get_import_segment thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   478
	val os = TextIO.openOut (OS.Path.joinDirFile {dir=output_dir,
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   479
						      file=thyname ^ ".imp"})
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   480
	fun out s = TextIO.output(os,s)
21056
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   481
    val (ignored, mapped) = StringPair.fold
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   482
      (fn ((bthy, bthm), v) => fn (ign, map) =>
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   483
        if bthy = thyname
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   484
        then case v
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   485
         of NONE => (bthm :: ign, map)
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   486
          | SOME w => (ign, (bthm, w) :: map)
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   487
        else (ign, map)) (HOL4Maps.get thy) ([],[]);
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   488
    fun mk init = StringPair.fold
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   489
      (fn ((bthy, bthm), v) => if bthy = thyname then cons (bthm, v) else I) init [];
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   490
    val constmaps = mk (HOL4ConstMaps.get thy);
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   491
    val constrenames = mk (HOL4Rename.get thy);
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   492
    val typemaps = mk (HOL4TypeMaps.get thy);
2cfe839e8d58 Symtab.foldl replaced by Symtab.fold
haftmann
parents: 20897
diff changeset
   493
    val defmaps = mk (HOL4DefMaps.get thy);
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   494
	fun new_name internal isa =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   495
	    if internal
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   496
	    then
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   497
		let
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 29585
diff changeset
   498
		    val paths = Long_Name.explode isa
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   499
		    val i = Library.drop(length paths - 2,paths)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   500
		in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   501
		    case i of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   502
			[seg,con] => output_thy ^ "." ^ seg ^ "." ^ con
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   503
		      | _ => error "hol4rews.dump internal error"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   504
		end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   505
	    else
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   506
		isa
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   507
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   508
	val _ = out "import\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   509
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   510
	val _ = out ("import_segment " ^ trans_string import_segment ^ "\n\n")
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   511
	val _ = if null defmaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   512
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   513
		else out "def_maps"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   514
	val _ = app (fn (hol,isa) =>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   515
			out ("\n  " ^ (trans_string hol) ^ " > " ^ (trans_string isa))) defmaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   516
	val _ = if null defmaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   517
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   518
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   519
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   520
	val _ = if null typemaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   521
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   522
		else out "type_maps"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   523
	val _ = app (fn (hol,(internal,isa)) =>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   524
			out ("\n  " ^ (trans_string hol) ^ " > " ^ (trans_string (new_name internal isa)))) typemaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   525
	val _ = if null typemaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   526
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   527
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   528
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   529
	val _ = if null constmaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   530
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   531
		else out "const_maps"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   532
	val _ = app (fn (hol,(internal,isa,opt_ty)) =>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   533
			(out ("\n  " ^ (trans_string hol) ^ " > " ^ (trans_string (follow_cname isa thy)));
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   534
			 case opt_ty of
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26481
diff changeset
   535
			     SOME ty => out (" :: \"" ^ (Display.string_of_ctyp (ctyp_of thy ty)) ^ "\"")
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   536
			   | NONE => ())) constmaps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   537
	val _ = if null constmaps
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   538
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   539
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   540
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   541
	val _ = if null constrenames
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   542
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   543
		else out "const_renames"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   544
	val _ = app (fn (old,new) =>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   545
			out ("\n  " ^ (trans_string old) ^ " > " ^ (trans_string new))) constrenames
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   546
	val _ = if null constrenames
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   547
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   548
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   549
17607
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   550
	fun gen2replay in_thy out_thy s = 
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   551
	    let
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 29585
diff changeset
   552
		val ss = Long_Name.explode s
17607
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   553
	    in
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   554
		if (hd ss = in_thy) then 
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 29585
diff changeset
   555
		    Long_Name.implode (out_thy::(tl ss))
17607
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   556
		else
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   557
		    s
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   558
	    end 
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   559
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   560
	val _ = if null mapped
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   561
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   562
		else out "thm_maps"
17607
7725da65f8e0 1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents: 17412
diff changeset
   563
	val _ = app (fn (hol,isa) => out ("\n  " ^ (trans_string hol) ^ " > " ^ (trans_string (gen2replay input_thy output_thy isa)))) mapped
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   564
	val _ = if null mapped 
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   565
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   566
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   567
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   568
	val _ = if null ignored
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   569
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   570
		else out "ignore_thms"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   571
	val _ = app (fn ign => out ("\n  " ^ (trans_string ign))) ignored
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   572
	val _ = if null ignored
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   573
		then ()
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   574
		else out "\n\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   575
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   576
	val _ = out "end\n"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   577
	val _ = TextIO.closeOut os
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   578
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   579
	thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   580
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   581
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   582
fun set_used_names names thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   583
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   584
	val unames = HOL4UNames.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   585
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   586
	case unames of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   587
	    [] => HOL4UNames.put names thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   588
	  | _ => error "hol4rews.set_used_names called on initialized data!"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   589
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   590
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22578
diff changeset
   591
val clear_used_names = HOL4UNames.put [];
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   592
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   593
fun get_defmap thyname const thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   594
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   595
	val maps = HOL4DefMaps.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   596
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   597
	StringPair.lookup maps (thyname,const)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   598
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   599
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   600
fun add_defmap thyname const defname thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   601
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   602
	val _ = message ("Adding defmap " ^ thyname ^ "." ^ const ^ " --> " ^ defname)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   603
	val maps = HOL4DefMaps.get thy
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   604
	val maps' = StringPair.update_new ((thyname,const),defname) maps
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   605
	val thy' = HOL4DefMaps.put maps' thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   606
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   607
	thy'
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   608
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   609
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   610
fun get_defname thyname name thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   611
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   612
	val maps = HOL4DefMaps.get thy
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   613
	fun F dname = (dname,add_defmap thyname name dname thy)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   614
    in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17322
diff changeset
   615
	case StringPair.lookup maps (thyname,name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   616
	    SOME thmname => (thmname,thy)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14980
diff changeset
   617
	  | NONE =>
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   618
	    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   619
		val used = HOL4UNames.get thy
28677
4693938e9c2a Thm.def_name;
wenzelm
parents: 26928
diff changeset
   620
		val defname = Thm.def_name name
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   621
		val pdefname = name ^ "_primdef"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   622
	    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   623
		if not (defname mem used)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   624
		then F defname                 (* name_def *)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   625
		else if not (pdefname mem used)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   626
		then F pdefname                (* name_primdef *)
20071
8f3e1ddb50e6 replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents: 18921
diff changeset
   627
		else F (Name.variant used pdefname) (* last resort *)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   628
	    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   629
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   630
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   631
local
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   632
    fun handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==", _],_,_]] = x
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   633
      | handle_meta [x as Appl[Appl[Constant "_constrain", Constant "all", _],_]] = x
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   634
      | handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==>", _],_,_]] = x
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   635
      | handle_meta [x] = Appl[Constant "Trueprop",x]
14518
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   636
      | handle_meta _ = error "hol4rews error: Trueprop not applied to single argument"
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   637
in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   638
val smarter_trueprop_parsing = [("Trueprop",handle_meta)]
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   639
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   640
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   641
local
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   642
    fun initial_maps thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   643
	thy |> add_hol4_type_mapping "min" "bool" false "bool"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   644
	    |> add_hol4_type_mapping "min" "fun" false "fun"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   645
	    |> add_hol4_type_mapping "min" "ind" false "Nat.ind"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   646
	    |> add_hol4_const_mapping "min" "=" false "op ="
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   647
	    |> add_hol4_const_mapping "min" "==>" false "op -->"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   648
	    |> add_hol4_const_mapping "min" "@" false "Hilbert_Choice.Eps"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   649
in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   650
val hol4_setup =
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18358
diff changeset
   651
  initial_maps #>
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18358
diff changeset
   652
  Attrib.add_attributes
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   653
    [("hol4rew", Attrib.no_args add_hol4_rewrite, "HOL4 rewrite rule")]
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   654
end