[infer][java] Simplify the API to translate Java method names into SIL procedure names

Summary: This removes some code duplication

Reviewed By: jvillard

Differential Revision: D4137565

fbshipit-source-id: a015a61
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent e757d92e72
commit b3e406ddf3

@ -48,12 +48,12 @@ let translate_item avlist : Annot.Item.t =
(** Translate a method annotation. *)
let translate_method proc_name_java ann : Annot.Method.t =
let translate_method proc_name ann : Annot.Method.t =
let global_ann = ann.Javalib.ma_global in
let param_ann = ann.Javalib.ma_parameters in
let ret_item =
let base_annotations = translate_item global_ann in
if is_suppress_warnings_annotated (Procname.Java proc_name_java) then
if is_suppress_warnings_annotated proc_name then
suppress_warnings :: base_annotations
else base_annotations in
let param_items = IList.map translate_item param_ann in

@ -17,4 +17,4 @@ open Javalib_pack
val translate_item : (JBasics.annotation * Javalib.visibility) list -> Annot.Item.t
(** Translate a method annotation. *)
val translate_method : Procname.java -> Javalib.method_annotations -> Annot.Method.t
val translate_method : Procname.t -> Javalib.method_annotations -> Annot.Method.t

@ -75,10 +75,8 @@ let add_edges
(** Add a concrete method. *)
let add_cmethod source_file program linereader icfg cm method_kind =
let cn, ms = JBasics.cms_split cm.Javalib.cm_class_method_signature in
let proc_name_java = JTransType.get_method_procname cn ms method_kind in
let proc_name = Procname.Java proc_name_java in
let add_cmethod source_file program linereader icfg cm proc_name =
let cn, _ = JBasics.cms_split cm.Javalib.cm_class_method_signature in
let jmethod = (Javalib.ConcreteMethod cm) in
match JTrans.create_procdesc source_file program linereader icfg jmethod with
| None -> ()
@ -101,10 +99,7 @@ let add_cmethod source_file program linereader icfg cm method_kind =
(** Add an abstract method. *)
let add_amethod source_file program linereader icfg am method_kind =
let cn, ms = JBasics.cms_split am.Javalib.am_class_method_signature in
let proc_name_java = JTransType.get_method_procname cn ms method_kind in
let proc_name = Procname.Java proc_name_java in
let add_amethod source_file program linereader icfg am proc_name =
let jmethod = (Javalib.AbstractMethod am) in
match JTrans.create_procdesc source_file program linereader icfg jmethod with
| None -> ()
@ -151,14 +146,14 @@ let create_icfg source_file linereader program icfg cn node =
if Config.dependency_mode && not (is_classname_cached cn) then
cache_classname cn;
let translate m =
let proc_name = JTransType.translate_method_name m in
(* each procedure has different scope: start names from id 0 *)
Ident.NameGenerator.reset ();
let method_kind = JTransType.get_method_kind m in
match m with
| Javalib.ConcreteMethod cm ->
add_cmethod source_file program linereader icfg cm method_kind
add_cmethod source_file program linereader icfg cm proc_name
| Javalib.AbstractMethod am ->
add_amethod source_file program linereader icfg am method_kind in
add_amethod source_file program linereader icfg am proc_name in
Javalib.m_iter translate node

@ -30,8 +30,11 @@ let init_loc_map : Location.t JBasics.ClassMap.t ref = ref JBasics.ClassMap.empt
(** Fix the line associated to a method definition.
Since Sawja often reports a method off by a few lines, we search
backwards for a line where the method name is. *)
let fix_method_definition_line linereader proc_name_java loc =
let proc_name = Procname.Java proc_name_java in
let fix_method_definition_line linereader proc_name loc =
let proc_name_java =
match proc_name with
| Procname.Java p -> p
| _ -> assert false in
let method_name =
if Procname.is_constructor proc_name then
let inner_class_name cname = snd (string_split_character cname '$') in
@ -232,8 +235,7 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
let cfg = icfg.JContext.cfg in
let tenv = icfg.JContext.tenv in
let cn, ms = JBasics.cms_split (Javalib.get_class_method_signature m) in
let proc_name_java = JTransType.get_method_procname cn ms (JTransType.get_method_kind m) in
let proc_name = Procname.Java proc_name_java in
let proc_name = JTransType.translate_method_name m in
if JClasspath.is_model proc_name then
begin
(* do not translate the method if there is a model for it *)
@ -253,7 +255,7 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
let formals =
formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation =
JAnnotation.translate_method proc_name_java am.Javalib.am_annotations in
JAnnotation.translate_method proc_name am.Javalib.am_annotations in
let procdesc =
let proc_attributes =
{ (ProcAttributes.default proc_name Config.Java) with
@ -280,7 +282,7 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
let formals =
formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation =
JAnnotation.translate_method proc_name_java cm.Javalib.cm_annotations in
JAnnotation.translate_method proc_name cm.Javalib.cm_annotations in
let proc_attributes =
{ (ProcAttributes.default proc_name Config.Java) with
ProcAttributes.access = trans_access cm.Javalib.cm_access;
@ -297,11 +299,11 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
let locals, formals = locals_formals program tenv cn impl in
let loc_start =
let loc = get_location source_file impl 0 in
fix_method_definition_line linereader proc_name_java loc in
fix_method_definition_line linereader proc_name loc in
let loc_exit =
get_location source_file impl (Array.length (JBir.code impl) - 1) in
let method_annotation =
JAnnotation.translate_method proc_name_java cm.Javalib.cm_annotations in
JAnnotation.translate_method proc_name cm.Javalib.cm_annotations in
update_constr_loc cn ms loc_start;
update_init_loc cn ms loc_exit;
let proc_attributes =
@ -521,7 +523,7 @@ let method_invocation
if JBasics.cn_equal cn' (JBasics.make_cn JConfig.infer_builtins_cl) &&
BuiltinDecl.is_declared proc
then proc
else Procname.Java (JTransType.get_method_procname cn' ms method_kind) in
else JTransType.get_method_procname cn' ms method_kind in
let call_instrs =
let callee_fun = Exp.Const (Const.Cfun callee_procname) in
let return_type =

@ -191,18 +191,18 @@ let get_method_kind m =
then Procname.Static
else Procname.Non_Static
(* create a mangled procname from an abstract or concrete method *)
let get_method_procname cn ms kind =
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 = cn_to_java_type cn in
Procname.java class_name return_type_name method_name args_type_name kind
let proc_name_java =
Procname.java class_name return_type_name method_name args_type_name method_kind in
Procname.Java proc_name_java
(* create a mangled procname from an abstract or concrete method *)
let translate_method_name m =
let cn, ms = JBasics.cms_split (Javalib.get_class_method_signature m) in
get_method_procname cn ms (get_method_kind m)
let get_class_procnames cn node =
let collect jmethod procnames =
let ms = Javalib.get_method_signature jmethod in
let kind = get_method_kind jmethod in
(get_method_procname cn ms kind) :: procnames in
Javalib.m_fold collect node []
let create_fieldname cn fs =
let fieldname cn fs =
@ -329,7 +329,10 @@ and get_class_struct_typ program tenv cn =
let super_classname = typename_of_classname super_cn in
super_classname :: interface_list in
(super_classname_list, nonstatics, statics, item_annotation) in
let methods = IList.map (fun j -> Procname.Java j) (get_class_procnames cn node) in
let methods =
Javalib.m_fold
(fun m procnames -> (translate_method_name m) :: procnames)
node [] in
Tenv.mk_struct tenv ~fields ~statics ~methods ~supers ~annots name
let get_class_type_no_pointer program tenv cn =

@ -26,7 +26,10 @@ val get_method_kind : JCode.jcode Javalib.jmethod -> Procname.method_kind
(** returns a procedure name based on the class name and the method's signature. *)
val get_method_procname :
JBasics.class_name -> JBasics.method_signature -> Procname.method_kind -> Procname.java
JBasics.class_name -> JBasics.method_signature -> Procname.method_kind -> Procname.t
(** translate the SIL procedure name of the Java method *)
val translate_method_name : JCode.jcode Javalib.jmethod -> Procname.t
(** [get_class_struct_typ program tenv cn] returns the struct_typ representation of the class *)
val get_class_struct_typ: JClasspath.program -> Tenv.t -> JBasics.class_name -> StructTyp.t

Loading…
Cancel
Save