[infer][java] Skip the translation of modeled methods earlier

Summary: Seems more natural to check this at this level

Reviewed By: sblackshear

Differential Revision: D4137569

fbshipit-source-id: 283e094
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent d5e7ee0d82
commit 2e16920f5a

@ -147,13 +147,19 @@ let create_icfg source_file linereader program icfg cn node =
cache_classname cn; cache_classname cn;
let translate m = let translate m =
let proc_name = JTransType.translate_method_name m in let proc_name = JTransType.translate_method_name m in
(* each procedure has different scope: start names from id 0 *) if JClasspath.is_model proc_name then
Ident.NameGenerator.reset (); (* do not translate the method if there is a model for it *)
match m with L.out_debug "Skipping method with a model: %s@." (Procname.to_string proc_name)
| Javalib.ConcreteMethod cm -> else
add_cmethod source_file program linereader icfg cm proc_name begin
| Javalib.AbstractMethod am -> (* each procedure has different scope: start names from id 0 *)
add_amethod source_file program linereader icfg am proc_name in Ident.NameGenerator.reset ();
match m with
| Javalib.ConcreteMethod cm ->
add_cmethod source_file program linereader icfg cm proc_name
| Javalib.AbstractMethod am ->
add_amethod source_file program linereader icfg am proc_name
end in
Javalib.m_iter translate node Javalib.m_iter translate node

@ -236,109 +236,102 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
let tenv = icfg.JContext.tenv in let tenv = icfg.JContext.tenv in
let cn, ms = JBasics.cms_split (Javalib.get_class_method_signature m) in let cn, ms = JBasics.cms_split (Javalib.get_class_method_signature m) in
let proc_name = JTransType.translate_method_name m in let proc_name = JTransType.translate_method_name m in
if JClasspath.is_model proc_name then let trans_access = function
begin | `Default -> PredSymb.Default
(* do not translate the method if there is a model for it *) | `Public -> PredSymb.Public
L.out_debug "Skipping method with a model: %s@." (Procname.to_string proc_name); | `Private -> PredSymb.Private
None | `Protected -> PredSymb.Protected in
end try
else let procdesc =
let trans_access = function match m with
| `Default -> PredSymb.Default | Javalib.AbstractMethod am -> (* create a procdesc with empty body *)
| `Public -> PredSymb.Public let formals =
| `Private -> PredSymb.Private formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
| `Protected -> PredSymb.Protected in let method_annotation =
try JAnnotation.translate_method proc_name am.Javalib.am_annotations in
let procdesc = let procdesc =
match m with
| Javalib.AbstractMethod am -> (* create a procdesc with empty body *)
let formals =
formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation =
JAnnotation.translate_method proc_name am.Javalib.am_annotations in
let procdesc =
let proc_attributes =
{ (ProcAttributes.default proc_name Config.Java) with
ProcAttributes.access = trans_access am.Javalib.am_access;
exceptions = IList.map JBasics.cn_name am.Javalib.am_exceptions;
formals;
is_abstract = true;
is_bridge_method = am.Javalib.am_bridge;
is_defined = true;
is_synthetic_method = am.Javalib.am_synthetic;
method_annotation;
ret_type = JTransType.return_type program tenv ms;
} in
Cfg.create_proc_desc cfg proc_attributes in
let start_kind = Cfg.Node.Start_node proc_name in
let start_node = Cfg.Procdesc.create_node procdesc Location.dummy start_kind [] in
let exit_kind = (Cfg.Node.Exit_node proc_name) in
let exit_node = Cfg.Procdesc.create_node procdesc Location.dummy exit_kind [] in
Cfg.Procdesc.node_set_succs_exn procdesc start_node [exit_node] [exit_node];
Cfg.Procdesc.set_start_node procdesc start_node;
Cfg.Procdesc.set_exit_node procdesc exit_node;
procdesc
| Javalib.ConcreteMethod cm when is_java_native cm ->
let formals =
formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation =
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;
exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions;
formals;
is_bridge_method = cm.Javalib.cm_bridge;
is_synthetic_method = cm.Javalib.cm_synthetic;
method_annotation;
ret_type = JTransType.return_type program tenv ms;
} in
Cfg.create_proc_desc cfg proc_attributes;
| Javalib.ConcreteMethod cm ->
let impl = get_implementation cm in
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 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 cm.Javalib.cm_annotations in
update_constr_loc cn ms loc_start;
update_init_loc cn ms loc_exit;
let proc_attributes = let proc_attributes =
{ (ProcAttributes.default proc_name Config.Java) with { (ProcAttributes.default proc_name Config.Java) with
ProcAttributes.access = trans_access cm.Javalib.cm_access; ProcAttributes.access = trans_access am.Javalib.am_access;
exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions; exceptions = IList.map JBasics.cn_name am.Javalib.am_exceptions;
formals; formals;
is_bridge_method = cm.Javalib.cm_bridge; is_abstract = true;
is_bridge_method = am.Javalib.am_bridge;
is_defined = true; is_defined = true;
is_synthetic_method = cm.Javalib.cm_synthetic; is_synthetic_method = am.Javalib.am_synthetic;
is_java_synchronized_method = cm.Javalib.cm_synchronized;
loc = loc_start;
locals;
method_annotation; method_annotation;
ret_type = JTransType.return_type program tenv ms; ret_type = JTransType.return_type program tenv ms;
} in } in
let procdesc = Cfg.create_proc_desc cfg proc_attributes in
Cfg.create_proc_desc cfg proc_attributes in let start_kind = Cfg.Node.Start_node proc_name in
let start_kind = Cfg.Node.Start_node proc_name in let start_node = Cfg.Procdesc.create_node procdesc Location.dummy start_kind [] in
let start_node = Cfg.Procdesc.create_node procdesc loc_start start_kind [] in let exit_kind = (Cfg.Node.Exit_node proc_name) in
let exit_kind = (Cfg.Node.Exit_node proc_name) in let exit_node = Cfg.Procdesc.create_node procdesc Location.dummy exit_kind [] in
let exit_node = Cfg.Procdesc.create_node procdesc loc_exit exit_kind [] in Cfg.Procdesc.node_set_succs_exn procdesc start_node [exit_node] [exit_node];
let exn_kind = Cfg.Node.exn_sink_kind in Cfg.Procdesc.set_start_node procdesc start_node;
let exn_node = Cfg.Procdesc.create_node procdesc loc_exit exn_kind [] in Cfg.Procdesc.set_exit_node procdesc exit_node;
JContext.add_exn_node proc_name exn_node; procdesc
Cfg.Procdesc.set_start_node procdesc start_node; | Javalib.ConcreteMethod cm when is_java_native cm ->
Cfg.Procdesc.set_exit_node procdesc exit_node; let formals =
Cfg.Node.add_locals_ret_declaration start_node proc_attributes locals; formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
procdesc in let method_annotation =
Some procdesc JAnnotation.translate_method proc_name cm.Javalib.cm_annotations in
with JBir.Subroutine | JBasics.Class_structure_error _ -> let proc_attributes =
L.do_err { (ProcAttributes.default proc_name Config.Java) with
"create_procdesc raised JBir.Subroutine or JBasics.Class_structure_error on %a@." ProcAttributes.access = trans_access cm.Javalib.cm_access;
Procname.pp proc_name; exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions;
None formals;
is_bridge_method = cm.Javalib.cm_bridge;
is_synthetic_method = cm.Javalib.cm_synthetic;
method_annotation;
ret_type = JTransType.return_type program tenv ms;
} in
Cfg.create_proc_desc cfg proc_attributes;
| Javalib.ConcreteMethod cm ->
let impl = get_implementation cm in
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 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 cm.Javalib.cm_annotations in
update_constr_loc cn ms loc_start;
update_init_loc cn ms loc_exit;
let proc_attributes =
{ (ProcAttributes.default proc_name Config.Java) with
ProcAttributes.access = trans_access cm.Javalib.cm_access;
exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions;
formals;
is_bridge_method = cm.Javalib.cm_bridge;
is_defined = true;
is_synthetic_method = cm.Javalib.cm_synthetic;
is_java_synchronized_method = cm.Javalib.cm_synchronized;
loc = loc_start;
locals;
method_annotation;
ret_type = JTransType.return_type program tenv ms;
} in
let procdesc =
Cfg.create_proc_desc cfg proc_attributes in
let start_kind = Cfg.Node.Start_node proc_name in
let start_node = Cfg.Procdesc.create_node procdesc loc_start start_kind [] in
let exit_kind = (Cfg.Node.Exit_node proc_name) in
let exit_node = Cfg.Procdesc.create_node procdesc loc_exit exit_kind [] in
let exn_kind = Cfg.Node.exn_sink_kind in
let exn_node = Cfg.Procdesc.create_node procdesc loc_exit exn_kind [] in
JContext.add_exn_node proc_name exn_node;
Cfg.Procdesc.set_start_node procdesc start_node;
Cfg.Procdesc.set_exit_node procdesc exit_node;
Cfg.Node.add_locals_ret_declaration start_node proc_attributes locals;
procdesc in
Some procdesc
with JBir.Subroutine | JBasics.Class_structure_error _ ->
L.do_err
"create_procdesc raised JBir.Subroutine or JBasics.Class_structure_error on %a@."
Procname.pp proc_name;
None
let builtin_new = let builtin_new =
Exp.Const (Const.Cfun BuiltinDecl.__new) Exp.Const (Const.Cfun BuiltinDecl.__new)

Loading…
Cancel
Save