simplify code handling default paramters

Reviewed By: ddino

Differential Revision: D2564783

fb-gh-sync-id: 5cca570
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent 042bcaf3e6
commit 1c80ba8bb7

@ -12,7 +12,7 @@
type method_signature = { type method_signature = {
_name : Procname.t; _name : Procname.t;
_args : (string * Clang_ast_t.type_ptr * Clang_ast_t.stmt option) list; _args : (string * Clang_ast_t.type_ptr) list;
_ret_type : Clang_ast_t.type_ptr; _ret_type : Clang_ast_t.type_ptr;
_attributes : Clang_ast_t.attribute list; _attributes : Clang_ast_t.attribute list;
_loc : Clang_ast_t.source_range; _loc : Clang_ast_t.source_range;
@ -65,7 +65,7 @@ let ms_to_string ms =
let gen = if ms._is_generated then " (generated)" else "" in let gen = if ms._is_generated then " (generated)" else "" in
"Method " ^ (Procname.to_string ms._name) ^ gen ^ " " ^ "Method " ^ (Procname.to_string ms._name) ^ gen ^ " " ^
IList.to_string IList.to_string
(fun (s1, s2, _) -> s1 ^ ", " ^ (Clang_ast_j.string_of_type_ptr s2)) (fun (s1, s2) -> s1 ^ ", " ^ (Clang_ast_j.string_of_type_ptr s2))
ms._args ms._args
^ "->" ^ (Clang_ast_j.string_of_type_ptr ms._ret_type) ^ " " ^ ^ "->" ^ (Clang_ast_j.string_of_type_ptr ms._ret_type) ^ " " ^
Clang_ast_j.string_of_source_range ms._loc Clang_ast_j.string_of_source_range ms._loc

@ -15,7 +15,7 @@ type method_signature
val ms_get_name : method_signature -> Procname.t val ms_get_name : method_signature -> Procname.t
val ms_get_args : method_signature -> val ms_get_args : method_signature ->
(string * Clang_ast_t.type_ptr * Clang_ast_t.stmt option) list (string * Clang_ast_t.type_ptr) list
val ms_get_ret_type : method_signature -> Clang_ast_t.type_ptr val ms_get_ret_type : method_signature -> Clang_ast_t.type_ptr
@ -27,7 +27,7 @@ val ms_is_instance : method_signature -> bool
val ms_get_lang : method_signature -> CFrontend_config.lang val ms_get_lang : method_signature -> CFrontend_config.lang
val make_ms : Procname.t -> (string * Clang_ast_t.type_ptr * Clang_ast_t.stmt option) list -> val make_ms : Procname.t -> (string * Clang_ast_t.type_ptr) list ->
Clang_ast_t.type_ptr -> Clang_ast_t.attribute list -> Clang_ast_t.source_range -> bool -> Clang_ast_t.type_ptr -> Clang_ast_t.attribute list -> Clang_ast_t.source_range -> bool ->
bool -> CFrontend_config.lang -> method_signature bool -> CFrontend_config.lang -> method_signature

@ -45,10 +45,10 @@ let get_class_param function_method_decl_info =
match function_method_decl_info with match function_method_decl_info with
| Cpp_Meth_decl_info (_, class_name, _) -> | Cpp_Meth_decl_info (_, class_name, _) ->
let class_type = Ast_expressions.create_class_type class_name in let class_type = Ast_expressions.create_class_type class_name in
[(CFrontend_config.this, class_type, None)] [(CFrontend_config.this, class_type)]
| ObjC_Meth_decl_info (_, class_name) -> | ObjC_Meth_decl_info (_, class_name) ->
let class_type = Ast_expressions.create_class_type class_name in let class_type = Ast_expressions.create_class_type class_name in
[(CFrontend_config.self, class_type, None)] [(CFrontend_config.self, class_type)]
| _ -> [] | _ -> []
else [] else []
@ -71,7 +71,7 @@ let get_parameters function_method_decl_info =
match par with match par with
| Clang_ast_t.ParmVarDecl (decl_info, name_info, type_ptr, var_decl_info) -> | Clang_ast_t.ParmVarDecl (decl_info, name_info, type_ptr, var_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in let name = name_info.Clang_ast_t.ni_name in
(name, type_ptr, var_decl_info.Clang_ast_t.vdi_init_expr) (name, type_ptr)
| _ -> assert false in | _ -> assert false in
let pars = IList.map par_to_ms_par (get_param_decls function_method_decl_info) in let pars = IList.map par_to_ms_par (get_param_decls function_method_decl_info) in
@ -200,7 +200,7 @@ let get_formal_parameters tenv ms =
let rec defined_parameters pl = let rec defined_parameters pl =
match pl with match pl with
| [] -> [] | [] -> []
| (name, raw_type, _):: pl' -> | (name, raw_type):: pl' ->
let should_add_pointer name ms = let should_add_pointer name ms =
let is_objc_self = name = CFrontend_config.self && let is_objc_self = name = CFrontend_config.self &&
CMethod_signature.ms_get_lang ms = CFrontend_config.OBJC in CMethod_signature.ms_get_lang ms = CFrontend_config.OBJC in

@ -600,7 +600,7 @@ struct
(Procname.to_string pn) <> CFrontend_config.builtin_object_size (Procname.to_string pn) <> CFrontend_config.builtin_object_size
| _ -> true in | _ -> true in
let params_stmt = if should_translate_args then let params_stmt = if should_translate_args then
CTrans_utils.assign_default_params params_stmt None fun_exp_stmt ~is_cxx_method:false CTrans_utils.assign_default_params params_stmt fun_exp_stmt
else [] in else [] in
let res_trans_par = let res_trans_par =
let instruction' = exec_with_self_exception (exec_with_lvalue_as_reference instruction) in let instruction' = exec_with_self_exception (exec_with_lvalue_as_reference instruction) in
@ -678,8 +678,7 @@ struct
let callee_pname = match sil_method with let callee_pname = match sil_method with
| Sil.Const (Sil.Cfun pn) -> pn | Sil.Const (Sil.Cfun pn) -> pn
| _ -> assert false (* method pointer not implemented, this shouldn't happen *) in | _ -> assert false (* method pointer not implemented, this shouldn't happen *) in
let class_name_opt = Some (Procname.c_get_class callee_pname) in let params_stmt = CTrans_utils.assign_default_params params_stmt fun_exp_stmt in
let params_stmt = CTrans_utils.assign_default_params params_stmt class_name_opt fun_exp_stmt ~is_cxx_method:true in
(* As we may have nodes coming from different parameters we need to *) (* As we may have nodes coming from different parameters we need to *)
(* call instruction for each parameter and collect the results *) (* call instruction for each parameter and collect the results *)
(* afterwards. The 'instructions' function does not do that *) (* afterwards. The 'instructions' function does not do that *)

@ -137,7 +137,7 @@ let get_predefined_ms_stringWithUTF8String class_name method_name mk_procname la
&& method_name = CFrontend_config.string_with_utf8_m in && method_name = CFrontend_config.string_with_utf8_m in
let id_type = Ast_expressions.create_id_type in let id_type = Ast_expressions.create_id_type in
get_predefined_ms_method condition class_name method_name Procname.Class_objc_method get_predefined_ms_method condition class_name method_name Procname.Class_objc_method
mk_procname lang [("x", Ast_expressions.create_char_star_type, None)] id_type [] None mk_procname lang [("x", Ast_expressions.create_char_star_type)] id_type [] None
let get_predefined_ms_retain_release class_name method_name mk_procname lang = let get_predefined_ms_retain_release class_name method_name mk_procname lang =
let condition = is_retain_or_release method_name in let condition = is_retain_or_release method_name in
@ -146,7 +146,7 @@ let get_predefined_ms_retain_release class_name method_name mk_procname lang =
then Ast_expressions.create_id_type else Ast_expressions.create_void_type in then Ast_expressions.create_id_type else Ast_expressions.create_void_type in
let class_name = CFrontend_config.nsobject_cl in let class_name = CFrontend_config.nsobject_cl in
let class_type = Ast_expressions.create_class_type class_name in let class_type = Ast_expressions.create_class_type class_name in
let args = [(CFrontend_config.self, class_type, None)] in let args = [(CFrontend_config.self, class_type)] in
get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method
mk_procname lang args return_type [] (get_builtinname method_name) mk_procname lang args return_type [] (get_builtinname method_name)
@ -156,7 +156,7 @@ let get_predefined_ms_autoreleasepool_init class_name method_name mk_procname la
&& class_name = CFrontend_config.nsautorelease_pool_cl in && class_name = CFrontend_config.nsautorelease_pool_cl in
let class_type = Ast_expressions.create_class_type class_name in let class_type = Ast_expressions.create_class_type class_name in
get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method
mk_procname lang [(CFrontend_config.self, class_type, None)] mk_procname lang [(CFrontend_config.self, class_type)]
Ast_expressions.create_void_type [] None Ast_expressions.create_void_type [] None
let get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procname lang = let get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procname lang =
@ -165,7 +165,7 @@ let get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procna
&& class_name = CFrontend_config.nsautorelease_pool_cl in && class_name = CFrontend_config.nsautorelease_pool_cl in
let class_type = Ast_expressions.create_class_type class_name in let class_type = Ast_expressions.create_class_type class_name in
get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method
mk_procname lang [(CFrontend_config.self, class_type, None)] Ast_expressions.create_void_type mk_procname lang [(CFrontend_config.self, class_type)] Ast_expressions.create_void_type
[] (Some SymExec.ModelBuiltins.__objc_release_autorelease_pool) [] (Some SymExec.ModelBuiltins.__objc_release_autorelease_pool)
let get_predefined_model_method_signature class_name method_name mk_procname lang = let get_predefined_model_method_signature class_name method_name mk_procname lang =

@ -708,28 +708,34 @@ let rec pointer_of_call_expr stmt =
| [stmt] -> pointer_of_call_expr stmt | [stmt] -> pointer_of_call_expr stmt
| _ -> None | _ -> None
let assign_default_params params_stmt class_name_opt stmt ~is_cxx_method = let get_decl_from_call_expr stmt =
match pointer_of_call_expr stmt with match pointer_of_call_expr stmt with
| Some pointer -> | Some pointer -> Ast_utils.get_decl pointer
(match CMethod_trans.method_signature_of_pointer class_name_opt pointer with | _ -> None
| Some callee_ms ->
(let args = CMethod_signature.ms_get_args callee_ms in
let args = if is_cxx_method then match args with _::tl -> tl | _ -> assert false let assign_default_params params_stmt call_stmt =
else args in let open Clang_ast_t in
let replace_default_arg param = match get_decl_from_call_expr call_stmt with
match param with | Some FunctionDecl (_, name_info, _, fdecl_info)
| Clang_ast_t.CXXDefaultArgExpr _, (_, _, Some default_instr) -> | Some CXXMethodDecl (_, name_info, _, fdecl_info, _)
default_instr | Some CXXConstructorDecl (_, name_info, _, fdecl_info, _) ->
| instr, _ -> instr in (let get_param_default_val param_decl = match param_decl with
try | ParmVarDecl (_, _, _, var_decl_info) -> var_decl_info.vdi_init_expr
let params_args = IList.combine params_stmt args in | _ -> None in
IList.map replace_default_arg params_args let replace_default_arg param = match param with
with Invalid_argument _ -> | CXXDefaultArgExpr _, Some default_expr -> default_expr
(* IList.combine failed because of different list lengths *) | instr, _ -> instr in
Printing.log_err "Param count doesn't match %s\n" let default_params = IList.map get_param_default_val fdecl_info.Clang_ast_t.fdi_parameters in
(Procname.to_string (CMethod_signature.ms_get_name callee_ms)); try
params_stmt) let param_args = IList.combine params_stmt default_params in
| None -> params_stmt) IList.map replace_default_arg param_args
with Invalid_argument _ ->
let name = name_info.ni_name in
(* IList.combine failed because of different list lengths *)
Printing.log_err "Param count doesn't match %s\n" name;
params_stmt)
| Some _ -> params_stmt
| None -> params_stmt | None -> params_stmt

@ -219,8 +219,7 @@ val is_logical_negation_of_int : Sil.tenv -> Clang_ast_t.expr_info -> Clang_ast_
val is_dispatch_function : Clang_ast_t.stmt list -> int option val is_dispatch_function : Clang_ast_t.stmt list -> int option
val assign_default_params : Clang_ast_t.stmt list -> string option -> Clang_ast_t.stmt -> val assign_default_params : Clang_ast_t.stmt list -> Clang_ast_t.stmt -> Clang_ast_t.stmt list
is_cxx_method:bool -> Clang_ast_t.stmt list
val is_block_enumerate_function : Clang_ast_t.obj_c_message_expr_info -> bool val is_block_enumerate_function : Clang_ast_t.obj_c_message_expr_info -> bool

Loading…
Cancel
Save