From 2916c97e0ac03b5d100bcdaa381cf137509741a2 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 16 Mar 2018 08:32:19 -0700 Subject: [PATCH] [easy] Java nits Reviewed By: sblackshear Differential Revision: D7290400 fbshipit-source-id: 42945c8 --- infer/src/IR/Typ.ml | 6 +++--- infer/src/IR/Typ.mli | 10 +++++----- infer/src/backend/symExec.ml | 2 +- infer/src/eradicate/typeCheck.ml | 13 +++++-------- infer/src/java/jTransType.ml | 5 +---- infer/src/quandary/TaintAnalysis.ml | 8 ++------ 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index ac17175d9..e71cca7a1 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -593,11 +593,11 @@ module Procname = struct let get_method j = j.method_name - let replace_method j mname = {j with method_name= mname} + let replace_method_name method_name j = {j with method_name} - let replace_return_type j ret_type = {j with return_type= Some ret_type} + let replace_parameters parameters j = {j with parameters} - let replace_parameters j parameters = {j with parameters} + let replace_return_type ret_type j = {j with return_type= Some ret_type} let get_return_type j = return_type_to_string j Verbose diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 184b6ba65..b6ada6ba8 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -286,10 +286,13 @@ module Procname : sig (** Create a Java procedure name from its class_name method_name args_type_name return_type_name method_kind. *) - val replace_parameters : t -> java_type list -> t + val replace_method_name : string -> t -> t + (** Replace the method name of an existing java procname. *) + + val replace_parameters : java_type list -> t -> t (** Replace the parameters of a java procname. *) - val replace_return_type : t -> java_type -> t + val replace_return_type : java_type -> t -> t (** Replace the method of a java procname. *) val get_class_name : t -> string @@ -310,9 +313,6 @@ module Procname : sig val get_parameters : t -> java_type list (** Return the parameters of a java procedure name. *) - val replace_method : t -> string -> t - (** Replace the method name of an existing java procname. *) - val get_return_typ : t -> typ (** Return the return type of [pname_java]. return Tvoid if there's no return type *) diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 20f90b74a..a8888f988 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -620,7 +620,7 @@ let resolve_java_pname tenv prop args pname_java call_flags : Typ.Procname.Java. (Typ.Procname.Java.get_parameters resolved_pname_java) |> List.rev in - Typ.Procname.Java.replace_parameters resolved_pname_java resolved_params + Typ.Procname.Java.replace_parameters resolved_params resolved_pname_java in let resolved_pname_java, other_args = let pname = Typ.Procname.Java pname_java diff --git a/infer/src/eradicate/typeCheck.ml b/infer/src/eradicate/typeCheck.ml index 9a74c8e4c..ab77d6c68 100644 --- a/infer/src/eradicate/typeCheck.ml +++ b/infer/src/eradicate/typeCheck.ml @@ -709,11 +709,9 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get let pname_get_from_pname_put pname_put = let object_t = (Some "java.lang", "Object") in let parameters = [object_t] in - Typ.Procname.Java.replace_parameters - (Typ.Procname.Java.replace_return_type - (Typ.Procname.Java.replace_method pname_put "get") - object_t) - parameters + pname_put |> Typ.Procname.Java.replace_method_name "get" + |> Typ.Procname.Java.replace_return_type object_t + |> Typ.Procname.Java.replace_parameters parameters in match call_params with | ((_, Exp.Lvar pv_map), _) :: ((_, exp_key), _) :: ((_, exp_value), typ_value) :: _ @@ -917,9 +915,8 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get (DExp.Dconst Const.Cfun Typ.Procname.Java pname_java, args, loc, call_flags) -> let pname_java' = let object_t = (Some "java.lang", "Object") in - Typ.Procname.Java.replace_return_type - (Typ.Procname.Java.replace_method pname_java "get") - object_t + pname_java |> Typ.Procname.Java.replace_method_name "get" + |> Typ.Procname.Java.replace_return_type object_t in let fun_dexp = DExp.Dconst (Const.Cfun (Typ.Procname.Java pname_java')) in Some (DExp.Dretcall (fun_dexp, args, loc, call_flags)) diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index a1f3f3e11..4697f8654 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -180,10 +180,7 @@ let rec string_of_type vt = JBasics.cn_name cn -let package_to_string p = - let rec aux p = match p with [] -> "" | [p] -> p | p :: rest -> p ^ "." ^ aux rest in - match p with [] -> None | _ -> Some (aux p) - +let package_to_string = function [] -> None | p -> Some (String.concat ~sep:"." p) let cn_to_java_type cn = (package_to_string (JBasics.cn_package cn), JBasics.cn_simple_name cn) diff --git a/infer/src/quandary/TaintAnalysis.ml b/infer/src/quandary/TaintAnalysis.ml index 23b1dddab..d498415cb 100644 --- a/infer/src/quandary/TaintAnalysis.ml +++ b/infer/src/quandary/TaintAnalysis.ml @@ -542,12 +542,8 @@ module Make (TaintSpecification : TaintSpec.S) = struct let handle_model callee_pname access_tree model = let is_variadic = match callee_pname with - | Typ.Procname.Java pname -> ( - match List.rev (Typ.Procname.Java.get_parameters pname) with - | (_, "java.lang.Object[]") :: _ -> - true - | _ -> - false ) + | Typ.Procname.Java pname -> + Typ.Procname.Java.is_vararg pname | _ -> false in