summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/warnings.ml39
-rw-r--r--utils/warnings.mli12
2 files changed, 42 insertions, 9 deletions
diff --git a/utils/warnings.ml b/utils/warnings.ml
index 33c85ba36..28bf42456 100644
--- a/utils/warnings.ml
+++ b/utils/warnings.ml
@@ -41,7 +41,8 @@ let check c =
with _ -> raise (Arg.Bad (Printf.sprintf "unknown warning option %c" c))
;;
-let flags = Array.create 26 true;;
+let active = Array.create 26 true;;
+let error = Array.create 26 false;;
let translate c =
check c;
@@ -51,7 +52,18 @@ let translate c =
(Char.code c - Char.code 'a', false)
;;
-let parse_options s =
+let is_active x =
+ let (n, _) = translate (letter x) in
+ active.(n)
+;;
+
+let is_error x =
+ let (n, _) = translate (letter x) in
+ error.(n)
+;;
+
+let parse_options iserr s =
+ let flags = if iserr then error else active in
for i = 0 to String.length s - 1 do
if s.[i] = 'A' then Array.fill flags 0 (Array.length flags) true
else if s.[i] = 'a' then Array.fill flags 0 (Array.length flags) false
@@ -62,11 +74,6 @@ let parse_options s =
done
;;
-let is_active x =
- let (n, _) = translate (letter x) in
- flags.(n)
-;;
-
let message = function
| Partial_match "" -> "this pattern-matching is not exhaustive."
| Partial_match s ->
@@ -88,3 +95,21 @@ let message = function
| Comment s -> "this is " ^ s ^ "."
| Other s -> s
;;
+
+let nerrors = ref 0;;
+
+let print ppf w =
+ Format.fprintf ppf "%s" (message w);
+ let (n, _) = translate (letter w) in
+ if error.(n) then incr nerrors;
+;;
+
+exception Errors of int;;
+
+let check_fatal () =
+ if !nerrors > 0 then begin
+ let e = Errors !nerrors in
+ nerrors := 0;
+ raise e;
+ end;
+;;
diff --git a/utils/warnings.mli b/utils/warnings.mli
index 16106c30f..b352e6b34 100644
--- a/utils/warnings.mli
+++ b/utils/warnings.mli
@@ -12,6 +12,8 @@
(* $Id$ *)
+open Format
+
type t = (* A is all *)
| Comment of string (* C *)
| Partial_application (* F *)
@@ -23,8 +25,14 @@ type t = (* A is all *)
| Other of string (* X *)
;;
-val parse_options : string -> unit;;
+val parse_options : iserror:bool -> string -> unit;;
val is_active : t -> bool;;
+val is_error : t -> bool;;
+
+val print : formatter -> t -> unit;;
+
+
+exception Errors of int;;
-val message : t -> string;;
+val check_fatal : unit -> unit;;