Core.Std.Array

Reviewed By: cristianoc

Differential Revision: D4232437

fbshipit-source-id: a9a1406
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent 7708fc7c56
commit c2abce7e3a

@ -52,5 +52,5 @@ let load_issues_to_errlog_map dir =
) !errLogMap map ) !errLogMap map
| None -> () in | None -> () in
match children_opt with match children_opt with
| Some children -> Array.iter load_issues_to_map children | Some children -> Array.iter ~f:load_issues_to_map children
| None -> () | None -> ()

@ -106,13 +106,12 @@ let print_stack_info = ref false
(* replace a dollar sign in a name with a D. We need this because dotty get confused if there is*) (* replace a dollar sign in a name with a D. We need this because dotty get confused if there is*)
(* a dollar sign i a label*) (* a dollar sign i a label*)
let strip_special_chars s = let strip_special_chars b =
let b = Bytes.of_string s in
let replace st c c' = let replace st c c' =
if Bytes.contains st c then begin if String.contains st c then begin
let idx = Bytes.index st c in let idx = String.index_exn st c in
try try
Bytes.set st idx c'; String.set st idx c';
st st
with Invalid_argument _ -> L.out "@\n@\n Invalid argument!!! @\n @.@.@."; assert false with Invalid_argument _ -> L.out "@\n@\n Invalid argument!!! @\n @.@.@."; assert false
end else st in end else st in
@ -124,7 +123,7 @@ let strip_special_chars s =
let s5 = replace s4 ')' 'B' in let s5 = replace s4 ')' 'B' in
let s6 = replace s5 '+' 'P' in let s6 = replace s5 '+' 'P' in
let s7 = replace s6 '-' 'M' in let s7 = replace s6 '-' 'M' in
Bytes.to_string s7 s7
let rec strexp_to_string pe coo f se = let rec strexp_to_string pe coo f se =
match se with match se with

@ -113,7 +113,7 @@ let rec slink ~stats ~skiplevels src dst =
then Unix.mkdir dst ~perm:0o700; then Unix.mkdir dst ~perm:0o700;
let items = Sys.readdir src in let items = Sys.readdir src in
Array.iter Array.iter
(fun item -> ~f:(fun item ->
slink ~stats ~skiplevels:(skiplevels - 1) slink ~stats ~skiplevels:(skiplevels - 1)
(Filename.concat src item) (Filename.concat dst item)) (Filename.concat src item) (Filename.concat dst item))
items items

@ -188,8 +188,8 @@ module Results_dir = struct
let clean_specs_dir () = let clean_specs_dir () =
create_dir specs_dir; (* create dir just in case it doesn't exist to avoid errors *) create_dir specs_dir; (* create dir just in case it doesn't exist to avoid errors *)
let files_to_remove = Array.map (Filename.concat specs_dir) (Sys.readdir specs_dir) in let files_to_remove = Array.map ~f:(Filename.concat specs_dir) (Sys.readdir specs_dir) in
Array.iter Sys.remove files_to_remove Array.iter ~f:Sys.remove files_to_remove
(** create a file at the given path, creating any missing directories *) (** create a file at the given path, creating any missing directories *)
let create_file pk path = let create_file pk path =
@ -245,13 +245,13 @@ let mark_file_updated fname =
(** Fold over all file paths recursively under [dir] which match [p]. *) (** Fold over all file paths recursively under [dir] which match [p]. *)
let fold_paths_matching ~dir ~p ~init ~f = let fold_paths_matching ~dir ~p ~init ~f =
let rec paths path_list dir = let rec paths path_list dir =
Array.fold_left Array.fold
(fun acc file -> ~f:(fun acc file ->
let path = dir // file in let path = dir // file in
if Sys.is_directory path = `Yes then (paths acc path) if Sys.is_directory path = `Yes then (paths acc path)
else if p path then f path acc else if p path then f path acc
else acc) else acc)
path_list ~init:path_list
(Sys.readdir dir) in (Sys.readdir dir) in
paths init dir paths init dir

@ -51,7 +51,7 @@ let compute_statistics values => {
let average = sum /. float_of_int num_elements; let average = sum /. float_of_int num_elements;
let values_arr = Array.of_list values; let values_arr = Array.of_list values;
Array.sort Array.sort
( cmp::(
fun a b => fun a b =>
if (a == b) { if (a == b) {
0 0

@ -10,7 +10,10 @@
(** General utility functions and definition with global scope *) (** General utility functions and definition with global scope *)
module Arg = Core.Std.Arg
module Array = Core.Std.Array
module Bool = Core.Std.Bool module Bool = Core.Std.Bool
module Bytes = Core.Std.Bytes
module Caml = Core.Std.Caml module Caml = Core.Std.Caml
module Filename = Core.Std.Filename module Filename = Core.Std.Filename
module Fn = Core.Std.Fn module Fn = Core.Std.Fn
@ -465,7 +468,7 @@ let directory_fold f init path =
match dirs with match dirs with
| [] -> accu | [] -> accu
| d:: tl -> | d:: tl ->
let (new_accu, new_dirs) = Array.fold_left (collect d) (accu, tl) (Sys.readdir d) in let (new_accu, new_dirs) = Array.fold ~f:(collect d) ~init:(accu, tl) (Sys.readdir d) in
loop new_accu new_dirs in loop new_accu new_dirs in
if Sys.is_directory path = `Yes then if Sys.is_directory path = `Yes then
loop init [path] loop init [path]
@ -488,7 +491,7 @@ let directory_iter f path =
match dirs with match dirs with
| [] -> () | [] -> ()
| d:: tl -> | d:: tl ->
let new_dirs = Array.fold_left (apply d) tl (Sys.readdir d) in let new_dirs = Array.fold ~f:(apply d) ~init:tl (Sys.readdir d) in
loop new_dirs in loop new_dirs in
if Sys.is_directory path = `Yes then if Sys.is_directory path = `Yes then
loop [path] loop [path]

@ -10,7 +10,10 @@
(** General utility functions *) (** General utility functions *)
module Arg = Core.Std.Arg
module Array = Core.Std.Array
module Bool = Core.Std.Bool module Bool = Core.Std.Bool
module Bytes = Core.Std.Bytes
module Caml = Core.Std.Caml module Caml = Core.Std.Caml
module Filename = Core.Std.Filename module Filename = Core.Std.Filename
module Fn = Core.Std.Fn module Fn = Core.Std.Fn

@ -515,7 +515,7 @@ let define_condition_side_effects e_cond instrs_cond sil_loc =
let fix_param_exps_mismatch params_stmt exps_param = let fix_param_exps_mismatch params_stmt exps_param =
let diff = IList.length params_stmt - IList.length exps_param in let diff = IList.length params_stmt - IList.length exps_param in
let args = if diff >0 then Array.make diff dummy_exp let args = if diff >0 then Array.create ~len:diff dummy_exp
else assert false in else assert false in
let exps'= exps_param @ (Array.to_list args) in let exps'= exps_param @ (Array.to_list args) in
exps' exps'

@ -71,7 +71,7 @@ let add_edges
if not super_call then if not super_call then
(* the exceptions node is just before the exit node *) (* the exceptions node is just before the exit node *)
Procdesc.node_set_succs_exn context.procdesc exn_node exit_nodes exit_nodes; Procdesc.node_set_succs_exn context.procdesc exn_node exit_nodes exit_nodes;
Array.iteri connect_nodes method_body_nodes Array.iteri ~f:connect_nodes method_body_nodes
(** Add a concrete method. *) (** Add a concrete method. *)
@ -90,7 +90,7 @@ let add_cmethod source_file program linereader icfg cm proc_name =
let instrs = JBir.code jbir_code in let instrs = JBir.code jbir_code in
let context = let context =
JContext.create_context icfg procdesc jbir_code cn source_file program in JContext.create_context icfg procdesc jbir_code cn source_file program in
let method_body_nodes = Array.mapi (JTrans.instruction context) instrs in let method_body_nodes = Array.mapi ~f:(JTrans.instruction context) instrs in
add_edges context start_node exn_node [exit_node] method_body_nodes jbir_code false add_edges context start_node exn_node [exit_node] method_body_nodes jbir_code false

@ -172,11 +172,11 @@ let translate_locals program tenv formals bytecode jbir_code =
(* TODO (#4040807): Needs to add the JBir temporary variables since other parts of the (* TODO (#4040807): Needs to add the JBir temporary variables since other parts of the
code are still relying on those *) code are still relying on those *)
let with_jbir_vars = let with_jbir_vars =
Array.fold_left Array.fold
(fun accu jbir_var -> ~f:(fun accu jbir_var ->
let var = Mangled.from_string (JBir.var_name_g jbir_var) in let var = Mangled.from_string (JBir.var_name_g jbir_var) in
collect accu (var, Typ.Tvoid)) collect accu (var, Typ.Tvoid))
with_bytecode_vars ~init:with_bytecode_vars
(JBir.vars jbir_code) in (JBir.vars jbir_code) in
snd with_jbir_vars snd with_jbir_vars
@ -245,7 +245,7 @@ let get_implementation cm =
let bytecode = Lazy.force t in let bytecode = Lazy.force t in
let c_code = let c_code =
Array.map Array.map
(function ~f:(function
| (JCode.OpInvoke (`Dynamic _, ms)) -> | (JCode.OpInvoke (`Dynamic _, ms)) ->
JCode.OpInvoke (`Static JBasics.java_lang_object, ms) JCode.OpInvoke (`Static JBasics.java_lang_object, ms)
| opcode -> | opcode ->

Loading…
Cancel
Save