@@ -10,33 +10,87 @@ open Hh_prelude
1010open Hack
1111module Fact_acc = Predicate. Fact_acc
1212
13+ let process_arg pos_map (exp , arg_pos ) =
14+ let arg =
15+ match exp with
16+ | Aast. String s when String. for_all ~f: (fun c -> Stdlib.Char. code c < 127 ) s
17+ ->
18+ (* TODO make this more general *)
19+ Some Argument. (Lit (StringLiteral. Key s))
20+ | Aast. Id (id_pos, _)
21+ | Aast. Class_const (_ , (id_pos , _ )) ->
22+ (match Xrefs.PosMap. find_opt id_pos pos_map with
23+ | Some (Xrefs. { target; _ } :: _ ) ->
24+ (* there shouldn't be more than one target for a symbol in that
25+ position *)
26+ Some (Argument. Xref target)
27+ | _ -> None )
28+ | _ -> None
29+ in
30+ (arg, arg_pos)
31+
32+ let process_call
33+ ~path
34+ ~pos_map
35+ ~fa_ref
36+ ~callee_pos
37+ ~id_pos
38+ ~receiver_span
39+ ~args
40+ ~arg_processor =
41+ let call_args = Build_fact. call_arguments (List. map args ~f: arg_processor) in
42+ let dispatch_arg =
43+ Option. (
44+ receiver_span >> = fun pos ->
45+ match Build_fact. call_arguments [(None , pos)] with
46+ | [arg] -> Some arg
47+ | _ -> None )
48+ in
49+ let callee_infos =
50+ match id_pos with
51+ | None -> []
52+ | Some pos ->
53+ (match Xrefs.PosMap. find_opt pos pos_map with
54+ | Some l -> l
55+ | None -> [] )
56+ in
57+ fa_ref :=
58+ Add_fact. file_call
59+ ~path
60+ callee_pos
61+ ~callee_infos
62+ ~call_args
63+ ~dispatch_arg
64+ ! fa_ref
65+ |> snd
66+
1367let call_handler ~path fa_ref (pos_map : Xrefs.pos_map ) =
1468 object (_self )
1569 inherit Tast_visitor. handler_base
1670
71+ method! at_expr _env expr =
72+ match expr with
73+ | (_ , _ , Aast. New ((_ , callee_pos , _ ), _ , args , _ , _ )) ->
74+ let arg_processor (_ , arg_pos , exp ) =
75+ process_arg pos_map (exp, arg_pos)
76+ in
77+ process_call
78+ ~path
79+ ~pos_map
80+ ~fa_ref
81+ ~callee_pos
82+ ~id_pos: (Some callee_pos)
83+ ~receiver_span: None
84+ ~args
85+ ~arg_processor
86+ | _ -> ()
87+
1788 method! at_Call _env call =
1889 let Aast. { func = (_, callee_pos, callee_exp); args; _ } = call in
19- let f arg =
90+ let arg_processor arg =
2091 let (_, arg_pos, exp) = Aast_utils. arg_to_expr arg in
21- let arg =
22- match exp with
23- | Aast. String s
24- when String. for_all ~f: (fun c -> Stdlib.Char. code c < 127 ) s ->
25- (* TODO make this more general *)
26- Some Argument. (Lit (StringLiteral. Key s))
27- | Aast. Id (id_pos, _)
28- | Aast. Class_const (_ , (id_pos , _ )) ->
29- (match Xrefs.PosMap. find_opt id_pos pos_map with
30- | Some (Xrefs. { target; _ } :: _ ) ->
31- (* there shouldn't be more than one target for a symbol in that
32- position *)
33- Some (Argument. Xref target)
34- | _ -> None )
35- | _ -> None
36- in
37- (arg, arg_pos)
92+ process_arg pos_map (exp, arg_pos)
3893 in
39- let call_args = Build_fact. call_arguments (List. map args ~f ) in
4094 let (id_pos, receiver_span) =
4195 match callee_exp with
4296 | Aast. Id (id_pos , _ ) -> (Some id_pos, None )
@@ -46,30 +100,15 @@ let call_handler ~path fa_ref (pos_map : Xrefs.pos_map) =
46100 (Some id_pos, Some receiver_span)
47101 | _ -> (None , None )
48102 in
49- let dispatch_arg =
50- Option. (
51- receiver_span >> = fun pos ->
52- match Build_fact. call_arguments [(None , pos)] with
53- | [arg] -> Some arg
54- | _ -> None )
55- in
56- let callee_infos =
57- match id_pos with
58- | None -> []
59- | Some pos ->
60- (match Xrefs.PosMap. find_opt pos pos_map with
61- | Some l -> l
62- | None -> [] )
63- in
64- fa_ref :=
65- Add_fact. file_call
66- ~path
67- callee_pos
68- ~callee_infos
69- ~call_args
70- ~dispatch_arg
71- ! fa_ref
72- |> snd
103+ process_call
104+ ~path
105+ ~pos_map
106+ ~fa_ref
107+ ~callee_pos
108+ ~id_pos
109+ ~receiver_span
110+ ~args
111+ ~arg_processor
73112 end
74113
75114let process_calls ctx path tast map_pos_decl fa =
0 commit comments