diff --git a/src/grew_utils.ml b/src/grew_utils.ml index 730b8f4348bbefd548ba77ecaaf35afb9843e141..a5c62f480b569322c8ea40dd2a7d52b6f2db6171 100644 --- a/src/grew_utils.ml +++ b/src/grew_utils.ml @@ -7,13 +7,48 @@ module StringMap = Map.Make (String) module IntSet = Set.Make (struct type t = int let compare = Pervasives.compare end) module IntMap = Map.Make (struct type t = int let compare = Pervasives.compare end) +(* ================================================================================ *) +module Loc = struct + type t = string * int + + let to_string (file,line) = sprintf "(file: %s, line: %d)" (Filename.basename file) line + + let opt_set_line line = function + | None -> None + | Some (file,_) -> Some (file, line) + + let opt_to_string = function + | None -> "" + | Some x -> to_string x +end (* module Loc *) + +(* ================================================================================ *) +module Error = struct + + exception Build of (string * Loc.t option) + exception Run of (string * Loc.t option) + exception Bug of (string * Loc.t option) + + let build_ ?loc message = + Log.fmessage "[%s] %s" (match loc with None -> "?" | Some x -> Loc.to_string x) message; + raise (Build (message, loc)) + let build ?loc = Printf.ksprintf (build_ ?loc) + + let run_ ?loc message = raise (Run (message, loc)) + let run ?loc = Printf.ksprintf (run_ ?loc) + + let bug_ ?loc message = raise (Bug (message, loc)) + let bug ?loc = Printf.ksprintf (bug_ ?loc) +end (* module Error *) (* ================================================================================ *) module String_ = struct let to_float string = try float_of_string string - with _ -> float_of_string (Str.global_replace (Str.regexp "\\.") "," string) + with _ -> + try float_of_string (Str.global_replace (Str.regexp "\\.") "," string) + with _ -> Error.build "[String_.to_float] cannot convert '%s'" string let of_float float = Str.global_replace (Str.regexp ",") "." (sprintf "%g" float) @@ -28,20 +63,6 @@ module Dot = struct ignore(Sys.command(sprintf "dot -Tpng -o %s %s " output_file temp_file_name)) end (* module Dot *) -(* ================================================================================ *) -module Loc = struct - type t = string * int - - let to_string (file,line) = sprintf "(file: %s, line: %d)" (Filename.basename file) line - - let opt_set_line line = function - | None -> None - | Some (file,_) -> Some (file, line) - - let opt_to_string = function - | None -> "" - | Some x -> to_string x -end (* module Loc *) (* ================================================================================ *) module File = struct @@ -536,24 +557,6 @@ module Massoc_gid = Massoc_make (Gid) (* ================================================================================ *) module Massoc_pid = Massoc_make (Pid) -(* ================================================================================ *) -module Error = struct - - exception Build of (string * Loc.t option) - exception Run of (string * Loc.t option) - exception Bug of (string * Loc.t option) - - let build_ ?loc message = - Log.fmessage "[%s] %s" (match loc with None -> "?" | Some x -> Loc.to_string x) message; - raise (Build (message, loc)) - let build ?loc = Printf.ksprintf (build_ ?loc) - - let run_ ?loc message = raise (Run (message, loc)) - let run ?loc = Printf.ksprintf (run_ ?loc) - - let bug_ ?loc message = raise (Bug (message, loc)) - let bug ?loc = Printf.ksprintf (bug_ ?loc) -end (* module Error *) (* ================================================================================ *) module Id = struct