From 84e159f74daa07368dba4eaaf3c08b0460f0f072 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Tue, 20 Feb 2018 10:47:35 -0800 Subject: [PATCH] [hil] make get_access_paths understand closures/capture Reviewed By: jeremydubreil Differential Revision: D7012296 fbshipit-source-id: 5ce5d9b --- infer/src/IR/HilExp.ml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/infer/src/IR/HilExp.ml b/infer/src/IR/HilExp.ml index 047a9ce80..5c859d133 100644 --- a/infer/src/IR/HilExp.ml +++ b/infer/src/IR/HilExp.ml @@ -31,8 +31,17 @@ let rec pp fmt = function F.fprintf fmt "%a %s %a" pp e1 (Binop.str Pp.text op) pp e2 | Exception e -> F.fprintf fmt "exception %a" pp e - | Closure (pname, _) -> - F.fprintf fmt "closure(%a)" Typ.Procname.pp pname + | Closure (pname, captured) -> + let pp_item fmt (base, exp) = + match exp with + | AccessExpression Base b when AccessPath.equal_base b base -> + F.fprintf fmt "%a captured" AccessPath.pp_base b + | _ -> + F.fprintf fmt "%a captured as %a" AccessPath.pp_base base pp exp + in + F.fprintf fmt "closure(%a, %a)" Typ.Procname.pp pname + (PrettyPrintable.pp_collection ~pp_item) + captured | Constant c -> Const.pp Pp.text fmt c | Cast (typ, e) -> @@ -92,7 +101,9 @@ let get_access_paths exp0 = get_access_paths_ e acc | BinaryOperator (_, e1, e2) -> get_access_paths_ e1 acc |> get_access_paths_ e2 - | Closure _ | Constant _ | Sizeof _ -> + | Closure (_, captured) -> + List.fold captured ~f:(fun acc (_, e) -> get_access_paths_ e acc) ~init:acc + | Constant _ | Sizeof _ -> acc in get_access_paths_ exp0 []