Procdesc.specialize_type_proc: fold -> filter_map

Reviewed By: jeremydubreil

Differential Revision: D8026820

fbshipit-source-id: b9b463f
master
Mehdi Bouaziz 7 years ago committed by Facebook Github Bot
parent 6b88176189
commit 0ba993fb68

@ -556,7 +556,7 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
let redirect_typename origin_id = let redirect_typename origin_id =
try Some (Ident.Map.find origin_id !subst_map) with Caml.Not_found -> None try Some (Ident.Map.find origin_id !subst_map) with Caml.Not_found -> None
in in
let convert_instr instrs = function let convert_instr = function
| Sil.Load | Sil.Load
( id ( id
, (Exp.Lvar origin_pvar as origin_exp) , (Exp.Lvar origin_pvar as origin_exp)
@ -567,20 +567,20 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
origin_typename origin_typename
in in
subst_map := Ident.Map.add id specialized_typname !subst_map ; subst_map := Ident.Map.add id specialized_typname !subst_map ;
Sil.Load (id, convert_exp origin_exp, mk_ptr_typ specialized_typname, loc) :: instrs Some (Sil.Load (id, convert_exp origin_exp, mk_ptr_typ specialized_typname, loc))
| Sil.Load (id, (Exp.Var origin_id as origin_exp), ({Typ.desc= Tstruct _} as origin_typ), loc) -> | Sil.Load (id, (Exp.Var origin_id as origin_exp), ({Typ.desc= Tstruct _} as origin_typ), loc) ->
let updated_typ : Typ.t = let updated_typ : Typ.t =
try Typ.mk ~default:origin_typ (Tstruct (Ident.Map.find origin_id !subst_map)) try Typ.mk ~default:origin_typ (Tstruct (Ident.Map.find origin_id !subst_map))
with Caml.Not_found -> origin_typ with Caml.Not_found -> origin_typ
in in
Sil.Load (id, convert_exp origin_exp, updated_typ, loc) :: instrs Some (Sil.Load (id, convert_exp origin_exp, updated_typ, loc))
| Sil.Load (id, origin_exp, origin_typ, loc) -> | Sil.Load (id, origin_exp, origin_typ, loc) ->
Sil.Load (id, convert_exp origin_exp, origin_typ, loc) :: instrs Some (Sil.Load (id, convert_exp origin_exp, origin_typ, loc))
| Sil.Store (assignee_exp, origin_typ, origin_exp, loc) -> | Sil.Store (assignee_exp, origin_typ, origin_exp, loc) ->
let set_instr = let set_instr =
Sil.Store (convert_exp assignee_exp, origin_typ, convert_exp origin_exp, loc) Sil.Store (convert_exp assignee_exp, origin_typ, convert_exp origin_exp, loc)
in in
set_instr :: instrs Some set_instr
| Sil.Call | Sil.Call
( return_ids ( return_ids
, Exp.Const (Const.Cfun (Typ.Procname.Java callee_pname_java)) , Exp.Const (Const.Cfun (Typ.Procname.Java callee_pname_java))
@ -600,25 +600,25 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
let call_instr = let call_instr =
Sil.Call (return_ids, Exp.Const (Const.Cfun redirected_pname), args, loc, call_flags) Sil.Call (return_ids, Exp.Const (Const.Cfun redirected_pname), args, loc, call_flags)
in in
call_instr :: instrs Some call_instr
| Sil.Call (return_ids, origin_call_exp, origin_args, loc, call_flags) -> | Sil.Call (return_ids, origin_call_exp, origin_args, loc, call_flags) ->
let converted_args = List.map ~f:(fun (exp, typ) -> (convert_exp exp, typ)) origin_args in let converted_args = List.map ~f:(fun (exp, typ) -> (convert_exp exp, typ)) origin_args in
let call_instr = let call_instr =
Sil.Call (return_ids, convert_exp origin_call_exp, converted_args, loc, call_flags) Sil.Call (return_ids, convert_exp origin_call_exp, converted_args, loc, call_flags)
in in
call_instr :: instrs Some call_instr
| Sil.Prune (origin_exp, loc, is_true_branch, if_kind) -> | Sil.Prune (origin_exp, loc, is_true_branch, if_kind) ->
Sil.Prune (convert_exp origin_exp, loc, is_true_branch, if_kind) :: instrs Some (Sil.Prune (convert_exp origin_exp, loc, is_true_branch, if_kind))
| Sil.Declare_locals (typed_vars, loc) -> | Sil.Declare_locals (typed_vars, loc) ->
let new_typed_vars = let new_typed_vars =
List.map ~f:(fun (pvar, typ) -> (convert_pvar pvar, typ)) typed_vars List.map ~f:(fun (pvar, typ) -> (convert_pvar pvar, typ)) typed_vars
in in
Sil.Declare_locals (new_typed_vars, loc) :: instrs Some (Sil.Declare_locals (new_typed_vars, loc))
| Sil.Nullify _ | Abstract _ | Sil.Remove_temps _ -> | Sil.Nullify _ | Abstract _ | Sil.Remove_temps _ ->
(* these are generated instructions that will be replaced by the preanalysis *) (* these are generated instructions that will be replaced by the preanalysis *)
instrs None
in in
let f_instr_list instrs = List.fold ~f:convert_instr ~init:[] instrs |> List.rev in let f_instr_list instrs = List.filter_map ~f:convert_instr instrs in
convert_cfg ~callee_pdesc ~resolved_pdesc ~f_instr_list convert_cfg ~callee_pdesc ~resolved_pdesc ~f_instr_list

Loading…
Cancel
Save