summaryrefslogtreecommitdiff
path: root/utils/warnings.ml
blob: 3deaca92a8c374c0565234ac6fc479480945f377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            Pierre Weis && Damien Doligez, INRIA Rocquencourt        *)
(*                                                                     *)
(*  Copyright 1998 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the Q Public License version 1.0.               *)
(*                                                                     *)
(***********************************************************************)

(* $Id$ *)

type t =
  | Partial_match of string          (* P *)
  | Unused_match                     (* U *)
  | Method_override of string list   (* M *)
  | Hide_instance_variable of string (* V *)
  | Partial_application              (* F *)
  | Statement_type                   (* S *)
  | Comment of string                (* C *)
  | Other of string                  (* X *)
;;

let pflag = ref true;;
let uflag = ref true;;
let mflag = ref true;;
let vflag = ref true;;
let fflag = ref true;;
let sflag = ref true;;
let cflag = ref true;;
let xflag = ref true;;

let rec parse_options s =
  for i = 0 to String.length s - 1 do
    match s.[i] with
    | 'P' -> pflag := true
    | 'p' -> pflag := false
    | 'U' -> uflag := true
    | 'u' -> uflag := false
    | 'M' -> mflag := true
    | 'm' -> mflag := false
    | 'V' -> vflag := true
    | 'v' -> vflag := false
    | 'F' -> fflag := true
    | 'f' -> fflag := false
    | 'S' -> sflag := true
    | 's' -> sflag := false
    | 'C' -> cflag := true
    | 'c' -> cflag := false
    | 'X' -> xflag := true
    | 'x' -> xflag := false
    | 'A' -> parse_options "PUMVFSX"
    | 'a' -> parse_options "pumvfsx"
    | c -> raise (Arg.Bad (Printf.sprintf "unknown warning option %c" c))
  done
;;

let is_active = function
  | Partial_match _ -> !pflag
  | Unused_match -> !uflag
  | Method_override _ -> !mflag
  | Hide_instance_variable _ -> !vflag
  | Partial_application -> !fflag
  | Statement_type -> !sflag
  | Comment _ -> !cflag
  | Other _ -> !xflag
;;

let message = function
  | 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
  | Unused_match -> "this match case is unused."
  | Method_override slist ->
      String.concat " "
        ("the following methods are overriden \
          by the inherited class:\n " :: slist)
  | Hide_instance_variable lab ->
      "this definition of an instance variable " ^ lab ^
      " hides a previously\ndefined instance variable of the same name."
  | Partial_application ->
      "this function application is partial,\n\
       maybe some arguments are missing."
  | Statement_type ->
      "this expression should have type unit."
  | Comment s -> "this is " ^ s ^ "."
  | Other s -> s
;;