source: Deliverables/D2.2/8051/src/utilities/error.ml @ 486

Last change on this file since 486 was 486, checked in by ayache, 9 years ago

Deliverable D2.2

File size: 1.0 KB
Line 
1let exit_flag = ref true
2
3let exit_if_error () = exit_flag := true
4
5let resume_if_error () = exit_flag := false
6
7exception Error of Position.t list * string
8
9let print_error positions msg =
10  Printf.sprintf "%s%s"
11    (String.concat "\n"
12       (List.map (fun p -> Position.string_of_pos p ^": ") positions))
13    msg
14
15let error_alert positions msg =
16  if !exit_flag then (
17    output_string stderr (print_error positions msg);
18    exit 1
19  )
20  else raise (Error (positions, msg))
21
22let global_error kind msg =
23  error_alert [] (Printf.sprintf "Global Error (%s):\n  %s\n"  kind msg)
24
25let error kind pos msg =
26  error_alert [pos] (Printf.sprintf "Error (%s):\n  %s\n" kind msg)
27
28let error2 kind pos1 pos2 msg =
29  error_alert [pos1; pos2] (Printf.sprintf "Error (%s):\n  %s\n" kind msg)
30
31let warning kind msg = 
32  let mem_flag = !exit_flag in
33  exit_flag := false;
34  (try 
35    error_alert [] (Printf.sprintf "Warning (%s):\n  %s\n"  kind msg)
36  with Error (positions, msg) -> 
37    output_string stderr (print_error positions msg));
38  exit_flag := mem_flag
Note: See TracBrowser for help on using the repository browser.