Move proc_flags from Utils to ProcAttributes

Reviewed By: sblackshear

Differential Revision: D4232444

fbshipit-source-id: a3fd370
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent f86fc2ce2d
commit 76f8450203

@ -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

@ -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

@ -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 */

@ -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 */

@ -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,

@ -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,

@ -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 *)

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save