From 04d2882a6b9903eb26e8af48ddf62d34b7119e43 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Wed, 17 Jan 2018 10:36:26 -0800 Subject: [PATCH] [cleanup] organize Java-specific functions on types Summary: Was trying to decide where to add a new Java utility function and realized that things are a bit disorganized. Some operations on `Typ.Name.t`'s live in `Typ.Procname`, and some live inside an inner `Java` module whereas some are outside of the module with a `java_` prefix. Let's move toward putting all Java/C/Objc/C++-specific functions in dedicated modules. This diff does some of the work for Java. There are Java-specific functions that operate on `Typ.Procname.t`'s that will have to be converted to work on `Typ.Procname.Java.t`'s, but changing those clients will be more involved. Will also move C/Objc/C++ functions in a follow-up. Reviewed By: jeremydubreil Differential Revision: D6737724 fbshipit-source-id: cdd6e68 --- infer/src/IR/DecompiledExp.ml | 2 +- infer/src/IR/Localise.ml | 8 +- infer/src/IR/Typ.ml | 468 +++++++++--------- infer/src/IR/Typ.mli | 116 +++-- infer/src/absint/PatternMatch.ml | 10 +- infer/src/absint/PatternMatch.mli | 2 +- infer/src/backend/inferconfig.ml | 4 +- infer/src/backend/interproc.ml | 2 +- infer/src/backend/rearrange.ml | 10 +- infer/src/backend/symExec.ml | 14 +- infer/src/backend/tabulation.ml | 2 +- infer/src/checkers/BoundedCallTree.ml | 2 +- infer/src/checkers/Litho.ml | 4 +- infer/src/checkers/NullabilitySuggest.ml | 6 +- infer/src/checkers/androidFramework.ml | 2 +- infer/src/checkers/annotationReachability.ml | 6 +- .../checkers/fragmentRetainsViewChecker.ml | 6 +- infer/src/concurrency/RacerD.ml | 24 +- infer/src/concurrency/RacerDConfig.ml | 12 +- infer/src/eradicate/eradicate.ml | 4 +- infer/src/eradicate/eradicateChecks.ml | 8 +- infer/src/eradicate/typeCheck.ml | 18 +- infer/src/eradicate/typeErr.ml | 4 +- infer/src/java/jTrans.ml | 4 +- infer/src/java/jTransType.ml | 4 +- infer/src/labs/ResourceLeaks.ml | 2 +- infer/src/quandary/JavaTaintAnalysis.ml | 4 +- infer/src/quandary/JavaTrace.ml | 10 +- infer/src/quandary/TaintAnalysis.ml | 4 +- 29 files changed, 386 insertions(+), 376 deletions(-) diff --git a/infer/src/IR/DecompiledExp.ml b/infer/src/IR/DecompiledExp.ml index fb2c7953d..c231eb920 100644 --- a/infer/src/IR/DecompiledExp.ml +++ b/infer/src/IR/DecompiledExp.ml @@ -61,7 +61,7 @@ let rec to_string = function let s = match pname with | Typ.Procname.Java pname_java -> - Typ.Procname.java_get_method pname_java + Typ.Procname.Java.get_method pname_java | _ -> Typ.Procname.to_string pname in diff --git a/infer/src/IR/Localise.ml b/infer/src/IR/Localise.ml index f8cf94855..18c25a70d 100644 --- a/infer/src/IR/Localise.ml +++ b/infer/src/IR/Localise.ml @@ -252,14 +252,14 @@ let rec format_typ typ = let format_field f = - if Config.curr_language_is Config.Java then Typ.Fieldname.java_get_field f + if Config.curr_language_is Config.Java then Typ.Fieldname.Java.get_field f else Typ.Fieldname.to_string f let format_method pname = match pname with | Typ.Procname.Java pname_java -> - Typ.Procname.java_get_method pname_java + Typ.Procname.Java.get_method pname_java | _ -> Typ.Procname.to_string pname @@ -462,8 +462,8 @@ let desc_context_leak pname context_typ fieldname leak_path : error_desc = | Typ.Procname.Java pname_java -> MF.monospaced_to_string (Printf.sprintf "%s.%s" - (Typ.Procname.java_get_class_name pname_java) - (Typ.Procname.java_get_method pname_java)) + (Typ.Procname.Java.get_class_name pname_java) + (Typ.Procname.Java.get_method pname_java)) | _ -> "" in diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index db51fc313..0785411c2 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -396,6 +396,41 @@ module Name = struct let java_io_serializable = from_string "java.io.Serializable" let java_lang_cloneable = from_string "java.lang.Cloneable" + + (** Given a package.class_name string, it looks for the latest dot and split the string + in two (package, class_name) *) + let split_classname package_classname = + match String.rsplit2 package_classname ~on:'.' with + | Some (x, y) -> + (Some x, y) + | None -> + (None, package_classname) + + + let split_typename typename = split_classname (name typename) + + let get_parent_class class_name = + let package_name, class_name_no_package = split_typename class_name in + match String.rsplit2 ~on:'$' class_name_no_package with + | Some (parent_class, _) -> + Some (from_package_class (Option.value ~default:"" package_name) parent_class) + | None -> + None + + + let is_anonymous_inner_class_name class_name = + let class_name_no_package = snd (split_typename class_name) in + match String.rsplit2 class_name_no_package ~on:'$' with + | Some (_, s) -> + let is_int = + try + ignore (int_of_string (String.strip s)) ; + true + with Failure _ -> false + in + is_int + | None -> + false end module Cpp = struct @@ -501,12 +536,6 @@ let rec java_from_string : string -> t = function type typ = t module Procname = struct - (* e.g. ("", "int") for primitive types or ("java.io", "PrintWriter") for objects *) - type java_type = string option * string - - (* compare in inverse order *) - let compare_java_type (p1, c1) (p2, c2) = [%compare : string * string option] (c1, p1) (c2, p2) - type method_kind = | Non_Static (* in Java, procedures called with invokevirtual, invokespecial, and invokeinterface *) @@ -516,14 +545,117 @@ module Procname = struct let equal_method_kind = [%compare.equal : method_kind] - (** Type of java procedure names. *) - type java = - { method_name: string - ; parameters: java_type list - ; class_name: Name.t - ; return_type: java_type option (* option because constructors have no return type *) - ; kind: method_kind } - [@@deriving compare] + (** Level of verbosity of some to_string functions. *) + type detail_level = Verbose | Non_verbose | Simple [@@deriving compare] + + let equal_detail_level = [%compare.equal : detail_level] + + let is_verbose v = match v with Verbose -> true | _ -> false + + module Java = struct + (* TODO: use Mangled.t here *) + type java_type = string option * string + + (* compare in inverse order *) + let compare_java_type (p1, c1) (p2, c2) = [%compare : string * string option] (c1, p1) (c2, p2) + + (** Type of java procedure names. *) + type t = + { method_name: string + ; parameters: java_type list + ; class_name: Name.t + ; return_type: java_type option (* option because constructors have no return type *) + ; kind: method_kind } + [@@deriving compare] + + let make class_name return_type method_name parameters kind = + {class_name; return_type; method_name; parameters; kind} + + + (** A type is a pair (package, type_name) that is translated in a string package.type_name *) + let type_to_string_verbosity p verbosity = + match p with + | None, typ -> + typ + | Some p, cls -> + if is_verbose verbosity then p ^ "." ^ cls else cls + + + (** Given a list of types, it creates a unique string of types separated by commas *) + let rec param_list_to_string inputList verbosity = + match inputList with + | [] -> + "" + | [head] -> + type_to_string_verbosity head verbosity + | head :: rest -> + type_to_string_verbosity head verbosity ^ "," ^ param_list_to_string rest verbosity + + + (** It is the same as java_type_to_string_verbosity, but Java return types are optional because + of constructors without type *) + let return_type_to_string j verbosity = + match j.return_type with None -> "" | Some typ -> type_to_string_verbosity typ verbosity + + + let get_class_name j = Name.name j.class_name + + let get_class_type_name j = j.class_name + + let get_simple_class_name j = snd (Name.Java.split_classname (get_class_name j)) + + let get_package j = fst (Name.Java.split_classname (get_class_name j)) + + let get_method j = j.method_name + + let replace_method j mname = {j with method_name= mname} + + let replace_return_type j ret_type = {j with return_type= Some ret_type} + + let replace_parameters j parameters = {j with parameters} + + let get_return_type j = return_type_to_string j Verbose + + let get_parameters j = j.parameters + + (** Prints a string of a java procname with the given level of verbosity *) + let to_string ?(withclass= false) j verbosity = + match verbosity with + | Verbose | Non_verbose -> + (* if verbose, then package.class.method(params): rtype, + else rtype package.class.method(params) + verbose is used for example to create unique filenames, non_verbose to create reports *) + let return_type = return_type_to_string j verbosity in + let params = param_list_to_string j.parameters verbosity in + let class_name = + type_to_string_verbosity (Name.Java.split_typename j.class_name) verbosity + in + let separator = + match (j.return_type, verbosity) with + | None, _ -> + "" + | Some _, Verbose -> + ":" + | _ -> + " " + in + let output = class_name ^ "." ^ j.method_name ^ "(" ^ params ^ ")" in + if equal_detail_level verbosity Verbose then output ^ separator ^ return_type + else return_type ^ separator ^ output + | Simple -> + (* methodname(...) or without ... if there are no parameters *) + let cls_prefix = + if withclass then + type_to_string_verbosity (Name.Java.split_typename j.class_name) verbosity ^ "." + else "" + in + let params = match j.parameters with [] -> "" | _ -> "..." in + let method_name = + if String.equal j.method_name "" then get_simple_class_name j + else cls_prefix ^ j.method_name + in + method_name ^ "(" ^ params ^ ")" + end (** Type of c procedure names. *) type c = @@ -556,7 +688,7 @@ module Procname = struct (** Type of procedure names. *) type t = - | Java of java + | Java of Java.t | C of c | Linters_dummy_method | Block of block_name @@ -568,11 +700,6 @@ module Procname = struct let hash = Hashtbl.hash - (** Level of verbosity of some to_string functions. *) - type detail_level = Verbose | Non_verbose | Simple [@@deriving compare] - - let equal_detail_level = [%compare.equal : detail_level] - let objc_method_kind_of_bool is_instance = if is_instance then ObjCInstanceMethod else ObjCClassMethod @@ -587,47 +714,6 @@ module Procname = struct let empty_block = Block "" - let is_verbose v = match v with Verbose -> true | _ -> false - - (** A type is a pair (package, type_name) that is translated in a string package.type_name *) - let java_type_to_string_verbosity p verbosity = - match p with - | None, typ -> - typ - | Some p, cls -> - if is_verbose verbosity then p ^ "." ^ cls else cls - - - (** Given a list of types, it creates a unique string of types separated by commas *) - let rec java_param_list_to_string inputList verbosity = - match inputList with - | [] -> - "" - | [head] -> - java_type_to_string_verbosity head verbosity - | head :: rest -> - java_type_to_string_verbosity head verbosity ^ "," - ^ java_param_list_to_string rest verbosity - - - (** It is the same as java_type_to_string_verbosity, but Java return types are optional because - of constructors without type *) - let java_return_type_to_string j verbosity = - match j.return_type with None -> "" | Some typ -> java_type_to_string_verbosity typ verbosity - - - (** Given a package.class_name string, it looks for the latest dot and split the string - in two (package, class_name) *) - let split_classname package_classname = - match String.rsplit2 package_classname ~on:'.' with - | Some (x, y) -> - (Some x, y) - | None -> - (None, package_classname) - - - let split_typename typename = split_classname (Name.name typename) - let c name mangled template_args ~is_generic_model = {name; mangled= Some mangled; template_args; is_generic_model} @@ -640,10 +726,6 @@ module Procname = struct ; is_generic_model= false } - let java class_name return_type method_name parameters kind = - {class_name; return_type; method_name; parameters; kind} - - (** Create an objc procedure name from a class_name and method_name. *) let objc_cpp class_name method_name kind template_args ~is_generic_model = {class_name; method_name; kind; template_args; is_generic_model} @@ -676,88 +758,13 @@ module Procname = struct t - let rec objc_cpp_replace_method_name t (new_method_name: string) = - match t with - | ObjC_Cpp osig -> - ObjC_Cpp {osig with method_name= new_method_name} - | WithBlockParameters (base, blocks) -> - WithBlockParameters (objc_cpp_replace_method_name base new_method_name, blocks) - | C _ | Block _ | Linters_dummy_method | Java _ -> - t - - - (** Get the class name of a Objective-C/C++ procedure name. *) - let objc_cpp_get_class_name objc_cpp = Name.name objc_cpp.class_name - - let objc_cpp_get_class_type_name objc_cpp = objc_cpp.class_name - - (** Return the package.classname of a java procname. *) - let java_get_class_name (j: java) = Name.name j.class_name - - (** Return the package.classname as a typename of a java procname. *) - let java_get_class_type_name (j: java) = j.class_name - - (** Return the class name of a java procedure name. *) - let java_get_simple_class_name (j: java) = snd (split_classname (java_get_class_name j)) - - (** Return the package of a java procname. *) - let java_get_package (j: java) = fst (split_classname (java_get_class_name j)) - - (** Return the method of a java procname. *) - let java_get_method (j: java) = j.method_name - - (** Replace the method of a java procname. *) - let java_replace_method (j: java) mname = {j with method_name= mname} - - (** Replace the return type of a java procname. *) - let java_replace_return_type j ret_type = {j with return_type= Some ret_type} - - (** Replace the parameters of a java procname. *) - let java_replace_parameters j parameters = {j with parameters} - - (** Return the method/function of a procname. *) - let rec get_method = function - | ObjC_Cpp name -> - name.method_name - | WithBlockParameters (base, _) -> - get_method base - | C {name} -> - QualifiedCppName.to_qual_string name - | Block name -> - name - | Java j -> - j.method_name - | Linters_dummy_method -> - "Linters_dummy_method" - - - (** Return whether the procname is a block procname. *) - let is_objc_block = function Block _ -> true | _ -> false - - (** Return whether the procname is a cpp lambda. *) - let is_cpp_lambda procname = String.is_substring ~substring:"operator()" (get_method procname) - - (** Return the language of the procedure. *) - let get_language = function - | ObjC_Cpp _ -> - Config.Clang - | C _ -> - Config.Clang - | Block _ -> - Config.Clang - | Linters_dummy_method -> - Config.Clang - | WithBlockParameters _ -> - Config.Clang - | Java _ -> - Config.Java - - - (** Return the return type of a java procname. *) - let java_get_return_type (j: java) = java_return_type_to_string j Verbose + (** Check if the procedure name is an anonymous inner class constructor. *) + let java_is_anonymous_inner_class_constructor = function + | Java js -> + Name.Java.is_anonymous_inner_class_name js.class_name + | _ -> + false - (** Return the parameters of a java procname. *) - let java_get_parameters j = j.parameters (** Return true if the java procedure is static *) let java_is_static = function Java j -> equal_method_kind j.kind Static | _ -> false @@ -776,61 +783,6 @@ module Procname = struct false - (** Prints a string of a java procname with the given level of verbosity *) - let java_to_string ?(withclass= false) (j: java) verbosity = - match verbosity with - | Verbose | Non_verbose -> - (* if verbose, then package.class.method(params): rtype, - else rtype package.class.method(params) - verbose is used for example to create unique filenames, non_verbose to create reports *) - let return_type = java_return_type_to_string j verbosity in - let params = java_param_list_to_string j.parameters verbosity in - let class_name = java_type_to_string_verbosity (split_typename j.class_name) verbosity in - let separator = - match (j.return_type, verbosity) with None, _ -> "" | Some _, Verbose -> ":" | _ -> " " - in - let output = class_name ^ "." ^ j.method_name ^ "(" ^ params ^ ")" in - if equal_detail_level verbosity Verbose then output ^ separator ^ return_type - else return_type ^ separator ^ output - | Simple -> - (* methodname(...) or without ... if there are no parameters *) - let cls_prefix = - if withclass then - java_type_to_string_verbosity (split_typename j.class_name) verbosity ^ "." - else "" - in - let params = match j.parameters with [] -> "" | _ -> "..." in - let method_name = - if String.equal j.method_name "" then java_get_simple_class_name j - else cls_prefix ^ j.method_name - in - method_name ^ "(" ^ params ^ ")" - - - (** Check if the class name is for an anonymous inner class. *) - let is_anonymous_inner_class_name class_name = - let class_name_no_package = snd (split_typename class_name) in - match String.rsplit2 class_name_no_package ~on:'$' with - | Some (_, s) -> - let is_int = - try - ignore (int_of_string (String.strip s)) ; - true - with Failure _ -> false - in - is_int - | None -> - false - - - (** Check if the procedure name is an anonymous inner class constructor. *) - let java_is_anonymous_inner_class_constructor = function - | Java js -> - is_anonymous_inner_class_name js.class_name - | _ -> - false - - (** Check if the procedure name is an acess method (e.g. access$100 used to access private members from a nested class. *) let java_is_access_method = function @@ -867,6 +819,59 @@ module Procname = struct false + let rec objc_cpp_replace_method_name t (new_method_name: string) = + match t with + | ObjC_Cpp osig -> + ObjC_Cpp {osig with method_name= new_method_name} + | WithBlockParameters (base, blocks) -> + WithBlockParameters (objc_cpp_replace_method_name base new_method_name, blocks) + | C _ | Block _ | Linters_dummy_method | Java _ -> + t + + + (** Get the class name of a Objective-C/C++ procedure name. *) + let objc_cpp_get_class_name objc_cpp = Name.name objc_cpp.class_name + + let objc_cpp_get_class_type_name objc_cpp = objc_cpp.class_name + + (** Return the method/function of a procname. *) + let rec get_method = function + | ObjC_Cpp name -> + name.method_name + | WithBlockParameters (base, _) -> + get_method base + | C {name} -> + QualifiedCppName.to_qual_string name + | Block name -> + name + | Java j -> + j.method_name + | Linters_dummy_method -> + "Linters_dummy_method" + + + (** Return whether the procname is a block procname. *) + let is_objc_block = function Block _ -> true | _ -> false + + (** Return whether the procname is a cpp lambda. *) + let is_cpp_lambda procname = String.is_substring ~substring:"operator()" (get_method procname) + + (** Return the language of the procedure. *) + let get_language = function + | ObjC_Cpp _ -> + Config.Clang + | C _ -> + Config.Clang + | Block _ -> + Config.Clang + | Linters_dummy_method -> + Config.Clang + | WithBlockParameters _ -> + Config.Clang + | Java _ -> + Config.Java + + let is_objc_constructor method_name = String.equal method_name "new" || String.is_prefix ~prefix:"init" method_name @@ -919,7 +924,7 @@ module Procname = struct match pn with | Java j -> let regexp = Str.regexp "com.facebook.infer.builtins.InferUndefined" in - Str.string_match regexp (java_get_class_name j) 0 + Str.string_match regexp (Java.get_class_name j) 0 | _ -> (* TODO: add cases for obj-c, c, c++ *) false @@ -977,7 +982,7 @@ module Procname = struct let rec to_unique_id pn = match pn with | Java j -> - java_to_string j Verbose + Java.to_string j Verbose | C {name; mangled} -> to_readable_string (name, mangled) true | ObjC_Cpp osig -> @@ -994,7 +999,7 @@ module Procname = struct let rec to_string p = match p with | Java j -> - java_to_string j Non_verbose + Java.to_string j Non_verbose | C {name; mangled} -> to_readable_string (name, mangled) false | ObjC_Cpp osig -> @@ -1011,7 +1016,7 @@ module Procname = struct let rec to_simplified_string ?(withclass= false) p = match p with | Java j -> - java_to_string ~withclass j Simple + Java.to_string ~withclass j Simple | C {name; mangled} -> to_readable_string (name, mangled) false ^ "()" | ObjC_Cpp osig -> @@ -1030,7 +1035,7 @@ module Procname = struct (* Strip autogenerated anonymous inner class numbers in order to keep the bug hash invariant when introducing new annonynous classes *) Str.global_replace (Str.regexp "$[0-9]+") "$_" - (java_to_string ~withclass:true pname Simple) + (Java.to_string ~withclass:true pname Simple) | ObjC_Cpp _ when is_objc_method p -> (* In Objective C, the list of parameters is part of the method name. To prevent the bug hash to change when a parameter is introduced or removed, only the part of the name @@ -1143,7 +1148,7 @@ end (** Return the return type of [pname_java]. *) let java_proc_return_typ pname_java : t = - let typ = java_from_string (Procname.java_get_return_type pname_java) in + let typ = java_from_string (Procname.Java.get_return_type pname_java) in match typ.desc with Tstruct _ -> mk (Tptr (typ, Pk_pointer)) | _ -> typ @@ -1202,32 +1207,6 @@ module Fieldname = struct fname - (** Returns the class part of the fieldname *) - let java_get_class fn = - let fn = to_string fn in - let ri = String.rindex_exn fn '.' in - String.slice fn 0 ri - - - (** Returns the last component of the fieldname *) - let java_get_field fn = - let fn = to_string fn in - let ri = 1 + String.rindex_exn fn '.' in - String.slice fn ri 0 - - - (** Check if the field is the synthetic this$n of a nested class, used to access the n-th outher instance. *) - let java_is_outer_instance fn = - let fn = to_string fn in - let fn_len = String.length fn in - fn_len <> 0 - && - let this = ".this$" in - let last_char = fn.[fn_len - 1] in - (last_char >= '0' && last_char <= '9') - && String.is_suffix fn ~suffix:(this ^ String.of_char last_char) - - let clang_get_qual_class = function | Clang {class_name} -> Some (Name.qual_name class_name) @@ -1248,6 +1227,29 @@ module Fieldname = struct String.is_prefix ~prefix:"val$" (to_flat_string field_name) | Clang _ -> false + + + let get_class fn = + let fn = to_string fn in + let ri = String.rindex_exn fn '.' in + String.slice fn 0 ri + + + let get_field fn = + let fn = to_string fn in + let ri = 1 + String.rindex_exn fn '.' in + String.slice fn ri 0 + + + let is_outer_instance fn = + let fn = to_string fn in + let fn_len = String.length fn in + fn_len <> 0 + && + let this = ".this$" in + let last_char = fn.[fn_len - 1] in + (last_char >= '0' && last_char <= '9') + && String.is_suffix fn ~suffix:(this ^ String.of_char last_char) end end diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index eec9ad5a4..b8e243f6c 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -159,6 +159,14 @@ module Name : sig val is_class : t -> bool (** [is_class name] holds if [name] names a Java class *) + val split_classname : string -> string option * string + (** Given a package.class_name string, look for the latest dot and split the string + in two (package, class_name). *) + + val get_parent_class : t -> t option + (** Given an inner classname like C$Inner1$Inner2, return Some C$Inner1. If the class is not an + inner class, return None *) + val java_lang_object : t val java_io_serializable : t @@ -250,8 +258,49 @@ type typ = t module Procname : sig (** Module for Procedure Names. *) + type method_kind = + | Non_Static + (** in Java, procedures called with invokevirtual, invokespecial, and invokeinterface *) + | Static (** in Java, procedures called with invokestatic *) + (** Type of java procedure names. *) - type java + module Java : sig + type t [@@deriving compare] + + (** e.g. ("", "int") for primitive types or ("java.io", "PrintWriter") for objects *) + type java_type = string option * string + + val make : Name.t -> java_type option -> string -> java_type list -> method_kind -> t + (** 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 + (** Replace the parameters of a java procname. *) + + val replace_return_type : t -> java_type -> t + (** Replace the method of a java procname. *) + + val get_class_name : t -> string + (** Return the class name of a java procedure name. *) + + val get_class_type_name : t -> Name.t + (** Return the class name as a typename of a java procedure name. *) + + val get_simple_class_name : t -> string + (** Return the simple class name of a java procedure name. *) + + val get_package : t -> string option + (** Return the package name of a java procedure name. *) + + val get_method : t -> string + (** Return the method name of a java procedure name. *) + + 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. *) + end (** Type of c procedure names. *) type c = private @@ -286,7 +335,7 @@ module Procname : sig bar() {foo(my_block)} is executed as foo_my_block() {my_block(); } where foo_my_block is created with WithBlockParameters (foo, [my_block]) *) type t = - | Java of java + | Java of Java.t | C of c | Linters_dummy_method | Block of block_name @@ -298,13 +347,6 @@ module Procname : sig val equal : t -> t -> bool - type java_type = string option * string - - type method_kind = - | Non_Static - (** in Java, procedures called with invokevirtual, invokespecial, and invokeinterface *) - | Static (** in Java, procedures called with invokestatic *) - (** Hash tables with proc names as keys. *) module Hashable : Caml.Hashtbl.HashedType with type t = t @@ -371,16 +413,6 @@ module Procname : sig val is_destructor : t -> bool (** Check if this is a dealloc method. *) - val java : Name.t -> java_type option -> string -> java_type list -> method_kind -> java - (** Create a Java procedure name from its - class_name method_name args_type_name return_type_name method_kind. *) - - val java_replace_parameters : java -> java_type list -> java - (** Replace the parameters of a java procname. *) - - val java_replace_return_type : java -> java_type -> java - (** Replace the method of a java procname. *) - val mangled_objc_block : string -> t (** Create an objc block name. *) @@ -403,24 +435,6 @@ module Procname : sig val objc_method_kind_of_bool : bool -> objc_cpp_method_kind (** Create ObjC method type from a bool is_instance. *) - val java_get_class_name : java -> string - (** Return the class name of a java procedure name. *) - - val java_get_class_type_name : java -> Name.t - (** Return the class name as a typename of a java procedure name. *) - - val java_get_simple_class_name : java -> string - (** Return the simple class name of a java procedure name. *) - - val java_get_package : java -> string option - (** Return the package name of a java procedure name. *) - - val java_get_method : java -> string - (** Return the method name of a java procedure name. *) - - val java_get_parameters : java -> java_type list - (** Return the parameters of a java procedure name. *) - val java_is_access_method : t -> bool (** Check if the procedure name is an acess method (e.g. access$100 used to access private members from a nested class. *) @@ -447,9 +461,6 @@ module Procname : sig val java_is_generated : t -> bool (** Check if the proc name comes from generated code *) - val java_replace_method : java -> string -> java - (** Replace the method name of an existing java procname. *) - val is_class_initializer : t -> bool (** Check if this is a class initializer. *) @@ -467,10 +478,6 @@ module Procname : sig (** Replace the class name component of a procedure name. In case of Java, replace package and class name. *) - val split_classname : string -> string option * string - (** Given a package.class_name string, look for the latest dot and split the string - in two (package, class_name). *) - val to_string : t -> string (** Convert a proc name to a string for the user to see. *) @@ -493,7 +500,7 @@ module Procname : sig (** get qualifiers of a class owning objc/C++ method *) end -val java_proc_return_typ : Procname.java -> t +val java_proc_return_typ : Procname.Java.t -> t (** Return the return type of [pname_java]. *) module Fieldname : sig @@ -521,6 +528,16 @@ module Fieldname : sig val is_captured_parameter : t -> bool (** Check if field is a captured parameter *) + + val get_class : t -> string + (** The class part of the fieldname *) + + val get_field : t -> string + (** The last component of the fieldname *) + + val is_outer_instance : t -> bool + (** Check if the field is the synthetic this$n of a nested class, used to access the n-th outer + instance. *) end val to_string : t -> string @@ -539,15 +556,6 @@ module Fieldname : sig val pp : Format.formatter -> t -> unit (** Pretty print a field name. *) - val java_get_class : t -> string - (** The class part of the fieldname *) - - val java_get_field : t -> string - (** The last component of the fieldname *) - - val java_is_outer_instance : t -> bool - (** Check if the field is the synthetic this$n of a nested class, used to access the n-th outher instance. *) - val clang_get_qual_class : t -> QualifiedCppName.t option (** get qualified classname of a field if it's coming from clang frontend. returns None otherwise *) end diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index ef29c454d..9e2d1c17c 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -182,7 +182,7 @@ let get_vararg_type_names tenv (call_node: Procdesc.Node.t) (ivar: Pvar.t) : str let is_getter pname_java = - Str.string_match (Str.regexp "get*") (Typ.Procname.java_get_method pname_java) 0 + Str.string_match (Str.regexp "get*") (Typ.Procname.Java.get_method pname_java) 0 let type_is_class typ = @@ -228,7 +228,7 @@ let method_is_initializer (tenv: Tenv.t) (proc_attributes: ProcAttributes.t) : b if type_has_initializer tenv this_type then match proc_attributes.ProcAttributes.proc_name with | Typ.Procname.Java pname_java -> - let mname = Typ.Procname.java_get_method pname_java in + let mname = Typ.Procname.Java.get_method pname_java in List.exists ~f:(String.equal mname) initializer_methods | _ -> false @@ -299,7 +299,7 @@ let override_exists f tenv proc_name = match proc_name with | Typ.Procname.Java proc_name_java -> let type_name = - Typ.Name.Java.from_string (Typ.Procname.java_get_class_name proc_name_java) + Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name proc_name_java) in List.exists ~f:(super_type_exists tenv) (type_get_direct_supertypes tenv (Typ.mk (Tstruct type_name))) @@ -345,7 +345,7 @@ let is_throwable tenv typename = is_subtype_of_str tenv typename "java.lang.Thro let check_class_attributes check tenv = function | Typ.Procname.Java java_pname -> let check_class_annots _ {Typ.Struct.annots} = check annots in - supertype_exists tenv check_class_annots (Typ.Procname.java_get_class_type_name java_pname) + supertype_exists tenv check_class_annots (Typ.Procname.Java.get_class_type_name java_pname) | _ -> false @@ -354,7 +354,7 @@ let check_class_attributes check tenv = function for the current class only*) let check_current_class_attributes check tenv = function | Typ.Procname.Java java_pname -> ( - match Tenv.lookup tenv (Typ.Procname.java_get_class_type_name java_pname) with + match Tenv.lookup tenv (Typ.Procname.Java.get_class_type_name java_pname) with | Some struct_typ -> check struct_typ.annots | _ -> diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index cda0ae6c6..024887239 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -23,7 +23,7 @@ val get_vararg_type_names : Tenv.t -> Procdesc.Node.t -> Pvar.t -> string list val method_is_initializer : Tenv.t -> ProcAttributes.t -> bool (** Check if the method is one of the known initializer methods. *) -val is_getter : Typ.Procname.java -> bool +val is_getter : Typ.Procname.Java.t -> bool (** Is this a getter proc name? *) val is_subtype : Tenv.t -> Typ.Name.t -> Typ.Name.t -> bool diff --git a/infer/src/backend/inferconfig.ml b/infer/src/backend/inferconfig.ml index b1079bd93..a8270bbb4 100644 --- a/infer/src/backend/inferconfig.ml +++ b/infer/src/backend/inferconfig.ml @@ -109,8 +109,8 @@ module FileOrProcMatcher = struct ~init:String.Map.empty m_patterns in let do_java pname_java = - let class_name = Typ.Procname.java_get_class_name pname_java - and method_name = Typ.Procname.java_get_method pname_java in + let class_name = Typ.Procname.Java.get_class_name pname_java + and method_name = Typ.Procname.Java.get_method pname_java in try let class_patterns = String.Map.find_exn pattern_map class_name in List.exists diff --git a/infer/src/backend/interproc.ml b/infer/src/backend/interproc.ml index eef3cb97a..7baee8b49 100644 --- a/infer/src/backend/interproc.ml +++ b/infer/src/backend/interproc.ml @@ -1084,7 +1084,7 @@ let report_runtime_exceptions tenv pdesc summary = match pname with | Typ.Procname.Java pname_java -> Typ.Procname.java_is_static pname - && String.equal (Typ.Procname.java_get_method pname_java) "main" + && String.equal (Typ.Procname.Java.get_method pname_java) "main" | _ -> false in diff --git a/infer/src/backend/rearrange.ml b/infer/src/backend/rearrange.ml index 746ab2640..4e52d71e4 100644 --- a/infer/src/backend/rearrange.ml +++ b/infer/src/backend/rearrange.ml @@ -753,7 +753,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = let guarded_by_str_is_current_class guarded_by_str = function | Typ.Procname.Java java_pname -> (* programmers write @GuardedBy("MyClass.class") when the field is guarded by the class *) - guarded_by_str_is_class guarded_by_str (Typ.Procname.java_get_class_name java_pname) + guarded_by_str_is_class guarded_by_str (Typ.Procname.Java.get_class_name java_pname) | _ -> false in @@ -765,7 +765,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = let guarded_by_str_is_super_class_this guarded_by_str pname = match pname with | Typ.Procname.Java java_pname -> - let current_class_type_name = Typ.Procname.java_get_class_type_name java_pname in + let current_class_type_name = Typ.Procname.Java.get_class_type_name java_pname in let comparison class_type_name _ = guarded_by_str_is_class_this (Typ.Name.to_string class_type_name) guarded_by_str in @@ -776,7 +776,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = (* return true if [guarded_by_str] is as suffix of ".this" *) let guarded_by_str_is_current_class_this guarded_by_str = function | Typ.Procname.Java java_pname -> - guarded_by_str_is_class_this (Typ.Procname.java_get_class_name java_pname) guarded_by_str + guarded_by_str_is_class_this (Typ.Procname.Java.get_class_name java_pname) guarded_by_str | _ -> false in @@ -807,7 +807,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = match extract_guarded_by_str item_annot with | Some "this" -> (* expand "this" into .this *) - Some (Printf.sprintf "%s.this" (Typ.Fieldname.java_get_class fld)) + Some (Printf.sprintf "%s.this" (Typ.Fieldname.Java.get_class fld)) | guarded_by_str_opt -> guarded_by_str_opt ) | _ -> @@ -876,7 +876,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = (* if the guarded-by string is "OuterClass.this", look for "this$n" for some n. note that this is a bit sketchy when there are mutliple this$n's, but there's nothing we can do to disambiguate them. *) - get_fld_strexp_and_typ typ (fun f _ -> Typ.Fieldname.java_is_outer_instance f) flds + get_fld_strexp_and_typ typ (fun f _ -> Typ.Fieldname.Java.is_outer_instance f) flds | None -> (* can't find an exact match. try a different convention. *) match_on_field_type typ flds diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 03c9512d9..ba560d58a 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -586,7 +586,7 @@ let resolve_virtual_pname tenv prop actuals callee_pname call_flags : Typ.Procna match pname with | Typ.Procname.Java pname_java -> ( - let name = Typ.Procname.java_get_class_type_name pname_java in + let name = Typ.Procname.Java.get_class_type_name pname_java in match Tenv.lookup tenv name with | Some _ -> Typ.mk (Typ.Tptr (Typ.mk (Tstruct name), Pk_pointer)) @@ -633,25 +633,25 @@ let resolve_virtual_pname tenv prop actuals callee_pname call_flags : Typ.Procna (** Resolve the name of the procedure to call based on the type of the arguments *) -let resolve_java_pname tenv prop args pname_java call_flags : Typ.Procname.java = +let resolve_java_pname tenv prop args pname_java call_flags : Typ.Procname.Java.t = let resolve_from_args resolved_pname_java args = let resolved_params = List.fold2_exn ~f:(fun accu (arg_exp, _) name -> match resolve_typename prop arg_exp with | Some class_name -> - Typ.Procname.split_classname (Typ.Name.name class_name) :: accu + Typ.Name.Java.split_classname (Typ.Name.name class_name) :: accu | None -> name :: accu ) ~init:[] args - (Typ.Procname.java_get_parameters resolved_pname_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_pname_java resolved_params in let resolved_pname_java, other_args = let pname = Typ.Procname.Java pname_java - and parameters = Typ.Procname.java_get_parameters pname_java in + and parameters = Typ.Procname.Java.get_parameters pname_java in let match_parameters args = Int.equal (List.length args) (List.length parameters) in match args with | [] -> @@ -721,7 +721,7 @@ let resolve_and_analyze tenv caller_pdesc prop args callee_proc_name call_flags let call_constructor_url_update_args pname actual_params = let url_pname = Typ.Procname.Java - (Typ.Procname.java + (Typ.Procname.Java.make (Typ.Name.Java.from_string "java.net.URL") None "" [(Some "java.lang", "String")] Typ.Procname.Non_Static) in diff --git a/infer/src/backend/tabulation.ml b/infer/src/backend/tabulation.ml index 468a045ca..2edd57c90 100644 --- a/infer/src/backend/tabulation.ml +++ b/infer/src/backend/tabulation.ml @@ -1323,7 +1323,7 @@ let exe_call_postprocess tenv ret_id trace_call callee_pname callee_attrs loc re let should_add_ret_attr _ = let is_likely_getter = function | Typ.Procname.Java pn_java -> - Int.equal (List.length (Typ.Procname.java_get_parameters pn_java)) 0 + Int.equal (List.length (Typ.Procname.Java.get_parameters pn_java)) 0 | _ -> false in diff --git a/infer/src/checkers/BoundedCallTree.ml b/infer/src/checkers/BoundedCallTree.ml index 8e5692efc..6b02fb998 100644 --- a/infer/src/checkers/BoundedCallTree.ml +++ b/infer/src/checkers/BoundedCallTree.ml @@ -112,7 +112,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct match pname with | Typ.Procname.Java java_proc -> String.equal frame.Stacktrace.class_str - (Typ.Procname.java_get_class_name java_proc) + (Typ.Procname.Java.get_class_name java_proc) | Typ.Procname.ObjC_Cpp objc_cpp_prod -> String.equal frame.Stacktrace.class_str (Typ.Procname.objc_cpp_get_class_name objc_cpp_prod) diff --git a/infer/src/checkers/Litho.ml b/infer/src/checkers/Litho.ml index 612ab649f..797c83b42 100644 --- a/infer/src/checkers/Litho.ml +++ b/infer/src/checkers/Litho.ml @@ -37,7 +37,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct -> ( PatternMatch.is_getter java_procname && - match Typ.Procname.java_get_package java_procname with + match Typ.Procname.Java.get_package java_procname with | Some package -> String.is_prefix ~prefix:"com.facebook.graphql.model" package | None -> @@ -150,7 +150,7 @@ let unroll_call call astate summary = let should_report proc_desc = match Procdesc.get_proc_name proc_desc with | Typ.Procname.Java java_pname -> ( - match Typ.Procname.java_get_method java_pname with "onCreateLayout" -> true | _ -> false ) + match Typ.Procname.Java.get_method java_pname with "onCreateLayout" -> true | _ -> false ) | _ -> false diff --git a/infer/src/checkers/NullabilitySuggest.ml b/infer/src/checkers/NullabilitySuggest.ml index 3722f52e5..85a12dbe9 100644 --- a/infer/src/checkers/NullabilitySuggest.ml +++ b/infer/src/checkers/NullabilitySuggest.ml @@ -140,8 +140,8 @@ let make_error_trace astate ap ud = let pretty_field_name proc_data field_name = match Procdesc.get_proc_name proc_data.ProcData.pdesc with | Typ.Procname.Java jproc_name -> - let proc_class_name = Typ.Procname.java_get_class_name jproc_name in - let field_class_name = Typ.Fieldname.java_get_class field_name in + let proc_class_name = Typ.Procname.Java.get_class_name jproc_name in + let field_class_name = Typ.Fieldname.Java.get_class field_name in if String.equal proc_class_name field_class_name then Typ.Fieldname.to_flat_string field_name else Typ.Fieldname.to_simplified_string field_name | _ -> @@ -154,7 +154,7 @@ let pretty_field_name proc_data field_name = let is_outside_codebase proc_desc tenv field_name = match Procdesc.get_proc_name proc_desc with | Typ.Procname.Java _ -> - let class_name = Typ.Fieldname.java_get_class field_name in + let class_name = Typ.Fieldname.Java.get_class field_name in let class_type = Typ.Name.Java.from_string class_name in let class_struct = Tenv.lookup tenv class_type in let first_method = diff --git a/infer/src/checkers/androidFramework.ml b/infer/src/checkers/androidFramework.ml index 7ad98c815..155c816a1 100644 --- a/infer/src/checkers/androidFramework.ml +++ b/infer/src/checkers/androidFramework.ml @@ -23,7 +23,7 @@ let drawable_prefix = "R$drawable" let is_destroy_method pname = match pname with | Typ.Procname.Java pname_java -> - let method_name = Typ.Procname.java_get_method pname_java in + let method_name = Typ.Procname.Java.get_method pname_java in String.equal method_name on_destroy || String.equal method_name on_destroy_view | _ -> false diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index 30bf40361..e3d54a15f 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -77,7 +77,7 @@ let is_modeled_expensive tenv = function && let is_subclass = let classname = - Typ.Name.Java.from_string (Typ.Procname.java_get_class_name proc_name_java) + Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name proc_name_java) in PatternMatch.is_subtype_of_str tenv classname in @@ -90,7 +90,7 @@ let is_allocator tenv pname = match pname with | Typ.Procname.Java pname_java -> let is_throwable () = - let class_name = Typ.Name.Java.from_string (Typ.Procname.java_get_class_name pname_java) in + let class_name = Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name pname_java) in PatternMatch.is_throwable tenv class_name in Typ.Procname.is_constructor pname && not (BuiltinDecl.is_declared pname) @@ -372,7 +372,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_unlikely pname = match pname with | Typ.Procname.Java java_pname -> - String.equal (Typ.Procname.java_get_method java_pname) "unlikely" + String.equal (Typ.Procname.Java.get_method java_pname) "unlikely" | _ -> false diff --git a/infer/src/checkers/fragmentRetainsViewChecker.ml b/infer/src/checkers/fragmentRetainsViewChecker.ml index 50591833a..a05c23eef 100644 --- a/infer/src/checkers/fragmentRetainsViewChecker.ml +++ b/infer/src/checkers/fragmentRetainsViewChecker.ml @@ -25,7 +25,7 @@ let callback_fragment_retains_view_java pname_java {Callbacks.proc_desc; summary (* TODO: complain if onDestroyView is not defined, yet the Fragment has View fields *) (* TODO: handle fields nullified in callees in the same file *) let is_on_destroy_view = - String.equal (Typ.Procname.java_get_method pname_java) "onDestroyView" + String.equal (Typ.Procname.Java.get_method pname_java) "onDestroyView" in let fld_typ_is_view typ = match typ.Typ.desc with @@ -36,11 +36,11 @@ let callback_fragment_retains_view_java pname_java {Callbacks.proc_desc; summary in (* is [fldname] a View type declared by [class_typename]? *) let is_declared_view_typ class_typename (fldname, fld_typ, _) = - let fld_classname = Typ.Name.Java.from_string (Typ.Fieldname.java_get_class fldname) in + let fld_classname = Typ.Name.Java.from_string (Typ.Fieldname.Java.get_class fldname) in Typ.Name.equal fld_classname class_typename && fld_typ_is_view fld_typ in if is_on_destroy_view then - let class_typename = Typ.Name.Java.from_string (Typ.Procname.java_get_class_name pname_java) in + let class_typename = Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name pname_java) in match Tenv.lookup tenv class_typename with | Some {fields} when AndroidFramework.is_fragment tenv class_typename -> let declared_view_fields = List.filter ~f:(is_declared_view_typ class_typename) fields in diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index fc6f2ce08..0dd0e37c5 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -126,7 +126,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct (** return true if this function is library code from the JDK core libraries or Android *) let is_java_library = function | Typ.Procname.Java java_pname -> ( - match Typ.Procname.java_get_package java_pname with + match Typ.Procname.Java.get_package java_pname with | Some package_name -> String.is_prefix ~prefix:"java." package_name || String.is_prefix ~prefix:"android." package_name @@ -139,7 +139,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_builder_function = function | Typ.Procname.Java java_pname -> - String.is_suffix ~suffix:"$Builder" (Typ.Procname.java_get_class_name java_pname) + String.is_suffix ~suffix:"$Builder" (Typ.Procname.Java.get_class_name java_pname) | _ -> false @@ -231,7 +231,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_modeled_functional = function | Typ.Procname.Java java_pname -> ( match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | "android.content.res.Resources", method_name -> (* all methods of Resources are considered @Functional except for the ones in this @@ -261,7 +261,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_owned_in_library = function | Typ.Procname.Java java_pname -> ( match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | "javax.inject.Provider", "get" -> (* in dependency injection, the library allocates fresh values behind the scenes *) @@ -296,7 +296,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_threadsafe_collection pn tenv = match pn with | Typ.Procname.Java java_pname -> - let typename = Typ.Name.Java.from_string (Typ.Procname.java_get_class_name java_pname) in + let typename = Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name java_pname) in let aux tn _ = match Typ.Name.name tn with | "java.util.concurrent.ConcurrentMap" @@ -326,7 +326,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | (AccessPath.FieldAccess base_field) :: (AccessPath.FieldAccess container_field) :: _ when Typ.Procname.is_java callee_pname -> let base_typename = - Typ.Name.Java.from_string (Typ.Fieldname.java_get_class base_field) + Typ.Name.Java.from_string (Typ.Fieldname.Java.get_class base_field) in is_annotated_synchronized base_typename container_field tenv | [(AccessPath.FieldAccess container_field)] -> ( @@ -393,7 +393,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_box = function | Typ.Procname.Java java_pname -> ( match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | ( ( "java.lang.Boolean" | "java.lang.Byte" @@ -861,7 +861,7 @@ let should_analyze_proc pdesc tenv = let get_current_class_and_threadsafe_superclasses tenv pname = match pname with | Typ.Procname.Java java_pname -> - let current_class = Typ.Procname.java_get_class_type_name java_pname in + let current_class = Typ.Procname.Java.get_class_type_name java_pname in let thread_safe_annotated_classes = PatternMatch.find_superclasses_with_attributes is_thread_safe tenv current_class in @@ -1215,7 +1215,7 @@ let report_thread_safety_violation tenv pdesc ~make_description ~report_kind acc let report_unannotated_interface_violation tenv pdesc access thread reported_pname = match reported_pname with | Typ.Procname.Java java_pname -> - let class_name = Typ.Procname.java_get_class_name java_pname in + let class_name = Typ.Procname.Java.get_class_name java_pname in let make_description _ _ _ _ = F.asprintf "Unprotected call to method of un-annotated interface %s. Consider annotating the class with %a, adding a lock, or using an interface that is known to be thread-safe." @@ -1231,8 +1231,8 @@ let report_unannotated_interface_violation tenv pdesc access thread reported_pna let pp_procname_short fmt = function | Typ.Procname.Java java -> F.fprintf fmt "%s.%s" - (Typ.Procname.java_get_class_name java) - (Typ.Procname.java_get_method java) + (Typ.Procname.Java.get_class_name java) + (Typ.Procname.Java.get_method java) | pname -> Typ.Procname.pp fmt pname @@ -1654,7 +1654,7 @@ let aggregate_by_class file_env = let classname = match pname with | Typ.Procname.Java java_pname -> - Typ.Procname.java_get_class_name java_pname + Typ.Procname.Java.get_class_name java_pname | _ -> "unknown" in diff --git a/infer/src/concurrency/RacerDConfig.ml b/infer/src/concurrency/RacerDConfig.ml index 5b5204793..9a6e8c394 100644 --- a/infer/src/concurrency/RacerDConfig.ml +++ b/infer/src/concurrency/RacerDConfig.ml @@ -28,21 +28,21 @@ module Models = struct type container_access = ContainerRead | ContainerWrite let is_thread_utils_type java_pname = - let pn = Typ.Procname.java_get_class_name java_pname in + let pn = Typ.Procname.Java.get_class_name java_pname in String.is_suffix ~suffix:"ThreadUtils" pn || String.is_suffix ~suffix:"ThreadUtil" pn let is_thread_utils_method method_name_str = function | Typ.Procname.Java java_pname -> is_thread_utils_type java_pname - && String.equal (Typ.Procname.java_get_method java_pname) method_name_str + && String.equal (Typ.Procname.Java.get_method java_pname) method_name_str | _ -> false let get_thread = function | Typ.Procname.Java java_pname when is_thread_utils_type java_pname -> ( - match Typ.Procname.java_get_method java_pname with + match Typ.Procname.Java.get_method java_pname with | "assertMainThread" | "assertOnUiThread" | "checkOnMainThread" -> MainThread | "isMainThread" | "isUiThread" -> @@ -110,7 +110,7 @@ module Models = struct if is_thread_utils_method "assertHoldsLock" (Typ.Procname.Java java_pname) then Lock else match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | ( ( "java.util.concurrent.locks.Lock" | "java.util.concurrent.locks.ReentrantLock" @@ -173,9 +173,9 @@ module Models = struct fun pn tenv -> match pn with | Typ.Procname.Java java_pname -> - let typename = Typ.Name.Java.from_string (Typ.Procname.java_get_class_name java_pname) in + let typename = Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name java_pname) in let get_container_access_ typename = - match (Typ.Name.name typename, Typ.Procname.java_get_method java_pname) with + match (Typ.Name.name typename, Typ.Procname.Java.get_method java_pname) with | ( ("android.util.SparseArray" | "android.support.v4.util.SparseArrayCompat") , ( "append" | "clear" diff --git a/infer/src/eradicate/eradicate.ml b/infer/src/eradicate/eradicate.ml index 86c8f4bd6..891249d5a 100644 --- a/infer/src/eradicate/eradicate.ml +++ b/infer/src/eradicate/eradicate.ml @@ -180,7 +180,7 @@ module MkCallback (Extension : ExtensionT) : CallBackT = struct let get_class_opt pn = match pn with | Typ.Procname.Java pn_java -> - Some (Typ.Procname.java_get_class_name pn_java) + Some (Typ.Procname.Java.get_class_name pn_java) | _ -> None in @@ -259,7 +259,7 @@ module MkCallback (Extension : ExtensionT) : CallBackT = struct let get_class pn = match pn with | Typ.Procname.Java pn_java -> - Some (Typ.Procname.java_get_class_name pn_java) + Some (Typ.Procname.Java.get_class_name pn_java) | _ -> None diff --git a/infer/src/eradicate/eradicateChecks.ml b/infer/src/eradicate/eradicateChecks.ml index cc5ac6e93..d52d078df 100644 --- a/infer/src/eradicate/eradicateChecks.ml +++ b/infer/src/eradicate/eradicateChecks.ml @@ -189,13 +189,13 @@ let check_field_assignment tenv find_canonical_duplicate curr_pdesc node instr_r in not (TypeAnnotation.get_value AnnotatedSignature.Nullable ta_lhs) && TypeAnnotation.get_value AnnotatedSignature.Nullable ta_rhs - && PatternMatch.type_is_class t_lhs && not (Typ.Fieldname.java_is_outer_instance fname) + && PatternMatch.type_is_class t_lhs && not (Typ.Fieldname.Java.is_outer_instance fname) && not (field_is_field_injector_readwrite ()) in let should_report_absent = Config.eradicate_optional_present && TypeAnnotation.get_value AnnotatedSignature.Present ta_lhs && not (TypeAnnotation.get_value AnnotatedSignature.Present ta_rhs) - && not (Typ.Fieldname.java_is_outer_instance fname) + && not (Typ.Fieldname.Java.is_outer_instance fname) in let should_report_mutable = let field_is_mutable () = @@ -267,11 +267,11 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_pname cu in let should_check_field_initialization = let in_current_class = - let fld_cname = Typ.Fieldname.java_get_class fn in + let fld_cname = Typ.Fieldname.Java.get_class fn in String.equal (Typ.Name.name name) fld_cname in not injector_readonly_annotated && PatternMatch.type_is_class ft && in_current_class - && not (Typ.Fieldname.java_is_outer_instance fn) + && not (Typ.Fieldname.Java.is_outer_instance fn) in if should_check_field_initialization then ( if Models.Inference.enabled then Models.Inference.field_add_nullable_annotation fn ; diff --git a/infer/src/eradicate/typeCheck.ml b/infer/src/eradicate/typeCheck.ml index 0f7542e7f..7180fe2b2 100644 --- a/infer/src/eradicate/typeCheck.ml +++ b/infer/src/eradicate/typeCheck.ml @@ -349,7 +349,7 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get let pvar = Pvar.mk (Mangled.from_string fld_name) curr_pname in let typestate' = update_typestate_fld pvar inner_origin fn typ in (Exp.Lvar pvar, typestate') - | Exp.Lfield (_exp', fn', _) when Typ.Fieldname.java_is_outer_instance fn' -> + | Exp.Lfield (_exp', fn', _) when Typ.Fieldname.Java.is_outer_instance fn' -> (* handle double dereference when accessing a field from an outer class *) let fld_name = Typ.Fieldname.to_string fn' ^ "_" ^ Typ.Fieldname.to_string fn in let pvar = Pvar.mk (Mangled.from_string fld_name) curr_pname in @@ -377,8 +377,8 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get match (curr_pname, pn) with | Typ.Procname.Java curr_pname_java, Typ.Procname.Java pn_java -> if String.equal - (Typ.Procname.java_get_class_name curr_pname_java) - (Typ.Procname.java_get_class_name pn_java) + (Typ.Procname.Java.get_class_name curr_pname_java) + (Typ.Procname.Java.get_class_name pn_java) then calls_this := true | _ -> () @@ -708,9 +708,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") + Typ.Procname.Java.replace_parameters + (Typ.Procname.Java.replace_return_type + (Typ.Procname.Java.replace_method pname_put "get") object_t) parameters in @@ -849,7 +849,7 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get let has_method pn name = match pn with | Typ.Procname.Java pn_java -> - String.equal (Typ.Procname.java_get_method pn_java) name + String.equal (Typ.Procname.Java.get_method pn_java) name | _ -> false in @@ -916,8 +916,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") + Typ.Procname.Java.replace_return_type + (Typ.Procname.Java.replace_method pname_java "get") object_t in let fun_dexp = DExp.Dconst (Const.Cfun (Typ.Procname.Java pname_java')) in diff --git a/infer/src/eradicate/typeErr.ml b/infer/src/eradicate/typeErr.ml index 05fdbbd74..dea48ff41 100644 --- a/infer/src/eradicate/typeErr.ml +++ b/infer/src/eradicate/typeErr.ml @@ -297,7 +297,7 @@ let report_error_now tenv (st_report_error: st_report_error) err_instance loc pd else match pn with | Typ.Procname.Java pn_java -> - MF.monospaced_to_string (Typ.Procname.java_get_method pn_java) + MF.monospaced_to_string (Typ.Procname.Java.get_method pn_java) | _ -> MF.monospaced_to_string (Typ.Procname.to_simplified_string pn) in @@ -340,7 +340,7 @@ let report_error_now tenv (st_report_error: st_report_error) err_instance loc pd else match pn with | Typ.Procname.Java pn_java -> - Typ.Procname.java_get_method pn_java + Typ.Procname.Java.get_method pn_java | _ -> Typ.Procname.to_simplified_string pn in diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 15710c2fa..c80aa2eae 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -27,8 +27,8 @@ let fix_method_definition_line linereader proc_name loc = let inner_class_name cname = match String.rsplit2 cname ~on:'$' with Some (_, icn) -> icn | None -> cname in - inner_class_name (Typ.Procname.java_get_simple_class_name proc_name_java) - else Typ.Procname.java_get_method proc_name_java + inner_class_name (Typ.Procname.Java.get_simple_class_name proc_name_java) + else Typ.Procname.Java.get_method proc_name_java in let regex = Str.regexp (Str.quote method_name) in let method_is_defined_here linenum = diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index f7d052907..6a6e55e66 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -224,7 +224,7 @@ let get_method_procname cn ms method_kind = let return_type_name, method_name, args_type_name = method_signature_names ms in let class_name = Typ.Name.Java.from_string (JBasics.cn_name cn) in let proc_name_java = - Typ.Procname.java class_name return_type_name method_name args_type_name method_kind + Typ.Procname.Java.make class_name return_type_name method_name args_type_name method_kind in Typ.Procname.Java proc_name_java @@ -406,7 +406,7 @@ let get_class_type program tenv cn = (** return true if [field_name] is the autogenerated C.$assertionsDisabled field for class C *) let is_autogenerated_assert_field field_name = - String.equal (Typ.Fieldname.java_get_field field_name) "$assertionsDisabled" + String.equal (Typ.Fieldname.Java.get_field field_name) "$assertionsDisabled" (** translate an object type *) diff --git a/infer/src/labs/ResourceLeaks.ml b/infer/src/labs/ResourceLeaks.ml index d84df86c2..03f616347 100644 --- a/infer/src/labs/ResourceLeaks.ml +++ b/infer/src/labs/ResourceLeaks.ml @@ -44,7 +44,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct false in PatternMatch.supertype_exists tenv is_closable_interface - (Typ.Name.Java.from_string (Typ.Procname.java_get_class_name java_procname)) + (Typ.Name.Java.from_string (Typ.Procname.Java.get_class_name java_procname)) | _ -> false in diff --git a/infer/src/quandary/JavaTaintAnalysis.ml b/infer/src/quandary/JavaTaintAnalysis.ml index b2d9731c5..b4cb90222 100644 --- a/infer/src/quandary/JavaTaintAnalysis.ml +++ b/infer/src/quandary/JavaTaintAnalysis.ml @@ -45,8 +45,8 @@ include TaintAnalysis.Make (struct -> ( let is_static = Typ.Procname.java_is_static pname in match - ( Typ.Procname.java_get_class_name java_pname - , Typ.Procname.java_get_method java_pname + ( Typ.Procname.Java.get_class_name java_pname + , Typ.Procname.Java.get_method java_pname , ret_typ_opt ) with | "android.content.Intent", ("putExtra" | "putExtras"), _ -> diff --git a/infer/src/quandary/JavaTrace.ml b/infer/src/quandary/JavaTrace.ml index 174d6bbe6..6c584316a 100644 --- a/infer/src/quandary/JavaTrace.ml +++ b/infer/src/quandary/JavaTrace.ml @@ -62,7 +62,7 @@ module SourceKind = struct let return = None in match pname with | Typ.Procname.Java pname -> ( - match (Typ.Procname.java_get_class_name pname, Typ.Procname.java_get_method pname) with + match (Typ.Procname.Java.get_class_name pname, Typ.Procname.Java.get_method pname) with | "android.content.Intent", "" when actual_has_type 2 "android.net.Uri" actuals tenv -> (* taint the [this] parameter passed to the constructor *) Some (IntentFromURI, Some 0) @@ -154,7 +154,7 @@ module SourceKind = struct match Procdesc.get_proc_name pdesc with | Typ.Procname.Java java_pname -> ( match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | "codetoanalyze.java.quandary.TaintedFormals", "taintedContextBad" -> taint_formals_with_types ["java.lang.Integer"; "java.lang.String"] Other formals @@ -298,7 +298,7 @@ module SinkKind = struct match pname with | Typ.Procname.Java java_pname -> ( match - (Typ.Procname.java_get_class_name java_pname, Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname, Typ.Procname.Java.get_method java_pname) with | "android.text.Html", "fromHtml" -> taint_nth 0 HTML @@ -424,8 +424,8 @@ module JavaSanitizer = struct | Typ.Procname.Java java_pname -> let procedure_string = Printf.sprintf "%s.%s" - (Typ.Procname.java_get_class_name java_pname) - (Typ.Procname.java_get_method java_pname) + (Typ.Procname.Java.get_class_name java_pname) + (Typ.Procname.Java.get_method java_pname) in List.find_map ~f:(fun procedure_regex -> diff --git a/infer/src/quandary/TaintAnalysis.ml b/infer/src/quandary/TaintAnalysis.ml index 65259193e..b099a75ae 100644 --- a/infer/src/quandary/TaintAnalysis.ml +++ b/infer/src/quandary/TaintAnalysis.ml @@ -121,7 +121,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct let is_endpoint source = match CallSite.pname (TraceDomain.Source.call_site source) with | Typ.Procname.Java java_pname -> - String.Set.mem (Lazy.force endpoints) (Typ.Procname.java_get_class_name java_pname) + String.Set.mem (Lazy.force endpoints) (Typ.Procname.Java.get_class_name java_pname) | _ -> false @@ -519,7 +519,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct let is_variadic = match callee_pname with | Typ.Procname.Java pname -> ( - match List.rev (Typ.Procname.java_get_parameters pname) with + match List.rev (Typ.Procname.Java.get_parameters pname) with | (_, "java.lang.Object[]") :: _ -> true | _ ->