[java] improve procname constructor

Summary:
Make all arguments named and move function from `Procname.Java` to `Procname`, and making it return a `Procname.t` as opposed to `Procname.Java.t` (all callers want a `Procname` eventually).

Various other small fixes in the callers.

Reviewed By: skcho

Differential Revision: D20492305

fbshipit-source-id: e646cc799
master
Nikos Gorogiannis 5 years ago committed by Facebook GitHub Bot
parent 2fa0948e8d
commit 90a544ad2e

@ -36,7 +36,7 @@ module Java = struct
; kind: kind }
[@@deriving compare]
let make class_name return_type method_name parameters kind =
let make ~class_name ~return_type ~method_name ~parameters ~kind () =
{class_name; return_type; method_name; parameters; kind}
@ -731,6 +731,10 @@ let describe f pn =
F.pp_print_string f name
let make_java ~class_name ~return_type ~method_name ~parameters ~kind () =
Java (Java.make ~class_name ~return_type ~method_name ~parameters ~kind ())
module Hashable = struct
type nonrec t = t

@ -25,10 +25,6 @@ module Java : sig
val class_initializer_method_name : string
val make : Typ.Name.t -> java_type option -> string -> java_type list -> kind -> t
(** Create a Java procedure name from its class_name method_name args_type_name return_type_name
method_kind. *)
val replace_method_name : string -> t -> t
(** Replace the method name of an existing java procname. *)
@ -249,6 +245,16 @@ module UnitCache : sig
val create : unit -> (t -> 'a option) * (t -> 'a -> unit)
end
val make_java :
class_name:Typ.Name.t
-> return_type:Java.java_type option
-> method_name:string
-> parameters:Java.java_type list
-> kind:Java.kind
-> unit
-> t
(** Create a Java procedure name. *)
val empty_block : t
(** Empty block name. *)

@ -728,10 +728,10 @@ let resolve_and_analyze tenv ~caller_summary ?(has_clang_model = false) prop arg
protocol. *)
let call_constructor_url_update_args pname actual_params =
let url_pname =
Procname.Java
(Procname.Java.make
(Typ.Name.Java.from_string "java.net.URL")
None "<init>" [JavaSplitName.java_lang_string] Procname.Java.Non_Static)
Procname.make_java
~class_name:(Typ.Name.Java.from_string "java.net.URL")
~return_type:None ~method_name:Procname.Java.constructor_method_name
~parameters:[JavaSplitName.java_lang_string] ~kind:Procname.Java.Non_Static ()
in
if Procname.equal url_pname pname then
match actual_params with

@ -260,20 +260,20 @@ module JNI = struct
end
end
let create_procname ~classname ~methodname ~signature ~use_signature =
let create_procname ~classname ~methodname:method_name ~signature ~use_signature =
let signature = if use_signature then signature else JNI.void_method_with_no_arguments in
let name = Typ.Name.Java.from_string classname in
let args, ret_typ = JNI.parse_method_str signature in
let java_type_args = List.map ~f:JNI.to_java_type args in
let java_type_ret_typ =
let class_name = Typ.Name.Java.from_string classname in
let args, return_type = JNI.parse_method_str signature in
let parameters = List.map ~f:JNI.to_java_type args in
let return_type =
if
String.equal methodname Procname.Java.constructor_method_name
|| String.equal methodname Procname.Java.class_initializer_method_name
String.equal method_name Procname.Java.constructor_method_name
|| String.equal method_name Procname.Java.class_initializer_method_name
then None
else Some (JNI.to_java_type ret_typ)
else Some (JNI.to_java_type return_type)
in
Procname.Java
(Procname.Java.make name java_type_ret_typ methodname java_type_args Procname.Java.Non_Static)
Procname.make_java ~class_name ~return_type ~method_name ~parameters
~kind:Procname.Java.Non_Static ()
let make_void_signature_procname ~classname ~methodname =

@ -263,14 +263,11 @@ let get_method_kind m =
if Javalib.is_static_method m then Procname.Java.Static else Procname.Java.Non_Static
let rec get_method_procname program tenv cn ms method_kind =
let rec get_method_procname program tenv cn ms kind =
let (_ : Struct.t) = get_class_struct_typ program tenv cn in
let return_type_name, method_name, args_type_name = method_signature_names ms in
let return_type, method_name, parameters = method_signature_names ms in
let class_name = Typ.Name.Java.from_string (JBasics.cn_name cn) in
let proc_name_java =
Procname.Java.make class_name return_type_name method_name args_type_name method_kind
in
Procname.Java proc_name_java
Procname.make_java ~class_name ~return_type ~method_name ~parameters ~kind ()
(* create a mangled procname from an abstract or concrete method *)

@ -16,14 +16,14 @@ let topl_class_name : Typ.Name.t = Typ.Name.Java.from_string ToplName.topl_prope
let topl_class_typ = Typ.mk (Tstruct topl_class_name)
let topl_call ret_id (ret_typ : Typ.desc) loc name arg_ts : Sil.instr =
let topl_call ret_id (ret_typ : Typ.desc) loc method_name arg_ts : Sil.instr =
let e_fun =
let ret_typ = Some JavaSplitName.void in
let args_typ = List.map arg_ts ~f:(fun _ -> JavaSplitName.java_lang_object) in
let return_type = Some JavaSplitName.void in
let parameters = List.map arg_ts ~f:(fun _ -> JavaSplitName.java_lang_object) in
Exp.Const
(Const.Cfun
(Procname.Java
(Procname.Java.make topl_class_name ret_typ name args_typ Procname.Java.Static)))
(Procname.make_java ~class_name:topl_class_name ~return_type ~method_name ~parameters
~kind:Procname.Java.Static ()))
in
Sil.Call ((ret_id, Typ.mk ret_typ), e_fun, arg_ts, loc, CallFlags.default)

@ -180,69 +180,66 @@ let test_from_json_string_with_valid_input =
[ ( "label1"
, Procname.Set.of_list
[ Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "lll.mmm.Nnn")
None "<init>"
make_java
~class_name:(Typ.Name.Java.from_string "lll.mmm.Nnn")
~return_type:None ~method_name:Java.constructor_method_name
~parameters:
[ mk_split (Some "java.lang", "String")
; mk_split (None, "int[]")
; mk_split (None, "long") ]
Java.Non_Static))
~kind:Java.Non_Static ())
; Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "ggg.hhh.Iii")
None "<clinit>"
make_java
~class_name:(Typ.Name.Java.from_string "ggg.hhh.Iii")
~return_type:None ~method_name:Java.class_initializer_method_name
~parameters:
[ mk_split (Some "java.lang", "String")
; mk_split (None, "int[]")
; mk_split (None, "long") ]
Java.Non_Static)) ] )
~kind:Java.Non_Static ()) ] )
; ( "label2"
, Procname.Set.of_list
[ Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "ddd.eee.Fff")
(Some (mk_split (None, "char[][]")))
"methodTwo"
make_java
~class_name:(Typ.Name.Java.from_string "ddd.eee.Fff")
~return_type:(Some (mk_split (None, "char[][]")))
~method_name:"methodTwo"
~parameters:
[ mk_split (Some "java.lang", "String")
; mk_split (None, "int[]")
; mk_split (None, "long") ]
Java.Non_Static))
~kind:Java.Non_Static ())
; Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "aaa.bbb.Ccc")
(Some (mk_split (None, "void")))
"methodOne" [] Java.Non_Static)) ] ) ]
make_java
~class_name:(Typ.Name.Java.from_string "aaa.bbb.Ccc")
~return_type:(Some (mk_split (None, "void")))
~method_name:"methodOne" ~parameters:[] ~kind:Java.Non_Static ()) ] ) ]
in
let expected3 =
[ ( "label1"
, Procname.Set.of_list
[ Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "lll.mmm.Nnn")
None "<init>" [] Java.Non_Static))
make_java
~class_name:(Typ.Name.Java.from_string "lll.mmm.Nnn")
~return_type:None ~method_name:Java.constructor_method_name ~parameters:[]
~kind:Java.Non_Static ())
; Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "ggg.hhh.Iii")
None "<clinit>" [] Java.Non_Static)) ] )
make_java
~class_name:(Typ.Name.Java.from_string "ggg.hhh.Iii")
~return_type:None ~method_name:Java.class_initializer_method_name ~parameters:[]
~kind:Java.Non_Static ()) ] )
; ( "label2"
, Procname.Set.of_list
[ Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "ddd.eee.Fff")
(Some (mk_split (None, "void")))
"methodTwo" [] Java.Non_Static))
make_java
~class_name:(Typ.Name.Java.from_string "ddd.eee.Fff")
~return_type:(Some (mk_split (None, "void")))
~method_name:"methodTwo" ~parameters:[] ~kind:Java.Non_Static ())
; Procname.(
Java
(Java.make
(Typ.Name.Java.from_string "aaa.bbb.Ccc")
(Some (mk_split (None, "void")))
"methodOne" [] Java.Non_Static)) ] ) ]
make_java
~class_name:(Typ.Name.Java.from_string "aaa.bbb.Ccc")
~return_type:(Some (mk_split (None, "void")))
~method_name:"methodOne" ~parameters:[] ~kind:Java.Non_Static ()) ] ) ]
in
[ ("test_from_json_string_1", input1, expected1, true)
; ("test_from_json_string_2", input2, expected2, true)

Loading…
Cancel
Save