Commit 5154a512 authored by bguillaum's avatar bguillaum

better error display

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8097 7838e531-6607-4d57-9587-6c381814729c
parent da806991
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment