Commit 9e933a8f authored by Armaël Guéneau's avatar Armaël Guéneau

Fix the generator for ocaml 4.06 and newer

parent 7f5679dc
......@@ -131,27 +131,20 @@ let str_cmp (s1:string) (s2:string) =
let str_starts_with p s =
let n = String.length p in
String.length s >= n
&& String.sub s 0 n = p
let str_replace char1 char2 s =
let s2 = String.copy s in
for i = 0 to pred (String.length s) do
if s2.[i] = char1 then s2.[i] <- char2;
done;
s2
String.length s >= n
&& String.sub s 0 n = p
let str_capitalize_1 s =
if String.length s <= 0 then s else
let s' = String.copy s in
s'.[0] <- Char.uppercase s.[0];
s'
let s' = Bytes.of_string s in
Bytes.set s' 0 (Char.uppercase s.[0]);
Bytes.unsafe_to_string s'
let str_capitalize_2 s =
if String.length s < 2 then s else
let s' = String.copy s in
s'.[1] <- Char.uppercase s.[1];
s'
let s' = Bytes.of_string s in
Bytes.set s' 1 (Char.uppercase s.[1]);
Bytes.unsafe_to_string s'
(**************************************************************)
......
......@@ -53,7 +53,6 @@ val list_index : 'a -> 'a list -> int
val str_cmp : string -> string -> int
val str_starts_with : string -> string -> bool
val str_replace : char -> char -> string -> string
(** Capitalize the first letter of a string (if any) *)
......
......@@ -62,8 +62,9 @@ let parse_file inputfile parse_fun ast_magic =
let ic = open_in_bin inputfile in
let is_ast_file =
try
let buffer = String.create (String.length ast_magic) in
really_input ic buffer 0 (String.length ast_magic);
let buffer =
really_input_string ic (String.length ast_magic)
in
if buffer = ast_magic then true
else if String.sub buffer 0 9 = String.sub ast_magic 0 9 then
raise Outdated_version
......
......@@ -96,7 +96,7 @@ let keyword_table =
(* To buffer string literals *)
let initial_string_buffer = String.create 256
let initial_string_buffer = Bytes.create 256
let string_buff = ref initial_string_buffer
let string_index = ref 0
......@@ -105,16 +105,16 @@ let reset_string_buffer () =
string_index := 0
let store_string_char c =
if !string_index >= String.length (!string_buff) then begin
let new_buff = String.create (String.length (!string_buff) * 2) in
String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff));
if !string_index >= Bytes.length (!string_buff) then begin
let new_buff = Bytes.create (Bytes.length (!string_buff) * 2) in
Bytes.blit (!string_buff) 0 new_buff 0 (Bytes.length (!string_buff));
string_buff := new_buff
end;
String.unsafe_set (!string_buff) (!string_index) c;
Bytes.unsafe_set (!string_buff) (!string_index) c;
incr string_index
let get_stored_string () =
let s = String.sub (!string_buff) 0 (!string_index) in
let s = Bytes.sub_string (!string_buff) 0 (!string_index) in
string_buff := initial_string_buffer;
s
......@@ -171,13 +171,14 @@ let cvt_nativeint_literal s =
let remove_underscores s =
let l = String.length s in
let b = Bytes.create l in
let rec remove src dst =
if src >= l then
if dst >= l then s else String.sub s 0 dst
if dst >= l then s else Bytes.sub_string b 0 dst
else
match s.[src] with
'_' -> remove (src + 1) dst
| c -> s.[dst] <- c; remove (src + 1) (dst + 1)
| c -> Bytes.set b dst c; remove (src + 1) (dst + 1)
in remove 0 0
(* Update the current location with file name and line number. *)
......
......@@ -81,7 +81,7 @@ let highlight_terminfo ppf num_lines lb loc1 loc2 =
(* Count number of lines in phrase *)
let lines = ref !num_loc_lines in
for i = pos0 to lb.lex_buffer_len - 1 do
if lb.lex_buffer.[i] = '\n' then incr lines
if Bytes.get lb.lex_buffer i = '\n' then incr lines
done;
(* If too many lines, give up *)
if !lines >= num_lines - 2 then raise Exit;
......@@ -96,7 +96,7 @@ let highlight_terminfo ppf num_lines lb loc1 loc2 =
Terminfo.standout true;
if pos = loc1.loc_end.pos_cnum || pos = loc2.loc_end.pos_cnum then
Terminfo.standout false;
let c = lb.lex_buffer.[pos + pos0] in
let c = Bytes.get lb.lex_buffer (pos + pos0) in
print_char c;
bol := (c = '\n')
done;
......@@ -117,7 +117,7 @@ let highlight_dumb ppf lb loc =
(* Determine line numbers for the start and end points *)
let line_start = ref 0 and line_end = ref 0 in
for pos = 0 to end_pos do
if lb.lex_buffer.[pos + pos0] = '\n' then begin
if Bytes.get lb.lex_buffer (pos + pos0) = '\n' then begin
if loc.loc_start.pos_cnum > pos then incr line_start;
if loc.loc_end.pos_cnum > pos then incr line_end;
end
......@@ -130,7 +130,7 @@ let highlight_dumb ppf lb loc =
let line = ref 0 in
let pos_at_bol = ref 0 in
for pos = 0 to end_pos do
let c = lb.lex_buffer.[pos + pos0] in
let c = Bytes.get lb.lex_buffer (pos + pos0) in
if c <> '\n' then begin
if !line = !line_start && !line = !line_end then
(* loc is on one line: print whole line *)
......
......@@ -235,8 +235,9 @@ let check_consistency filename crcs =
let read_pers_struct modname filename =
let ic = open_in_bin filename in
try
let buffer = String.create (String.length cmi_magic_number) in
really_input ic buffer 0 (String.length cmi_magic_number);
let buffer =
really_input_string ic (String.length cmi_magic_number)
in
if buffer <> cmi_magic_number then begin
close_in ic;
raise(Error(Not_an_interface filename))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment