1998-11-05 00:08:28 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1998-11-05 00:08:28 -08:00
|
|
|
(* *)
|
|
|
|
(* 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
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
(* When you change this, you need to update the documentation:
|
|
|
|
- man/ocamlc.m in ocaml
|
|
|
|
- man/ocamlopt.m in ocaml
|
|
|
|
- manual/cmds/comp.etex in the doc sources
|
|
|
|
- manual/cmds/native.etex in the doc sources
|
|
|
|
*)
|
1998-11-05 00:08:28 -08:00
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
type t =
|
|
|
|
| Comment_start (* 1 *)
|
|
|
|
| Comment_not_end (* 2 *)
|
|
|
|
| Deprecated (* 3 *)
|
|
|
|
| Fragile_match of string (* 4 *)
|
|
|
|
| Partial_application (* 5 *)
|
|
|
|
| Labels_omitted (* 6 *)
|
|
|
|
| Method_override of string list (* 7 *)
|
|
|
|
| Partial_match of string (* 8 *)
|
|
|
|
| Non_closed_record_pattern of string (* 9 *)
|
|
|
|
| Statement_type (* 10 *)
|
|
|
|
| Unused_match (* 11 *)
|
|
|
|
| Unused_pat (* 12 *)
|
2010-04-07 20:58:41 -07:00
|
|
|
| Instance_variable_override of string list (* 13 *)
|
2009-11-02 04:17:49 -08:00
|
|
|
| Illegal_backslash (* 14 *)
|
|
|
|
| Implicit_public_methods of string list (* 15 *)
|
|
|
|
| Unerasable_optional_argument (* 16 *)
|
|
|
|
| Undeclared_virtual_method of string (* 17 *)
|
|
|
|
| Not_principal of string (* 18 *)
|
|
|
|
| Without_principality of string (* 19 *)
|
|
|
|
| Unused_argument (* 20 *)
|
|
|
|
| Nonreturning_statement (* 21 *)
|
|
|
|
| Camlp4 of string (* 22 *)
|
2010-01-29 07:02:39 -08:00
|
|
|
| Useless_record_with (* 23 *)
|
|
|
|
| Bad_module_name of string (* 24 *)
|
|
|
|
| All_clauses_guarded (* 25 *)
|
2009-11-02 04:17:49 -08:00
|
|
|
| Unused_var of string (* 26 *)
|
|
|
|
| Unused_var_strict of string (* 27 *)
|
2009-11-19 04:27:15 -08:00
|
|
|
| Wildcard_arg_to_constant_constr (* 28 *)
|
2010-01-07 07:15:07 -08:00
|
|
|
| Eol_in_string (* 29 *)
|
2010-04-29 23:26:51 -07:00
|
|
|
| Duplicate_definitions of string * string * string * string (*30 *)
|
2012-01-17 13:57:54 -08:00
|
|
|
| Multiple_definition of string * string * string (* 31 *)
|
2012-01-18 00:31:11 -08:00
|
|
|
| Unused_value_declaration of string (* 32 *)
|
|
|
|
| Unused_open of string (* 33 *)
|
|
|
|
| Unused_type_declaration of string (* 34 *)
|
|
|
|
| Unused_for_index of string (* 35 *)
|
|
|
|
| Unused_ancestor of string (* 36 *)
|
2012-04-18 02:01:17 -07:00
|
|
|
| Unused_constructor of string * bool * bool (* 37 *)
|
|
|
|
| Unused_exception of string * bool (* 38 *)
|
2012-05-29 05:30:49 -07:00
|
|
|
| Unused_rec_flag (* 39 *)
|
2013-04-26 06:09:24 -07:00
|
|
|
| Name_out_of_scope of string * string list * bool (* 40 *)
|
2013-03-12 07:56:15 -07:00
|
|
|
| Ambiguous_name of string list * string list * bool (* 41 *)
|
2013-02-18 18:45:09 -08:00
|
|
|
| Disambiguated_name of string (* 42 *)
|
2013-02-18 19:12:36 -08:00
|
|
|
| Nonoptional_label of string (* 43 *)
|
2013-05-16 05:36:15 -07:00
|
|
|
| Open_shadow_identifier of string * string (* 44 *)
|
1999-12-23 10:02:58 -08:00
|
|
|
;;
|
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
(* If you remove a warning, leave a hole in the numbering. NEVER change
|
|
|
|
the numbers of existing warnings.
|
|
|
|
If you add a new warning, add it at the end with a new number;
|
|
|
|
do NOT reuse one of the holes.
|
|
|
|
*)
|
1999-12-23 10:02:58 -08:00
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
let number = function
|
|
|
|
| Comment_start -> 1
|
|
|
|
| Comment_not_end -> 2
|
|
|
|
| Deprecated -> 3
|
|
|
|
| Fragile_match _ -> 4
|
|
|
|
| Partial_application -> 5
|
|
|
|
| Labels_omitted -> 6
|
|
|
|
| Method_override _ -> 7
|
|
|
|
| Partial_match _ -> 8
|
|
|
|
| Non_closed_record_pattern _ -> 9
|
|
|
|
| Statement_type -> 10
|
|
|
|
| Unused_match -> 11
|
|
|
|
| Unused_pat -> 12
|
|
|
|
| Instance_variable_override _ -> 13
|
|
|
|
| Illegal_backslash -> 14
|
|
|
|
| Implicit_public_methods _ -> 15
|
|
|
|
| Unerasable_optional_argument -> 16
|
|
|
|
| Undeclared_virtual_method _ -> 17
|
|
|
|
| Not_principal _ -> 18
|
|
|
|
| Without_principality _ -> 19
|
|
|
|
| Unused_argument -> 20
|
|
|
|
| Nonreturning_statement -> 21
|
|
|
|
| Camlp4 _ -> 22
|
|
|
|
| Useless_record_with -> 23
|
|
|
|
| Bad_module_name _ -> 24
|
|
|
|
| All_clauses_guarded -> 25
|
|
|
|
| Unused_var _ -> 26
|
|
|
|
| Unused_var_strict _ -> 27
|
2009-11-19 04:27:15 -08:00
|
|
|
| Wildcard_arg_to_constant_constr -> 28
|
2010-01-07 07:15:07 -08:00
|
|
|
| Eol_in_string -> 29
|
2010-04-29 23:26:51 -07:00
|
|
|
| Duplicate_definitions _ -> 30
|
2012-01-17 13:57:54 -08:00
|
|
|
| Multiple_definition _ -> 31
|
2012-01-18 00:31:11 -08:00
|
|
|
| Unused_value_declaration _ -> 32
|
|
|
|
| Unused_open _ -> 33
|
|
|
|
| Unused_type_declaration _ -> 34
|
|
|
|
| Unused_for_index _ -> 35
|
|
|
|
| Unused_ancestor _ -> 36
|
|
|
|
| Unused_constructor _ -> 37
|
2012-03-06 11:47:07 -08:00
|
|
|
| Unused_exception _ -> 38
|
2012-05-29 05:30:49 -07:00
|
|
|
| Unused_rec_flag -> 39
|
2012-10-29 00:54:06 -07:00
|
|
|
| Name_out_of_scope _ -> 40
|
|
|
|
| Ambiguous_name _ -> 41
|
2013-02-18 18:45:09 -08:00
|
|
|
| Disambiguated_name _ -> 42
|
2013-02-18 19:12:36 -08:00
|
|
|
| Nonoptional_label _ -> 43
|
2013-05-16 05:36:15 -07:00
|
|
|
| Open_shadow_identifier _ -> 44
|
1999-12-23 10:02:58 -08:00
|
|
|
;;
|
1998-11-05 00:08:28 -08:00
|
|
|
|
2013-05-16 05:36:15 -07:00
|
|
|
let last_warning_number = 44
|
2009-11-02 04:17:49 -08:00
|
|
|
(* Must be the max number returned by the [number] function. *)
|
2000-08-23 10:13:17 -07:00
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
let letter = function
|
|
|
|
| 'a' ->
|
|
|
|
let rec loop i = if i = 0 then [] else i :: loop (i - 1) in
|
|
|
|
loop last_warning_number
|
|
|
|
| 'b' -> []
|
|
|
|
| 'c' -> [1; 2]
|
|
|
|
| 'd' -> [3]
|
|
|
|
| 'e' -> [4]
|
|
|
|
| 'f' -> [5]
|
|
|
|
| 'g' -> []
|
|
|
|
| 'h' -> []
|
|
|
|
| 'i' -> []
|
|
|
|
| 'j' -> []
|
2012-05-29 05:30:49 -07:00
|
|
|
| 'k' -> [32; 33; 34; 35; 36; 37; 38; 39]
|
2009-11-02 04:17:49 -08:00
|
|
|
| 'l' -> [6]
|
|
|
|
| 'm' -> [7]
|
|
|
|
| 'n' -> []
|
|
|
|
| 'o' -> []
|
|
|
|
| 'p' -> [8]
|
|
|
|
| 'q' -> []
|
|
|
|
| 'r' -> [9]
|
|
|
|
| 's' -> [10]
|
|
|
|
| 't' -> []
|
|
|
|
| 'u' -> [11; 12]
|
|
|
|
| 'v' -> [13]
|
|
|
|
| 'w' -> []
|
2010-04-29 23:26:51 -07:00
|
|
|
| 'x' -> [14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 30]
|
2009-11-02 04:17:49 -08:00
|
|
|
| 'y' -> [26]
|
|
|
|
| 'z' -> [27]
|
|
|
|
| _ -> assert false
|
2000-08-23 10:13:17 -07:00
|
|
|
;;
|
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
let active = Array.create (last_warning_number + 1) true;;
|
|
|
|
let error = Array.create (last_warning_number + 1) false;;
|
|
|
|
|
|
|
|
let is_active x = active.(number x);;
|
|
|
|
let is_error x = error.(number x);;
|
|
|
|
|
|
|
|
let parse_opt flags s =
|
|
|
|
let set i = flags.(i) <- true in
|
|
|
|
let clear i = flags.(i) <- false in
|
|
|
|
let set_all i = active.(i) <- true; error.(i) <- true in
|
2009-12-22 08:31:46 -08:00
|
|
|
let error () = raise (Arg.Bad "Ill-formed list of warnings") in
|
2010-05-04 10:39:17 -07:00
|
|
|
let rec get_num n i =
|
|
|
|
if i >= String.length s then i, n
|
|
|
|
else match s.[i] with
|
|
|
|
| '0'..'9' -> get_num (10 * n + Char.code s.[i] - Char.code '0') (i + 1)
|
|
|
|
| _ -> i, n
|
|
|
|
in
|
|
|
|
let get_range i =
|
|
|
|
let i, n1 = get_num 0 i in
|
|
|
|
if i + 2 < String.length s && s.[i] = '.' && s.[i + 1] = '.' then
|
|
|
|
let i, n2 = get_num 0 (i + 2) in
|
|
|
|
if n2 < n1 then error ();
|
|
|
|
i, n1, n2
|
|
|
|
else
|
|
|
|
i, n1, n1
|
|
|
|
in
|
2009-11-02 04:17:49 -08:00
|
|
|
let rec loop i =
|
|
|
|
if i >= String.length s then () else
|
|
|
|
match s.[i] with
|
|
|
|
| 'A' .. 'Z' ->
|
|
|
|
List.iter set (letter (Char.lowercase s.[i]));
|
|
|
|
loop (i+1)
|
|
|
|
| 'a' .. 'z' ->
|
|
|
|
List.iter clear (letter s.[i]);
|
|
|
|
loop (i+1)
|
|
|
|
| '+' -> loop_letter_num set (i+1)
|
|
|
|
| '-' -> loop_letter_num clear (i+1)
|
|
|
|
| '@' -> loop_letter_num set_all (i+1)
|
|
|
|
| c -> error ()
|
|
|
|
and loop_letter_num myset i =
|
|
|
|
if i >= String.length s then error () else
|
|
|
|
match s.[i] with
|
2010-05-04 10:39:17 -07:00
|
|
|
| '0' .. '9' ->
|
|
|
|
let i, n1, n2 = get_range i in
|
|
|
|
for n = n1 to min n2 last_warning_number do myset n done;
|
|
|
|
loop i
|
2009-11-02 04:17:49 -08:00
|
|
|
| 'A' .. 'Z' ->
|
|
|
|
List.iter myset (letter (Char.lowercase s.[i]));
|
|
|
|
loop (i+1)
|
|
|
|
| 'a' .. 'z' ->
|
|
|
|
List.iter myset (letter s.[i]);
|
|
|
|
loop (i+1)
|
|
|
|
| _ -> error ()
|
|
|
|
in
|
|
|
|
loop 0
|
1998-11-05 00:08:28 -08:00
|
|
|
;;
|
|
|
|
|
2009-11-02 04:17:49 -08:00
|
|
|
let parse_options errflag s = parse_opt (if errflag then error else active) s;;
|
|
|
|
|
2010-05-04 10:45:43 -07:00
|
|
|
(* If you change these, don't forget to change them in man/ocamlc.m *)
|
2013-05-16 05:36:15 -07:00
|
|
|
let defaults_w = "+a-4-6-7-9-27-29-32..39-41..42-44";;
|
2009-11-02 04:17:49 -08:00
|
|
|
let defaults_warn_error = "-a";;
|
|
|
|
|
|
|
|
let () = parse_options false defaults_w;;
|
|
|
|
let () = parse_options true defaults_warn_error;;
|
2001-09-27 00:31:29 -07:00
|
|
|
|
1998-11-05 00:08:28 -08:00
|
|
|
let message = function
|
2010-01-29 07:02:39 -08:00
|
|
|
| Comment_start -> "this is the start of a comment."
|
|
|
|
| Comment_not_end -> "this is not the end of a comment."
|
|
|
|
| Deprecated -> "this syntax is deprecated."
|
2006-09-21 07:54:54 -07:00
|
|
|
| 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 ^ "."
|
2010-01-29 07:02:39 -08:00
|
|
|
| Partial_application ->
|
|
|
|
"this function application is partial,\n\
|
|
|
|
maybe some arguments are missing."
|
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] ->
|
2010-04-07 20:58:41 -07:00
|
|
|
"the method " ^ lab ^ " is overridden."
|
2006-06-12 00:33:14 -07:00
|
|
|
| Method_override (cname :: slist) ->
|
1998-11-05 00:08:28 -08:00
|
|
|
String.concat " "
|
2010-05-21 05:00:49 -07:00
|
|
|
("the following methods are overridden by the class"
|
2006-06-12 00:33:14 -07:00
|
|
|
:: cname :: ":\n " :: slist)
|
|
|
|
| Method_override [] -> assert false
|
2010-01-29 07:02:39 -08: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
|
|
|
|
| Non_closed_record_pattern s ->
|
|
|
|
"the following labels are not bound in this record pattern:\n" ^ s ^
|
2012-03-31 13:55:13 -07:00
|
|
|
"\nEither bind these labels explicitly or add '; _' to the pattern."
|
2010-01-29 07:02:39 -08:00
|
|
|
| Statement_type ->
|
|
|
|
"this expression should have type unit."
|
|
|
|
| Unused_match -> "this match case is unused."
|
|
|
|
| Unused_pat -> "this sub-pattern is unused."
|
2010-04-07 20:58:41 -07:00
|
|
|
| Instance_variable_override [lab] ->
|
2009-11-02 04:17:49 -08:00
|
|
|
"the instance variable " ^ lab ^ " is overridden.\n" ^
|
2006-04-04 19:28:13 -07:00
|
|
|
"The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
|
2010-04-07 20:58:41 -07:00
|
|
|
| Instance_variable_override (cname :: slist) ->
|
|
|
|
String.concat " "
|
2010-05-21 05:00:49 -07:00
|
|
|
("the following instance variables are overridden by the class"
|
2010-04-07 20:58:41 -07:00
|
|
|
:: cname :: ":\n " :: slist) ^
|
|
|
|
"\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
|
|
|
|
| Instance_variable_override [] -> assert false
|
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
|
2005-09-14 20:09:26 -07:00
|
|
|
| Useless_record_with ->
|
2012-04-13 05:44:29 -07:00
|
|
|
"all the fields are explicitly listed in this record:\n\
|
2012-03-31 13:55:13 -07:00
|
|
|
the 'with' clause is useless."
|
2008-10-06 06:53:54 -07:00
|
|
|
| Bad_module_name (modname) ->
|
|
|
|
"bad source file name: \"" ^ modname ^ "\" is not a valid module name."
|
2010-01-29 07:02:39 -08:00
|
|
|
| All_clauses_guarded ->
|
|
|
|
"bad style, all clauses in this pattern-matching are guarded."
|
|
|
|
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
|
2009-11-19 04:27:15 -08:00
|
|
|
| Wildcard_arg_to_constant_constr ->
|
|
|
|
"wildcard pattern given as argument to a constant constructor"
|
2010-01-07 07:15:07 -08:00
|
|
|
| Eol_in_string ->
|
|
|
|
"unescaped end-of-line in a string constant (non-portable code)"
|
2010-04-29 23:26:51 -07:00
|
|
|
| Duplicate_definitions (kind, cname, tc1, tc2) ->
|
2010-04-30 07:41:57 -07:00
|
|
|
Printf.sprintf "the %s %s is defined in both types %s and %s."
|
2010-04-29 23:26:51 -07:00
|
|
|
kind cname tc1 tc2
|
2012-01-17 13:57:54 -08:00
|
|
|
| Multiple_definition(modname, file1, file2) ->
|
|
|
|
Printf.sprintf
|
|
|
|
"files %s and %s both define a module named %s"
|
|
|
|
file1 file2 modname
|
2011-12-21 07:40:54 -08:00
|
|
|
| Unused_value_declaration v -> "unused value " ^ v ^ "."
|
2011-12-22 03:04:20 -08:00
|
|
|
| Unused_open s -> "unused open " ^ s ^ "."
|
2011-12-22 07:42:40 -08:00
|
|
|
| Unused_type_declaration s -> "unused type " ^ s ^ "."
|
2011-12-29 09:49:58 -08:00
|
|
|
| Unused_for_index s -> "unused for-loop index " ^ s ^ "."
|
|
|
|
| Unused_ancestor s -> "unused ancestor variable " ^ s ^ "."
|
2012-04-18 02:01:17 -07:00
|
|
|
| Unused_constructor (s, false, false) -> "unused constructor " ^ s ^ "."
|
|
|
|
| Unused_constructor (s, true, _) ->
|
|
|
|
"constructor " ^ s ^
|
|
|
|
" is never used to build values.\n\
|
|
|
|
(However, this constructor appears in patterns.)"
|
|
|
|
| Unused_constructor (s, false, true) ->
|
|
|
|
"constructor " ^ s ^
|
|
|
|
" is never used to build values.\n\
|
2012-04-18 11:44:09 -07:00
|
|
|
Its type is exported as a private type."
|
2012-04-18 02:01:17 -07:00
|
|
|
| Unused_exception (s, false) ->
|
|
|
|
"unused exception constructor " ^ s ^ "."
|
|
|
|
| Unused_exception (s, true) ->
|
|
|
|
"exception constructor " ^ s ^
|
|
|
|
" is never raised or used to build values.\n\
|
|
|
|
(However, this constructor appears in patterns.)"
|
2012-05-29 05:30:49 -07:00
|
|
|
| Unused_rec_flag ->
|
|
|
|
"unused rec flag."
|
2013-04-26 06:09:24 -07:00
|
|
|
| Name_out_of_scope (ty, [nm], false) ->
|
|
|
|
nm ^ " was selected from type " ^ ty ^
|
|
|
|
".\nIt is not visible in the current scope, and will not \n\
|
|
|
|
be selected if the type becomes unknown."
|
|
|
|
| Name_out_of_scope (_, _, false) -> assert false
|
|
|
|
| Name_out_of_scope (ty, slist, true) ->
|
|
|
|
"this record of type "^ ty ^" contains fields that are \n\
|
|
|
|
not visible in the current scope: "
|
|
|
|
^ String.concat " " slist ^ ".\n\
|
|
|
|
They will not be selected if the type becomes unknown."
|
2013-03-12 07:56:15 -07:00
|
|
|
| Ambiguous_name ([s], tl, false) ->
|
|
|
|
s ^ " belongs to several types: " ^ String.concat " " tl ^
|
|
|
|
"\nThe first one was selected. Please disambiguate if this is wrong."
|
|
|
|
| Ambiguous_name (_, _, false) -> assert false
|
|
|
|
| Ambiguous_name (slist, tl, true) ->
|
|
|
|
"these field labels belong to several types: " ^
|
|
|
|
String.concat " " tl ^
|
|
|
|
"\nThe first one was selected. Please disambiguate if this is wrong."
|
2013-02-18 18:45:09 -08:00
|
|
|
| Disambiguated_name s ->
|
|
|
|
"this use of " ^ s ^ " required disambiguation."
|
2013-02-18 19:12:36 -08:00
|
|
|
| Nonoptional_label s ->
|
|
|
|
"the label " ^ s ^ " is not optional."
|
2013-05-16 05:36:15 -07:00
|
|
|
| Open_shadow_identifier (kind, s) ->
|
|
|
|
Printf.sprintf
|
|
|
|
"this open statement shadows the %s identifier %s (which is later used)"
|
|
|
|
kind s
|
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
|
2009-11-02 04:17:49 -08:00
|
|
|
let num = number 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;
|
2009-11-02 04:17:49 -08:00
|
|
|
Format.fprintf ppf "%d: %s" num 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;
|
2009-11-02 04:17:49 -08:00
|
|
|
if error.(num) 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;
|
|
|
|
;;
|
2010-05-04 11:44:38 -07:00
|
|
|
|
|
|
|
let descriptions =
|
|
|
|
[
|
2010-05-05 08:08:53 -07:00
|
|
|
1, "Suspicious-looking start-of-comment mark.";
|
|
|
|
2, "Suspicious-looking end-of-comment mark.";
|
|
|
|
3, "Deprecated syntax.";
|
|
|
|
4, "Fragile pattern matching: matching that will remain complete even\n\
|
|
|
|
\ if additional constructors are added to one of the variant types\n\
|
|
|
|
\ matched.";
|
|
|
|
5, "Partially applied function: expression whose result has function\n\
|
|
|
|
\ type and is ignored.";
|
|
|
|
6, "Label omitted in function application.";
|
2012-07-26 12:21:54 -07:00
|
|
|
7, "Method overridden.";
|
2010-05-05 08:08:53 -07:00
|
|
|
8, "Partial match: missing cases in pattern-matching.";
|
|
|
|
9, "Missing fields in a record pattern.";
|
|
|
|
10, "Expression on the left-hand side of a sequence that doesn't have type\n\
|
|
|
|
\ \"unit\" (and that is not a function, see warning number 5).";
|
2010-05-04 11:44:38 -07:00
|
|
|
11, "Redundant case in a pattern matching (unused match case).";
|
|
|
|
12, "Redundant sub-pattern in a pattern-matching.";
|
2012-07-26 12:21:54 -07:00
|
|
|
13, "Instance variable overridden.";
|
2010-05-04 11:44:38 -07:00
|
|
|
14, "Illegal backslash escape in a string constant.";
|
|
|
|
15, "Private method made public implicitly.";
|
|
|
|
16, "Unerasable optional argument.";
|
|
|
|
17, "Undeclared virtual method.";
|
|
|
|
18, "Non-principal type.";
|
|
|
|
19, "Type without principality.";
|
|
|
|
20, "Unused function argument.";
|
|
|
|
21, "Non-returning statement.";
|
|
|
|
22, "Camlp4 warning.";
|
|
|
|
23, "Useless record \"with\" clause.";
|
2012-02-23 11:15:09 -08:00
|
|
|
24, "Bad module name: the source file name is not a valid OCaml module \
|
|
|
|
name.";
|
2010-05-05 08:08:53 -07:00
|
|
|
25, "Pattern-matching with all clauses guarded. Exhaustiveness cannot be\n\
|
2012-02-23 11:15:09 -08:00
|
|
|
\ checked.";
|
|
|
|
26, "Suspicious unused variable: unused variable that is bound\n\
|
|
|
|
\ with \"let\" or \"as\", and doesn't start with an underscore (\"_\")\n\
|
|
|
|
\ character.";
|
2010-05-05 08:08:53 -07:00
|
|
|
27, "Innocuous unused variable: unused variable that is not bound with\n\
|
|
|
|
\ \"let\" nor \"as\", and doesn't start with an underscore (\"_\")\n\
|
|
|
|
\ character.";
|
2010-05-04 11:44:38 -07:00
|
|
|
28, "Wildcard pattern given as argument to a constant constructor.";
|
|
|
|
29, "Unescaped end-of-line in a string constant (non-portable code).";
|
2010-05-05 08:08:53 -07:00
|
|
|
30, "Two labels or constructors of the same name are defined in two\n\
|
|
|
|
\ mutually recursive types.";
|
2012-01-18 00:31:11 -08:00
|
|
|
31, "A module is linked twice in the same executable.";
|
|
|
|
32, "Unused value declaration.";
|
|
|
|
33, "Unused open statement.";
|
|
|
|
34, "Unused type declaration.";
|
|
|
|
35, "Unused for-loop index.";
|
|
|
|
36, "Unused ancestor variable.";
|
|
|
|
37, "Unused constructor.";
|
2012-03-06 11:47:07 -08:00
|
|
|
38, "Unused exception constructor.";
|
2012-05-29 05:30:49 -07:00
|
|
|
39, "Unused rec flag.";
|
2012-10-29 00:54:06 -07:00
|
|
|
40, "Constructor or label name used out of scope.";
|
|
|
|
41, "Ambiguous constructor or label name.";
|
2013-02-18 19:12:36 -08:00
|
|
|
42, "Disambiguated constructor or label name.";
|
|
|
|
43, "Nonoptional label applied as optional.";
|
2013-05-16 05:36:15 -07:00
|
|
|
44, "Open statement shadows an already defined identifier.";
|
2010-05-04 11:44:38 -07:00
|
|
|
]
|
2011-06-20 14:40:56 -07:00
|
|
|
;;
|
2010-05-04 11:44:38 -07:00
|
|
|
|
|
|
|
let help_warnings () =
|
|
|
|
List.iter (fun (i, s) -> Printf.printf "%3i %s\n" i s) descriptions;
|
2012-01-18 04:14:51 -08:00
|
|
|
print_endline " A All warnings.";
|
|
|
|
for i = Char.code 'b' to Char.code 'z' do
|
|
|
|
let c = Char.chr i in
|
|
|
|
match letter c with
|
|
|
|
| [] -> ()
|
|
|
|
| [n] ->
|
|
|
|
Printf.printf " %c Synonym for warning %i.\n" (Char.uppercase c) n
|
|
|
|
| l ->
|
|
|
|
Printf.printf " %c Set of warnings %s.\n"
|
|
|
|
(Char.uppercase c)
|
|
|
|
(String.concat ", " (List.map string_of_int l))
|
|
|
|
done;
|
2010-05-04 11:44:38 -07:00
|
|
|
exit 0
|
2011-06-20 14:40:56 -07:00
|
|
|
;;
|