src/HOL/Import/hol4rews.ML
changeset 17412 e26cb20ef0cc
parent 17322 781abf7011e6
child 17607 7725da65f8e0
equal deleted inserted replaced
17411:664434175578 17412:e26cb20ef0cc
   108 end;
   108 end;
   109 
   109 
   110 structure HOL4Imports = TheoryDataFun(HOL4ImportsArgs);
   110 structure HOL4Imports = TheoryDataFun(HOL4ImportsArgs);
   111 
   111 
   112 fun get_segment2 thyname thy =
   112 fun get_segment2 thyname thy =
   113   Symtab.curried_lookup (HOL4Imports.get thy) thyname
   113   Symtab.lookup (HOL4Imports.get thy) thyname
   114 
   114 
   115 fun set_segment thyname segname thy =
   115 fun set_segment thyname segname thy =
   116     let
   116     let
   117 	val imps = HOL4Imports.get thy
   117 	val imps = HOL4Imports.get thy
   118 	val imps' = Symtab.curried_update_new (thyname,segname) imps
   118 	val imps' = Symtab.update_new (thyname,segname) imps
   119     in
   119     in
   120 	HOL4Imports.put imps' thy
   120 	HOL4Imports.put imps' thy
   121     end
   121     end
   122 
   122 
   123 structure HOL4CMovesArgs: THEORY_DATA_ARGS =
   123 structure HOL4CMovesArgs: THEORY_DATA_ARGS =
   271 
   271 
   272 fun ignore_hol4 bthy bthm thy =
   272 fun ignore_hol4 bthy bthm thy =
   273     let
   273     let
   274 	val _ = message ("Ignoring " ^ bthy ^ "." ^ bthm)
   274 	val _ = message ("Ignoring " ^ bthy ^ "." ^ bthm)
   275 	val curmaps = HOL4Maps.get thy
   275 	val curmaps = HOL4Maps.get thy
   276 	val newmaps = StringPair.update_new(((bthy,bthm),NONE),curmaps)
   276 	val newmaps = StringPair.update_new ((bthy,bthm),NONE) curmaps
   277 	val upd_thy = HOL4Maps.put newmaps thy
   277 	val upd_thy = HOL4Maps.put newmaps thy
   278     in
   278     in
   279 	upd_thy
   279 	upd_thy
   280     end
   280     end
   281 
   281 
   289 val get_output_dir = #1 o HOL4Dump.get
   289 val get_output_dir = #1 o HOL4Dump.get
   290 
   290 
   291 fun add_hol4_move bef aft thy =
   291 fun add_hol4_move bef aft thy =
   292     let
   292     let
   293 	val curmoves = HOL4Moves.get thy
   293 	val curmoves = HOL4Moves.get thy
   294 	val newmoves = Symtab.curried_update_new (bef, aft) curmoves
   294 	val newmoves = Symtab.update_new (bef, aft) curmoves
   295     in
   295     in
   296 	HOL4Moves.put newmoves thy
   296 	HOL4Moves.put newmoves thy
   297     end
   297     end
   298 
   298 
   299 fun get_hol4_move bef thy =
   299 fun get_hol4_move bef thy =
   300   Symtab.curried_lookup (HOL4Moves.get thy) bef
   300   Symtab.lookup (HOL4Moves.get thy) bef
   301 
   301 
   302 fun follow_name thmname thy =
   302 fun follow_name thmname thy =
   303     let
   303     let
   304 	val moves = HOL4Moves.get thy
   304 	val moves = HOL4Moves.get thy
   305 	fun F thmname =
   305 	fun F thmname =
   306 	    case Symtab.curried_lookup moves thmname of
   306 	    case Symtab.lookup moves thmname of
   307 		SOME name => F name
   307 		SOME name => F name
   308 	      | NONE => thmname
   308 	      | NONE => thmname
   309     in
   309     in
   310 	F thmname
   310 	F thmname
   311     end
   311     end
   312 
   312 
   313 fun add_hol4_cmove bef aft thy =
   313 fun add_hol4_cmove bef aft thy =
   314     let
   314     let
   315 	val curmoves = HOL4CMoves.get thy
   315 	val curmoves = HOL4CMoves.get thy
   316 	val newmoves = Symtab.curried_update_new (bef, aft) curmoves
   316 	val newmoves = Symtab.update_new (bef, aft) curmoves
   317     in
   317     in
   318 	HOL4CMoves.put newmoves thy
   318 	HOL4CMoves.put newmoves thy
   319     end
   319     end
   320 
   320 
   321 fun get_hol4_cmove bef thy =
   321 fun get_hol4_cmove bef thy =
   322   Symtab.curried_lookup (HOL4CMoves.get thy) bef
   322   Symtab.lookup (HOL4CMoves.get thy) bef
   323 
   323 
   324 fun follow_cname thmname thy =
   324 fun follow_cname thmname thy =
   325     let
   325     let
   326 	val moves = HOL4CMoves.get thy
   326 	val moves = HOL4CMoves.get thy
   327 	fun F thmname =
   327 	fun F thmname =
   328 	    case Symtab.curried_lookup moves thmname of
   328 	    case Symtab.lookup moves thmname of
   329 		SOME name => F name
   329 		SOME name => F name
   330 	      | NONE => thmname
   330 	      | NONE => thmname
   331     in
   331     in
   332 	F thmname
   332 	F thmname
   333     end
   333     end
   335 fun add_hol4_mapping bthy bthm isathm thy =
   335 fun add_hol4_mapping bthy bthm isathm thy =
   336     let
   336     let
   337 	val isathm = follow_name isathm thy
   337 	val isathm = follow_name isathm thy
   338 	val _ = message ("Adding theorem map: " ^ bthy ^ "." ^ bthm ^ " --> " ^ isathm)
   338 	val _ = message ("Adding theorem map: " ^ bthy ^ "." ^ bthm ^ " --> " ^ isathm)
   339 	val curmaps = HOL4Maps.get thy
   339 	val curmaps = HOL4Maps.get thy
   340 	val newmaps = StringPair.update_new(((bthy,bthm),SOME isathm),curmaps)
   340 	val newmaps = StringPair.update_new ((bthy,bthm),SOME isathm) curmaps
   341 	val upd_thy = HOL4Maps.put newmaps thy
   341 	val upd_thy = HOL4Maps.put newmaps thy
   342     in
   342     in
   343 	upd_thy
   343 	upd_thy
   344     end;
   344     end;
   345 
   345 
   346 fun get_hol4_type_mapping bthy tycon thy =
   346 fun get_hol4_type_mapping bthy tycon thy =
   347     let
   347     let
   348 	val maps = HOL4TypeMaps.get thy
   348 	val maps = HOL4TypeMaps.get thy
   349     in
   349     in
   350 	StringPair.lookup(maps,(bthy,tycon))
   350 	StringPair.lookup maps (bthy,tycon)
   351     end
   351     end
   352 
   352 
   353 fun get_hol4_mapping bthy bthm thy =
   353 fun get_hol4_mapping bthy bthm thy =
   354     let
   354     let
   355 	val curmaps = HOL4Maps.get thy
   355 	val curmaps = HOL4Maps.get thy
   356     in
   356     in
   357 	StringPair.lookup(curmaps,(bthy,bthm))
   357 	StringPair.lookup curmaps (bthy,bthm)
   358     end;
   358     end;
   359 
   359 
   360 fun add_hol4_const_mapping bthy bconst internal isaconst thy =
   360 fun add_hol4_const_mapping bthy bconst internal isaconst thy =
   361     let
   361     let
   362 	val thy = case opt_get_output_thy thy of
   362 	val thy = case opt_get_output_thy thy of
   364 		    | output_thy => if internal
   364 		    | output_thy => if internal
   365 				    then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
   365 				    then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
   366 				    else thy
   366 				    else thy
   367 	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   367 	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   368 	val curmaps = HOL4ConstMaps.get thy
   368 	val curmaps = HOL4ConstMaps.get thy
   369 	val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst,NONE)),curmaps)
   369 	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,NONE)) curmaps
   370 	val upd_thy = HOL4ConstMaps.put newmaps thy
   370 	val upd_thy = HOL4ConstMaps.put newmaps thy
   371     in
   371     in
   372 	upd_thy
   372 	upd_thy
   373     end;
   373     end;
   374 
   374 
   375 fun add_hol4_const_renaming bthy bconst newname thy =
   375 fun add_hol4_const_renaming bthy bconst newname thy =
   376     let
   376     let
   377 	val currens = HOL4Rename.get thy
   377 	val currens = HOL4Rename.get thy
   378 	val _ = message ("Adding renaming " ^ bthy ^ "." ^ bconst ^ " -> " ^ newname)
   378 	val _ = message ("Adding renaming " ^ bthy ^ "." ^ bconst ^ " -> " ^ newname)
   379 	val newrens = StringPair.update_new(((bthy,bconst),newname),currens)
   379 	val newrens = StringPair.update_new ((bthy,bconst),newname) currens
   380 	val upd_thy = HOL4Rename.put newrens thy
   380 	val upd_thy = HOL4Rename.put newrens thy
   381     in
   381     in
   382 	upd_thy
   382 	upd_thy
   383     end;
   383     end;
   384 
   384 
   385 fun get_hol4_const_renaming bthy bconst thy =
   385 fun get_hol4_const_renaming bthy bconst thy =
   386     let
   386     let
   387 	val currens = HOL4Rename.get thy
   387 	val currens = HOL4Rename.get thy
   388     in
   388     in
   389 	StringPair.lookup(currens,(bthy,bconst))
   389 	StringPair.lookup currens (bthy,bconst)
   390     end;
   390     end;
   391 
   391 
   392 fun get_hol4_const_mapping bthy bconst thy =
   392 fun get_hol4_const_mapping bthy bconst thy =
   393     let
   393     let
   394 	val bconst = case get_hol4_const_renaming bthy bconst thy of
   394 	val bconst = case get_hol4_const_renaming bthy bconst thy of
   395 			 SOME name => name
   395 			 SOME name => name
   396 		       | NONE => bconst
   396 		       | NONE => bconst
   397 	val maps = HOL4ConstMaps.get thy
   397 	val maps = HOL4ConstMaps.get thy
   398     in
   398     in
   399 	StringPair.lookup(maps,(bthy,bconst))
   399 	StringPair.lookup maps (bthy,bconst)
   400     end
   400     end
   401 
   401 
   402 fun add_hol4_const_wt_mapping bthy bconst internal isaconst typ thy =
   402 fun add_hol4_const_wt_mapping bthy bconst internal isaconst typ thy =
   403     let
   403     let
   404 	val thy = case opt_get_output_thy thy of
   404 	val thy = case opt_get_output_thy thy of
   406 		    | output_thy => if internal
   406 		    | output_thy => if internal
   407 				    then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
   407 				    then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy
   408 				    else thy
   408 				    else thy
   409 	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   409 	val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   410 	val curmaps = HOL4ConstMaps.get thy
   410 	val curmaps = HOL4ConstMaps.get thy
   411 	val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst,SOME typ)),curmaps)
   411 	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,SOME typ)) curmaps
   412 	val upd_thy = HOL4ConstMaps.put newmaps thy
   412 	val upd_thy = HOL4ConstMaps.put newmaps thy
   413     in
   413     in
   414 	upd_thy
   414 	upd_thy
   415     end;
   415     end;
   416 
   416 
   417 fun add_hol4_type_mapping bthy bconst internal isaconst thy =
   417 fun add_hol4_type_mapping bthy bconst internal isaconst thy =
   418     let
   418     let
   419 	val curmaps = HOL4TypeMaps.get thy
   419 	val curmaps = HOL4TypeMaps.get thy
   420 	val _ = writeln ("Adding tmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   420 	val _ = writeln ("Adding tmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else ""))
   421 	val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst)),curmaps)
   421 	val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst)) curmaps
   422                handle x => let val (internal, isaconst') = the (StringPair.lookup (curmaps, (bthy, bconst))) in
   422                handle x => let val (internal, isaconst') = the (StringPair.lookup curmaps (bthy, bconst)) in
   423                       warning ("couldn't map type "^bthy^"."^bconst^" to "^isaconst^": already mapped to "^isaconst'); raise x end
   423                       warning ("couldn't map type "^bthy^"."^bconst^" to "^isaconst^": already mapped to "^isaconst'); raise x end
   424         val upd_thy = HOL4TypeMaps.put newmaps thy
   424         val upd_thy = HOL4TypeMaps.put newmaps thy
   425     in
   425     in
   426 	upd_thy
   426 	upd_thy
   427     end;
   427     end;
   429 fun add_hol4_pending bthy bthm hth thy =
   429 fun add_hol4_pending bthy bthm hth thy =
   430     let
   430     let
   431 	val thmname = Sign.full_name (sign_of thy) bthm
   431 	val thmname = Sign.full_name (sign_of thy) bthm
   432 	val _ = message ("Add pending " ^ bthy ^ "." ^ bthm)
   432 	val _ = message ("Add pending " ^ bthy ^ "." ^ bthm)
   433 	val curpend = HOL4Pending.get thy
   433 	val curpend = HOL4Pending.get thy
   434 	val newpend = StringPair.update_new(((bthy,bthm),hth),curpend)
   434 	val newpend = StringPair.update_new ((bthy,bthm),hth) curpend
   435 	val upd_thy = HOL4Pending.put newpend thy
   435 	val upd_thy = HOL4Pending.put newpend thy
   436 	val thy' = case opt_get_output_thy upd_thy of
   436 	val thy' = case opt_get_output_thy upd_thy of
   437 		       "" => add_hol4_mapping bthy bthm thmname upd_thy
   437 		       "" => add_hol4_mapping bthy bthm thmname upd_thy
   438 		     | output_thy =>
   438 		     | output_thy =>
   439 		       let
   439 		       let
   448 
   448 
   449 fun get_hol4_theorem thyname thmname thy =
   449 fun get_hol4_theorem thyname thmname thy =
   450     let
   450     let
   451 	val isathms = HOL4Thms.get thy
   451 	val isathms = HOL4Thms.get thy
   452     in
   452     in
   453 	StringPair.lookup (isathms,(thyname,thmname))
   453 	StringPair.lookup isathms (thyname,thmname)
   454     end
   454     end
   455 
   455 
   456 fun add_hol4_theorem thyname thmname hth thy =
   456 fun add_hol4_theorem thyname thmname hth thy =
   457     let
   457     let
   458 	val _ = message ("Adding HOL4 theorem " ^ thyname ^ "." ^ thmname)
   458 	val _ = message ("Adding HOL4 theorem " ^ thyname ^ "." ^ thmname)
   459 	val isathms = HOL4Thms.get thy
   459 	val isathms = HOL4Thms.get thy
   460 	val isathms' = StringPair.update_new (((thyname,thmname),hth),isathms)
   460 	val isathms' = StringPair.update_new ((thyname,thmname),hth) isathms
   461 	val thy' = HOL4Thms.put isathms' thy
   461 	val thy' = HOL4Thms.put isathms' thy
   462     in
   462     in
   463 	thy'
   463 	thy'
   464     end
   464     end
   465 
   465 
   690 
   690 
   691 fun get_defmap thyname const thy =
   691 fun get_defmap thyname const thy =
   692     let
   692     let
   693 	val maps = HOL4DefMaps.get thy
   693 	val maps = HOL4DefMaps.get thy
   694     in
   694     in
   695 	StringPair.lookup(maps,(thyname,const))
   695 	StringPair.lookup maps (thyname,const)
   696     end
   696     end
   697 
   697 
   698 fun add_defmap thyname const defname thy =
   698 fun add_defmap thyname const defname thy =
   699     let
   699     let
   700 	val _ = message ("Adding defmap " ^ thyname ^ "." ^ const ^ " --> " ^ defname)
   700 	val _ = message ("Adding defmap " ^ thyname ^ "." ^ const ^ " --> " ^ defname)
   701 	val maps = HOL4DefMaps.get thy
   701 	val maps = HOL4DefMaps.get thy
   702 	val maps' = StringPair.update_new(((thyname,const),defname),maps)
   702 	val maps' = StringPair.update_new ((thyname,const),defname) maps
   703 	val thy' = HOL4DefMaps.put maps' thy
   703 	val thy' = HOL4DefMaps.put maps' thy
   704     in
   704     in
   705 	thy'
   705 	thy'
   706     end
   706     end
   707 
   707 
   708 fun get_defname thyname name thy =
   708 fun get_defname thyname name thy =
   709     let
   709     let
   710 	val maps = HOL4DefMaps.get thy
   710 	val maps = HOL4DefMaps.get thy
   711 	fun F dname = (dname,add_defmap thyname name dname thy)
   711 	fun F dname = (dname,add_defmap thyname name dname thy)
   712     in
   712     in
   713 	case StringPair.lookup(maps,(thyname,name)) of
   713 	case StringPair.lookup maps (thyname,name) of
   714 	    SOME thmname => (thmname,thy)
   714 	    SOME thmname => (thmname,thy)
   715 	  | NONE =>
   715 	  | NONE =>
   716 	    let
   716 	    let
   717 		val used = HOL4UNames.get thy
   717 		val used = HOL4UNames.get thy
   718 		val defname = def_name name
   718 		val defname = def_name name