@ -73,47 +73,43 @@ let add_edges
Cfg . Node . set_succs_exn cfg exn_node exit_nodes exit_nodes ;
Cfg . Node . set_succs_exn cfg exn_node exit_nodes exit_nodes ;
Array . iteri connect_nodes method_body_nodes
Array . iteri connect_nodes method_body_nodes
(* * Add a concrete method. *)
(* * Add a concrete method. *)
let add_cmethod source_file program icfg cm is_static =
let add_cmethod source_file program icfg cm method_kind =
let cfg = icfg . JContext . cfg in
let cfg = icfg . JContext . cfg in
let tenv = icfg . JContext . tenv in
let cn , ms = JBasics . cms_split cm . Javalib . cm_class_method_signature in
let cn , ms = JBasics . cms_split cm . Javalib . cm_class_method_signature in
match JTrans . get_method_procdesc program cfg tenv cn ms is_static with
let proc_name_java = JTransType . get_method_procname cn ms method_kind in
| JTrans . Defined procdesc when JClasspath . is_model ( Cfg . Procdesc . get_proc_name procdesc ) ->
let proc_name = Procname . Java proc_name_java in
(* do not capture the method if there is a model for it *)
match Cfg . Procdesc . find_from_name cfg proc_name with
JUtils . log
| None -> ()
" Skipping method with a model: %s@. "
| Some _ when JTrans . is_java_native cm -> ()
( Procname . to_string ( Cfg . Procdesc . get_proc_name procdesc ) ) ;
| Some procdesc ->
| JTrans . Defined procdesc ->
let start_node = Cfg . Procdesc . get_start_node procdesc in
let start_node = Cfg . Procdesc . get_start_node procdesc in
let exit_node = Cfg . Procdesc . get_exit_node procdesc in
let exit_node = Cfg . Procdesc . get_exit_node procdesc in
let exn_node =
let exn_node =
match JContext . get_exn_node procdesc with
match JContext . get_exn_node procdesc with
| Some node -> node
| Some node -> node
| None -> assert false in
| None ->
failwithf " No exn node found for %s " ( Procname . to_string proc_name ) in
let impl = JTrans . get_implementation cm in
let impl = JTrans . get_implementation cm in
let instrs = JBir . code impl in
let instrs = JBir . code impl in
let context =
let context =
JContext . create_context icfg procdesc impl cn source_file program in
JContext . create_context icfg procdesc impl cn source_file program in
let method_body_nodes = Array . mapi ( JTrans . instruction context ) instrs in
let method_body_nodes = Array . mapi ( JTrans . instruction context ) instrs in
let procname = Cfg . Procdesc . get_proc_name procdesc in
add_edges context start_node exn_node [ exit_node ] method_body_nodes impl false ;
add_edges context start_node exn_node [ exit_node ] method_body_nodes impl false ;
Cg . add_defined_node icfg . JContext . cg procname ;
Cg . add_defined_node icfg . JContext . cg proc_name
| JTrans . Called _ -> ()
(* * Add an abstract method. *)
(* * Add an abstract method. *)
let add_amethod program icfg am is_static =
let add_amethod icfg am method_kind =
let cfg = icfg . JContext . cfg in
let cfg = icfg . JContext . cfg in
let tenv = icfg . JContext . tenv in
let cn , ms = JBasics . cms_split am . Javalib . am_class_method_signature in
let cn , ms = JBasics . cms_split am . Javalib . am_class_method_signature in
match JTrans . get_method_procdesc program cfg tenv cn ms is_static with
let proc_name_java = JTransType . get_method_procname cn ms method_kind in
| JTrans . Defined procdesc when ( JClasspath . is_model ( Cfg . Procdesc . get_proc_name procdesc ) ) ->
let proc_name = Procname . Java proc_name_java in
(* do not capture the method if there is a model for it *)
match Cfg . Procdesc . find_from_name cfg proc_name with
JUtils . log " Skipping method with a model: %s@. " ( Procname . to_string ( Cfg . Procdesc . get_proc_name procdesc ) ) ;
| None -> ()
| JTrans . Defined procdesc ->
| Some procdesc ->
Cg . add_defined_node icfg . JContext . cg ( Cfg . Procdesc . get_proc_name procdesc )
Cg . add_defined_node icfg . JContext . cg ( Cfg . Procdesc . get_proc_name procdesc )
| JTrans . Called _ -> ()
let path_of_cached_classname cn =
let path_of_cached_classname cn =
@ -155,7 +151,7 @@ let create_icfg source_file linereader program icfg cn node =
let cfg = icfg . JContext . cfg in
let cfg = icfg . JContext . cfg in
let tenv = icfg . JContext . tenv in
let tenv = icfg . JContext . tenv in
begin
begin
Javalib . m_iter ( JTrans . create_ local_ procdesc source_file program linereader cfg tenv ) node ;
Javalib . m_iter ( JTrans . create_ procdesc source_file program linereader cfg tenv ) node ;
Javalib . m_iter ( fun m ->
Javalib . m_iter ( fun m ->
(* each procedure has different scope: start names from id 0 *)
(* each procedure has different scope: start names from id 0 *)
Ident . NameGenerator . reset () ;
Ident . NameGenerator . reset () ;
@ -164,18 +160,10 @@ let create_icfg source_file linereader program icfg cn node =
| Javalib . ConcreteMethod cm ->
| Javalib . ConcreteMethod cm ->
add_cmethod source_file program icfg cm method_kind
add_cmethod source_file program icfg cm method_kind
| Javalib . AbstractMethod am ->
| Javalib . AbstractMethod am ->
add_amethod program icfg am method_kind
add_amethod icfg am method_kind
) node
) node
end
end
(*
This type definition is for a future improvement of the capture where in one pass , the frontend will
translate things differently whether a source file is found for a given class
type capture_status =
| With_source of string
| Library of string
| Unknown
* )
(* returns true for the set of classes that are selected to be translated *)
(* returns true for the set of classes that are selected to be translated *)
let should_capture classes package_opt source_basename node =
let should_capture classes package_opt source_basename node =