extend warning 3 to other deprecated features: Latin1, (&) and (or)

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13706 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 2013-05-28 11:05:58 +00:00
parent 2b5ba03cf7
commit e69730e0d6
7 changed files with 57 additions and 27 deletions

View File

@ -31,6 +31,9 @@ Compilers:
bytecode executable can be loaded on 32-bit hosts.
- PR#5980: warning on open statements which shadow an existing identifier
(if it is actually used in the scope of the open)
* warning 3 is extended to warn about other deprecated features:
- ISO-latin1 characters in identifiers
- uses of the (&) and (or) operators instead of (&&) and (||)
Standard library:
- PR#5986: new flag Marshal.Compat_32 for the serialization functions

View File

@ -1,4 +1,4 @@
4.01.0+dev14-2013-05-22
4.01.0+dev15-2013-05-28
# The version string is the first line of this file.
# It must be in the format described in stdlib/sys.mli

View File

@ -641,7 +641,8 @@ and transl_exp0 e =
transl_function e.exp_loc !Clflags.native_code repr partial pl)
in
Lfunction(kind, params, body)
| Texp_apply({exp_desc = Texp_ident(path, _, {val_kind = Val_prim p})}, oargs)
| Texp_apply({exp_desc = Texp_ident(path, _, {val_kind = Val_prim p})} as fn,
oargs)
when List.length oargs >= p.prim_arity
&& List.for_all (fun (_, arg,_) -> arg <> None) oargs ->
let args, args' = cut p.prim_arity oargs in
@ -666,6 +667,12 @@ and transl_exp0 e =
wrap (Lsend(Cached, meth, obj, [cache; pos], e.exp_loc))
| _ -> assert false
else begin
if p.prim_name = "%sequand" && Path.last path = "&" then
Location.prerr_warning fn.exp_loc
(Warnings.Deprecated "operator (&); you should use (&&) instead");
if p.prim_name = "%sequor" && Path.last path = "or" then
Location.prerr_warning fn.exp_loc
(Warnings.Deprecated "operator (or); you should use (||) instead");
let prim = transl_prim e.exp_loc p args in
match (prim, args) with
(Praise, [arg1]) ->

View File

@ -188,6 +188,16 @@ let remove_underscores s =
| c -> s.[dst] <- c; remove (src + 1) (dst + 1)
in remove 0 0
(* recover the name from a LABEL or OPTLABEL token *)
let get_label_name lexbuf =
let s = Lexing.lexeme lexbuf in
let name = String.sub s 1 (String.length s - 2) in
if Hashtbl.mem keyword_table name then
raise (Error(Keyword_as_label name, Location.curr lexbuf));
name
;;
(* Update the current location with file name and line number. *)
let update_loc lexbuf file line absolute chars =
@ -203,6 +213,13 @@ let update_loc lexbuf file line absolute chars =
}
;;
(* Warn about Latin-1 characters used in idents *)
let warn_latin1 lexbuf =
Location.prerr_warning (Location.curr lexbuf)
(Warnings.Deprecated "ISO-Latin1 characters in identifiers")
;;
(* Error report *)
open Format
@ -229,9 +246,12 @@ let report_error ppf = function
let newline = ('\010' | "\013\010" )
let blank = [' ' '\009' '\012']
let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_']
let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222']
let identchar =
let lowercase = ['a'-'z' '_']
let uppercase = ['A'-'Z']
let identchar = ['A'-'Z' 'a'-'z' '_' '\'' '0'-'9']
let lowercase_latin1 = ['a'-'z' '\223'-'\246' '\248'-'\255' '_']
let uppercase_latin1 = ['A'-'Z' '\192'-'\214' '\216'-'\222']
let identchar_latin1 =
['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9']
let symbolchar =
['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~']
@ -262,26 +282,25 @@ rule token = parse
| "~"
{ TILDE }
| "~" lowercase identchar * ':'
{ let s = Lexing.lexeme lexbuf in
let name = String.sub s 1 (String.length s - 2) in
if Hashtbl.mem keyword_table name then
raise (Error(Keyword_as_label name, Location.curr lexbuf));
LABEL name }
| "?" { QUESTION }
{ LABEL (get_label_name lexbuf) }
| "~" lowercase_latin1 identchar_latin1 * ':'
{ warn_latin1 lexbuf; LABEL (get_label_name lexbuf) }
| "?"
{ QUESTION }
| "?" lowercase identchar * ':'
{ let s = Lexing.lexeme lexbuf in
let name = String.sub s 1 (String.length s - 2) in
if Hashtbl.mem keyword_table name then
raise (Error(Keyword_as_label name, Location.curr lexbuf));
OPTLABEL name }
{ OPTLABEL (get_label_name lexbuf) }
| "?" lowercase_latin1 identchar_latin1 * ':'
{ warn_latin1 lexbuf; OPTLABEL (get_label_name lexbuf) }
| lowercase identchar *
{ let s = Lexing.lexeme lexbuf in
try
Hashtbl.find keyword_table s
with Not_found ->
LIDENT s }
try Hashtbl.find keyword_table s
with Not_found -> LIDENT s }
| lowercase_latin1 identchar_latin1 *
{ warn_latin1 lexbuf; LIDENT (Lexing.lexeme lexbuf) }
| uppercase identchar *
{ UIDENT(Lexing.lexeme lexbuf) } (* No capitalized keywords *)
| uppercase_latin1 identchar_latin1 *
{ warn_latin1 lexbuf; UIDENT(Lexing.lexeme lexbuf) }
| int_literal
{ try
INT (cvt_int_literal (Lexing.lexeme lexbuf))

View File

@ -310,7 +310,8 @@ let rec transl_type env policy styp =
check (Env.find_type path env)
| _ -> raise Not_found
in check decl;
Location.prerr_warning styp.ptyp_loc Warnings.Deprecated;
Location.prerr_warning styp.ptyp_loc
(Warnings.Deprecated "old syntax for polymorphic variant type");
(path, decl,true)
with Not_found -> try
if present <> [] then raise Not_found;
@ -327,7 +328,7 @@ let rec transl_type env policy styp =
in
if List.length stl <> decl.type_arity then
raise(Error(styp.ptyp_loc, env,
Type_arity_mismatch(lid.txt, decl.type_arity,
Type_arity_mismatch(lid.txt, decl.type_arity,
List.length stl)));
let args = List.map (transl_type env policy) stl in
let params = instance_list decl.type_params in

View File

@ -20,7 +20,7 @@
type t =
| Comment_start (* 1 *)
| Comment_not_end (* 2 *)
| Deprecated (* 3 *)
| Deprecated of string (* 3 *)
| Fragile_match of string (* 4 *)
| Partial_application (* 5 *)
| Labels_omitted (* 6 *)
@ -73,7 +73,7 @@ type t =
let number = function
| Comment_start -> 1
| Comment_not_end -> 2
| Deprecated -> 3
| Deprecated _ -> 3
| Fragile_match _ -> 4
| Partial_application -> 5
| Labels_omitted -> 6
@ -221,7 +221,7 @@ let () = parse_options true defaults_warn_error;;
let message = function
| 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."
| Deprecated s -> "deprecated feature: " ^ s
| Fragile_match "" ->
"this pattern-matching is fragile."
| Fragile_match s ->
@ -375,7 +375,7 @@ let descriptions =
[
1, "Suspicious-looking start-of-comment mark.";
2, "Suspicious-looking end-of-comment mark.";
3, "Deprecated syntax.";
3, "Deprecated feature.";
4, "Fragile pattern matching: matching that will remain complete even\n\
\ if additional constructors are added to one of the variant types\n\
\ matched.";

View File

@ -15,7 +15,7 @@ open Format
type t =
| Comment_start (* 1 *)
| Comment_not_end (* 2 *)
| Deprecated (* 3 *)
| Deprecated of string (* 3 *)
| Fragile_match of string (* 4 *)
| Partial_application (* 5 *)
| Labels_omitted (* 6 *)