@ -20,8 +20,9 @@ module type CMethod_decl = sig
val process_methods : Sil . tenv -> Cg . t -> Cfg . cfg -> CContext . curr_class -> string option ->
Clang_ast_t . decl list -> unit
val function_decl : Sil . tenv -> Cfg . cfg -> Cg . t -> string option -> bool -> Clang_ast_t . decl_info ->
string -> Clang_ast_t . qual_type -> Clang_ast_t . function_decl_info -> ( Mangled . t * Sil . typ * bool ) list -> Procname . t option -> CContext . curr_class -> unit
val function_decl : Sil . tenv -> Cfg . cfg -> Cg . t -> string option -> Clang_ast_t . decl ->
( Clang_ast_t . qual_type * bool * Procname . t * ( Mangled . t * Sil . typ * bool ) list ) option ->
CContext . curr_class -> unit
val process_getter_setter : CContext . t -> Procname . t -> bool
end
@ -29,68 +30,13 @@ end
module CMethod_decl_funct ( T : CModule_type . CTranslation ) : CMethod_decl =
struct
let method_body_to_translate di ms body =
let method_body_to_translate ms body =
match body with
| Some body ->
if not ( CLocation . should_translate_lib ( CMethod_signature . ms_get_loc ms ) )
then None else Some body
| None -> body
type function_method_decl_info =
| Func_decl_info of Clang_ast_t . function_decl_info * string
| Meth_decl_info of Clang_ast_t . obj_c_method_decl_info * string
let is_instance_method function_method_decl_info is_instance is_anonym_block =
if is_anonym_block then is_instance
else (
match function_method_decl_info with
| Func_decl_info ( function_decl_info , _ ) -> false
| Meth_decl_info ( method_decl_info , _ ) ->
method_decl_info . Clang_ast_t . omdi_is_instance_method )
let get_parameters function_method_decl_info =
let par_to_ms_par par =
match par with
| ParmVarDecl ( decl_info , name_info , qtype , var_decl_info ) ->
let name = name_info . Clang_ast_t . ni_name in
Printing . log_out " Adding param '%s' " name ;
Printing . log_out " with pointer %s@. " decl_info . Clang_ast_t . di_pointer ;
( name , CTypes . get_type qtype , var_decl_info . vdi_init_expr )
| _ -> assert false in
match function_method_decl_info with
| Func_decl_info ( function_decl_info , _ ) ->
list_map par_to_ms_par function_decl_info . Clang_ast_t . fdi_parameters
| Meth_decl_info ( method_decl_info , class_name ) ->
let pars = list_map par_to_ms_par method_decl_info . Clang_ast_t . omdi_parameters in
if ( is_instance_method function_method_decl_info false false ) then
( " self " , class_name , None ) :: pars
else pars
let get_return_type function_method_decl_info =
match function_method_decl_info with
| Func_decl_info ( _ , qt ) -> qt
| Meth_decl_info ( method_decl_info , _ ) ->
let qt = method_decl_info . Clang_ast_t . omdi_result_type in
CTypes . get_type qt
let build_method_signature decl_info procname function_method_decl_info is_instance is_anonym_block is_generated =
let source_range = decl_info . Clang_ast_t . di_source_range in
let qt = get_return_type function_method_decl_info in
let is_instance_method = is_instance_method function_method_decl_info is_instance is_anonym_block in
let parameters = get_parameters function_method_decl_info in
let attributes = decl_info . Clang_ast_t . di_attributes in
CMethod_signature . make_ms procname parameters qt attributes source_range is_instance_method is_generated
let create_function_signature di fdecl_info name qt is_instance anonym_block_opt =
let procname , is_anonym_block =
match anonym_block_opt with
| Some block -> block , true
| None -> CMethod_trans . mk_procname_from_function name ( CTypes . get_type qt ) , false in
let ms = build_method_signature di procname
( Func_decl_info ( fdecl_info , CTypes . get_type qt ) ) is_instance is_anonym_block false in
( match method_body_to_translate di ms fdecl_info . Clang_ast_t . fdi_body with
| Some body -> Some body , ms
| None -> None , ms )
let model_exists procname =
Specs . summary_exists_in_models procname && not ! CFrontend_config . models_mode
@ -147,58 +93,55 @@ struct
CMethod_trans . create_external_procdesc cfg procname is_objc_method None ;
()
let function_decl tenv cfg cg namespace is_instance di name qt fdecl_info captured_vars anonym_block_opt curr_class =
Printing . log_out " \n Found FunctionDecl '%s'. Processing... \n " name ;
let function_decl tenv cfg cg namespace func_decl block_data_opt curr_class =
Printing . log_out " \n Resetting the goto_labels hashmap... \n " ;
CTrans_utils . GotoLabel . reset_all_labels () ; (* C Language Std 6.8.6.1-1 *)
match create_function_signature di fdecl_info name qt is_instance anonym_block_opt with
| Some body , ms -> (* Only in the case the function declaration has a defined body we create a procdesc *)
let ms , body_opt , param_decls =
CMethod_trans . method_signature_of_decl curr_class func_decl block_data_opt in
match method_body_to_translate ms body_opt with
| Some body -> (* Only in the case the function declaration has a defined body we create a procdesc *)
let procname = CMethod_signature . ms_get_name ms in
let is_anonym_block , captured_vars =
match block_data_opt with
| Some ( _ , _ , _ , captured_vars ) -> true , captured_vars
| None -> false , [] in
if CMethod_trans . create_local_procdesc cfg tenv ms [ body ] captured_vars false then
let is_instance = CMethod_signature . ms_is_instance ms in
let is_anonym_block = Option . is_some anonym_block_opt in
let is_objc_method = is_anonym_block in
let curr_class = if is_anonym_block then curr_class else CContext . ContextNoCls in
let attributes = CMethod_signature . ms_get_attributes ms in
CMethod_signature . add ms ;
add_method tenv cg cfg curr_class procname namespace [ body ] is_objc_method is_instance
captured_vars is_anonym_block fdecl_info . Clang_ast_t . fdi_parameters attributes
| None , ms -> CMethod_signature . add ms
let process_objc_method_decl tenv cg cfg namespace curr_class decl_info name_info method_decl_info =
let class_name = CContext . get_curr_class_name curr_class in
let method_name = name_info . Clang_ast_t . ni_name in
let is_instance = method_decl_info . Clang_ast_t . omdi_is_instance_method in
let method_kind = Procname . objc_method_kind_of_bool is_instance in
let procname = CMethod_trans . mk_procname_from_method class_name method_name method_kind in
let method_decl = Meth_decl_info ( method_decl_info , class_name ) in
let is_generated = Ast_utils . is_generated name_info in
let ms = build_method_signature decl_info procname method_decl false false is_generated in
Printing . log_out " ....Processing implementation for method '%s' \n " ( Procname . to_string procname ) ;
captured_vars is_anonym_block param_decls attributes
| None -> CMethod_signature . add ms
let process_objc_method_decl tenv cg cfg namespace curr_class meth_decl =
let ms , body_opt , param_decls =
CMethod_trans . method_signature_of_decl curr_class meth_decl None in
CMethod_signature . add ms ;
( match method_body_to_translate decl_info ms method_decl_info . Clang_ast_t . omdi_body with
| Some body ->
let is_instance = CMethod_signature . ms_is_instance ms in
let attributes = CMethod_signature . ms_get_attributes ms in
if CMethod_trans . create_local_procdesc cfg tenv ms [ body ] [] is_instance then
add_method tenv cg cfg curr_class procname namespace [ body ] true is_instance [] false
method_decl_info . Clang_ast_t . omdi_parameters attributes
| None -> () )
match method_body_to_translate ms body_opt with
| Some body ->
let is_instance = CMethod_signature . ms_is_instance ms in
let attributes = CMethod_signature . ms_get_attributes ms in
let procname = CMethod_signature . ms_get_name ms in
if CMethod_trans . create_local_procdesc cfg tenv ms [ body ] [] is_instance then
add_method tenv cg cfg curr_class procname namespace [ body ] true is_instance [] false
param_decls attributes
| None -> ()
let rec process_one_method_decl tenv cg cfg curr_class namespace dec =
match dec with
| ObjCMethodDecl ( decl_info , name_info , method_decl_info ) ->
process_objc_method_decl tenv cg cfg namespace curr_class decl_info name_info method_decl_info
| ObjCPropertyImplDecl ( decl_info , property_impl_decl_info ) ->
| ObjCMethodDecl ( decl_info , name_info , method_decl_info ) ->
process_objc_method_decl tenv cg cfg namespace curr_class dec
| ObjCPropertyImplDecl ( decl_info , property_impl_decl_info ) ->
let pname = Ast_utils . property_name property_impl_decl_info in
Printing . log_out " ADDING: ObjCPropertyImplDecl for property '%s' " pname ;
let getter_setter = ObjcProperty_decl . make_getter_setter curr_class decl_info pname in
list_iter ( process_one_method_decl tenv cg cfg curr_class namespace ) getter_setter
| EmptyDecl _ | ObjCIvarDecl _ | ObjCPropertyDecl _ -> ()
| d -> Printing . log_err
" \n WARNING: found Method Declaration '%s' skipped. NEED TO BE FIXED \n \n " ( Ast_utils . string_of_decl d ) ;
| _ ->
Printing . log_stats
" \n WARNING: found Method Declaration '%s' skipped. NEED TO BE FIXED \n \n " ( Ast_utils . string_of_decl dec ) ;
()
let process_methods tenv cg cfg curr_class namespace decl_list =