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