1998-11-05 00:08:28 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Pierre Weis && Damien Doligez, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1998 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1998-11-05 00:08:28 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1999-12-23 10:02:58 -08:00
|
|
|
(* Please keep them in alphabetical order *)
|
|
|
|
|
|
|
|
type t = (* A is all *)
|
2004-11-30 10:57:04 -08:00
|
|
|
| Comment_start (* C *)
|
|
|
|
| Comment_not_end
|
2001-09-25 02:54:18 -07:00
|
|
|
| Deprecated (* D *)
|
2006-09-21 07:54:54 -07:00
|
|
|
| Fragile_match of string (* E *)
|
1999-12-23 10:02:58 -08:00
|
|
|
| Partial_application (* F *)
|
2002-01-20 07:12:21 -08:00
|
|
|
| Labels_omitted (* L *)
|
1999-12-23 10:02:58 -08:00
|
|
|
| Method_override of string list (* M *)
|
1999-10-29 07:42:37 -07:00
|
|
|
| Partial_match of string (* P *)
|
1999-12-23 10:02:58 -08:00
|
|
|
| Statement_type (* S *)
|
2004-11-30 10:57:04 -08:00
|
|
|
| Unused_match (* U *)
|
|
|
|
| Unused_pat
|
2006-04-04 19:28:13 -07:00
|
|
|
| Instance_variable_override of string (* V *)
|
2004-11-30 10:57:04 -08:00
|
|
|
| Illegal_backslash (* X *)
|
|
|
|
| Implicit_public_methods of string list
|
|
|
|
| Unerasable_optional_argument
|
|
|
|
| Undeclared_virtual_method of string
|
|
|
|
| Not_principal of string
|
|
|
|
| Without_principality of string
|
|
|
|
| Unused_argument
|
|
|
|
| Nonreturning_statement
|
|
|
|
| Camlp4 of string
|
|
|
|
| All_clauses_guarded
|
2005-09-14 20:09:26 -07:00
|
|
|
| Useless_record_with
|
2004-11-06 12:17:47 -08:00
|
|
|
| Unused_var of string (* Y *)
|
|
|
|
| Unused_var_strict of string (* Z *)
|
1998-11-05 00:08:28 -08:00
|
|
|
;;
|
|
|
|
|
1999-12-23 10:02:58 -08:00
|
|
|
let letter = function (* 'a' is all *)
|
2004-11-30 10:57:04 -08:00
|
|
|
| Comment_start
|
|
|
|
| Comment_not_end -> 'c'
|
2001-09-25 02:54:18 -07:00
|
|
|
| Deprecated -> 'd'
|
2006-09-21 07:54:54 -07:00
|
|
|
| Fragile_match _ -> 'e'
|
1999-12-23 10:02:58 -08:00
|
|
|
| Partial_application -> 'f'
|
2001-09-06 01:52:32 -07:00
|
|
|
| Labels_omitted -> 'l'
|
1999-12-23 10:02:58 -08:00
|
|
|
| Method_override _ -> 'm'
|
|
|
|
| Partial_match _ -> 'p'
|
|
|
|
| Statement_type -> 's'
|
2004-11-30 10:57:04 -08:00
|
|
|
| Unused_match
|
|
|
|
| Unused_pat -> 'u'
|
2006-04-04 19:28:13 -07:00
|
|
|
| Instance_variable_override _ -> 'v'
|
2004-11-30 10:57:04 -08:00
|
|
|
| Illegal_backslash
|
|
|
|
| Implicit_public_methods _
|
|
|
|
| Unerasable_optional_argument
|
|
|
|
| Undeclared_virtual_method _
|
|
|
|
| Not_principal _
|
|
|
|
| Without_principality _
|
|
|
|
| Unused_argument
|
|
|
|
| Nonreturning_statement
|
|
|
|
| Camlp4 _
|
2005-09-14 20:09:26 -07:00
|
|
|
| Useless_record_with
|
2004-11-30 10:57:04 -08:00
|
|
|
| All_clauses_guarded -> 'x'
|
2004-11-06 12:17:47 -08:00
|
|
|
| Unused_var _ -> 'y'
|
|
|
|
| Unused_var_strict _ -> 'z'
|
1999-12-23 10:02:58 -08:00
|
|
|
;;
|
|
|
|
|
2005-02-16 06:38:32 -08:00
|
|
|
let active = Array.create 27 true;;
|
|
|
|
let error = Array.create 27 false;;
|
1999-12-23 10:02:58 -08:00
|
|
|
|
|
|
|
let translate c =
|
|
|
|
if c >= 'A' && c <= 'Z' then
|
|
|
|
(Char.code c - Char.code 'A', true)
|
2005-02-16 06:38:32 -08:00
|
|
|
else if c >= 'a' && c <= 'z' then
|
1999-12-23 10:02:58 -08:00
|
|
|
(Char.code c - Char.code 'a', false)
|
2005-03-24 09:20:54 -08:00
|
|
|
else
|
|
|
|
(26, false)
|
1999-12-23 10:02:58 -08:00
|
|
|
;;
|
1998-11-05 00:08:28 -08:00
|
|
|
|
2000-08-23 10:13:17 -07:00
|
|
|
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
|
1998-11-05 00:08:28 -08:00
|
|
|
for i = 0 to String.length s - 1 do
|
1999-12-23 10:02:58 -08:00
|
|
|
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
|
|
|
|
else begin
|
|
|
|
let (n, fl) = translate s.[i] in
|
|
|
|
flags.(n) <- fl;
|
|
|
|
end;
|
1998-11-05 00:08:28 -08:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
2004-11-30 10:57:04 -08:00
|
|
|
let () = parse_options false "elz";;
|
2001-09-27 00:31:29 -07:00
|
|
|
|
1998-11-05 00:08:28 -08:00
|
|
|
let message = function
|
1999-10-29 07:42:37 -07:00
|
|
|
| Partial_match "" -> "this pattern-matching is not exhaustive."
|
|
|
|
| Partial_match s ->
|
|
|
|
"this pattern-matching is not exhaustive.\n\
|
|
|
|
Here is an example of a value that is not matched:\n" ^ s
|
1998-11-05 00:08:28 -08:00
|
|
|
| Unused_match -> "this match case is unused."
|
2006-09-21 07:54:54 -07:00
|
|
|
| Unused_pat -> "this sub-pattern is unused."
|
|
|
|
| Fragile_match "" ->
|
|
|
|
"this pattern-matching is fragile."
|
|
|
|
| Fragile_match s ->
|
|
|
|
"this pattern-matching is fragile.\n\
|
|
|
|
It will remain exhaustive when constructors are added to type " ^ s ^ "."
|
2001-09-06 01:52:32 -07:00
|
|
|
| Labels_omitted ->
|
|
|
|
"labels were omitted in the application of this function."
|
2006-06-12 00:33:14 -07:00
|
|
|
| Method_override [lab] ->
|
|
|
|
"the method " ^ lab ^ " is overriden in the same class."
|
|
|
|
| Method_override (cname :: slist) ->
|
1998-11-05 00:08:28 -08:00
|
|
|
String.concat " "
|
2006-06-12 00:33:14 -07:00
|
|
|
("the following methods are overriden by the class"
|
|
|
|
:: cname :: ":\n " :: slist)
|
|
|
|
| Method_override [] -> assert false
|
2006-04-04 19:28:13 -07:00
|
|
|
| Instance_variable_override lab ->
|
|
|
|
"the instance variable " ^ lab ^ " is overriden.\n" ^
|
|
|
|
"The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
|
1998-11-05 00:08:28 -08:00
|
|
|
| Partial_application ->
|
|
|
|
"this function application is partial,\n\
|
|
|
|
maybe some arguments are missing."
|
|
|
|
| Statement_type ->
|
|
|
|
"this expression should have type unit."
|
2004-11-30 10:57:04 -08:00
|
|
|
| Comment_start -> "this is the start of a comment."
|
|
|
|
| Comment_not_end -> "this is not the end of a comment."
|
2001-09-25 02:54:18 -07:00
|
|
|
| Deprecated -> "this syntax is deprecated."
|
2004-11-06 12:17:47 -08:00
|
|
|
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
|
2004-11-30 10:57:04 -08:00
|
|
|
| Illegal_backslash -> "illegal backslash escape in string."
|
|
|
|
| Implicit_public_methods l ->
|
|
|
|
"the following private methods were made public implicitly:\n "
|
|
|
|
^ String.concat " " l ^ "."
|
|
|
|
| Unerasable_optional_argument -> "this optional argument cannot be erased."
|
|
|
|
| Undeclared_virtual_method m -> "the virtual method "^m^" is not declared."
|
|
|
|
| Not_principal s -> s^" is not principal."
|
|
|
|
| Without_principality s -> s^" without principality."
|
|
|
|
| Unused_argument -> "this argument will not be used by the function."
|
2006-04-16 16:28:22 -07:00
|
|
|
| Nonreturning_statement ->
|
|
|
|
"this statement never returns (or has an unsound type.)"
|
2004-11-30 10:57:04 -08:00
|
|
|
| Camlp4 s -> s
|
|
|
|
| All_clauses_guarded ->
|
|
|
|
"bad style, all clauses in this pattern-matching are guarded."
|
2005-09-14 20:09:26 -07:00
|
|
|
| Useless_record_with ->
|
|
|
|
"this record is defined by a `with' expression,\n\
|
|
|
|
but no fields are borrowed from the original."
|
1998-11-05 00:08:28 -08:00
|
|
|
;;
|
2000-08-23 10:13:17 -07:00
|
|
|
|
|
|
|
let nerrors = ref 0;;
|
|
|
|
|
|
|
|
let print ppf w =
|
2000-10-26 06:38:43 -07:00
|
|
|
let msg = message w in
|
2004-11-10 04:47:20 -08:00
|
|
|
let flag = Char.uppercase (letter w) in
|
2000-10-26 06:38:43 -07:00
|
|
|
let newlines = ref 0 in
|
|
|
|
for i = 0 to String.length msg - 1 do
|
|
|
|
if msg.[i] = '\n' then incr newlines;
|
|
|
|
done;
|
2000-10-31 06:55:30 -08:00
|
|
|
let (out, flush, newline, space) =
|
|
|
|
Format.pp_get_all_formatter_output_functions ppf ()
|
|
|
|
in
|
|
|
|
let countnewline x = incr newlines; newline x in
|
|
|
|
Format.pp_set_all_formatter_output_functions ppf out flush countnewline space;
|
2004-11-10 04:47:20 -08:00
|
|
|
Format.fprintf ppf "%c: %s" flag msg;
|
2000-10-31 06:55:30 -08:00
|
|
|
Format.pp_print_flush ppf ();
|
|
|
|
Format.pp_set_all_formatter_output_functions ppf out flush newline space;
|
2000-08-23 10:13:17 -07:00
|
|
|
let (n, _) = translate (letter w) in
|
|
|
|
if error.(n) then incr nerrors;
|
2000-10-26 06:38:43 -07:00
|
|
|
!newlines
|
2000-08-23 10:13:17 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
exception Errors of int;;
|
|
|
|
|
|
|
|
let check_fatal () =
|
|
|
|
if !nerrors > 0 then begin
|
|
|
|
let e = Errors !nerrors in
|
|
|
|
nerrors := 0;
|
|
|
|
raise e;
|
|
|
|
end;
|
|
|
|
;;
|