You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
957 lines
32 KiB
957 lines
32 KiB
7 years ago
|
(*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
7 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
7 years ago
|
*)
|
||
|
|
||
|
open! IStd
|
||
|
|
||
|
(** To be used in 'list_constraint *)
|
||
|
type accept_more
|
||
7 years ago
|
|
||
|
and end_of_list
|
||
7 years ago
|
|
||
|
(** To be used in 'emptyness *)
|
||
|
type empty
|
||
7 years ago
|
|
||
|
and non_empty
|
||
7 years ago
|
|
||
|
(* Type shorthands *)
|
||
|
|
||
|
type typ = Typ.t
|
||
|
|
||
5 years ago
|
type c = Procname.C.t
|
||
7 years ago
|
|
||
5 years ago
|
type objc_cpp = Procname.ObjC_Cpp.t
|
||
7 years ago
|
|
||
5 years ago
|
type java = Procname.Java.t
|
||
6 years ago
|
|
||
7 years ago
|
type qual_name = QualifiedCppName.t
|
||
|
|
||
|
type templated_name = qual_name * Typ.template_arg list
|
||
|
|
||
|
(* Typ helpers *)
|
||
|
|
||
|
let template_args_of_template_spec_info = function
|
||
|
| Typ.NoTemplate ->
|
||
|
[]
|
||
|
| Typ.Template {args} ->
|
||
|
args
|
||
|
|
||
|
|
||
|
let templated_name_of_class_name class_name =
|
||
|
let open Typ in
|
||
|
match class_name with
|
||
|
| CStruct qual_name | CUnion qual_name | ObjcClass qual_name | ObjcProtocol qual_name ->
|
||
|
(qual_name, [])
|
||
|
| CppClass (qual_name, template_spec_info) ->
|
||
|
(qual_name, template_args_of_template_spec_info template_spec_info)
|
||
6 years ago
|
| JavaClass mangled_name ->
|
||
5 years ago
|
(QualifiedCppName.of_list [JavaClassName.to_string mangled_name], [])
|
||
6 years ago
|
|
||
|
|
||
|
let templated_name_of_java java =
|
||
|
let qual_name =
|
||
5 years ago
|
QualifiedCppName.of_list [Procname.Java.get_class_name java; Procname.Java.get_method java]
|
||
6 years ago
|
in
|
||
|
(qual_name, [])
|
||
7 years ago
|
|
||
|
|
||
|
(* Intermediate matcher types *)
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'arg_payload) name_matcher =
|
||
5 years ago
|
{ on_objc_cpp: 'context -> 'f_in -> objc_cpp -> 'f_out option
|
||
|
; on_qual_name: 'context -> 'f_in -> qual_name -> 'f_out option }
|
||
|
|
||
|
type ('f_in, 'f_out, 'list_constraint) template_arg =
|
||
|
{eat_template_arg: 'f_in * Typ.template_arg list -> ('f_out * Typ.template_arg list) option}
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'list_constraint, 'arg_payload) templ_matcher =
|
||
5 years ago
|
{ on_objc_cpp: 'context -> 'f_in -> objc_cpp -> ('f_out * Typ.template_arg list) option
|
||
7 years ago
|
; on_templated_name:
|
||
5 years ago
|
'context -> 'f_in -> templated_name -> ('f_out * Typ.template_arg list) option }
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'emptyness) path_extra =
|
||
|
| PathEmpty : ('context, 'f, 'f, empty) path_extra
|
||
6 years ago
|
| PathNonEmpty :
|
||
5 years ago
|
{on_objc_cpp: 'context -> 'f_in -> objc_cpp -> 'f_out option}
|
||
|
-> ('context, 'f_in, 'f_out, non_empty) path_extra
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'emptyness, 'arg_payload) path_matcher =
|
||
5 years ago
|
{ on_templated_name: 'context -> 'f_in -> templated_name -> 'f_out option
|
||
|
; path_extra: ('context, 'f_in, 'f_out, 'emptyness) path_extra }
|
||
7 years ago
|
|
||
6 years ago
|
type typ_matcher = typ -> bool
|
||
|
|
||
7 years ago
|
(* Combinators *)
|
||
|
|
||
5 years ago
|
let empty : ('context, 'f, 'f, empty, 'arg_payload) path_matcher =
|
||
6 years ago
|
let on_templated_name _context f (qual_name, template_args) =
|
||
7 years ago
|
match (QualifiedCppName.extract_last qual_name, template_args) with
|
||
|
| None, [] ->
|
||
5 years ago
|
Some f
|
||
7 years ago
|
| None, _ ->
|
||
|
assert false
|
||
|
| Some _, _ ->
|
||
|
None
|
||
|
in
|
||
5 years ago
|
{on_templated_name; path_extra= PathEmpty}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let name_cons :
|
||
5 years ago
|
('context, 'f_in, 'f_out, _, 'arg_payload) path_matcher
|
||
6 years ago
|
-> string
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher =
|
||
7 years ago
|
fun m name ->
|
||
5 years ago
|
let {on_templated_name} = m in
|
||
6 years ago
|
let match_fuzzy_name =
|
||
6 years ago
|
let fuzzy_name_regexp = name |> Str.quote |> Printf.sprintf "^%s\\(<.+>\\)?$" |> Str.regexp in
|
||
6 years ago
|
fun s -> Str.string_match fuzzy_name_regexp s 0
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_qual_name context f qual_name =
|
||
7 years ago
|
match QualifiedCppName.extract_last qual_name with
|
||
6 years ago
|
| Some (last, rest) when match_fuzzy_name last ->
|
||
6 years ago
|
on_templated_name context f (rest, [])
|
||
7 years ago
|
| _ ->
|
||
|
None
|
||
|
in
|
||
5 years ago
|
let on_objc_cpp context f (objc_cpp : Procname.ObjC_Cpp.t) =
|
||
6 years ago
|
if match_fuzzy_name objc_cpp.method_name then
|
||
6 years ago
|
on_templated_name context f (templated_name_of_class_name objc_cpp.class_name)
|
||
7 years ago
|
else None
|
||
|
in
|
||
5 years ago
|
{on_objc_cpp; on_qual_name}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let name_cons_f :
|
||
5 years ago
|
('context, 'f_in, 'f_out, _, 'arg_payload) path_matcher
|
||
6 years ago
|
-> ('context -> string -> bool)
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher =
|
||
6 years ago
|
fun m f_name ->
|
||
5 years ago
|
let {on_templated_name} = m in
|
||
6 years ago
|
let on_qual_name context f qual_name =
|
||
|
match QualifiedCppName.extract_last qual_name with
|
||
|
| Some (last, rest) when f_name context last ->
|
||
|
on_templated_name context f (rest, [])
|
||
|
| _ ->
|
||
|
None
|
||
|
in
|
||
5 years ago
|
let on_objc_cpp context f (objc_cpp : Procname.ObjC_Cpp.t) =
|
||
6 years ago
|
if f_name context objc_cpp.method_name then
|
||
|
on_templated_name context f (templated_name_of_class_name objc_cpp.class_name)
|
||
|
else None
|
||
|
in
|
||
5 years ago
|
{on_objc_cpp; on_qual_name}
|
||
6 years ago
|
|
||
|
|
||
6 years ago
|
let all_names_cons :
|
||
5 years ago
|
('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher
|
||
|
-> ('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher =
|
||
7 years ago
|
fun m ->
|
||
5 years ago
|
let {on_templated_name; path_extra= PathNonEmpty {on_objc_cpp}} = m in
|
||
6 years ago
|
let rec on_templated_name_rec context f templated_name =
|
||
|
match on_templated_name context f templated_name with
|
||
7 years ago
|
| Some _ as some ->
|
||
|
some
|
||
6 years ago
|
| None -> (
|
||
7 years ago
|
let qual_name, _template_args = templated_name in
|
||
|
match QualifiedCppName.extract_last qual_name with
|
||
|
| None ->
|
||
|
None
|
||
|
| Some (_last, rest) ->
|
||
6 years ago
|
on_templated_name_rec context f (rest, []) )
|
||
7 years ago
|
in
|
||
|
let on_templated_name = on_templated_name_rec in
|
||
5 years ago
|
let on_objc_cpp context f (objc_cpp : Procname.ObjC_Cpp.t) =
|
||
6 years ago
|
match on_objc_cpp context f objc_cpp with
|
||
7 years ago
|
| Some _ as some ->
|
||
|
some
|
||
|
| None ->
|
||
6 years ago
|
on_templated_name context f (templated_name_of_class_name objc_cpp.class_name)
|
||
7 years ago
|
in
|
||
5 years ago
|
{on_templated_name; path_extra= PathNonEmpty {on_objc_cpp}}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let templ_begin :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
|
-> ('context, 'f_in, 'f_out, accept_more, 'arg_payload) templ_matcher =
|
||
7 years ago
|
fun m ->
|
||
5 years ago
|
let {on_objc_cpp; on_qual_name} = m in
|
||
6 years ago
|
let on_templated_name context f (qual_name, template_args) =
|
||
5 years ago
|
match on_qual_name context f qual_name with None -> None | Some f -> Some (f, template_args)
|
||
7 years ago
|
in
|
||
5 years ago
|
let on_objc_cpp context f (objc_cpp : Procname.ObjC_Cpp.t) =
|
||
6 years ago
|
match on_objc_cpp context f objc_cpp with
|
||
7 years ago
|
| None ->
|
||
|
None
|
||
5 years ago
|
| Some f ->
|
||
7 years ago
|
let template_args = template_args_of_template_spec_info objc_cpp.template_args in
|
||
5 years ago
|
Some (f, template_args)
|
||
7 years ago
|
in
|
||
5 years ago
|
{on_objc_cpp; on_templated_name}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let templ_cons :
|
||
5 years ago
|
('context, 'f_in, 'f_interm, accept_more, 'arg_payload) templ_matcher
|
||
5 years ago
|
-> ('f_interm, 'f_out, 'lc) template_arg
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'lc, 'arg_payload) templ_matcher =
|
||
7 years ago
|
fun m template_arg ->
|
||
5 years ago
|
let {on_objc_cpp; on_templated_name} = m in
|
||
|
let {eat_template_arg} = template_arg in
|
||
6 years ago
|
let on_templated_name context f templated_name =
|
||
|
on_templated_name context f templated_name |> Option.bind ~f:eat_template_arg
|
||
|
in
|
||
|
let on_objc_cpp context f objc_cpp =
|
||
|
on_objc_cpp context f objc_cpp |> Option.bind ~f:eat_template_arg
|
||
7 years ago
|
in
|
||
5 years ago
|
{on_objc_cpp; on_templated_name}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let templ_end :
|
||
5 years ago
|
('context, 'f_in, 'f_out, _, 'arg_payload) templ_matcher
|
||
|
-> ('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher =
|
||
5 years ago
|
let match_empty_templ_args (f, template_args) =
|
||
|
match template_args with [] -> Some f | _ -> None
|
||
7 years ago
|
in
|
||
|
fun m ->
|
||
5 years ago
|
let {on_objc_cpp; on_templated_name} = m in
|
||
6 years ago
|
let on_templated_name context f templated_name =
|
||
|
on_templated_name context f templated_name |> Option.bind ~f:match_empty_templ_args
|
||
|
in
|
||
|
let on_objc_cpp context f objc_cpp =
|
||
|
on_objc_cpp context f objc_cpp |> Option.bind ~f:match_empty_templ_args
|
||
7 years ago
|
in
|
||
5 years ago
|
{on_templated_name; path_extra= PathNonEmpty {on_objc_cpp}}
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
module type Common = sig
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) matcher
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) dispatcher
|
||
7 years ago
|
|
||
5 years ago
|
val make_dispatcher :
|
||
|
('context, 'f, 'arg_payload) matcher list -> ('context, 'f, 'arg_payload) dispatcher
|
||
7 years ago
|
|
||
7 years ago
|
(* Template arguments *)
|
||
|
|
||
5 years ago
|
val any_typ : ('f, 'f, accept_more) template_arg
|
||
7 years ago
|
(** Eats a type *)
|
||
|
|
||
5 years ago
|
val capt_typ : (Typ.t -> 'f, 'f, accept_more) template_arg
|
||
|
(** Captures a type *)
|
||
|
|
||
|
val capt_int : (Int64.t -> 'f, 'f, accept_more) template_arg
|
||
7 years ago
|
(** Captures an int *)
|
||
|
|
||
5 years ago
|
val capt_all : (Typ.template_arg list -> 'f, 'f, end_of_list) template_arg
|
||
7 years ago
|
(** Captures all template args *)
|
||
|
|
||
5 years ago
|
val ( ~- ) : string -> ('context, 'f, 'f, 'arg_payload) name_matcher
|
||
7 years ago
|
(** Starts a path with a name *)
|
||
|
|
||
5 years ago
|
val ( ~+ ) : ('context -> string -> bool) -> ('context, 'f, 'f, 'arg_payload) name_matcher
|
||
6 years ago
|
(** Starts a path with a matching name that satisfies the given function *)
|
||
|
|
||
7 years ago
|
val ( &+ ) :
|
||
5 years ago
|
('context, 'f_in, 'f_interm, accept_more, 'arg_payload) templ_matcher
|
||
5 years ago
|
-> ('f_interm, 'f_out, 'lc) template_arg
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'lc, 'arg_payload) templ_matcher
|
||
7 years ago
|
(** Separate template arguments *)
|
||
|
|
||
|
val ( < ) :
|
||
5 years ago
|
('context, 'f_in, 'f_interm, 'arg_payload) name_matcher
|
||
5 years ago
|
-> ('f_interm, 'f_out, 'lc) template_arg
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'lc, 'arg_payload) templ_matcher
|
||
7 years ago
|
(** Starts template arguments after a name *)
|
||
|
|
||
|
val ( >:: ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, _, 'arg_payload) templ_matcher
|
||
6 years ago
|
-> string
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
7 years ago
|
(** Ends template arguments and starts a name *)
|
||
|
|
||
5 years ago
|
val ( >::+ ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'lc, 'arg_payload) templ_matcher
|
||
5 years ago
|
-> ('context -> string -> bool)
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
5 years ago
|
|
||
7 years ago
|
val ( &+...>:: ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, accept_more, 'arg_payload) templ_matcher
|
||
6 years ago
|
-> string
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
7 years ago
|
(** Ends template arguments with eats-ALL and starts a name *)
|
||
|
|
||
|
val ( &:: ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
6 years ago
|
-> string
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
7 years ago
|
(** Separates names (accepts ALL template arguments on the left one) *)
|
||
|
|
||
6 years ago
|
val ( &::+ ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
6 years ago
|
-> ('context -> string -> bool)
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
6 years ago
|
|
||
7 years ago
|
val ( <>:: ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
6 years ago
|
-> string
|
||
5 years ago
|
-> ('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
7 years ago
|
(** Separates names (accepts NO template arguments on the left one) *)
|
||
|
end
|
||
7 years ago
|
|
||
7 years ago
|
module Common = struct
|
||
|
(* Template arguments *)
|
||
7 years ago
|
|
||
7 years ago
|
(** Eats all template args *)
|
||
5 years ago
|
let any_template_args : ('f, 'f, end_of_list) template_arg =
|
||
|
let eat_template_arg (f, _) = Some (f, []) in
|
||
|
{eat_template_arg}
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
(** Eats a type *)
|
||
5 years ago
|
let any_typ : ('f, 'f, accept_more) template_arg =
|
||
|
let eat_template_arg (f, template_args) =
|
||
|
match template_args with Typ.TType _ :: rest -> Some (f, rest) | _ -> None
|
||
7 years ago
|
in
|
||
5 years ago
|
{eat_template_arg}
|
||
|
|
||
|
|
||
|
(** Captures a type *)
|
||
|
let capt_typ : (Typ.t -> 'f, 'f, accept_more) template_arg =
|
||
|
let eat_template_arg (f, template_args) =
|
||
|
match template_args with Typ.TType ty :: rest -> Some (f ty, rest) | _ -> None
|
||
7 years ago
|
in
|
||
5 years ago
|
{eat_template_arg}
|
||
7 years ago
|
|
||
|
|
||
|
(** Captures an int *)
|
||
5 years ago
|
let capt_int : (Int64.t -> 'f, 'f, accept_more) template_arg =
|
||
|
let eat_template_arg (f, template_args) =
|
||
|
match template_args with Typ.TInt i :: rest -> Some (f i, rest) | _ -> None
|
||
7 years ago
|
in
|
||
5 years ago
|
{eat_template_arg}
|
||
7 years ago
|
|
||
|
|
||
|
(** Captures all template args *)
|
||
5 years ago
|
let capt_all : (Typ.template_arg list -> 'f, 'f, end_of_list) template_arg =
|
||
|
let eat_template_arg (f, template_args) = Some (f template_args, []) in
|
||
|
{eat_template_arg}
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
let ( <! ) name_matcher () = templ_begin name_matcher
|
||
7 years ago
|
|
||
7 years ago
|
let ( >! ) templ_matcher () = templ_end templ_matcher
|
||
7 years ago
|
|
||
7 years ago
|
let ( &::! ) path_matcher name = name_cons path_matcher name
|
||
7 years ago
|
|
||
6 years ago
|
let ( &::+! ) path_matcher f_name = name_cons_f path_matcher f_name
|
||
|
|
||
7 years ago
|
let ( &::.*! ) path_matcher () = all_names_cons path_matcher
|
||
|
|
||
7 years ago
|
let ( ~- ) name = empty &::! name
|
||
7 years ago
|
|
||
6 years ago
|
let ( ~+ ) f_name = name_cons_f empty f_name
|
||
|
|
||
7 years ago
|
let ( &+ ) templ_matcher template_arg = templ_cons templ_matcher template_arg
|
||
7 years ago
|
|
||
7 years ago
|
let ( &+...>! ) templ_matcher () = templ_matcher &+ any_template_args >! ()
|
||
|
|
||
|
let ( <...>! ) name_matcher () = name_matcher <! () &+...>! ()
|
||
|
|
||
7 years ago
|
let ( < ) name_matcher template_arg = name_matcher <! () &+ template_arg
|
||
7 years ago
|
|
||
7 years ago
|
let ( >:: ) templ_matcher name = templ_matcher >! () &::! name
|
||
7 years ago
|
|
||
5 years ago
|
let ( >::+ ) templ_matcher f_name = templ_matcher >! () &::+! f_name
|
||
|
|
||
7 years ago
|
let ( &+...>:: ) templ_matcher name = templ_matcher &+...>! () &::! name
|
||
7 years ago
|
|
||
7 years ago
|
let ( &:: ) name_matcher name = name_matcher <...>! () &::! name
|
||
7 years ago
|
|
||
6 years ago
|
let ( &::+ ) name_matcher f_name = name_matcher <...>! () &::+! f_name
|
||
|
|
||
7 years ago
|
let ( <>:: ) name_matcher name = name_matcher <! () >:: name
|
||
|
end
|
||
7 years ago
|
|
||
5 years ago
|
module Call = struct
|
||
7 years ago
|
include Common
|
||
7 years ago
|
|
||
7 years ago
|
(** Little abstraction over arguments: currently actual args, we'll want formal args later *)
|
||
|
module FuncArg = struct
|
||
5 years ago
|
type 'arg_payload t = {exp: Exp.t; typ: Typ.t; arg_payload: 'arg_payload}
|
||
5 years ago
|
|
||
|
let typ {typ} = typ
|
||
7 years ago
|
|
||
5 years ago
|
let exp {exp} = exp
|
||
7 years ago
|
|
||
5 years ago
|
let arg_payload {arg_payload} = arg_payload
|
||
6 years ago
|
|
||
5 years ago
|
let get_var_exn {exp; typ} =
|
||
|
match exp with
|
||
6 years ago
|
| Exp.Var v ->
|
||
|
v
|
||
|
| e ->
|
||
5 years ago
|
Logging.(die InternalError) "Expected Lvar, got %a:%a" Exp.pp e (Typ.pp Pp.text) typ
|
||
7 years ago
|
end
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out) proc_matcher =
|
||
|
{ on_objc_cpp: 'context -> 'f_in -> objc_cpp -> 'f_out option
|
||
|
; on_c: 'context -> 'f_in -> c -> 'f_out option
|
||
|
; on_java: 'context -> 'f_in -> java -> 'f_out option }
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'arg_payload) on_args =
|
||
|
'context -> 'f_in * 'arg_payload FuncArg.t list -> ('f_out * 'arg_payload FuncArg.t list) option
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_proc_out, 'f_out, 'arg_payload) args_matcher =
|
||
5 years ago
|
{ on_proc: ('context, 'f_in, 'f_proc_out) proc_matcher
|
||
5 years ago
|
; on_args: ('context, 'f_proc_out, 'f_out, 'arg_payload) on_args }
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'arg_payload) one_arg_matcher =
|
||
|
{match_arg: 'context -> 'arg_payload FuncArg.t -> bool}
|
||
7 years ago
|
|
||
5 years ago
|
type ('arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) arg_capture =
|
||
|
{get_captured_value: 'arg_payload FuncArg.t -> 'arg_in; do_capture: 'f_in -> 'arg_out -> 'f_out}
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) one_arg =
|
||
|
{ one_arg_matcher: ('context, 'arg_payload) one_arg_matcher
|
||
|
; capture: ('arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) arg_capture }
|
||
7 years ago
|
|
||
5 years ago
|
type ('arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) arg_preparer =
|
||
|
{ on_empty:
|
||
|
('f_in -> 'arg_out -> 'f_out) -> 'f_in -> ('f_out * 'arg_payload FuncArg.t list) option
|
||
7 years ago
|
; wrapper: 'arg_in -> 'arg_out }
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'arg_payload) func_arg =
|
||
|
{eat_func_arg: ('context, 'f_in, 'f_out, 'arg_payload) on_args}
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) matcher =
|
||
|
{ on_objc_cpp: 'context -> objc_cpp -> 'arg_payload FuncArg.t list -> 'f option
|
||
|
; on_c: 'context -> c -> 'arg_payload FuncArg.t list -> 'f option
|
||
|
; on_java: 'context -> java -> 'arg_payload FuncArg.t list -> 'f option }
|
||
7 years ago
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) pre_result =
|
||
6 years ago
|
| DoesNotMatch
|
||
|
| Matches of 'f
|
||
5 years ago
|
| RetryWith of ('context, 'f, 'arg_payload) matcher
|
||
7 years ago
|
|
||
|
let pre_bind_opt opt ~f = match opt with None -> DoesNotMatch | Some x -> f x
|
||
|
|
||
|
let pre_map_opt opt ~f = match opt with None -> DoesNotMatch | Some x -> Matches (f x)
|
||
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'arg_payload) func_args_end =
|
||
|
on_args:('context, 'f_in, 'f_out, 'arg_payload) on_args
|
||
6 years ago
|
-> 'context
|
||
5 years ago
|
-> 'arg_payload FuncArg.t list
|
||
5 years ago
|
-> 'f_in
|
||
5 years ago
|
-> ('context, 'f_out, 'arg_payload) pre_result
|
||
5 years ago
|
|
||
5 years ago
|
type ('context, 'f_in, 'f_out, 'arg_payload) all_args_matcher =
|
||
5 years ago
|
{ on_objc_cpp:
|
||
|
'context
|
||
|
-> 'f_in
|
||
|
-> objc_cpp
|
||
5 years ago
|
-> 'arg_payload FuncArg.t list
|
||
|
-> ('context, 'f_out, 'arg_payload) pre_result
|
||
|
; on_c:
|
||
|
'context
|
||
|
-> 'f_in
|
||
|
-> c
|
||
|
-> 'arg_payload FuncArg.t list
|
||
|
-> ('context, 'f_out, 'arg_payload) pre_result
|
||
5 years ago
|
; on_java:
|
||
5 years ago
|
'context
|
||
|
-> 'f_in
|
||
|
-> java
|
||
|
-> 'arg_payload FuncArg.t list
|
||
|
-> ('context, 'f_out, 'arg_payload) pre_result }
|
||
5 years ago
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) dispatcher =
|
||
5 years ago
|
'context -> Procname.t -> 'arg_payload FuncArg.t list -> 'f option
|
||
7 years ago
|
|
||
6 years ago
|
let args_begin :
|
||
5 years ago
|
('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher
|
||
|
-> ('context, 'f_in, 'f_out, 'f_out, 'arg_payload) args_matcher =
|
||
5 years ago
|
let on_args _context f_args = Some f_args in
|
||
7 years ago
|
fun m ->
|
||
5 years ago
|
let {on_templated_name; path_extra= PathNonEmpty {on_objc_cpp}} = m in
|
||
6 years ago
|
let on_c context f (c : c) =
|
||
7 years ago
|
let template_args = template_args_of_template_spec_info c.template_args in
|
||
5 years ago
|
on_templated_name context f (c.name, template_args)
|
||
6 years ago
|
in
|
||
6 years ago
|
let on_java context f (java : java) =
|
||
5 years ago
|
on_templated_name context f (templated_name_of_java java)
|
||
6 years ago
|
in
|
||
5 years ago
|
let on_objc_cpp context f objc_cpp = on_objc_cpp context f objc_cpp in
|
||
|
let on_proc : _ proc_matcher = {on_objc_cpp; on_c; on_java} in
|
||
|
{on_proc; on_args}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let args_cons :
|
||
5 years ago
|
('context, 'f_in, 'f_proc_out, 'f_interm, 'arg_payload) args_matcher
|
||
|
-> ('context, 'f_interm, 'f_out, 'arg_payload) func_arg
|
||
|
-> ('context, 'f_in, 'f_proc_out, 'f_out, 'arg_payload) args_matcher =
|
||
7 years ago
|
fun m func_arg ->
|
||
5 years ago
|
let {on_proc; on_args} = m in
|
||
|
let {eat_func_arg} = func_arg in
|
||
|
let on_args context f_args = on_args context f_args |> Option.bind ~f:(eat_func_arg context) in
|
||
|
{on_proc; on_args}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let args_end :
|
||
5 years ago
|
('context, 'f_in, 'f_proc_out, 'f_out, 'arg_payload) args_matcher
|
||
|
-> ('context, 'f_proc_out, 'f_out, 'arg_payload) func_args_end
|
||
|
-> ('context, 'f_in, 'f_out, 'arg_payload) all_args_matcher =
|
||
7 years ago
|
fun m func_args_end ->
|
||
6 years ago
|
let {on_proc= {on_c; on_java; on_objc_cpp}; on_args} = m in
|
||
6 years ago
|
let on_c context f c args =
|
||
|
on_c context f c |> pre_bind_opt ~f:(func_args_end ~on_args context args)
|
||
|
in
|
||
|
let on_java context f java args =
|
||
|
on_java context f java |> pre_bind_opt ~f:(func_args_end ~on_args context args)
|
||
|
in
|
||
|
let on_objc_cpp context f objc_cpp args =
|
||
|
on_objc_cpp context f objc_cpp |> pre_bind_opt ~f:(func_args_end ~on_args context args)
|
||
7 years ago
|
in
|
||
6 years ago
|
{on_c; on_java; on_objc_cpp}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
let make_matcher :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) all_args_matcher
|
||
5 years ago
|
-> 'f_in
|
||
5 years ago
|
-> ('context, 'f_out, 'arg_payload) matcher =
|
||
7 years ago
|
fun m f ->
|
||
5 years ago
|
let ({on_c; on_java; on_objc_cpp} : (_, _, _, _) all_args_matcher) = m in
|
||
6 years ago
|
let on_objc_cpp context objc_cpp args =
|
||
|
match on_objc_cpp context f objc_cpp args with
|
||
7 years ago
|
| DoesNotMatch ->
|
||
|
None
|
||
|
| Matches res ->
|
||
|
Some res
|
||
|
| RetryWith {on_objc_cpp} ->
|
||
6 years ago
|
on_objc_cpp context objc_cpp args
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_c context c args =
|
||
|
match on_c context f c args with
|
||
7 years ago
|
| DoesNotMatch ->
|
||
|
None
|
||
|
| Matches res ->
|
||
|
Some res
|
||
|
| RetryWith {on_c} ->
|
||
6 years ago
|
on_c context c args
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_java context java args =
|
||
|
match on_java context f java args with
|
||
6 years ago
|
| DoesNotMatch ->
|
||
|
None
|
||
|
| Matches res ->
|
||
|
Some res
|
||
|
| RetryWith {on_java} ->
|
||
6 years ago
|
on_java context java args
|
||
6 years ago
|
in
|
||
|
{on_objc_cpp; on_c; on_java}
|
||
7 years ago
|
|
||
|
|
||
|
(** Simple implementation of a dispatcher, could be optimized later *)
|
||
5 years ago
|
let make_dispatcher :
|
||
|
('context, 'f, 'arg_payload) matcher list -> ('context, 'f, 'arg_payload) dispatcher =
|
||
7 years ago
|
fun matchers ->
|
||
6 years ago
|
let on_objc_cpp context objc_cpp args =
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) ->
|
||
6 years ago
|
matcher.on_objc_cpp context objc_cpp args )
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_c context c args =
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) -> matcher.on_c context c args)
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_java context java args =
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) -> matcher.on_java context java args)
|
||
6 years ago
|
in
|
||
6 years ago
|
fun context procname args ->
|
||
7 years ago
|
match procname with
|
||
|
| ObjC_Cpp objc_cpp ->
|
||
6 years ago
|
on_objc_cpp context objc_cpp args
|
||
7 years ago
|
| C c ->
|
||
6 years ago
|
on_c context c args
|
||
6 years ago
|
| Java java ->
|
||
6 years ago
|
on_java context java args
|
||
7 years ago
|
| _ ->
|
||
|
None
|
||
7 years ago
|
|
||
|
|
||
5 years ago
|
let merge_dispatchers :
|
||
5 years ago
|
('context, 'f, 'arg_payload) dispatcher
|
||
|
-> ('context, 'f, 'arg_payload) dispatcher
|
||
|
-> ('context, 'f, 'arg_payload) dispatcher =
|
||
5 years ago
|
fun dispatcher1 dispatcher2 context procname args ->
|
||
|
match dispatcher1 context procname args with
|
||
|
| Some _ as r ->
|
||
|
r
|
||
|
| None ->
|
||
|
dispatcher2 context procname args
|
||
|
|
||
|
|
||
7 years ago
|
(* Function args *)
|
||
7 years ago
|
|
||
7 years ago
|
(** Matches any arg *)
|
||
5 years ago
|
let match_any_arg : _ one_arg_matcher =
|
||
|
let match_arg _context _arg = true in
|
||
|
{match_arg}
|
||
7 years ago
|
|
||
7 years ago
|
|
||
7 years ago
|
(** Matches the type matched by the given path_matcher *)
|
||
6 years ago
|
let match_typ :
|
||
5 years ago
|
('context, _, _, non_empty, 'arg_payload) path_matcher
|
||
|
-> ('context, 'arg_payload) one_arg_matcher =
|
||
7 years ago
|
fun m ->
|
||
5 years ago
|
let ({on_templated_name} : (_, _, _, non_empty, 'arg_payload) path_matcher) = m in
|
||
6 years ago
|
let rec match_typ context typ =
|
||
7 years ago
|
match typ with
|
||
|
| {Typ.desc= Tstruct name} ->
|
||
6 years ago
|
name |> templated_name_of_class_name |> on_templated_name context () |> Option.is_some
|
||
7 years ago
|
| {Typ.desc= Tptr (typ, _ptr_kind)} ->
|
||
6 years ago
|
match_typ context typ
|
||
7 years ago
|
| _ ->
|
||
|
false
|
||
|
in
|
||
5 years ago
|
let match_arg context arg = match_typ context (FuncArg.typ arg) in
|
||
|
{match_arg}
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
(** Matches the type matched by the given typ_matcher *)
|
||
|
let match_prim_typ : typ_matcher -> _ one_arg_matcher =
|
||
|
fun on_typ ->
|
||
5 years ago
|
let match_arg _context arg = on_typ (FuncArg.typ arg) in
|
||
|
{match_arg}
|
||
6 years ago
|
|
||
|
|
||
7 years ago
|
(* Function argument capture *)
|
||
6 years ago
|
|
||
7 years ago
|
(** Do not capture this argument *)
|
||
5 years ago
|
let no_capture : (_, _, 'f, 'f, _) arg_capture =
|
||
7 years ago
|
let get_captured_value _arg = () in
|
||
|
let do_capture f _v = f in
|
||
|
{get_captured_value; do_capture}
|
||
|
|
||
|
|
||
|
(** Capture the argument *)
|
||
5 years ago
|
let capture_arg :
|
||
|
('arg_payload FuncArg.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) arg_capture =
|
||
7 years ago
|
let get_captured_value arg = arg in
|
||
|
let do_capture f v = f v in
|
||
|
{get_captured_value; do_capture}
|
||
|
|
||
|
|
||
5 years ago
|
(** Capture the argument value *)
|
||
5 years ago
|
let capture_arg_val :
|
||
|
('arg_payload, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) arg_capture =
|
||
|
let get_captured_value arg = FuncArg.arg_payload arg in
|
||
5 years ago
|
let do_capture f v = f v in
|
||
|
{get_captured_value; do_capture}
|
||
|
|
||
|
|
||
7 years ago
|
(** Capture the argument expression *)
|
||
5 years ago
|
let capture_arg_exp : (Exp.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, _) arg_capture =
|
||
7 years ago
|
let get_captured_value arg = FuncArg.exp arg in
|
||
|
let do_capture f v = f v in
|
||
|
{get_captured_value; do_capture}
|
||
|
|
||
|
|
||
6 years ago
|
(** Capture the argument local var or fail *)
|
||
5 years ago
|
let capture_arg_var_exn : (Ident.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, _) arg_capture =
|
||
6 years ago
|
let get_captured_value arg = FuncArg.get_var_exn arg in
|
||
|
let do_capture f v = f v in
|
||
|
{get_captured_value; do_capture}
|
||
|
|
||
|
|
||
7 years ago
|
let mandatory_arg =
|
||
|
let on_empty _do_capture _f = None in
|
||
|
let wrapper = Fn.id in
|
||
|
{on_empty; wrapper}
|
||
|
|
||
|
|
||
|
let optional_arg =
|
||
|
let on_empty do_capture f = Some (do_capture f None, []) in
|
||
|
let wrapper = Option.some in
|
||
|
{on_empty; wrapper}
|
||
|
|
||
|
|
||
6 years ago
|
let make_arg :
|
||
5 years ago
|
('arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) arg_preparer
|
||
|
-> ('context, 'arg_in, 'arg_out, 'f_in, 'f_out, 'arg_payload) one_arg
|
||
|
-> ('context, 'f_in, 'f_out, 'arg_payload) func_arg =
|
||
7 years ago
|
fun arg_preparer one_arg ->
|
||
|
let {on_empty; wrapper} = arg_preparer in
|
||
|
let {one_arg_matcher; capture} = one_arg in
|
||
5 years ago
|
let {match_arg} = one_arg_matcher in
|
||
7 years ago
|
let {get_captured_value; do_capture} = capture in
|
||
5 years ago
|
let eat_func_arg context (f, args) =
|
||
7 years ago
|
match args with
|
||
|
| [] ->
|
||
|
on_empty do_capture f
|
||
5 years ago
|
| arg :: rest when match_arg context arg ->
|
||
7 years ago
|
Some (arg |> get_captured_value |> wrapper |> do_capture f, rest)
|
||
|
| _ ->
|
||
|
None
|
||
|
in
|
||
5 years ago
|
{eat_func_arg}
|
||
7 years ago
|
|
||
|
|
||
5 years ago
|
let any_arg : ('context, unit, _, 'f, 'f, 'arg_payload) one_arg =
|
||
7 years ago
|
{one_arg_matcher= match_any_arg; capture= no_capture}
|
||
|
|
||
|
|
||
5 years ago
|
let capt_arg :
|
||
|
('context, 'arg_payload FuncArg.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) one_arg
|
||
5 years ago
|
=
|
||
7 years ago
|
{one_arg_matcher= match_any_arg; capture= capture_arg}
|
||
|
|
||
|
|
||
5 years ago
|
let all_args : ('context, 'arg_payload FuncArg.t list -> 'f_out, 'f_out, 'arg_payload) func_arg =
|
||
5 years ago
|
let eat_func_arg _context (f, args) = Some (f args, []) in
|
||
|
{eat_func_arg}
|
||
|
|
||
|
|
||
5 years ago
|
let capt_arg_payload :
|
||
|
('context, 'arg_payload, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) one_arg =
|
||
5 years ago
|
{one_arg_matcher= match_any_arg; capture= capture_arg_val}
|
||
|
|
||
|
|
||
5 years ago
|
let capt_exp : ('context, Exp.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) one_arg =
|
||
7 years ago
|
{one_arg_matcher= match_any_arg; capture= capture_arg_exp}
|
||
|
|
||
|
|
||
5 years ago
|
let capt_var_exn : ('context, Ident.t, 'wrapped_arg, 'wrapped_arg -> 'f, 'f, 'arg_payload) one_arg
|
||
|
=
|
||
6 years ago
|
{one_arg_matcher= match_any_arg; capture= capture_arg_var_exn}
|
||
|
|
||
|
|
||
6 years ago
|
let any_arg_of_typ m = {one_arg_matcher= match_typ (m <...>! ()); capture= no_capture}
|
||
|
|
||
7 years ago
|
let capt_arg_of_typ m = {one_arg_matcher= match_typ (m <...>! ()); capture= capture_arg}
|
||
|
|
||
5 years ago
|
let capt_arg_payload_of_typ m =
|
||
|
{one_arg_matcher= match_typ (m <...>! ()); capture= capture_arg_val}
|
||
|
|
||
|
|
||
7 years ago
|
let capt_exp_of_typ m = {one_arg_matcher= match_typ (m <...>! ()); capture= capture_arg_exp}
|
||
|
|
||
6 years ago
|
let one_arg_matcher_of_prim_typ typ =
|
||
6 years ago
|
let on_typ typ' = Typ.equal_ignore_quals typ typ' in
|
||
6 years ago
|
match_prim_typ on_typ
|
||
|
|
||
|
|
||
|
let any_arg_of_prim_typ typ =
|
||
|
{one_arg_matcher= one_arg_matcher_of_prim_typ typ; capture= no_capture}
|
||
|
|
||
|
|
||
|
let capt_exp_of_prim_typ typ =
|
||
|
{one_arg_matcher= one_arg_matcher_of_prim_typ typ; capture= capture_arg_exp}
|
||
6 years ago
|
|
||
|
|
||
7 years ago
|
(* Function args end *)
|
||
6 years ago
|
|
||
7 years ago
|
(** Matches if there is no function arguments left *)
|
||
5 years ago
|
let no_args_left : ('context, _, _, 'arg_payload) func_args_end =
|
||
7 years ago
|
let match_empty_args = function Some (f, []) -> Matches f | _ -> DoesNotMatch in
|
||
5 years ago
|
fun ~on_args context args f -> on_args context (f, args) |> match_empty_args
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
(** Matches any function arguments *)
|
||
5 years ago
|
let any_func_args : ('context, _, _, 'arg_payload) func_args_end =
|
||
5 years ago
|
fun ~on_args context args f -> on_args context (f, args) |> pre_map_opt ~f:fst
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
(** If [func_args_end1] does not match, use [func_args_end2] *)
|
||
6 years ago
|
let alternative_args_end :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) func_args_end
|
||
|
-> ('context, 'f_in, 'f_out, 'arg_payload) func_args_end
|
||
|
-> ('context, 'f_in, 'f_out, 'arg_payload) func_args_end =
|
||
6 years ago
|
fun func_args_end1 func_args_end2 ~on_args context args f_capt ->
|
||
|
match func_args_end1 ~on_args context args f_capt with
|
||
7 years ago
|
| DoesNotMatch ->
|
||
6 years ago
|
func_args_end2 ~on_args context args f_capt
|
||
7 years ago
|
| otherwise ->
|
||
|
otherwise
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
(** Retries matching with another matcher *)
|
||
5 years ago
|
let args_end_retry : _ matcher -> ('context, _, _, 'arg_payload) func_args_end =
|
||
6 years ago
|
fun m ~on_args:_ _context _args _f_capt -> RetryWith m
|
||
7 years ago
|
|
||
7 years ago
|
|
||
5 years ago
|
(** Retries matching with another matcher if the function does not have the exact number/types of
|
||
|
args *)
|
||
5 years ago
|
let exact_args_or_retry :
|
||
|
('context, 'f, 'arg_payload) matcher -> ('context, _, _, 'arg_payload) func_args_end =
|
||
7 years ago
|
fun m -> alternative_args_end no_args_left (args_end_retry m)
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
let wrong_args_internal_error : _ matcher =
|
||
|
let on_procname procname =
|
||
5 years ago
|
Logging.(die InternalError) "Unexpected number/types of arguments for %a" Procname.pp procname
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_c _context c _args = on_procname (C c) in
|
||
|
let on_java _context java _args = on_procname (Java java) in
|
||
|
let on_objc_cpp _context objc_cpp _args = on_procname (ObjC_Cpp objc_cpp) in
|
||
6 years ago
|
{on_c; on_java; on_objc_cpp}
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
let ( $! ) path_matcher () = args_begin path_matcher
|
||
7 years ago
|
|
||
7 years ago
|
let ( >$! ) templ_matcher () = templ_matcher >! () $! ()
|
||
7 years ago
|
|
||
7 years ago
|
let ( $*--> ) all_args_matcher f = make_matcher all_args_matcher f
|
||
7 years ago
|
|
||
7 years ago
|
let ( $+! ) args_matcher func_arg = args_cons args_matcher func_arg
|
||
|
|
||
|
let ( $!! ) one_arg () = make_arg mandatory_arg one_arg
|
||
|
|
||
|
let ( $?! ) one_arg () = make_arg optional_arg one_arg
|
||
|
|
||
|
let ( $+ ) args_matcher one_arg = args_matcher $+! (one_arg $!! ())
|
||
|
|
||
5 years ago
|
let ( $++ ) args_matcher () = args_matcher $+! all_args
|
||
|
|
||
7 years ago
|
let ( $+? ) args_matcher one_arg = args_matcher $+! (one_arg $?! ())
|
||
7 years ago
|
|
||
7 years ago
|
let ( >$ ) templ_matcher one_arg = templ_matcher >$! () $+ one_arg
|
||
7 years ago
|
|
||
7 years ago
|
let ( $* ) args_matcher func_args_end = args_end args_matcher func_args_end
|
||
7 years ago
|
|
||
7 years ago
|
let ( $--> ) args_matcher f = args_matcher $* no_args_left $*--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( $ ) name_matcher func_arg = name_matcher <...>! () $! () $+ func_arg
|
||
7 years ago
|
|
||
7 years ago
|
let ( <>$ ) name_matcher one_arg = name_matcher <! () >$ one_arg
|
||
7 years ago
|
|
||
7 years ago
|
let ( $+...$--> ) args_matcher f = args_matcher $* any_func_args $*--> f
|
||
7 years ago
|
|
||
5 years ago
|
let ( $++$--> ) args_matcher f = args_matcher $++ () $--> f
|
||
|
|
||
7 years ago
|
let ( >--> ) templ_matcher f = templ_matcher >$! () $+...$--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( >$$--> ) templ_matcher f = templ_matcher >$! () $--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( $$--> ) name_matcher f = name_matcher <...>! () $! () $--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( <>$$--> ) name_matcher f = name_matcher <! () >$$--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( &--> ) name_matcher f = name_matcher <...>! () $! () $+...$--> f
|
||
7 years ago
|
|
||
5 years ago
|
let ( &++> ) name_matcher f = name_matcher <...>! () $! () $++$--> f
|
||
|
|
||
7 years ago
|
let ( <>--> ) name_matcher f = name_matcher <! () >--> f
|
||
7 years ago
|
|
||
7 years ago
|
let ( &::.*--> ) name_matcher f = name_matcher <...>! () &::.*! () $! () $+...$--> f
|
||
|
|
||
7 years ago
|
let ( $!--> ) args_matcher f =
|
||
|
args_matcher $* exact_args_or_retry wrong_args_internal_error $*--> f
|
||
|
end
|
||
7 years ago
|
|
||
7 years ago
|
module type NameCommon = sig
|
||
7 years ago
|
include Common
|
||
|
|
||
7 years ago
|
val ( >--> ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, _, 'arg_payload) templ_matcher
|
||
6 years ago
|
-> 'f_in
|
||
5 years ago
|
-> ('context, 'f_out, 'arg_payload) matcher
|
||
7 years ago
|
|
||
7 years ago
|
val ( <>--> ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
|
-> 'f_in
|
||
|
-> ('context, 'f_out, 'arg_payload) matcher
|
||
7 years ago
|
|
||
|
val ( &--> ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
|
-> 'f_in
|
||
|
-> ('context, 'f_out, 'arg_payload) matcher
|
||
7 years ago
|
|
||
|
val ( &::.*--> ) :
|
||
5 years ago
|
('context, 'f_in, 'f_out, 'arg_payload) name_matcher
|
||
|
-> 'f_in
|
||
|
-> ('context, 'f_out, 'arg_payload) matcher
|
||
7 years ago
|
(** After a name, accepts ALL template arguments, accepts ALL path tails (names, templates),
|
||
5 years ago
|
accepts ALL function arguments, binds the function *)
|
||
7 years ago
|
end
|
||
|
|
||
|
module NameCommon = struct
|
||
|
include Common
|
||
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) matcher =
|
||
6 years ago
|
{ on_templated_name: 'context -> templated_name -> 'f option
|
||
|
; on_objc_cpp: 'context -> objc_cpp -> 'f option }
|
||
7 years ago
|
|
||
6 years ago
|
let make_matcher :
|
||
5 years ago
|
('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher
|
||
6 years ago
|
-> 'f_in
|
||
5 years ago
|
-> ('context, 'f_out, 'arg_payload) matcher =
|
||
7 years ago
|
fun m f ->
|
||
6 years ago
|
let ({on_templated_name; path_extra= PathNonEmpty {on_objc_cpp}}
|
||
5 years ago
|
: ('context, 'f_in, 'f_out, non_empty, 'arg_payload) path_matcher) =
|
||
7 years ago
|
m
|
||
|
in
|
||
5 years ago
|
let on_templated_name context templated_name = templated_name |> on_templated_name context f in
|
||
|
let on_objc_cpp context objc_cpp = objc_cpp |> on_objc_cpp context f in
|
||
7 years ago
|
{on_templated_name; on_objc_cpp}
|
||
7 years ago
|
|
||
|
|
||
|
let ( &-->! ) path_matcher f = make_matcher path_matcher f
|
||
|
|
||
|
let ( >--> ) templ_matcher f = templ_matcher >! () &-->! f
|
||
|
|
||
|
let ( <>--> ) name_matcher f = name_matcher <! () >--> f
|
||
|
|
||
7 years ago
|
let ( &--> ) name_matcher f = name_matcher <...>! () &-->! f
|
||
|
|
||
|
let ( &::.*--> ) name_matcher f = name_matcher <...>! () &::.*! () &-->! f
|
||
7 years ago
|
end
|
||
7 years ago
|
|
||
|
module ProcName = struct
|
||
|
include NameCommon
|
||
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) dispatcher = 'context -> Procname.t -> 'f option
|
||
7 years ago
|
|
||
5 years ago
|
let make_dispatcher :
|
||
|
('context, 'f, 'arg_payload) matcher list -> ('context, 'f, 'arg_payload) dispatcher =
|
||
7 years ago
|
fun matchers ->
|
||
6 years ago
|
let on_objc_cpp context objc_cpp =
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) -> matcher.on_objc_cpp context objc_cpp)
|
||
7 years ago
|
in
|
||
6 years ago
|
let on_templated_name context templated_name =
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) ->
|
||
6 years ago
|
matcher.on_templated_name context templated_name )
|
||
6 years ago
|
in
|
||
5 years ago
|
let on_java context (java : Procname.Java.t) =
|
||
6 years ago
|
let templated_name = templated_name_of_java java in
|
||
6 years ago
|
on_templated_name context templated_name
|
||
6 years ago
|
in
|
||
6 years ago
|
let on_c context (c : c) =
|
||
7 years ago
|
let template_args = template_args_of_template_spec_info c.template_args in
|
||
|
let templated_name = (c.name, template_args) in
|
||
6 years ago
|
on_templated_name context templated_name
|
||
7 years ago
|
in
|
||
6 years ago
|
fun context procname ->
|
||
6 years ago
|
match procname with
|
||
|
| ObjC_Cpp objc_cpp ->
|
||
6 years ago
|
on_objc_cpp context objc_cpp
|
||
6 years ago
|
| C c ->
|
||
6 years ago
|
on_c context c
|
||
6 years ago
|
| Java java ->
|
||
6 years ago
|
on_java context java
|
||
6 years ago
|
| _ ->
|
||
|
None
|
||
7 years ago
|
end
|
||
|
|
||
|
module TypName = struct
|
||
|
include NameCommon
|
||
|
|
||
5 years ago
|
type ('context, 'f, 'arg_payload) dispatcher = 'context -> Typ.name -> 'f option
|
||
7 years ago
|
|
||
5 years ago
|
let make_dispatcher :
|
||
|
('context, 'f, 'arg_payload) matcher list -> ('context, 'f, 'arg_payload) dispatcher =
|
||
6 years ago
|
fun matchers context typname ->
|
||
6 years ago
|
let templated_name = templated_name_of_class_name typname in
|
||
6 years ago
|
List.find_map matchers ~f:(fun (matcher : _ matcher) ->
|
||
6 years ago
|
matcher.on_templated_name context templated_name )
|
||
7 years ago
|
end
|