store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
1 (* Title: HOL/Tools/Sledgehammer/sledgehammer_util.ML
2 Author: Jasmin Blanchette, TU Muenchen
4 General-purpose functions used by the Sledgehammer modules.
7 signature SLEDGEHAMMER_UTIL =
9 val plural_s : int -> string
10 val serial_commas : string -> string list -> string list
11 val replace_all : string -> string -> string -> string
12 val remove_all : string -> string -> string
13 val parse_bool_option : bool -> string -> string -> bool option
14 val parse_time_option : string -> string -> Time.time option
15 val hashw : word * word -> word
16 val hashw_char : Char.char * word -> word
17 val hashw_string : string * word -> word
20 structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
23 fun plural_s n = if n = 1 then "" else "s"
25 fun serial_commas _ [] = ["??"]
26 | serial_commas _ [s] = [s]
27 | serial_commas conj [s1, s2] = [s1, conj, s2]
28 | serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
29 | serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
31 fun replace_all bef aft =
33 fun aux seen "" = String.implode (rev seen)
35 if String.isPrefix bef s then
36 aux seen "" ^ aft ^ aux [] (unprefix bef s)
38 aux (String.sub (s, 0) :: seen) (String.extract (s, 1, NONE))
41 fun remove_all bef = replace_all bef ""
43 fun parse_bool_option option name s =
45 "smart" => if option then NONE else raise Option
46 | "false" => SOME false
50 handle Option.Option =>
51 let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
52 error ("Parameter " ^ quote name ^ " must be assigned " ^
53 space_implode " " (serial_commas "or" ss) ^ ".")
56 fun parse_time_option _ "none" = NONE
57 | parse_time_option name s =
60 case space_explode " " s of
61 [s1, "min"] => 60000 * the (Int.fromString s1)
62 | [s1, "s"] => 1000 * the (Int.fromString s1)
63 | [s1, "ms"] => the (Int.fromString s1)
67 error ("Parameter " ^ quote name ^ " must be assigned a positive time \
68 \value (e.g., \"60 s\", \"200 ms\") or \"none\".")
70 SOME (Time.fromMilliseconds msecs)
73 (* This hash function is recommended in Compilers: Principles, Techniques, and
74 Tools, by Aho, Sethi and Ullman. The hashpjw function, which they
75 particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *)
76 fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w))
77 fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w)
78 fun hashw_string (s:string, w) = CharVector.foldl hashw_char w s