src/HOL/Tools/Nitpick/nitpick_util.ML
changeset 53815 e8aa538e959e
parent 53806 de4653037e0d
child 54554 b8d0d8407c3b
equal deleted inserted replaced
53814:255a2929c137 53815:e8aa538e959e
    51   val serial_commas : string -> string list -> string list
    51   val serial_commas : string -> string list -> string list
    52   val pretty_serial_commas : string -> Pretty.T list -> Pretty.T list
    52   val pretty_serial_commas : string -> Pretty.T list -> Pretty.T list
    53   val parse_bool_option : bool -> string -> string -> bool option
    53   val parse_bool_option : bool -> string -> string -> bool option
    54   val parse_time_option : string -> string -> Time.time option
    54   val parse_time_option : string -> string -> Time.time option
    55   val string_of_time : Time.time -> string
    55   val string_of_time : Time.time -> string
    56   val spying : bool -> (unit -> string) -> unit
       
    57   val nat_subscript : int -> string
    56   val nat_subscript : int -> string
    58   val flip_polarity : polarity -> polarity
    57   val flip_polarity : polarity -> polarity
    59   val prop_T : typ
    58   val prop_T : typ
    60   val bool_T : typ
    59   val bool_T : typ
    61   val nat_T : typ
    60   val nat_T : typ
    77   val indent_size : int
    76   val indent_size : int
    78   val pstrs : string -> Pretty.T list
    77   val pstrs : string -> Pretty.T list
    79   val unyxml : string -> string
    78   val unyxml : string -> string
    80   val pretty_maybe_quote : Pretty.T -> Pretty.T
    79   val pretty_maybe_quote : Pretty.T -> Pretty.T
    81   val hash_term : term -> int
    80   val hash_term : term -> int
       
    81   val spying : bool -> (unit -> Proof.state * int * string) -> unit
    82 end;
    82 end;
    83 
    83 
    84 structure Nitpick_Util : NITPICK_UTIL =
    84 structure Nitpick_Util : NITPICK_UTIL =
    85 struct
    85 struct
    86 
    86 
   240 
   240 
   241 val parse_bool_option = Sledgehammer_Util.parse_bool_option
   241 val parse_bool_option = Sledgehammer_Util.parse_bool_option
   242 val parse_time_option = Sledgehammer_Util.parse_time_option
   242 val parse_time_option = Sledgehammer_Util.parse_time_option
   243 val string_of_time = ATP_Util.string_of_time
   243 val string_of_time = ATP_Util.string_of_time
   244 
   244 
   245 val spying_version = "a"
       
   246 
       
   247 fun spying false _ = ()
       
   248   | spying true f =
       
   249     let val message = f () in
       
   250       File.append (Path.explode "$ISABELLE_HOME_USER/spy_nitpick")
       
   251         (spying_version ^ " " ^ timestamp () ^ ": " ^ message ^ "\n")
       
   252     end
       
   253 
       
   254 val subscript = implode o map (prefix "\<^sub>") o Symbol.explode
   245 val subscript = implode o map (prefix "\<^sub>") o Symbol.explode
   255 fun nat_subscript n =
   246 fun nat_subscript n =
   256   n |> signed_string_of_int |> print_mode_active Symbol.xsymbolsN ? subscript
   247   n |> signed_string_of_int |> print_mode_active Symbol.xsymbolsN ? subscript
   257 
   248 
   258 fun flip_polarity Pos = Neg
   249 fun flip_polarity Pos = Neg
   323   | hashw_term (Free (s, _)) = hashw_string (s, 0w0)
   314   | hashw_term (Free (s, _)) = hashw_string (s, 0w0)
   324   | hashw_term _ = 0w0
   315   | hashw_term _ = 0w0
   325 
   316 
   326 val hash_term = Word.toInt o hashw_term
   317 val hash_term = Word.toInt o hashw_term
   327 
   318 
       
   319 val hackish_string_of_term = Sledgehammer_Util.hackish_string_of_term
       
   320 
       
   321 val spying_version = "b"
       
   322 
       
   323 fun spying false _ = ()
       
   324   | spying true f =
       
   325     let
       
   326       val (state, i, message) = f ()
       
   327       val ctxt = Proof.context_of state
       
   328       val goal = Logic.get_goal (prop_of (#goal (Proof.goal state))) i
       
   329       val hash = String.substring (SHA1.rep (SHA1.digest (hackish_string_of_term ctxt goal)), 0, 12)
       
   330     in
       
   331       File.append (Path.explode "$ISABELLE_HOME_USER/spy_nitpick")
       
   332         (spying_version ^ " " ^ timestamp () ^ ": " ^ hash ^ ": " ^ message ^ "\n")
       
   333     end
       
   334 
   328 end;
   335 end;