Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur ocaml-4.00.1/typing/typecore.ml ocaml-4.00.1-format-check/typing/typecore.ml
- --- ocaml-4.00.1/typing/typecore.ml 2013-03-13 00:54:14.000000000 +0100
- +++ ocaml-4.00.1-format-check/typing/typecore.ml 2013-03-13 01:25:46.000000000 +0100
- @@ -37,6 +37,11 @@
- | Label_not_mutable of Longident.t
- | Incomplete_format of string
- | Bad_conversion of string * int * char
- + | Incompatible_flags of string * int * char * char
- + | Bad_conversion_flag of string * int * char * char
- + | Unexpected_width of string * int
- + | Unexpected_precision of string * int
- + | Size_overflow of string * int
- | Undefined_method of type_expr * string
- | Undefined_inherited_method of string
- | Virtual_class of Longident.t
- @@ -1088,6 +1093,16 @@
- raise (Error (loc, Bad_conversion (fmt, i, c))) in
- let incomplete_format fmt =
- raise (Error (loc, Incomplete_format fmt)) in
- + let size_overflow fmt i =
- + raise (Error (loc, Size_overflow (fmt, i))) in
- + let incompatible_flags fmt i f1 f2 =
- + raise (Error (loc, Incompatible_flags (fmt, i, f1, f2))) in
- + let bad_conversion_flag f c fmt i =
- + raise (Error (loc, Bad_conversion_flag (fmt, i, c, f))) in
- + let unexpected_width fmt i =
- + raise (Error (loc, Unexpected_width (fmt, i))) in
- + let unexpected_precision fmt i =
- + raise (Error (loc, Unexpected_precision (fmt, i))) in
- let rec type_in_format fmt =
- @@ -1098,6 +1113,29 @@
- and ty_aresult = newvar ()
- and ty_uresult = newvar () in
- + let zero_flag = ref false
- + and plus_flag = ref false
- + and minus_flag = ref false
- + and width_flag = ref false
- + and prec_flag = ref false in
- +
- + let rec check_flags valid_flags fmt i j =
- + let check (flag_ref, flag_char, error) =
- + if !flag_ref && not (List.mem flag_char valid_flags) then
- + error fmt i;
- + flag_ref := false;
- + in
- + if !zero_flag && !minus_flag then incompatible_flags fmt i '-' '0';
- + if !minus_flag && not !width_flag then incompatible_flags fmt i '-' 'W';
- + if !zero_flag && not !width_flag then incompatible_flags fmt i '0' 'W';
- + List.iter check [
- + (zero_flag, '0', bad_conversion_flag '0' fmt.[j]);
- + (plus_flag, '+', bad_conversion_flag '+' fmt.[j]);
- + (minus_flag, '-', bad_conversion_flag '-' fmt.[j]);
- + (width_flag, 'w', unexpected_width);
- + (prec_flag, '.', unexpected_precision);
- + ] in
- +
- let meta = ref 0 in
- let rec scan_format i =
- @@ -1117,13 +1155,24 @@
- let rec scan_flags i j =
- if j >= len then incomplete_format fmt else
- match fmt.[j] with
- - | '#' | '0' | '-' | ' ' | '+' -> scan_flags i (j + 1)
- + | '#' | ' ' -> scan_flags i (j + 1)
- + | '0' -> zero_flag := true; scan_flags i (j + 1)
- + | '+' -> plus_flag := true; scan_flags i (j + 1)
- + | '-' -> minus_flag := true; scan_flags i (j + 1)
- | _ -> scan_width i j
- - and scan_width i j = scan_width_or_prec_value scan_precision i j
- - and scan_decimal_string scan i j =
- + and scan_width i j =
- + if j >= len then incomplete_format fmt else
- + match fmt.[j] with
- + | '*' | '0' .. '9' ->
- + width_flag := true;
- + scan_width_or_prec_value scan_precision i j
- + | _ ->
- + scan_precision i j
- + and scan_decimal_string scan i j digit_nb =
- if j >= len then incomplete_format fmt else
- + if digit_nb > 9 then size_overflow fmt i else
- match fmt.[j] with
- - | '0' .. '9' -> scan_decimal_string scan i (j + 1)
- + | '0' .. '9' -> scan_decimal_string scan i (j + 1) (digit_nb + 1)
- | _ -> scan i j
- and scan_width_or_prec_value scan i j =
- if j >= len then incomplete_format fmt else
- @@ -1131,12 +1180,13 @@
- | '*' ->
- let ty_uresult, ty_result = scan i (j + 1) in
- ty_uresult, ty_arrow Predef.type_int ty_result
- - | '-' | '+' -> scan_decimal_string scan i (j + 1)
- - | _ -> scan_decimal_string scan i j
- + | _ -> scan_decimal_string scan i j 0
- and scan_precision i j =
- if j >= len then incomplete_format fmt else
- match fmt.[j] with
- - | '.' -> scan_width_or_prec_value scan_conversion i (j + 1)
- + | '.' ->
- + prec_flag := true;
- + scan_width_or_prec_value scan_conversion i (j + 1)
- | _ -> scan_conversion i j
- and scan_indication j =
- if j >= len then j - 1 else
- @@ -1199,20 +1249,36 @@
- and scan_conversion i j =
- if j >= len then incomplete_format fmt else
- match fmt.[j] with
- - | '%' | '@' | '!' | ',' -> scan_format (j + 1)
- + | '%' | '@' | '!' | ',' ->
- + check_flags [] fmt i j;
- + scan_format (j + 1)
- | 's' | 'S' ->
- + check_flags [ '-' ; 'w' ; '.' ] fmt i j;
- let j = scan_indication (j + 1) in
- conversion j Predef.type_string
- | '[' ->
- + check_flags [] fmt i j;
- let j = scan_range (j + 1) in
- let j = scan_indication (j + 1) in
- conversion j Predef.type_string
- - | 'c' | 'C' -> conversion j Predef.type_char
- + | 'c' | 'C' ->
- + check_flags [] fmt i j;
- + conversion j Predef.type_char
- | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' | 'N' ->
- + if !zero_flag && !prec_flag then incompatible_flags fmt i '0' '.';
- + check_flags [ '0' ; '+' ; '-' ; 'w' ; '.' ] fmt i j;
- conversion j Predef.type_int
- - | 'f' | 'e' | 'E' | 'g' | 'G' | 'F' -> conversion j Predef.type_float
- - | 'B' | 'b' -> conversion j Predef.type_bool
- + | 'f' | 'e' | 'E' | 'g' | 'G' ->
- + check_flags [ '0' ; '+' ; '-' ; 'w' ; '.' ] fmt i j;
- + conversion j Predef.type_float
- + | 'F' ->
- + check_flags [] fmt i j;
- + conversion j Predef.type_float
- + | 'B' | 'b' ->
- + check_flags [] fmt i j;
- + conversion j Predef.type_bool
- | 'a' | 'r' as conv ->
- + check_flags [] fmt i j;
- let conversion =
- if conv = 'a' then conversion_a else conversion_r in
- let ty_e = newvar () in
- @@ -1232,8 +1298,12 @@
- | 'l' | 'L' -> conversion_r j ty_e (Pref.type_list ty_e)
- | 'o' | 'O' -> conversion_r j ty_e (Pref.type_option ty_e)
- | _ -> conversion_r (j - 1) ty_e ty_e end *)
- - | 't' -> conversion j (ty_arrow ty_input ty_aresult)
- + | 't' ->
- + check_flags [] fmt i j;
- + conversion j (ty_arrow ty_input ty_aresult)
- | 'l' | 'n' | 'L' as c ->
- + if !zero_flag && !prec_flag then incompatible_flags fmt i '0' '.';
- + check_flags [ '0' ; '+' ; '-' ; 'w' ; '.' ] fmt i j;
- let j = j + 1 in
- if j >= len then conversion (j - 1) Predef.type_int else begin
- match fmt.[j] with
- @@ -1247,6 +1317,7 @@
- | c -> conversion (j - 1) Predef.type_int
- end
- | '{' | '(' as c ->
- + check_flags [] fmt i j;
- let j = j + 1 in
- if j >= len then incomplete_format fmt else
- let sj =
- @@ -3105,11 +3176,35 @@
- | Label_not_mutable lid ->
- fprintf ppf "The record field label %a is not mutable" longident lid
- | Incomplete_format s ->
- - fprintf ppf "Premature end of format string ``%S''" s
- + fprintf ppf "Premature end of format string %S" s
- | Bad_conversion (fmt, i, c) ->
- fprintf ppf
- "Bad conversion %%%c, at char number %d \
- - in format string ``%s''" c i fmt
- + in format string %S" c i fmt
- + | Bad_conversion_flag (fmt, i, c, flag) ->
- + fprintf ppf
- + "Bad conversion %%%c%c, at char number %d \
- + in format string %S" flag c i fmt
- + | Incompatible_flags (fmt, i, flag, 'W') ->
- + fprintf ppf
- + "Flag %C invalid without width, at char number %d in format string %S"
- + flag i fmt
- + | Incompatible_flags (fmt, i, flag, '.') ->
- + fprintf ppf
- + "Incompatible flag %C with precision, at char number %d in format \
- + string %S" flag i fmt
- + | Incompatible_flags (fmt, i, flag1, flag2) ->
- + fprintf ppf
- + "Incompatible flags %C and %C, at char number %d in format string %S"
- + flag1 flag2 i fmt
- + | Unexpected_width (fmt, i) ->
- + fprintf ppf "Unexpected width, at char number %d in format string %S"
- + i fmt
- + | Unexpected_precision (fmt, i) ->
- + fprintf ppf "Unexpected precision, at char number %d in format string %S"
- + i fmt
- + | Size_overflow (fmt, i) ->
- + fprintf ppf "Size overflow, at char number %d in format string %S" i fmt
- | Undefined_method (ty, me) ->
- reset_and_mark_loops ty;
- fprintf ppf
- diff -Naur ocaml-4.00.1/typing/typecore.mli ocaml-4.00.1-format-check/typing/typecore.mli
- --- ocaml-4.00.1/typing/typecore.mli 2013-03-13 00:54:14.000000000 +0100
- +++ ocaml-4.00.1-format-check/typing/typecore.mli 2013-03-13 00:53:51.000000000 +0100
- @@ -79,6 +79,11 @@
- | Label_not_mutable of Longident.t
- | Incomplete_format of string
- | Bad_conversion of string * int * char
- + | Incompatible_flags of string * int * char * char
- + | Bad_conversion_flag of string * int * char * char
- + | Unexpected_width of string * int
- + | Unexpected_precision of string * int
- + | Size_overflow of string * int
- | Undefined_method of type_expr * string
- | Undefined_inherited_method of string
- | Virtual_class of Longident.t
Add Comment
Please, Sign In to add comment