Clean up the Procname module, and remove remaining assert false

Reviewed By: sblackshear

Differential Revision: D3063888

fb-gh-sync-id: baf4102
shipit-source-id: baf4102
master
Cristiano Calcagno 9 years ago committed by Facebook Github Bot 0
parent 91ae1baebc
commit c198d76631

@ -142,7 +142,7 @@ let iterate_callbacks store_summary call_graph exe_env =
let cluster_id proc_name =
match proc_name with
| Procname.Java pname_java ->
Procname.java_get_class pname_java
Procname.java_get_class_name pname_java
| _ ->
"unknown" in
let cluster proc_names =

@ -677,13 +677,13 @@ module Node = struct
let set_instr =
Sil.Set (convert_exp assignee_exp, origin_typ, convert_exp origin_exp, loc) in
set_instr :: instrs
| Sil.Call (return_ids, Sil.Const (Sil.Cfun callee_pname),
| Sil.Call (return_ids, Sil.Const (Sil.Cfun (Procname.Java callee_pname_java)),
(Sil.Var id, _) :: origin_args, loc, call_flags)
when call_flags.Sil.cf_virtual && redirected_class_name id <> None ->
let redirected_typ = Option.get (redirected_class_name id) in
let redirected_pname =
Procname.java_replace_class
callee_pname (extract_class_name redirected_typ)
Procname.replace_class
(Procname.Java callee_pname_java) (extract_class_name redirected_typ)
and args =
let other_args = (IList.map (fun (exp, typ) -> (convert_exp exp, typ)) origin_args) in
(Sil.Var id, redirected_typ) :: other_args in

@ -151,16 +151,11 @@ let load_patterns json_key inferconfig =
IList.fold_left (translate json_key) [] found
(* Check if a proc name is matching the name given as string *)
(** Check if a proc name is matching the name given as string. *)
let match_method language proc_name method_name =
not (SymExec.function_is_builtin proc_name) &&
match proc_name with
| Procname.Java pname_java ->
Procname.java_get_method pname_java = method_name
| _ ->
if language = Config.C_CPP
then Procname.c_get_method proc_name = method_name
else false
Procname.get_language proc_name = language &&
Procname.get_method proc_name = method_name
(* Module to create matcher based on strings present in the source file *)
module FileContainsStringMatcher = struct
@ -231,7 +226,7 @@ struct
StringMap.empty
m_patterns in
let do_java pname_java =
let class_name = Procname.java_get_class pname_java
let class_name = Procname.java_get_class_name pname_java
and method_name = Procname.java_get_method pname_java in
try
let class_patterns = StringMap.find class_name pattern_map in

@ -417,7 +417,7 @@ let desc_context_leak pname context_typ fieldname leak_path : error_desc =
let pname_str = match pname with
| Procname.Java pname_java ->
Printf.sprintf "%s.%s"
(Procname.java_get_class pname_java)
(Procname.java_get_class_name pname_java)
(Procname.java_get_method pname_java)
| _ ->
"" in

@ -357,8 +357,8 @@ let add_dispatch_calls cfg cg tenv f_translate_typ_opt =
(match pname with
| Procname.Java pname_java ->
let param_type_strs =
IList.map Procname.java_type_to_string (Procname.java_get_parameters pname) in
let receiver_type_str = Procname.java_get_class pname_java in
IList.map Procname.java_type_to_string (Procname.java_get_parameters pname_java) in
let receiver_type_str = Procname.java_get_class_name pname_java in
let return_type_str = Procname.java_get_return_type pname_java in
IList.iter
(fun typ_str -> f_translate_typ tenv typ_str)

@ -19,7 +19,7 @@ type method_kind =
| Static (* in Java, procedures called with invokestatic *)
| Non_Static (* in Java, procedures called with invokevirtual, invokespecial, and invokeinterface *)
(* java procedure name *)
(** Type of java procedure names. *)
type java = {
class_name: java_type;
return_type: java_type option; (* option because constructors have no return type *)
@ -28,50 +28,46 @@ type java = {
kind: method_kind
}
type objc_method_kind =
| Instance_objc_method
| Class_objc_method
(** Type of c procedure names. *)
type c = string * (string option)
let mangled_of_objc_method_kind kind =
match kind with
| Instance_objc_method -> Some "instance"
| Class_objc_method -> Some "class"
let objc_method_kind_of_bool is_instance =
if is_instance then Instance_objc_method
else Class_objc_method
(* C++/ObjC method signature *)
type objc_cpp_method = {
(** Type of Objective C and C++ procedure names: method signatures. *)
type objc_cpp = {
class_name: string;
method_name: string;
mangled: string option;
}
(** Type of Objective C block names. *)
type block = string
type c_function = string * (string option)
(** Type of procedure names. *)
type t =
| Java of java
(* a pair (plain, mangled optional) for standard C function *)
| C of c_function
(* structure with class name and method name for methods in Objective C and C++ *)
| ObjC_Cpp of objc_cpp_method
| C of c
| ObjC_Cpp of objc_cpp
| Block of block
(* Defines the level of verbosity of some to_string functions *)
(** Level of verbosity of some to_string functions. *)
type detail_level =
| Verbose
| Non_verbose
| Simple
type objc_method_kind =
| Instance_objc_method
| Class_objc_method
let mangled_of_objc_method_kind kind =
match kind with
| Instance_objc_method -> Some "instance"
| Class_objc_method -> Some "class"
let empty = Block ""
let objc_method_kind_of_bool is_instance =
if is_instance then Instance_objc_method
else Class_objc_method
let empty_block = Block ""
let is_verbose v =
match v with
@ -165,7 +161,7 @@ let split_classname package_classname =
let from_string_c_fun (s: string) = C (s, None)
let mangled_c_fun (plain: string) (mangled: string) = C (plain, Some mangled)
let c (plain: string) (mangled: string) = (plain, Some mangled)
let java class_name return_type method_name parameters kind =
{
@ -177,8 +173,8 @@ let java class_name return_type method_name parameters kind =
}
(** Create an objc procedure name from a class_name and method_name. *)
let mangled_c_method class_name method_name mangled =
ObjC_Cpp {
let objc_cpp class_name method_name mangled =
{
class_name = class_name;
method_name = method_name;
mangled = mangled;
@ -196,36 +192,27 @@ let is_c_method = function
| ObjC_Cpp _ -> true
| _ -> false
(** Replace package and classname of a java procname. *)
let java_replace_class p package_classname =
match p with
(** Replace the class name component of a procedure name.
In case of Java, replace package and class name. *)
let replace_class t new_class = match t with
| Java j ->
Java { j with class_name = (split_classname package_classname) }
| _ ->
Utils.assert_false __POS__
(** Replace the class name of an objc procedure name. *)
let c_method_replace_class t class_name =
match t with
Java { j with class_name = (split_classname new_class) }
| ObjC_Cpp osig ->
ObjC_Cpp { osig with class_name = class_name }
| _ ->
Utils.assert_false __POS__
ObjC_Cpp { osig with class_name = new_class }
| C _
| Block _ ->
t
(** Get the class name of a Objective-C/C++ procedure name. *)
let c_get_class t =
match t with
| ObjC_Cpp osig ->
osig.class_name
| _ ->
Utils.assert_false __POS__
let objc_cpp_get_class_name objc_cpp =
objc_cpp.class_name
(** Return the package.classname of a java procname. *)
let java_get_class (j : java) =
let java_get_class_name (j : java) =
java_type_to_string j.class_name
(** Return the class name of a java procedure name. *)
let java_get_simple_class (j : java) =
let java_get_simple_class_name (j : java) =
snd j.class_name
(** Return the package of a java procname. *)
@ -237,61 +224,58 @@ let java_get_method (j : java) =
j.method_name
(** Replace the method of a java procname. *)
let java_replace_method j mname = match j with
| Java j ->
Java { j with method_name = mname }
| _ ->
Utils.assert_false __POS__
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 p ret_type = match p with
| Java j ->
Java { j with return_type = Some ret_type }
| _ ->
Utils.assert_false __POS__
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 p parameters = match p with
| Java j ->
Java { j with parameters }
| _ ->
Utils.assert_false __POS__
let java_replace_parameters j parameters =
{ j with parameters }
(** Return the method of a objc/c++ procname. *)
let c_get_method = function
(** Return the method/function of a procname. *)
let get_method = function
| ObjC_Cpp name ->
name.method_name
| C (name, _) ->
name
| Block name ->
name
| _ ->
Utils.assert_false __POS__
| Java j ->
j.method_name
(** Return the language of the procedure. *)
let get_language = function
| ObjC_Cpp _ ->
Config.C_CPP
| C _ ->
Config.C_CPP
| Block _ ->
Config.C_CPP
| 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
(** Return the parameters of a java procname. *)
let java_get_parameters = function
| Java j ->
j.parameters
| _ ->
Utils.assert_false __POS__
let java_get_parameters j =
j.parameters
(** Return the parameters of a java procname as strings. *)
let java_get_parameters_as_strings = function
| Java j ->
IList.map (fun param -> java_type_to_string param) j.parameters
| _ ->
Utils.assert_false __POS__
let java_get_parameters_as_strings j =
IList.map (fun param -> java_type_to_string param) j.parameters
(** Return true if the java procedure is static *)
let java_is_static = function
| Java j ->
j.kind = Static
| _ ->
Utils.assert_false __POS__
false
(** Prints a string of a java procname with the given level of verbosity *)
let java_to_string ?(withclass = false) (j : java) verbosity =
@ -322,7 +306,7 @@ let java_to_string ?(withclass = false) (j : java) verbosity =
| _ -> "..." in
let method_name =
if j.method_name = "<init>" then
java_get_simple_class j
java_get_simple_class_name j
else
cls_prefix ^ j.method_name in
method_name ^ "(" ^ params ^ ")"
@ -410,7 +394,7 @@ let is_class_initializer = function
let is_infer_undefined pn = match pn with
| Java j ->
let regexp = Str.regexp "com.facebook.infer.models.InferUndefined" in
Str.string_match regexp (java_get_class j) 0
Str.string_match regexp (java_get_class_name j) 0
| _ ->
(* TODO: add cases for obj-c, c, c++ *)
false

@ -8,25 +8,25 @@
* of patent rights can be found in the PATENTS file in the same directory.
*)
(** Module for Procedure Names *)
(** Module for Procedure Names. *)
(** Type of java procedure names *)
(** Type of java procedure names. *)
type java
(** Type of C function names *)
type c_function
(** Type of c procedure names. *)
type c
(** Type of Objective C and C++ method names *)
type objc_cpp_method
(** Type of Objective C and C++ procedure names. *)
type objc_cpp
(** Type of Objective C block names *)
(** Type of Objective C block names. *)
type block
(** Type of procedure names *)
(** Type of procedure names. *)
type t =
| Java of java
| C of c_function
| ObjC_Cpp of objc_cpp_method
| C of c
| ObjC_Cpp of objc_cpp
| Block of block
type java_type = string option * string
@ -39,62 +39,84 @@ type objc_method_kind =
| Instance_objc_method (* for instance methods in ObjC *)
| Class_objc_method (* for class methods in ObjC *)
val empty : t
(** Hash tables with proc names as keys. *)
module Hash : Hashtbl.S with type key = t
(** Mangled string for method types *)
val mangled_of_objc_method_kind : objc_method_kind -> string option
(** Maps from proc names. *)
module Map : Map.S with type key = t
(** Create ObjC method type from a bool is_instance *)
val objc_method_kind_of_bool : bool -> objc_method_kind
(** Sets of proc names. *)
module Set : Set.S with type elt = t
(** Create a C procedure name from plain and mangled name. *)
val c : string -> string -> c
(** Comparison for proc names *)
(** Comparison for proc names. *)
val compare : t -> t -> int
(** Equality for proc names *)
(** Empty block name. *)
val empty_block : t
(** Equality for proc names. *)
val equal : t -> t -> bool
(** Convert a string to a proc name *)
(** Convert a string to a proc name. *)
val from_string_c_fun : string -> t
(** Create a Java procedure name from its
class_name method_name args_type_name return_type_name method_kind *)
val java : java_type -> java_type option -> string -> java_type list -> method_kind -> java
(** Return the language of the procedure. *)
val get_language : t -> Config.language
(** Create a C++ procedure name from plain and mangled name *)
val mangled_c_fun : string -> string -> t
(** Return the method/function of a procname. *)
val get_method : t -> string
(** Create an objc procedure name from a class_name and method_name. *)
val mangled_c_method : string -> string -> string option -> t
(** Hash function for procname. *)
val hash_pname : t -> int
(** Create an objc block name. *)
val mangled_objc_block : string -> t
(** Check if a class string is an anoynmous inner class name. *)
val is_anonymous_inner_class_name : string -> bool
(** Check if this is an Objective-C/C++ method name. *)
val is_c_method : t -> bool
(** Check if this is a constructor. *)
val is_constructor : t -> bool
(** Return true if this is a Java procedure name *)
(** Check if this is a Java procedure name. *)
val is_java : t -> bool
(** Return true if this is an Objective-C/C++ method name *)
val is_c_method : t -> bool
(** Check if this is a dealloc method in Objective-C. *)
val is_objc_dealloc : t -> bool
(** Replace package and classname of a java procname. *)
val java_replace_class : t -> string -> t
(** Create a Java procedure name from its
class_name method_name args_type_name return_type_name method_kind. *)
val java : java_type -> java_type option -> string -> java_type list -> method_kind -> java
(** Replace the parameters of a java procname. *)
val java_replace_parameters : t -> java_type list -> t
val java_replace_parameters : java -> java_type list -> java
(** Replace the method of a java procname. *)
val java_replace_return_type : t -> java_type -> t
val java_replace_return_type : java -> java_type -> java
(** Replace the class name of an Objective-C procedure name. *)
val c_method_replace_class : t -> string -> t
(** Create an objc block name. *)
val mangled_objc_block : string -> t
(** Mangled string for method types. *)
val mangled_of_objc_method_kind : objc_method_kind -> string option
(** Create an objc procedure name from a class_name and method_name. *)
val objc_cpp : string -> string -> string option -> objc_cpp
(** Get the class name of a Objective-C/C++ procedure name. *)
val c_get_class : t -> string
val objc_cpp_get_class_name : objc_cpp -> string
(** Create ObjC method type from a bool is_instance. *)
val objc_method_kind_of_bool : bool -> objc_method_kind
(** Return the class name of a java procedure name. *)
val java_get_class : java -> string
val java_get_class_name : java -> string
(** Return the simple class name of a java procedure name. *)
val java_get_simple_class : java -> string
val java_get_simple_class_name : java -> string
(** Return the package name of a java procedure name. *)
val java_get_package : java -> string option
@ -102,48 +124,18 @@ val java_get_package : java -> string option
(** Return the method name of a java procedure name. *)
val java_get_method : java -> string
(** Return the method of a objc/c++ procname. *)
val c_get_method : t -> string
(** Replace the method name of an existing java procname. *)
val java_replace_method : t -> string -> t
(** Return the return type of a java procedure name. *)
val java_get_return_type : java -> string
(** Return the parameters of a java procedure name. *)
val java_get_parameters : t -> java_type list
val java_get_parameters : java -> java_type list
(** Return the parameters of a java procname as strings. *)
val java_get_parameters_as_strings : t -> string list
(** Return true if the java procedure is static *)
val java_is_static : t -> bool
(** Check if the last parameter is a hidden inner class, and remove it if present.
This is used in private constructors, where a proxy constructor is generated
with an extra parameter and calls the normal constructor. *)
val java_remove_hidden_inner_class_parameter : t -> t option
val java_get_parameters_as_strings : java -> string list
(** Check if a class string is an anoynmous inner class name *)
val is_anonymous_inner_class_name : string -> bool
(** [is_constructor pname] returns true if [pname] is a constructor *)
val is_constructor : t -> bool
(** [is_objc_dealloc pname] returns true if [pname] is the dealloc method in Objective-C *)
val is_objc_dealloc : t -> bool
(** [java_is_close pname] returns true if the method name is "close" *)
val java_is_close : t -> bool
(** [is_class_initializer pname] returns true if [pname] is a class initializer *)
val is_class_initializer : t -> bool
(** [is_infer_undefined pn] returns true if [pn] is a special Infer undefined proc *)
val is_infer_undefined : t -> bool
val split_classname : string -> string option * string
(** Check if the procedure name is an acess method (e.g. access$100 used to
access private members from a nested class. *)
val java_is_access_method : t -> bool
(** Check if the procedure belongs to an anonymous inner class. *)
val java_is_anonymous_inner_class : t -> bool
@ -151,47 +143,55 @@ val java_is_anonymous_inner_class : t -> bool
(** Check if the procedure name is an anonymous inner class constructor. *)
val java_is_anonymous_inner_class_constructor : t -> bool
(** Check if the procedure name is an acess method (e.g. access$100 used to
access private members from a nested class. *)
val java_is_access_method : t -> bool
(** Check if the method name is "close". *)
val java_is_close : t -> bool
(** Check if the java procedure is static. *)
val java_is_static : t -> bool
(** Check if the proc name has the type of a java vararg.
Note: currently only checks that the last argument has type Object[]. *)
val java_is_vararg : t -> bool
(** Convert a proc name to a string for the user to see *)
val to_string : t -> string
(** Convert a proc name into a easy string for the user to see in an IDE *)
val to_simplified_string : ?withclass: bool -> t -> string
(** Check if the last parameter is a hidden inner class, and remove it if present.
This is used in private constructors, where a proxy constructor is generated
with an extra parameter and calls the normal constructor. *)
val java_remove_hidden_inner_class_parameter : t -> t option
(** Convert a proc name into a unique identifier *)
val to_unique_id : t -> string
(** Replace the method name of an existing java procname. *)
val java_replace_method : java -> string -> java
(** Convert a java type to a string. *)
val java_type_to_string : java_type -> string
(** Convert a proc name to a filename *)
val to_filename : t -> string
(** Check if this is a class initializer. *)
val is_class_initializer : t -> bool
(** Pretty print a proc name *)
(** Check if this is a special Infer undefined procedure. *)
val is_infer_undefined : t -> bool
(** Pretty print a proc name. *)
val pp : Format.formatter -> t -> unit
(** hash function for procname *)
val hash_pname : t -> int
(** Pretty print a set of proc names. *)
val pp_set : Format.formatter -> Set.t -> unit
(** hash tables with proc names as keys *)
module Hash : Hashtbl.S with type key = t
(** Replace the class name component of a procedure name.
In case of Java, replace package and class name. *)
val replace_class : t -> string -> t
(** maps from proc names *)
module Map : Map.S with type key = t
(** Given a package.class_name string, look for the latest dot and split the string
in two (package, class_name). *)
val split_classname : string -> string option * string
(** sets of proc names *)
module Set : Set.S with type elt = t
(** Convert a proc name to a string for the user to see. *)
val to_string : t -> string
(** Pretty print a set of proc names *)
val pp_set : Format.formatter -> Set.t -> unit
(** Convert a proc name into a easy string for the user to see in an IDE. *)
val to_simplified_string : ?withclass: bool -> t -> string
(*
(** Replace the method of a java procname. *)
val java_replace_method : t -> string -> t
*)
(** Convert a proc name into a unique identifier. *)
val to_unique_id : t -> string
(** Convert a proc name to a filename. *)
val to_filename : t -> string

@ -1613,7 +1613,8 @@ let get_overrides_of tenv supertype pname =
(* get all types in the type environment that are non-reflexive subtypes of [supertype] *)
if not (Sil.typ_equal typ supertype) && Subtyping_check.check_subtype tenv typ supertype then
(* only select the ones that implement [pname] as overrides *)
let resolved_pname = Procname.java_replace_class pname (Typename.name tname) in
let resolved_pname =
Procname.replace_class pname (Typename.name tname) in
if typ_has_method resolved_pname typ then (typ, resolved_pname) :: overrides_acc
else overrides_acc
else overrides_acc in

@ -547,9 +547,7 @@ let resolve_method tenv class_name proc_name =
let rec resolve class_name =
visited := Typename.Set.add class_name !visited;
let right_proc_name =
if Procname.is_java proc_name then
Procname.java_replace_class proc_name (Typename.name class_name)
else Procname.c_method_replace_class proc_name (Typename.name class_name) in
Procname.replace_class proc_name (Typename.name class_name) in
match Sil.tenv_lookup tenv class_name with
| Some { Sil.csu = Csu.Class _; def_methods; superclasses } ->
if method_exists right_proc_name def_methods then
@ -568,7 +566,8 @@ let resolve_method tenv class_name proc_name =
Logging.d_strln
("Couldn't find method in the hierarchy of type "^(Typename.name class_name));
proc_name
| Some proc_name -> proc_name
| Some proc_name ->
proc_name
let resolve_typename prop receiver_exp =
let typexp_opt =
@ -619,7 +618,7 @@ let resolve_virtual_pname tenv prop actuals callee_pname call_flags : Procname.t
match pname with
| Procname.Java pname_java ->
(try
let receiver_typ_str = Procname.java_get_class pname_java in
let receiver_typ_str = Procname.java_get_class_name pname_java in
Sil.Tptr (lookup_java_typ_from_string tenv receiver_typ_str, Sil.Pk_pointer)
with Cannot_convert_string_to_typ _ -> fallback_typ)
| _ ->
@ -676,11 +675,11 @@ let resolve_virtual_pname tenv prop actuals callee_pname call_flags : Procname.t
(** Resolve the name of the procedure to call based on the type of the arguments *)
let resolve_java_pname tenv prop args pname call_flags : Procname.t =
let resolve_from_args pname args =
let parameters = Procname.java_get_parameters pname in
let resolve_java_pname tenv prop args pname_java call_flags : Procname.java =
let resolve_from_args resolved_pname_java args =
let parameters = Procname.java_get_parameters resolved_pname_java in
if IList.length args <> IList.length parameters then
pname
resolved_pname_java
else
let resolved_params =
IList.fold_left2
@ -689,24 +688,33 @@ let resolve_java_pname tenv prop args pname call_flags : Procname.t =
| Some class_name ->
(Procname.split_classname (Typename.name class_name)) :: accu
| None -> name :: accu)
[] args (Procname.java_get_parameters pname) |> IList.rev in
Procname.java_replace_parameters pname resolved_params in
let resolved_pname, other_args =
[] args (Procname.java_get_parameters resolved_pname_java) |> IList.rev in
Procname.java_replace_parameters resolved_pname_java resolved_params in
let resolved_pname_java, other_args =
match args with
| [] -> pname, []
| [] ->
pname_java, []
| (first_arg, _) :: other_args when call_flags.Sil.cf_virtual ->
let resolved =
begin
match resolve_typename prop first_arg with
| Some class_name -> resolve_method tenv class_name pname
| None -> pname
| Some class_name ->
begin
match resolve_method tenv class_name (Procname.Java pname_java) with
| Procname.Java resolved_pname_java ->
resolved_pname_java
| _ ->
pname_java
end
| None ->
pname_java
end in
resolved, other_args
| _ :: other_args when Procname.is_constructor pname ->
pname, other_args
| _ :: other_args when Procname.is_constructor (Procname.Java pname_java) ->
pname_java, other_args
| args ->
pname, args in
resolve_from_args resolved_pname other_args
pname_java, args in
resolve_from_args resolved_pname_java other_args
(** Resolve the procedure name and run the analysis of the resolved procedure
@ -733,8 +741,12 @@ let resolve_and_analyze
Cfg.specialize_types callee_proc_desc resolved_pname args)
(Ondemand.get_proc_desc callee_proc_name)
end) in
let resolved_pname =
resolve_java_pname tenv prop args callee_proc_name call_flags in
let resolved_pname = match callee_proc_name with
| Procname.Java callee_proc_name_java ->
Procname.Java
(resolve_java_pname tenv prop args callee_proc_name_java call_flags)
| _ ->
callee_proc_name in
analyze_ondemand resolved_pname;
resolved_pname, Specs.get_summary resolved_pname
@ -2828,12 +2840,14 @@ module ModelBuiltins = struct
let _ =
let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in
Builtin.register_procname
(Procname.mangled_c_method "NSArray" "arrayWithObjects:count:" method_kind)
(Procname.ObjC_Cpp
(Procname.objc_cpp "NSArray" "arrayWithObjects:count:" method_kind))
execute_NSArray_arrayWithObjects_count
let _ =
let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in
Builtin.register_procname
(Procname.mangled_c_method "NSArray" "arrayWithObjects:" method_kind)
(Procname.ObjC_Cpp
(Procname.objc_cpp "NSArray" "arrayWithObjects:" method_kind))
execute_NSArray_arrayWithObjects
let execute_objc_NSDictionary_alloc_no_fail
@ -2853,7 +2867,9 @@ module ModelBuiltins = struct
let __objc_dictionary_literal =
let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in
let pname = Procname.mangled_c_method "NSDictionary" "__objc_dictionary_literal:" method_kind in
let pname =
Procname.ObjC_Cpp
(Procname.objc_cpp "NSDictionary" "__objc_dictionary_literal:" method_kind) in
Builtin.register_procname pname execute___objc_dictionary_literal;
pname

@ -1150,7 +1150,11 @@ let exe_call_postprocess ret_ids trace_call callee_pname loc results =
(fun (p, path) -> (quantify_path_idents_remove_constant_strings p, path))
res_with_path_idents in
let should_add_ret_attr _ =
let is_likely_getter pn = IList.length (Procname.java_get_parameters pn) = 0 in
let is_likely_getter = function
| Procname.Java pn_java ->
IList.length (Procname.java_get_parameters pn_java) = 0
| _ ->
false in
!Config.idempotent_getters &&
!Config.curr_language = Config.Java &&
is_likely_getter callee_pname in

@ -139,12 +139,15 @@ let java_method_to_procname java_method =
let objc_method_to_procname objc_method =
let method_kind = Procname.objc_method_kind_of_bool (not objc_method.is_static) in
let mangled = Procname.mangled_of_objc_method_kind method_kind in
Procname.mangled_c_method objc_method.classname objc_method.method_name mangled
Procname.ObjC_Cpp
(Procname.objc_cpp objc_method.classname objc_method.method_name mangled)
let method_str_to_pname method_str =
match method_str.language with
| Config.C_CPP -> objc_method_to_procname method_str
| Config.Java -> java_method_to_procname method_str
| Config.C_CPP ->
objc_method_to_procname method_str
| Config.Java ->
java_method_to_procname method_str
let sources =
IList.map method_str_to_pname sources

@ -65,7 +65,8 @@ let callback_checker_main_java
proc_name_java ({ Callbacks.proc_desc; tenv } as callback_args) =
let typename =
Typename.TN_csu
(Csu.Class Csu.Java, Mangled.from_string (Procname.java_get_class proc_name_java)) in
(Csu.Class Csu.Java,
Mangled.from_string (Procname.java_get_class_name proc_name_java)) in
match Sil.tenv_lookup tenv typename with
| Some ({ struct_name = Some _; def_methods } as struct_typ) ->
let typ = Sil.Tstruct struct_typ in

@ -49,9 +49,9 @@ module APIs = struct
&&
(match pkgname with
| "" ->
Procname.java_get_simple_class pn_java = cname
Procname.java_get_simple_class_name pn_java = cname
| _ ->
Procname.java_get_class pn_java = pkgname ^ "." ^ cname)
Procname.java_get_class_name pn_java = pkgname ^ "." ^ cname)
| _ ->
false
let is_begin pn =

@ -220,7 +220,7 @@ let callback_check_write_to_parcel_java
match Cfg.Node.get_callees node with
| [] -> false
| [Procname.Java pname_java] ->
let class_name = Procname.java_get_class pname_java in
let class_name = Procname.java_get_class_name pname_java in
let method_name = Procname.java_get_method pname_java in
(try
class_name = "android.os.Parcel" &&
@ -375,7 +375,7 @@ let callback_monitor_nullcheck { Callbacks.proc_desc; idenv; proc_name } =
(match proc_name with
| Procname.Java pname_java ->
L.stdout "call in %s %s: %a with first arg: %a@."
(Procname.java_get_class pname_java)
(Procname.java_get_class_name pname_java)
(Procname.java_get_method pname_java)
(Sil.pp_instr pe_text) instr
(Sil.pp_exp pe_text) arg1

@ -57,7 +57,7 @@ module ConstantFlow = Dataflow.MakeDF(struct
let has_class pn name = match pn with
| Procname.Java pn_java ->
Procname.java_get_class pn_java = name
Procname.java_get_class_name pn_java = name
| _ ->
false in
let has_method pn name = match pn with

@ -38,7 +38,8 @@ let callback_fragment_retains_view_java
Typename.equal fld_classname class_typename && fld_typ_is_view fld_typ in
if is_on_destroy_view then
begin
let class_typename = Typename.Java.from_string (Procname.java_get_class pname_java) in
let class_typename =
Typename.Java.from_string (Procname.java_get_class_name pname_java) in
match Sil.tenv_lookup tenv class_typename with
| Some ({ Sil.struct_name = Some _; instance_fields } as struct_typ)
when AndroidFramework.is_fragment (Sil.Tstruct struct_typ) tenv ->

@ -30,7 +30,7 @@ let type_is_object = function
let java_proc_name_with_class_method pn_java class_with_path method_name =
(try
Procname.java_get_class pn_java = class_with_path &&
Procname.java_get_class_name pn_java = class_with_path &&
Procname.java_get_method pn_java = method_name
with _ -> false)
@ -199,7 +199,7 @@ let has_formal_proc_argument_type_names proc_desc argument_type_names =
let has_formal_method_argument_type_names cfg pname_java argument_type_names =
has_formal_proc_argument_type_names
cfg ((Procname.java_get_class pname_java):: argument_type_names)
cfg ((Procname.java_get_class_name pname_java):: argument_type_names)
let is_getter pname_java =
Str.string_match (Str.regexp "get*") (Procname.java_get_method pname_java) 0
@ -319,7 +319,7 @@ let proc_calls resolve_attributes pdesc filter : (Procname.t * ProcAttributes.t)
let proc_iter_overridden_methods f tenv proc_name =
let do_super_type tenv super_class_name =
let super_proc_name =
Procname.java_replace_class proc_name (Typename.name super_class_name) in
Procname.replace_class proc_name (Typename.name super_class_name) in
match Sil.tenv_lookup tenv super_class_name with
| Some ({ Sil.def_methods }) ->
let is_override pname =
@ -333,9 +333,9 @@ let proc_iter_overridden_methods f tenv proc_name =
| _ -> () in
match proc_name with
| Procname.Java pname_java ->
| Procname.Java proc_name_java ->
let type_name =
let class_name = Procname.java_get_class pname_java in
let class_name = Procname.java_get_class_name proc_name_java in
Typename.TN_csu (Csu.Class Csu.Java, Mangled.from_string class_name) in
(match Sil.tenv_lookup tenv type_name with
| Some curr_struct_typ ->

@ -33,7 +33,7 @@ let is_modeled_expensive =
| Procname.Java proc_name_java ->
not (SymExec.function_is_builtin proc_name) &&
let classname =
Typename.Java.from_string (Procname.java_get_class proc_name_java) in
Typename.Java.from_string (Procname.java_get_class_name proc_name_java) in
(Lazy.force matcher) (AndroidFramework.is_subclass tenv classname) proc_name
| _ ->
false
@ -120,7 +120,7 @@ let is_allocator tenv pname = match pname with
| Procname.Java pname_java ->
let is_throwable () =
let class_name =
Typename.Java.from_string (Procname.java_get_class pname_java) in
Typename.Java.from_string (Procname.java_get_class_name pname_java) in
AndroidFramework.is_throwable tenv class_name in
Procname.is_constructor pname
&& not (SymExec.function_is_builtin pname)

@ -27,7 +27,7 @@ let callback_sql { Callbacks.proc_desc; proc_name } =
(* Check for SQL string concatenations *)
let do_instr const_map node instr =
let do_call pn_java i1 i2 l =
if Procname.java_get_class pn_java = "java.lang.StringBuilder"
if Procname.java_get_class_name pn_java = "java.lang.StringBuilder"
&& Procname.java_get_method pn_java = "append"
then
begin

@ -558,16 +558,18 @@ struct
Procname.from_string_c_fun name
else
let crc = string_crc_hex32 mangled in
Procname.mangled_c_fun name crc
Procname.C (Procname.c name crc)
let mk_procname_from_objc_method class_name method_name method_kind =
let mangled = Procname.mangled_of_objc_method_kind method_kind in
Procname.mangled_c_method class_name method_name mangled
Procname.ObjC_Cpp
(Procname.objc_cpp class_name method_name mangled)
let mk_procname_from_cpp_method class_name method_name tp =
let type_name = Ast_utils.string_of_type_ptr tp in
let type_name_crc = Some (string_crc_hex32 type_name) in
Procname.mangled_c_method class_name method_name type_name_crc
Procname.ObjC_Cpp
(Procname.objc_cpp class_name method_name type_name_crc)
let get_var_name_string name_info var_decl_info =
let clang_name = Ast_utils.get_qualified_name name_info in

@ -216,7 +216,7 @@ let get_method_name_from_clang tenv ms_opt =
match ObjcCategory_decl.get_base_class_name_from_category decl with
| Some class_name ->
let procname = CMethod_signature.ms_get_name ms in
let new_procname = Procname.c_method_replace_class procname class_name in
let new_procname = Procname.replace_class procname class_name in
CMethod_signature.ms_set_name ms new_procname;
Some ms
| None -> Some ms)
@ -249,8 +249,13 @@ let get_class_name_method_call_from_clang tenv obj_c_message_expr_info =
| Some pointer ->
(match method_signature_of_pointer tenv pointer with
| Some ms ->
let class_name = Procname.c_get_class (CMethod_signature.ms_get_name ms) in
Some class_name
begin
match CMethod_signature.ms_get_name ms with
| Procname.ObjC_Cpp objc_cpp ->
Some (Procname.objc_cpp_get_class_name objc_cpp)
| _ ->
None
end
| None -> None)
| None -> None
@ -280,9 +285,9 @@ let get_objc_method_data obj_c_message_expr_info =
let get_objc_property_accessor tenv ms =
let open Clang_ast_t in
let pointer_to_property_opt = CMethod_signature.ms_get_pointer_to_property_opt ms in
match Ast_utils.get_decl_opt pointer_to_property_opt with
| Some (ObjCPropertyDecl _ as d) ->
let class_name = Procname.c_get_class (CMethod_signature.ms_get_name ms) in
match Ast_utils.get_decl_opt pointer_to_property_opt, CMethod_signature.ms_get_name ms with
| Some (ObjCPropertyDecl _ as d), Procname.ObjC_Cpp objc_cpp ->
let class_name = Procname.objc_cpp_get_class_name objc_cpp in
let field_name = CField_decl.get_property_corresponding_ivar tenv
CTypes_decl.type_ptr_to_sil_type class_name d in
if CMethod_signature.ms_is_getter ms then

@ -44,17 +44,21 @@ struct
match method_pointer_opt with
| Some pointer -> CMethod_trans.method_signature_of_pointer context.tenv pointer
| None -> None in
let procname =
let proc_name =
match CMethod_trans.get_method_name_from_clang context.tenv ms_opt with
| Some ms -> CMethod_signature.ms_get_name ms
| Some ms ->
CMethod_signature.ms_get_name ms
| None -> (* fall back to our method resolution if clang's fails *)
let class_name = CMethod_trans.get_class_name_method_call_from_receiver_kind context
obj_c_message_expr_info act_params in
General_utils.mk_procname_from_objc_method class_name selector method_kind in
let class_name = Procname.c_get_class procname in
let predefined_ms_opt =
CTrans_models.get_predefined_model_method_signature class_name selector
General_utils.mk_procname_from_objc_method CFrontend_config.OBJC in
let predefined_ms_opt = match proc_name with
| Procname.ObjC_Cpp objc_cpp ->
let class_name = Procname.objc_cpp_get_class_name objc_cpp in
CTrans_models.get_predefined_model_method_signature class_name selector
General_utils.mk_procname_from_objc_method CFrontend_config.OBJC
| _ ->
None in
match predefined_ms_opt, ms_opt with
| Some ms, _ ->
ignore (CMethod_trans.create_local_procdesc context.cfg context.tenv ms [] [] is_instance);
@ -62,22 +66,23 @@ struct
| None, Some ms ->
ignore (CMethod_trans.create_local_procdesc context.cfg context.tenv ms [] [] is_instance);
if CMethod_signature.ms_is_getter ms || CMethod_signature.ms_is_setter ms then
procname, CMethod_trans.MCNoVirtual
proc_name, CMethod_trans.MCNoVirtual
else
procname, mc_type
proc_name, mc_type
| _ ->
CMethod_trans.create_external_procdesc context.cfg procname is_instance None;
procname, mc_type
CMethod_trans.create_external_procdesc context.cfg proc_name is_instance None;
proc_name, mc_type
let add_autorelease_call context exp typ sil_loc =
let method_name = Procname.c_get_method (Cfg.Procdesc.get_proc_name context.CContext.procdesc) in
let method_name = Procname.get_method (Cfg.Procdesc.get_proc_name context.CContext.procdesc) in
if !Config.arc_mode &&
not (CTrans_utils.is_owning_name method_name) &&
ObjcInterface_decl.is_pointer_to_objc_class context.CContext.tenv typ then
let fname = SymExec.ModelBuiltins.__set_autorelease_attribute in
let ret_id = Ident.create_fresh Ident.knormal in
let stmt_call = Sil.Call([ret_id], (Sil.Const (Sil.Cfun fname)), [(exp, typ)], sil_loc, Sil.cf_default) in
let stmt_call =
Sil.Call ([ret_id], (Sil.Const (Sil.Cfun fname)), [(exp, typ)], sil_loc, Sil.cf_default) in
([ret_id], [stmt_call])
else ([], [])
@ -1838,7 +1843,7 @@ struct
and objCDictionaryLiteral_trans trans_state info stmt_info stmts =
let typ = CTypes_decl.class_from_pointer_type trans_state.context.CContext.tenv info.Clang_ast_t.ei_type_ptr in
let dictionary_literal_pname = SymExec.ModelBuiltins.__objc_dictionary_literal in
let dictionary_literal_s = Procname.c_get_method dictionary_literal_pname in
let dictionary_literal_s = Procname.get_method dictionary_literal_pname in
let obj_c_message_expr_info =
Ast_expressions.make_obj_c_message_expr_info_class dictionary_literal_s typ None in
let stmts = General_utils.swap_elements_list stmts in

@ -197,7 +197,7 @@ struct
let same_class =
let get_class_opt pn = match pn with
| Procname.Java pn_java ->
Some (Procname.java_get_class pn_java)
Some (Procname.java_get_class_name pn_java)
| _ ->
None in
get_class_opt init_pn = get_class_opt callee_pn in
@ -261,7 +261,7 @@ struct
let get_class pn = match pn with
| Procname.Java pn_java ->
Some (Procname.java_get_class pn_java)
Some (Procname.java_get_class_name pn_java)
| _ ->
None

@ -386,7 +386,7 @@ let typecheck_instr ext calls_this checks (node: Cfg.Node.t) idenv get_proc_desc
let constructor_check_calls_this calls_this pn =
match curr_pname, pn with
| Procname.Java curr_pname_java, Procname.Java pn_java ->
if Procname.java_get_class curr_pname_java = Procname.java_get_class pn_java
if Procname.java_get_class_name curr_pname_java = Procname.java_get_class_name pn_java
then calls_this := true
| _ ->
() in
@ -734,9 +734,10 @@ let typecheck_instr ext calls_this checks (node: Cfg.Node.t) idenv get_proc_desc
((_, exp_key), _) ::
((_, exp_value), typ_value) :: _ ->
(* Convert the dexp for k to the dexp for m.get(k) *)
let convert_dexp_key_to_dexp_get = function
| Some dexp_key ->
let pname_get = pname_get_from_pname_put callee_pname in
let convert_dexp_key_to_dexp_get dopt = match dopt, callee_pname with
| Some dexp_key, Procname.Java callee_pname_java ->
let pname_get =
Procname.Java (pname_get_from_pname_put callee_pname_java) in
let dexp_get = Sil.Dconst (Sil.Cfun pname_get) in
let dexp_map = Sil.Dpvar pv_map in
let args = [dexp_map; dexp_key] in
@ -869,13 +870,16 @@ let typecheck_instr ext calls_this checks (node: Cfg.Node.t) idenv get_proc_desc
(* which is then treated as a normal condition != null. *)
let handle_containsKey e =
let map_dexp = function
| Some (Sil.Dretcall (Sil.Dconst (Sil.Cfun pname), args, loc, call_flags)) ->
let pname' =
| Some
(Sil.Dretcall
(Sil.Dconst
(Sil.Cfun (Procname.Java pname_java)), args, loc, call_flags)) ->
let pname_java' =
let object_t = (Some "java.lang", "Object") in
Procname.java_replace_return_type
(Procname.java_replace_method pname "get")
(Procname.java_replace_method pname_java "get")
object_t in
let fun_dexp = Sil.Dconst (Sil.Cfun pname') in
let fun_dexp = Sil.Dconst (Sil.Cfun (Procname.Java pname_java')) in
Some (Sil.Dretcall (fun_dexp, args, loc, call_flags))
| _ -> None in
begin

@ -113,7 +113,7 @@ let rec inhabit_typ typ cfg env =
let typ_class_name =
match constructor with
| Procname.Java pname_java ->
Procname.java_get_simple_class pname_java
Procname.java_get_simple_class_name pname_java
| _ ->
create_fresh_local_name () in
(env, Mangled.from_string typ_class_name)
@ -198,7 +198,8 @@ let create_dummy_harness_file harness_name =
if Sys.file_exists sources_dir then sources_dir
else Filename.get_temp_dir_name () in
let file_str =
Procname.java_get_class harness_name ^ "_" ^Procname.java_get_method harness_name ^ ".java" in
Procname.java_get_class_name
harness_name ^ "_" ^Procname.java_get_method harness_name ^ ".java" in
Filename.concat dummy_file_dir file_str in
DB.source_file_from_string dummy_file_name

@ -192,7 +192,7 @@ let do_all_files classpath sources classes =
let never_null_matcher =
Inferconfig.NeverReturnNull.load_matcher (Inferconfig.inferconfig ()) in
let skip source_file =
skip_translation_matcher source_file Procname.empty in
skip_translation_matcher source_file Procname.empty_block in
let translate_source_file basename (package_opt, _) source_file =
init_global_state source_file;
if not (skip source_file) then

@ -33,7 +33,7 @@ let fix_method_definition_line linereader proc_name_java loc =
let method_name =
if Procname.is_constructor proc_name then
let inner_class_name cname = snd (string_split_character cname '$') in
inner_class_name (Procname.java_get_simple_class proc_name_java)
inner_class_name (Procname.java_get_simple_class_name proc_name_java)
else Procname.java_get_method proc_name_java in
let regex = Str.regexp (Str.quote method_name) in
let method_is_defined_here linenum =

@ -52,7 +52,7 @@ module StructuredSil = struct
let dummy_typ = Sil.Tvoid
let dummy_loc = Location.dummy
let dummy_procname = Procname.empty
let dummy_procname = Procname.empty_block
let label_counter = ref 0

Loading…
Cancel
Save