simplify the API to create procedure descriptions

Summary:
public
Remove the need to create a record with two elements to create a procedure description

Reviewed By: cristianoc

Differential Revision: D2872744

fb-gh-sync-id: d26bbdc
master
jrm 9 years ago committed by facebook-github-bot-5
parent dc0b91662a
commit 18668a41ce

@ -373,6 +373,20 @@ module Node = struct
(** Counter for identifiers of procdescs *) (** Counter for identifiers of procdescs *)
let proc_desc_id_counter = ref 0 let proc_desc_id_counter = ref 0
let proc_desc_create cfg proc_attributes =
incr proc_desc_id_counter;
let pdesc =
{
pd_attributes = proc_attributes;
pd_id = !proc_desc_id_counter;
pd_nodes = [];
pd_start_node = dummy ();
pd_exit_node = dummy ();
pd_changed = true
} in
pdesc_tbl_add cfg proc_attributes.ProcAttributes.proc_name pdesc;
pdesc
let remove_node' filter_out_fun cfg node = let remove_node' filter_out_fun cfg node =
let remove_node_in_cfg nodes = let remove_node_in_cfg nodes =
IList.filter filter_out_fun nodes in IList.filter filter_out_fun nodes in
@ -620,26 +634,7 @@ module Procdesc = struct
type t = Node.proc_desc type t = Node.proc_desc
let compute_distance_to_exit_node = Node.proc_desc_compute_distance_to_exit_node let compute_distance_to_exit_node = Node.proc_desc_compute_distance_to_exit_node
type proc_desc_builder = let create = Node.proc_desc_create
{ cfg : cfg;
proc_attributes : ProcAttributes.t;
}
let create (b : proc_desc_builder) =
let open Node in
incr proc_desc_id_counter;
let pdesc =
{
pd_attributes = b.proc_attributes;
pd_id = !proc_desc_id_counter;
pd_nodes = [];
pd_start_node = dummy ();
pd_exit_node = dummy ();
pd_changed = true
} in
pdesc_tbl_add b.cfg b.proc_attributes.ProcAttributes.proc_name pdesc;
pdesc
let remove = Node.proc_desc_remove let remove = Node.proc_desc_remove
let find_from_name = Node.proc_desc_from_name let find_from_name = Node.proc_desc_from_name
let get_attributes = Node.proc_desc_get_attributes let get_attributes = Node.proc_desc_get_attributes

@ -31,13 +31,8 @@ module Procdesc : sig
(** Compute the distance of each node to the exit node, if not computed already *) (** Compute the distance of each node to the exit node, if not computed already *)
val compute_distance_to_exit_node : t -> unit val compute_distance_to_exit_node : t -> unit
type proc_desc_builder =
{ cfg : cfg;
proc_attributes : ProcAttributes.t;
}
(** Create a procdesc *) (** Create a procdesc *)
val create : proc_desc_builder -> t val create : cfg -> ProcAttributes.t -> t
(** [remove cfg name remove_nodes] remove the procdesc [name] from the control flow graph [cfg]. *) (** [remove cfg name remove_nodes] remove the procdesc [name] from the control flow graph [cfg]. *)
(** It also removes all the nodes from the procedure from the cfg if remove_nodes is true *) (** It also removes all the nodes from the procedure from the cfg if remove_nodes is true *)

@ -580,15 +580,15 @@ let check_deallocate_static_memory prop_after =
let proc_desc_copy cfg pdesc pname pname' = let proc_desc_copy cfg pdesc pname pname' =
if (Procname.equal pname pname') then pdesc if (Procname.equal pname pname') then pdesc
else else
(match Cfg.Procdesc.find_from_name cfg pname' with begin
| Some pdesc' -> pdesc' match Cfg.Procdesc.find_from_name cfg pname' with
| None -> | Some pdesc' -> pdesc'
Cfg.Procdesc.create { | None ->
Cfg.Procdesc.cfg = cfg; let proc_attributes =
proc_attributes = { (ProcAttributes.copy (Cfg.Procdesc.get_attributes pdesc)) with
{ (ProcAttributes.copy (Cfg.Procdesc.get_attributes pdesc)) with ProcAttributes.proc_name = pname'; } in
ProcAttributes.proc_name = pname'; }; Cfg.Procdesc.create cfg proc_attributes
}) end
let method_exists right_proc_name methods = let method_exists right_proc_name methods =
if !Config.curr_language = Config.Java then if !Config.curr_language = Config.Java then

@ -349,10 +349,7 @@ let create_local_procdesc cfg tenv ms fbody captured is_objc_inst_method =
method_annotation; method_annotation;
ret_type; ret_type;
} in } in
Cfg.Procdesc.create { Cfg.Procdesc.create cfg proc_attributes in
Cfg.Procdesc.cfg;
proc_attributes;
} in
if defined then if defined then
(if !Config.arc_mode then (if !Config.arc_mode then
Cfg.Procdesc.set_flag procdesc Mleak_buckets.objc_arc_flag "true"; Cfg.Procdesc.set_flag procdesc Mleak_buckets.objc_arc_flag "true";
@ -377,19 +374,14 @@ let create_external_procdesc cfg proc_name is_objc_inst_method type_opt =
ret_type, IList.map (fun typ -> (Mangled.from_string "x", typ)) arg_types ret_type, IList.map (fun typ -> (Mangled.from_string "x", typ)) arg_types
| None -> Sil.Tvoid, []) in | None -> Sil.Tvoid, []) in
let loc = Location.dummy in let loc = Location.dummy in
let _ = let proc_attributes =
let proc_attributes = { (ProcAttributes.default proc_name Config.C_CPP) with
{ (ProcAttributes.default proc_name Config.C_CPP) with ProcAttributes.formals;
ProcAttributes.formals; is_objc_instance_method = is_objc_inst_method;
is_objc_instance_method = is_objc_inst_method; loc;
loc; ret_type;
ret_type;
} in
Cfg.Procdesc.create {
Cfg.Procdesc.cfg = cfg;
proc_attributes = proc_attributes;
} in } in
() ignore (Cfg.Procdesc.create cfg proc_attributes)
let create_procdesc_with_pointer context pointer class_name_opt name tp = let create_procdesc_with_pointer context pointer class_name_opt name tp =
let open CContext in let open CContext in

@ -270,10 +270,7 @@ let setup_harness_cfg harness_name harness_cfg env source_dir cg tenv =
ProcAttributes.is_defined = true; ProcAttributes.is_defined = true;
loc = env.pc; loc = env.pc;
} in } in
Cfg.Procdesc.create { Cfg.Procdesc.create harness_cfg proc_attributes in
Cfg.Procdesc.cfg = harness_cfg;
proc_attributes;
} in
let harness_node = let harness_node =
(* important to reverse the list or there will be scoping issues! *) (* important to reverse the list or there will be scoping issues! *)
let instrs = (IList.rev env.instrs) in let instrs = (IList.rev env.instrs) in

@ -297,10 +297,7 @@ let create_local_procdesc program linereader cfg tenv node m =
method_annotation; method_annotation;
ret_type = JTransType.return_type program tenv ms meth_kind; ret_type = JTransType.return_type program tenv ms meth_kind;
} in } in
Cfg.Procdesc.create { Cfg.Procdesc.create cfg proc_attributes in
Cfg.Procdesc.cfg = cfg;
proc_attributes;
} in
let start_kind = Cfg.Node.Start_node procdesc in let start_kind = Cfg.Node.Start_node procdesc in
let start_node = Cfg.Node.create cfg Location.dummy start_kind [] procdesc [] in let start_node = Cfg.Node.create cfg Location.dummy start_kind [] procdesc [] in
let exit_kind = (Cfg.Node.Exit_node procdesc) in let exit_kind = (Cfg.Node.Exit_node procdesc) in
@ -311,22 +308,17 @@ let create_local_procdesc program linereader cfg tenv node m =
| Javalib.ConcreteMethod cm when is_java_native cm -> | Javalib.ConcreteMethod cm when is_java_native cm ->
let formals = formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in let formals = formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in
let _procdesc = let proc_attributes =
let proc_attributes = { (ProcAttributes.default proc_name Config.Java) with
{ (ProcAttributes.default proc_name Config.Java) with ProcAttributes.access = trans_access cm.Javalib.cm_access;
ProcAttributes.access = trans_access cm.Javalib.cm_access; exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions;
exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions; formals;
formals; is_bridge_method = cm.Javalib.cm_bridge;
is_bridge_method = cm.Javalib.cm_bridge; is_synthetic_method = cm.Javalib.cm_synthetic;
is_synthetic_method = cm.Javalib.cm_synthetic; method_annotation;
method_annotation; ret_type = JTransType.return_type program tenv ms meth_kind;
ret_type = JTransType.return_type program tenv ms meth_kind;
} in
Cfg.Procdesc.create {
Cfg.Procdesc.cfg = cfg;
proc_attributes = proc_attributes;
} in } in
() ignore (Cfg.Procdesc.create cfg proc_attributes)
| Javalib.ConcreteMethod cm -> | Javalib.ConcreteMethod cm ->
let impl = get_implementation cm in let impl = get_implementation cm in
let locals, formals = locals_formals program tenv cn impl meth_kind in let locals, formals = locals_formals program tenv cn impl meth_kind in
@ -351,10 +343,7 @@ let create_local_procdesc program linereader cfg tenv node m =
method_annotation; method_annotation;
ret_type = JTransType.return_type program tenv ms meth_kind; ret_type = JTransType.return_type program tenv ms meth_kind;
} in } in
Cfg.Procdesc.create { Cfg.Procdesc.create cfg proc_attributes in
Cfg.Procdesc.cfg = cfg;
proc_attributes = proc_attributes;
} in
let start_kind = Cfg.Node.Start_node procdesc in let start_kind = Cfg.Node.Start_node procdesc in
let start_node = Cfg.Node.create cfg loc_start start_kind [] procdesc [] in let start_node = Cfg.Node.create cfg loc_start start_kind [] procdesc [] in
let exit_kind = (Cfg.Node.Exit_node procdesc) in let exit_kind = (Cfg.Node.Exit_node procdesc) in
@ -391,10 +380,7 @@ let create_external_procdesc program cfg tenv cn ms kind =
ProcAttributes.formals; ProcAttributes.formals;
ret_type = return_type; ret_type = return_type;
} in } in
Cfg.Procdesc.create { Cfg.Procdesc.create cfg proc_attributes)
Cfg.Procdesc.cfg = cfg;
proc_attributes = proc_attributes;
})
(** returns the procedure description of the given method and creates it if it hasn't been created before *) (** returns the procedure description of the given method and creates it if it hasn't been created before *)
let rec get_method_procdesc program cfg tenv cn ms kind = let rec get_method_procdesc program cfg tenv cn ms kind =

Loading…
Cancel
Save