Core.Std.String.Map

Reviewed By: sblackshear

Differential Revision: D4232446

fbshipit-source-id: c90eaf7
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent e00c4cd2dd
commit 78ec954ae2

@ -239,16 +239,16 @@ module Err_table = struct
size filter err_table
let pp_stats_footprint ekind fmt (err_table: err_log) =
let err_name_map = ref StringMap.empty in (* map error name to count *)
let err_name_map = ref String.Map.empty in (* map error name to count *)
let count_err (err_name: Localise.t) n =
let err_string = Localise.to_string err_name in
let count = try StringMap.find err_string !err_name_map with Not_found -> 0 in
err_name_map := StringMap.add err_string (count + n) !err_name_map in
let count = try String.Map.find_exn !err_name_map err_string with Not_found -> 0 in
err_name_map := String.Map.add ~key:err_string ~data:(count + n) !err_name_map in
let count (ekind', in_footprint, err_name, _, _) eds =
if ekind = ekind' && in_footprint then count_err err_name (ErrDataSet.cardinal eds) in
ErrLogHash.iter count err_table;
let pp err_string count = F.fprintf fmt " %s:%d" err_string count in
StringMap.iter pp !err_name_map
let pp ~key:err_string ~data:count = F.fprintf fmt " %s:%d" err_string count in
String.Map.iteri ~f:pp !err_name_map
module LocMap =
Map.Make(struct

@ -153,12 +153,12 @@ let iterate_callbacks store_summary call_graph exe_env =
IList.fold_left
(fun map proc_name ->
let proc_cluster = cluster_id proc_name in
let bucket = try StringMap.find proc_cluster map with Not_found -> [] in
StringMap.add proc_cluster (proc_name:: bucket) map)
StringMap.empty
let bucket = try String.Map.find_exn map proc_cluster with Not_found -> [] in
String.Map.add ~key:proc_cluster ~data:(proc_name:: bucket) map)
String.Map.empty
proc_names in
(* Return all values of the map *)
IList.map snd (StringMap.bindings cluster_map) in
String.Map.data cluster_map in
let reset_summary proc_name =
let attributes_opt =
Specs.proc_resolve_attributes proc_name in

@ -54,14 +54,14 @@ let stitch_summaries stacktrace_file summary_files out_file =
summary_files in
let summary_map = IList.fold_left
(fun acc stacktree ->
StringMap.add (frame_id_of_summary stacktree) stacktree acc)
StringMap.empty
String.Map.add ~key:(frame_id_of_summary stacktree) ~data:stacktree acc)
String.Map.empty
summaries in
let expand_stack_frame frame =
(* TODO: Implement k > 1 case *)
let frame_id = frame_id_of_stackframe frame in
if StringMap.exists (fun key _ -> key = frame_id) summary_map then
StringMap.find frame_id summary_map
if String.Map.existsi ~f:(fun ~key ~data:_ -> key = frame_id) summary_map then
String.Map.find_exn summary_map frame_id
else
stracktree_of_frame frame in
let expanded_frames = IList.map expand_stack_frame stacktrace.frames in

@ -110,16 +110,16 @@ module FileOrProcMatcher = struct
(fun map pattern ->
let previous =
try
StringMap.find pattern.Config.class_name map
String.Map.find_exn map pattern.Config.class_name
with Not_found -> [] in
StringMap.add pattern.Config.class_name (pattern:: previous) map)
StringMap.empty
String.Map.add ~key:pattern.Config.class_name ~data:(pattern:: previous) map)
String.Map.empty
m_patterns in
let do_java pname_java =
let class_name = Procname.java_get_class_name pname_java
and method_name = Procname.java_get_method pname_java in
try
let class_patterns = StringMap.find class_name pattern_map in
let class_patterns = String.Map.find_exn pattern_map class_name in
IList.exists
(fun p ->
match p.Config.method_name with

@ -93,9 +93,6 @@ module StringHash = Hashtbl.Make (String)
(** Maps from integers *)
module IntMap = Map.Make (Int)
(** Maps from strings *)
module StringMap = Map.Make (String)
(** {2 Printing} *)
(** Kind of simple printing: default or with full types *)

@ -81,9 +81,6 @@ module StringHash : Hashtbl.S with type key = string
(** Maps from integers *)
module IntMap : Map.S with type key = int
(** Maps from strings *)
module StringMap : Map.S with type key = string
(** {2 Printing} *)
(** Colors supported in printing *)

@ -69,16 +69,14 @@ end
(** Environment for boolean variables. *)
module Env = struct
type t = bool StringMap.t [@@deriving compare]
let empty = StringMap.empty
let add = StringMap.add
let remove = StringMap.remove
let get map name =
try Some (StringMap.find name map)
with Not_found -> None
type t = bool String.Map.t [@@deriving compare]
let empty = String.Map.empty
let add key data map = String.Map.add ~key ~data map
let remove key map = String.Map.remove map key
let get map name = String.Map.find map name
let pp fmt map =
let pp_elem fmt (s, b) = F.fprintf fmt "%s:%b" s b in
let l = StringMap.bindings map in
let l = String.Map.to_alist map in
if l <> [] then F.fprintf fmt "%a" (pp_seq pp_elem) l
end

@ -110,10 +110,10 @@ let get_compilation_database_files_buck () =
Logging.out "Reading compilation database from:@\n%s@\n" (String.concat ~sep:"\n" lines);
let scan_output compilation_database_files chan =
Scanf.sscanf chan "%s %s"
(fun target file -> StringMap.add target file compilation_database_files) in
(fun target file -> String.Map.add ~key:target ~data:file compilation_database_files) in
(* Map from targets to json output *)
let compilation_database_files = IList.fold_left scan_output StringMap.empty lines in
IList.map (snd) (StringMap.bindings compilation_database_files)
let compilation_database_files = IList.fold_left scan_output String.Map.empty lines in
String.Map.data compilation_database_files
with Unix.Unix_error (err, _, _) ->
Process.print_error_and_exit
"Cannot execute %s\n%!"

@ -119,7 +119,7 @@ let add_source_file path map =
let current_source_file =
SourceFile.from_abs_path (convert_to_absolute path) in
try
match StringMap.find basename map with
match String.Map.find_exn map basename with
| Singleton previous_source_file ->
(* Another source file with the same base name has been found.
Reading the package from the source file to resolve the ambiguity
@ -137,7 +137,7 @@ let add_source_file path map =
with Not_found ->
(* Most common case: there is no conflict with the base name of the source file *)
Singleton current_source_file in
StringMap.add basename entry map
String.Map.add ~key:basename ~data:entry map
let add_root_path path roots =
@ -184,7 +184,7 @@ let load_from_verbose_output () =
""
((String.Set.elements roots) @ paths) in
(classpath, sources, classes) in
loop [] String.Set.empty StringMap.empty JBasics.ClassSet.empty
loop [] String.Set.empty String.Map.empty JBasics.ClassSet.empty
let classname_of_class_filename class_filename =
@ -232,7 +232,7 @@ let search_sources () =
let initial_map =
IList.fold_left
(fun map path -> add_source_file path map)
StringMap.empty
String.Map.empty
Config.sources in
match Config.sourcepath with
| None -> initial_map

@ -34,7 +34,7 @@ type file_entry =
(** load the list of source files and the list of classes from the javac verbose file *)
val load_sources_and_classes : unit ->
string * file_entry StringMap.t * JBasics.ClassSet.t
string * file_entry String.Map.t * JBasics.ClassSet.t
type classmap = JCode.jcode Javalib.interface_or_class JBasics.ClassMap.t

@ -116,7 +116,7 @@ let save_tenv tenv =
(* The program is loaded and translated *)
let do_all_files classpath sources classes =
L.do_out "Translating %d source files (%d classes)@."
(StringMap.cardinal sources)
(String.Map.length sources)
(JBasics.ClassSet.cardinal classes);
let program = JClasspath.load_program classpath classes in
let tenv = load_tenv () in
@ -132,8 +132,8 @@ let do_all_files classpath sources classes =
init_global_state source_file;
if not (skip source_file) then
do_source_file linereader classes program tenv basename package_opt source_file in
StringMap.iter
(fun basename file_entry ->
String.Map.iteri
~f:(fun ~key:basename ~data:file_entry ->
match file_entry with
| JClasspath.Singleton source_file ->
translate_source_file basename (None, source_file) source_file
@ -154,7 +154,7 @@ let do_all_files classpath sources classes =
let () =
JBasics.set_permissive true;
let classpath, sources, classes = JClasspath.load_sources_and_classes () in
if StringMap.is_empty sources then
if String.Map.is_empty sources then
failwith "Failed to load any Java source code"
else
do_all_files classpath sources classes

Loading…
Cancel
Save