From 76f845020395e964f0c1c4941485763aa68b2961 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 9 Dec 2016 16:32:12 -0800 Subject: [PATCH] Move proc_flags from Utils to ProcAttributes Reviewed By: sblackshear Differential Revision: D4232444 fbshipit-source-id: a3fd370 --- infer/src/IR/ProcAttributes.re | 19 +++++++++++++++++++ infer/src/IR/ProcAttributes.rei | 22 ++++++++++++++++++++++ infer/src/IR/Procdesc.re | 3 ++- infer/src/IR/Procdesc.rei | 2 +- infer/src/backend/InferPrint.re | 2 +- infer/src/backend/specs.ml | 2 +- infer/src/backend/specs.mli | 2 +- infer/src/backend/symExec.ml | 4 ++-- infer/src/base/Utils.ml | 20 -------------------- infer/src/base/Utils.mli | 18 ------------------ infer/src/checkers/checkers.ml | 6 +++--- 11 files changed, 52 insertions(+), 48 deletions(-) diff --git a/infer/src/IR/ProcAttributes.re b/infer/src/IR/ProcAttributes.re index 1938507d2..fecba5769 100644 --- a/infer/src/IR/ProcAttributes.re +++ b/infer/src/IR/ProcAttributes.re @@ -15,6 +15,25 @@ let module L = Logging; let module F = Format; +/** flags for a procedure */ +type proc_flags = Hashtbl.t string string; + +let compare_proc_flags x y => { + let bindings x => Hashtbl.fold (fun k d l => [(k, d), ...l]) x []; + [%compare : list (string, string)] (bindings x) (bindings y) +}; + +let proc_flags_empty () :proc_flags => Hashtbl.create 1; + +let proc_flag_skip = "skip"; + +let proc_flag_ignore_return = "ignore_return"; + +let proc_flags_add proc_flags key value => Hashtbl.replace proc_flags key value; + +let proc_flags_find proc_flags key => Hashtbl.find proc_flags key; + + /** Type for ObjC accessors */ type objc_accessor_type = | Objc_getter Ident.fieldname diff --git a/infer/src/IR/ProcAttributes.rei b/infer/src/IR/ProcAttributes.rei index 4f81beb4e..1784c79dd 100644 --- a/infer/src/IR/ProcAttributes.rei +++ b/infer/src/IR/ProcAttributes.rei @@ -10,6 +10,28 @@ open! Utils; /** Attributes of a procedure. */ + +/** flags for a procedure */ +type proc_flags = Hashtbl.t string string [@@deriving compare]; + + +/** keys for proc_flags */ +let proc_flag_skip: string; /** key to specify that a function should be treated as a skip function */ + +let proc_flag_ignore_return: string; /** key to specify that it is OK to ignore the return value */ + + +/** empty proc flags */ +let proc_flags_empty: unit => proc_flags; + + +/** add a key value pair to a proc flags */ +let proc_flags_add: proc_flags => string => string => unit; + + +/** find a value for a key in the proc flags */ +let proc_flags_find: proc_flags => string => string; + type objc_accessor_type = | Objc_getter Ident.fieldname | Objc_setter Ident.fieldname diff --git a/infer/src/IR/Procdesc.re b/infer/src/IR/Procdesc.re index 48e53e8ac..e9594400e 100644 --- a/infer/src/IR/Procdesc.re +++ b/infer/src/IR/Procdesc.re @@ -464,7 +464,8 @@ let set_exit_node pdesc node => pdesc.exit_node = node; /** Set a flag for the proc desc */ -let set_flag pdesc key value => proc_flags_add pdesc.attributes.proc_flags key value; +let set_flag pdesc key value => + ProcAttributes.proc_flags_add pdesc.attributes.proc_flags key value; /** Set the start node of the proc desc */ diff --git a/infer/src/IR/Procdesc.rei b/infer/src/IR/Procdesc.rei index bfb5ddee4..786cf6f58 100644 --- a/infer/src/IR/Procdesc.rei +++ b/infer/src/IR/Procdesc.rei @@ -188,7 +188,7 @@ let get_exit_node: t => Node.t; /** Get flags for the proc desc */ -let get_flags: t => proc_flags; +let get_flags: t => ProcAttributes.proc_flags; /** Return name and type of formal parameters */ diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index d592fa14c..f95519ba7 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -128,7 +128,7 @@ type summary_val = { vsymop: int, verr: int, vfile: string, - vflags: proc_flags, + vflags: ProcAttributes.proc_flags, vline: int, vtop: string, vsignature: string, diff --git a/infer/src/backend/specs.ml b/infer/src/backend/specs.ml index 8c6201dd8..c956e5cc6 100644 --- a/infer/src/backend/specs.ml +++ b/infer/src/backend/specs.ml @@ -798,7 +798,7 @@ let reset_summary call_graph proc_name attributes_opt proc_desc_option = init_summary ( Procname.Set.elements dependents, [], - proc_flags_empty (), + ProcAttributes.proc_flags_empty (), [], Some (Cg.get_calls call_graph proc_name), proc_attributes, diff --git a/infer/src/backend/specs.mli b/infer/src/backend/specs.mli index a78121dd3..144ed796c 100644 --- a/infer/src/backend/specs.mli +++ b/infer/src/backend/specs.mli @@ -215,7 +215,7 @@ val is_active : summary -> bool val init_summary : (Procname.t list * (* depend list *) Procdesc.Node.id list * (* nodes *) - proc_flags * (* procedure flags *) + ProcAttributes.proc_flags * (* procedure flags *) (Procname.t * Location.t) list * (* calls *) (Cg.in_out_calls option) * (* in and out calls *) ProcAttributes.t * (* attributes of the procedure *) diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 5ea3fca9f..50a0b8017 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -377,7 +377,7 @@ let check_inherently_dangerous_function caller_pname callee_pname = let call_should_be_skipped callee_summary = (* check skip flag *) - Specs.get_flag callee_summary proc_flag_skip <> None + Specs.get_flag callee_summary ProcAttributes.proc_flag_skip <> None (* skip abstract methods *) || callee_summary.Specs.attributes.ProcAttributes.is_abstract (* treat calls with no specs as skip functions in angelic mode *) @@ -1539,7 +1539,7 @@ and proc_call summary {Builtin.pdesc; tenv; prop_= pre; path; ret_id; args= actu | _, None -> true | _, Some (id, _) -> Errdesc.id_is_assigned_then_dead (State.get_node ()) id in if is_ignored - && Specs.get_flag summary proc_flag_ignore_return = None then + && Specs.get_flag summary ProcAttributes.proc_flag_ignore_return = None then let err_desc = Localise.desc_return_value_ignored callee_pname loc in let exn = (Exceptions.Return_value_ignored (err_desc, __POS__)) in Reporting.log_warning caller_pname exn in diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index a4c68f08f..6d6a4602d 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -447,26 +447,6 @@ let filename_to_relative root fname = remainder -(** flags for a procedure *) -type proc_flags = (string, string) Hashtbl.t - -let compare_proc_flags x y = - let bindings x = Hashtbl.fold (fun k d l -> (k, d) :: l) x [] in - [%compare: (string * string) list] (bindings x) (bindings y) - - -let proc_flags_empty () : proc_flags = Hashtbl.create 1 - -let proc_flag_skip = "skip" -let proc_flag_ignore_return = "ignore_return" - -let proc_flags_add proc_flags key value = - Hashtbl.replace proc_flags key value - -let proc_flags_find proc_flags key = - Hashtbl.find proc_flags key - - let directory_fold f init path = let collect current_dir (accu, dirs) path = let full_path = current_dir // path in diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index 18de67fda..c6b134eea 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -213,24 +213,6 @@ val do_outf : outfile option -> (outfile -> unit) -> unit (** close an outfile *) val close_outf : outfile -> unit -(** flags for a procedure *) -type proc_flags = (string, string) Hashtbl.t [@@deriving compare] - -(** keys for proc_flags *) - -val proc_flag_skip : string (** key to specify that a function should be treated as a skip function *) - -val proc_flag_ignore_return : string (** key to specify that it is OK to ignore the return value *) - -(** empty proc flags *) -val proc_flags_empty : unit -> proc_flags - -(** add a key value pair to a proc flags *) -val proc_flags_add : proc_flags -> string -> string -> unit - -(** find a value for a key in the proc flags *) -val proc_flags_find : proc_flags -> string -> string - (** Functional fold function over all the file of a directory *) val directory_fold : ('a -> string -> 'a) -> 'a -> string -> 'a diff --git a/infer/src/checkers/checkers.ml b/infer/src/checkers/checkers.ml index 7b88ec6b5..a4cb8a361 100644 --- a/infer/src/checkers/checkers.ml +++ b/infer/src/checkers/checkers.ml @@ -33,7 +33,7 @@ end (* PP *) (** State that persists in the .specs files. *) module ST = struct let add summary key value = - proc_flags_add summary.Specs.attributes.ProcAttributes.proc_flags key value + ProcAttributes.proc_flags_add summary.Specs.attributes.ProcAttributes.proc_flags key value let pname_add proc_name key value = let summary = Specs.get_summary_unsafe "ST.pname_add" proc_name in @@ -44,14 +44,14 @@ module ST = struct let pname_find proc_name key = if Procname.Set.mem proc_name !files_open then let summary = Specs.get_summary_unsafe "ST.pname_find" proc_name in - proc_flags_find summary.Specs.attributes.ProcAttributes.proc_flags key + ProcAttributes.proc_flags_find summary.Specs.attributes.ProcAttributes.proc_flags key else begin match Specs.get_summary proc_name with | None -> raise Not_found | Some summary -> begin files_open := Procname.Set.add proc_name !files_open; - proc_flags_find summary.Specs.attributes.ProcAttributes.proc_flags key + ProcAttributes.proc_flags_find summary.Specs.attributes.ProcAttributes.proc_flags key end end