From 90a544ad2e53de86eff6c1a71589e8b26435cd6c Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 17 Mar 2020 11:56:41 -0700 Subject: [PATCH] [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 --- infer/src/IR/Procname.ml | 6 +- infer/src/IR/Procname.mli | 14 +++- infer/src/biabduction/SymExec.ml | 8 +- infer/src/java/JProcname.ml | 20 ++--- infer/src/java/jTransType.ml | 9 +-- infer/src/topl/ToplUtils.ml | 10 +-- infer/src/unit/JavaProfilerSamplesTest.ml | 93 +++++++++++------------ 7 files changed, 82 insertions(+), 78 deletions(-) diff --git a/infer/src/IR/Procname.ml b/infer/src/IR/Procname.ml index edd4d7372..7d030b356 100644 --- a/infer/src/IR/Procname.ml +++ b/infer/src/IR/Procname.ml @@ -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 diff --git a/infer/src/IR/Procname.mli b/infer/src/IR/Procname.mli index 35ddb31a1..63ad63030 100644 --- a/infer/src/IR/Procname.mli +++ b/infer/src/IR/Procname.mli @@ -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. *) diff --git a/infer/src/biabduction/SymExec.ml b/infer/src/biabduction/SymExec.ml index 7dc19fa46..2dd890e11 100644 --- a/infer/src/biabduction/SymExec.ml +++ b/infer/src/biabduction/SymExec.ml @@ -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 "" [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 diff --git a/infer/src/java/JProcname.ml b/infer/src/java/JProcname.ml index 62a9e3bda..1af8b6bdf 100644 --- a/infer/src/java/JProcname.ml +++ b/infer/src/java/JProcname.ml @@ -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 = diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index bc1b8e809..fc277e6fd 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -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 *) diff --git a/infer/src/topl/ToplUtils.ml b/infer/src/topl/ToplUtils.ml index 7e6c9a16e..a7e097f50 100644 --- a/infer/src/topl/ToplUtils.ml +++ b/infer/src/topl/ToplUtils.ml @@ -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) diff --git a/infer/src/unit/JavaProfilerSamplesTest.ml b/infer/src/unit/JavaProfilerSamplesTest.ml index 47e90fd1c..08aa87bf7 100644 --- a/infer/src/unit/JavaProfilerSamplesTest.ml +++ b/infer/src/unit/JavaProfilerSamplesTest.ml @@ -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 "" - [ mk_split (Some "java.lang", "String") - ; mk_split (None, "int[]") - ; mk_split (None, "long") ] - 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: + [ mk_split (Some "java.lang", "String") + ; mk_split (None, "int[]") + ; mk_split (None, "long") ] + ~kind:Java.Non_Static ()) ; Procname.( - Java - (Java.make - (Typ.Name.Java.from_string "ggg.hhh.Iii") - None "" - [ mk_split (Some "java.lang", "String") - ; mk_split (None, "int[]") - ; mk_split (None, "long") ] - 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: + [ mk_split (Some "java.lang", "String") + ; mk_split (None, "int[]") + ; mk_split (None, "long") ] + ~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" - [ mk_split (Some "java.lang", "String") - ; mk_split (None, "int[]") - ; mk_split (None, "long") ] - Java.Non_Static)) + 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") ] + ~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 "" [] 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 "" [] 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)