fold_slope_range, java_get_vararg_values: got rid of refs

Reviewed By: ngorogiannis

Differential Revision: D8026721

fbshipit-source-id: 9564a19
master
Mehdi Bouaziz 7 years ago committed by Facebook Github Bot
parent 6c58614f40
commit 6b88176189

@ -306,19 +306,18 @@ let fold_instrs pdesc ~init ~f =
fold_nodes ~f:fold_node ~init pdesc fold_nodes ~f:fold_node ~init pdesc
(** iterate between two nodes or until we reach a branching structure *) (** fold between two nodes or until we reach a branching structure *)
let iter_slope_range f src_node dst_node = let fold_slope_range =
let visited = ref NodeSet.empty in let rec aux node visited acc ~f =
let rec do_node node = let visited = NodeSet.add node visited in
visited := NodeSet.add node !visited ; let acc = f acc node in
f node ;
match Node.get_succs node with match Node.get_succs node with
| [n] -> | [n] when not (NodeSet.mem n visited) ->
if not (NodeSet.mem n !visited) && not (Node.equal node dst_node) then do_node n aux n visited acc ~f
| _ -> | _ ->
() acc
in in
do_node src_node fun src_node dst_node ~init ~f -> aux src_node (NodeSet.singleton dst_node) init ~f
(** Set the exit node of the proc desc *) (** Set the exit node of the proc desc *)

@ -187,8 +187,8 @@ val iter_instrs : (Node.t -> Sil.instr -> unit) -> t -> unit
val iter_nodes : (Node.t -> unit) -> t -> unit val iter_nodes : (Node.t -> unit) -> t -> unit
(** iterate over all the nodes of a procedure *) (** iterate over all the nodes of a procedure *)
val iter_slope_range : (Node.t -> unit) -> Node.t -> Node.t -> unit val fold_slope_range : Node.t -> Node.t -> init:'accum -> f:('accum -> Node.t -> 'accum) -> 'accum
(** iterate between two nodes or until we reach a branching structure *) (** fold between two nodes or until we reach a branching structure *)
val set_succs_exn_only : Node.t -> Node.t list -> unit val set_succs_exn_only : Node.t -> Node.t list -> unit

@ -236,24 +236,22 @@ let method_is_initializer (tenv: Tenv.t) (proc_attributes: ProcAttributes.t) : b
(** Get the vararg values by looking for array assignments to the pvar. *) (** Get the vararg values by looking for array assignments to the pvar. *)
let java_get_vararg_values node pvar idenv = let java_get_vararg_values node pvar idenv =
let values = ref [] in let values_of_instr acc = function
let do_instr = function
| Sil.Store (Exp.Lindex (array_exp, _), _, content_exp, _) | Sil.Store (Exp.Lindex (array_exp, _), _, content_exp, _)
when Exp.equal (Exp.Lvar pvar) (Idenv.expand_expr idenv array_exp) -> when Exp.equal (Exp.Lvar pvar) (Idenv.expand_expr idenv array_exp) ->
(* Each vararg argument is an assignment to a pvar denoting an array of objects. *) (* Each vararg argument is an assignment to a pvar denoting an array of objects. *)
values := content_exp :: !values content_exp :: acc
| _ -> | _ ->
() acc
in in
let do_node n = List.iter ~f:do_instr (Procdesc.Node.get_instrs n) in let values_of_node acc n =
let () = Procdesc.Node.get_instrs n |> List.fold ~f:values_of_instr ~init:acc
match Errdesc.find_program_variable_assignment node pvar with
| Some (node', _) ->
Procdesc.iter_slope_range do_node node' node
| None ->
()
in in
!values match Errdesc.find_program_variable_assignment node pvar with
| Some (node', _) ->
Procdesc.fold_slope_range node' node ~f:values_of_node ~init:[]
| None ->
[]
let proc_calls resolve_attributes pdesc filter : (Typ.Procname.t * ProcAttributes.t) list = let proc_calls resolve_attributes pdesc filter : (Typ.Procname.t * ProcAttributes.t) list =

Loading…
Cancel
Save